Backed out 9 changesets (bug 1580448) for linux build bustages in /builds/worker/workspace/obj-build/dist/include/mozilla/dom/JSWindowActorChild.h CLOSED TREE

Backed out changeset 6b4db1a501df (bug 1580448)
Backed out changeset 677257a41457 (bug 1580448)
Backed out changeset 6db8de5fc125 (bug 1580448)
Backed out changeset fd7527c86239 (bug 1580448)
Backed out changeset bfbd3330b0a5 (bug 1580448)
Backed out changeset dafa80c63322 (bug 1580448)
Backed out changeset 2a1701831a6a (bug 1580448)
Backed out changeset 9b548bd38671 (bug 1580448)
Backed out changeset 358f764ae48b (bug 1580448)
This commit is contained in:
Stefan Hindli 2020-04-30 10:58:27 +03:00
Родитель 49c6346195
Коммит e22cd35728
70 изменённых файлов: 501 добавлений и 2182 удалений

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

@ -26,7 +26,7 @@
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/IdleDeadline.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/MediaControlUtils.h"
#include "mozilla/dom/MediaControlService.h"
#include "mozilla/dom/MediaMetadata.h"
@ -1204,7 +1204,7 @@ void ChromeUtils::RegisterWindowActor(const GlobalObject& aGlobal,
ErrorResult& aRv) {
MOZ_ASSERT(XRE_IsParentProcess());
RefPtr<JSActorService> service = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> service = JSWindowActorService::GetSingleton();
service->RegisterWindowActor(aName, aOptions, aRv);
}
@ -1213,30 +1213,10 @@ void ChromeUtils::UnregisterWindowActor(const GlobalObject& aGlobal,
const nsACString& aName) {
MOZ_ASSERT(XRE_IsParentProcess());
RefPtr<JSActorService> service = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> service = JSWindowActorService::GetSingleton();
service->UnregisterWindowActor(aName);
}
/* static */
void ChromeUtils::RegisterProcessActor(const GlobalObject& aGlobal,
const nsACString& aName,
const ProcessActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_ASSERT(XRE_IsParentProcess());
RefPtr<JSActorService> service = JSActorService::GetSingleton();
service->RegisterProcessActor(aName, aOptions, aRv);
}
/* static */
void ChromeUtils::UnregisterProcessActor(const GlobalObject& aGlobal,
const nsACString& aName) {
MOZ_ASSERT(XRE_IsParentProcess());
RefPtr<JSActorService> service = JSActorService::GetSingleton();
service->UnregisterProcessActor(aName);
}
/* static */
bool ChromeUtils::IsClassifierBlockingErrorCode(GlobalObject& aGlobal,
uint32_t aError) {

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

@ -30,7 +30,6 @@ struct MediaMetadataInit;
class MozQueryInterface;
class PrecompiledScript;
class Promise;
struct ProcessActorOptions;
struct WindowActorOptions;
class ChromeUtils {
@ -201,14 +200,6 @@ class ChromeUtils {
static void UnregisterWindowActor(const GlobalObject& aGlobal,
const nsACString& aName);
static void RegisterProcessActor(const GlobalObject& aGlobal,
const nsACString& aName,
const ProcessActorOptions& aOptions,
ErrorResult& aRv);
static void UnregisterProcessActor(const GlobalObject& aGlobal,
const nsACString& aName);
static bool IsClassifierBlockingErrorCode(GlobalObject& aGlobal,
uint32_t aError);

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

@ -20,7 +20,7 @@
#include "mozilla/dom/SameProcessMessageQueue.h"
#include "mozilla/dom/ScriptLoader.h"
#include "mozilla/dom/WindowProxyHolder.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
using namespace mozilla;
using namespace mozilla::dom;
@ -37,7 +37,7 @@ InProcessBrowserChildMessageManager::Create(nsDocShell* aShell,
NS_ENSURE_TRUE(mm->Init(), nullptr);
if (XRE_IsParentProcess()) {
RefPtr<JSActorService> wasvc = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> wasvc = JSWindowActorService::GetSingleton();
wasvc->RegisterChromeEventTarget(mm);
}
@ -111,7 +111,7 @@ InProcessBrowserChildMessageManager::InProcessBrowserChildMessageManager(
InProcessBrowserChildMessageManager::~InProcessBrowserChildMessageManager() {
if (XRE_IsParentProcess()) {
JSActorService::UnregisterChromeEventTarget(this);
JSWindowActorService::UnregisterChromeEventTarget(this);
}
mAnonymousGlobalScopes.Clear();

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

@ -30,7 +30,7 @@
#include "mozilla/dom/BrowserParent.h"
#include "mozilla/dom/HTMLTextAreaElement.h"
#include "mozilla/dom/HTMLInputElement.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
#ifdef MOZ_XUL
# include "nsXULElement.h"
@ -50,7 +50,7 @@ nsWindowRoot::~nsWindowRoot() {
}
if (XRE_IsContentProcess()) {
JSActorService::UnregisterChromeEventTarget(this);
JSWindowActorService::UnregisterChromeEventTarget(this);
}
}
@ -379,7 +379,7 @@ already_AddRefed<EventTarget> NS_NewWindowRoot(nsPIDOMWindowOuter* aWindow) {
nsCOMPtr<EventTarget> result = new nsWindowRoot(aWindow);
if (XRE_IsContentProcess()) {
RefPtr<JSActorService> wasvc = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> wasvc = JSWindowActorService::GetSingleton();
wasvc->RegisterChromeEventTarget(result);
}

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

@ -4,8 +4,6 @@
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
interface nsIContentChild;
/**
* An optimized QueryInterface method, generated by generateQI.
*
@ -448,18 +446,6 @@ partial namespace ChromeUtils {
[ChromeOnly]
void unregisterWindowActor(UTF8String aName);
/**
* Register a new toplevel content global actor. This method may only be
* called in the parent process. |name| must be globally unique.
*
* See JSProcessActor.webidl for ProcessActorOptions fields documentation.
*/
[ChromeOnly, Throws]
void registerProcessActor(UTF8String aName, optional ProcessActorOptions aOptions = {});
[ChromeOnly]
void unregisterProcessActor(UTF8String aName);
[ChromeOnly]
// aError should a nsresult.
boolean isClassifierBlockingErrorCode(unsigned long aError);

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

@ -1,54 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
interface mixin JSActor {
[Throws]
void sendAsyncMessage(DOMString messageName,
optional any obj);
[Throws]
Promise<any> sendQuery(DOMString messageName,
optional any obj);
};
/**
* WebIDL callback interface version of the nsIObserver interface for use when
* calling the observe method on JSActors.
*
* NOTE: This isn't marked as ChromeOnly, as it has no interface object, and
* thus cannot be conditionally exposed.
*/
[Exposed=Window]
callback interface MozObserverCallback {
void observe(nsISupports subject, ByteString topic, DOMString? data);
};
/**
* WebIDL callback interface calling the `willDestroy`, `didDestroy`, and
* `actorCreated` methods on JSActors.
*/
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback MozJSActorCallback = void();
/**
* The willDestroy method, if present, will be called at the last opportunity
* to send messages to the remote side, giving implementers the chance to clean
* up and send final messages.
* The didDestroy method, if present, will be called after the actor is no
* longer able to receive any more messages.
* The actorCreated method, if present, will be called immediately after the
* actor has been created and initialized.
*
* NOTE: Messages may be received between willDestroy and didDestroy, but they
* may not be sent.
*/
[GenerateInit]
dictionary MozJSActorCallbacks {
[ChromeOnly] MozJSActorCallback willDestroy;
[ChromeOnly] MozJSActorCallback didDestroy;
[ChromeOnly] MozJSActorCallback actorCreated;
};

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

@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* An actor architecture designed to allow compositional parent/content
* communications. The lifetime of a JSProcessActor{Child, Parent} is the `ContentParent`
* (for the parent-side) / `ContentChild` (for the child-side).
*/
interface nsISupports;
/**
* Base class for parent-side actor.
*/
[ChromeOnly, Exposed=Window]
interface JSProcessActorParent {
[ChromeOnly]
constructor();
readonly attribute nsIContentParent manager;
};
JSProcessActorParent includes JSActor;
[ChromeOnly, Exposed=Window]
interface JSProcessActorChild {
[ChromeOnly]
constructor();
readonly attribute nsIContentChild manager;
};
JSProcessActorChild includes JSActor;
/**
* Used by `ChromeUtils.registerProcessActor()` to register actors.
*/
dictionary ProcessActorOptions {
/**
* An array of remote type which restricts the actor is allowed to instantiate
* in specific process type. If this is defined, the prefix of process type
* matches the remote type by prefix match is allowed to instantiate, ex: if
* Fission is enabled, the prefix of process type will be `webIsolated`, it
* can prefix match remote type either `web` or `webIsolated`. If not passed,
* all content processes are allowed to instantiate the actor.
*/
sequence<DOMString> remoteTypes;
/** This fields are used for configuring individual sides of the actor. */
ProcessActorSidedOptions parent;
ProcessActorChildOptions child;
};
dictionary ProcessActorSidedOptions {
/**
* The JSM path which should be loaded for the actor on this side.
* If not passed, the specified side cannot receive messages, but may send
* them using `sendAsyncMessage` or `sendQuery`.
*/
required ByteString moduleURI;
};
dictionary ProcessActorChildOptions : ProcessActorSidedOptions {
/**
* An array of observer topics to listen to. An observer will be added for each
* topic in the list.
*
* Observer notifications in the list use nsGlobalContentInner or
* nsGlobalContentOuter object as their subject, and the events will only be
* dispatched to the corresponding content actor. If additional observer
* notification's subjects are needed, please file a bug for that.
**/
sequence<ByteString> observers;
};

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

@ -4,16 +4,19 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* An actor architecture designed to allow compositional parent/content
* communications. The lifetime of a JSWindowActor{Child, Parent} is the `WindowGlobalParent`
* (for the parent-side) / `WindowGlobalChild` (for the child-side).
*
* See https://firefox-source-docs.mozilla.org/dom/Fission.html#jswindowactor for
* more details on how to use this architecture.
*/
interface nsISupports;
interface nsIContentChild;
interface nsIContentParent;
interface mixin JSWindowActor {
[Throws]
void sendAsyncMessage(DOMString messageName,
optional any obj);
[Throws]
Promise<any> sendQuery(DOMString messageName,
optional any obj);
};
[ChromeOnly, Exposed=Window]
interface JSWindowActorParent {
@ -30,13 +33,13 @@ interface JSWindowActorParent {
[Throws]
readonly attribute CanonicalBrowsingContext? browsingContext;
};
JSWindowActorParent includes JSActor;
JSWindowActorParent includes JSWindowActor;
[ChromeOnly, Exposed=Window]
interface JSWindowActorChild {
[ChromeOnly]
constructor();
/**
* Actor initialization occurs after the constructor is called but before the
* first message is delivered. Until the actor is initialized, accesses to
@ -61,7 +64,45 @@ interface JSWindowActorChild {
[Throws]
readonly attribute WindowProxy? contentWindow;
};
JSWindowActorChild includes JSActor;
JSWindowActorChild includes JSWindowActor;
/**
* WebIDL callback interface version of the nsIObserver interface for use when
* calling the observe method on JSWindowActors.
*
* NOTE: This isn't marked as ChromeOnly, as it has no interface object, and
* thus cannot be conditionally exposed.
*/
[Exposed=Window]
callback interface MozObserverCallback {
void observe(nsISupports subject, ByteString topic, DOMString? data);
};
/**
* WebIDL callback interface calling the `willDestroy`, `didDestroy`, and
* `actorCreated` methods on JSWindowActors.
*/
[MOZ_CAN_RUN_SCRIPT_BOUNDARY]
callback MozJSWindowActorCallback = void();
/**
* The willDestroy method, if present, will be called at the last opportunity
* to send messages to the remote side, giving implementers the chance to clean
* up and send final messages.
* The didDestroy method, if present, will be called after the actor is no
* longer able to receive any more messages.
* The actorCreated method, if present, will be called immediately after the
* actor has been created and initialized.
*
* NOTE: Messages may be received between willDestroy and didDestroy, but they
* may not be sent.
*/
[GenerateInit]
dictionary MozJSWindowActorCallbacks {
[ChromeOnly] MozJSWindowActorCallback willDestroy;
[ChromeOnly] MozJSWindowActorCallback didDestroy;
[ChromeOnly] MozJSWindowActorCallback actorCreated;
};
/**
* Used by ChromeUtils.registerWindowActor() to register JS window actor.

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

@ -8,7 +8,6 @@ interface URI;
interface nsIDocShell;
interface RemoteTab;
interface nsITransportSecurityInfo;
interface nsIContentParent;
[Exposed=Window, ChromeOnly]
interface WindowContext {

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

@ -49,8 +49,6 @@ WEBIDL_FILES = [
'HeapSnapshot.webidl',
'InspectorUtils.webidl',
'IteratorResult.webidl',
'JSActor.webidl',
'JSProcessActor.webidl',
'JSWindowActor.webidl',
'L10nOverlays.webidl',
'Localization.webidl',

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

@ -48,9 +48,7 @@
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/IPCBlobInputStreamChild.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSProcessActorBinding.h"
#include "mozilla/dom/JSProcessActorChild.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/LSObject.h"
#include "mozilla/dom/MemoryReportRequest.h"
#include "mozilla/dom/PLoginReputationChild.h"
@ -76,7 +74,6 @@
#include "mozilla/ipc/FileDescriptorSetChild.h"
#include "mozilla/ipc/FileDescriptorUtils.h"
#include "mozilla/ipc/GeckoChildProcessHost.h"
#include "mozilla/ipc/InProcessChild.h"
#include "mozilla/ipc/LibrarySandboxPreload.h"
#include "mozilla/ipc/ProcessChild.h"
#include "mozilla/ipc/PChildToParentStreamChild.h"
@ -2177,15 +2174,6 @@ void ContentChild::ActorDestroy(ActorDestroyReason why) {
// keep persistent state.
ProcessChild::QuickExit();
#else
// Destroy our JSProcessActors, and reject any pending queries.
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorChild> processActors;
mProcessActors.SwapElements(processActors);
for (auto iter = processActors.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->RejectPendingQueries();
iter.Data()->AfterDestroy();
}
mProcessActors.Clear();
# if defined(XP_WIN)
RefPtr<DllServices> dllSvc(DllServices::Get());
dllSvc->DisableFull();
@ -2633,28 +2621,20 @@ mozilla::ipc::IPCResult ContentChild::RecvInitBlobURLs(
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvInitJSActorInfos(
nsTArray<JSProcessActorInfo>&& aContentInfos,
nsTArray<JSWindowActorInfo>&& aWindowInfos) {
RefPtr<JSActorService> actSvc = JSActorService::GetSingleton();
actSvc->LoadJSActorInfos(aContentInfos, aWindowInfos);
mozilla::ipc::IPCResult ContentChild::RecvInitJSWindowActorInfos(
nsTArray<JSWindowActorInfo>&& aInfos) {
RefPtr<JSWindowActorService> actSvc = JSWindowActorService::GetSingleton();
actSvc->LoadJSWindowActorInfos(aInfos);
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUnregisterJSWindowActor(
const nsCString& aName) {
RefPtr<JSActorService> actSvc = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> actSvc = JSWindowActorService::GetSingleton();
actSvc->UnregisterWindowActor(aName);
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvUnregisterJSProcessActor(
const nsCString& aName) {
RefPtr<JSActorService> actSvc = JSActorService::GetSingleton();
actSvc->UnregisterProcessActor(aName);
return IPC_OK();
}
mozilla::ipc::IPCResult ContentChild::RecvLastPrivateDocShellDestroyed() {
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
obs->NotifyObservers(nullptr, "last-pb-context-exited", nullptr);
@ -4209,98 +4189,6 @@ NS_IMETHODIMP ContentChild::GetChildID(uint64_t* aOut) {
return NS_OK;
}
NS_IMETHODIMP ContentChild::GetActor(const nsACString& aName,
JSProcessActorChild** retval) {
if (!CanSend()) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
RefPtr<JSProcessActorChild> actor(mProcessActors.Get(aName));
actor.forget(retval);
return NS_OK;
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ErrorResult result;
ConstructActor(aName, &obj, result);
if (result.Failed()) {
return result.StealNSResult();
}
// Unwrap our actor to a JSProcessActorChild object.
RefPtr<JSProcessActorChild> actor;
nsresult rv = UNWRAP_OBJECT(JSProcessActorChild, &obj, actor);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
actor.forget(retval);
return NS_OK;
}
IPCResult ContentChild::RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack) {
StructuredCloneData data;
data.BorrowFromClonedMessageDataForChild(aData);
StructuredCloneData stack;
stack.BorrowFromClonedMessageDataForChild(aStack);
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
return IPC_OK();
}
void ContentChild::ReceiveRawMessage(const JSActorMessageMeta& aMeta,
StructuredCloneData&& aData,
StructuredCloneData&& aStack) {
RefPtr<JSProcessActorChild> actor =
GetActor(aMeta.actorName(), IgnoreErrors());
if (actor) {
actor->ReceiveRawMessage(aMeta, std::move(aData), std::move(aStack));
}
}
already_AddRefed<mozilla::dom::JSProcessActorChild> ContentChild::GetActor(
const nsACString& aName, ErrorResult& aRv) {
if (!CanSend()) {
aRv.ThrowInvalidStateError(
"Cannot get JSProcessActor, process is shutting down");
return nullptr;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
return mProcessActors.Get(aName);
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ConstructActor(aName, &obj, aRv);
if (aRv.Failed()) {
return nullptr;
}
// Unwrap our actor to a JSProcessActorChild object.
RefPtr<JSProcessActorChild> actor;
if (NS_FAILED(UNWRAP_OBJECT(JSProcessActorChild, &obj, actor))) {
aRv.ThrowTypeMismatchError(
"Constructed actor does not inherit from JSProcessActorChild");
return nullptr;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
return actor.forget();
}
} // namespace dom
#if defined(__OpenBSD__) && defined(MOZ_SANDBOX)

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

@ -12,8 +12,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/BrowserBridgeChild.h"
#include "mozilla/dom/ProcessActor.h"
#include "mozilla/dom/JSProcessActorChild.h"
#include "mozilla/dom/PBrowserOrId.h"
#include "mozilla/dom/PContentChild.h"
#include "mozilla/dom/RemoteBrowser.h"
@ -44,7 +42,6 @@ struct LookAndFeelInt;
class nsDocShellLoadState;
class nsFrameLoader;
class nsIOpenWindowInfo;
class JSProcessActorChild;
namespace mozilla {
class RemoteSpellcheckEngineChild;
@ -81,8 +78,7 @@ class ContentChild final
public nsIContentChild,
public nsIWindowProvider,
public mozilla::ipc::IShmemAllocator,
public mozilla::ipc::ChildToParentStreamActorManager,
public ProcessActor {
public mozilla::ipc::ChildToParentStreamActorManager {
typedef mozilla::dom::ClonedMessageData ClonedMessageData;
typedef mozilla::ipc::FileDescriptor FileDescriptor;
typedef mozilla::ipc::PFileDescriptorSetChild PFileDescriptorSetChild;
@ -394,7 +390,7 @@ class ContentChild final
// Call RemoteTypePrefix() on the result to remove URIs if you want to use
// this for telemetry.
const nsAString& GetRemoteType() const override;
const nsAString& GetRemoteType() const;
mozilla::ipc::IPCResult RecvInitServiceWorkers(
const ServiceWorkerConfiguration& aConfig);
@ -402,14 +398,11 @@ class ContentChild final
mozilla::ipc::IPCResult RecvInitBlobURLs(
nsTArray<BlobURLRegistrationData>&& aRegistations);
mozilla::ipc::IPCResult RecvInitJSActorInfos(
nsTArray<JSProcessActorInfo>&& aContentInfos,
nsTArray<JSWindowActorInfo>&& aWindowInfos);
mozilla::ipc::IPCResult RecvInitJSWindowActorInfos(
nsTArray<JSWindowActorInfo>&& aInfos);
mozilla::ipc::IPCResult RecvUnregisterJSWindowActor(const nsCString& aName);
mozilla::ipc::IPCResult RecvUnregisterJSProcessActor(const nsCString& aName);
mozilla::ipc::IPCResult RecvLastPrivateDocShellDestroyed();
mozilla::ipc::IPCResult RecvNotifyProcessPriorityChanged(
@ -708,10 +701,6 @@ class ContentChild final
PFileDescriptorSetChild* SendPFileDescriptorSetConstructor(
const FileDescriptor& aFD) override;
// Get a JS actor object by name.
already_AddRefed<mozilla::dom::JSProcessActorChild> GetActor(
const nsACString& aName, ErrorResult& aRv);
private:
static void ForceKillTimerCallback(nsITimer* aTimer, void* aClosure);
void StartForceKillTimer();
@ -804,17 +793,6 @@ class ContentChild final
mozilla::ipc::IPCResult RecvDisplayLoadError(
const MaybeDiscarded<BrowsingContext>& aContext, const nsAString& aURI);
mozilla::ipc::IPCResult RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack);
void ReceiveRawMessage(const JSActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack);
JSActor::Type GetSide() override { return JSActor::Type::Child; }
private:
#ifdef NIGHTLY_BUILD
virtual PContentChild::Result OnMessageReceived(const Message& aMsg) override;
#else
@ -906,7 +884,6 @@ class ContentChild final
// See `BrowsingContext::mEpochs` for an explanation of this field.
uint64_t mBrowsingContextFieldEpoch = 0;
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorChild> mProcessActors;
DISALLOW_EVIL_CONSTRUCTORS(ContentChild);
};

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

@ -92,8 +92,7 @@
#include "mozilla/dom/GetFilesHelper.h"
#include "mozilla/dom/IPCBlobInputStreamParent.h"
#include "mozilla/dom/IPCBlobUtils.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSProcessActorBinding.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/LocalStorageCommon.h"
#include "mozilla/dom/MediaController.h"
#include "mozilla/dom/MemoryReportRequest.h"
@ -1676,15 +1675,6 @@ void ContentParent::ActorDestroy(ActorDestroyReason why) {
mConsoleService = nullptr;
// Destroy our JSProcessActors, and reject any pending queries.
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorParent> processActors;
mProcessActors.SwapElements(processActors);
for (auto iter = processActors.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->RejectPendingQueries();
iter.Data()->AfterDestroy();
}
mProcessActors.Clear();
if (obs) {
RefPtr<nsHashPropertyBag> props = new nsHashPropertyBag();
@ -2623,16 +2613,12 @@ bool ContentParent::InitInternal(ProcessPriority aInitialPriority) {
}
}
// Send down { Parent, Window }ActorOptions at startup to content process.
RefPtr<JSActorService> actorSvc = JSActorService::GetSingleton();
// Send down WindowActorOptions at startup to content process.
RefPtr<JSWindowActorService> actorSvc = JSWindowActorService::GetSingleton();
if (actorSvc) {
nsTArray<JSProcessActorInfo> contentInfos;
actorSvc->GetJSProcessActorInfos(contentInfos);
nsTArray<JSWindowActorInfo> windowInfos;
actorSvc->GetJSWindowActorInfos(windowInfos);
Unused << SendInitJSActorInfos(contentInfos, windowInfos);
nsTArray<JSWindowActorInfo> infos;
actorSvc->GetJSWindowActorInfos(infos);
Unused << SendInitJSWindowActorInfos(infos);
}
// Start up nsPluginHost and run FindPlugins to cache the plugin list.
@ -6434,99 +6420,6 @@ NS_IMETHODIMP ContentParent::GetChildID(uint64_t* aOut) {
return NS_OK;
}
IPCResult ContentParent::RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack) {
StructuredCloneData data;
data.BorrowFromClonedMessageDataForParent(aData);
StructuredCloneData stack;
stack.BorrowFromClonedMessageDataForParent(aStack);
ReceiveRawMessage(aMeta, std::move(data), std::move(stack));
return IPC_OK();
}
void ContentParent::ReceiveRawMessage(const JSActorMessageMeta& aMeta,
StructuredCloneData&& aData,
StructuredCloneData&& aStack) {
RefPtr<JSProcessActorParent> actor =
GetActor(aMeta.actorName(), IgnoreErrors());
if (actor) {
actor->ReceiveRawMessage(aMeta, std::move(aData), std::move(aStack));
}
}
already_AddRefed<JSProcessActorParent> ContentParent::GetActor(
const nsACString& aName, ErrorResult& aRv) {
if (!CanSend()) {
aRv.ThrowInvalidStateError(nsPrintfCString(
"Cannot get actor '%s': content parent is ready to communicate.",
PromiseFlatCString(aName).get()));
return nullptr;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
return do_AddRef(mProcessActors.GetWeak(aName));
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ConstructActor(aName, &obj, aRv);
if (aRv.Failed()) {
return nullptr;
}
// Unwrap our actor to a JSProcessActorParent object.
RefPtr<JSProcessActorParent> actor;
if (NS_FAILED(UNWRAP_OBJECT(JSProcessActorParent, &obj, actor))) {
aRv.ThrowTypeMismatchError(
"Constructed actor does not inherit from JSProcessActorParent");
return nullptr;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
return actor.forget();
}
NS_IMETHODIMP ContentParent::GetActor(const nsACString& aName,
JSProcessActorParent** retval) {
if (!CanSend()) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
// Check if this actor has already been created, and return it if it has.
if (mProcessActors.Contains(aName)) {
RefPtr<JSProcessActorParent> actor(mProcessActors.Get(aName));
actor.forget(retval);
return NS_OK;
}
// Otherwise, we want to create a new instance of this actor.
JS::RootedObject obj(RootingCx());
ErrorResult result;
ConstructActor(aName, &obj, result);
if (result.Failed()) {
return result.StealNSResult();
}
// Unwrap our actor to a JSProcessActorParent object.
RefPtr<JSProcessActorParent> actor;
nsresult rv = UNWRAP_OBJECT(JSProcessActorParent, &obj, actor);
if (NS_FAILED(rv)) {
return rv;
}
MOZ_RELEASE_ASSERT(!actor->Manager(),
"mManager was already initialized once!");
actor->Init(aName, this);
mProcessActors.Put(aName, RefPtr{actor});
actor.forget(retval);
return NS_OK;
}
} // namespace dom
} // namespace mozilla

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

@ -11,8 +11,6 @@
#include "mozilla/dom/ipc/IdType.h"
#include "mozilla/dom/MediaSessionBinding.h"
#include "mozilla/dom/RemoteBrowser.h"
#include "mozilla/dom/JSProcessActorParent.h"
#include "mozilla/dom/ProcessActor.h"
#include "mozilla/gfx/gfxVarReceiver.h"
#include "mozilla/gfx/GPUProcessListener.h"
#include "mozilla/ipc/BackgroundUtils.h"
@ -143,8 +141,7 @@ class ContentParent final
public mozilla::MemoryReportingProcess,
public mozilla::dom::ipc::MessageManagerCallback,
public mozilla::ipc::IShmemAllocator,
public mozilla::ipc::ParentToChildStreamActorManager,
public ProcessActor {
public mozilla::ipc::ParentToChildStreamActorManager {
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
typedef mozilla::ipc::PFileDescriptorSetParent PFileDescriptorSetParent;
typedef mozilla::ipc::TestShellParent TestShellParent;
@ -240,7 +237,7 @@ class ContentParent final
static void BroadcastFontListChanged();
const nsAString& GetRemoteType() const override;
const nsAString& GetRemoteType() const;
virtual void DoGetRemoteType(nsAString& aRemoteType,
ErrorResult& aError) const override {
@ -338,7 +335,6 @@ class ContentParent final
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_NSICONTENTPARENT
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMGEOPOSITIONCALLBACK
NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
@ -1288,10 +1284,6 @@ class ContentParent final
PSHEntryParent* aNewLSHE, PSHEntryParent* aNewOSHE,
const MaybeDiscarded<BrowsingContext>& aMaybeContext);
mozilla::ipc::IPCResult RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack);
mozilla::ipc::IPCResult RecvAbortOtherOrientationPendingPromises(
const MaybeDiscarded<BrowsingContext>& aContext);
@ -1325,7 +1317,7 @@ class ContentParent final
static bool ShouldSyncPreference(const char16_t* aData);
JSActor::Type GetSide() override { return JSActor::Type::Parent; }
NS_IMETHOD GetChildID(uint64_t* aChildID) override;
static const nsTArray<RefPtr<BrowsingContextGroup>>& BrowsingContextGroups() {
return *sBrowsingContextGroupHolder;
@ -1338,13 +1330,6 @@ class ContentParent final
nsTArray<ContentParent*>& aContentParents, uint32_t aMaxContentParents,
bool aPreferUsed);
// Get a JS actor object by name.
already_AddRefed<JSProcessActorParent> GetActor(const nsACString& aName,
ErrorResult& aRv);
void ReceiveRawMessage(const JSActorMessageMeta& aMeta,
StructuredCloneData&& aData,
StructuredCloneData&& aStack);
private:
// Released in ActorDealloc; deliberately not exposed to the CC.
RefPtr<ContentParent> mSelfRef;
@ -1502,8 +1487,6 @@ class ContentParent final
// A preference serializer used to share preferences with the process.
// Cleared once startup is complete.
UniquePtr<mozilla::ipc::SharedPreferenceSerializer> mPrefSerializer;
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorParent> mProcessActors;
};
NS_DEFINE_STATIC_IID_ACCESSOR(ContentParent, NS_CONTENTPARENT_IID)

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

@ -1,246 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/ChromeUtilsBinding.h"
#include "mozilla/dom/EventListenerBinding.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTargetBinding.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/JSProcessActorBinding.h"
#include "mozilla/dom/JSProcessActorChild.h"
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/MessageManagerBinding.h"
#include "mozilla/dom/PContent.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/WindowGlobalChild.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Logging.h"
namespace mozilla {
namespace dom {
namespace {
StaticRefPtr<JSActorService> gJSActorService;
}
JSActorService::JSActorService() { MOZ_ASSERT(NS_IsMainThread()); }
JSActorService::~JSActorService() { MOZ_ASSERT(NS_IsMainThread()); }
/* static */
already_AddRefed<JSActorService> JSActorService::GetSingleton() {
MOZ_ASSERT(NS_IsMainThread());
if (!gJSActorService) {
gJSActorService = new JSActorService();
ClearOnShutdown(&gJSActorService);
}
RefPtr<JSActorService> service = gJSActorService.get();
return service.forget();
}
void JSActorService::RegisterWindowActor(const nsACString& aName,
const WindowActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
auto entry = mWindowActorDescriptors.LookupForAdd(aName);
if (entry) {
aRv.ThrowNotSupportedError(nsPrintfCString(
"'%s' actor is already registered.", PromiseFlatCString(aName).get()));
return;
}
// Insert a new entry for the protocol.
RefPtr<JSWindowActorProtocol> proto =
JSWindowActorProtocol::FromWebIDLOptions(aName, aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
entry.OrRemove();
return;
}
entry.OrInsert([&] { return proto; });
// Send information about the newly added entry to every existing content
// process.
AutoTArray<JSWindowActorInfo, 1> windowInfos{proto->ToIPC()};
nsTArray<JSProcessActorInfo> contentInfos{};
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendInitJSActorInfos(contentInfos, windowInfos);
}
// Register event listeners for any existing chrome targets.
for (EventTarget* target : mChromeEventTargets) {
proto->RegisterListenersFor(target);
}
// Add observers to the protocol.
proto->AddObservers();
}
void JSActorService::UnregisterWindowActor(const nsACString& aName) {
nsAutoCString name(aName);
RefPtr<JSWindowActorProtocol> proto;
if (mWindowActorDescriptors.Remove(aName, getter_AddRefs(proto))) {
// If we're in the parent process, also unregister the window actor in all
// live content processes.
if (XRE_IsParentProcess()) {
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendUnregisterJSWindowActor(name);
}
}
// Remove listeners for this actor from each of our chrome targets.
for (EventTarget* target : mChromeEventTargets) {
proto->UnregisterListenersFor(target);
}
// Remove observers for this actor from observer serivce.
proto->RemoveObservers();
}
}
void JSActorService::LoadJSActorInfos(nsTArray<JSProcessActorInfo>& aProcess,
nsTArray<JSWindowActorInfo>& aWindow) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsContentProcess());
for (uint32_t i = 0, len = aProcess.Length(); i < len; i++) {
// Create our JSProcessActorProtocol, register it in
// mProcessActorDescriptors.
RefPtr<JSProcessActorProtocol> proto =
JSProcessActorProtocol::FromIPC(aProcess[i]);
mProcessActorDescriptors.Put(aProcess[i].name(), RefPtr{proto});
// Add observers for each actor.
proto->AddObservers();
}
for (uint32_t i = 0, len = aWindow.Length(); i < len; i++) {
// Create our JSWindowActorProtocol, register it in mWindowActorDescriptors.
RefPtr<JSWindowActorProtocol> proto =
JSWindowActorProtocol::FromIPC(aWindow[i]);
mWindowActorDescriptors.Put(aWindow[i].name(), RefPtr{proto});
// Register listeners for each chrome target.
for (EventTarget* target : mChromeEventTargets) {
proto->RegisterListenersFor(target);
}
// Add observers for each actor.
proto->AddObservers();
}
}
void JSActorService::GetJSWindowActorInfos(
nsTArray<JSWindowActorInfo>& aInfos) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
for (auto iter = mWindowActorDescriptors.ConstIter(); !iter.Done();
iter.Next()) {
aInfos.AppendElement(iter.Data()->ToIPC());
}
}
void JSActorService::RegisterChromeEventTarget(EventTarget* aTarget) {
MOZ_ASSERT(!mChromeEventTargets.Contains(aTarget));
mChromeEventTargets.AppendElement(aTarget);
// Register event listeners on the newly added Window Root.
for (auto iter = mWindowActorDescriptors.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->RegisterListenersFor(aTarget);
}
}
/* static */
void JSActorService::UnregisterChromeEventTarget(EventTarget* aTarget) {
if (gJSActorService) {
// NOTE: No need to unregister listeners here, as the target is going away.
gJSActorService->mChromeEventTargets.RemoveElement(aTarget);
}
}
void JSActorService::RegisterProcessActor(const nsACString& aName,
const ProcessActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
auto entry = mProcessActorDescriptors.LookupForAdd(aName);
if (entry) {
aRv.ThrowNotSupportedError(nsPrintfCString(
"'%s' actor is already registered.", PromiseFlatCString(aName).get()));
return;
}
// Insert a new entry for the protocol.
RefPtr<JSProcessActorProtocol> proto =
JSProcessActorProtocol::FromWebIDLOptions(aName, aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
entry.OrRemove();
return;
}
entry.OrInsert([&] { return proto; });
// Send information about the newly added entry to every existing content
// process.
AutoTArray<JSProcessActorInfo, 1> contentInfos{proto->ToIPC()};
nsTArray<JSWindowActorInfo> windowInfos{};
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendInitJSActorInfos(contentInfos, windowInfos);
}
// Add observers to the protocol.
proto->AddObservers();
}
void JSActorService::UnregisterProcessActor(const nsACString& aName) {
nsAutoCString name(aName);
RefPtr<JSProcessActorProtocol> proto;
if (mProcessActorDescriptors.Remove(aName, getter_AddRefs(proto))) {
// If we're in the parent process, also unregister the Content actor in all
// live content processes.
if (XRE_IsParentProcess()) {
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendUnregisterJSProcessActor(name);
}
}
// Remove observers for this actor from observer serivce.
proto->RemoveObservers();
}
}
void JSActorService::GetJSProcessActorInfos(
nsTArray<JSProcessActorInfo>& aInfos) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
for (auto iter = mProcessActorDescriptors.ConstIter(); !iter.Done();
iter.Next()) {
aInfos.AppendElement(iter.Data()->ToIPC());
}
}
already_AddRefed<JSProcessActorProtocol>
JSActorService::GetJSProcessActorProtocol(const nsACString& aName) {
return mProcessActorDescriptors.Get(aName);
}
already_AddRefed<JSWindowActorProtocol>
JSActorService::GetJSWindowActorProtocol(const nsACString& aName) {
return mWindowActorDescriptors.Get(aName);
}
} // namespace dom
} // namespace mozilla

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

@ -1,97 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSActorService_h
#define mozilla_dom_JSActorService_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/ErrorResult.h"
#include "nsIURI.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/dom/JSActor.h"
#include "mozilla/dom/JSProcessActorProtocol.h"
#include "mozilla/dom/JSWindowActorProtocol.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/extensions/WebExtensionContentScript.h"
namespace mozilla {
namespace dom {
struct ProcessActorOptions;
struct WindowActorOptions;
class JSProcessActorInfo;
class JSWindowActorInfo;
class EventTarget;
class JSActorService final {
public:
NS_INLINE_DECL_REFCOUNTING(JSActorService)
static already_AddRefed<JSActorService> GetSingleton();
// Register or unregister a chrome event target.
void RegisterChromeEventTarget(EventTarget* aTarget);
// NOTE: This method is static, as it may be called during shutdown.
static void UnregisterChromeEventTarget(EventTarget* aTarget);
// Register child's Actor for content process.
void LoadJSActorInfos(nsTArray<JSProcessActorInfo>& aProcess,
nsTArray<JSWindowActorInfo>& aWindow);
// --- Window Actor
void RegisterWindowActor(const nsACString& aName,
const WindowActorOptions& aOptions,
ErrorResult& aRv);
void UnregisterWindowActor(const nsACString& aName);
// Get the named of Window Actor and the child's WindowActorOptions
// from mDescriptors to JSWindowActorInfos.
void GetJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);
already_AddRefed<JSWindowActorProtocol> GetJSWindowActorProtocol(
const nsACString& aName);
// -- Content Actor
void RegisterProcessActor(const nsACString& aName,
const ProcessActorOptions& aOptions,
ErrorResult& aRv);
void UnregisterProcessActor(const nsACString& aName);
// Get the named of Content Actor and the child's ProcessActorOptions
// from mDescriptors to JSProcessActorInfos.
void GetJSProcessActorInfos(nsTArray<JSProcessActorInfo>& aInfos);
already_AddRefed<JSProcessActorProtocol> GetJSProcessActorProtocol(
const nsACString& aName);
private:
JSActorService();
~JSActorService();
nsTArray<EventTarget*> mChromeEventTargets;
// -- Window Actor
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorProtocol>
mWindowActorDescriptors;
// -- Content Actor
nsRefPtrHashtable<nsCStringHashKey, JSProcessActorProtocol>
mProcessActorDescriptors;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSActorService_h

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

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSProcessActorBinding.h"
#include "mozilla/dom/JSProcessActorChild.h"
#include "mozilla/ipc/InProcessChild.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSProcessActorChild, JSActor, mManager)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSProcessActorChild, JSActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSProcessActorChild)
NS_INTERFACE_MAP_END_INHERITING(JSActor)
NS_IMPL_ADDREF_INHERITED(JSProcessActorChild, JSActor)
NS_IMPL_RELEASE_INHERITED(JSProcessActorChild, JSActor)
JSObject* JSProcessActorChild::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return JSProcessActorChild_Binding::Wrap(aCx, this, aGivenProto);
}
void JSProcessActorChild::SendRawMessage(const JSActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) {
// We only ever have JSProcessActorChild in a multi-process scenario.
MOZ_ASSERT(XRE_IsContentProcess());
if (NS_WARN_IF(!mCanSend || !mManager || !mManager->CanSend())) {
aRv.ThrowInvalidStateError("JSProcessActorChild cannot send at the moment");
return;
}
if (NS_WARN_IF(
!AllowMessage(aMeta, aData.DataLength() + aStack.DataLength()))) {
aRv.ThrowDataCloneError(
nsPrintfCString("JSProcessActorChild serialization error: data too "
"large, in actor '%s'",
PromiseFlatCString(aMeta.actorName()).get()));
return;
}
ClonedMessageData msgData;
ClonedMessageData stackData;
if (NS_WARN_IF(!aData.BuildClonedMessageDataForChild(mManager, msgData)) ||
NS_WARN_IF(!aStack.BuildClonedMessageDataForChild(mManager, stackData))) {
aRv.ThrowDataCloneError(nsPrintfCString(
"JSProcessActorChild serialization error: cannot clone, in actor '%s'",
PromiseFlatCString(aMeta.actorName()).get()));
return;
}
if (NS_WARN_IF(!mManager->SendRawMessage(aMeta, msgData, stackData))) {
aRv.ThrowOperationError(
nsPrintfCString("JSProcessActorChild send error in actor '%s'",
PromiseFlatCString(aMeta.actorName()).get()));
return;
}
}
void JSProcessActorChild::Init(const nsACString& aName,
ContentChild* aManager) {
MOZ_ASSERT(!mManager, "Cannot Init() a JSProcessActorChild twice!");
SetName(aName);
mManager = aManager;
InvokeCallback(CallbackFunction::ActorCreated);
}
void JSProcessActorChild::AfterDestroy() {
JSActor::AfterDestroy();
mManager = nullptr;
}
} // namespace dom
} // namespace mozilla

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

@ -1,59 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSProcessActorChild_h
#define mozilla_dom_JSProcessActorChild_h
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/JSActor.h"
namespace mozilla {
namespace dom {
// Placeholder implementation.
class JSProcessActorChild final : public JSActor {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(JSProcessActorChild,
JSActor)
nsIGlobalObject* GetParentObject() const override {
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
}
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<JSProcessActorChild> Constructor(
GlobalObject& aGlobal) {
return MakeAndAddRef<JSProcessActorChild>();
}
ContentChild* Manager() const { return mManager; }
void Init(const nsACString& aName, ContentChild* aManager);
void AfterDestroy();
protected:
// Send the message described by the structured clone data |aData|, and the
// message metadata |aMetadata|. The underlying transport should call the
// |ReceiveMessage| method on the other side asynchronously.
virtual void SendRawMessage(const JSActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) override;
private:
~JSProcessActorChild() { MOZ_ASSERT(!mManager); }
bool mCanSend = true;
RefPtr<ContentChild> mManager;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSProcessActorChild_h

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

@ -1,84 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSProcessActorBinding.h"
#include "mozilla/dom/JSProcessActorParent.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSProcessActorParent, JSActor, mManager)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSProcessActorParent, JSActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSProcessActorParent)
NS_INTERFACE_MAP_END_INHERITING(JSActor)
NS_IMPL_ADDREF_INHERITED(JSProcessActorParent, JSActor)
NS_IMPL_RELEASE_INHERITED(JSProcessActorParent, JSActor)
JSObject* JSProcessActorParent::WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return JSProcessActorParent_Binding::Wrap(aCx, this, aGivenProto);
}
void JSProcessActorParent::Init(const nsACString& aName,
ContentParent* aManager) {
MOZ_ASSERT(!mManager, "Cannot Init() a JSProcessActorParent twice!");
SetName(aName);
mManager = aManager;
}
JSProcessActorParent::~JSProcessActorParent() { MOZ_ASSERT(!mManager); }
void JSProcessActorParent::SendRawMessage(const JSActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) {
if (NS_WARN_IF(!mCanSend || !mManager || !mManager->CanSend())) {
aRv.ThrowInvalidStateError(
nsPrintfCString("Actor '%s' cannot send message '%s' during shutdown.",
PromiseFlatCString(aMeta.actorName()).get(),
NS_ConvertUTF16toUTF8(aMeta.messageName()).get()));
return;
}
if (NS_WARN_IF(
!AllowMessage(aMeta, aData.DataLength() + aStack.DataLength()))) {
aRv.ThrowDataError(nsPrintfCString(
"Actor '%s' cannot send message '%s': message too long.",
PromiseFlatCString(aMeta.actorName()).get(),
NS_ConvertUTF16toUTF8(aMeta.messageName()).get()));
return;
}
// Cross-process case - send data over ContentParent to other side.
ClonedMessageData msgData;
ClonedMessageData stackData;
if (NS_WARN_IF(!aData.BuildClonedMessageDataForParent(mManager, msgData)) ||
NS_WARN_IF(
!aStack.BuildClonedMessageDataForParent(mManager, stackData))) {
aRv.ThrowDataCloneError(
nsPrintfCString("Actor '%s' cannot send message '%s': cannot clone.",
PromiseFlatCString(aMeta.actorName()).get(),
NS_ConvertUTF16toUTF8(aMeta.messageName()).get()));
return;
}
if (NS_WARN_IF(!mManager->SendRawMessage(aMeta, msgData, stackData))) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
}
}
void JSProcessActorParent::AfterDestroy() {
JSActor::AfterDestroy();
mManager = nullptr;
}
} // namespace dom
} // namespace mozilla

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

@ -1,65 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSProcessActorParent_h
#define mozilla_dom_JSProcessActorParent_h
#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/JSActor.h"
#include "mozilla/extensions/WebExtensionContentScript.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
namespace mozilla {
namespace dom {
class JSProcessActorParent final : public JSActor {
public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(JSProcessActorParent,
JSActor)
nsIGlobalObject* GetParentObject() const override {
return xpc::NativeGlobal(xpc::PrivilegedJunkScope());
}
JSObject* WrapObject(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) override;
static already_AddRefed<JSProcessActorParent> Constructor(
GlobalObject& aGlobal) {
return MakeAndAddRef<JSProcessActorParent>();
}
ContentParent* Manager() const { return mManager; }
void Init(const nsACString& aName, ContentParent* aManager);
void AfterDestroy();
protected:
// Send the message described by the structured clone data |aData|, and the
// message metadata |aMetadata|. The underlying transport should call the
// |ReceiveMessage| method on the other side asynchronously.
virtual void SendRawMessage(const JSActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) override;
private:
~JSProcessActorParent();
bool mCanSend = true;
RefPtr<ContentParent> mManager;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSProcessActorParent_h

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

@ -1,144 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSProcessActorProtocol.h"
namespace mozilla {
namespace dom {
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSProcessActorProtocol)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSProcessActorProtocol)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSProcessActorProtocol)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTION(JSProcessActorProtocol)
/* static */ already_AddRefed<JSProcessActorProtocol>
JSProcessActorProtocol::FromIPC(const JSProcessActorInfo& aInfo) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsContentProcess());
RefPtr<JSProcessActorProtocol> proto =
new JSProcessActorProtocol(aInfo.name());
proto->mRemoteTypes = aInfo.remoteTypes();
proto->mChild.mModuleURI = aInfo.url();
proto->mChild.mObservers = aInfo.observers();
return proto.forget();
}
JSProcessActorInfo JSProcessActorProtocol::ToIPC() {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
JSProcessActorInfo info;
info.name() = mName;
info.remoteTypes() = mRemoteTypes;
info.url() = mChild.mModuleURI;
info.observers() = mChild.mObservers;
return info;
}
already_AddRefed<JSProcessActorProtocol>
JSProcessActorProtocol::FromWebIDLOptions(const nsACString& aName,
const ProcessActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
RefPtr<JSProcessActorProtocol> proto = new JSProcessActorProtocol(aName);
if (aOptions.mParent.WasPassed()) {
proto->mParent.mModuleURI.emplace(aOptions.mParent.Value().mModuleURI);
}
if (aOptions.mChild.WasPassed()) {
proto->mChild.mModuleURI.emplace(aOptions.mChild.Value().mModuleURI);
}
if (!aOptions.mChild.WasPassed() && !aOptions.mParent.WasPassed()) {
aRv.ThrowNotSupportedError(
"No point registering an actor with neither child nor parent "
"specifications.");
return nullptr;
}
if (aOptions.mChild.WasPassed() &&
aOptions.mChild.Value().mObservers.WasPassed()) {
proto->mChild.mObservers = aOptions.mChild.Value().mObservers.Value();
}
return proto.forget();
}
NS_IMETHODIMP JSProcessActorProtocol::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
ErrorResult error;
RefPtr<JSProcessActorChild> actor =
ContentChild::GetSingleton()->GetActor(mName, error);
// Don't raise an error if creation of our actor was vetoed.
if (NS_WARN_IF(error.Failed())) {
nsresult rv = error.StealNSResult();
if (rv == NS_ERROR_NOT_AVAILABLE) {
return NS_OK;
}
return rv;
}
// Build a observer callback.
JS::Rooted<JSObject*> global(RootingCx(),
JS::GetNonCCWObjectGlobal(actor->GetWrapper()));
RefPtr<MozObserverCallback> observerCallback =
new MozObserverCallback(actor->GetWrapper(), global, nullptr, nullptr);
observerCallback->Observe(aSubject, nsDependentCString(aTopic),
aData ? nsDependentString(aData) : VoidString());
return NS_OK;
}
void JSProcessActorProtocol::AddObservers() {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
for (auto& topic : mChild.mObservers) {
// This makes the observer service hold an owning reference to the
// JSProcessActorProtocol. The JSWindowActorProtocol objects will be living
// for the full lifetime of the content process, thus the extra strong
// referencec doesn't have a negative impact.
os->AddObserver(this, topic.get(), false);
}
}
void JSProcessActorProtocol::RemoveObservers() {
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
for (auto& topic : mChild.mObservers) {
os->RemoveObserver(this, topic.get());
}
}
bool JSProcessActorProtocol::RemoteTypePrefixMatches(
const nsDependentSubstring& aRemoteType) {
for (auto& remoteType : mRemoteTypes) {
if (StringBeginsWith(aRemoteType, remoteType)) {
return true;
}
}
return false;
}
bool JSProcessActorProtocol::Matches(const nsAString& aRemoteType) {
if (!mRemoteTypes.IsEmpty() &&
!RemoteTypePrefixMatches(RemoteTypePrefix(aRemoteType))) {
return false;
}
return true;
}
} // namespace dom
} // namespace mozilla

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

@ -1,76 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSProcessActorProtocol_h
#define mozilla_dom_JSProcessActorProtocol_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/ErrorResult.h"
#include "nsIURI.h"
#include "nsString.h"
#include "nsTArray.h"
#include "nsIObserver.h"
namespace mozilla {
namespace dom {
struct ProcessActorOptions;
class JSProcessActorInfo;
class EventTarget;
/**
* Object corresponding to a single process actor protocol
*
* This object also can act as a carrier for methods and other state related to
* a single protocol managed by the JSActorService.
*/
class JSProcessActorProtocol final : public nsIObserver {
public:
NS_DECL_NSIOBSERVER
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(JSProcessActorProtocol, nsIObserver)
static already_AddRefed<JSProcessActorProtocol> FromIPC(
const JSProcessActorInfo& aInfo);
JSProcessActorInfo ToIPC();
static already_AddRefed<JSProcessActorProtocol> FromWebIDLOptions(
const nsACString& aName, const ProcessActorOptions& aOptions,
ErrorResult& aRv);
struct Sided {
Maybe<nsCString> mModuleURI;
};
struct ParentSide : public Sided {};
struct ChildSide : public Sided {
nsTArray<nsCString> mObservers;
};
const ParentSide& Parent() const { return mParent; }
const ChildSide& Child() const { return mChild; }
void AddObservers();
void RemoveObservers();
bool Matches(const nsAString& aRemoteType);
private:
explicit JSProcessActorProtocol(const nsACString& aName) : mName(aName) {}
bool RemoteTypePrefixMatches(const nsDependentSubstring& aRemoteType);
~JSProcessActorProtocol() = default;
nsCString mName;
nsTArray<nsString> mRemoteTypes;
ParentSide mParent;
ChildSide mChild;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSProcessActorProtocol_h

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

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSActor.h"
#include "mozilla/dom/JSActorBinding.h"
#include "mozilla/dom/JSWindowActor.h"
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/Attributes.h"
#include "mozilla/Telemetry.h"
@ -24,30 +24,30 @@
namespace mozilla {
namespace dom {
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSActor)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActor)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSActor)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSActor)
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSWindowActor)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_CLASS(JSActor)
NS_IMPL_CYCLE_COLLECTION_CLASS(JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(JSActor)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mWrappedJS)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPendingQueries)
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(JSActor)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mWrappedJS)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPendingQueries)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(JSActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(JSWindowActor)
JSActor::JSActor() : mNextQueryId(0) {}
JSWindowActor::JSWindowActor() : mNextQueryId(0) {}
// RAII class to ensure that, if we crash while handling a message, the
// crash will be annotated with the name of the actor and the message.
@ -67,13 +67,13 @@ struct MOZ_RAII AutoAnnotateMessageInCaseOfCrash {
}
};
void JSActor::StartDestroy() {
void JSWindowActor::StartDestroy() {
AutoAnnotateMessageInCaseOfCrash guard(/* aActorName = */ mName,
NS_LITERAL_CSTRING("<WillDestroy>"));
InvokeCallback(CallbackFunction::WillDestroy);
}
void JSActor::AfterDestroy() {
void JSWindowActor::AfterDestroy() {
AutoAnnotateMessageInCaseOfCrash guard(/* aActorName = */ mName,
NS_LITERAL_CSTRING("<DidDestroy>"));
InvokeCallback(CallbackFunction::DidDestroy);
@ -81,12 +81,12 @@ void JSActor::AfterDestroy() {
RejectPendingQueries();
}
void JSActor::InvokeCallback(CallbackFunction callback) {
void JSWindowActor::InvokeCallback(CallbackFunction callback) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
AutoEntryScript aes(GetParentObject(), "JSActor destroy callback");
AutoEntryScript aes(GetParentObject(), "JSWindowActor destroy callback");
JSContext* cx = aes.cx();
MozJSActorCallbacks callbacksHolder;
MozJSWindowActorCallbacks callbacksHolder;
NS_ENSURE_TRUE_VOID(GetWrapper());
JS::Rooted<JS::Value> val(cx, JS::ObjectValue(*GetWrapper()));
if (NS_WARN_IF(!callbacksHolder.Init(cx, val))) {
@ -109,11 +109,11 @@ void JSActor::InvokeCallback(CallbackFunction callback) {
}
}
nsresult JSActor::QueryInterfaceActor(const nsIID& aIID, void** aPtr) {
nsresult JSWindowActor::QueryInterfaceActor(const nsIID& aIID, void** aPtr) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
if (!mWrappedJS) {
AutoEntryScript aes(GetParentObject(), "JSActor query interface");
AutoEntryScript aes(GetParentObject(), "JSWindowActor query interface");
JSContext* cx = aes.cx();
JS::Rooted<JSObject*> self(cx, GetWrapper());
@ -131,7 +131,7 @@ nsresult JSActor::QueryInterfaceActor(const nsIID& aIID, void** aPtr) {
return mWrappedJS->QueryInterface(aIID, aPtr);
}
void JSActor::RejectPendingQueries() {
void JSWindowActor::RejectPendingQueries() {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
// Take our queries out, in case somehow rejecting promises can trigger
@ -144,8 +144,8 @@ void JSActor::RejectPendingQueries() {
}
/* static */
bool JSActor::AllowMessage(const JSActorMessageMeta& aMetadata,
size_t aDataLength) {
bool JSWindowActor::AllowMessage(const JSWindowActorMessageMeta& aMetadata,
size_t aDataLength) {
// A message includes more than structured clone data, so subtract
// 20KB to make it more likely that a message within this bound won't
// result in an overly large IPC message.
@ -170,7 +170,7 @@ bool JSActor::AllowMessage(const JSActorMessageMeta& aMetadata,
return false;
}
void JSActor::SetName(const nsACString& aName) {
void JSWindowActor::SetName(const nsACString& aName) {
MOZ_ASSERT(mName.IsEmpty(), "Cannot set name twice!");
mName = aName;
}
@ -203,8 +203,10 @@ static ipc::StructuredCloneData CaptureJSStack(JSContext* aCx) {
return CloneJSStack(aCx, stack);
}
void JSActor::SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
JS::Handle<JS::Value> aObj, ErrorResult& aRv) {
void JSWindowActor::SendAsyncMessage(JSContext* aCx,
const nsAString& aMessageName,
JS::Handle<JS::Value> aObj,
ErrorResult& aRv) {
ipc::StructuredCloneData data;
if (!nsFrameMessageManager::GetParamsForMessage(
aCx, aObj, JS::UndefinedHandleValue, data)) {
@ -212,18 +214,17 @@ void JSActor::SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
return;
}
JSActorMessageMeta meta;
JSWindowActorMessageMeta meta;
meta.actorName() = mName;
meta.messageName() = aMessageName;
meta.kind() = JSActorMessageKind::Message;
meta.kind() = JSWindowActorMessageKind::Message;
SendRawMessage(meta, std::move(data), CaptureJSStack(aCx), aRv);
}
already_AddRefed<Promise> JSActor::SendQuery(JSContext* aCx,
const nsAString& aMessageName,
JS::Handle<JS::Value> aObj,
ErrorResult& aRv) {
already_AddRefed<Promise> JSWindowActor::SendQuery(
JSContext* aCx, const nsAString& aMessageName, JS::Handle<JS::Value> aObj,
ErrorResult& aRv) {
ipc::StructuredCloneData data;
if (!nsFrameMessageManager::GetParamsForMessage(
aCx, aObj, JS::UndefinedHandleValue, data)) {
@ -242,11 +243,11 @@ already_AddRefed<Promise> JSActor::SendQuery(JSContext* aCx,
return nullptr;
}
JSActorMessageMeta meta;
JSWindowActorMessageMeta meta;
meta.actorName() = mName;
meta.messageName() = aMessageName;
meta.queryId() = mNextQueryId++;
meta.kind() = JSActorMessageKind::Query;
meta.kind() = JSWindowActorMessageKind::Query;
mPendingQueries.Put(meta.queryId(), RefPtr{promise});
@ -263,15 +264,15 @@ already_AddRefed<Promise> JSActor::SendQuery(JSContext* aCx,
} \
} while (0)
void JSActor::ReceiveRawMessage(const JSActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack) {
void JSWindowActor::ReceiveRawMessage(const JSWindowActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
AutoAnnotateMessageInCaseOfCrash guard(
/* aActorName = */ mName,
NS_LossyConvertUTF16toASCII(aMetadata.messageName()));
AutoEntryScript aes(GetParentObject(), "JSActor message handler");
AutoEntryScript aes(GetParentObject(), "JSWindowActor message handler");
JSContext* cx = aes.cx();
// Read the message into a JS object from IPC.
@ -295,18 +296,18 @@ void JSActor::ReceiveRawMessage(const JSActorMessageMeta& aMetadata,
CHILD_DIAGNOSTIC_ASSERT(false, "Stack must be a SavedFrame object");
return;
}
stackSetter.emplace(cx, stack, "JSActor query");
stackSetter.emplace(cx, stack, "JSWindowActor query");
}
}
switch (aMetadata.kind()) {
case JSActorMessageKind::QueryResolve:
case JSActorMessageKind::QueryReject:
case JSWindowActorMessageKind::QueryResolve:
case JSWindowActorMessageKind::QueryReject:
ReceiveQueryReply(cx, aMetadata, data, error);
break;
case JSActorMessageKind::Message:
case JSActorMessageKind::Query:
case JSWindowActorMessageKind::Message:
case JSWindowActorMessageKind::Query:
ReceiveMessageOrQuery(cx, aMetadata, data, error);
break;
@ -317,10 +318,9 @@ void JSActor::ReceiveRawMessage(const JSActorMessageMeta& aMetadata,
Unused << error.MaybeSetPendingException(cx);
}
void JSActor::ReceiveMessageOrQuery(JSContext* aCx,
const JSActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData,
ErrorResult& aRv) {
void JSWindowActor::ReceiveMessageOrQuery(
JSContext* aCx, const JSWindowActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData, ErrorResult& aRv) {
// The argument which we want to pass to IPC.
RootedDictionary<ReceiveMessageArgument> argument(aCx);
argument.mTarget = this;
@ -336,7 +336,7 @@ void JSActor::ReceiveMessageOrQuery(JSContext* aCx,
// will be resolved or rejected once the listener has been called. Our
// listener on this promise will then send the reply.
RefPtr<Promise> promise;
if (aMetadata.kind() == JSActorMessageKind::Query) {
if (aMetadata.kind() == JSWindowActorMessageKind::Query) {
promise = Promise::Create(xpc::NativeGlobal(global), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
@ -351,7 +351,7 @@ void JSActor::ReceiveMessageOrQuery(JSContext* aCx,
RefPtr<MessageListener> messageListener =
new MessageListener(self, global, nullptr, nullptr);
messageListener->ReceiveMessage(argument, &retval, aRv,
"JSActor receive message",
"JSWindowActor receive message",
MessageListener::eRethrowExceptions);
// If we have a promise, resolve or reject it respectively.
@ -370,9 +370,10 @@ void JSActor::ReceiveMessageOrQuery(JSContext* aCx,
}
}
void JSActor::ReceiveQueryReply(JSContext* aCx,
const JSActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData, ErrorResult& aRv) {
void JSWindowActor::ReceiveQueryReply(JSContext* aCx,
const JSWindowActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData,
ErrorResult& aRv) {
if (NS_WARN_IF(aMetadata.actorName() != mName)) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return;
@ -392,7 +393,7 @@ void JSActor::ReceiveQueryReply(JSContext* aCx,
return;
}
if (aMetadata.kind() == JSActorMessageKind::QueryResolve) {
if (aMetadata.kind() == JSWindowActorMessageKind::QueryResolve) {
promise->MaybeResolve(data);
} else {
promise->MaybeReject(data);
@ -401,16 +402,16 @@ void JSActor::ReceiveQueryReply(JSContext* aCx,
// Native handler for our generated promise which is used to handle Queries and
// send the reply when their promises have been resolved.
JSActor::QueryHandler::QueryHandler(JSActor* aActor,
const JSActorMessageMeta& aMetadata,
Promise* aPromise)
JSWindowActor::QueryHandler::QueryHandler(
JSWindowActor* aActor, const JSWindowActorMessageMeta& aMetadata,
Promise* aPromise)
: mActor(aActor),
mPromise(aPromise),
mMessageName(aMetadata.messageName()),
mQueryId(aMetadata.queryId()) {}
void JSActor::QueryHandler::RejectedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue) {
void JSWindowActor::QueryHandler::RejectedCallback(
JSContext* aCx, JS::Handle<JS::Value> aValue) {
if (!mActor) {
// Make sure that this rejection is reported. See comment below.
Unused << JS::CallOriginalPromiseReject(aCx, aValue);
@ -451,11 +452,11 @@ void JSActor::QueryHandler::RejectedCallback(JSContext* aCx,
data->Write(aCx, JS::UndefinedHandleValue, rv);
}
SendReply(aCx, JSActorMessageKind::QueryReject, std::move(*data));
SendReply(aCx, JSWindowActorMessageKind::QueryReject, std::move(*data));
}
void JSActor::QueryHandler::ResolvedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue) {
void JSWindowActor::QueryHandler::ResolvedCallback(
JSContext* aCx, JS::Handle<JS::Value> aValue) {
if (!mActor) {
return;
}
@ -483,14 +484,15 @@ void JSActor::QueryHandler::ResolvedCallback(JSContext* aCx,
return;
}
SendReply(aCx, JSActorMessageKind::QueryResolve, std::move(data));
SendReply(aCx, JSWindowActorMessageKind::QueryResolve, std::move(data));
}
void JSActor::QueryHandler::SendReply(JSContext* aCx, JSActorMessageKind aKind,
ipc::StructuredCloneData&& aData) {
void JSWindowActor::QueryHandler::SendReply(JSContext* aCx,
JSWindowActorMessageKind aKind,
ipc::StructuredCloneData&& aData) {
MOZ_ASSERT(mActor);
JSActorMessageMeta meta;
JSWindowActorMessageMeta meta;
meta.actorName() = mActor->Name();
meta.messageName() = mMessageName;
meta.queryId() = mQueryId;
@ -505,14 +507,14 @@ void JSActor::QueryHandler::SendReply(JSContext* aCx, JSActorMessageKind aKind,
mPromise = nullptr;
}
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSActor::QueryHandler)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActor::QueryHandler)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSActor::QueryHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSActor::QueryHandler)
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSWindowActor::QueryHandler)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSWindowActor::QueryHandler)
NS_IMPL_CYCLE_COLLECTION(JSActor::QueryHandler, mActor, mPromise)
NS_IMPL_CYCLE_COLLECTION(JSWindowActor::QueryHandler, mActor, mPromise)
} // namespace dom
} // namespace mozilla

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

@ -4,8 +4,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSActor_h
#define mozilla_dom_JSActor_h
#ifndef mozilla_dom_JSWindowActor_h
#define mozilla_dom_JSWindowActor_h
#include "js/TypeDecls.h"
#include "ipc/IPCMessageUtils.h"
@ -23,7 +23,7 @@ class nsQueryActorParent;
namespace mozilla {
namespace dom {
enum class JSActorMessageKind {
enum class JSWindowActorMessageKind {
Message,
Query,
QueryResolve,
@ -31,16 +31,16 @@ enum class JSActorMessageKind {
EndGuard_,
};
class JSActorMessageMeta;
class JSWindowActorMessageMeta;
class QueryPromiseHandler;
// Common base class for JSWindowActor{Parent,Child}.
class JSActor : public nsISupports, public nsWrapperCache {
class JSWindowActor : public nsISupports, public nsWrapperCache {
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(JSActor)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(JSWindowActor)
JSActor();
JSWindowActor();
enum class Type { Parent, Child };
enum class CallbackFunction { WillDestroy, DidDestroy, ActorCreated };
@ -55,7 +55,7 @@ class JSActor : public nsISupports, public nsWrapperCache {
JS::Handle<JS::Value> aObj,
ErrorResult& aRv);
void ReceiveRawMessage(const JSActorMessageMeta& aMetadata,
void ReceiveRawMessage(const JSWindowActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack);
@ -67,17 +67,17 @@ class JSActor : public nsISupports, public nsWrapperCache {
// Send the message described by the structured clone data |aData|, and the
// message metadata |aMetadata|. The underlying transport should call the
// |ReceiveMessage| method on the other side asynchronously.
virtual void SendRawMessage(const JSActorMessageMeta& aMetadata,
virtual void SendRawMessage(const JSWindowActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) = 0;
// Check if a message is so large that IPC will probably crash if we try to
// send it. If it is too large, record telemetry about the message.
static bool AllowMessage(const JSActorMessageMeta& aMetadata,
static bool AllowMessage(const JSWindowActorMessageMeta& aMetadata,
size_t aDataLength);
virtual ~JSActor() = default;
virtual ~JSWindowActor() = default;
void SetName(const nsACString& aName);
@ -94,10 +94,11 @@ class JSActor : public nsISupports, public nsWrapperCache {
nsresult QueryInterfaceActor(const nsIID& aIID, void** aPtr);
void ReceiveMessageOrQuery(JSContext* aCx,
const JSActorMessageMeta& aMetadata,
const JSWindowActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData, ErrorResult& aRv);
void ReceiveQueryReply(JSContext* aCx, const JSActorMessageMeta& aMetadata,
void ReceiveQueryReply(JSContext* aCx,
const JSWindowActorMessageMeta& aMetadata,
JS::Handle<JS::Value> aData, ErrorResult& aRv);
// Helper object used while processing query messages to send the final reply
@ -107,8 +108,8 @@ class JSActor : public nsISupports, public nsWrapperCache {
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(QueryHandler)
QueryHandler(JSActor* aActor, const JSActorMessageMeta& aMetadata,
Promise* aPromise);
QueryHandler(JSWindowActor* aActor,
const JSWindowActorMessageMeta& aMetadata, Promise* aPromise);
void RejectedCallback(JSContext* aCx,
JS::Handle<JS::Value> aValue) override;
@ -119,10 +120,10 @@ class JSActor : public nsISupports, public nsWrapperCache {
private:
~QueryHandler() = default;
void SendReply(JSContext* aCx, JSActorMessageKind aKind,
void SendReply(JSContext* aCx, JSWindowActorMessageKind aKind,
ipc::StructuredCloneData&& aData);
RefPtr<JSActor> mActor;
RefPtr<JSWindowActor> mActor;
RefPtr<Promise> mPromise;
nsString mMessageName;
uint64_t mQueryId;
@ -140,12 +141,12 @@ class JSActor : public nsISupports, public nsWrapperCache {
namespace IPC {
template <>
struct ParamTraits<mozilla::dom::JSActorMessageKind>
struct ParamTraits<mozilla::dom::JSWindowActorMessageKind>
: public ContiguousEnumSerializer<
mozilla::dom::JSActorMessageKind,
mozilla::dom::JSActorMessageKind::Message,
mozilla::dom::JSActorMessageKind::EndGuard_> {};
mozilla::dom::JSWindowActorMessageKind,
mozilla::dom::JSWindowActorMessageKind::Message,
mozilla::dom::JSWindowActorMessageKind::EndGuard_> {};
} // namespace IPC
#endif // !defined(mozilla_dom_JSActor_h)
#endif // !defined(mozilla_dom_JSWindowActor_h)

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

@ -43,7 +43,7 @@ namespace {
class AsyncMessageToParent : public Runnable {
public:
AsyncMessageToParent(const JSActorMessageMeta& aMetadata,
AsyncMessageToParent(const JSWindowActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
WindowGlobalChild* aManager)
@ -63,7 +63,7 @@ class AsyncMessageToParent : public Runnable {
}
private:
JSActorMessageMeta mMetadata;
JSWindowActorMessageMeta mMetadata;
ipc::StructuredCloneData mData;
ipc::StructuredCloneData mStack;
RefPtr<WindowGlobalChild> mManager;
@ -71,7 +71,7 @@ class AsyncMessageToParent : public Runnable {
} // anonymous namespace
void JSWindowActorChild::SendRawMessage(const JSActorMessageMeta& aMeta,
void JSWindowActorChild::SendRawMessage(const JSWindowActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) {
@ -145,25 +145,26 @@ Nullable<WindowProxyHolder> JSWindowActorChild::GetContentWindow(
}
void JSWindowActorChild::StartDestroy() {
JSActor::StartDestroy();
JSWindowActor::StartDestroy();
mCanSend = false;
}
void JSWindowActorChild::AfterDestroy() {
JSActor::AfterDestroy();
JSWindowActor::AfterDestroy();
mManager = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorChild, JSActor, mManager)
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorChild, JSWindowActor, mManager)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSWindowActorChild, JSActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSWindowActorChild,
JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActorChild)
NS_INTERFACE_MAP_END_INHERITING(JSActor)
NS_INTERFACE_MAP_END_INHERITING(JSWindowActor)
NS_IMPL_ADDREF_INHERITED(JSWindowActorChild, JSActor)
NS_IMPL_RELEASE_INHERITED(JSWindowActorChild, JSActor)
NS_IMPL_ADDREF_INHERITED(JSWindowActorChild, JSWindowActor)
NS_IMPL_RELEASE_INHERITED(JSWindowActorChild, JSWindowActor)
} // namespace dom
} // namespace mozilla

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

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -11,11 +11,9 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/JSWindowActor.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"
#include "nsIContentChild.h"
namespace mozilla {
namespace dom {

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

@ -37,7 +37,7 @@ namespace {
class AsyncMessageToChild : public Runnable {
public:
AsyncMessageToChild(const JSActorMessageMeta& aMetadata,
AsyncMessageToChild(const JSWindowActorMessageMeta& aMetadata,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
WindowGlobalParent* aManager)
@ -57,7 +57,7 @@ class AsyncMessageToChild : public Runnable {
}
private:
JSActorMessageMeta mMetadata;
JSWindowActorMessageMeta mMetadata;
ipc::StructuredCloneData mData;
ipc::StructuredCloneData mStack;
RefPtr<WindowGlobalParent> mManager;
@ -65,7 +65,7 @@ class AsyncMessageToChild : public Runnable {
} // anonymous namespace
void JSWindowActorParent::SendRawMessage(const JSActorMessageMeta& aMeta,
void JSWindowActorParent::SendRawMessage(const JSWindowActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack,
ErrorResult& aRv) {
@ -115,25 +115,26 @@ CanonicalBrowsingContext* JSWindowActorParent::GetBrowsingContext(
}
void JSWindowActorParent::StartDestroy() {
JSActor::StartDestroy();
JSWindowActor::StartDestroy();
mCanSend = false;
}
void JSWindowActorParent::AfterDestroy() {
JSActor::AfterDestroy();
JSWindowActor::AfterDestroy();
mManager = nullptr;
}
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorParent, JSActor, mManager)
NS_IMPL_CYCLE_COLLECTION_INHERITED(JSWindowActorParent, JSWindowActor, mManager)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSWindowActorParent, JSActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(JSWindowActorParent,
JSWindowActor)
NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(JSWindowActorParent)
NS_INTERFACE_MAP_END_INHERITING(JSActor)
NS_INTERFACE_MAP_END_INHERITING(JSWindowActor)
NS_IMPL_ADDREF_INHERITED(JSWindowActorParent, JSActor)
NS_IMPL_RELEASE_INHERITED(JSWindowActorParent, JSActor)
NS_IMPL_ADDREF_INHERITED(JSWindowActorParent, JSWindowActor)
NS_IMPL_RELEASE_INHERITED(JSWindowActorParent, JSWindowActor)
} // namespace dom
} // namespace mozilla

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

@ -11,7 +11,6 @@
#include "mozilla/Attributes.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/JSWindowActor.h"
#include "nsCycleCollectionParticipant.h"
#include "nsWrapperCache.h"

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

@ -5,10 +5,26 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/ChromeUtilsBinding.h"
#include "mozilla/dom/EventListenerBinding.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventTargetBinding.h"
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/MessageManagerBinding.h"
#include "mozilla/dom/PContent.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/WindowGlobalChild.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/Logging.h"
namespace mozilla {
namespace dom {
namespace {
StaticRefPtr<JSWindowActorService> gJSWindowActorService;
}
NS_IMPL_CYCLE_COLLECTING_ADDREF(JSWindowActorProtocol)
NS_IMPL_CYCLE_COLLECTING_RELEASE(JSWindowActorProtocol)
@ -126,7 +142,7 @@ JSWindowActorProtocol::FromWebIDLOptions(const nsACString& aName,
// We don't support the mOnce field, as it doesn't work well in this
// environment. For now, throw an error in that case.
if (entry.mValue.mOnce) {
aRv.ThrowNotSupportedError("mOnce is not supported");
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return nullptr;
}
@ -362,5 +378,137 @@ bool JSWindowActorProtocol::Matches(BrowsingContext* aBrowsingContext,
return true;
}
JSWindowActorService::JSWindowActorService() { MOZ_ASSERT(NS_IsMainThread()); }
JSWindowActorService::~JSWindowActorService() { MOZ_ASSERT(NS_IsMainThread()); }
/* static */
already_AddRefed<JSWindowActorService> JSWindowActorService::GetSingleton() {
MOZ_ASSERT(NS_IsMainThread());
if (!gJSWindowActorService) {
gJSWindowActorService = new JSWindowActorService();
ClearOnShutdown(&gJSWindowActorService);
}
RefPtr<JSWindowActorService> service = gJSWindowActorService.get();
return service.forget();
}
void JSWindowActorService::RegisterWindowActor(
const nsACString& aName, const WindowActorOptions& aOptions,
ErrorResult& aRv) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
auto entry = mDescriptors.LookupForAdd(aName);
if (entry) {
aRv.ThrowNotSupportedError(nsPrintfCString(
"'%s' actor is already registered.", PromiseFlatCString(aName).get()));
return;
}
// Insert a new entry for the protocol.
RefPtr<JSWindowActorProtocol> proto =
JSWindowActorProtocol::FromWebIDLOptions(aName, aOptions, aRv);
if (NS_WARN_IF(aRv.Failed())) {
entry.OrRemove();
return;
}
entry.OrInsert([&] { return proto; });
// Send information about the newly added entry to every existing content
// process.
AutoTArray<JSWindowActorInfo, 1> ipcInfos{proto->ToIPC()};
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendInitJSWindowActorInfos(ipcInfos);
}
// Register event listeners for any existing chrome targets.
for (EventTarget* target : mChromeEventTargets) {
proto->RegisterListenersFor(target);
}
// Add observers to the protocol.
proto->AddObservers();
}
void JSWindowActorService::UnregisterWindowActor(const nsACString& aName) {
nsAutoCString name(aName);
RefPtr<JSWindowActorProtocol> proto;
if (mDescriptors.Remove(aName, getter_AddRefs(proto))) {
// If we're in the parent process, also unregister the window actor in all
// live content processes.
if (XRE_IsParentProcess()) {
for (auto* cp : ContentParent::AllProcesses(ContentParent::eLive)) {
Unused << cp->SendUnregisterJSWindowActor(name);
}
}
// Remove listeners for this actor from each of our chrome targets.
for (EventTarget* target : mChromeEventTargets) {
proto->UnregisterListenersFor(target);
}
// Remove observers for this actor from observer serivce.
proto->RemoveObservers();
}
}
void JSWindowActorService::LoadJSWindowActorInfos(
nsTArray<JSWindowActorInfo>& aInfos) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsContentProcess());
for (uint32_t i = 0, len = aInfos.Length(); i < len; i++) {
// Create our JSWindowActorProtocol, register it in mDescriptors.
RefPtr<JSWindowActorProtocol> proto =
JSWindowActorProtocol::FromIPC(aInfos[i]);
mDescriptors.Put(aInfos[i].name(), RefPtr{proto});
// Register listeners for each chrome target.
for (EventTarget* target : mChromeEventTargets) {
proto->RegisterListenersFor(target);
}
// Add observers for each actor.
proto->AddObservers();
}
}
void JSWindowActorService::GetJSWindowActorInfos(
nsTArray<JSWindowActorInfo>& aInfos) {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(XRE_IsParentProcess());
for (auto iter = mDescriptors.ConstIter(); !iter.Done(); iter.Next()) {
aInfos.AppendElement(iter.Data()->ToIPC());
}
}
void JSWindowActorService::RegisterChromeEventTarget(EventTarget* aTarget) {
MOZ_ASSERT(!mChromeEventTargets.Contains(aTarget));
mChromeEventTargets.AppendElement(aTarget);
// Register event listeners on the newly added Window Root.
for (auto iter = mDescriptors.Iter(); !iter.Done(); iter.Next()) {
iter.Data()->RegisterListenersFor(aTarget);
}
}
/* static */
void JSWindowActorService::UnregisterChromeEventTarget(EventTarget* aTarget) {
if (gJSWindowActorService) {
// NOTE: No need to unregister listeners here, as the target is going away.
gJSWindowActorService->mChromeEventTargets.RemoveElement(aTarget);
}
}
already_AddRefed<JSWindowActorProtocol> JSWindowActorService::GetProtocol(
const nsACString& aName) {
return mDescriptors.Get(aName);
}
} // namespace dom
} // namespace mozilla

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

@ -4,32 +4,35 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_JSWindowActorProtocol_h
#define mozilla_dom_JSWindowActorProtocol_h
#ifndef mozilla_dom_JSWindowActorService_h
#define mozilla_dom_JSWindowActorService_h
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/ErrorResult.h"
#include "nsIURI.h"
#include "nsRefPtrHashtable.h"
#include "nsString.h"
#include "nsTArray.h"
#include "mozilla/dom/JSWindowActor.h"
#include "nsIObserver.h"
#include "nsIDOMEventListener.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/extensions/WebExtensionContentScript.h"
namespace mozilla {
namespace dom {
struct WindowActorOptions;
class JSWindowActorInfo;
class EventTarget;
/**
* Object corresponding to a single window actor protocol. This object acts as
* an Event listener for the actor which is called for events which would
* Object corresponding to a single actor protocol. This object acts as an
* Event listener for the actor which is called for events which would
* trigger actor creation.
*
* This object also can act as a carrier for methods and other state related to
* a single protocol managed by the JSActorService.
* a single protocol managed by the JSWindowActorService.
*/
class JSWindowActorProtocol final : public nsIObserver,
public nsIDOMEventListener {
@ -94,7 +97,42 @@ class JSWindowActorProtocol final : public nsIObserver,
RefPtr<extensions::MatchPatternSet> mURIMatcher;
};
class JSWindowActorService final {
public:
NS_INLINE_DECL_REFCOUNTING(JSWindowActorService)
static already_AddRefed<JSWindowActorService> GetSingleton();
void RegisterWindowActor(const nsACString& aName,
const WindowActorOptions& aOptions,
ErrorResult& aRv);
void UnregisterWindowActor(const nsACString& aName);
// Register child's Window Actor from JSWindowActorInfos for content process.
void LoadJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);
// Get the named of Window Actor and the child's WindowActorOptions
// from mDescriptors to JSWindowActorInfos.
void GetJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);
// Register or unregister a chrome event target.
void RegisterChromeEventTarget(EventTarget* aTarget);
// NOTE: This method is static, as it may be called during shutdown.
static void UnregisterChromeEventTarget(EventTarget* aTarget);
already_AddRefed<JSWindowActorProtocol> GetProtocol(const nsACString& aName);
private:
JSWindowActorService();
~JSWindowActorService();
nsTArray<EventTarget*> mChromeEventTargets;
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorProtocol> mDescriptors;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_JSWindowActorProtocol_h
#endif // mozilla_dom_JSWindowActorService_h

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

@ -127,8 +127,6 @@ using refcounted class mozilla::dom::CrossProcessSHEntry from "mozilla/dom/Maybe
using mozilla::ContentBlockingNotifier::StorageAccessGrantedReason from "mozilla/ContentBlockingNotifier.h";
using mozilla::ContentBlockingNotifier::BlockingDecision from "mozilla/ContentBlockingNotifier.h";
using mozilla::ContentBlocking::StorageAccessPromptChoices from "mozilla/ContentBlocking.h";
using JSActorMessageKind from "mozilla/dom/JSActor.h";
using JSActorMessageMeta from "mozilla/dom/PWindowGlobal.h";
union ChromeRegistryItem
{
@ -241,31 +239,15 @@ struct JSWindowActorInfo
{
nsCString name;
bool allFrames;
// The module of the url.
nsCString? url;
JSWindowActorEventDecl[] events;
// Observer notifications this actor listens to.
nsCString[] observers;
nsString[] matches;
nsString[] remoteTypes;
nsString[] messageManagerGroups;
};
struct JSProcessActorInfo
{
// The name of the actor.
nsCString name;
// The module of the url.
nsCString? url;
// Observer notifications this actor listens to.
nsCString[] observers;
nsString[] remoteTypes;
};
struct GMPAPITags
{
nsCString api;
@ -461,9 +443,6 @@ both:
async PWebBrowserPersistDocument(nullable PBrowser aBrowser,
MaybeDiscardedBrowsingContext aContext);
async RawMessage(JSActorMessageMeta aMetadata, ClonedMessageData aData,
ClonedMessageData aStack);
child:
async InitGMPService(Endpoint<PGMPServiceChild> service);
async InitProcessHangMonitor(Endpoint<PProcessHangMonitorChild> hangMonitor);
@ -631,20 +610,15 @@ child:
async InitBlobURLs(BlobURLRegistrationData[] registrations);
/**
* Send JS{Content, Window}ActorInfos to child process.
* Send JSWindowActorInfos to child process.
*/
async InitJSActorInfos(JSProcessActorInfo[] aContentInfos, JSWindowActorInfo[] aWindowInfos);
async InitJSWindowActorInfos(JSWindowActorInfo[] aInfos);
/**
* Unregister a previously registered JSWindowActor in the child process.
*/
async UnregisterJSWindowActor(nsCString name);
/**
* Unregister a previously registered JSProcessActor in the child process.
*/
async UnregisterJSProcessActor(nsCString name);
async SetXPCOMProcessAttributes(XPCOMInitData xpcomInit,
StructuredCloneData initialData,
LookAndFeelInt[] lookAndFeelIntCache,

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

@ -14,7 +14,7 @@ include DOMTypes;
include ClientIPCTypes;
include NeckoChannelParams;
using JSActorMessageKind from "mozilla/dom/JSActor.h";
using JSWindowActorMessageKind from "mozilla/dom/JSWindowActor.h";
using mozilla::gfx::IntRect from "mozilla/gfx/Rect.h";
using moveonly mozilla::gfx::PaintFragment from "mozilla/gfx/CrossProcessPaint.h";
using nscolor from "nsColor.h";
@ -24,11 +24,11 @@ using mozilla::dom::TabId from "mozilla/dom/ipc/IdType.h";
namespace mozilla {
namespace dom {
struct JSActorMessageMeta {
struct JSWindowActorMessageMeta {
nsCString actorName;
nsString messageName;
uint64_t queryId;
JSActorMessageKind kind;
JSWindowActorMessageKind kind;
};
struct IPCWebShareData
@ -70,7 +70,7 @@ child:
async SaveStorageAccessGranted(nsCString aPermissionKey);
both:
async RawMessage(JSActorMessageMeta aMetadata, ClonedMessageData aData,
async RawMessage(JSWindowActorMessageMeta aMetadata, ClonedMessageData aData,
ClonedMessageData aStack);
parent:

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

@ -1,124 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/ProcessActor.h"
#include "nsContentUtils.h"
#include "mozJSComponentLoader.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/Logging.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSProcessActorParent.h"
#include "mozilla/dom/JSProcessActorChild.h"
namespace mozilla {
namespace dom {
void ProcessActor::ConstructActor(const nsACString& aName,
JS::MutableHandleObject aActor,
ErrorResult& aRv) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
JSActor::Type actorType = GetSide();
MOZ_ASSERT_IF(actorType == JSActor::Type::Parent, XRE_IsParentProcess());
// Constructing an actor requires a running script, so push an AutoEntryScript
// onto the stack.
AutoEntryScript aes(xpc::PrivilegedJunkScope(), "ProcessActor construction");
JSContext* cx = aes.cx();
RefPtr<JSActorService> actorSvc = JSActorService::GetSingleton();
if (!actorSvc) {
aRv.ThrowInvalidStateError(
"While constructing JSProcessActor, could not acquire JSActorService.");
return;
}
RefPtr<JSProcessActorProtocol> proto =
actorSvc->GetJSProcessActorProtocol(aName);
if (!proto) {
aRv.ThrowNotFoundError(nsPrintfCString("No such JSProcessActor '%s'",
PromiseFlatCString(aName).get()));
return;
}
if (!proto->Matches(GetRemoteType())) {
aRv.ThrowTypeMismatchError(
nsPrintfCString("JSProcessActor '%s' does not match this process",
PromiseFlatCString(aName).get()));
return;
}
// Load the module using mozJSComponentLoader.
RefPtr<mozJSComponentLoader> loader = mozJSComponentLoader::Get();
MOZ_ASSERT(loader);
JS::RootedObject global(cx);
JS::RootedObject exports(cx);
const JSProcessActorProtocol::Sided* side;
if (actorType == JSActor::Type::Parent) {
side = &proto->Parent();
} else {
side = &proto->Child();
}
// Support basic functionally such as SendAsyncMessage and SendQuery for
// unspecified moduleURI.
if (!side->mModuleURI) {
RefPtr<JSActor> actor;
if (actorType == JSActor::Type::Parent) {
actor = new JSProcessActorParent();
} else {
actor = new JSProcessActorChild();
}
JS::Rooted<JS::Value> wrapper(cx);
if (!ToJSValue(cx, actor, &wrapper)) {
aRv.NoteJSContextException(cx);
return;
}
MOZ_ASSERT(wrapper.isObject());
aActor.set(&wrapper.toObject());
return;
}
aRv = loader->Import(cx, side->mModuleURI.ref(), &global, &exports);
if (aRv.Failed()) {
return;
}
MOZ_ASSERT(exports, "null exports!");
// Load the specific property from our module.
JS::RootedValue ctor(cx);
nsAutoCString ctorName(aName);
ctorName.Append(actorType == JSActor::Type::Parent
? NS_LITERAL_CSTRING("Parent")
: NS_LITERAL_CSTRING("Child"));
if (!JS_GetProperty(cx, exports, ctorName.get(),
&ctor)) {
aRv.NoteJSContextException(cx);
return;
}
if (NS_WARN_IF(!ctor.isObject())) {
nsPrintfCString message("Could not find actor constructor '%s'",
PromiseFlatCString(ctorName).get());
aRv.ThrowNotFoundError(message);
return;
}
// Invoke the constructor loaded from the module.
if (!JS::Construct(cx, ctor, JS::HandleValueArray::empty(), aActor)) {
aRv.NoteJSContextException(cx);
return;
}
}
} // namespace dom
} // namespace mozilla

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

@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_ProcessActor_h
#define mozilla_dom_ProcessActor_h
#include "nsWrapperCache.h"
#include "nsISupports.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/ErrorResult.h"
#include "nsIURI.h"
#include "nsString.h"
#include "mozilla/dom/JSActor.h"
namespace mozilla {
namespace dom {
// Common base class for Content{Parent, Child}.
class ProcessActor : public nsISupports {
protected:
virtual ~ProcessActor() = default;
// Load the module for the named Content Actor and contruct it.
// This method will not initialize the actor or set its manager,
// which is handled by callers.
void ConstructActor(const nsACString& aName, JS::MutableHandleObject aActor,
ErrorResult& aRv);
virtual const nsAString& GetRemoteType() const = 0;
virtual JSActor::Type GetSide() = 0;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_ProcessActor_h

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

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "RefMessageBodyService.h"
#include "nsContentUtils.h"
namespace mozilla {
namespace dom {

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

@ -8,7 +8,6 @@
#include "nsFrameLoader.h"
#include "nsFrameLoaderOwner.h"
#include "nsQueryObject.h"
namespace mozilla {
namespace dom {

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

@ -6,8 +6,6 @@
#define mozilla_dom_RemoteWebProgress_h
#include "nsIRemoteWebProgress.h"
#include "nsCycleCollectionParticipant.h"
#include "nsCOMPtr.h"
namespace mozilla {
namespace dom {

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

@ -4,8 +4,6 @@
#include "RemoteWebProgressRequest.h"
#include "nsIURI.h"
namespace mozilla {
namespace dom {

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

@ -10,7 +10,7 @@
#include "mozJSComponentLoader.h"
#include "mozilla/ContentBlockingAllowList.h"
#include "mozilla/Logging.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "mozilla/dom/JSWindowActorParent.h"
#include "mozilla/dom/JSWindowActorChild.h"
@ -42,8 +42,9 @@ void WindowGlobalActor::ConstructActor(const nsACString& aName,
ErrorResult& aRv) {
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
JSActor::Type actorType = GetSide();
MOZ_ASSERT_IF(actorType == JSActor::Type::Parent, XRE_IsParentProcess());
JSWindowActor::Type actorType = GetSide();
MOZ_ASSERT_IF(actorType == JSWindowActor::Type::Parent,
XRE_IsParentProcess());
// Constructing an actor requires a running script, so push an AutoEntryScript
// onto the stack.
@ -51,18 +52,15 @@ void WindowGlobalActor::ConstructActor(const nsACString& aName,
"WindowGlobalActor construction");
JSContext* cx = aes.cx();
RefPtr<JSActorService> actorSvc = JSActorService::GetSingleton();
RefPtr<JSWindowActorService> actorSvc = JSWindowActorService::GetSingleton();
if (!actorSvc) {
aRv.ThrowNotSupportedError("Could not acquire actor service");
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
RefPtr<JSWindowActorProtocol> proto =
actorSvc->GetJSWindowActorProtocol(aName);
RefPtr<JSWindowActorProtocol> proto = actorSvc->GetProtocol(aName);
if (!proto) {
aRv.ThrowNotSupportedError(nsPrintfCString(
"Could not get JSWindowActorProtocol: %s is not registered",
PromiseFlatCString(aName).get()));
aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
return;
}
@ -79,7 +77,7 @@ void WindowGlobalActor::ConstructActor(const nsACString& aName,
JS::RootedObject exports(cx);
const JSWindowActorProtocol::Sided* side;
if (actorType == JSActor::Type::Parent) {
if (actorType == JSWindowActor::Type::Parent) {
side = &proto->Parent();
} else {
side = &proto->Child();
@ -88,8 +86,8 @@ void WindowGlobalActor::ConstructActor(const nsACString& aName,
// Support basic functionally such as SendAsyncMessage and SendQuery for
// unspecified moduleURI.
if (!side->mModuleURI) {
RefPtr<JSActor> actor;
if (actorType == JSActor::Type::Parent) {
RefPtr<JSWindowActor> actor;
if (actorType == JSWindowActor::Type::Parent) {
actor = new JSWindowActorParent();
} else {
actor = new JSWindowActorChild();
@ -116,9 +114,8 @@ void WindowGlobalActor::ConstructActor(const nsACString& aName,
// Load the specific property from our module.
JS::RootedValue ctor(cx);
nsAutoCString ctorName(aName);
ctorName.Append(actorType == JSActor::Type::Parent
? NS_LITERAL_CSTRING("Parent")
: NS_LITERAL_CSTRING("Child"));
ctorName.AppendASCII(actorType == JSWindowActor::Type::Parent ? "Parent"
: "Child");
if (!JS_GetProperty(cx, exports, ctorName.get(), &ctor)) {
aRv.NoteJSContextException(cx);
return;

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

@ -13,7 +13,7 @@
#include "mozilla/ErrorResult.h"
#include "nsIURI.h"
#include "nsString.h"
#include "mozilla/dom/JSActor.h"
#include "mozilla/dom/JSWindowActor.h"
namespace mozilla {
namespace dom {
@ -34,7 +34,7 @@ class WindowGlobalActor : public nsISupports {
ErrorResult& aRv);
virtual nsIURI* GetDocumentURI() = 0;
virtual const nsAString& GetRemoteType() = 0;
virtual JSActor::Type GetSide() = 0;
virtual JSWindowActor::Type GetSide() = 0;
virtual dom::BrowsingContext* BrowsingContext() = 0;
};

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

@ -34,7 +34,7 @@
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorService.h"
#include "nsIHttpChannelInternal.h"
#include "nsIURIMutator.h"
@ -440,7 +440,7 @@ mozilla::ipc::IPCResult WindowGlobalChild::RecvDispatchSecurityPolicyViolation(
}
IPCResult WindowGlobalChild::RecvRawMessage(
const JSActorMessageMeta& aMeta, const ClonedMessageData& aData,
const JSWindowActorMessageMeta& aMeta, const ClonedMessageData& aData,
const ClonedMessageData& aStack) {
StructuredCloneData data;
data.BorrowFromClonedMessageDataForChild(aData);
@ -450,7 +450,7 @@ IPCResult WindowGlobalChild::RecvRawMessage(
return IPC_OK();
}
void WindowGlobalChild::ReceiveRawMessage(const JSActorMessageMeta& aMeta,
void WindowGlobalChild::ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
StructuredCloneData&& aData,
StructuredCloneData&& aStack) {
RefPtr<JSWindowActorChild> actor =
@ -535,7 +535,7 @@ void WindowGlobalChild::ActorDestroy(ActorDestroyReason aWhy) {
profiler_unregister_page(mInnerWindowId);
#endif
// Destroy our JSActors, and reject any pending queries.
// Destroy our JSWindowActors, and reject any pending queries.
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorChild> windowActors;
mWindowActors.SwapElements(windowActors);
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {

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

@ -23,7 +23,7 @@ class BrowsingContext;
class WindowContext;
class WindowGlobalParent;
class JSWindowActorChild;
class JSActorMessageMeta;
class JSWindowActorMessageMeta;
class BrowserChild;
/**
@ -89,7 +89,7 @@ class WindowGlobalChild final : public WindowGlobalActor,
// |nullptr| if the actor has been torn down, or is in-process.
already_AddRefed<BrowserChild> GetBrowserChild();
void ReceiveRawMessage(const JSActorMessageMeta& aMeta,
void ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack);
@ -114,10 +114,10 @@ class WindowGlobalChild final : public WindowGlobalActor,
protected:
const nsAString& GetRemoteType() override;
JSActor::Type GetSide() override { return JSActor::Type::Child; }
JSWindowActor::Type GetSide() override { return JSWindowActor::Type::Child; }
// IPC messages
mozilla::ipc::IPCResult RecvRawMessage(const JSActorMessageMeta& aMeta,
mozilla::ipc::IPCResult RecvRawMessage(const JSWindowActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack);

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

@ -41,9 +41,9 @@
#include "mozilla/dom/DOMException.h"
#include "mozilla/dom/DOMExceptionBinding.h"
#include "mozilla/dom/JSActorService.h"
#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorParent.h"
#include "mozilla/dom/JSWindowActorService.h"
using namespace mozilla::ipc;
using namespace mozilla::dom::ipc;
@ -326,9 +326,9 @@ IPCResult WindowGlobalParent::RecvDestroy() {
return IPC_OK();
}
IPCResult WindowGlobalParent::RecvRawMessage(const JSActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack) {
IPCResult WindowGlobalParent::RecvRawMessage(
const JSWindowActorMessageMeta& aMeta, const ClonedMessageData& aData,
const ClonedMessageData& aStack) {
StructuredCloneData data;
data.BorrowFromClonedMessageDataForParent(aData);
StructuredCloneData stack;
@ -337,9 +337,9 @@ IPCResult WindowGlobalParent::RecvRawMessage(const JSActorMessageMeta& aMeta,
return IPC_OK();
}
void WindowGlobalParent::ReceiveRawMessage(const JSActorMessageMeta& aMeta,
StructuredCloneData&& aData,
StructuredCloneData&& aStack) {
void WindowGlobalParent::ReceiveRawMessage(
const JSWindowActorMessageMeta& aMeta, StructuredCloneData&& aData,
StructuredCloneData&& aStack) {
RefPtr<JSWindowActorParent> actor =
GetActor(aMeta.actorName(), IgnoreErrors());
if (actor) {

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

@ -38,7 +38,7 @@ namespace dom {
class WindowGlobalChild;
class JSWindowActorParent;
class JSActorMessageMeta;
class JSWindowActorMessageMeta;
/**
* A handle in the parent process to a specific nsGlobalWindowInner object.
@ -81,7 +81,7 @@ class WindowGlobalParent final : public WindowContext,
// |nullptr| if the actor has been torn down, or is in-process.
already_AddRefed<BrowserParent> GetBrowserParent();
void ReceiveRawMessage(const JSActorMessageMeta& aMeta,
void ReceiveRawMessage(const JSWindowActorMessageMeta& aMeta,
ipc::StructuredCloneData&& aData,
ipc::StructuredCloneData&& aStack);
@ -177,7 +177,7 @@ class WindowGlobalParent final : public WindowContext,
protected:
const nsAString& GetRemoteType() override;
JSActor::Type GetSide() override { return JSActor::Type::Parent; }
JSWindowActor::Type GetSide() override { return JSWindowActor::Type::Parent; }
// IPC messages
mozilla::ipc::IPCResult RecvLoadURI(
@ -204,7 +204,7 @@ class WindowGlobalParent final : public WindowContext,
mozilla::ipc::IPCResult RecvSetClientInfo(
const IPCClientInfo& aIPCClientInfo);
mozilla::ipc::IPCResult RecvDestroy();
mozilla::ipc::IPCResult RecvRawMessage(const JSActorMessageMeta& aMeta,
mozilla::ipc::IPCResult RecvRawMessage(const JSWindowActorMessageMeta& aMeta,
const ClonedMessageData& aData,
const ClonedMessageData& aStack);

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

@ -55,18 +55,13 @@ EXPORTS.mozilla.dom += [
'DocShellMessageUtils.h',
'EffectsInfo.h',
'FilePickerParent.h',
'JSActor.h',
'JSActorService.h',
'JSProcessActorChild.h',
'JSProcessActorParent.h',
'JSProcessActorProtocol.h',
'JSWindowActor.h',
'JSWindowActorChild.h',
'JSWindowActorParent.h',
'JSWindowActorProtocol.h',
'JSWindowActorService.h',
'MaybeDiscarded.h',
'MemoryReportRequest.h',
'PermissionMessageUtils.h',
'ProcessActor.h',
'PropertyBagUtils.h',
'ReferrerInfoUtils.h',
'RefMessageBodyService.h',
@ -112,20 +107,15 @@ UNIFIED_SOURCES += [
'CSPMessageUtils.cpp',
'DocShellMessageUtils.cpp',
'FilePickerParent.cpp',
'JSActor.cpp',
'JSActorService.cpp',
'JSProcessActorChild.cpp',
'JSProcessActorParent.cpp',
'JSProcessActorProtocol.cpp',
'JSWindowActor.cpp',
'JSWindowActorChild.cpp',
'JSWindowActorParent.cpp',
'JSWindowActorProtocol.cpp',
'JSWindowActorService.cpp',
'MemMapSnapshot.cpp',
'MemoryReportRequest.cpp',
'MMPrinter.cpp',
'PermissionMessageUtils.cpp',
'PreallocatedProcessManager.cpp',
'ProcessActor.cpp',
'ProcessPriorityManager.cpp',
'PropertyBagUtils.cpp',
'ReferrerInfoUtils.cpp',
@ -239,7 +229,6 @@ JAR_MANIFESTS += ['jar.mn']
BROWSER_CHROME_MANIFESTS += [
'tests/browser.ini',
'tests/JSProcessActor/browser.ini',
'tests/JSWindowActor/browser.ini',
]

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

@ -1,11 +1,7 @@
#include "nsISupports.idl"
webidl JSProcessActorChild;
[scriptable, builtinclass, uuid(b0c6e5f3-02f1-4f11-a0af-336fc231f3bf)]
interface nsIContentChild: nsISupports {
// Internal ID of the process.
readonly attribute unsigned long long childID;
JSProcessActorChild getActor(in ACString name);
};

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

@ -1,11 +1,7 @@
#include "nsISupports.idl"
webidl JSProcessActorParent;
[scriptable, builtinclass, uuid(81fc08b9-c901-471f-ab0d-876362eba770)]
interface nsIContentParent: nsISupports {
// Internal ID of the process.
readonly attribute unsigned long long childID;
JSProcessActorParent getActor(in ACString name);
};

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

@ -1,10 +0,0 @@
[DEFAULT]
support-files =
head.js
[browser_getActor.js]
[browser_observer_notification.js]
[browser_registerProcessActor.js]
[browser_sendAsyncMessage.js]
[browser_sendQuery.js]

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

@ -1,37 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
declTest("getActor on both sides", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
ok(parent, "WindowGlobalParent should have value.");
let actorParent = parent.getActor("TestProcessActor");
is(
actorParent.show(),
"TestProcessActorParent",
"actor show should have vaule."
);
is(
actorParent.manager,
parent,
"manager should match WindowGlobalParent.contentParent"
);
await SpecialPowers.spawn(browser, [], async function() {
let child = ChromeUtils.contentChild;
ok(child, "WindowGlobalChild should have value.");
let actorChild = child.getActor("TestProcessActor");
is(
actorChild.show(),
"TestProcessActorChild",
"actor show should have vaule."
);
is(
actorChild.manager,
child,
"manager should match ChromeUtils.contentChild."
);
});
},
});

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

@ -1,41 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
/* eslint-disable no-unused-vars */
declTest("test observer triggering actor creation", {
async test(browser) {
await SpecialPowers.spawn(browser, [], async function() {
const TOPIC = "test-js-content-actor-child-observer";
Services.obs.notifyObservers(content.window, TOPIC, "dataString");
let child = ChromeUtils.contentChild;
let actorChild = child.getActor("TestProcessActor");
ok(actorChild, "JSProcessActorChild should have value.");
ok(
actorChild.lastObserved,
"JSProcessActorChild lastObserved should have value."
);
let { subject, topic, data } = actorChild.lastObserved;
is(topic, TOPIC, "Topic matches");
is(data, "dataString", "Data matches");
});
},
});
declTest("test observers with null data", {
async test(browser) {
await SpecialPowers.spawn(browser, [], async function() {
const TOPIC = "test-js-content-actor-child-observer";
Services.obs.notifyObservers(content.window, TOPIC);
let child = ChromeUtils.contentChild;
let actorChild = child.getActor("TestProcessActor");
ok(actorChild, "JSProcessActorChild should have value.");
let { subject, topic, data } = actorChild.lastObserved;
is(topic, TOPIC, "Topic matches");
is(data, null, "Data matches");
});
},
});

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

@ -1,16 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
declTest("double register", {
async test() {
SimpleTest.doesThrow(
() =>
ChromeUtils.registerContentActor(
"TestProcessActor",
processActorOptions
),
"Should throw if register has duplicate name."
);
},
});

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

@ -1,51 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
declTest("asyncMessage testing", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
let actorParent = parent.getActor("TestProcessActor");
ok(actorParent, "JSProcessActorParent should have value.");
await ContentTask.spawn(browser, {}, async function() {
let child = ChromeUtils.contentChild;
let actorChild = child.getActor("TestProcessActor");
ok(actorChild, "JSProcessActorChild should have value.");
let promise = new Promise(resolve => {
actorChild.sendAsyncMessage("init", {});
actorChild.done = data => resolve(data);
}).then(data => {
ok(data.initial, "Initial should be true.");
ok(data.toParent, "ToParent should be true.");
ok(data.toChild, "ToChild should be true.");
});
await promise;
});
},
});
declTest("asyncMessage without both sides", {
async test(browser) {
// If we don't create a parent actor, make sure the parent actor
// gets created by having sent the message.
await ContentTask.spawn(browser, {}, async function() {
let child = ChromeUtils.contentChild;
let actorChild = child.getActor("TestProcessActor");
ok(actorChild, "JSProcessActorChild should have value.");
let promise = new Promise(resolve => {
actorChild.sendAsyncMessage("init", {});
actorChild.done = data => resolve(data);
}).then(data => {
ok(data.initial, "Initial should be true.");
ok(data.toParent, "ToParent should be true.");
ok(data.toChild, "ToChild should be true.");
});
await promise;
});
},
});

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

@ -1,78 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
function maybeAsyncStack(offset, column) {
if (!Services.prefs.getBoolPref("javascript.options.asyncstack")) {
return "";
}
let stack = Error().stack.replace(/^.*?\n/, "");
return (
"JSActor query*" +
stack.replace(
/^([^\n]+?):(\d+):\d+/,
(m0, m1, m2) => `${m1}:${+m2 + offset}:${column}`
)
);
}
declTest("sendQuery Error", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
let actorParent = parent.getActor("TestProcessActor");
let asyncStack = maybeAsyncStack(2, 8);
let error = await actorParent
.sendQuery("error", { message: "foo" })
.catch(e => e);
is(error.message, "foo", "Error should have the correct message");
is(error.name, "SyntaxError", "Error should have the correct name");
is(
error.stack,
"receiveMessage@resource://testing-common/TestProcessActorChild.jsm:28:31\n" +
asyncStack,
"Error should have the correct stack"
);
},
});
declTest("sendQuery Exception", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
let actorParent = parent.getActor("TestProcessActor");
let asyncStack = maybeAsyncStack(2, 8);
let error = await actorParent
.sendQuery("exception", {
message: "foo",
result: Cr.NS_ERROR_INVALID_ARG,
})
.catch(e => e);
is(error.message, "foo", "Error should have the correct message");
is(
error.result,
Cr.NS_ERROR_INVALID_ARG,
"Error should have the correct result code"
);
is(
error.stack,
"receiveMessage@resource://testing-common/TestProcessActorChild.jsm:31:22\n" +
asyncStack,
"Error should have the correct stack"
);
},
});
declTest("sendQuery testing", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal.contentParent;
let actorParent = parent.getActor("TestProcessActor");
ok(actorParent, "JSWindowActorParent should have value.");
let { result } = await actorParent.sendQuery("asyncAdd", { a: 10, b: 20 });
is(result, 30);
},
});

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

@ -1,59 +0,0 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Provide infrastructure for JSWindowActor tests.
*/
const URL = "about:blank";
const TEST_URL = "http://test2.example.org/";
let processActorOptions = {
parent: {
moduleURI: "resource://testing-common/TestProcessActorParent.jsm",
},
child: {
moduleURI: "resource://testing-common/TestProcessActorChild.jsm",
observers: ["test-js-content-actor-child-observer"],
},
};
function declTest(name, cfg) {
let { url = "about:blank", remoteTypes, fission, test } = cfg;
// Build the actor options object which will be used to register & unregister our window actor.
let actorOptions = {
parent: Object.assign({}, processActorOptions.parent),
child: Object.assign({}, processActorOptions.child),
};
if (remoteTypes !== undefined) {
actorOptions.remoteTypes = remoteTypes;
}
// Add a new task for the actor test declared here.
add_task(async function() {
info("Entering test: " + name);
// Create a fresh window with the correct settings, and register our actor.
let win = await BrowserTestUtils.openNewBrowserWindow({
remote: true,
fission,
});
ChromeUtils.registerProcessActor("TestProcessActor", actorOptions);
// Wait for the provided URL to load in our browser
let browser = win.gBrowser.selectedBrowser;
BrowserTestUtils.loadURI(browser, url);
await BrowserTestUtils.browserLoaded(browser, false, url);
// Run the provided test
info("browser ready");
try {
await Promise.resolve(test(browser, win));
} finally {
// Clean up after we're done.
ChromeUtils.unregisterProcessActor("TestProcessActor");
await BrowserTestUtils.closeWindow(win);
info("Exiting test: " + name);
}
});
}

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

@ -17,7 +17,7 @@ declTest("crash actor", {
let newTabBrowser = newTab.linkedBrowser;
let parent = newTabBrowser.browsingContext.currentWindowGlobal.getActor(
"TestWindow"
"Test"
);
ok(parent, "JSWindowActorParent should have value.");
@ -30,12 +30,8 @@ declTest("crash actor", {
"Actor should be loaded in the content process."
);
// Make sure that the actor is loaded.
let actorChild = child.getActor("TestWindow");
is(
actorChild.show(),
"TestWindowChild",
"actor show should have value."
);
let actorChild = child.getActor("Test");
is(actorChild.show(), "TestChild", "actor show should have value.");
is(
actorChild.manager,
child,
@ -66,7 +62,7 @@ declTest("crash actor", {
let newTabBrowser = newTab.linkedBrowser;
let parent = newTabBrowser.browsingContext.currentWindowGlobal.getActor(
"TestWindow"
"Test"
);
ok(parent, "JSWindowActorParent should have value.");
@ -79,12 +75,8 @@ declTest("crash actor", {
"Actor should be loaded in the content process."
);
// Make sure that the actor is loaded.
let actorChild = child.getActor("TestWindow");
is(
actorChild.show(),
"TestWindowChild",
"actor show should have value."
);
let actorChild = child.getActor("Test");
is(actorChild.show(), "TestChild", "actor show should have value.");
is(
actorChild.manager,
child,

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

@ -14,7 +14,7 @@ declTest("destroy actor by iframe remove", {
await ContentTaskUtils.waitForEvent(frame, "load");
is(content.window.frames.length, 1, "There should be an iframe.");
let child = frame.contentWindow.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let willDestroyPromise = new Promise(resolve => {
@ -44,7 +44,7 @@ declTest("destroy actor by iframe remove", {
await Promise.all([willDestroyPromise, didDestroyPromise]);
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/InvalidStateError/,
"Should throw if frame destroy."
);
@ -68,7 +68,7 @@ declTest("destroy actor by page navigates", {
let frame = content.document.querySelector("iframe");
frame.contentWindow.location = url;
let child = frame.contentWindow.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let willDestroyPromise = new Promise(resolve => {
@ -100,7 +100,7 @@ declTest("destroy actor by page navigates", {
]);
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/InvalidStateError/,
"Should throw if frame destroy."
);
@ -117,7 +117,7 @@ declTest("destroy actor by tab being closed", {
let newTabBrowser = newTab.linkedBrowser;
let parent = newTabBrowser.browsingContext.currentWindowGlobal.getActor(
"TestWindow"
"Test"
);
ok(parent, "JSWindowActorParent should have value.");
@ -153,7 +153,7 @@ declTest("destroy actor by tab being closed", {
info("setting up destroy listeners");
await SpecialPowers.spawn(newTabBrowser, [], () => {
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
Services.obs.addObserver(function obs(subject, topic, data) {

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

@ -32,7 +32,7 @@ declTest("test event triggering actor creation", {
is(data, "mozshowdropdown");
let parent = browser.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
ok(actorParent, "JSWindowActorParent should have value.");
is(
subject.wrappedJSObject,

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

@ -6,8 +6,8 @@ declTest("getActor on both sides", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent, "WindowGlobalParent should have value.");
let actorParent = parent.getActor("TestWindow");
is(actorParent.show(), "TestWindowParent", "actor show should have vaule.");
let actorParent = parent.getActor("Test");
is(actorParent.show(), "TestParent", "actor show should have vaule.");
is(actorParent.manager, parent, "manager should match WindowGlobalParent.");
await SpecialPowers.spawn(browser, [], async function() {
@ -18,8 +18,8 @@ declTest("getActor on both sides", {
false,
"Actor should be loaded in the content process."
);
let actorChild = child.getActor("TestWindow");
is(actorChild.show(), "TestWindowChild", "actor show should have vaule.");
let actorChild = child.getActor("Test");
is(actorChild.show(), "TestChild", "actor show should have vaule.");
is(actorChild.manager, child, "manager should match WindowGlobalChild.");
});
},

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

@ -11,7 +11,7 @@ declTest("getActor with mismatch", {
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent, "WindowGlobalParent should have value.");
Assert.throws(
() => parent.getActor("TestWindow"),
() => parent.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if it doesn't match."
);
@ -21,7 +21,7 @@ declTest("getActor with mismatch", {
ok(child, "WindowGlobalChild should have value.");
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if it doesn't match."
);
@ -35,12 +35,12 @@ declTest("getActor with matches", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent.getActor("TestWindow"), "JSWindowActorParent should have value.");
ok(parent.getActor("Test"), "JSWindowActorParent should have value.");
await SpecialPowers.spawn(browser, [], async function() {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
ok(child.getActor("TestWindow"), "JSWindowActorChild should have value.");
ok(child.getActor("Test"), "JSWindowActorChild should have value.");
});
},
});
@ -61,7 +61,7 @@ declTest("getActor with iframe matches", {
await content.SpecialPowers.spawn(frame, [], () => {
let child = content.windowGlobalChild;
Assert.ok(
child.getActor("TestWindow"),
child.getActor("Test"),
"JSWindowActorChild should have value."
);
});
@ -85,7 +85,7 @@ declTest("getActor with iframe mismatch", {
await content.SpecialPowers.spawn(frame, [], () => {
let child = content.windowGlobalChild;
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if it doesn't match."
);
@ -99,12 +99,12 @@ declTest("getActor with remoteType match", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent.getActor("TestWindow"), "JSWindowActorParent should have value.");
ok(parent.getActor("Test"), "JSWindowActorParent should have value.");
await SpecialPowers.spawn(browser, [], async function() {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
ok(child.getActor("TestWindow"), "JSWindowActorChild should have value.");
ok(child.getActor("Test"), "JSWindowActorChild should have value.");
});
},
});
@ -117,7 +117,7 @@ declTest("getActor with iframe remoteType match", {
await SpecialPowers.spawn(browser, [TEST_URL], async function(url) {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
ok(child.getActor("TestWindow"), "JSWindowActorChild should have value.");
ok(child.getActor("Test"), "JSWindowActorChild should have value.");
// Create and append an iframe into the window's document.
let frame = content.document.createElement("iframe");
@ -129,7 +129,7 @@ declTest("getActor with iframe remoteType match", {
await content.SpecialPowers.spawn(frame, [], () => {
child = content.windowGlobalChild;
Assert.ok(
child.getActor("TestWindow"),
child.getActor("Test"),
"JSWindowActorChild should have value."
);
});
@ -144,7 +144,7 @@ declTest("getActor with remoteType mismatch", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
Assert.throws(
() => parent.getActor("TestWindow"),
() => parent.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if its remoteTypes don't match."
);
@ -153,7 +153,7 @@ declTest("getActor with remoteType mismatch", {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if its remoteTypes don't match."
);
@ -167,12 +167,12 @@ declTest("getActor with iframe messageManagerGroups match", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
ok(parent.getActor("TestWindow"), "JSWindowActorParent should have value.");
ok(parent.getActor("Test"), "JSWindowActorParent should have value.");
await SpecialPowers.spawn(browser, [TEST_URL], async function(url) {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
ok(child.getActor("TestWindow"), "JSWindowActorChild should have value.");
ok(child.getActor("Test"), "JSWindowActorChild should have value.");
});
},
});
@ -184,7 +184,7 @@ declTest("getActor with iframe messageManagerGroups mismatch", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
Assert.throws(
() => parent.getActor("TestWindow"),
() => parent.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if its messageManagerGroups doesn't match."
);
@ -193,7 +193,7 @@ declTest("getActor with iframe messageManagerGroups mismatch", {
let child = content.windowGlobalChild;
ok(child, "WindowGlobalChild should have value.");
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if its messageManagerGroups doesn't match."
);
@ -212,7 +212,7 @@ declTest("getActor without allFrames", {
is(content.frames.length, 1, "There should be an iframe.");
let child = frame.contentWindow.windowGlobalChild;
Assert.throws(
() => child.getActor("TestWindow"),
() => child.getActor("Test"),
/NS_ERROR_NOT_AVAILABLE/,
"Should throw if allFrames is false."
);
@ -230,7 +230,7 @@ declTest("getActor with allFrames", {
content.document.body.appendChild(frame);
is(content.frames.length, 1, "There should be an iframe.");
let child = frame.contentWindow.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
});
},
@ -242,7 +242,7 @@ declTest("getActor without includeChrome", {
async test(_browser, win) {
let parent = win.docShell.browsingContext.currentWindowGlobal;
SimpleTest.doesThrow(
() => parent.getActor("TestWindow"),
() => parent.getActor("Test"),
"Should throw if includeChrome is false."
);
},
@ -253,7 +253,7 @@ declTest("getActor with includeChrome", {
async test(_browser, win) {
let parent = win.docShell.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
ok(actorParent, "JSWindowActorParent should have value.");
},
});

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

@ -10,12 +10,12 @@ declTest("test observer triggering actor creation", {
Services.obs.notifyObservers(content.window, TOPIC, "dataString");
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let { subject, topic, data } = actorChild.lastObserved;
is(
subject.windowGlobalChild.getActor("TestWindow"),
subject.windowGlobalChild.getActor("Test"),
actorChild,
"Should have been recieved on the right actor"
);
@ -32,12 +32,12 @@ declTest("test observers with null data", {
Services.obs.notifyObservers(content.window, TOPIC);
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let { subject, topic, data } = actorChild.lastObserved;
is(
subject.windowGlobalChild.getActor("TestWindow"),
subject.windowGlobalChild.getActor("Test"),
actorChild,
"Should have been recieved on the right actor"
);
@ -53,7 +53,7 @@ declTest("observers don't notify with wrong window", {
const TOPIC = "test-js-window-actor-child-observer";
Services.obs.notifyObservers(null, TOPIC);
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
is(
actorChild.lastObserved,
@ -74,7 +74,7 @@ declTest("observers notify with audio-playback", {
audio.play();
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let observePromise = new Promise(resolve => {

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

@ -5,7 +5,7 @@
declTest("double register", {
async test() {
SimpleTest.doesThrow(
() => ChromeUtils.registerWindowActor("TestWindow", windowActorOptions),
() => ChromeUtils.registerWindowActor("Test", windowActorOptions),
"Should throw if register has duplicate name."
);
},

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

@ -5,12 +5,12 @@
declTest("asyncMessage testing", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
ok(actorParent, "JSWindowActorParent should have value.");
await ContentTask.spawn(browser, {}, async function() {
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let promise = new Promise(resolve => {
@ -33,7 +33,7 @@ declTest("asyncMessage without both sides", {
// gets created by having sent the message.
await ContentTask.spawn(browser, {}, async function() {
let child = content.windowGlobalChild;
let actorChild = child.getActor("TestWindow");
let actorChild = child.getActor("Test");
ok(actorChild, "JSWindowActorChild should have value.");
let promise = new Promise(resolve => {

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

@ -9,7 +9,7 @@ function maybeAsyncStack(offset, column) {
let stack = Error().stack.replace(/^.*?\n/, "");
return (
"JSActor query*" +
"JSWindowActor query*" +
stack.replace(
/^([^\n]+?):(\d+):\d+/,
(m0, m1, m2) => `${m1}:${+m2 + offset}:${column}`
@ -20,7 +20,7 @@ function maybeAsyncStack(offset, column) {
declTest("sendQuery Error", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
let asyncStack = maybeAsyncStack(2, 8);
let error = await actorParent
@ -31,7 +31,7 @@ declTest("sendQuery Error", {
is(error.name, "SyntaxError", "Error should have the correct name");
is(
error.stack,
"receiveMessage@resource://testing-common/TestWindowChild.jsm:28:31\n" +
"receiveMessage@resource://testing-common/TestChild.jsm:28:31\n" +
asyncStack,
"Error should have the correct stack"
);
@ -41,7 +41,7 @@ declTest("sendQuery Error", {
declTest("sendQuery Exception", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
let asyncStack = maybeAsyncStack(2, 8);
let error = await actorParent
@ -59,7 +59,7 @@ declTest("sendQuery Exception", {
);
is(
error.stack,
"receiveMessage@resource://testing-common/TestWindowChild.jsm:31:22\n" +
"receiveMessage@resource://testing-common/TestChild.jsm:31:22\n" +
asyncStack,
"Error should have the correct stack"
);
@ -69,7 +69,7 @@ declTest("sendQuery Exception", {
declTest("sendQuery testing", {
async test(browser) {
let parent = browser.browsingContext.currentWindowGlobal;
let actorParent = parent.getActor("TestWindow");
let actorParent = parent.getActor("Test");
ok(actorParent, "JSWindowActorParent should have value.");
let { result } = await actorParent.sendQuery("asyncAdd", { a: 10, b: 20 });
@ -85,7 +85,7 @@ declTest("sendQuery in-process early lifetime", {
let iframe = browser.contentDocument.createElement("iframe");
browser.contentDocument.body.appendChild(iframe);
let wgc = iframe.contentWindow.windowGlobalChild;
let actorChild = wgc.getActor("TestWindow");
let actorChild = wgc.getActor("Test");
let { result } = await actorChild.sendQuery("asyncMul", { a: 10, b: 20 });
is(result, 200);
},

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

@ -9,10 +9,10 @@ const URL = "about:blank";
const TEST_URL = "http://test2.example.org/";
let windowActorOptions = {
parent: {
moduleURI: "resource://testing-common/TestWindowParent.jsm",
moduleURI: "resource://testing-common/TestParent.jsm",
},
child: {
moduleURI: "resource://testing-common/TestWindowChild.jsm",
moduleURI: "resource://testing-common/TestChild.jsm",
events: {
mozshowdropdown: {},
@ -60,7 +60,7 @@ function declTest(name, cfg) {
remote: true,
fission,
});
ChromeUtils.registerWindowActor("TestWindow", actorOptions);
ChromeUtils.registerWindowActor("Test", actorOptions);
// Wait for the provided URL to load in our browser
let browser = win.gBrowser.selectedBrowser;
@ -73,7 +73,7 @@ function declTest(name, cfg) {
await Promise.resolve(test(browser, win));
} finally {
// Clean up after we're done.
ChromeUtils.unregisterWindowActor("TestWindow");
ChromeUtils.unregisterWindowActor("Test");
await BrowserTestUtils.closeWindow(win);
info("Exiting test: " + name);
}

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

@ -6,9 +6,9 @@
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["TestWindowChild"];
var EXPORTED_SYMBOLS = ["TestChild"];
class TestWindowChild extends JSWindowActorChild {
class TestChild extends JSWindowActorChild {
constructor() {
super();
}
@ -54,7 +54,7 @@ class TestWindowChild extends JSWindowActorChild {
}
show() {
return "TestWindowChild";
return "TestChild";
}
willDestroy() {

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

@ -6,9 +6,9 @@
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["TestWindowParent"];
var EXPORTED_SYMBOLS = ["TestParent"];
class TestWindowParent extends JSWindowActorParent {
class TestParent extends JSWindowActorParent {
constructor() {
super();
this.wrappedJSObject = this;
@ -41,6 +41,6 @@ class TestWindowParent extends JSWindowActorParent {
}
show() {
return "TestWindowParent";
return "TestParent";
}
}

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

@ -1,64 +0,0 @@
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
var EXPORTED_SYMBOLS = ["TestProcessActorChild"];
class TestProcessActorChild extends JSProcessActorChild {
constructor() {
super();
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "toChild":
aMessage.data.toChild = true;
this.sendAsyncMessage("toParent", aMessage.data);
break;
case "asyncAdd":
let { a, b } = aMessage.data;
return new Promise(resolve => {
resolve({ result: a + b });
});
case "error":
return Promise.reject(new SyntaxError(aMessage.data.message));
case "exception":
return Promise.reject(
Components.Exception(aMessage.data.message, aMessage.data.result)
);
case "done":
this.done(aMessage.data);
break;
}
return undefined;
}
observe(subject, topic, data) {
this.lastObserved = { subject, topic, data };
}
show() {
return "TestProcessActorChild";
}
willDestroy() {
Services.obs.notifyObservers(
this,
"test-js-content-actor-willdestroy",
true
);
}
didDestroy() {
Services.obs.notifyObservers(
this,
"test-js-content-actor-diddestroy",
true
);
}
}

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

@ -1,36 +0,0 @@
/* vim: set ts=2 sw=2 sts=2 et tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
var EXPORTED_SYMBOLS = ["TestProcessActorParent"];
class TestProcessActorParent extends JSProcessActorParent {
constructor() {
super();
this.wrappedJSObject = this;
}
receiveMessage(aMessage) {
switch (aMessage.name) {
case "init":
aMessage.data.initial = true;
this.sendAsyncMessage("toChild", aMessage.data);
break;
case "toParent":
aMessage.data.toParent = true;
this.sendAsyncMessage("done", aMessage.data);
break;
case "asyncMul":
let { a, b } = aMessage.data;
return { result: a * b };
}
return undefined;
}
show() {
return "TestProcessActorParent";
}
}

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

@ -17,10 +17,8 @@ with Files('KeyPressEventModelCheckerChild.jsm'):
BUG_COMPONENT = ('Core', 'DOM: Events')
TESTING_JS_MODULES += [
'TestProcessActorChild.jsm',
'TestProcessActorParent.jsm',
'TestWindowChild.jsm',
'TestWindowParent.jsm',
'TestChild.jsm',
'TestParent.jsm',
]
FINAL_TARGET_FILES.actors += [

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

@ -311,8 +311,6 @@ module.exports = {
InstallTriggerImpl: false,
IntersectionObserver: false,
IntersectionObserverEntry: false,
JSProcessActorChild: false,
JSProcessActorParent: false,
JSWindowActorChild: false,
JSWindowActorParent: false,
KeyEvent: false,