From 18bb37dcc898a915807ce83431787c177e61d401 Mon Sep 17 00:00:00 2001 From: Brian Grinstead Date: Tue, 27 Feb 2018 10:04:14 -0800 Subject: [PATCH] Bug 1392352 - Part 2 - Translate the tabbrowser implementation into a JS class;r=mconley,r=dao CLOSED TREE We keep the XBL binding around for , , and . This can eventually be migrated to a Custom Element once we have platform support, but in the meantime this is a way to get the many thousands of LOC into a JS class. MozReview-Commit-ID: 1dCQp527yF9 --HG-- extra : rebase_source : 26b833413bab71168aa15e03f0f3803884be3f6b extra : amend_source : 150cef6748ca8a9e819de0c674fac5966dd574cf --- .../browser-fullScreenAndPointerLock.js | 2 +- browser/base/content/browser.js | 17 +- browser/base/content/browser.xul | 4 +- browser/base/content/global-scripts.inc | 1 + browser/base/content/tabbrowser.js | 11800 ++++++++-------- browser/base/content/tabbrowser.xml | 6301 +-------- .../browser_tabopen_squeeze_reflows.js | 2 +- ...ser_tabstrip_overflow_underflow_reflows.js | 2 +- browser/base/jar.mn | 1 + .../test/browser_scratchpad_contexts.js | 2 +- .../BrowserTestUtils/BrowserTestUtils.jsm | 2 +- .../addoncompat/RemoteAddonsParent.jsm | 10 +- .../addoncompat/multiprocessShims.js | 6 +- toolkit/modules/PopupNotifications.jsm | 4 +- 14 files changed, 5660 insertions(+), 12494 deletions(-) mode change 100755 => 100644 browser/base/content/global-scripts.inc diff --git a/browser/base/content/browser-fullScreenAndPointerLock.js b/browser/base/content/browser-fullScreenAndPointerLock.js index 7b4a00bb7c0f..7ec7650aeaf7 100644 --- a/browser/base/content/browser-fullScreenAndPointerLock.js +++ b/browser/base/content/browser-fullScreenAndPointerLock.js @@ -376,7 +376,7 @@ var FullScreen = { // request was initiated from an in-process browser, we need // to get its corresponding browser here. let browser; - if (event.target == gBrowser) { + if (event.target == gBrowser.container) { browser = event.originalTarget; } else { let topWin = event.target.ownerGlobal.top; diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 799fdf7369bf..7af51097d0c6 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -221,6 +221,7 @@ XPCOMUtils.defineLazyGetter(this, "Win7Features", function() { const nsIWebNavigation = Ci.nsIWebNavigation; +var gBrowser = null; // Will be instantiated by the constructor. var gLastValidURLStr = ""; var gInPrintPreviewMode = false; var gContextMenu = null; // nsContextMenu instance @@ -234,9 +235,8 @@ if (AppConstants.platform != "macosx") { var gEditUIVisible = true; } -/* globals gBrowser, gNavToolbox, gURLBar:true */ +/* globals gNavToolbox, gURLBar:true */ [ - ["gBrowser", "content"], ["gNavToolbox", "navigator-toolbox"], ["gURLBar", "urlbar"], ].forEach(function(elementGlobal) { @@ -1196,8 +1196,7 @@ var gBrowserInit = { window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = new nsBrowserAccess(); - let initBrowser = - document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser"); + let initBrowser = gBrowser.initialBrowser; // remoteType and sameProcessAsFrameLoader are passed through to // updateBrowserRemoteness as part of an options object, which itself defaults @@ -1301,7 +1300,7 @@ var gBrowserInit = { if (!gMultiProcessBrowser) { // There is a Content:Click message manually sent from content. - Services.els.addSystemEventListener(gBrowser, "click", contentAreaClick, true); + Services.els.addSystemEventListener(gBrowser.container, "click", contentAreaClick, true); } // hook up UI through progress listener @@ -4342,15 +4341,11 @@ var XULBrowserWindow = { }, forceInitialBrowserRemote(aRemoteType) { - let initBrowser = - document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser"); - gBrowser.updateBrowserRemoteness(initBrowser, true, { remoteType: aRemoteType }); + gBrowser.updateBrowserRemoteness(gBrowser.initialBrowser, true, { remoteType: aRemoteType }); }, forceInitialBrowserNonRemote(aOpener) { - let initBrowser = - document.getAnonymousElementByAttribute(gBrowser, "anonid", "initialBrowser"); - gBrowser.updateBrowserRemoteness(initBrowser, false, { opener: aOpener }); + gBrowser.updateBrowserRemoteness(gBrowser.initialBrowser, false, { opener: aOpener }); }, setDefaultStatus(status) { diff --git a/browser/base/content/browser.xul b/browser/base/content/browser.xul index 3fcb22117276..423486d484f0 100644 --- a/browser/base/content/browser.xul +++ b/browser/base/content/browser.xul @@ -14,6 +14,7 @@ + @@ -1209,8 +1210,7 @@ - - gBrowser; - - this.tabbrowser.tabbox; @@ -6494,6 +207,12 @@ window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils); + + + return window.gBrowser; + + + if (!this._restoreTabsButtonWrapperWidth) { diff --git a/browser/base/content/test/performance/browser_tabopen_squeeze_reflows.js b/browser/base/content/test/performance/browser_tabopen_squeeze_reflows.js index c0631aea3c69..a968fb9fc03c 100644 --- a/browser/base/content/test/performance/browser_tabopen_squeeze_reflows.js +++ b/browser/base/content/test/performance/browser_tabopen_squeeze_reflows.js @@ -14,7 +14,7 @@ const EXPECTED_REFLOWS = [ stack: [ "select@chrome://global/content/bindings/textbox.xml", "focusAndSelectUrlBar@chrome://browser/content/browser.js", - "_adjustFocusAfterTabSwitch@chrome://browser/content/tabbrowser.xml", + "_adjustFocusAfterTabSwitch@chrome://browser/content/tabbrowser.js", ], } ]; diff --git a/browser/base/content/test/performance/browser_tabstrip_overflow_underflow_reflows.js b/browser/base/content/test/performance/browser_tabstrip_overflow_underflow_reflows.js index 292433d241b5..f3654eec704e 100644 --- a/browser/base/content/test/performance/browser_tabstrip_overflow_underflow_reflows.js +++ b/browser/base/content/test/performance/browser_tabstrip_overflow_underflow_reflows.js @@ -14,7 +14,7 @@ const EXPECTED_OVERFLOW_REFLOWS = [ stack: [ "select@chrome://global/content/bindings/textbox.xml", "focusAndSelectUrlBar@chrome://browser/content/browser.js", - "_adjustFocusAfterTabSwitch@chrome://browser/content/tabbrowser.xml", + "_adjustFocusAfterTabSwitch@chrome://browser/content/tabbrowser.js", ] }, ]; diff --git a/browser/base/jar.mn b/browser/base/jar.mn index d06052d5ca7d..56261c7e3ad7 100644 --- a/browser/base/jar.mn +++ b/browser/base/jar.mn @@ -117,6 +117,7 @@ browser.jar: content/browser/contentSearchUI.js (content/contentSearchUI.js) content/browser/contentSearchUI.css (content/contentSearchUI.css) content/browser/tabbrowser.css (content/tabbrowser.css) + content/browser/tabbrowser.js (content/tabbrowser.js) content/browser/tabbrowser.xml (content/tabbrowser.xml) * content/browser/urlbarBindings.xml (content/urlbarBindings.xml) content/browser/utilityOverlay.js (content/utilityOverlay.js) diff --git a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js index 738ece698a0b..adb23b29f86d 100644 --- a/devtools/client/scratchpad/test/browser_scratchpad_contexts.js +++ b/devtools/client/scratchpad/test/browser_scratchpad_contexts.js @@ -91,7 +91,7 @@ function runTests() { "setText() worked with no end for the replace range"); }, then: function* ([, , result]) { - is(result.class, "XULElement", + is(result.class, "Object", "chrome context has access to chrome objects"); } }, { diff --git a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm index 024d6be03eec..8f33a59b9fd6 100644 --- a/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm +++ b/testing/mochitest/BrowserTestUtils/BrowserTestUtils.jsm @@ -144,7 +144,7 @@ var BrowserTestUtils = { */ openNewForegroundTab(tabbrowser, ...args) { let options; - if (tabbrowser instanceof Ci.nsIDOMXULElement) { + if (tabbrowser.ownerGlobal && tabbrowser === tabbrowser.ownerGlobal.gBrowser) { // tabbrowser is a tabbrowser, read the rest of the arguments from args. let [ opening = "about:blank", diff --git a/toolkit/components/addoncompat/RemoteAddonsParent.jsm b/toolkit/components/addoncompat/RemoteAddonsParent.jsm index 5dd3242a574c..3a231631f063 100644 --- a/toolkit/components/addoncompat/RemoteAddonsParent.jsm +++ b/toolkit/components/addoncompat/RemoteAddonsParent.jsm @@ -439,13 +439,17 @@ var EventTargetParent = { // Some non-browser windows define gBrowser globals which are not elements // and can't be passed to target.contains(). - if (window && - window.gBrowser instanceof Ci.nsIDOMXULElement && - target.contains(window.gBrowser)) { + if (window && window.gBrowser && + window.gBrowser.container instanceof Ci.nsIDOMXULElement && + target.contains(window.gBrowser.container)) { return window; } } + if (target.ownerGlobal && target === target.ownerGlobal.gBrowser) { + return target.ownerGlobal; + } + return null; }, diff --git a/toolkit/components/addoncompat/multiprocessShims.js b/toolkit/components/addoncompat/multiprocessShims.js index 6ccd5de3786a..7c65966c2656 100644 --- a/toolkit/components/addoncompat/multiprocessShims.js +++ b/toolkit/components/addoncompat/multiprocessShims.js @@ -113,10 +113,10 @@ AddonInterpositionService.prototype = { if (target.localName == "browser" && target.isRemoteBrowser) { return "RemoteBrowserElement"; } + } - if (target.localName == "tabbrowser") { - return "TabBrowserElement"; - } + if (target.ownerGlobal && target === target.ownerGlobal.gBrowser) { + return "TabBrowserElement"; } if (target instanceof Ci.nsIDOMChromeWindow && target.gMultiProcessBrowser) { diff --git a/toolkit/modules/PopupNotifications.jsm b/toolkit/modules/PopupNotifications.jsm index 91178b5165d2..2aec7b81147a 100644 --- a/toolkit/modules/PopupNotifications.jsm +++ b/toolkit/modules/PopupNotifications.jsm @@ -188,7 +188,7 @@ Notification.prototype = { * The PopupNotifications object manages popup notifications for a given browser * window. * @param tabbrowser - * window's . Used to observe tab switching events and + * window's TabBrowser. Used to observe tab switching events and * for determining the active browser element. * @param panel * The element to use for notifications. The panel is @@ -211,7 +211,7 @@ Notification.prototype = { */ function PopupNotifications(tabbrowser, panel, iconBox, options = {}) { - if (!(tabbrowser instanceof Ci.nsIDOMXULElement)) + if (!tabbrowser) throw "Invalid tabbrowser"; if (iconBox && !(iconBox instanceof Ci.nsIDOMXULElement)) throw "Invalid iconBox";