Bug 1196963 - Make extensions work without being in developer mode r=jduell

This commit is contained in:
Fabrice Desré 2015-08-26 18:40:05 -07:00
Родитель ff9f41144e
Коммит db3cd46808
5 изменённых файлов: 43 добавлений и 12 удалений

Просмотреть файл

@ -11,15 +11,14 @@ function debug(s) {
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Promise.jsm");
try {
if (Services.prefs.getBoolPref("dom.apps.customization.enabled")) {
Cu.import("resource://gre/modules/UserCustomizations.jsm");
}
} catch(e) {}
XPCOMUtils.defineLazyModuleGetter(this, "UserCustomizations",
"resource://gre/modules/UserCustomizations.jsm");
const APPS_SERVICE_CID = Components.ID("{05072afa-92fe-45bf-ae22-39b69c117058}");
@ -157,6 +156,16 @@ AppsService.prototype = {
return null;
},
isExtensionResource: function(aURI) {
// This is only expected to be used by NeckoParent, and will not work
// properly in child processes.
if (Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT) {
throw Cr.NS_ERROR_FAILURE;
}
return UserCustomizations.isFromExtension(aURI);
},
classID : APPS_SERVICE_CID,
QueryInterface : XPCOMUtils.generateQI([Ci.nsIAppsService])
}

Просмотреть файл

@ -34,6 +34,7 @@ function log(aStr) {
this.UserCustomizations = {
extensions: new Map(), // id -> extension. Needed to disable extensions.
appId: new Set(),
register: function(aApp) {
if (!this._enabled || !aApp.enabled || aApp.role != "addon") {
@ -51,7 +52,10 @@ this.UserCustomizations = {
});
this.extensions.set(aApp.manifestURL, extension);
extension.startup();
extension.startup().then(() => {
let uri = Services.io.newURI(aApp.origin, null, null);
this.appId.add(uri.host);
});
},
unregister: function(aApp) {
@ -63,9 +67,15 @@ this.UserCustomizations = {
if (this.extensions.has(aApp.manifestURL)) {
this.extensions.get(aApp.manifestURL).shutdown();
this.extensions.delete(aApp.manifestURL);
let uri = Services.io.newURI(aApp.origin, null, null);
this.appId.delete(uri.host);
}
},
isFromExtension: function(aURI) {
return this.appId.has(aURI.host);
},
// Checks that this is a valid extension manifest.
// The format is documented at https://developer.chrome.com/extensions/manifest
checkExtensionManifest: function(aManifest) {

Просмотреть файл

@ -16,7 +16,7 @@ interface nsIURI;
* This service allows accessing some DOMApplicationRegistry methods from
* non-javascript code.
*/
[scriptable, uuid(03f1e30e-a1aa-4e18-ab3f-cd04b3b35a54)]
[scriptable, uuid(8a035714-ed14-446f-8bd7-837e91cdce9e)]
interface nsIAppsService : nsISupports
{
mozIApplication getAppByManifestURL(in DOMString manifestURL);
@ -83,4 +83,11 @@ interface nsIAppsService : nsISupports
* Returns the scope for app to use with service workers.
*/
DOMString getScopeByLocalId(in unsigned long localId);
/**
* Returns true if this uri is a script or css resource loaded
* from an extension.
* Available only in the parent process.
*/
bool isExtensionResource(in nsIURI uri);
};

Просмотреть файл

@ -580,7 +580,17 @@ NeckoParent::AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized
}
}
nsCOMPtr<nsIURI> appUri = DeserializeURI(aAppURI);
if (!haveValidBrowser) {
// Extension loads come from chrome and have no valid browser, so we check
// for these early on.
bool fromExtension = false;
if (NS_SUCCEEDED(appsService->IsExtensionResource(appUri, &fromExtension)) &&
fromExtension) {
RemoteOpenFileParent* parent = new RemoteOpenFileParent(fileURL);
return parent;
}
return nullptr;
}
@ -591,7 +601,6 @@ NeckoParent::AllocPRemoteOpenFileParent(const SerializedLoadContext& aSerialized
// Check if we load the whitelisted app uri for the neterror page.
bool netErrorWhiteList = false;
nsCOMPtr<nsIURI> appUri = DeserializeURI(aAppURI);
if (appUri) {
nsAdoptingString netErrorURI;
netErrorURI = Preferences::GetString("b2g.neterror.url");

Просмотреть файл

@ -210,10 +210,6 @@ RemoteOpenFileChild::AsyncRemoteFileOpen(int32_t aFlags,
mTabChild = static_cast<TabChild*>(aTabChild);
if (MissingRequiredTabChild(mTabChild, "remoteopenfile")) {
return NS_ERROR_ILLEGAL_VALUE;
}
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
// Windows/OSX desktop builds skip remoting, and just open file in child
// process when asked for NSPR handle