From 778252994f3f72cc51002c64910765c6249d6023 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Wed, 12 Dec 2018 17:58:19 -0800 Subject: [PATCH] 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 --- .../test/performance/browser_startup_content.js | 2 +- browser/installer/package-manifest.in | 1 - mobile/android/installer/package-manifest.in | 1 - .../content/tabswitch-content-process.js | 9 +++------ toolkit/components/extensions/Extension.jsm | 8 ++------ toolkit/components/extensions/ExtensionChild.jsm | 8 ++------ .../components/extensions/ExtensionContent.jsm | 6 ++---- .../components/extensions/ExtensionPageChild.jsm | 10 +++------- .../extensions/ExtensionPolicyService.cpp | 8 ++++++-- ...cess-script.js => ExtensionProcessScript.jsm} | 16 +++------------- .../extensions/extensions-toolkit.manifest | 4 ---- toolkit/components/extensions/moz.build | 2 +- .../extensions/mozIExtensionProcessScript.idl | 6 ++++++ .../test/xpcshell/test_ext_startup_perf.js | 1 + toolkit/mozapps/extensions/AddonManager.jsm | 2 +- 15 files changed, 31 insertions(+), 53 deletions(-) rename toolkit/components/extensions/{extension-process-script.js => ExtensionProcessScript.jsm} (96%) diff --git a/browser/base/content/test/performance/browser_startup_content.js b/browser/base/content/test/performance/browser_startup_content.js index fbfe16bb66c8..678e4bee11d1 100644 --- a/browser/base/content/test/performance/browser_startup_content.js +++ b/browser/base/content/test/performance/browser_startup_content.js @@ -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", ]), diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index e7a2672f1d57..df20841bdec6 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -359,7 +359,6 @@ ; [Extensions] @RESPATH@/components/extensions-toolkit.manifest -@RESPATH@/components/extension-process-script.js @RESPATH@/browser/components/extensions-browser.manifest ; [Normandy] diff --git a/mobile/android/installer/package-manifest.in b/mobile/android/installer/package-manifest.in index afc60f652e05..61e841a1e1af 100644 --- a/mobile/android/installer/package-manifest.in +++ b/mobile/android/installer/package-manifest.in @@ -264,7 +264,6 @@ ; [Extensions] @BINPATH@/components/extensions-toolkit.manifest @BINPATH@/components/extensions-mobile.manifest -@BINPATH@/components/extension-process-script.js ; Features @BINPATH@/features/* diff --git a/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js b/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js index 5a30aa3a1de5..c3d767f6a169 100644 --- a/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js +++ b/testing/talos/talos/tests/tabswitch/content/tabswitch-content-process.js @@ -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() { diff --git a/toolkit/components/extensions/Extension.jsm b/toolkit/components/extensions/Extension.jsm index b77c11ec04e0..355c6f1604ad 100644 --- a/toolkit/components/extensions/Extension.jsm +++ b/toolkit/components/extensions/Extension.jsm @@ -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); diff --git a/toolkit/components/extensions/ExtensionChild.jsm b/toolkit/components/extensions/ExtensionChild.jsm index 2e96faa710b7..b8dba83f249b 100644 --- a/toolkit/components/extensions/ExtensionChild.jsm +++ b/toolkit/components/extensions/ExtensionChild.jsm @@ -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); } diff --git a/toolkit/components/extensions/ExtensionContent.jsm b/toolkit/components/extensions/ExtensionContent.jsm index 4e6b6b86fca9..0685225f91cc 100644 --- a/toolkit/components/extensions/ExtensionContent.jsm +++ b/toolkit/components/extensions/ExtensionContent.jsm @@ -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); diff --git a/toolkit/components/extensions/ExtensionPageChild.jsm b/toolkit/components/extensions/ExtensionPageChild.jsm index 6d02fa83cc98..1277ab173308 100644 --- a/toolkit/components/extensions/ExtensionPageChild.jsm +++ b/toolkit/components/extensions/ExtensionPageChild.jsm @@ -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 { diff --git a/toolkit/components/extensions/ExtensionPolicyService.cpp b/toolkit/components/extensions/ExtensionPolicyService.cpp index aa878677e9de..e680bc08799c 100644 --- a/toolkit/components/extensions/ExtensionPolicyService.cpp +++ b/toolkit/components/extensions/ExtensionPolicyService.cpp @@ -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 sProcessScript; if (MOZ_UNLIKELY(!sProcessScript)) { - sProcessScript = - do_GetService("@mozilla.org/webextensions/extension-process-script;1"); + nsCOMPtr jsm = + do_ImportModule("resource://gre/modules/ExtensionProcessScript.jsm"); + MOZ_RELEASE_ASSERT(jsm); + + Unused << jsm->GetExtensionProcessScript(getter_AddRefs(sProcessScript)); MOZ_RELEASE_ASSERT(sProcessScript); ClearOnShutdown(&sProcessScript); } diff --git a/toolkit/components/extensions/extension-process-script.js b/toolkit/components/extensions/ExtensionProcessScript.jsm similarity index 96% rename from toolkit/components/extensions/extension-process-script.js rename to toolkit/components/extensions/ExtensionProcessScript.jsm index dff6b893d2c3..e48e51242490 100644 --- a/toolkit/components/extensions/extension-process-script.js +++ b/toolkit/components/extensions/ExtensionProcessScript.jsm @@ -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(); diff --git a/toolkit/components/extensions/extensions-toolkit.manifest b/toolkit/components/extensions/extensions-toolkit.manifest index 81224d5ad3af..1bb8d3182e52 100644 --- a/toolkit/components/extensions/extensions-toolkit.manifest +++ b/toolkit/components/extensions/extensions-toolkit.manifest @@ -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} diff --git a/toolkit/components/extensions/moz.build b/toolkit/components/extensions/moz.build index 5a914b518335..d2a053d52bb3 100644 --- a/toolkit/components/extensions/moz.build +++ b/toolkit/components/extensions/moz.build @@ -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', ] diff --git a/toolkit/components/extensions/mozIExtensionProcessScript.idl b/toolkit/components/extensions/mozIExtensionProcessScript.idl index 77df945d9086..8105f5fca653 100644 --- a/toolkit/components/extensions/mozIExtensionProcessScript.idl +++ b/toolkit/components/extensions/mozIExtensionProcessScript.idl @@ -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; +}; diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_startup_perf.js b/toolkit/components/extensions/test/xpcshell/test_ext_startup_perf.js index 2cf348e2648d..5d1d54bb9c8a 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_startup_perf.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_startup_perf.js @@ -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", ]; diff --git a/toolkit/mozapps/extensions/AddonManager.jsm b/toolkit/mozapps/extensions/AddonManager.jsm index 2dd84258fe2a..6107d1e6a246 100644 --- a/toolkit/mozapps/extensions/AddonManager.jsm +++ b/toolkit/mozapps/extensions/AddonManager.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*$/;