mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Backed out 10 changesets (bug 1728326) for causing build bustages. CLOSED TREE
Backed out changeset 39267f23ee63 (bug 1728326) Backed out changeset 070f187c2005 (bug 1728326) Backed out changeset f06e0af1bf81 (bug 1728326) Backed out changeset d21475767077 (bug 1728326) Backed out changeset 4ca5e36e3c71 (bug 1728326) Backed out changeset fd700124d69b (bug 1728326) Backed out changeset 5c8d87c04ac6 (bug 1728326) Backed out changeset 247504b7ea84 (bug 1728326) Backed out changeset de8879fc8126 (bug 1728326) Backed out changeset ebf25d0924d6 (bug 1728326)
This commit is contained in:
parent
1bc2d91d64
commit
a23f838d22
@ -216,14 +216,6 @@ interface nsIServiceWorkerManager : nsISupports
|
||||
[implicit_jscontext]
|
||||
Promise registerForAddonPrincipal(in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
* Get an extension background service worker registration for a
|
||||
* given extension principal, return an nsIServiceWorkerRegistrationInfo
|
||||
* if one exists (or null if no registration has been found).
|
||||
*/
|
||||
void getRegistrationForAddonPrincipal(in nsIPrincipal aPrincipal,
|
||||
[optional, retval] out nsIServiceWorkerRegistrationInfo regInfo);
|
||||
|
||||
/**
|
||||
* Unregister an existing ServiceWorker registration for `aScope`.
|
||||
* It keeps aCallback alive until the operation is concluded.
|
||||
|
@ -2740,41 +2740,6 @@ ServiceWorkerManager::RegisterForAddonPrincipal(nsIPrincipal* aPrincipal,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServiceWorkerManager::GetRegistrationForAddonPrincipal(
|
||||
nsIPrincipal* aPrincipal, nsIServiceWorkerRegistrationInfo** aInfo) {
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
|
||||
MOZ_ASSERT(aPrincipal);
|
||||
auto* addonPolicy = BasePrincipal::Cast(aPrincipal)->AddonPolicy();
|
||||
if (!addonPolicy) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCString scope;
|
||||
auto result = addonPolicy->GetURL(u""_ns);
|
||||
if (result.isOk()) {
|
||||
scope.Assign(NS_ConvertUTF16toUTF8(result.unwrap()));
|
||||
} else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURI> scopeURI;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(scopeURI), scope);
|
||||
if (NS_FAILED(rv)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
RefPtr<ServiceWorkerRegistrationInfo> info =
|
||||
GetServiceWorkerRegistrationInfo(aPrincipal, scopeURI);
|
||||
if (!info) {
|
||||
aInfo = nullptr;
|
||||
return NS_OK;
|
||||
}
|
||||
info.forget(aInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ServiceWorkerManager::GetRegistrationByPrincipal(
|
||||
nsIPrincipal* aPrincipal, const nsAString& aScope,
|
||||
|
@ -52,7 +52,6 @@
|
||||
#include "mozilla/dom/WorkerBinding.h"
|
||||
#include "mozilla/dom/JSExecutionManager.h"
|
||||
#include "mozilla/dom/WindowContext.h"
|
||||
#include "mozilla/extensions/ExtensionBrowser.h" // extensions::Create{AndDispatchInitWorkerContext,WorkerLoaded,WorkerDestroyed}Runnable
|
||||
#include "mozilla/extensions/WebExtensionPolicy.h"
|
||||
#include "mozilla/StorageAccess.h"
|
||||
#include "mozilla/StoragePrincipalHelper.h"
|
||||
@ -369,20 +368,6 @@ class CompileScriptRunnable final : public WorkerDebuggeeRunnable {
|
||||
ErrorResult rv;
|
||||
workerinternals::LoadMainScript(aWorkerPrivate, std::move(mOriginStack),
|
||||
mScriptURL, WorkerScript, rv);
|
||||
|
||||
if (aWorkerPrivate->ExtensionAPIAllowed()) {
|
||||
MOZ_ASSERT(aWorkerPrivate->IsServiceWorker());
|
||||
RefPtr<Runnable> extWorkerRunnable =
|
||||
extensions::CreateWorkerLoadedRunnable(
|
||||
aWorkerPrivate->ServiceWorkerID(), aWorkerPrivate->GetBaseURI());
|
||||
// Dispatch as a low priority runnable.
|
||||
if (NS_FAILED(aWorkerPrivate->DispatchToMainThreadForMessaging(
|
||||
extWorkerRunnable.forget()))) {
|
||||
NS_WARNING(
|
||||
"Failed to dispatch runnable to notify extensions worker loaded");
|
||||
}
|
||||
}
|
||||
|
||||
rv.WouldReportJSException();
|
||||
// Explicitly ignore NS_BINDING_ABORTED on rv. Or more precisely, still
|
||||
// return false and don't SetWorkerScriptExecutedSuccessfully() in that
|
||||
@ -3343,10 +3328,6 @@ void WorkerPrivate::ExecutionReady() {
|
||||
}
|
||||
|
||||
data->mScope->MutableClientSourceRef().WorkerExecutionReady(this);
|
||||
|
||||
if (ExtensionAPIAllowed()) {
|
||||
extensions::CreateAndDispatchInitWorkerContextRunnable();
|
||||
}
|
||||
}
|
||||
|
||||
void WorkerPrivate::InitializeGCTimers() {
|
||||
@ -3547,20 +3528,6 @@ void WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot) {
|
||||
NS_WARNING("Failed to dispatch runnable!");
|
||||
}
|
||||
} else {
|
||||
if (ExtensionAPIAllowed()) {
|
||||
MOZ_ASSERT(IsServiceWorker());
|
||||
RefPtr<Runnable> extWorkerRunnable =
|
||||
extensions::CreateWorkerDestroyedRunnable(ServiceWorkerID(),
|
||||
GetBaseURI());
|
||||
// Dispatch as a low priority runnable.
|
||||
if (NS_FAILED(
|
||||
DispatchToMainThreadForMessaging(extWorkerRunnable.forget()))) {
|
||||
NS_WARNING(
|
||||
"Failed to dispatch runnable to notify extensions worker "
|
||||
"destroyed");
|
||||
}
|
||||
}
|
||||
|
||||
// Note, this uses the lower priority DispatchToMainThreadForMessaging for
|
||||
// dispatching TopLevelWorkerFinishedRunnable to the main thread so that
|
||||
// other relevant runnables are guaranteed to run before it.
|
||||
@ -3569,12 +3536,6 @@ void WorkerPrivate::ScheduleDeletion(WorkerRanOrNot aRanOrNot) {
|
||||
if (NS_FAILED(DispatchToMainThreadForMessaging(runnable.forget()))) {
|
||||
NS_WARNING("Failed to dispatch runnable!");
|
||||
}
|
||||
|
||||
// NOTE: Calling any WorkerPrivate methods (or accessing member data) after
|
||||
// this point is unsafe (the TopLevelWorkerFinishedRunnable just dispatched
|
||||
// may be able to call ClearSelfAndParentEventTargetRef on this
|
||||
// WorkerPrivate instance and by the time we get here the WorkerPrivate
|
||||
// instance destructor may have been already called).
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,9 +170,11 @@ class WorkerPrivate final : public RelativeTimeline {
|
||||
}
|
||||
|
||||
bool ExtensionAPIAllowed() {
|
||||
return (
|
||||
StaticPrefs::extensions_backgroundServiceWorker_enabled_AtStartup() &&
|
||||
mExtensionAPIAllowed);
|
||||
// This method should never be actually called if the extension background
|
||||
// service worker is disabled by pref.
|
||||
MOZ_ASSERT(
|
||||
StaticPrefs::extensions_backgroundServiceWorker_enabled_AtStartup());
|
||||
return mExtensionAPIAllowed;
|
||||
}
|
||||
|
||||
void SetIsDebuggerRegistered(bool aDebuggerRegistered) {
|
||||
|
@ -757,13 +757,7 @@ class ChildAPIManager {
|
||||
|
||||
this.conduit = context.openConduit(this, {
|
||||
childId: this.id,
|
||||
send: [
|
||||
"CreateProxyContext",
|
||||
"ContextLoaded",
|
||||
"APICall",
|
||||
"AddListener",
|
||||
"RemoveListener",
|
||||
],
|
||||
send: ["CreateProxyContext", "APICall", "AddListener", "RemoveListener"],
|
||||
recv: ["CallResult", "RunListener"],
|
||||
});
|
||||
|
||||
|
@ -2293,7 +2293,7 @@ class EventManager {
|
||||
return;
|
||||
}
|
||||
primed.pendingEvents.push({ args, resolve, reject });
|
||||
extension.emit("background-script-event");
|
||||
extension.emit("background-page-event");
|
||||
});
|
||||
|
||||
let fire = {
|
||||
|
@ -166,11 +166,6 @@ function getContextChildManagerGetter(
|
||||
viewType: this.viewType,
|
||||
url: this.uri.spec,
|
||||
incognito: this.incognito,
|
||||
// Additional data a BaseContext subclass may optionally send
|
||||
// as part of the CreateProxyContext request sent to the main process
|
||||
// (e.g. WorkerContexChild implements this method to send the service
|
||||
// worker descriptor id along with the details send by default here).
|
||||
...this.getCreateProxyContextData?.(),
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -736,26 +736,6 @@ class DevToolsExtensionPageContextParent extends ExtensionPageContextParent {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The parent side of proxied API context for extension background service
|
||||
* worker script.
|
||||
*/
|
||||
class BackgroundWorkerContextParent extends ProxyContextParent {
|
||||
constructor(envType, extension, params) {
|
||||
// TODO: split out from ProxyContextParent a base class that
|
||||
// doesn't expect a xulBrowser and one for contexts that are
|
||||
// expected to have a xulBrowser associated.
|
||||
super(envType, extension, params, null, extension.principal);
|
||||
|
||||
this.viewType = params.viewType;
|
||||
this.workerDescriptorId = params.workerDescriptorId;
|
||||
|
||||
this.extension.views.add(this);
|
||||
|
||||
extension.emit("extension-proxy-context-load", this);
|
||||
}
|
||||
}
|
||||
|
||||
ParentAPIManager = {
|
||||
proxyContexts: new Map(),
|
||||
|
||||
@ -766,13 +746,7 @@ ParentAPIManager = {
|
||||
this.conduit = new BroadcastConduit(this, {
|
||||
id: "ParentAPIManager",
|
||||
reportOnClosed: "childId",
|
||||
recv: [
|
||||
"CreateProxyContext",
|
||||
"ContextLoaded",
|
||||
"APICall",
|
||||
"AddListener",
|
||||
"RemoveListener",
|
||||
],
|
||||
recv: ["CreateProxyContext", "APICall", "AddListener", "RemoveListener"],
|
||||
send: ["CallResult"],
|
||||
query: ["RunListener"],
|
||||
});
|
||||
@ -864,9 +838,7 @@ ParentAPIManager = {
|
||||
}
|
||||
}
|
||||
|
||||
if (envType == "addon_parent" && data.viewType === "background_worker") {
|
||||
context = new BackgroundWorkerContextParent(envType, extension, data);
|
||||
} else if (envType == "addon_parent") {
|
||||
if (envType == "addon_parent") {
|
||||
context = new ExtensionPageContextParent(
|
||||
envType,
|
||||
extension,
|
||||
@ -895,13 +867,6 @@ ParentAPIManager = {
|
||||
this.proxyContexts.set(childId, context);
|
||||
},
|
||||
|
||||
recvContextLoaded(data, { actor, sender }) {
|
||||
let context = this.getContextById(data.childId);
|
||||
verifyActorForContext(actor, context);
|
||||
const { extension } = context;
|
||||
extension.emit("extension-proxy-context-load:completed", context);
|
||||
},
|
||||
|
||||
recvConduitClosed(sender) {
|
||||
this.closeProxyContext(sender.id);
|
||||
},
|
||||
@ -1597,40 +1562,6 @@ function watchExtensionProxyContextLoad(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper is used to subscribe a listener (e.g. in the ext-backgroundPage)
|
||||
* to be called for every ExtensionProxyContext created for an extension
|
||||
* background service worker given its related extension.
|
||||
*
|
||||
* @param {object} params.extension
|
||||
* The Extension on which we are going to listen for the newly created ExtensionProxyContext.
|
||||
* @param {function} onExtensionWorkerContextLoaded
|
||||
* The callback that is called when the worker script has been fully loaded (as `callback(context)`);
|
||||
*
|
||||
* @returns {function}
|
||||
* Unsubscribe the listener.
|
||||
*/
|
||||
function watchExtensionWorkerContextLoaded(
|
||||
{ extension },
|
||||
onExtensionWorkerContextLoaded
|
||||
) {
|
||||
if (typeof onExtensionWorkerContextLoaded !== "function") {
|
||||
throw new Error("Missing onExtensionWorkerContextLoaded handler");
|
||||
}
|
||||
|
||||
const listener = (event, context) => {
|
||||
if (context.viewType == "background_worker") {
|
||||
onExtensionWorkerContextLoaded(context);
|
||||
}
|
||||
};
|
||||
|
||||
extension.on("extension-proxy-context-load:completed", listener);
|
||||
|
||||
return () => {
|
||||
extension.off("extension-proxy-context-load:completed", listener);
|
||||
};
|
||||
}
|
||||
|
||||
// Manages icon details for toolbar buttons in the |pageAction| and
|
||||
// |browserAction| APIs.
|
||||
let IconDetails = {
|
||||
@ -1983,7 +1914,6 @@ var ExtensionParent = {
|
||||
apiManager,
|
||||
promiseExtensionViewLoaded,
|
||||
watchExtensionProxyContextLoad,
|
||||
watchExtensionWorkerContextLoaded,
|
||||
DebugUtils,
|
||||
};
|
||||
|
||||
|
@ -346,32 +346,6 @@ var ExtensionProcessScript = {
|
||||
};
|
||||
|
||||
var ExtensionAPIRequestHandler = {
|
||||
initExtensionWorker(policy, serviceWorkerInfo) {
|
||||
let extension = extensions.get(policy);
|
||||
|
||||
if (!extension) {
|
||||
throw new Error(`Extension instance not found for addon ${policy.id}`);
|
||||
}
|
||||
|
||||
ExtensionWorkerChild.initExtensionWorkerContext(
|
||||
extension,
|
||||
serviceWorkerInfo
|
||||
);
|
||||
},
|
||||
|
||||
onExtensionWorkerLoaded(policy, serviceWorkerDescriptorId) {
|
||||
ExtensionWorkerChild.notifyExtensionWorkerContextLoaded(
|
||||
serviceWorkerDescriptorId,
|
||||
policy
|
||||
);
|
||||
},
|
||||
|
||||
onExtensionWorkerDestroyed(policy, serviceWorkerDescriptorId) {
|
||||
ExtensionWorkerChild.destroyExtensionWorkerContext(
|
||||
serviceWorkerDescriptorId
|
||||
);
|
||||
},
|
||||
|
||||
handleAPIRequest(policy, request) {
|
||||
try {
|
||||
let extension = extensions.get(policy);
|
||||
@ -385,12 +359,6 @@ var ExtensionAPIRequestHandler = {
|
||||
request,
|
||||
});
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
`Extension context not found for API request: ${request}`
|
||||
);
|
||||
}
|
||||
|
||||
// Add a property to the request object for the normalizedArgs.
|
||||
request.normalizedArgs = this.validateAndNormalizeRequestArgs({
|
||||
context,
|
||||
@ -411,14 +379,36 @@ var ExtensionAPIRequestHandler = {
|
||||
},
|
||||
|
||||
getExtensionContextForAPIRequest({ extension, request }) {
|
||||
if (request.serviceWorkerInfo) {
|
||||
return ExtensionWorkerChild.getExtensionWorkerContext(
|
||||
let context;
|
||||
|
||||
if (request.window) {
|
||||
throw new Error(
|
||||
`Extension API request originated from an extension window are not yet supported`
|
||||
);
|
||||
} else if (request.serviceWorkerInfo) {
|
||||
context = ExtensionWorkerChild.getContextForWorker(
|
||||
extension,
|
||||
request.serviceWorkerInfo
|
||||
);
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
`Extension context not found for the extension service worker`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw new Error(
|
||||
`Extension API request originated from an unsupported extension global`
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
if (!context.useWebIDLBindings) {
|
||||
const { viewType, contextId } = context;
|
||||
throw new Error(
|
||||
`Extension ${extension.id} context "${viewType}" ${contextId} does not support WebIDL bindings`
|
||||
);
|
||||
}
|
||||
|
||||
return context;
|
||||
},
|
||||
|
||||
validateAndNormalizeRequestArgs({ context, request }) {
|
||||
|
@ -594,7 +594,6 @@ class WorkerContextChild extends BaseContext {
|
||||
this.viewType = "background_worker";
|
||||
this.uri = Services.io.newURI(serviceWorkerInfo.scriptURL);
|
||||
this.workerClientInfoId = serviceWorkerInfo.clientInfoId;
|
||||
this.workerDescriptorId = serviceWorkerInfo.descriptorId;
|
||||
this.workerPrincipal = serviceWorkerInfo.principal;
|
||||
this.incognito = serviceWorkerInfo.principal.privateBrowsingId > 0;
|
||||
|
||||
@ -619,11 +618,6 @@ class WorkerContextChild extends BaseContext {
|
||||
};
|
||||
}
|
||||
|
||||
getCreateProxyContextData() {
|
||||
const { workerDescriptorId } = this;
|
||||
return { workerDescriptorId };
|
||||
}
|
||||
|
||||
openConduit(subject, address) {
|
||||
let proc = ChromeUtils.domProcessChild;
|
||||
let conduit = proc.getActor("ProcessConduits").openConduit(subject, {
|
||||
@ -631,7 +625,6 @@ class WorkerContextChild extends BaseContext {
|
||||
extensionId: this.extension.id,
|
||||
envType: this.envType,
|
||||
workerScriptURL: this.uri.spec,
|
||||
workerDescriptorId: this.workerDescriptorId,
|
||||
...address,
|
||||
});
|
||||
this.callOnClose(conduit);
|
||||
@ -641,14 +634,6 @@ class WorkerContextChild extends BaseContext {
|
||||
return conduit;
|
||||
}
|
||||
|
||||
notifyWorkerLoaded() {
|
||||
this.childManager.conduit.sendContextLoaded({
|
||||
childId: this.childManager.id,
|
||||
extensionId: this.extension.id,
|
||||
workerDescriptorId: this.workerDescriptorId,
|
||||
});
|
||||
}
|
||||
|
||||
withAPIRequest(request, callable) {
|
||||
this.webidlAPIRequest = request;
|
||||
try {
|
||||
@ -719,101 +704,31 @@ defineLazyGetter(
|
||||
);
|
||||
|
||||
var ExtensionWorkerChild = {
|
||||
// Map<serviceWorkerDescriptorId, ExtensionWorkerContextChild>
|
||||
// Map<workerClientInfoId, ExtensionWorkerContextChild>
|
||||
extensionWorkerContexts: new Map(),
|
||||
|
||||
apiManager: ExtensionPageChild.apiManager,
|
||||
|
||||
/**
|
||||
* Create an extension worker context (on a mozExtensionAPIRequest with
|
||||
* requestType "initWorkerContext").
|
||||
*
|
||||
* @param {BrowserExtensionContent} extension
|
||||
* The extension for which the context should be created.
|
||||
* @param {mozIExtensionServiceWorkerInfo} serviceWorkerInfo
|
||||
*/
|
||||
initExtensionWorkerContext(extension, serviceWorkerInfo) {
|
||||
if (!WebExtensionPolicy.isExtensionProcess) {
|
||||
throw new Error(
|
||||
"Cannot create an extension worker context in current process"
|
||||
);
|
||||
}
|
||||
|
||||
const swId = serviceWorkerInfo.descriptorId;
|
||||
let context = this.extensionWorkerContexts.get(swId);
|
||||
if (context) {
|
||||
if (context.extension !== extension) {
|
||||
throw new Error(
|
||||
"A different extension context already exists for this service worker"
|
||||
);
|
||||
}
|
||||
throw new Error(
|
||||
"An extension context was already initialized for this service worker"
|
||||
);
|
||||
}
|
||||
|
||||
context = new WorkerContextChild(extension, { serviceWorkerInfo });
|
||||
this.extensionWorkerContexts.set(swId, context);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get an existing extension worker context for the given extension and
|
||||
* service worker.
|
||||
*
|
||||
* @param {BrowserExtensionContent} extension
|
||||
* The extension for which the context should be created.
|
||||
* @param {mozIExtensionServiceWorkerInfo} serviceWorkerInfo
|
||||
*
|
||||
* @returns {ExtensionWorkerContextChild}
|
||||
*/
|
||||
getExtensionWorkerContext(extension, serviceWorkerInfo) {
|
||||
getContextForWorker(extension, serviceWorkerInfo) {
|
||||
if (!serviceWorkerInfo) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const context = this.extensionWorkerContexts.get(
|
||||
serviceWorkerInfo.descriptorId
|
||||
let context = this.extensionWorkerContexts.get(
|
||||
serviceWorkerInfo.clientInfoId
|
||||
);
|
||||
|
||||
if (context?.extension === extension) {
|
||||
if (context && context.extension === extension) {
|
||||
return context;
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
// Lazily create the context.
|
||||
if (!context) {
|
||||
context = new WorkerContextChild(extension, { serviceWorkerInfo });
|
||||
|
||||
/**
|
||||
* Notify the main process when an extension worker script has been loaded.
|
||||
*
|
||||
* @param {number} descriptorId The service worker descriptor ID of the destroyed context.
|
||||
* @param {WebExtensionPolicy} policy
|
||||
*/
|
||||
notifyExtensionWorkerContextLoaded(descriptorId, policy) {
|
||||
let context = this.extensionWorkerContexts.get(descriptorId);
|
||||
if (context) {
|
||||
if (context.extension.id !== policy.id) {
|
||||
Cu.reportError(
|
||||
new Error(
|
||||
`ServiceWorker ${descriptorId} does not belong to the expected extension: ${policy.id}`
|
||||
)
|
||||
);
|
||||
return;
|
||||
}
|
||||
context.notifyWorkerLoaded();
|
||||
this.extensionWorkerContexts.set(serviceWorkerInfo.clientInfoId, context);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Close the ExtensionWorkerContextChild belonging to the given service worker, if any.
|
||||
*
|
||||
* @param {number} descriptorId The service worker descriptor ID of the destroyed context.
|
||||
*/
|
||||
destroyExtensionWorkerContext(descriptorId) {
|
||||
let context = this.extensionWorkerContexts.get(descriptorId);
|
||||
if (context) {
|
||||
context.unload();
|
||||
this.extensionWorkerContexts.delete(descriptorId);
|
||||
}
|
||||
return context;
|
||||
},
|
||||
|
||||
shutdownExtension(extensionId) {
|
||||
|
@ -12,7 +12,6 @@ interface mozIExtensionServiceWorkerInfo : nsISupports
|
||||
readonly attribute nsIPrincipal principal;
|
||||
readonly attribute AString scriptURL;
|
||||
readonly attribute AString clientInfoId;
|
||||
readonly attribute unsigned long long descriptorId;
|
||||
};
|
||||
|
||||
[scriptable, uuid(876d45db-5c1b-4c9b-9148-1c86b33d120b)]
|
||||
@ -160,33 +159,4 @@ interface mozIExtensionAPIRequestHandler : nsISupports
|
||||
void handleAPIRequest(in nsISupports extension,
|
||||
in mozIExtensionAPIRequest apiRequest,
|
||||
[optional, retval] out mozIExtensionAPIRequestResult apiRequestResult);
|
||||
|
||||
/**
|
||||
* A method called when an extension background service worker is initialized and
|
||||
* ready to execute its main script.
|
||||
*
|
||||
* @param extension An instance of the WebExtensionPolicy webidl interface.
|
||||
* @param serviceWorkerInfo
|
||||
*/
|
||||
void initExtensionWorker(in nsISupports extension,
|
||||
in mozIExtensionServiceWorkerInfo serviceWorkerInfo);
|
||||
|
||||
/**
|
||||
* A method called when an extension background service worker has loaded its
|
||||
* main script.
|
||||
*
|
||||
* @param extension An instance of the WebExtensionPolicy webidl interface.
|
||||
* @param serviceWorkerDescriptorId
|
||||
*/
|
||||
void onExtensionWorkerLoaded(in nsISupports extension,
|
||||
in unsigned long long serviceWorkerDescriptorId);
|
||||
|
||||
/**
|
||||
* A method called when an extension background service worker is destroyed.
|
||||
*
|
||||
* @param extension An instance of the WebExtensionPolicy webidl interface.
|
||||
* @param serviceWorkerDescriptorId
|
||||
*/
|
||||
void onExtensionWorkerDestroyed(in nsISupports extension,
|
||||
in unsigned long long serviceWorkerDescriptorId);
|
||||
};
|
||||
|
@ -7,11 +7,7 @@
|
||||
var { ExtensionParent } = ChromeUtils.import(
|
||||
"resource://gre/modules/ExtensionParent.jsm"
|
||||
);
|
||||
var {
|
||||
HiddenExtensionPage,
|
||||
promiseExtensionViewLoaded,
|
||||
watchExtensionWorkerContextLoaded,
|
||||
} = ExtensionParent;
|
||||
var { HiddenExtensionPage, promiseExtensionViewLoaded } = ExtensionParent;
|
||||
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
@ -83,7 +79,7 @@ class BackgroundPage extends HiddenExtensionPage {
|
||||
if (extension.persistentListeners) {
|
||||
EventManager.clearPrimedListeners(this.extension, false);
|
||||
}
|
||||
extension.emit("background-script-aborted");
|
||||
extension.emit("background-page-aborted");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -103,7 +99,7 @@ class BackgroundPage extends HiddenExtensionPage {
|
||||
EventManager.clearPrimedListeners(extension, !!this.extension);
|
||||
}
|
||||
|
||||
extension.emit("background-script-started");
|
||||
extension.emit("background-page-started");
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
@ -115,6 +111,7 @@ class BackgroundPage extends HiddenExtensionPage {
|
||||
// Responsible for the background.service_worker section of the manifest.
|
||||
class BackgroundWorker {
|
||||
constructor(extension, options) {
|
||||
this.registrationInfo = null;
|
||||
this.extension = extension;
|
||||
this.workerScript = options.service_worker;
|
||||
|
||||
@ -123,48 +120,21 @@ class BackgroundWorker {
|
||||
}
|
||||
}
|
||||
|
||||
get registrationInfo() {
|
||||
const { principal } = this.extension;
|
||||
return serviceWorkerManager.getRegistrationForAddonPrincipal(principal);
|
||||
}
|
||||
|
||||
getWorkerInfo(descriptorId) {
|
||||
return this.registrationInfo?.getWorkerByID(descriptorId);
|
||||
}
|
||||
|
||||
validateWorkerInfoForContext(context) {
|
||||
const { extension } = this;
|
||||
if (!this.getWorkerInfo(context.workerDescriptorId)) {
|
||||
throw new Error(
|
||||
`ServiceWorkerInfo not found for ${extension.policy.debugName} contextId ${context.contextId}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async build() {
|
||||
const { extension } = this;
|
||||
|
||||
let context;
|
||||
try {
|
||||
const contextPromise = new Promise(resolve => {
|
||||
let unwatch = watchExtensionWorkerContextLoaded(
|
||||
{ extension, viewType: "background_worker" },
|
||||
context => {
|
||||
unwatch();
|
||||
this.validateWorkerInfoForContext(context);
|
||||
resolve(context);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
// TODO(Bug 17228327): follow up to spawn the active worker for a previously installed
|
||||
// background service worker.
|
||||
await serviceWorkerManager.registerForAddonPrincipal(
|
||||
const regInfo = await serviceWorkerManager.registerForAddonPrincipal(
|
||||
this.extension.principal
|
||||
);
|
||||
this.registrationInfo = regInfo.QueryInterface(
|
||||
Ci.nsIServiceWorkerRegistrationInfo
|
||||
);
|
||||
|
||||
context = await contextPromise;
|
||||
|
||||
// TODO(bug 17228326): wait for worker context to be loaded (as we currently do
|
||||
// for the delayed background page).
|
||||
await this.waitForActiveWorker();
|
||||
} catch (e) {
|
||||
// Extension may be shutting down before the background worker has registered or
|
||||
@ -175,16 +145,15 @@ class BackgroundWorker {
|
||||
EventManager.clearPrimedListeners(this.extension, false);
|
||||
}
|
||||
|
||||
extension.emit("background-script-aborted");
|
||||
// TODO(bug 17228326): rename this to "background-script-aborted".
|
||||
extension.emit("background-page-aborted");
|
||||
return;
|
||||
}
|
||||
|
||||
if (context) {
|
||||
// Wait until all event listeners registered by the script so far
|
||||
// to be handled.
|
||||
await Promise.all(context.listenerPromises);
|
||||
context.listenerPromises = null;
|
||||
}
|
||||
// TODO(bug 17228326): wait for worker context to be loaded and
|
||||
// wait for all persistent event listeners registered by the worker
|
||||
// script to be handled (as we currently do for the delayed background
|
||||
// page).
|
||||
|
||||
if (extension.persistentListeners) {
|
||||
// |this.extension| may be null if the extension was shut down.
|
||||
@ -193,7 +162,8 @@ class BackgroundWorker {
|
||||
EventManager.clearPrimedListeners(extension, !!this.extension);
|
||||
}
|
||||
|
||||
extension.emit("background-script-started");
|
||||
// TODO(bug 17228326): rename this to "background-script-started".
|
||||
extension.emit("background-page-started");
|
||||
}
|
||||
|
||||
shutdown(isAppShutdown) {
|
||||
@ -205,6 +175,8 @@ class BackgroundWorker {
|
||||
if (!isAppShutdown) {
|
||||
this.registrationInfo?.forceShutdown();
|
||||
}
|
||||
|
||||
this.registrationInfo = null;
|
||||
}
|
||||
|
||||
waitForActiveWorker() {
|
||||
@ -284,18 +256,18 @@ this.backgroundPage = class extends ExtensionAPI {
|
||||
// Used by runtime messaging to wait for background page listeners.
|
||||
let bgStartupPromise = new Promise(resolve => {
|
||||
let done = () => {
|
||||
extension.off("background-script-started", done);
|
||||
extension.off("background-script-aborted", done);
|
||||
extension.off("background-page-started", done);
|
||||
extension.off("background-page-aborted", done);
|
||||
extension.off("shutdown", done);
|
||||
resolve();
|
||||
};
|
||||
extension.on("background-script-started", done);
|
||||
extension.on("background-script-aborted", done);
|
||||
extension.on("background-page-started", done);
|
||||
extension.on("background-page-aborted", done);
|
||||
extension.on("shutdown", done);
|
||||
});
|
||||
|
||||
extension.wakeupBackground = () => {
|
||||
extension.emit("background-script-event");
|
||||
extension.emit("background-page-event");
|
||||
extension.wakeupBackground = () => bgStartupPromise;
|
||||
return bgStartupPromise;
|
||||
};
|
||||
@ -306,7 +278,7 @@ this.backgroundPage = class extends ExtensionAPI {
|
||||
|
||||
EventManager.primeListeners(extension);
|
||||
|
||||
extension.once("start-background-script", async () => {
|
||||
extension.once("start-background-page", async () => {
|
||||
if (!this.extension) {
|
||||
// Extension was shut down. Don't build the background page.
|
||||
// Primed listeners have been cleared in onShutdown.
|
||||
@ -322,13 +294,13 @@ this.backgroundPage = class extends ExtensionAPI {
|
||||
// or else we can miss it if the event occurs after the first
|
||||
// window is painted but before #2
|
||||
// 2. After all windows have been restored.
|
||||
extension.once("background-script-event", async () => {
|
||||
extension.once("background-page-event", async () => {
|
||||
await ExtensionParent.browserPaintedPromise;
|
||||
extension.emit("start-background-script");
|
||||
extension.emit("start-background-page");
|
||||
});
|
||||
|
||||
ExtensionParent.browserStartupPromise.then(() => {
|
||||
extension.emit("start-background-script");
|
||||
extension.emit("start-background-page");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,9 @@ this.runtime = class extends ExtensionAPI {
|
||||
return () => {};
|
||||
}
|
||||
let listener = () => fire.sync();
|
||||
extension.on("background-script-started", listener);
|
||||
extension.on("background-page-started", listener);
|
||||
return () => {
|
||||
extension.off("background-script-started", listener);
|
||||
extension.off("background-page-started", listener);
|
||||
};
|
||||
},
|
||||
}).api(),
|
||||
@ -70,9 +70,9 @@ this.runtime = class extends ExtensionAPI {
|
||||
break;
|
||||
}
|
||||
};
|
||||
extension.on("background-script-started", listener);
|
||||
extension.on("background-page-started", listener);
|
||||
return () => {
|
||||
extension.off("background-script-started", listener);
|
||||
extension.off("background-page-started", listener);
|
||||
};
|
||||
},
|
||||
}).api(),
|
||||
|
@ -125,25 +125,19 @@ add_task(async function test_unload_extension_during_background_page_startup() {
|
||||
|
||||
let bgStartupPromise = new Promise(resolve => {
|
||||
function onBackgroundPageDone(eventName) {
|
||||
extension.extension.off(
|
||||
"background-script-started",
|
||||
onBackgroundPageDone
|
||||
);
|
||||
extension.extension.off(
|
||||
"background-script-aborted",
|
||||
onBackgroundPageDone
|
||||
);
|
||||
extension.extension.off("background-page-started", onBackgroundPageDone);
|
||||
extension.extension.off("background-page-aborted", onBackgroundPageDone);
|
||||
|
||||
if (eventName === "background-script-aborted") {
|
||||
info("Background script startup was interrupted");
|
||||
if (eventName === "background-page-aborted") {
|
||||
info("Background page startup was interrupted");
|
||||
resolve("bg_aborted");
|
||||
} else {
|
||||
info("Background script startup finished normally");
|
||||
info("Background page startup finished normally");
|
||||
resolve("bg_fully_loaded");
|
||||
}
|
||||
}
|
||||
extension.extension.on("background-script-started", onBackgroundPageDone);
|
||||
extension.extension.on("background-script-aborted", onBackgroundPageDone);
|
||||
extension.extension.on("background-page-started", onBackgroundPageDone);
|
||||
extension.extension.on("background-page-aborted", onBackgroundPageDone);
|
||||
});
|
||||
|
||||
let bgStartingPromise = new Promise(resolve => {
|
||||
|
@ -418,7 +418,7 @@ add_task(async function test_serviceworker_lifecycle_events() {
|
||||
info(
|
||||
"trigger delayed call to nsIServiceWorkerManager.registerForAddonPrincipal"
|
||||
);
|
||||
extension.extension.emit("start-background-script");
|
||||
extension.extension.emit("start-background-page");
|
||||
|
||||
info("Force activate the extension worker");
|
||||
const newSwReg = swm.getRegistrationByPrincipal(
|
||||
|
@ -27,7 +27,7 @@ const PAGE_HTML = `<!DOCTYPE html><meta charset="utf-8"><script src="script.js">
|
||||
|
||||
function trackEvents(wrapper) {
|
||||
let events = new Map();
|
||||
for (let event of ["background-script-event", "start-background-script"]) {
|
||||
for (let event of ["background-page-event", "start-background-page"]) {
|
||||
events.set(event, false);
|
||||
wrapper.extension.once(event, () => events.set(event, true));
|
||||
}
|
||||
@ -67,7 +67,7 @@ async function test(what, background, script) {
|
||||
|
||||
function awaitBgEvent() {
|
||||
return new Promise(resolve =>
|
||||
extension.extension.once("background-script-event", resolve)
|
||||
extension.extension.once("background-page-event", resolve)
|
||||
);
|
||||
}
|
||||
|
||||
@ -81,12 +81,12 @@ async function test(what, background, script) {
|
||||
]);
|
||||
|
||||
equal(
|
||||
events.get("background-script-event"),
|
||||
events.get("background-page-event"),
|
||||
true,
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
false,
|
||||
"Background page should not be started"
|
||||
);
|
||||
@ -98,9 +98,9 @@ async function test(what, background, script) {
|
||||
await promise;
|
||||
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
true,
|
||||
"Should have gotten start-background-script event"
|
||||
"Should have gotten start-background-page event"
|
||||
);
|
||||
|
||||
await extension.awaitFinish("messaging-test");
|
||||
@ -123,14 +123,14 @@ async function test(what, background, script) {
|
||||
]);
|
||||
|
||||
equal(
|
||||
events.get("background-script-event"),
|
||||
events.get("background-page-event"),
|
||||
true,
|
||||
"Should have gotten a background script event"
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
false,
|
||||
"Background script should not be started"
|
||||
"Background page should not be started"
|
||||
);
|
||||
|
||||
equal(extension.messageQueue.size, 0, "Have not yet received bg-ran message");
|
||||
@ -140,9 +140,9 @@ async function test(what, background, script) {
|
||||
await promise;
|
||||
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
true,
|
||||
"Should have gotten start-background-script event"
|
||||
"Should have gotten start-background-page event"
|
||||
);
|
||||
|
||||
await extension.awaitFinish("messaging-test");
|
||||
|
@ -451,7 +451,7 @@ add_task(async function test_shutdown_before_background_loaded() {
|
||||
fireWakeupBeforeBgFail = fire.wakeup();
|
||||
fireAsyncBeforeBgFail = fire.async();
|
||||
|
||||
extension.extension.once("background-script-aborted", resolve);
|
||||
extension.extension.once("background-page-aborted", resolve);
|
||||
info("Forcing the background load to fail");
|
||||
browser.remove();
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ function promiseExtensionEvent(wrapper, event) {
|
||||
|
||||
function trackEvents(wrapper) {
|
||||
let events = new Map();
|
||||
for (let event of ["background-script-event", "start-background-script"]) {
|
||||
for (let event of ["background-page-event", "start-background-page"]) {
|
||||
events.set(event, false);
|
||||
wrapper.extension.once(event, () => events.set(event, true));
|
||||
}
|
||||
@ -112,9 +112,9 @@ add_task(async function test_proxy_startup() {
|
||||
equal(2, nonProxiedRequests, "non proxied request ok");
|
||||
|
||||
equal(
|
||||
events.get("background-script-event"),
|
||||
events.get("background-page-event"),
|
||||
false,
|
||||
"Should not have gotten a background script event"
|
||||
"Should not have gotten a background page event"
|
||||
);
|
||||
|
||||
// Make a request that the extension will proxy once it is started.
|
||||
@ -123,27 +123,27 @@ add_task(async function test_proxy_startup() {
|
||||
ExtensionTestUtils.fetch("http://proxied.example.com/?a=1"),
|
||||
]);
|
||||
|
||||
await promiseExtensionEvent(extension, "background-script-event");
|
||||
await promiseExtensionEvent(extension, "background-page-event");
|
||||
equal(
|
||||
events.get("background-script-event"),
|
||||
events.get("background-page-event"),
|
||||
true,
|
||||
"Should have gotten a background script event"
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
|
||||
// Test the background page startup.
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
false,
|
||||
"Should have gotten a background script event"
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
|
||||
Services.obs.notifyObservers(null, "browser-delayed-startup-finished");
|
||||
await new Promise(executeSoon);
|
||||
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
true,
|
||||
"Should have gotten a background script event"
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
|
||||
// Verify our proxied request finishes properly and that the
|
||||
|
@ -38,7 +38,7 @@ Services.prefs.setBoolPref(
|
||||
|
||||
function trackEvents(wrapper) {
|
||||
let events = new Map();
|
||||
for (let event of ["background-script-event", "start-background-script"]) {
|
||||
for (let event of ["background-page-event", "start-background-page"]) {
|
||||
events.set(event, false);
|
||||
wrapper.extension.once(event, () => events.set(event, true));
|
||||
}
|
||||
@ -47,23 +47,23 @@ function trackEvents(wrapper) {
|
||||
|
||||
async function testPersistentRequestStartup(extension, events, expect) {
|
||||
equal(
|
||||
events.get("background-script-event"),
|
||||
events.get("background-page-event"),
|
||||
expect.background,
|
||||
"Should have gotten a background script event"
|
||||
"Should have gotten a background page event"
|
||||
);
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
false,
|
||||
"Background script should not be started"
|
||||
"Background page should not be started"
|
||||
);
|
||||
|
||||
Services.obs.notifyObservers(null, "browser-delayed-startup-finished");
|
||||
await ExtensionParent.browserPaintedPromise;
|
||||
|
||||
equal(
|
||||
events.get("start-background-script"),
|
||||
events.get("start-background-page"),
|
||||
expect.delayedStart,
|
||||
"Should have gotten start-background-script event"
|
||||
"Should have gotten start-background-page event"
|
||||
);
|
||||
|
||||
if (expect.request) {
|
||||
|
@ -43,13 +43,6 @@ ExtensionServiceWorkerInfo::GetClientInfoId(nsAString& aClientInfoId) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ExtensionServiceWorkerInfo::GetDescriptorId(uint64_t* aDescriptorId) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
*aDescriptorId = mDescriptorId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// mozIExtensionAPIRequest
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ExtensionAPIRequest)
|
||||
@ -91,12 +84,10 @@ ExtensionAPIRequest::ExtensionAPIRequest(
|
||||
}
|
||||
|
||||
void ExtensionAPIRequest::Init(Maybe<dom::ClientInfo>& aSWClientInfo,
|
||||
const uint64_t aSWDescriptorId,
|
||||
JS::HandleValue aRequestArgs,
|
||||
JS::HandleValue aCallerStack) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mSWClientInfo = aSWClientInfo;
|
||||
mSWDescriptorId = aSWDescriptorId;
|
||||
mArgs.set(aRequestArgs);
|
||||
mStack.set(aCallerStack);
|
||||
mNormalizedArgs.setUndefined();
|
||||
@ -224,7 +215,7 @@ ExtensionAPIRequest::GetServiceWorkerInfo(
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
NS_ENSURE_ARG_POINTER(aSWInfo);
|
||||
if (mSWClientInfo.isSome() && !mSWInfo) {
|
||||
mSWInfo = new ExtensionServiceWorkerInfo(*mSWClientInfo, mSWDescriptorId);
|
||||
mSWInfo = new ExtensionServiceWorkerInfo(*mSWClientInfo);
|
||||
}
|
||||
NS_IF_ADDREF(*aSWInfo = mSWInfo);
|
||||
return NS_OK;
|
||||
|
@ -38,15 +38,13 @@ class ExtensionServiceWorkerInfo : public mozIExtensionServiceWorkerInfo {
|
||||
NS_DECL_MOZIEXTENSIONSERVICEWORKERINFO
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
explicit ExtensionServiceWorkerInfo(const dom::ClientInfo& aClientInfo,
|
||||
const uint64_t aDescriptorId)
|
||||
: mClientInfo(aClientInfo), mDescriptorId(aDescriptorId) {}
|
||||
explicit ExtensionServiceWorkerInfo(const dom::ClientInfo& aClientInfo)
|
||||
: mClientInfo(aClientInfo) {}
|
||||
|
||||
private:
|
||||
virtual ~ExtensionServiceWorkerInfo() = default;
|
||||
|
||||
dom::ClientInfo mClientInfo;
|
||||
uint64_t mDescriptorId;
|
||||
};
|
||||
|
||||
// A class that represents a WebExtensions API request (a method call,
|
||||
@ -64,8 +62,7 @@ class ExtensionAPIRequest : public mozIExtensionAPIRequest {
|
||||
const mozIExtensionAPIRequest::RequestType aRequestType,
|
||||
const ExtensionAPIRequestTarget& aRequestTarget);
|
||||
|
||||
void Init(Maybe<dom::ClientInfo>& aSWClientInfo,
|
||||
const uint64_t aSWDescriptorId, JS::HandleValue aRequestArgs,
|
||||
void Init(Maybe<dom::ClientInfo>& aSWClientInfo, JS::HandleValue aRequestArgs,
|
||||
JS::HandleValue aCallerStack);
|
||||
|
||||
static bool ShouldHaveResult(const APIRequestType& aRequestType) {
|
||||
@ -108,7 +105,6 @@ class ExtensionAPIRequest : public mozIExtensionAPIRequest {
|
||||
JS::Heap<JS::Value> mArgs;
|
||||
JS::Heap<JS::Value> mNormalizedArgs;
|
||||
Maybe<dom::ClientInfo> mSWClientInfo;
|
||||
uint64_t mSWDescriptorId;
|
||||
RefPtr<ExtensionServiceWorkerInfo> mSWInfo;
|
||||
|
||||
// Only set for addListener/removeListener API requests.
|
||||
|
@ -291,8 +291,6 @@ void RequestWorkerRunnable::Init(nsIGlobalObject* aGlobal, JSContext* aCx,
|
||||
ErrorResult& aRv) {
|
||||
MOZ_ASSERT(dom::IsCurrentThreadRunningWorker());
|
||||
|
||||
mSWDescriptorId = mWorkerPrivate->ServiceWorkerID();
|
||||
|
||||
auto* workerScope = mWorkerPrivate->GlobalScope();
|
||||
if (NS_WARN_IF(!workerScope)) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
@ -428,7 +426,7 @@ already_AddRefed<ExtensionAPIRequest> RequestWorkerRunnable::CreateAPIRequest(
|
||||
|
||||
RefPtr<ExtensionAPIRequest> request = new ExtensionAPIRequest(
|
||||
mOuterRequest->GetRequestType(), *mOuterRequest->GetRequestTarget());
|
||||
request->Init(mClientInfo, mSWDescriptorId, callArgs, callerStackValue);
|
||||
request->Init(mClientInfo, callArgs, callerStackValue);
|
||||
|
||||
if (mEventListener) {
|
||||
request->SetEventListener(mEventListener.forget());
|
||||
@ -627,75 +625,5 @@ void RequestWorkerRunnable::ReadResult(JSContext* aCx,
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
}
|
||||
|
||||
// RequestInitWorkerContextRunnable
|
||||
|
||||
RequestInitWorkerRunnable::RequestInitWorkerRunnable(
|
||||
dom::WorkerPrivate* aWorkerPrivate, Maybe<dom::ClientInfo>& aSWClientInfo)
|
||||
: WorkerMainThreadRunnable(aWorkerPrivate,
|
||||
"extensions::RequestInitWorkerRunnable"_ns) {
|
||||
MOZ_ASSERT(dom::IsCurrentThreadRunningWorker());
|
||||
MOZ_ASSERT(aSWClientInfo.isSome());
|
||||
mClientInfo = aSWClientInfo;
|
||||
}
|
||||
|
||||
bool RequestInitWorkerRunnable::MainThreadRun() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
auto* baseURI = mWorkerPrivate->GetBaseURI();
|
||||
RefPtr<WebExtensionPolicy> policy =
|
||||
ExtensionPolicyService::GetSingleton().GetByURL(baseURI);
|
||||
|
||||
RefPtr<ExtensionServiceWorkerInfo> swInfo = new ExtensionServiceWorkerInfo(
|
||||
*mClientInfo, mWorkerPrivate->ServiceWorkerID());
|
||||
|
||||
nsCOMPtr<mozIExtensionAPIRequestHandler> handler =
|
||||
&ExtensionAPIRequestForwarder::APIRequestHandler();
|
||||
MOZ_ASSERT(handler);
|
||||
|
||||
if (NS_FAILED(handler->InitExtensionWorker(policy, swInfo))) {
|
||||
NS_WARNING("nsIExtensionAPIRequestHandler.initExtensionWorker call failed");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// NotifyWorkerLoadedRunnable
|
||||
|
||||
nsresult NotifyWorkerLoadedRunnable::Run() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
RefPtr<WebExtensionPolicy> policy =
|
||||
ExtensionPolicyService::GetSingleton().GetByURL(mSWBaseURI.get());
|
||||
|
||||
nsCOMPtr<mozIExtensionAPIRequestHandler> handler =
|
||||
&ExtensionAPIRequestForwarder::APIRequestHandler();
|
||||
MOZ_ASSERT(handler);
|
||||
|
||||
NS_WARN_IF(
|
||||
NS_FAILED(handler->OnExtensionWorkerLoaded(policy, mSWDescriptorId)));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// NotifyWorkerDestroyedRunnable
|
||||
|
||||
nsresult NotifyWorkerDestroyedRunnable::Run() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
RefPtr<WebExtensionPolicy> policy =
|
||||
ExtensionPolicyService::GetSingleton().GetByURL(mSWBaseURI.get());
|
||||
|
||||
nsCOMPtr<mozIExtensionAPIRequestHandler> handler =
|
||||
&ExtensionAPIRequestForwarder::APIRequestHandler();
|
||||
MOZ_ASSERT(handler);
|
||||
|
||||
if (NS_FAILED(handler->OnExtensionWorkerDestroyed(policy, mSWDescriptorId))) {
|
||||
NS_WARNING(
|
||||
"nsIExtensionAPIRequestHandler.onExtensionWorkerDestroyed call failed");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
} // namespace extensions
|
||||
} // namespace mozilla
|
||||
|
@ -186,7 +186,6 @@ class RequestWorkerRunnable : public dom::WorkerMainThreadRunnable {
|
||||
Maybe<UniquePtr<dom::StructuredCloneHolder>> mArgsHolder;
|
||||
Maybe<UniquePtr<dom::SerializedStackHolder>> mStackHolder;
|
||||
Maybe<dom::ClientInfo> mClientInfo;
|
||||
uint64_t mSWDescriptorId;
|
||||
|
||||
// Only set for addListener/removeListener API requests.
|
||||
RefPtr<ExtensionEventListener> mEventListener;
|
||||
@ -196,60 +195,6 @@ class RequestWorkerRunnable : public dom::WorkerMainThreadRunnable {
|
||||
ExtensionAPIRequestForwarder* mOuterRequest;
|
||||
};
|
||||
|
||||
class RequestInitWorkerRunnable : public dom::WorkerMainThreadRunnable {
|
||||
Maybe<dom::ClientInfo> mClientInfo;
|
||||
|
||||
public:
|
||||
RequestInitWorkerRunnable(dom::WorkerPrivate* aWorkerPrivate,
|
||||
Maybe<dom::ClientInfo>& aSWClientInfo);
|
||||
bool MainThreadRun() override;
|
||||
};
|
||||
|
||||
class NotifyWorkerLoadedRunnable : public Runnable {
|
||||
uint64_t mSWDescriptorId;
|
||||
nsCOMPtr<nsIURI> mSWBaseURI;
|
||||
|
||||
public:
|
||||
explicit NotifyWorkerLoadedRunnable(const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI)
|
||||
: Runnable("extensions::NotifyWorkerLoadedRunnable"),
|
||||
mSWDescriptorId(aServiceWorkerDescriptorId),
|
||||
mSWBaseURI(aWorkerBaseURI) {
|
||||
MOZ_ASSERT(mSWDescriptorId > 0);
|
||||
MOZ_ASSERT(mSWBaseURI);
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING_INHERITED(NotifyWorkerLoadedRunnable, Runnable)
|
||||
|
||||
private:
|
||||
~NotifyWorkerLoadedRunnable() = default;
|
||||
};
|
||||
|
||||
class NotifyWorkerDestroyedRunnable : public Runnable {
|
||||
uint64_t mSWDescriptorId;
|
||||
nsCOMPtr<nsIURI> mSWBaseURI;
|
||||
|
||||
public:
|
||||
explicit NotifyWorkerDestroyedRunnable(
|
||||
const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI)
|
||||
: Runnable("extensions::NotifyWorkerDestroyedRunnable"),
|
||||
mSWDescriptorId(aServiceWorkerDescriptorId),
|
||||
mSWBaseURI(aWorkerBaseURI) {
|
||||
MOZ_ASSERT(mSWDescriptorId > 0);
|
||||
MOZ_ASSERT(mSWBaseURI);
|
||||
}
|
||||
|
||||
NS_IMETHOD Run() override;
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING_INHERITED(NotifyWorkerDestroyedRunnable, Runnable)
|
||||
|
||||
private:
|
||||
~NotifyWorkerDestroyedRunnable() = default;
|
||||
};
|
||||
|
||||
} // namespace extensions
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -97,52 +97,6 @@ bool ExtensionAPIAllowed(JSContext* aCx, JSObject* aGlobal) {
|
||||
#endif
|
||||
}
|
||||
|
||||
void CreateAndDispatchInitWorkerContextRunnable() {
|
||||
MOZ_ASSERT(dom::IsCurrentThreadRunningWorker());
|
||||
// DO NOT pass this WorkerPrivate raw pointer to anything else but the
|
||||
// RequestInitWorkerRunnable (which extends dom::WorkerMainThreadRunnable).
|
||||
dom::WorkerPrivate* workerPrivate = dom::GetCurrentThreadWorkerPrivate();
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
MOZ_ASSERT(workerPrivate->ExtensionAPIAllowed());
|
||||
MOZ_ASSERT(workerPrivate->IsServiceWorker());
|
||||
workerPrivate->AssertIsOnWorkerThread();
|
||||
|
||||
auto* workerScope = workerPrivate->GlobalScope();
|
||||
if (NS_WARN_IF(!workerScope)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Maybe<dom::ClientInfo> clientInfo = workerScope->GetClientInfo();
|
||||
if (NS_WARN_IF(clientInfo.isNothing())) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<RequestInitWorkerRunnable> runnable =
|
||||
new RequestInitWorkerRunnable(std::move(workerPrivate), clientInfo);
|
||||
IgnoredErrorResult rv;
|
||||
runnable->Dispatch(dom::WorkerStatus::Canceling, rv);
|
||||
if (rv.Failed()) {
|
||||
NS_WARNING("Failed to dispatch extensions::RequestInitWorkerRunnable");
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<Runnable> CreateWorkerLoadedRunnable(
|
||||
const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI) {
|
||||
RefPtr<NotifyWorkerLoadedRunnable> runnable = new NotifyWorkerLoadedRunnable(
|
||||
aServiceWorkerDescriptorId, aWorkerBaseURI);
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
already_AddRefed<Runnable> CreateWorkerDestroyedRunnable(
|
||||
const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI) {
|
||||
RefPtr<NotifyWorkerDestroyedRunnable> runnable =
|
||||
new NotifyWorkerDestroyedRunnable(aServiceWorkerDescriptorId,
|
||||
aWorkerBaseURI);
|
||||
return runnable.forget();
|
||||
}
|
||||
|
||||
void ExtensionBrowser::SetLastError(JS::Handle<JS::Value> aLastError) {
|
||||
mLastError.set(aLastError);
|
||||
mCheckedLastError = false;
|
||||
|
@ -27,16 +27,6 @@ class ExtensionTest;
|
||||
|
||||
bool ExtensionAPIAllowed(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
void CreateAndDispatchInitWorkerContextRunnable();
|
||||
|
||||
already_AddRefed<Runnable> CreateWorkerLoadedRunnable(
|
||||
const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI);
|
||||
|
||||
already_AddRefed<Runnable> CreateWorkerDestroyedRunnable(
|
||||
const uint64_t aServiceWorkerDescriptorId,
|
||||
const nsCOMPtr<nsIURI>& aWorkerBaseURI);
|
||||
|
||||
class ExtensionBrowser final : public nsISupports, public nsWrapperCache {
|
||||
nsCOMPtr<nsIGlobalObject> mGlobal;
|
||||
JS::Heap<JS::Value> mLastError;
|
||||
|
Loading…
Reference in New Issue
Block a user