Bug 1513366: Part 5 - Migrate extension process script to a JSM. r=aswan

This simplifies things all around, and gets rid of one more unnecessary
component registration.

--HG--
rename : toolkit/components/extensions/extension-process-script.js => toolkit/components/extensions/ExtensionProcessScript.jsm
extra : rebase_source : 7ceb6ada0730f8241bbd5ddbd889a320da22b1b1
This commit is contained in:
Kris Maglione 2018-12-12 17:58:19 -08:00
Родитель ec6680483d
Коммит 778252994f
15 изменённых файлов: 31 добавлений и 53 удалений

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

@ -20,7 +20,6 @@ const kDumpAllStacks = false;
const whitelist = {
components: new Set([
"ContentProcessSingleton.js",
"extension-process-script.js",
]),
modules: new Set([
"chrome://mochikit/content/ShutdownLeaksCollector.jsm",
@ -68,6 +67,7 @@ const whitelist = {
"resource://gre/modules/TelemetryUtils.jsm", // bug 1470339
// Extensions
"resource://gre/modules/ExtensionProcessScript.jsm",
"resource://gre/modules/ExtensionUtils.jsm",
"resource://gre/modules/MessageChannel.jsm",
]),

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

@ -359,7 +359,6 @@
; [Extensions]
@RESPATH@/components/extensions-toolkit.manifest
@RESPATH@/components/extension-process-script.js
@RESPATH@/browser/components/extensions-browser.manifest
; [Normandy]

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

@ -264,7 +264,6 @@
; [Extensions]
@BINPATH@/components/extensions-toolkit.manifest
@BINPATH@/components/extensions-mobile.manifest
@BINPATH@/components/extension-process-script.js
; Features
@BINPATH@/features/*

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

@ -7,15 +7,12 @@ const Registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
const UUID = "0f459ab4-b4ba-4741-ac89-ee47dea07adb";
const ABOUT_PATH_PATH = "content/test.html";
XPCOMUtils.defineLazyGetter(
this, "processScript",
() => Cc["@mozilla.org/webextensions/extension-process-script;1"]
.getService().wrappedJSObject);
const {WebExtensionPolicy} = Cu.getGlobalForObject(Services);
const TPSProcessScript = {
init() {
let extensionChild = processScript.getExtensionChild(WEBEXTENSION_ID);
let aboutPageURI = extensionChild.baseURI.resolve(ABOUT_PATH_PATH);
let extensionPolicy = WebExtensionPolicy.getByID(WEBEXTENSION_ID);
let aboutPageURI = extensionPolicy.getURL(ABOUT_PATH_PATH);
class TabSwitchAboutModule {
constructor() {

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

@ -42,6 +42,7 @@ XPCOMUtils.defineLazyModuleGetters(this, {
AppConstants: "resource://gre/modules/AppConstants.jsm",
AsyncShutdown: "resource://gre/modules/AsyncShutdown.jsm",
ExtensionPermissions: "resource://gre/modules/ExtensionPermissions.jsm",
ExtensionProcessScript: "resource://gre/modules/ExtensionProcessScript.jsm",
ExtensionStorage: "resource://gre/modules/ExtensionStorage.jsm",
ExtensionStorageIDB: "resource://gre/modules/ExtensionStorageIDB.jsm",
ExtensionTelemetry: "resource://gre/modules/ExtensionTelemetry.jsm",
@ -57,11 +58,6 @@ XPCOMUtils.defineLazyModuleGetters(this, {
XPIProvider: "resource://gre/modules/addons/XPIProvider.jsm",
});
XPCOMUtils.defineLazyGetter(
this, "processScript",
() => Cc["@mozilla.org/webextensions/extension-process-script;1"]
.getService().wrappedJSObject);
// This is used for manipulating jar entry paths, which always use Unix
// separators.
XPCOMUtils.defineLazyGetter(
@ -1871,7 +1867,7 @@ class Extension extends ExtensionData {
this.initSharedData();
this.policy.active = false;
this.policy = processScript.initExtension(this);
this.policy = ExtensionProcessScript.initExtension(this);
this.policy.extension = this;
this.updatePermissions(this.startupReason);

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

@ -26,17 +26,13 @@ XPCOMUtils.defineLazyServiceGetter(this, "finalizationService",
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionContent: "resource://gre/modules/ExtensionContent.jsm",
ExtensionPageChild: "resource://gre/modules/ExtensionPageChild.jsm",
ExtensionProcessScript: "resource://gre/modules/ExtensionProcessScript.jsm",
MessageChannel: "resource://gre/modules/MessageChannel.jsm",
NativeApp: "resource://gre/modules/NativeMessaging.jsm",
PerformanceCounters: "resource://gre/modules/PerformanceCounters.jsm",
PromiseUtils: "resource://gre/modules/PromiseUtils.jsm",
});
XPCOMUtils.defineLazyGetter(
this, "processScript",
() => Cc["@mozilla.org/webextensions/extension-process-script;1"]
.getService().wrappedJSObject);
// We're using the pref to avoid loading PerformanceCounters.jsm for nothing.
XPCOMUtils.defineLazyPreferenceGetter(this, "gTimingEnabled",
"extensions.webextensions.enablePerformanceCounters",
@ -725,7 +721,7 @@ class BrowserExtensionContent extends EventEmitter {
if (this.dependencies) {
for (let id of this.dependencies) {
let extension = processScript.getExtensionChild(id);
let extension = ExtensionProcessScript.getExtensionChild(id);
if (extension) {
apiManagers.push(extension.experimentAPIManager);
}

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

@ -13,6 +13,7 @@ ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionProcessScript: "resource://gre/modules/ExtensionProcessScript.jsm",
ExtensionTelemetry: "resource://gre/modules/ExtensionTelemetry.jsm",
LanguageDetector: "resource:///modules/translation/LanguageDetector.jsm",
MessageChannel: "resource://gre/modules/MessageChannel.jsm",
@ -24,9 +25,6 @@ XPCOMUtils.defineLazyServiceGetter(this, "styleSheetService",
"@mozilla.org/content/style-sheet-service;1",
"nsIStyleSheetService");
XPCOMUtils.defineLazyServiceGetter(this, "processScript",
"@mozilla.org/webextensions/extension-process-script;1");
const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer", "initWithCallback");
ChromeUtils.import("resource://gre/modules/ExtensionChild.jsm");
@ -648,7 +646,7 @@ class UserScript extends Script {
}
var contentScripts = new DefaultWeakMap(matcher => {
const extension = processScript.extensions.get(matcher.extension);
const extension = ExtensionProcessScript.extensions.get(matcher.extension);
if ("userScriptOptions" in matcher) {
return new UserScript(extension, matcher);

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

@ -15,20 +15,16 @@ var EXPORTED_SYMBOLS = ["ExtensionPageChild"];
*/
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionChildDevToolsUtils",
"resource://gre/modules/ExtensionChildDevToolsUtils.jsm");
ChromeUtils.defineModuleGetter(this, "ExtensionProcessScript",
"resource://gre/modules/ExtensionProcessScript.jsm");
ChromeUtils.defineModuleGetter(this, "Schemas",
"resource://gre/modules/Schemas.jsm");
ChromeUtils.defineModuleGetter(this, "WebNavigationFrames",
"resource://gre/modules/WebNavigationFrames.jsm");
XPCOMUtils.defineLazyGetter(
this, "processScript",
() => Cc["@mozilla.org/webextensions/extension-process-script;1"]
.getService().wrappedJSObject);
const CATEGORY_EXTENSION_SCRIPTS_ADDON = "webextension-scripts-addon";
const CATEGORY_EXTENSION_SCRIPTS_DEVTOOLS = "webextension-scripts-devtools";
@ -90,7 +86,7 @@ const initializeBackgroundPage = (context) => {
};
function getFrameData(global) {
return processScript.getFrameData(global, true);
return ExtensionProcessScript.getFrameData(global, true);
}
var apiManager = new class extends SchemaAPIManager {

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

@ -28,6 +28,7 @@
#include "nsGlobalWindowOuter.h"
#include "nsILoadInfo.h"
#include "nsIXULRuntime.h"
#include "nsImportModule.h"
#include "nsNetUtil.h"
#include "nsPrintfCString.h"
#include "nsPIDOMWindow.h"
@ -56,8 +57,11 @@ static mozIExtensionProcessScript& ProcessScript() {
static nsCOMPtr<mozIExtensionProcessScript> sProcessScript;
if (MOZ_UNLIKELY(!sProcessScript)) {
sProcessScript =
do_GetService("@mozilla.org/webextensions/extension-process-script;1");
nsCOMPtr<mozIExtensionProcessScriptJSM> jsm =
do_ImportModule("resource://gre/modules/ExtensionProcessScript.jsm");
MOZ_RELEASE_ASSERT(jsm);
Unused << jsm->GetExtensionProcessScript(getter_AddRefs(sProcessScript));
MOZ_RELEASE_ASSERT(sProcessScript);
ClearOnShutdown(&sProcessScript);
}

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

@ -10,6 +10,8 @@
* after startup, in *every* browser process live outside of this file.
*/
var EXPORTED_SYMBOLS = ["ExtensionProcessScript"];
ChromeUtils.import("resource://gre/modules/MessageChannel.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm");
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
@ -275,17 +277,7 @@ ExtensionManager = {
},
};
function ExtensionProcessScript() {
}
ExtensionProcessScript.prototype = {
classID: Components.ID("{21f9819e-4cdf-49f9-85a0-850af91a5058}"),
QueryInterface: ChromeUtils.generateQI([Ci.mozIExtensionProcessScript]),
_xpcom_factory: XPCOMUtils.generateSingletonFactory(ExtensionProcessScript),
get wrappedJSObject() { return this; },
var ExtensionProcessScript = {
extensions,
getFrameData(global, force) {
@ -322,6 +314,4 @@ ExtensionProcessScript.prototype = {
},
};
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ExtensionProcessScript]);
ExtensionManager.init();

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

@ -11,7 +11,3 @@ category webextension-scripts-addon toolkit chrome://extensions/content/child/ex
category webextension-schemas events chrome://extensions/content/schemas/events.json
category webextension-schemas native_manifest chrome://extensions/content/schemas/native_manifest.json
category webextension-schemas types chrome://extensions/content/schemas/types.json
component {21f9819e-4cdf-49f9-85a0-850af91a5058} extension-process-script.js
contract @mozilla.org/webextensions/extension-process-script;1 {21f9819e-4cdf-49f9-85a0-850af91a5058}

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

@ -18,6 +18,7 @@ EXTRA_JS_MODULES += [
'ExtensionParent.jsm',
'ExtensionPermissions.jsm',
'ExtensionPreferencesManager.jsm',
'ExtensionProcessScript.jsm',
'ExtensionSettingsStore.jsm',
'ExtensionStorage.jsm',
'ExtensionStorageIDB.jsm',
@ -35,7 +36,6 @@ EXTRA_JS_MODULES += [
]
EXTRA_COMPONENTS += [
'extension-process-script.js',
'extensions-toolkit.manifest',
]

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

@ -19,3 +19,9 @@ interface mozIExtensionProcessScript : nsISupports
void initExtensionDocument(in nsISupports extension, in Document doc,
in bool privileged);
};
[scriptable,uuid(9f2a6434-f0ef-4063-ae33-368d929805d2)]
interface mozIExtensionProcessScriptJSM : nsISupports
{
readonly attribute mozIExtensionProcessScript ExtensionProcessScript;
};

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

@ -14,6 +14,7 @@ const STARTUP_MODULES = [
// Otherwise the data comes from the startup cache. We should test for
// this.
"resource://gre/modules/ExtensionPermissions.jsm",
"resource://gre/modules/ExtensionProcessScript.jsm",
"resource://gre/modules/ExtensionUtils.jsm",
"resource://gre/modules/ExtensionTelemetry.jsm",
];

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

@ -79,7 +79,7 @@ XPCOMUtils.defineLazyPreferenceGetter(this, "WEBEXT_PERMISSION_PROMPTS",
// since it needs to be able to track things like new frameLoader globals that
// are created before other framework code has been initialized.
Services.ppmm.loadProcessScript(
"data:,Components.classes['@mozilla.org/webextensions/extension-process-script;1'].getService()",
"data:,ChromeUtils.import('resource://gre/modules/ExtensionProcessScript.jsm')",
true);
const INTEGER = /^[1-9]\d*$/;