Bug 1358080 - add logic to get inner window id to InsecurePasswordUtils.jsm;r=MattN draft
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 20 Apr 2017 12:35:13 +0200
changeset 569308 a2b081159611a8852f6676412b801eaed7786b93
parent 568867 093a8b181555711d1a6f73104047d049c9655efd
child 626178 9d99d0524c58ee78597e45d081e3ef387b98058c
push id56142
push userjdescottes@mozilla.com
push dateThu, 27 Apr 2017 10:15:37 +0000
reviewersMattN
bugs1358080
milestone55.0a1
Bug 1358080 - add logic to get inner window id to InsecurePasswordUtils.jsm;r=MattN InsecurePasswordUtils.jsm used to rely on a devtools util to get the innerWindowId of window objects. As devtools are moving out of mozilla-central, this code needs to be extracted and the dependency should be removed. MozReview-Commit-ID: 8rI3Lxu16h5
toolkit/components/passwordmgr/InsecurePasswordUtils.jsm
--- a/toolkit/components/passwordmgr/InsecurePasswordUtils.jsm
+++ b/toolkit/components/passwordmgr/InsecurePasswordUtils.jsm
@@ -5,27 +5,22 @@
 this.EXPORTED_SYMBOLS = [ "InsecurePasswordUtils" ];
 
 const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
 const STRINGS_URI = "chrome://global/locale/security/security.properties";
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
-XPCOMUtils.defineLazyModuleGetter(this, "devtools",
-                                  "resource://devtools/shared/Loader.jsm");
 XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
                                    "@mozilla.org/contentsecuritymanager;1",
                                    "nsIContentSecurityManager");
 XPCOMUtils.defineLazyServiceGetter(this, "gScriptSecurityManager",
                                    "@mozilla.org/scriptsecuritymanager;1",
                                    "nsIScriptSecurityManager");
-XPCOMUtils.defineLazyGetter(this, "WebConsoleUtils", () => {
-  return this.devtools.require("devtools/server/actors/utils/webconsole-utils").WebConsoleUtils;
-});
 
 /*
  * A module that provides utility functions for form security.
  *
  * Note:
  *  This module uses isSecureContextIfOpenerIgnored instead of isSecureContext.
  *
  *  We don't want to expose JavaScript APIs in a non-Secure Context even if
@@ -34,18 +29,31 @@ XPCOMUtils.defineLazyGetter(this, "WebCo
  *  an insecure opener to gain access to Secure Context-only APIs. However,
  *  in the case of form fields such as password fields we don't need to worry
  *  about whether the opener is secure or not. In fact to flag a password
  *  field as insecure in such circumstances would unnecessarily confuse our
  *  users.
  */
 this.InsecurePasswordUtils = {
   _formRootsWarned: new WeakMap(),
+
+  /**
+   * Gets the ID of the inner window of this DOM window.
+   *
+   * @param nsIDOMWindow window
+   * @return integer
+   *         Inner ID for the given window.
+   */
+  _getInnerWindowId(window) {
+      return window.QueryInterface(Ci.nsIInterfaceRequestor)
+               .getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID;
+  },
+
   _sendWebConsoleMessage(messageTag, domDoc) {
-    let windowId = WebConsoleUtils.getInnerWindowId(domDoc.defaultView);
+    let windowId = this._getInnerWindowId(domDoc.defaultView);
     let category = "Insecure Password Field";
     // All web console messages are warnings for now.
     let flag = Ci.nsIScriptError.warningFlag;
     let bundle = Services.strings.createBundle(STRINGS_URI);
     let message = bundle.GetStringFromName(messageTag);
     let consoleMsg = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
     consoleMsg.initWithWindowID(message, domDoc.location.href, 0, 0, 0, flag, category, windowId);