Bug 1312690: Add some stupid microoptimizations. r?aswan draft
authorKris Maglione <maglione.k@gmail.com>
Tue, 01 Nov 2016 16:56:21 -0700
changeset 432819 559bb54fb330faf8bfa6b03b01be509e86c3eab9
parent 432818 a8b91bd31af109b3ac109b8a9125e0dc42b05153
child 535764 fc2e7ad19524acd0fd868e2d89ef02b1eb830cee
push id34435
push usermaglione.k@gmail.com
push dateWed, 02 Nov 2016 20:58:46 +0000
reviewersaswan
bugs1312690
milestone52.0a1
Bug 1312690: Add some stupid microoptimizations. r?aswan MozReview-Commit-ID: 4qoNuG2k0KS
toolkit/components/extensions/ExtensionContent.jsm
toolkit/components/extensions/ExtensionManagement.jsm
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -205,21 +205,21 @@ Script.prototype = {
    *        change.
    * @param {string} when
    *        The document's current load state, or if triggered by a
    *        document state change, the new document state that triggered
    *        the injection.
    */
   tryInject(window, sandbox, shouldRun, when) {
     if (shouldRun("document_start")) {
-      let winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
-                           .getInterface(Ci.nsIDOMWindowUtils);
-
       let {cssURLs} = this;
       if (cssURLs.length > 0) {
+        let winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor)
+                             .getInterface(Ci.nsIDOMWindowUtils);
+
         let method = this.remove_css ? winUtils.removeSheetUsingURIString : winUtils.loadSheetUsingURIString;
         for (let url of cssURLs) {
           runSafeSyncWithoutClone(method, url, winUtils.AUTHOR_SHEET);
         }
 
         this.deferred.resolve();
       }
     }
--- a/toolkit/components/extensions/ExtensionManagement.jsm
+++ b/toolkit/components/extensions/ExtensionManagement.jsm
@@ -234,18 +234,17 @@ var Service = {
 
 // API Levels Helpers
 
 // Find the add-on associated with this document via the
 // principal's originAttributes. This value is computed by
 // extensionURIToAddonID, which ensures that we don't inject our
 // API into webAccessibleResources or remote web pages.
 function getAddonIdForWindow(window) {
-  let principal = window.document.nodePrincipal;
-  return principal.originAttributes.addonId;
+  return Cu.getObjectPrincipal(window).originAttributes.addonId;
 }
 
 const API_LEVELS = Object.freeze({
   NO_PRIVILEGES: 0,
   CONTENTSCRIPT_PRIVILEGES: 1,
   FULL_PRIVILEGES: 2,
 });