Bug 1491561 - Remove the XPCOM registrations for LoadContext; r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D5945
This commit is contained in:
Ehsan Akhgari 2018-09-15 11:38:45 -04:00
parent b3f188e17a
commit 02f08121ff
13 changed files with 47 additions and 72 deletions

View File

@ -201,34 +201,27 @@ LoadContext::GetInterface(const nsIID& aIID, void** aResult)
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

View File

@ -122,8 +122,8 @@ private:
#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

View File

@ -76,16 +76,4 @@
*/
#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__

View File

@ -37,9 +37,6 @@
#include "nsSHEntryShared.h"
#include "nsSHistory.h"
// LoadContexts (used for testing)
#include "LoadContext.h"
using mozilla::dom::ContentHandlerService;
static bool gInitialized = false;
@ -117,8 +114,6 @@ 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 },
@ -142,8 +137,6 @@ const mozilla::Module::CIDEntry kDocShellCIDs[] = {
{ &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 }
};
@ -197,8 +190,6 @@ const mozilla::Module::ContractIDEntry kDocShellContracts[] = {
{ 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 }
};

View File

@ -15,8 +15,8 @@ var gPublicLoader = Cc["@mozilla.org/image/loader;1"].createInstance(Ci.imgILoad
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++;

View File

@ -16,6 +16,7 @@ interface nsIComponentManager;
interface nsICycleCollectorListener;
interface nsIEditorSpellCheck;
interface nsIFile;
interface nsILoadContext;
interface nsIURI;
interface nsIJSCID;
interface nsIJSIID;
@ -725,8 +726,11 @@ interface nsIXPCComponents_Utils : nsISupports
/* 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();
};
/**

View File

@ -20,6 +20,7 @@
#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"
@ -3233,11 +3234,20 @@ nsXPCComponents_Utils::CreateCommandLine(nsISupports** aCommandLine)
}
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;
}

View File

@ -16,9 +16,6 @@ var URIs = [
"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({
@ -70,7 +67,7 @@ add_test(function test_setPrivate_regular() {
* 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);
@ -82,7 +79,7 @@ add_test(function test_LoadContextPrivate() {
* 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);

View File

@ -17,7 +17,7 @@ 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;

View File

@ -12,10 +12,8 @@ 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) ?

View File

@ -13,10 +13,9 @@
<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();
@ -191,8 +190,7 @@
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");

View File

@ -4,10 +4,8 @@
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();

View File

@ -32,10 +32,8 @@ 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",