Bug 1245916: Add additional browser window scripts to eslint globals. r=felipe draft
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 05 Feb 2016 12:16:39 -0800
changeset 331374 94daff602b51d7ad57a24872d9eba9b304cf2da9
parent 331373 91a60ef0359ef53093fe197ed63dbc4e1a9f10a5
child 331375 a88116d149af76aa35ee0757b3b51b6f97646ebe
push id10969
push userdtownsend@mozilla.com
push dateTue, 16 Feb 2016 22:40:19 +0000
reviewersfelipe
bugs1245916
milestone47.0a1
Bug 1245916: Add additional browser window scripts to eslint globals. r=felipe This adds more of the scripts that browser.js relies on and also makes browser-chrome head files import the browser.js globals. The MOZ_JSDOWNLOADS block in contentAreaUtils only seems to hide a single function, I don't see any need to keep hiding that now we're on by default. MozReview-Commit-ID: 5zvF3JtJrZG
.eslintignore
browser/base/content/browser.js
testing/eslint-plugin-mozilla/lib/helpers.js
testing/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
toolkit/content/contentAreaUtils.js
toolkit/content/jar.mn
--- a/.eslintignore
+++ b/.eslintignore
@@ -182,17 +182,16 @@ toolkit/components/workerloader/tests/mo
 # Tests old non-star function generators
 toolkit/modules/tests/xpcshell/test_task.js
 
 # Not yet updated
 toolkit/components/osfile/**
 toolkit/components/passwordmgr/**
 
 # Uses preprocessing
-toolkit/content/contentAreaUtils.js
 toolkit/content/widgets/videocontrols.xml
 toolkit/content/widgets/wizard.xml
 toolkit/components/jsdownloads/src/DownloadIntegration.jsm
 toolkit/components/search/nsSearchService.js
 toolkit/components/url-classifier/**
 toolkit/components/urlformatter/nsURLFormatter.js
 toolkit/identity/FirefoxAccounts.jsm
 toolkit/modules/AppConstants.jsm
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -78,16 +78,17 @@ var gMultiProcessBrowser =
 var gAppInfo = Cc["@mozilla.org/xre/app-info;1"]
                   .getService(Ci.nsIXULAppInfo)
                   .QueryInterface(Ci.nsIXULRuntime);
 
 if (AppConstants.platform != "macosx") {
   var gEditUIVisible = true;
 }
 
+/*globals gBrowser, gNavToolbox, gURLBar, gNavigatorBundle*/
 [
   ["gBrowser",            "content"],
   ["gNavToolbox",         "navigator-toolbox"],
   ["gURLBar",             "urlbar"],
   ["gNavigatorBundle",    "bundle_browser"]
 ].forEach(function (elementGlobal) {
   var [name, id] = elementGlobal;
   window.__defineGetter__(name, function () {
--- a/testing/eslint-plugin-mozilla/lib/helpers.js
+++ b/testing/eslint-plugin-mozilla/lib/helpers.js
@@ -299,16 +299,32 @@ module.exports = {
           parent.type == "FunctionDeclaration") {
         return false;
       }
     }
     return true;
   },
 
   /**
+   * Check whether we might be in a test head file.
+   *
+   * @param  {RuleContext} scope
+   *         You should pass this from within a rule
+   *         e.g. helpers.getIsBrowserMochitest(this)
+   *
+   * @return {Boolean}
+   *         True or false
+   */
+  getIsHeadFile: function(scope) {
+    var pathAndFilename = scope.getFilename();
+
+    return /.*[\\/]head(_.+)?\.js$/.test(pathAndFilename);
+  },
+
+  /**
    * Check whether we are in a browser mochitest.
    *
    * @param  {RuleContext} scope
    *         You should pass this from within a rule
    *         e.g. helpers.getIsBrowserMochitest(this)
    *
    * @return {Boolean}
    *         True or false
--- a/testing/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
+++ b/testing/eslint-plugin-mozilla/lib/rules/import-browserjs-globals.js
@@ -13,16 +13,19 @@
 // -----------------------------------------------------------------------------
 
 var fs = require("fs");
 var path = require("path");
 var helpers = require("../helpers");
 var globals = require("../globals");
 
 const SCRIPTS = [
+  //"browser/base/content/nsContextMenu.js",
+  "toolkit/content/contentAreaUtils.js",
+  "browser/components/places/content/editBookmarkOverlay.js",
   "toolkit/components/printing/content/printUtils.js",
   "toolkit/content/viewZoomOverlay.js",
   "browser/components/places/content/browserPlacesViews.js",
   "browser/base/content/browser.js",
   "browser/components/downloads/content/downloads.js",
   "browser/components/downloads/content/indicator.js",
   "browser/components/customizableui/content/panelUI.js",
   "toolkit/obsolete/content/inlineSpellCheckUI.js",
@@ -42,23 +45,24 @@ const SCRIPTS = [
   "browser/base/content/browser-safebrowsing.js",
   "browser/base/content/browser-sidebar.js",
   "browser/base/content/browser-social.js",
   "browser/base/content/browser-syncui.js",
   "browser/base/content/browser-tabsintitlebar.js",
   "browser/base/content/browser-thumbnails.js",
   "browser/base/content/browser-trackingprotection.js",
   "browser/base/content/browser-data-submission-info-bar.js",
-  "browser/base/content/browser-fxaccounts.js",
+  "browser/base/content/browser-fxaccounts.js"
 ];
 
 module.exports = function(context) {
   return {
     Program: function(node) {
-      if (!helpers.getIsBrowserMochitest(this)) {
+      if (!helpers.getIsBrowserMochitest(this) &&
+          !helpers.getIsHeadFile(this)) {
         return;
       }
 
       let root = helpers.getRootDir(context);
       for (let script of SCRIPTS) {
         let fileName = path.join(root, script);
         try {
           let newGlobals = globals.getGlobalsForFile(fileName);
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -1,12 +1,11 @@
-# -*- 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/.
+/* 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/. */
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 XPCOMUtils.defineLazyModuleGetter(this, "BrowserUtils",
                                   "resource://gre/modules/BrowserUtils.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Downloads",
                                   "resource://gre/modules/Downloads.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "DownloadLastDir",
@@ -20,16 +19,18 @@ XPCOMUtils.defineLazyModuleGetter(this, 
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
                                   "resource://gre/modules/Promise.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Services",
                                   "resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Task",
                                   "resource://gre/modules/Task.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "Deprecated",
                                   "resource://gre/modules/Deprecated.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "AppConstants",
+                                  "resource://gre/modules/AppConstants.jsm");
 
 var ContentAreaUtils = {
 
   // this is for backwards compatibility.
   get ioService() {
     return Services.io;
   },
 
@@ -346,17 +347,17 @@ XPCOMUtils.defineConstant(this, "kSaveAs
  *    aShouldBypassCache and aReferrer. The source, the save name and the save
  *    mode are the ones determined previously.
  *
  * @param aURL
  *        The String representation of the URL of the document being saved
  * @param aDocument
  *        The document to be saved
  * @param aDefaultFileName
- *        The caller-provided suggested filename if we don't 
+ *        The caller-provided suggested filename if we don't
  *        find a better one
  * @param aContentDisposition
  *        The caller-provided content-disposition header to use.
  * @param aContentType
  *        The caller-provided content-type to use
  * @param aShouldBypassCache
  *        If true, the document will always be refetched from the server
  * @param aFilePickerTitleKey
@@ -588,17 +589,17 @@ function AutoChosen(aFileAutoChosen, aUr
   this.file = aFileAutoChosen;
   this.uri  = aUriAutoChosen;
 }
 
 /**
  * Structure for holding info about a URL and the target filename it should be
  * saved to. This structure is populated by initFileInfo(...).
  * @param aSuggestedFileName This is used by initFileInfo(...) when it
- *        cannot 'discover' the filename from the url 
+ *        cannot 'discover' the filename from the url
  * @param aFileName The target filename
  * @param aFileBaseName The filename without the file extension
  * @param aFileExt The extension of the filename
  * @param aUri An nsIURI object for the url that is being saved
  */
 function FileInfo(aSuggestedFileName, aFileName, aFileBaseName, aFileExt, aUri) {
   this.suggestedFileName = aSuggestedFileName;
   this.fileName = aFileName;
@@ -647,40 +648,40 @@ function initFileInfo(aFI, aURL, aURLCha
     } else {
       aFI.fileExt = getDefaultExtension(aFI.fileName, aFI.uri, aContentType);
       aFI.fileBaseName = getFileBaseName(aFI.fileName);
     }
   } catch (e) {
   }
 }
 
-/** 
+/**
  * Given the Filepicker Parameters (aFpP), show the file picker dialog,
  * prompting the user to confirm (or change) the fileName.
  * @param aFpP
  *        A structure (see definition in internalSave(...) method)
  *        containing all the data used within this method.
  * @param aSkipPrompt
  *        If true, attempt to save the file automatically to the user's default
  *        download directory, thus skipping the explicit prompt for a file name,
  *        but only if the associated preference is set.
  *        If false, don't save the file automatically to the user's
  *        default download directory, even if the associated preference
  *        is set, but ask for the target explicitly.
  * @param aRelatedURI
  *        An nsIURI associated with the download. The last used
- *        directory of the picker is retrieved from/stored in the 
+ *        directory of the picker is retrieved from/stored in the
  *        Content Pref Service using this URI.
  * @return Promise
  * @resolve a boolean. When true, it indicates that the file picker dialog
  *          is accepted.
  */
 function promiseTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRelatedURI)
 {
-  return Task.spawn(function() {
+  return Task.spawn(function*() {
     let downloadLastDir = new DownloadLastDir(window);
     let prefBranch = Services.prefs.getBranch("browser.download.");
     let useDownloadDir = prefBranch.getBoolPref("useDownloadDir");
 
     if (!aSkipPrompt)
       useDownloadDir = false;
 
     // Default to the user's default downloads directory configured
@@ -688,17 +689,17 @@ function promiseTargetFile(aFpP, /* opti
     let dirPath = yield Downloads.getPreferredDownloadsDirectory();
     let dirExists = yield OS.File.exists(dirPath);
     let dir = new FileUtils.File(dirPath);
 
     if (useDownloadDir && dirExists) {
       dir.append(getNormalizedLeafName(aFpP.fileInfo.fileName,
                                        aFpP.fileInfo.fileExt));
       aFpP.file = uniqueFile(dir);
-      throw new Task.Result(true);
+      return true;
     }
 
     // We must prompt for the file name explicitly.
     // If we must prompt because we were asked to...
     let deferred = Promise.defer();
     if (useDownloadDir) {
       // Keep async behavior in both branches
       Services.tm.mainThread.dispatch(function() {
@@ -743,32 +744,32 @@ function promiseTargetFile(aFpP, /* opti
     }
 
     let deferComplete = Promise.defer();
     fp.open(function(aResult) {
       deferComplete.resolve(aResult);
     });
     let result = yield deferComplete.promise;
     if (result == Components.interfaces.nsIFilePicker.returnCancel || !fp.file) {
-      throw new Task.Result(false);
+      return false;
     }
 
     if (aFpP.saveMode != SAVEMODE_FILEONLY)
       prefBranch.setIntPref("save_converter_index", fp.filterIndex);
 
     // Do not store the last save directory as a pref inside the private browsing mode
     downloadLastDir.setFile(aRelatedURI, fp.file.parent);
 
     fp.file.leafName = validateFileName(fp.file.leafName);
 
     aFpP.saveAsType = fp.filterIndex;
     aFpP.file = fp.file;
     aFpP.fileURL = fp.fileURL;
 
-    throw new Task.Result(true);
+    return true;
   });
 }
 
 // Since we're automatically downloading, we don't get the file picker's
 // logic to check for existing files, so we need to do that here.
 //
 // Note - this code is identical to that in
 //   mozilla/toolkit/mozapps/downloads/src/nsHelperAppDlg.js.in
@@ -790,17 +791,16 @@ function uniqueFile(aLocalFile)
     else {
       // replace the last (n) in the filename with (n+1)
       aLocalFile.leafName = aLocalFile.leafName.replace(/^(.*\()\d+\)/, "$1" + (collisionCount + 1) + ")");
     }
   }
   return aLocalFile;
 }
 
-#ifdef MOZ_JSDOWNLOADS
 /**
  * Download a URL using the new jsdownloads API.
  *
  * @param aURL
  *        the url to download
  * @param [optional] aFileName
  *        the destination file name, if omitted will be obtained from the url.
  * @param aInitiatingDocument
@@ -836,17 +836,16 @@ function DownloadURL(aURL, aFileName, aI
     download.tryToKeepPartialData = true;
     download.start();
 
     // Add the download to the list, allowing it to be managed.
     let list = yield Downloads.getList(Downloads.ALL);
     list.add(download);
   }).then(null, Components.utils.reportError);
 }
-#endif
 
 // We have no DOM, and can only save the URL as is.
 const SAVEMODE_FILEONLY      = 0x00;
 XPCOMUtils.defineConstant(this, "SAVEMODE_FILEONLY", SAVEMODE_FILEONLY);
 // We have a DOM and can save as complete.
 const SAVEMODE_COMPLETE_DOM  = 0x01;
 XPCOMUtils.defineConstant(this, "SAVEMODE_COMPLETE_DOM", SAVEMODE_COMPLETE_DOM);
 // We have a DOM which we can serialize as text.
@@ -1152,20 +1151,20 @@ function validateFileName(aFileName)
   return aFileName.replace(re, "_");
 }
 
 function getNormalizedLeafName(aFile, aDefaultExtension)
 {
   if (!aDefaultExtension)
     return aFile;
 
-#ifdef XP_WIN
-  // Remove trailing dots and spaces on windows
-  aFile = aFile.replace(/[\s.]+$/, "");
-#endif
+  if (AppConstants.platform == "win") {
+    // Remove trailing dots and spaces on windows
+    aFile = aFile.replace(/[\s.]+$/, "");
+  }
 
   // Remove leading dots
   aFile = aFile.replace(/^\.+/, "");
 
   // Fix up the file name we're saving to to include the default extension
   var i = aFile.lastIndexOf(".");
   if (aFile.substr(i + 1) != aDefaultExtension)
     return aFile + "." + aDefaultExtension;
--- a/toolkit/content/jar.mn
+++ b/toolkit/content/jar.mn
@@ -38,17 +38,17 @@ toolkit.jar:
    content/global/aboutTelemetry.xhtml
    content/global/aboutTelemetry.css
    content/global/directionDetector.html
    content/global/plugins.html
    content/global/plugins.css
    content/global/browser-child.js
    content/global/browser-content.js
 *   content/global/buildconfig.html
-*  content/global/contentAreaUtils.js
+   content/global/contentAreaUtils.js
 #ifndef MOZ_FENNEC
    content/global/customizeToolbar.css
    content/global/customizeToolbar.js
    content/global/customizeToolbar.xul
 #endif
    content/global/devicestorage.properties
 #ifndef MOZ_FENNEC
    content/global/editMenuOverlay.js