Bug 1509309 - Move most browser-*.js scripts from global-scripts.inc to browser.xul. r=Standard8
authorDão Gottwald <dao@mozilla.com>
Tue, 27 Nov 2018 21:55:21 +0000
changeset 504820 5e1161b3716a6b8492ee8029920a19595c42a136
parent 504819 74216c81fc8d385d94e1f7ea6b0c2377aca65953
child 504821 49aba2e71c128cd0d1be6df09e7931884ed91b3e
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8
bugs1509309
milestone65.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 1509309 - Move most browser-*.js scripts from global-scripts.inc to browser.xul. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D13064
browser/base/content/browser.js
browser/base/content/browser.xul
browser/base/content/global-scripts.inc
browser/base/content/tabbrowser.js
browser/base/content/urlbarBindings.xml
browser/components/search/content/search-one-offs.js
browser/components/search/content/search.xml
browser/components/search/content/searchbar.js
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -1,16 +1,13 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* eslint-env mozilla/browser-window */
-/* globals StatusPanel */
-
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 ChromeUtils.import("resource://gre/modules/NotificationDB.jsm");
 
 const {WebExtensionPolicy} = Cu.getGlobalForObject(Services);
 
 // lazy module getters
--- a/browser/base/content/browser.xul
+++ b/browser/base/content/browser.xul
@@ -83,16 +83,30 @@
 #include global-scripts.inc
 
 <script type="application/javascript"
 #ifdef BROWSER_XHTML
 xmlns="http://www.w3.org/1999/xhtml"
 #endif
 >
   Services.scriptloader.loadSubScript("chrome://global/content/contentAreaUtils.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-captivePortal.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-compacttheme.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-contentblocking.js", this);
+#ifdef MOZ_DATA_REPORTING
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-data-submission-info-bar.js", this);
+#endif
+#ifndef MOZILLA_OFFICIAL
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-development-helpers.js", this);
+#endif
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-media.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-pageActions.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-plugins.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-sidebar.js", this);
+  Services.scriptloader.loadSubScript("chrome://browser/content/browser-tabsintitlebar.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/tabbrowser.js", this);
   Services.scriptloader.loadSubScript("chrome://browser/content/search/searchbar.js", this);
 
   window.onload = gBrowserInit.onLoad.bind(gBrowserInit);
   window.onunload = gBrowserInit.onUnload.bind(gBrowserInit);
   window.onclose = WindowIsClosing;
 
 #ifdef BROWSER_XHTML
--- a/browser/base/content/global-scripts.inc
+++ b/browser/base/content/global-scripts.inc
@@ -1,44 +1,32 @@
 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+# JS files which are needed by browser.xul but no other top level windows to
+# support MacOS specific features should be loaded directly from browser.xul
+# rather than this file.
+
 # If you update this list, you may need to add a mapping within the following
 # file so that ESLint works correctly:
 # tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
 
 <script type="text/javascript"
 #ifdef BROWSER_XHTML
 xmlns="http://www.w3.org/1999/xhtml"
 #endif
 >
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 for (let script of [
   "chrome://browser/content/browser.js",
-
-  "chrome://browser/content/browser-captivePortal.js",
-  "chrome://browser/content/browser-compacttheme.js",
-  "chrome://browser/content/browser-contentblocking.js",
-  "chrome://browser/content/browser-media.js",
-  "chrome://browser/content/browser-pageActions.js",
   "chrome://browser/content/browser-places.js",
-  "chrome://browser/content/browser-plugins.js",
-  "chrome://browser/content/browser-sidebar.js",
-  "chrome://browser/content/browser-tabsintitlebar.js",
-
   "chrome://global/content/globalOverlay.js",
   "chrome://browser/content/utilityOverlay.js",
 #ifdef XP_MACOSX
   "chrome://global/content/macWindowMenu.js",
 #endif
-#ifdef MOZ_DATA_REPORTING
-  "chrome://browser/content/browser-data-submission-info-bar.js",
-#endif
-#ifndef MOZILLA_OFFICIAL
-  "chrome://browser/content/browser-development-helpers.js",
-#endif
 ]) {
   Services.scriptloader.loadSubScript(script, this);
 }
 </script>
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1,15 +1,13 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* eslint-env mozilla/browser-window */
-
 { // start private scope for gBrowser
 
 /**
  * A set of known icons to use for internal pages. These are hardcoded so we can
  * start loading them faster than ContentLinkHandler would normally find them.
  */
 const FAVICON_DEFAULTS = {
   "about:newtab": "chrome://branding/content/icon32.png",
--- a/browser/base/content/urlbarBindings.xml
+++ b/browser/base/content/urlbarBindings.xml
@@ -1932,17 +1932,17 @@ file, You can obtain one at http://mozil
         document.getAnonymousElementByAttribute(this, "anonid", "footer");
       </field>
 
       <field name="shrinkDelay" readonly="true">
         250
       </field>
 
       <field name="oneOffSearchButtons" readonly="true">
-        new window.SearchOneOffs(
+        new SearchOneOffs(
           document.getAnonymousElementByAttribute(this, "anonid",
                                                   "one-off-search-buttons"));
       </field>
 
       <field name="_overrideValue">null</field>
       <property name="overrideValue"
                 onget="return this._overrideValue;"
                 onset="this._overrideValue = val; return val;"/>
--- a/browser/components/search/content/search-one-offs.js
+++ b/browser/components/search/content/search-one-offs.js
@@ -2,18 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 /* eslint-env mozilla/browser-window */
 /* globals XULCommandEvent */
 
-{
-
 class SearchOneOffs {
   constructor(container) {
     this.container = container;
 
     this.container.appendChild(MozXULElement.parseXULToFragment(`
       <deck class="search-panel-one-offs-header search-panel-header search-panel-current-input">
         <label class="searchbar-oneoffheader-search" value="&searchWithHeader.label;"/>
         <hbox class="search-panel-searchforwith search-panel-current-input">
@@ -1231,10 +1229,8 @@ class SearchOneOffs {
       this.selectedButton = null;
       this._contextEngine = null;
     });
   }
 }
 
 window.SearchOneOffs = SearchOneOffs;
 
-}
-
--- a/browser/components/search/content/search.xml
+++ b/browser/components/search/content/search.xml
@@ -466,17 +466,17 @@
               this._bundle = Services.strings.createBundle(kBundleURI);
             }
             return this._bundle;
           ]]>
         </getter>
       </property>
 
       <field name="oneOffButtons" readonly="true">
-        new window.SearchOneOffs(
+        new SearchOneOffs(
           document.getAnonymousElementByAttribute(this, "anonid",
                                                   "search-one-off-buttons"));
       </field>
 
       <method name="updateHeader">
         <body><![CDATA[
           let currentEngine = Services.search.defaultEngine;
           let uri = currentEngine.iconURI;
--- a/browser/components/search/content/searchbar.js
+++ b/browser/components/search/content/searchbar.js
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
-/* eslint-env mozilla/browser-window */
 /* globals XULCommandEvent */
 
 // This is loaded into chrome windows with the subscript loader. Wrap in
 // a block to prevent accidentally leaking globals onto `window`.
 {
 
 const inheritsMap = {
   ".searchbar-textbox": ["disabled", "disableautocomplete", "searchengine", "src", "newlines"],
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/browser-window.js
@@ -18,26 +18,24 @@ var path = require("path");
 var helpers = require("../helpers");
 var globals = require("../globals");
 
 const rootDir = helpers.rootDir;
 
 // When updating EXTRA_SCRIPTS or MAPPINGS, be sure to also update the
 // 'support-files' config in `tools/lint/eslint.yml`.
 
-// These are scripts not included in global-scripts.inc, but which are loaded
-// via overlays.
+// These are scripts not loaded from browser.xul or global-scripts.inc
+// but via other includes.
 const EXTRA_SCRIPTS = [
   "browser/base/content/nsContextMenu.js",
-  "toolkit/content/contentAreaUtils.js",
-  "toolkit/content/customElements.js",
   "browser/components/places/content/editBookmark.js",
   "browser/components/downloads/content/downloads.js",
   "browser/components/downloads/content/indicator.js",
-  // Via editMenuCommands.inc.xul
+  "toolkit/content/customElements.js",
   "toolkit/content/editMenuOverlay.js",
 ];
 
 const extraDefinitions = [
   // Via Components.utils, defineModuleGetter, defineLazyModuleGetters or
   // defineLazyScriptGetter (and map to
   // single) variable.
   {name: "XPCOMUtils", writable: false},
@@ -48,22 +46,22 @@ const extraDefinitions = [
 const MAPPINGS = {
   "printUtils.js": "toolkit/components/printing/content/printUtils.js",
   "panelUI.js": "browser/components/customizableui/content/panelUI.js",
   "viewSourceUtils.js":
     "toolkit/components/viewsource/content/viewSourceUtils.js",
 };
 
 const globalScriptsRegExp =
-  /<script type=\"application\/javascript\" src=\"(.*)\"\/>|^\s*"(.*?\.js)",$/;
+  /^\s*(?:Services.scriptloader.loadSubScript\(\"(.*?)\", this\);|"(.*?\.js)",)$/;
 
-function getGlobalScriptsIncludes() {
+function getGlobalScriptIncludes(scriptPath) {
   let fileData;
   try {
-    fileData = fs.readFileSync(helpers.globalScriptsPath, {encoding: "utf8"});
+    fileData = fs.readFileSync(scriptPath, {encoding: "utf8"});
   } catch (ex) {
     // The file isn't present, so this isn't an m-c repository.
     return null;
   }
 
   fileData = fileData.split("\n");
 
   let result = [];
@@ -84,19 +82,27 @@ function getGlobalScriptsIncludes() {
 
       result.push(sourceFile);
     }
   }
 
   return result;
 }
 
+function getGlobalScripts() {
+  let results = [];
+  for (let scriptPath of helpers.globalScriptPaths) {
+    results = results.concat(getGlobalScriptIncludes(scriptPath));
+  }
+  return results;
+}
+
 function getScriptGlobals() {
   let fileGlobals = [];
-  let scripts = getGlobalScriptsIncludes();
+  let scripts = getGlobalScripts();
   if (!scripts) {
     return [];
   }
 
   for (let script of scripts.concat(EXTRA_SCRIPTS)) {
     let fileName = path.join(rootDir, script);
     try {
       fileGlobals = fileGlobals.concat(globals.getGlobalsForFile(fileName));
@@ -117,15 +123,15 @@ function mapGlobals(fileGlobals) {
     globalObjects[global.name] = global.writable;
   }
   return globalObjects;
 }
 
 function getMozillaCentralItems() {
   return {
     globals: mapGlobals(getScriptGlobals()),
-    browserjsScripts: getGlobalScriptsIncludes().concat(EXTRA_SCRIPTS),
+    browserjsScripts: getGlobalScripts().concat(EXTRA_SCRIPTS),
   };
 }
 
 module.exports = helpers.isMozillaCentralBased() ?
  getMozillaCentralItems() :
  helpers.getSavedEnvironmentItems("browser-window");
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -727,23 +727,25 @@ module.exports = {
    * When ESLint is run from SublimeText, paths retrieved from
    * context.getFileName contain leading and trailing double-quote characters.
    * These characters need to be removed.
    */
   cleanUpPath(pathName) {
     return pathName.replace(/^"/, "").replace(/"$/, "");
   },
 
-  get globalScriptsPath() {
-    return path.join(this.rootDir, "browser",
-                     "base", "content", "global-scripts.inc");
+  get globalScriptPaths() {
+    return [
+      path.join(this.rootDir, "browser", "base", "content", "browser.xul"),
+      path.join(this.rootDir, "browser", "base", "content", "global-scripts.inc"),
+    ];
   },
 
   isMozillaCentralBased() {
-    return fs.existsSync(this.globalScriptsPath);
+    return fs.existsSync(this.globalScriptPaths[0]);
   },
 
   getSavedEnvironmentItems(environment) {
     return require("./environments/saved-globals.json").environments[environment];
   },
 
   getSavedRuleData(rule) {
     return require("./rules/saved-rules-data.json").rulesData[rule];