Bug 1514936, part 1 - Remove the outer argument to nsIFactory::createInstance. r=xpcom-reviewers,preferences-reviewers,nika,Gijs

This patch won't actually build, because a few bits of code are used
for both nsIFactory::createInstance and static components, and static
components are not fixed until the next patch.

The first place is nsLoadGroupConstructor, which uses an nsIFactory
macro to create a static component constructor. (This could be worked
around by expanding the macro to the state before this patch.)

The other issue is that nsAppShellConstructor is used in an nsIFactory
on OSX, but as a static component on all other platforms. This could
be worked around by wrapping nsAppShellConstructor in an adaptor that
passes in the extra null argument to nsAppShellConstructor.

Differential Revision: https://phabricator.services.mozilla.com/D146456
This commit is contained in:
Andrew McCreight 2022-05-17 20:24:19 +00:00
parent 9fc6a0a416
commit c8c5c819df
80 changed files with 112 additions and 325 deletions

View File

@ -123,7 +123,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -16,10 +16,7 @@ const kPromptServiceFactory = Cm.getClassObject(
);
var fakePromptServiceFactory = {
createInstance(aOuter, aIid) {
if (aOuter != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIid) {
return promptService.QueryInterface(aIid);
},
};

View File

@ -60,10 +60,7 @@ AboutModule.prototype = {
};
var AboutModuleFactory = {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return new AboutModule().QueryInterface(aIID);
},

View File

@ -2663,7 +2663,7 @@ let ChromeURLBlockPolicy = {
contractID: "@mozilla-org/policy-engine-content-policy-service;1",
classID: Components.ID("{ba7b9118-cabc-4845-8b26-4215d2a59ed7}"),
QueryInterface: ChromeUtils.generateQI(["nsIContentPolicy"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -170,7 +170,7 @@ let WebsiteFilter = {
"nsIObserver",
"nsISupportsWeakReference",
]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
isAllowed(url) {

View File

@ -16,10 +16,7 @@ const mockUpdateManager = {
QueryInterface: ChromeUtils.generateQI(["nsIUpdateManager"]),
createInstance(outer, iiD) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iiD) {
return this.QueryInterface(iiD);
},

View File

@ -29,10 +29,7 @@ let TestAboutPage = {
return channel;
},
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -25,10 +25,7 @@ function run_test() {
CID: uuidGenerator.generateUUID(),
scheme: "XULAppInfo",
contractID: XULAPPINFO_CONTRACTID,
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return XULAppInfo.QueryInterface(iid);
},
};

View File

@ -72,10 +72,7 @@ function run_test() {
CID: uuidGenerator.generateUUID(),
scheme: "XULAppInfo",
contractID: "@mozilla.org/xre/app-info;1",
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return XULAppInfo.QueryInterface(iid);
},
};
@ -91,10 +88,7 @@ function run_test() {
CID: testProtocols[i].CID,
contractID:
"@mozilla.org/network/protocol;1?name=" + testProtocols[i].scheme,
createInstance(aOuter, aIID) {
if (aOuter != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
let handler = new ProtocolHandler(this.scheme, this.flags, this.CID);
return handler.QueryInterface(aIID);
},

View File

@ -50,7 +50,7 @@ var policy = {
},
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -38,7 +38,7 @@ function createChromeScript() {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -44,7 +44,7 @@ var policy = {
},
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -39,7 +39,7 @@ var policy = {
},
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -662,10 +662,7 @@ var BrowserElementPromptService = {
var newInstance = new BrowserElementPromptFactory(oldInstance);
var newFactory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return newInstance.QueryInterface(iid);
},
};

View File

@ -212,10 +212,7 @@ setupPrototype(GlobalPCList, {
]),
classID: PC_MANAGER_CID,
_xpcom_factory: {
createInstance(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return _globalPCList.QueryInterface(iid);
},
},

View File

@ -42,10 +42,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=874090
throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
},
createInstance: function(aOuter, aIID) {
if (aOuter != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function(aIID) {
return this.QueryInterface(aIID);
}
};

View File

@ -105,10 +105,7 @@ var MockServices = (function() {
throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
},
createInstance(aOuter, aIID) {
if (aOuter != null) {
throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
}
createInstance(aIID) {
return this.QueryInterface(aIID);
},
};

View File

@ -95,10 +95,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=782211
throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
},
createInstance(aOuter, aIID) {
if (aOuter != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return this.QueryInterface(aIID);
},
};

View File

@ -32,7 +32,7 @@ function createChromeScript() {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -44,10 +44,7 @@ let mockAlertsService = {
throw Components.Exception("", Cr.NS_ERROR_NO_INTERFACE);
},
createInstance(aOuter, aIID) {
if (aOuter != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return this.QueryInterface(aIID);
},
};

View File

@ -42,9 +42,9 @@ function setupPolicy() {
return this;
throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
},
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -10,10 +10,7 @@ var provider = {
"nsIFactory",
"nsIGeolocationProvider",
]),
createInstance: function eventsink_ci(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function eventsink_ci(iid) {
return this.QueryInterface(iid);
},
startup() {},

View File

@ -10,10 +10,7 @@ var provider = {
"nsIFactory",
"nsIGeolocationProvider",
]),
createInstance: function eventsink_ci(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function eventsink_ci(iid) {
return this.QueryInterface(iid);
},
startup() {},

View File

@ -86,9 +86,7 @@ var ComponentUtils = {
var factory = component.prototype._xpcom_factory;
if (!factory) {
factory = {
createInstance: function(outer, iid) {
if (outer)
throw Cr.NS_ERROR_NO_AGGREGATION;
createInstance: function(iid) {
return (new component()).QueryInterface(iid);
},
QueryInterface: nsIFactoryQI
@ -107,10 +105,7 @@ var ComponentUtils = {
function XPCOMUtils_generateSingletonFactory(aServiceConstructor) {
return {
_instance: null,
createInstance: function XPCU_SF_createInstance(aOuter, aIID) {
if (aOuter !== null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
createInstance: function XPCU_SF_createInstance(aIID) {
if (this._instance === null) {
this._instance = new aServiceConstructor();
}

View File

@ -166,9 +166,7 @@ add_test(function test_categoryRegistration()
platformVersion: "",
});
let XULAppInfoFactory = {
createInstance: function (outer, iid) {
if (outer != null)
throw Cr.NS_ERROR_NO_AGGREGATION;
createInstance: function (iid) {
return XULAppInfo.QueryInterface(iid);
}
};

View File

@ -42,10 +42,7 @@ CustomProtocolHandler.prototype = {
},
/** nsIFactory */
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return this.QueryInterface(aIID);
},

View File

@ -18,10 +18,7 @@ var unsafeAboutModule = {
};
var factory = {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return unsafeAboutModule.QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),

View File

@ -107,13 +107,7 @@ ProtocolHandler.prototype = {
Ci.nsIRequest.LOAD_BYPASS_CACHE,
/** nsIFactory */
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception(
"createInstance no aggregation",
Cr.NS_ERROR_NO_AGGREGATION
);
}
createInstance(aIID) {
return this.QueryInterface(aIID);
},

View File

@ -21,10 +21,7 @@ var isNosniff = false;
*/
var sniffer = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIContentSniffer"]),
createInstance: function sniffer_ci(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function sniffer_ci(iid) {
return this.QueryInterface(iid);
},

View File

@ -20,10 +20,7 @@ const categoryName = "net-channel-event-sinks";
*/
var eventsink = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIChannelEventSink"]),
createInstance: function eventsink_ci(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function eventsink_ci(iid) {
return this.QueryInterface(iid);
},

View File

@ -35,7 +35,7 @@ TestProtocolHandler.prototype = {
function TestProtocolHandlerFactory() {}
TestProtocolHandlerFactory.prototype = {
createInstance(delegate, iid) {
createInstance(iid) {
return new TestProtocolHandler().QueryInterface(iid);
},
};

View File

@ -49,7 +49,7 @@ TestProtocolHandler.prototype = {
function TestProtocolHandlerFactory() {}
TestProtocolHandlerFactory.prototype = {
createInstance(delegate, iid) {
createInstance(iid) {
return new TestProtocolHandler().QueryInterface(iid);
},
};

View File

@ -23,10 +23,7 @@ function run_test() {
};
let xulRuntimeFactory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return xulRuntime.QueryInterface(iid);
},
};

View File

@ -32,10 +32,7 @@ AboutPage.prototype = {
return channel;
},
createInstance(outer, iid) {
if (outer !== null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -41,10 +41,7 @@ MockObjectRegisterer.prototype = {
var isChrome = location.protocol == "chrome:";
var providedConstructor = this._replacementCtor;
this._mockFactory = {
createInstance: function MF_createInstance(aOuter, aIid) {
if (aOuter != null) {
throw SpecialPowers.Cr.NS_ERROR_NO_AGGREGATION;
}
createInstance: function MF_createInstance(aIid) {
var inst = new providedConstructor().QueryInterface(aIid);
if (!isChrome) {
inst = SpecialPowers.wrapCallbackObject(inst);

View File

@ -127,11 +127,7 @@ var updateAppInfo = function(options) {
} catch (ex) {}
let factory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return currentAppInfo.QueryInterface(iid);
},
};

View File

@ -46,11 +46,7 @@ var MockRegistrar = Object.freeze({
let cid = Services.uuid.generateUUID();
let factory = {
createInstance(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
let wrappedMock;
if (mock.prototype && mock.prototype.constructor) {
wrappedMock = Object.create(mock.prototype);
@ -60,7 +56,7 @@ var MockRegistrar = Object.freeze({
}
try {
let genuine = originalFactory.createInstance(outer, iid);
let genuine = originalFactory.createInstance(iid);
wrappedMock._genuine = genuine;
} catch (ex) {
logger.info("Creating original instance failed", ex);

View File

@ -26,10 +26,7 @@ var oldClassID = "";
var newClassID = Services.uuid.generateUUID();
var newFactory = function(window) {
return {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return new MockColorPickerInstance(window).QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),

View File

@ -31,10 +31,7 @@ var oldClassID;
var newClassID = Services.uuid.generateUUID();
var newFactory = function(window) {
return {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return new MockFilePickerInstance(window).QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),

View File

@ -14,10 +14,7 @@ var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
var oldClassID, oldFactory;
var newClassID = Services.uuid.generateUUID();
var newFactory = {
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return new MockPermissionPromptInstance().QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),

View File

@ -302,10 +302,7 @@ var _fakeIdleService = {
factory: {
// nsIFactory
createInstance(aOuter, aIID) {
if (aOuter) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(aIID) {
return _fakeIdleService.QueryInterface(aIID);
},
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),

View File

@ -151,7 +151,7 @@ AutoCompleteSearchBase.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -154,7 +154,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -153,7 +153,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -152,7 +152,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -156,7 +156,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -156,7 +156,7 @@ AutoCompleteSearch.prototype = {
]),
// nsIFactory implementation
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -72,7 +72,7 @@ AutoCompleteSearch.prototype = {
"nsIFactory",
"nsIAutoCompleteSearch",
]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -68,10 +68,7 @@ function mockServicesChromeScript() {
QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
createInstance: function(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -13,10 +13,7 @@ var mockNetworkStatusService = {
QueryInterface: ChromeUtils.generateQI(["nsINetworkLinkService"]),
createInstance(outer, iiD) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iiD) {
return this.QueryInterface(iiD);
},

View File

@ -39,10 +39,7 @@ const mockAlertsService = {
QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -379,10 +379,7 @@ var ChannelEventSink = {
},
// nsIFactory implementation
createInstance(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return this.QueryInterface(iid);
},
};

View File

@ -8,8 +8,7 @@
extern "C" {
// Implemented in Rust.
nsresult nsKeyValueServiceConstructor(nsISupports* aOuter, REFNSIID aIID,
void** aResult);
nsresult nsKeyValueServiceConstructor(REFNSIID aIID, void** aResult);
} // extern "C"
NS_DEFINE_NAMED_CID(NS_KEY_VALUE_SERVICE_CID);

View File

@ -26,7 +26,7 @@ use atomic_refcell::AtomicRefCell;
use error::KeyValueError;
use libc::c_void;
use moz_task::{create_background_task_queue, DispatchOptions, TaskRunnable};
use nserror::{nsresult, NS_ERROR_FAILURE, NS_ERROR_NO_AGGREGATION, NS_OK};
use nserror::{nsresult, NS_ERROR_FAILURE, NS_OK};
use nsstring::{nsACString, nsCString};
use owned_value::{owned_to_variant, variant_to_owned};
use rkv::backend::{SafeModeDatabase, SafeModeEnvironment};
@ -44,8 +44,7 @@ use xpcom::{
getter_addrefs,
interfaces::{
nsIKeyValueDatabaseCallback, nsIKeyValueEnumeratorCallback, nsIKeyValuePair,
nsIKeyValueVariantCallback, nsIKeyValueVoidCallback, nsISerialEventTarget, nsISupports,
nsIVariant,
nsIKeyValueVariantCallback, nsIKeyValueVoidCallback, nsISerialEventTarget, nsIVariant,
},
nsIID, xpcom, xpcom_method, RefPtr,
};
@ -56,16 +55,11 @@ type KeyValuePairResult = Result<(String, OwnedValue), KeyValueError>;
#[no_mangle]
pub unsafe extern "C" fn nsKeyValueServiceConstructor(
outer: *const nsISupports,
iid: &nsIID,
result: *mut *mut c_void,
) -> nsresult {
*result = ptr::null_mut();
if !outer.is_null() {
return NS_ERROR_NO_AGGREGATION;
}
let service = KeyValueService::new();
service.QueryInterface(iid, result)
}

View File

@ -24,10 +24,7 @@ function createAppInfo(ID, name, version, platformVersion = "1.0") {
});
let XULAppInfoFactory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return gAppInfo.QueryInterface(iid);
},
};

View File

@ -156,11 +156,8 @@ const gTest0TimerCallback = {
};
const gTest0Factory = {
createInstance: function T0F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest0TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T0F_createInstance(aIID) {
return gTest0TimerCallback.QueryInterface(aIID);
},
};
@ -174,11 +171,8 @@ const gTest1TimerCallback = {
};
const gTest1Factory = {
createInstance: function T1F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest1TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T1F_createInstance(aIID) {
return gTest1TimerCallback.QueryInterface(aIID);
},
};
@ -192,11 +186,8 @@ const gTest2TimerCallback = {
};
const gTest2Factory = {
createInstance: function T2F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest2TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T2F_createInstance(aIID) {
return gTest2TimerCallback.QueryInterface(aIID);
},
};
@ -205,11 +196,8 @@ const gTest3TimerCallback = {
};
const gTest3Factory = {
createInstance: function T3F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest3TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T3F_createInstance(aIID) {
return gTest3TimerCallback.QueryInterface(aIID);
},
};
@ -227,11 +215,8 @@ const gTest4TimerCallback = {
};
const gTest4Factory = {
createInstance: function T4F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest4TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T4F_createInstance(aIID) {
return gTest4TimerCallback.QueryInterface(aIID);
},
};
@ -249,11 +234,8 @@ const gTest5TimerCallback = {
};
const gTest5Factory = {
createInstance: function T5F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest5TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T5F_createInstance(aIID) {
return gTest5TimerCallback.QueryInterface(aIID);
},
};
@ -271,11 +253,8 @@ const gTest6TimerCallback = {
};
const gTest6Factory = {
createInstance: function T6F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest6TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T6F_createInstance(aIID) {
return gTest6TimerCallback.QueryInterface(aIID);
},
};
@ -293,11 +272,8 @@ const gTest7TimerCallback = {
};
const gTest7Factory = {
createInstance: function T7F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest7TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T7F_createInstance(aIID) {
return gTest7TimerCallback.QueryInterface(aIID);
},
};
@ -313,11 +289,8 @@ const gTest8TimerCallback = {
};
const gTest8Factory = {
createInstance: function T8F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest8TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T8F_createInstance(aIID) {
return gTest8TimerCallback.QueryInterface(aIID);
},
};
@ -342,11 +315,8 @@ const gTest10TimerCallback = {
};
const gTest9Factory = {
createInstance: function T9F_createInstance(aOuter, aIID) {
if (aOuter == null) {
return gTest9TimerCallback.QueryInterface(aIID);
}
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
createInstance: function T9F_createInstance(aIID) {
return gTest9TimerCallback.QueryInterface(aIID);
},
};

View File

@ -11,10 +11,7 @@ const tPFContract = "@mozilla.org/passwordmanager/authpromptfactory;1";
var TestPromptFactory = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIPromptFactory"]),
createInstance: function tPF_ci(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function tPF_ci(iid) {
return this.QueryInterface(iid);
},

View File

@ -56,7 +56,7 @@ var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
var autoCompleteSimple = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIAutoCompleteSearch"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -56,7 +56,7 @@ var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
var autoCompleteSimple = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIAutoCompleteSearch"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -59,7 +59,7 @@ var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
var autoCompleteSimple = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIAutoCompleteSearch"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -52,7 +52,7 @@ var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
var autoCompleteSimple = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIAutoCompleteSearch"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -57,7 +57,7 @@ var autoCompleteSimpleName = "@mozilla.org/autocomplete/search;1?name=simple"
var autoCompleteSimple = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory", "nsIAutoCompleteSearch"]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -64,7 +64,7 @@ let autoCompleteSimple = {
"nsIFactory",
"nsIAutoCompleteSearch"
]),
createInstance(outer, iid) {
createInstance(iid) {
return this.QueryInterface(iid);
},

View File

@ -325,14 +325,7 @@ amManager.prototype = {
classID: Components.ID("{4399533d-08d1-458c-a87a-235f74451cfa}"),
_xpcom_factory: {
createInstance(aOuter, aIid) {
if (aOuter != null) {
throw Components.Exception(
"Component does not support aggregation",
Cr.NS_ERROR_NO_AGGREGATION
);
}
createInstance(aIid) {
if (!gSingleton) {
gSingleton = new amManager();
}

View File

@ -335,10 +335,7 @@ var InstallConfirm = {
};
var InstallConfirmFactory = {
createInstance: function createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance: function createInstance(iid) {
return InstallConfirm.QueryInterface(iid);
},
};

View File

@ -2433,10 +2433,7 @@ Update.prototype = {
const UpdateServiceFactory = {
_instance: null,
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return this._instance == null
? (this._instance = new UpdateService())
: this._instance;

View File

@ -2074,10 +2074,7 @@ nsToolkitProfileService::Flush() {
NS_IMPL_ISUPPORTS(nsToolkitProfileFactory, nsIFactory)
NS_IMETHODIMP
nsToolkitProfileFactory::CreateInstance(nsISupports* aOuter, const nsID& aIID,
void** aResult) {
if (aOuter) return NS_ERROR_NO_AGGREGATION;
nsToolkitProfileFactory::CreateInstance(const nsID& aIID, void** aResult) {
RefPtr<nsToolkitProfileService> profileService =
nsToolkitProfileService::gService;
if (!profileService) {

View File

@ -39,11 +39,7 @@ const ShellService = {
let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
let factory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return ShellService.QueryInterface(iid);
},
};

View File

@ -2119,10 +2119,7 @@ nsSingletonFactory::nsSingletonFactory(nsISupports* aSingleton)
NS_IMPL_ISUPPORTS(nsSingletonFactory, nsIFactory)
NS_IMETHODIMP
nsSingletonFactory::CreateInstance(nsISupports* aOuter, const nsIID& aIID,
void** aResult) {
NS_ENSURE_NO_AGGREGATION(aOuter);
nsSingletonFactory::CreateInstance(const nsIID& aIID, void** aResult) {
return mSingleton->QueryInterface(aIID, aResult);
}

View File

@ -176,10 +176,7 @@ function registerMockWindowsRegKeyFactory() {
Ci.nsIWindowsRegKey
);
let mockWindowsRegKeyFactory = {
createInstance(outer, iid) {
if (outer != null) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
info("Create a mock wrapper around RegKey");
var key = new MockWindowsRegKey(originalRegKey);
return key.QueryInterface(iid);

View File

@ -11,9 +11,8 @@ namespace mozilla {
NS_IMPL_ISUPPORTS(GenericFactory, nsIFactory)
NS_IMETHODIMP
GenericFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult) {
return mCtor(aOuter, aIID, aResult);
GenericFactory::CreateInstance(REFNSIID aIID, void** aResult) {
return mCtor(aIID, aResult);
}
} // namespace mozilla

View File

@ -28,8 +28,7 @@ struct Module {
typedef already_AddRefed<nsIFactory> (*GetFactoryProcPtr)(
const Module& module, const CIDEntry& entry);
typedef nsresult (*ConstructorProcPtr)(nsISupports* aOuter, const nsIID& aIID,
void** aResult);
typedef nsresult (*ConstructorProcPtr)(const nsIID& aIID, void** aResult);
typedef nsresult (*LoadFuncPtr)();
typedef void (*UnloadFuncPtr)();

View File

@ -13,30 +13,22 @@
#include "mozilla/Module.h"
#define NS_GENERIC_FACTORY_CONSTRUCTOR(_InstanceClass) \
static nsresult _InstanceClass##Constructor(nsISupports* aOuter, \
REFNSIID aIID, void** aResult) { \
static nsresult _InstanceClass##Constructor(REFNSIID aIID, void** aResult) { \
RefPtr<_InstanceClass> inst; \
\
*aResult = nullptr; \
if (nullptr != aOuter) { \
return NS_ERROR_NO_AGGREGATION; \
} \
\
inst = new _InstanceClass(); \
return inst->QueryInterface(aIID, aResult); \
}
#define NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(_InstanceClass, _InitMethod) \
static nsresult _InstanceClass##Constructor(nsISupports* aOuter, \
REFNSIID aIID, void** aResult) { \
static nsresult _InstanceClass##Constructor(REFNSIID aIID, void** aResult) { \
nsresult rv; \
\
RefPtr<_InstanceClass> inst; \
\
*aResult = nullptr; \
if (nullptr != aOuter) { \
return NS_ERROR_NO_AGGREGATION; \
} \
\
inst = new _InstanceClass(); \
rv = inst->_InitMethod(); \
@ -65,14 +57,10 @@ struct RemoveAlreadyAddRefed<already_AddRefed<T>> {
// 'Constructor' that uses an existing getter function that gets a singleton.
#define NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(_InstanceClass, _GetterProc) \
static nsresult _InstanceClass##Constructor(nsISupports* aOuter, \
REFNSIID aIID, void** aResult) { \
static nsresult _InstanceClass##Constructor(REFNSIID aIID, void** aResult) { \
RefPtr<_InstanceClass> inst; \
\
*aResult = nullptr; \
if (nullptr != aOuter) { \
return NS_ERROR_NO_AGGREGATION; \
} \
\
using T = \
mozilla::detail::RemoveAlreadyAddRefed<decltype(_GetterProc())>::Type; \

View File

@ -199,12 +199,8 @@ private:
NS_IMPL_ISUPPORTS(StaticModuleFactory, nsIFactory)
NS_IMETHODIMP StaticModuleFactory::CreateInstance(nsISupports* aOuter,
const nsIID& aIID,
NS_IMETHODIMP StaticModuleFactory::CreateInstance(const nsIID& aIID,
void** aResult) {
if (aOuter) {
return NS_ERROR_NO_AGGREGATION;
}
return CreateInstanceImpl(mID, aIID, aResult);
}

View File

@ -1067,7 +1067,7 @@ nsComponentManagerImpl::CreateInstance(const nsCID& aClass, const nsIID& aIID,
nsresult rv;
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
if (factory) {
rv = factory->CreateInstance(nullptr, aIID, aResult);
rv = factory->CreateInstance(aIID, aResult);
if (NS_SUCCEEDED(rv) && !*aResult) {
NS_ERROR("Factory did not return an object but returned success!");
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
@ -1150,7 +1150,7 @@ nsComponentManagerImpl::CreateInstanceByContractID(const char* aContractID,
nsresult rv;
nsCOMPtr<nsIFactory> factory = entry->GetFactory();
if (factory) {
rv = factory->CreateInstance(nullptr, aIID, aResult);
rv = factory->CreateInstance(aIID, aResult);
if (NS_SUCCEEDED(rv) && !*aResult) {
NS_ERROR("Factory did not return an object but returned success!");
rv = NS_ERROR_SERVICE_NOT_AVAILABLE;
@ -1762,7 +1762,7 @@ already_AddRefed<nsIFactory> nsFactoryEntry::GetFactory() {
nsresult nsFactoryEntry::CreateInstance(const nsIID& aIID, void** aResult) {
nsCOMPtr<nsIFactory> factory = GetFactory();
NS_ENSURE_TRUE(factory, NS_ERROR_FAILURE);
return factory->CreateInstance(nullptr, aIID, aResult);
return factory->CreateInstance(aIID, aResult);
}
size_t nsFactoryEntry::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) {

View File

@ -178,7 +178,7 @@ nsresult nsCreateInstanceByContractID::operator()(const nsIID& aIID,
nsresult nsCreateInstanceFromFactory::operator()(const nsIID& aIID,
void** aInstancePtr) const {
nsresult status = mFactory->CreateInstance(nullptr, aIID, aInstancePtr);
nsresult status = mFactory->CreateInstance(aIID, aInstancePtr);
if (NS_FAILED(status)) {
*aInstancePtr = 0;
}

View File

@ -15,17 +15,13 @@ interface nsIFactory : nsISupports {
/**
* Creates an instance of a component.
*
* @param aOuter Pointer to a component that wishes to be aggregated
* in the resulting instance. This will be nullptr if no
* aggregation is requested.
* @param iid The IID of the interface being requested in
* the component which is being currently created.
* @param result [out] Pointer to the newly created instance, if successful.
* @throws NS_NOINTERFACE - Interface not accessible.
* @throws NS_ERROR_NO_AGGREGATION - if an 'outer' object is supplied, but the
* component is not aggregatable.
* NS_ERROR* - Method failure.
*/
void createInstance(in nsISupports aOuter, in nsIIDRef iid,
[retval, iid_is(iid)] out nsQIResult result);
void createInstance(in nsIIDRef iid,
[retval, iid_is(iid)] out nsQIResult result);
};

View File

@ -46,12 +46,7 @@ nsINIParserFactory::CreateINIParser(nsIFile* aINIFile, nsIINIParser** aResult) {
}
NS_IMETHODIMP
nsINIParserFactory::CreateInstance(nsISupports* aOuter, REFNSIID aIID,
void** aResult) {
if (NS_WARN_IF(aOuter)) {
return NS_ERROR_NO_AGGREGATION;
}
nsINIParserFactory::CreateInstance(REFNSIID aIID, void** aResult) {
// We are our own singleton.
return QueryInterface(aIID, aResult);
}

View File

@ -80,8 +80,7 @@ class Factory final : public nsIFactory {
Factory() : mFirstComponentCreated(false) {}
NS_IMETHOD CreateInstance(nsISupports* aDelegate, const nsIID& aIID,
void** aResult) override;
NS_IMETHOD CreateInstance(const nsIID& aIID, void** aResult) override;
bool mFirstComponentCreated;
};
@ -129,8 +128,7 @@ NS_INTERFACE_MAP_BEGIN(Component2)
NS_INTERFACE_MAP_END
NS_IMETHODIMP
Factory::CreateInstance(nsISupports* aDelegate, const nsIID& aIID,
void** aResult) {
Factory::CreateInstance(const nsIID& aIID, void** aResult) {
// Make sure that the second thread beat the main thread to the getService
// call.
MOZ_RELEASE_ASSERT(!NS_IsMainThread(), "Wrong thread!");
@ -144,7 +142,6 @@ Factory::CreateInstance(nsISupports* aDelegate, const nsIID& aIID,
mon.Wait(PR_MillisecondsToInterval(3000));
}
NS_ENSURE_FALSE(aDelegate, NS_ERROR_NO_AGGREGATION);
NS_ENSURE_ARG_POINTER(aResult);
nsCOMPtr<nsISupports> instance;

View File

@ -37,10 +37,7 @@ function run_test() {
let factory = {
QueryInterface: ChromeUtils.generateQI(["nsIFactory"]),
createInstance(outer, iid) {
if (outer) {
throw Components.Exception("", Cr.NS_ERROR_NO_AGGREGATION);
}
createInstance(iid) {
return testObject.QueryInterface(iid);
},
};