Bug 1578067 - Part 3: Update openLinkIn() and use more - update contentAreaClick. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Sun, 13 Oct 2019 13:21:01 +0200
changeset 37141 8f6a7dd3996f3db7a990a7faab70f34d13a6e0ff
parent 37140 aafc1fdafb54c5ae4cd9ae6034823d58dea85d98
child 37142 f171994fe29ab5f98c710d71d124dd1e681c0908
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersfrg
bugs1578067
Bug 1578067 - Part 3: Update openLinkIn() and use more - update contentAreaClick. r=frg
suite/base/content/contentAreaClick.js
--- a/suite/base/content/contentAreaClick.js
+++ b/suite/base/content/contentAreaClick.js
@@ -52,17 +52,21 @@
       return true;
     }
 
     var isKeyCommand = (event.type == "command");
     var ceParams = hrefAndLinkNodeForClickEvent(event);
     if (ceParams) {
       var href = ceParams.href;
       if (isKeyCommand) {
-        openNewTabWith(href, event.target, event.altKey);
+        var doc = event.target.ownerDocument;
+        urlSecurityCheck(href, doc.nodePrincipal);
+        openLinkIn(href, event && event.altKey ? "tabshifted" : "tab",
+                   { charset: doc.characterSet,
+                     referrerURI: doc.documentURIObject });
         event.stopPropagation();
       }
       else {
         // if in mailnews block the link left click if we determine
         // that this URL is phishy (i.e. a potential email scam)
         if ("gMessengerBundle" in this && event.button < 2 &&
             isPhishingURL(ceParams.linkNode, false, href))
           return false;
@@ -83,69 +87,40 @@
         Services.prefs.getBoolPref("middlemouse.contentLoadURL") &&
         !Services.prefs.getBoolPref("general.autoScroll")) {
       middleMousePaste(event);
     }
 
     return true;
   }
 
-  function openNewTabOrWindow(event, href, node)
-  {
-    // should we open it in a new tab?
-    if (Services.prefs.getBoolPref("browser.tabs.opentabfor.middleclick")) {
-      openNewTabWith(href, node, null, event);
-      event.stopPropagation();
-      return true;
-    }
+function handleLinkClick(event, href, linkNode) {
+  if (event.button == 2) // right click
+    return false;
+
+  var where = whereToOpenLink(event);
+  if (where == "current")
+    return false;
 
-    // should we open it in a new window?
-    if (Services.prefs.getBoolPref("middlemouse.openNewWindow")) {
-      if (gPrivate)
-        openNewPrivateWith(href, node);
-      else
-        openNewWindowWith(href, node);
-      event.stopPropagation();
-      return true;
-    }
+  var doc = event.target.ownerDocument;
 
-    // let someone else deal with it
-    return false;
+  if (where == "save") {
+    saveURL(href, linkNode ? gatherTextUnder(linkNode) : "", null, false,
+            true, doc.documentURIObject, doc);
+    event.preventDefault();
+    return true;
   }
 
-  function handleLinkClick(event, href, linkNode)
-  {
-    // Checking to make sure we are allowed to open this URL
-    // (call to urlSecurityCheck) is now done within openNew... functions
-
-    switch (event.button) {
-      case 0:                                                         // if left button clicked
-        if (event.metaKey || event.ctrlKey) {                         // and meta or ctrl are down
-          if (openNewTabOrWindow(event, href, linkNode))
-            return true;
-        }
-        var saveModifier = Services.prefs.getBoolPref("ui.key.saveLink.shift", true);
-        saveModifier = saveModifier ? event.shiftKey : event.altKey;
-
-        if (saveModifier) {                                           // if saveModifier is down
-          var doc = linkNode.ownerDocument;
-          saveURL(href, gatherTextUnder(linkNode), "SaveLinkTitle",
-                  false, true, doc.documentURIObject, doc);
-          return true;
-        }
-        if (event.altKey)                                             // if alt is down
-          return true;                                                // do nothing
-        return false;
-      case 1:                                                         // if middle button clicked
-        if (openNewTabOrWindow(event, href, linkNode))
-          return true;
-        break;
-    }
-    return false;
-  }
+  urlSecurityCheck(href, doc.nodePrincipal);
+  openLinkIn(href, where, { referrerURI: doc.documentURIObject,
+                            charset: doc.characterSet,
+                            private: gPrivate ? true : false });
+  event.preventDefault();
+  return true;
+}
 
   var gURIFixup = null;
 
   function middleMousePaste(event) {
 
     let clipboard = readFromClipboard();
 
     if (!clipboard)
@@ -180,17 +155,17 @@
         // but don't let that interfere with the loading of the url.
         Cu.reportError(ex);
       }
 
       if (where != "current" ||
           lastLocationChange == gBrowser.selectedBrowser.lastLocationChange) {
         openUILink(data.url, event,
                    { ignoreButton: true,
-                       disallowInheritPrincipal: !data.mayInheritPrincipal });
+                     disallowInheritPrincipal: !data.mayInheritPrincipal });
       }
     });
 
     event.stopPropagation();
   }
 
   function stripUnsafeProtocolOnPaste(pasteData) {
     // Don't allow pasting javascript URIs since we don't support