Bug 1491561 - Remove the XPCOM registrations for LoadContext; r=bzbarsky
authorEhsan Akhgari <ehsan@mozilla.com>
Sat, 15 Sep 2018 11:38:45 -0400
changeset 436890 9bc9a1e07a53
parent 436889 6dcfa4ae78c3
child 436891 3ab80aaa53f9
push id34664
push useraciure@mozilla.com
push dateTue, 18 Sep 2018 07:43:05 +0000
treeherdermozilla-central@85b4d2bf888a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1491561
milestone64.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 1491561 - Remove the XPCOM registrations for LoadContext; r=bzbarsky Differential Revision: https://phabricator.services.mozilla.com/D5945
docshell/base/LoadContext.cpp
docshell/base/LoadContext.h
docshell/build/nsDocShellCID.h
docshell/build/nsDocShellModule.cpp
image/test/unit/test_private_channel.js
js/xpconnect/idl/xpccomponents.idl
js/xpconnect/src/XPCComponents.cpp
netwerk/test/unit/test_bug826063.js
netwerk/test/unit/test_cacheflags.js
toolkit/components/contentprefs/ContentPrefServiceParent.jsm
toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html
toolkit/components/contentprefs/tests/unit_cps2/head.js
toolkit/mozapps/downloads/DownloadLastDir.jsm
--- a/docshell/base/LoadContext.cpp
+++ b/docshell/base/LoadContext.cpp
@@ -196,39 +196,32 @@ LoadContext::GetInterface(const nsIID& a
     *aResult = static_cast<nsILoadContext*>(this);
     NS_ADDREF_THIS();
     return NS_OK;
   }
 
   return NS_NOINTERFACE;
 }
 
-static nsresult
-CreateTestInstance(bool aPrivate, nsISupports *aOuter, REFNSIID aIID, void **aResult)
+static already_AddRefed<nsILoadContext>
+CreateInstance(bool aPrivate)
 {
-  // Shamelessly modified from NS_GENERIC_FACTORY_CONSTRUCTOR
-  *aResult = nullptr;
-
-  if (aOuter) {
-    return NS_ERROR_NO_AGGREGATION;
-  }
-
   OriginAttributes oa;
   oa.mPrivateBrowsingId = aPrivate ? 1 : 0;
 
-  RefPtr<LoadContext> lc = new LoadContext(oa);
+  nsCOMPtr<nsILoadContext> lc = new LoadContext(oa);
 
-  return lc->QueryInterface(aIID, aResult);
+  return lc.forget();
 }
 
-nsresult
-CreateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult)
+already_AddRefed<nsILoadContext>
+CreateLoadContext()
 {
-  return CreateTestInstance(false, aOuter, aIID, aResult);
+  return CreateInstance(false);
 }
 
-nsresult
-CreatePrivateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult)
+already_AddRefed<nsILoadContext>
+CreatePrivateLoadContext()
 {
-  return CreateTestInstance(true, aOuter, aIID, aResult);
+  return CreateInstance(true);
 }
 
 } // namespace mozilla
--- a/docshell/base/LoadContext.h
+++ b/docshell/base/LoadContext.h
@@ -117,14 +117,14 @@ private:
   bool mUseRemoteTabs;
   bool mUseTrackingProtection;
   OriginAttributes mOriginAttributes;
 #ifdef DEBUG
   bool mIsNotNull;
 #endif
 };
 
-nsresult CreateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult);
-nsresult CreatePrivateTestLoadContext(nsISupports *aOuter, REFNSIID aIID, void **aResult);
+already_AddRefed<nsILoadContext> CreateLoadContext();
+already_AddRefed<nsILoadContext> CreatePrivateLoadContext();
 
 } // namespace mozilla
 
 #endif // LoadContext_h
--- a/docshell/build/nsDocShellCID.h
+++ b/docshell/build/nsDocShellCID.h
@@ -71,21 +71,9 @@
  * An observer service topic that can be listened to to catch destruction
  * of chrome browsing areas (both toplevel ones and subframes).  The
  * subject of the notification will be the nsIWebNavigation being
  * destroyed.  At this time the additional data wstring is not defined
  * to be anything in particular.
  */
 #define NS_CHROME_WEBNAVIGATION_DESTROY "chrome-webnavigation-destroy"
 
-/**
- * A way to create nsILoadContexts from script
- */
-#define NS_LOADCONTEXT_CONTRACTID "@mozilla.org/loadcontext;1"
-#define NS_LOADCONTEXT_CID \
-    { 0xd0181d36, 0x19a2, 0x4347, \
-      { 0x8f, 0x00, 0x04, 0x13, 0xa0, 0x70, 0xaa, 0xdc } }
-#define NS_PRIVATELOADCONTEXT_CONTRACTID "@mozilla.org/privateloadcontext;1"
-#define NS_PRIVATELOADCONTEXT_CID \
-    { 0x01629810, 0xd8ae, 0x4455, \
-      { 0x86, 0xe8, 0x69, 0x68, 0x87, 0xd1, 0xf7, 0x8d } }
-
 #endif // nsDocShellCID_h__
--- a/docshell/build/nsDocShellModule.cpp
+++ b/docshell/build/nsDocShellModule.cpp
@@ -32,19 +32,16 @@
 #include "nsExternalURLHandlerService.h"
 #endif
 
 // session history
 #include "nsSHEntry.h"
 #include "nsSHEntryShared.h"
 #include "nsSHistory.h"
 
-// LoadContexts (used for testing)
-#include "LoadContext.h"
-
 using mozilla::dom::ContentHandlerService;
 
 static bool gInitialized = false;
 
 // The one time initialization for this module
 static nsresult
 Initialize()
 {
@@ -112,18 +109,16 @@ NS_DEFINE_NAMED_CID(NS_OSPERMISSIONREQUE
 #ifdef MOZ_ENABLE_DBUS
 NS_DEFINE_NAMED_CID(NS_DBUSHANDLERAPP_CID);
 #endif
 #if defined(MOZ_WIDGET_ANDROID)
 NS_DEFINE_NAMED_CID(NS_EXTERNALURLHANDLERSERVICE_CID);
 #endif
 NS_DEFINE_NAMED_CID(NS_SHENTRY_CID);
 NS_DEFINE_NAMED_CID(NS_CONTENTHANDLERSERVICE_CID);
-NS_DEFINE_NAMED_CID(NS_LOADCONTEXT_CID);
-NS_DEFINE_NAMED_CID(NS_PRIVATELOADCONTEXT_CID);
 
 const mozilla::Module::CIDEntry kDocShellCIDs[] = {
   { &kNS_DOCSHELL_CID, false, nullptr, nsDocShellConstructor },
   { &kNS_DEFAULTURIFIXUP_CID, false, nullptr, nsDefaultURIFixupConstructor },
   { &kNS_WEBNAVIGATION_INFO_CID, false, nullptr, nsWebNavigationInfoConstructor },
   { &kNS_ABOUT_REDIRECTOR_MODULE_CID, false, nullptr, nsAboutRedirector::Create },
   { &kNS_URI_LOADER_CID, false, nullptr, nsURILoaderConstructor },
   { &kNS_DOCUMENTLOADER_SERVICE_CID, false, nullptr, nsDocLoaderConstructor },
@@ -137,18 +132,16 @@ const mozilla::Module::CIDEntry kDocShel
   { &kNS_LOCALHANDLERAPP_CID, false, nullptr, PlatformLocalHandlerApp_tConstructor },
 #ifdef MOZ_ENABLE_DBUS
   { &kNS_DBUSHANDLERAPP_CID, false, nullptr, nsDBusHandlerAppConstructor },
 #endif
 #if defined(MOZ_WIDGET_ANDROID)
   { &kNS_EXTERNALURLHANDLERSERVICE_CID, false, nullptr, nsExternalURLHandlerServiceConstructor },
 #endif
   { &kNS_SHENTRY_CID, false, nullptr, nsSHEntryConstructor },
-  { &kNS_LOADCONTEXT_CID, false, nullptr, mozilla::CreateTestLoadContext },
-  { &kNS_PRIVATELOADCONTEXT_CID, false, nullptr, mozilla::CreatePrivateTestLoadContext },
   { nullptr }
 };
 
 const mozilla::Module::ContractIDEntry kDocShellContracts[] = {
   { "@mozilla.org/docshell;1", &kNS_DOCSHELL_CID },
   { NS_URIFIXUP_CONTRACTID, &kNS_DEFAULTURIFIXUP_CID },
   { NS_WEBNAVIGATION_INFO_CONTRACTID, &kNS_WEBNAVIGATION_INFO_CID },
   { NS_ABOUT_MODULE_CONTRACTID_PREFIX "about", &kNS_ABOUT_REDIRECTOR_MODULE_CID },
@@ -192,18 +185,16 @@ const mozilla::Module::ContractIDEntry k
   { NS_LOCALHANDLERAPP_CONTRACTID, &kNS_LOCALHANDLERAPP_CID },
 #ifdef MOZ_ENABLE_DBUS
   { NS_DBUSHANDLERAPP_CONTRACTID, &kNS_DBUSHANDLERAPP_CID },
 #endif
 #if defined(MOZ_WIDGET_ANDROID)
   { NS_EXTERNALURLHANDLERSERVICE_CONTRACTID, &kNS_EXTERNALURLHANDLERSERVICE_CID },
 #endif
   { NS_SHENTRY_CONTRACTID, &kNS_SHENTRY_CID },
-  { NS_LOADCONTEXT_CONTRACTID, &kNS_LOADCONTEXT_CID },
-  { NS_PRIVATELOADCONTEXT_CONTRACTID, &kNS_PRIVATELOADCONTEXT_CID },
   { NS_OSPERMISSIONREQUEST_CONTRACTID, &kNS_OSPERMISSIONREQUEST_CID, mozilla::Module::MAIN_PROCESS_ONLY },
   { nullptr }
 };
 
 static const mozilla::Module kDocShellModule = {
   mozilla::Module::kVersion,
   kDocShellCIDs,
   kDocShellContracts,
--- a/image/test/unit/test_private_channel.js
+++ b/image/test/unit/test_private_channel.js
@@ -10,18 +10,18 @@ load('image_load_helpers.js');
 
 var gHits = 0;
 
 var gIoService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
 var gPublicLoader = Cc["@mozilla.org/image/loader;1"].createInstance(Ci.imgILoader);
 var gPrivateLoader = Cc["@mozilla.org/image/loader;1"].createInstance(Ci.imgILoader);
 gPrivateLoader.QueryInterface(Ci.imgICache).respectPrivacyNotifications();
 
-var nonPrivateLoadContext = Cc["@mozilla.org/loadcontext;1"].createInstance(Ci.nsILoadContext);
-var privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].createInstance(Ci.nsILoadContext);
+var nonPrivateLoadContext = Cu.createLoadContext();
+var privateLoadContext = Cu.createPrivateLoadContext();
 
 function imageHandler(metadata, response) {
   gHits++;
   response.setHeader("Cache-Control", "max-age=10000", false);
   response.setStatusLine(metadata.httpVersion, 200, "OK");
   response.setHeader("Content-Type", "image/png", false);
   var body = "iVBORw0KGgoAAAANSUhEUgAAAAMAAAADCAIAAADZSiLoAAAAEUlEQVQImWP4z8AAQTAamQkAhpcI+DeMzFcAAAAASUVORK5CYII=";
   response.bodyOutputStream.write(body, body.length);
--- a/js/xpconnect/idl/xpccomponents.idl
+++ b/js/xpconnect/idl/xpccomponents.idl
@@ -11,16 +11,17 @@
 
 interface xpcIJSWeakReference;
 interface nsIClassInfo;
 interface nsICommandParams;
 interface nsIComponentManager;
 interface nsICycleCollectorListener;
 interface nsIEditorSpellCheck;
 interface nsIFile;
+interface nsILoadContext;
 interface nsIURI;
 interface nsIJSCID;
 interface nsIJSIID;
 interface nsIPrincipal;
 interface nsIStackFrame;
 webidl Element;
 
 /**
@@ -720,18 +721,21 @@ interface nsIXPCComponents_Utils : nsISu
     void recordReplayDirective(in long directive);
 
     /* Create a spellchecker object. */
     nsIEditorSpellCheck createSpellChecker();
 
     /* Create a commandline object. */
     nsISupports createCommandLine();
 
-    /* Create a command params object. */
-    nsICommandParams createCommandParams();
+    /* Create a loadcontext object. */
+    nsILoadContext createLoadContext();
+
+    /* Create a private loadcontext object. */
+    nsILoadContext createPrivateLoadContext();
 };
 
 /**
 * Interface for the 'Components' object.
 *
 * The first interface contains things that are available to non-chrome XBL code
 * that runs in a scope with an ExpandedPrincipal. The second interface
 * includes members that are only exposed to chrome.
--- a/js/xpconnect/src/XPCComponents.cpp
+++ b/js/xpconnect/src/XPCComponents.cpp
@@ -15,16 +15,17 @@
 #include "nsContentUtils.h"
 #include "nsCycleCollector.h"
 #include "jsfriendapi.h"
 #include "js/CharacterEncoding.h"
 #include "js/SavedFrameAPI.h"
 #include "js/StructuredClone.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
+#include "mozilla/LoadContext.h"
 #include "mozilla/Preferences.h"
 #include "nsJSEnvironment.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/ResultExtensions.h"
 #include "mozilla/URLPreloader.h"
 #include "mozilla/dom/DOMException.h"
 #include "mozilla/dom/DOMExceptionBinding.h"
 #include "mozilla/dom/BindingUtils.h"
@@ -3228,21 +3229,30 @@ nsXPCComponents_Utils::CreateCommandLine
 {
     NS_ENSURE_ARG_POINTER(aCommandLine);
     nsCOMPtr<nsISupports> commandLine = new nsCommandLine();
     commandLine.forget(aCommandLine);
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsXPCComponents_Utils::CreateCommandParams(nsICommandParams** aCommandParams)
+nsXPCComponents_Utils::CreateLoadContext(nsILoadContext** aLoadContext)
 {
-    NS_ENSURE_ARG_POINTER(aCommandParams);
-    nsCOMPtr<nsICommandParams> commandParams = new nsCommandParams();
-    commandParams.forget(aCommandParams);
+    NS_ENSURE_ARG_POINTER(aLoadContext);
+    nsCOMPtr<nsILoadContext> loadContext = CreateLoadContext();
+    loadContext.forget(aLoadContext);
+    return NS_OK;
+}
+
+NS_IMETHODIMP
+nsXPCComponents_Utils::CreatePrivateLoadContext(nsILoadContext** aLoadContext)
+{
+    NS_ENSURE_ARG_POINTER(aLoadContext);
+    nsCOMPtr<nsILoadContext> loadContext = CreatePrivateLoadContext();
+    loadContext.forget(aLoadContext);
     return NS_OK;
 }
 
 /***************************************************************************/
 /***************************************************************************/
 /***************************************************************************/
 
 
--- a/netwerk/test/unit/test_bug826063.js
+++ b/netwerk/test/unit/test_bug826063.js
@@ -11,19 +11,16 @@ ChromeUtils.import("resource://gre/modul
 
 
 var URIs = [
   "http://example.org",
   "https://example.org",
   "ftp://example.org"
   ];
 
-let LoadContext = Components.Constructor("@mozilla.org/loadcontext;1");
-let PrivateLoadContext = Components.Constructor("@mozilla.org/privateloadcontext;1");
-
 function* getChannels() {
   for (let u of URIs) {
     yield NetUtil.newChannel({
       uri: u,
       loadUsingSystemPrincipal: true
     });
   }
 }
@@ -65,29 +62,29 @@ add_test(function test_setPrivate_regula
   }
   run_next_test();
 });
 
 /**
  * Load context mandates private mode
  */
 add_test(function test_LoadContextPrivate() {
-  let ctx = new PrivateLoadContext();
+  let ctx = Cu.createPrivateLoadContext();
   for (let c of getChannels()) {
     c.notificationCallbacks = ctx;
     checkPrivate(c, true);
   }
   run_next_test();
 });
 
 /**
  * Load context mandates regular mode
  */
 add_test(function test_LoadContextRegular() {
-  let ctx = new LoadContext();
+  let ctx = Cu.createLoadContext();
   for (let c of getChannels()) {
     c.notificationCallbacks = ctx;
     checkPrivate(c, false);
   }
   run_next_test();
 });
 
 
--- a/netwerk/test/unit/test_cacheflags.js
+++ b/netwerk/test/unit/test_cacheflags.js
@@ -12,17 +12,17 @@ var httpsBase = "http://localhost:4445";
 var shortexpPath = "/shortexp" + suffix;
 var longexpPath = "/longexp/" + suffix;
 var longexp2Path = "/longexp/2/" + suffix;
 var nocachePath = "/nocache" + suffix;
 var nostorePath = "/nostore" + suffix;
 var test410Path = "/test410" + suffix;
 var test404Path = "/test404" + suffix;
 
-var PrivateBrowsingLoadContext = Cc["@mozilla.org/privateloadcontext;1"].createInstance(Ci.nsILoadContext);
+var PrivateBrowsingLoadContext = Cu.createPrivateLoadContext();
 
 function make_channel(url, flags, usePrivateBrowsing) {
   var securityFlags = Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
 
   var uri = Services.io.newURI(url);
   var principal = Services.scriptSecurityManager.createCodebasePrincipal(uri,
     { privateBrowsingId : usePrivateBrowsing ? 1 : 0 });
 
--- a/toolkit/components/contentprefs/ContentPrefServiceParent.jsm
+++ b/toolkit/components/contentprefs/ContentPrefServiceParent.jsm
@@ -7,20 +7,18 @@
 
 var EXPORTED_SYMBOLS = [ "ContentPrefServiceParent" ];
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 
 ChromeUtils.defineModuleGetter(this, "_methodsCallableFromChild",
                                "resource://gre/modules/ContentPrefUtils.jsm");
 
-let loadContext = Cc["@mozilla.org/loadcontext;1"].
-                    createInstance(Ci.nsILoadContext);
-let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
-                           createInstance(Ci.nsILoadContext);
+let loadContext = Cu.createLoadContext();
+let privateLoadContext = Cu.createPrivateLoadContext();
 
 function contextArg(context) {
   return (context && context.usePrivateBrowsing) ?
            privateLoadContext :
            loadContext;
 }
 
 var ContentPrefServiceParent = {
--- a/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html
+++ b/toolkit/components/contentprefs/tests/mochitest/test_remoteContentPrefs.html
@@ -8,20 +8,19 @@
   <script type="text/javascript" src="/tests/SimpleTest/AddTask.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 </head>
 <body>
 
   <script type="application/javascript">
     "use strict";
 
-    let loadContext = SpecialPowers.Cc["@mozilla.org/loadcontext;1"].
-                        createInstance(SpecialPowers.Ci.nsILoadContext);
-    let privateLoadContext = SpecialPowers.Cc["@mozilla.org/privateloadcontext;1"].
-                        createInstance(SpecialPowers.Ci.nsILoadContext);
+    let Cu = SpecialPowers.Cu;
+    let loadContext = Cu.createLoadContext();
+    let privateLoadContext = Cu.createPrivateLoadContext();
 
     SimpleTest.waitForExplicitFinish();
 
     const childFrameURL =
       "data:text/html,<!DOCTYPE HTML><html><body></body></html>";
 
     function childFrameScript(isFramePrivate) {
       "use strict";
@@ -186,18 +185,17 @@
           },
           onContentPrefRemoved(group, name, isPrivate) {
             observed.reject("got unexpected notification");
           },
         };
 
         cps.addObserverForName("test", prefObserver);
 
-        let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
-                            createInstance(Ci.nsILoadContext);
+        let privateLoadContext = Cu.createPrivateLoadContext();
         cps.set("http://mochi.test", "test", 42, privateLoadContext);
         let event = await observed.promise;
         tester.is(event.name, "test", "got the right event");
         tester.is(event.isPrivate, true, "the event was for an isPrivate pref");
 
         mm.sendAsyncMessage("testRemoteContentPrefs:getPref",
                             { group: "http://mochi.test", name: "test" });
 
--- a/toolkit/components/contentprefs/tests/unit_cps2/head.js
+++ b/toolkit/components/contentprefs/tests/unit_cps2/head.js
@@ -1,18 +1,16 @@
 /* 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/. */
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-let loadContext = Cc["@mozilla.org/loadcontext;1"].
-                    createInstance(Ci.nsILoadContext);
-let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
-                           createInstance(Ci.nsILoadContext);
+let loadContext = Cu.createLoadContext();
+let privateLoadContext = Cu.createPrivateLoadContext();
 
 // There has to be a profile directory before the CPS service is gotten.
 do_get_profile();
 let cps = Cc["@mozilla.org/content-pref/service;1"].
           getService(Ci.nsIContentPrefService2);
 
 function makeCallback(resolve, callbacks, success = null) {
   callbacks = callbacks || {};
--- a/toolkit/mozapps/downloads/DownloadLastDir.jsm
+++ b/toolkit/mozapps/downloads/DownloadLastDir.jsm
@@ -27,20 +27,18 @@
 const LAST_DIR_PREF = "browser.download.lastDir";
 const SAVE_PER_SITE_PREF = LAST_DIR_PREF + ".savePerSite";
 const nsIFile = Ci.nsIFile;
 
 var EXPORTED_SYMBOLS = [ "DownloadLastDir" ];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-let nonPrivateLoadContext = Cc["@mozilla.org/loadcontext;1"].
-                              createInstance(Ci.nsILoadContext);
-let privateLoadContext = Cc["@mozilla.org/privateloadcontext;1"].
-                              createInstance(Ci.nsILoadContext);
+let nonPrivateLoadContext = Cu.createLoadContext();
+let privateLoadContext = Cu.createPrivateLoadContext();
 
 var observer = {
   QueryInterface: ChromeUtils.generateQI(["nsIObserver",
                                           "nsISupportsWeakReference"]),
 
   observe(aSubject, aTopic, aData) {
     switch (aTopic) {
       case "last-pb-context-exited":