Bug 1512650 - Allow overriding actions like Switch to tab. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Wed, 16 Jan 2019 14:27:36 +0000
changeset 514077 987910383af00b26d557da874c16d039fba18da5
parent 514068 6e8f0fdbe2e21fbf8db2bbfe1cefd5ba13ea665b
child 514078 078e5984f999de05c3987fd04679b8703a042cb3
push id1953
push userffxbld-merge
push dateMon, 11 Mar 2019 12:10:20 +0000
treeherdermozilla-release@9c35dcbaa899 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1512650
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1512650 - Allow overriding actions like Switch to tab. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D16541
browser/components/urlbar/UrlbarInput.jsm
--- a/browser/components/urlbar/UrlbarInput.jsm
+++ b/browser/components/urlbar/UrlbarInput.jsm
@@ -4,16 +4,17 @@
 
 "use strict";
 
 var EXPORTED_SYMBOLS = ["UrlbarInput"];
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetters(this, {
+  AppConstants: "resource://gre/modules/AppConstants.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
   QueryContext: "resource:///modules/UrlbarUtils.jsm",
   Services: "resource://gre/modules/Services.jsm",
   UrlbarController: "resource:///modules/UrlbarController.jsm",
   UrlbarPrefs: "resource:///modules/UrlbarPrefs.jsm",
   UrlbarUtils: "resource:///modules/UrlbarUtils.jsm",
   UrlbarValueFormatter: "resource:///modules/UrlbarValueFormatter.jsm",
   UrlbarView: "resource:///modules/UrlbarView.jsm",
@@ -288,34 +289,32 @@ class UrlbarInput {
     let where = this._whereToOpen(event);
     let openParams = {
       postData: null,
       allowInheritPrincipal: false,
     };
 
     switch (result.type) {
       case UrlbarUtils.MATCH_TYPE.TAB_SWITCH: {
+        if (this._overrideDefaultAction(event)) {
+          where = "current";
+          break;
+        }
+
         this.handleRevert();
         let prevTab = this.window.gBrowser.selectedTab;
         let loadOpts = {
           adoptIntoActiveWindow: UrlbarPrefs.get("switchTabs.adoptIntoActiveWindow"),
         };
 
         if (this.window.switchToTabHavingURI(Services.io.newURI(result.payload.url), false, loadOpts) &&
             prevTab.isEmpty) {
           this.window.gBrowser.removeTab(prevTab);
         }
         return;
-
-        // TODO: How to handle meta chars?
-        // Once we get here, we got a TAB_SWITCH match but the user
-        // bypassed it by pressing shift/meta/ctrl. Those modifiers
-        // might otherwise affect where we open - we always want to
-        // open in the current tab.
-        // where = "current";
       }
       case UrlbarUtils.MATCH_TYPE.SEARCH:
         // TODO: port _parseAndRecordSearchEngineLoad.
         return;
       case UrlbarUtils.MATCH_TYPE.OMNIBOX:
         // Give the extension control of handling the command.
         ExtensionSearchHandler.handleInputEntered(result.payload.keyword,
                                                   result.payload.content,
@@ -517,16 +516,23 @@ class UrlbarInput {
       // the beginning or end (or both).
       let trimmedSegments = spec.split(trimmedSpec);
       selectedVal = trimmedSegments[0] + selectedVal;
     }
 
     return selectedVal;
   }
 
+  _overrideDefaultAction(event) {
+    return event.shiftKey ||
+           event.altKey ||
+           (AppConstants.platform == "macosx" ?
+              event.metaKey : event.ctrlKey);
+  }
+
   /**
    * @param {string} url
    * @returns {object}
    *   The action object
    */
   _parseActionUrl(url) {
     const MOZ_ACTION_REGEX = /^moz-action:([^,]+),(.*)$/;
     if (!MOZ_ACTION_REGEX.test(url)) {