mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-19 00:05:36 +00:00
Bug 1605209 - Turn actor names into nsCString;r=nika
This should save (a little) memory and avoid quite a few conversions. Differential Revision: https://phabricator.services.mozilla.com/D70341
This commit is contained in:
parent
acc935de46
commit
5435691b55
@ -2011,7 +2011,7 @@ nsDocShell::GetLoadURIDelegate(nsILoadURIDelegate** aLoadURIDelegate) {
|
|||||||
|
|
||||||
already_AddRefed<nsILoadURIDelegate> nsDocShell::GetLoadURIDelegate() {
|
already_AddRefed<nsILoadURIDelegate> nsDocShell::GetLoadURIDelegate() {
|
||||||
if (nsCOMPtr<nsILoadURIDelegate> result =
|
if (nsCOMPtr<nsILoadURIDelegate> result =
|
||||||
do_QueryActor(u"LoadURIDelegate", GetWindow())) {
|
do_QueryActor("LoadURIDelegate", GetWindow())) {
|
||||||
return result.forget();
|
return result.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1198,7 +1198,7 @@ void ChromeUtils::ResetLastExternalProtocolIframeAllowed(
|
|||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
void ChromeUtils::RegisterWindowActor(const GlobalObject& aGlobal,
|
void ChromeUtils::RegisterWindowActor(const GlobalObject& aGlobal,
|
||||||
const nsAString& aName,
|
const nsACString& aName,
|
||||||
const WindowActorOptions& aOptions,
|
const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv) {
|
ErrorResult& aRv) {
|
||||||
MOZ_ASSERT(XRE_IsParentProcess());
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
@ -1209,7 +1209,7 @@ void ChromeUtils::RegisterWindowActor(const GlobalObject& aGlobal,
|
|||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
void ChromeUtils::UnregisterWindowActor(const GlobalObject& aGlobal,
|
void ChromeUtils::UnregisterWindowActor(const GlobalObject& aGlobal,
|
||||||
const nsAString& aName) {
|
const nsACString& aName) {
|
||||||
MOZ_ASSERT(XRE_IsParentProcess());
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
|
|
||||||
RefPtr<JSWindowActorService> service = JSWindowActorService::GetSingleton();
|
RefPtr<JSWindowActorService> service = JSWindowActorService::GetSingleton();
|
||||||
|
@ -193,12 +193,12 @@ class ChromeUtils {
|
|||||||
static void ResetLastExternalProtocolIframeAllowed(GlobalObject& aGlobal);
|
static void ResetLastExternalProtocolIframeAllowed(GlobalObject& aGlobal);
|
||||||
|
|
||||||
static void RegisterWindowActor(const GlobalObject& aGlobal,
|
static void RegisterWindowActor(const GlobalObject& aGlobal,
|
||||||
const nsAString& aName,
|
const nsACString& aName,
|
||||||
const WindowActorOptions& aOptions,
|
const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
static void UnregisterWindowActor(const GlobalObject& aGlobal,
|
static void UnregisterWindowActor(const GlobalObject& aGlobal,
|
||||||
const nsAString& aName);
|
const nsACString& aName);
|
||||||
|
|
||||||
static bool IsClassifierBlockingErrorCode(GlobalObject& aGlobal,
|
static bool IsClassifierBlockingErrorCode(GlobalObject& aGlobal,
|
||||||
uint32_t aError);
|
uint32_t aError);
|
||||||
|
@ -205,7 +205,7 @@ nsresult nsWindowRoot::GetControllerForCommand(const char* aCommand,
|
|||||||
// At this point, it is known that a child process is focused, so ask
|
// At this point, it is known that a child process is focused, so ask
|
||||||
// its Controllers actor if the command is supported.
|
// its Controllers actor if the command is supported.
|
||||||
nsCOMPtr<nsIController> controller =
|
nsCOMPtr<nsIController> controller =
|
||||||
do_QueryActor(u"Controllers", canonicalFocusedBC);
|
do_QueryActor("Controllers", canonicalFocusedBC);
|
||||||
if (controller) {
|
if (controller) {
|
||||||
bool supported;
|
bool supported;
|
||||||
controller->SupportsCommand(aCommand, &supported);
|
controller->SupportsCommand(aCommand, &supported);
|
||||||
|
@ -441,10 +441,10 @@ partial namespace ChromeUtils {
|
|||||||
* See JSWindowActor.webidl for WindowActorOptions fields documentation.
|
* See JSWindowActor.webidl for WindowActorOptions fields documentation.
|
||||||
*/
|
*/
|
||||||
[ChromeOnly, Throws]
|
[ChromeOnly, Throws]
|
||||||
void registerWindowActor(DOMString aName, optional WindowActorOptions aOptions = {});
|
void registerWindowActor(UTF8String aName, optional WindowActorOptions aOptions = {});
|
||||||
|
|
||||||
[ChromeOnly]
|
[ChromeOnly]
|
||||||
void unregisterWindowActor(DOMString aName);
|
void unregisterWindowActor(UTF8String aName);
|
||||||
|
|
||||||
[ChromeOnly]
|
[ChromeOnly]
|
||||||
// aError should a nsresult.
|
// aError should a nsresult.
|
||||||
|
@ -68,7 +68,7 @@ interface WindowGlobalParent : WindowContext {
|
|||||||
* customize actor creation.
|
* customize actor creation.
|
||||||
*/
|
*/
|
||||||
[Throws]
|
[Throws]
|
||||||
JSWindowActorParent getActor(DOMString name);
|
JSWindowActorParent getActor(UTF8String name);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders a region of the frame into an image bitmap.
|
* Renders a region of the frame into an image bitmap.
|
||||||
@ -130,5 +130,5 @@ interface WindowGlobalChild {
|
|||||||
* customize actor creation.
|
* customize actor creation.
|
||||||
*/
|
*/
|
||||||
[Throws]
|
[Throws]
|
||||||
JSWindowActorChild getActor(DOMString name);
|
JSWindowActorChild getActor(UTF8String name);
|
||||||
};
|
};
|
||||||
|
@ -2919,7 +2919,7 @@ NS_IMETHODIMP
|
|||||||
BrowserChild::GetWebBrowserChrome(nsIWebBrowserChrome3** aWebBrowserChrome) {
|
BrowserChild::GetWebBrowserChrome(nsIWebBrowserChrome3** aWebBrowserChrome) {
|
||||||
nsCOMPtr<nsPIDOMWindowOuter> outer = do_GetInterface(WebNavigation());
|
nsCOMPtr<nsPIDOMWindowOuter> outer = do_GetInterface(WebNavigation());
|
||||||
if (nsCOMPtr<nsIWebBrowserChrome3> chrome =
|
if (nsCOMPtr<nsIWebBrowserChrome3> chrome =
|
||||||
do_QueryActor(u"WebBrowserChrome", outer)) {
|
do_QueryActor("WebBrowserChrome", outer)) {
|
||||||
chrome.forget(aWebBrowserChrome);
|
chrome.forget(aWebBrowserChrome);
|
||||||
} else {
|
} else {
|
||||||
// TODO: remove fallback
|
// TODO: remove fallback
|
||||||
|
@ -2346,7 +2346,7 @@ mozilla::ipc::IPCResult BrowserParent::RecvEnableDisableCommands(
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIBrowserController> browserController =
|
nsCOMPtr<nsIBrowserController> browserController =
|
||||||
do_QueryActor(u"Controllers", aContext.get_canonical());
|
do_QueryActor("Controllers", aContext.get_canonical());
|
||||||
if (browserController) {
|
if (browserController) {
|
||||||
browserController->EnableDisableCommands(aAction, aEnabledCommands,
|
browserController->EnableDisableCommands(aAction, aEnabledCommands,
|
||||||
aDisabledCommands);
|
aDisabledCommands);
|
||||||
|
@ -2653,7 +2653,7 @@ mozilla::ipc::IPCResult ContentChild::RecvInitJSWindowActorInfos(
|
|||||||
}
|
}
|
||||||
|
|
||||||
mozilla::ipc::IPCResult ContentChild::RecvUnregisterJSWindowActor(
|
mozilla::ipc::IPCResult ContentChild::RecvUnregisterJSWindowActor(
|
||||||
const nsString& aName) {
|
const nsCString& aName) {
|
||||||
RefPtr<JSWindowActorService> actSvc = JSWindowActorService::GetSingleton();
|
RefPtr<JSWindowActorService> actSvc = JSWindowActorService::GetSingleton();
|
||||||
actSvc->UnregisterWindowActor(aName);
|
actSvc->UnregisterWindowActor(aName);
|
||||||
return IPC_OK();
|
return IPC_OK();
|
||||||
|
@ -408,7 +408,7 @@ class ContentChild final
|
|||||||
mozilla::ipc::IPCResult RecvInitJSWindowActorInfos(
|
mozilla::ipc::IPCResult RecvInitJSWindowActorInfos(
|
||||||
nsTArray<JSWindowActorInfo>&& aInfos);
|
nsTArray<JSWindowActorInfo>&& aInfos);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvUnregisterJSWindowActor(const nsString& aName);
|
mozilla::ipc::IPCResult RecvUnregisterJSWindowActor(const nsCString& aName);
|
||||||
|
|
||||||
mozilla::ipc::IPCResult RecvLastPrivateDocShellDestroyed();
|
mozilla::ipc::IPCResult RecvLastPrivateDocShellDestroyed();
|
||||||
|
|
||||||
|
@ -52,14 +52,6 @@ JSWindowActor::JSWindowActor() : mNextQueryId(0) {}
|
|||||||
// RAII class to ensure that, if we crash while handling a message, the
|
// 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.
|
// crash will be annotated with the name of the actor and the message.
|
||||||
struct MOZ_RAII AutoAnnotateMessageInCaseOfCrash {
|
struct MOZ_RAII AutoAnnotateMessageInCaseOfCrash {
|
||||||
AutoAnnotateMessageInCaseOfCrash(const nsCString& aActorName,
|
|
||||||
const nsString& aMessageName) {
|
|
||||||
CrashReporter::AnnotateCrashReport(
|
|
||||||
CrashReporter::Annotation::JSActorName, aActorName);
|
|
||||||
CrashReporter::AnnotateCrashReport(
|
|
||||||
CrashReporter::Annotation::JSActorMessage,
|
|
||||||
NS_LossyConvertUTF16toASCII(aMessageName));
|
|
||||||
}
|
|
||||||
AutoAnnotateMessageInCaseOfCrash(const nsCString& aActorName,
|
AutoAnnotateMessageInCaseOfCrash(const nsCString& aActorName,
|
||||||
const nsCString& aMessageName) {
|
const nsCString& aMessageName) {
|
||||||
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::JSActorName,
|
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::JSActorName,
|
||||||
@ -68,19 +60,21 @@ struct MOZ_RAII AutoAnnotateMessageInCaseOfCrash {
|
|||||||
CrashReporter::Annotation::JSActorMessage, aMessageName);
|
CrashReporter::Annotation::JSActorMessage, aMessageName);
|
||||||
}
|
}
|
||||||
~AutoAnnotateMessageInCaseOfCrash() {
|
~AutoAnnotateMessageInCaseOfCrash() {
|
||||||
CrashReporter::RemoveCrashReportAnnotation(CrashReporter::Annotation::JSActorMessage);
|
CrashReporter::RemoveCrashReportAnnotation(
|
||||||
CrashReporter::RemoveCrashReportAnnotation(CrashReporter::Annotation::JSActorName);
|
CrashReporter::Annotation::JSActorMessage);
|
||||||
|
CrashReporter::RemoveCrashReportAnnotation(
|
||||||
|
CrashReporter::Annotation::JSActorName);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void JSWindowActor::StartDestroy() {
|
void JSWindowActor::StartDestroy() {
|
||||||
AutoAnnotateMessageInCaseOfCrash guard(mCName,
|
AutoAnnotateMessageInCaseOfCrash guard(/* aActorName = */ mName,
|
||||||
NS_LITERAL_CSTRING("<WillDestroy>"));
|
NS_LITERAL_CSTRING("<WillDestroy>"));
|
||||||
InvokeCallback(CallbackFunction::WillDestroy);
|
InvokeCallback(CallbackFunction::WillDestroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSWindowActor::AfterDestroy() {
|
void JSWindowActor::AfterDestroy() {
|
||||||
AutoAnnotateMessageInCaseOfCrash guard(mCName,
|
AutoAnnotateMessageInCaseOfCrash guard(/* aActorName = */ mName,
|
||||||
NS_LITERAL_CSTRING("<DidDestroy>"));
|
NS_LITERAL_CSTRING("<DidDestroy>"));
|
||||||
InvokeCallback(CallbackFunction::DidDestroy);
|
InvokeCallback(CallbackFunction::DidDestroy);
|
||||||
// Clear out & reject mPendingQueries
|
// Clear out & reject mPendingQueries
|
||||||
@ -161,7 +155,7 @@ bool JSWindowActor::AllowMessage(const JSWindowActorMessageMeta& aMetadata,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoString messageName(aMetadata.actorName());
|
nsAutoString messageName(NS_ConvertUTF8toUTF16(aMetadata.actorName()));
|
||||||
messageName.AppendLiteral("::");
|
messageName.AppendLiteral("::");
|
||||||
messageName.Append(aMetadata.messageName());
|
messageName.Append(aMetadata.messageName());
|
||||||
|
|
||||||
@ -176,10 +170,9 @@ bool JSWindowActor::AllowMessage(const JSWindowActorMessageMeta& aMetadata,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSWindowActor::SetName(const nsAString& aName) {
|
void JSWindowActor::SetName(const nsACString& aName) {
|
||||||
MOZ_ASSERT(mName.IsEmpty(), "Cannot set name twice!");
|
MOZ_ASSERT(mName.IsEmpty(), "Cannot set name twice!");
|
||||||
mName = aName;
|
mName = aName;
|
||||||
mCName = NS_LossyConvertUTF16toASCII(aName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ipc::StructuredCloneData CloneJSStack(JSContext* aCx,
|
static ipc::StructuredCloneData CloneJSStack(JSContext* aCx,
|
||||||
@ -275,7 +268,9 @@ void JSWindowActor::ReceiveRawMessage(const JSWindowActorMessageMeta& aMetadata,
|
|||||||
ipc::StructuredCloneData&& aData,
|
ipc::StructuredCloneData&& aData,
|
||||||
ipc::StructuredCloneData&& aStack) {
|
ipc::StructuredCloneData&& aStack) {
|
||||||
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
||||||
AutoAnnotateMessageInCaseOfCrash guard(mCName, aMetadata.messageName());
|
AutoAnnotateMessageInCaseOfCrash guard(
|
||||||
|
/* aActorName = */ mName,
|
||||||
|
NS_LossyConvertUTF16toASCII(aMetadata.messageName()));
|
||||||
|
|
||||||
AutoEntryScript aes(GetParentObject(), "JSWindowActor message handler");
|
AutoEntryScript aes(GetParentObject(), "JSWindowActor message handler");
|
||||||
JSContext* cx = aes.cx();
|
JSContext* cx = aes.cx();
|
||||||
@ -473,17 +468,15 @@ void JSWindowActor::QueryHandler::ResolvedCallback(
|
|||||||
IgnoredErrorResult error;
|
IgnoredErrorResult error;
|
||||||
data.Write(aCx, aValue, error);
|
data.Write(aCx, aValue, error);
|
||||||
if (NS_WARN_IF(error.Failed())) {
|
if (NS_WARN_IF(error.Failed())) {
|
||||||
// We failed to serialize the message over IPC. Report this error to the
|
nsAutoCString msg;
|
||||||
// console, and send a reject reply.
|
|
||||||
nsAutoString msg;
|
|
||||||
msg.Append(mActor->Name());
|
msg.Append(mActor->Name());
|
||||||
msg.Append(':');
|
msg.Append(':');
|
||||||
msg.Append(mMessageName);
|
msg.Append(NS_LossyConvertUTF16toASCII(mMessageName));
|
||||||
msg.AppendLiteral(": message reply cannot be cloned.");
|
msg.AppendLiteral(": message reply cannot be cloned.");
|
||||||
|
|
||||||
auto exc = MakeRefPtr<Exception>(
|
auto exc = MakeRefPtr<Exception>(msg, NS_ERROR_FAILURE,
|
||||||
NS_ConvertUTF16toUTF8(msg), NS_ERROR_FAILURE,
|
NS_LITERAL_CSTRING("DataCloneError"),
|
||||||
NS_LITERAL_CSTRING("DataCloneError"), nullptr, nullptr);
|
nullptr, nullptr);
|
||||||
|
|
||||||
JS::Rooted<JS::Value> val(aCx);
|
JS::Rooted<JS::Value> val(aCx);
|
||||||
if (ToJSValue(aCx, exc, &val)) {
|
if (ToJSValue(aCx, exc, &val)) {
|
||||||
|
@ -45,7 +45,7 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
|
|||||||
enum class Type { Parent, Child };
|
enum class Type { Parent, Child };
|
||||||
enum class CallbackFunction { WillDestroy, DidDestroy, ActorCreated };
|
enum class CallbackFunction { WillDestroy, DidDestroy, ActorCreated };
|
||||||
|
|
||||||
const nsString& Name() const { return mName; }
|
const nsCString& Name() const { return mName; }
|
||||||
|
|
||||||
void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
||||||
JS::Handle<JS::Value> aObj, ErrorResult& aRv);
|
JS::Handle<JS::Value> aObj, ErrorResult& aRv);
|
||||||
@ -79,7 +79,7 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
|
|||||||
|
|
||||||
virtual ~JSWindowActor() = default;
|
virtual ~JSWindowActor() = default;
|
||||||
|
|
||||||
void SetName(const nsAString& aName);
|
void SetName(const nsACString& aName);
|
||||||
|
|
||||||
void StartDestroy();
|
void StartDestroy();
|
||||||
|
|
||||||
@ -130,10 +130,7 @@ class JSWindowActor : public nsISupports, public nsWrapperCache {
|
|||||||
};
|
};
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> mWrappedJS;
|
nsCOMPtr<nsISupports> mWrappedJS;
|
||||||
// A ASCII-encoded version of the name, cached to avoid converting UTF-16 =>
|
nsCString mName;
|
||||||
// UTF-8 at every message.
|
|
||||||
nsCString mCName;
|
|
||||||
nsString mName;
|
|
||||||
nsRefPtrHashtable<nsUint64HashKey, Promise> mPendingQueries;
|
nsRefPtrHashtable<nsUint64HashKey, Promise> mPendingQueries;
|
||||||
uint64_t mNextQueryId;
|
uint64_t mNextQueryId;
|
||||||
};
|
};
|
||||||
|
@ -30,7 +30,7 @@ JSObject* JSWindowActorChild::WrapObject(JSContext* aCx,
|
|||||||
|
|
||||||
WindowGlobalChild* JSWindowActorChild::GetManager() const { return mManager; }
|
WindowGlobalChild* JSWindowActorChild::GetManager() const { return mManager; }
|
||||||
|
|
||||||
void JSWindowActorChild::Init(const nsAString& aName,
|
void JSWindowActorChild::Init(const nsACString& aName,
|
||||||
WindowGlobalChild* aManager) {
|
WindowGlobalChild* aManager) {
|
||||||
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorChild twice!");
|
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorChild twice!");
|
||||||
SetName(aName);
|
SetName(aName);
|
||||||
|
@ -52,7 +52,7 @@ class JSWindowActorChild final : public JSWindowActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
WindowGlobalChild* GetManager() const;
|
WindowGlobalChild* GetManager() const;
|
||||||
void Init(const nsAString& aName, WindowGlobalChild* aManager);
|
void Init(const nsACString& aName, WindowGlobalChild* aManager);
|
||||||
void StartDestroy();
|
void StartDestroy();
|
||||||
void AfterDestroy();
|
void AfterDestroy();
|
||||||
Document* GetDocument(ErrorResult& aRv);
|
Document* GetDocument(ErrorResult& aRv);
|
||||||
|
@ -26,7 +26,7 @@ JSObject* JSWindowActorParent::WrapObject(JSContext* aCx,
|
|||||||
|
|
||||||
WindowGlobalParent* JSWindowActorParent::GetManager() const { return mManager; }
|
WindowGlobalParent* JSWindowActorParent::GetManager() const { return mManager; }
|
||||||
|
|
||||||
void JSWindowActorParent::Init(const nsAString& aName,
|
void JSWindowActorParent::Init(const nsACString& aName,
|
||||||
WindowGlobalParent* aManager) {
|
WindowGlobalParent* aManager) {
|
||||||
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorParent twice!");
|
MOZ_ASSERT(!mManager, "Cannot Init() a JSWindowActorParent twice!");
|
||||||
SetName(aName);
|
SetName(aName);
|
||||||
|
@ -43,7 +43,7 @@ class JSWindowActorParent final : public JSWindowActor {
|
|||||||
nsIGlobalObject* GetParentObject() const override;
|
nsIGlobalObject* GetParentObject() const override;
|
||||||
|
|
||||||
WindowGlobalParent* GetManager() const;
|
WindowGlobalParent* GetManager() const;
|
||||||
void Init(const nsAString& aName, WindowGlobalParent* aManager);
|
void Init(const nsACString& aName, WindowGlobalParent* aManager);
|
||||||
void StartDestroy();
|
void StartDestroy();
|
||||||
void AfterDestroy();
|
void AfterDestroy();
|
||||||
CanonicalBrowsingContext* GetBrowsingContext(ErrorResult& aRv);
|
CanonicalBrowsingContext* GetBrowsingContext(ErrorResult& aRv);
|
||||||
|
@ -94,7 +94,7 @@ JSWindowActorInfo JSWindowActorProtocol::ToIPC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JSWindowActorProtocol>
|
already_AddRefed<JSWindowActorProtocol>
|
||||||
JSWindowActorProtocol::FromWebIDLOptions(const nsAString& aName,
|
JSWindowActorProtocol::FromWebIDLOptions(const nsACString& aName,
|
||||||
const WindowActorOptions& aOptions,
|
const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv) {
|
ErrorResult& aRv) {
|
||||||
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
|
||||||
@ -395,16 +395,15 @@ already_AddRefed<JSWindowActorService> JSWindowActorService::GetSingleton() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JSWindowActorService::RegisterWindowActor(
|
void JSWindowActorService::RegisterWindowActor(
|
||||||
const nsAString& aName, const WindowActorOptions& aOptions,
|
const nsACString& aName, const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv) {
|
ErrorResult& aRv) {
|
||||||
MOZ_ASSERT(NS_IsMainThread());
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
MOZ_ASSERT(XRE_IsParentProcess());
|
MOZ_ASSERT(XRE_IsParentProcess());
|
||||||
|
|
||||||
auto entry = mDescriptors.LookupForAdd(aName);
|
auto entry = mDescriptors.LookupForAdd(aName);
|
||||||
if (entry) {
|
if (entry) {
|
||||||
aRv.ThrowNotSupportedError(
|
aRv.ThrowNotSupportedError(nsPrintfCString(
|
||||||
nsPrintfCString("'%s' actor is already registered.",
|
"'%s' actor is already registered.", PromiseFlatCString(aName).get()));
|
||||||
NS_ConvertUTF16toUTF8(aName).get()));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,8 +433,8 @@ void JSWindowActorService::RegisterWindowActor(
|
|||||||
proto->AddObservers();
|
proto->AddObservers();
|
||||||
}
|
}
|
||||||
|
|
||||||
void JSWindowActorService::UnregisterWindowActor(const nsAString& aName) {
|
void JSWindowActorService::UnregisterWindowActor(const nsACString& aName) {
|
||||||
nsAutoString name(aName);
|
nsAutoCString name(aName);
|
||||||
|
|
||||||
RefPtr<JSWindowActorProtocol> proto;
|
RefPtr<JSWindowActorProtocol> proto;
|
||||||
if (mDescriptors.Remove(aName, getter_AddRefs(proto))) {
|
if (mDescriptors.Remove(aName, getter_AddRefs(proto))) {
|
||||||
@ -507,7 +506,7 @@ void JSWindowActorService::UnregisterChromeEventTarget(EventTarget* aTarget) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JSWindowActorProtocol> JSWindowActorService::GetProtocol(
|
already_AddRefed<JSWindowActorProtocol> JSWindowActorService::GetProtocol(
|
||||||
const nsAString& aName) {
|
const nsACString& aName) {
|
||||||
return mDescriptors.Get(aName);
|
return mDescriptors.Get(aName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class JSWindowActorProtocol final : public nsIObserver,
|
|||||||
JSWindowActorInfo ToIPC();
|
JSWindowActorInfo ToIPC();
|
||||||
|
|
||||||
static already_AddRefed<JSWindowActorProtocol> FromWebIDLOptions(
|
static already_AddRefed<JSWindowActorProtocol> FromWebIDLOptions(
|
||||||
const nsAString& aName, const WindowActorOptions& aOptions,
|
const nsACString& aName, const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
struct Sided {
|
struct Sided {
|
||||||
@ -78,13 +78,13 @@ class JSWindowActorProtocol final : public nsIObserver,
|
|||||||
const nsAString& aRemoteType);
|
const nsAString& aRemoteType);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit JSWindowActorProtocol(const nsAString& aName) : mName(aName) {}
|
explicit JSWindowActorProtocol(const nsACString& aName) : mName(aName) {}
|
||||||
extensions::MatchPatternSet* GetURIMatcher();
|
extensions::MatchPatternSet* GetURIMatcher();
|
||||||
bool RemoteTypePrefixMatches(const nsDependentSubstring& aRemoteType);
|
bool RemoteTypePrefixMatches(const nsDependentSubstring& aRemoteType);
|
||||||
bool MessageManagerGroupMatches(BrowsingContext* aBrowsingContext);
|
bool MessageManagerGroupMatches(BrowsingContext* aBrowsingContext);
|
||||||
~JSWindowActorProtocol() = default;
|
~JSWindowActorProtocol() = default;
|
||||||
|
|
||||||
nsString mName;
|
nsCString mName;
|
||||||
bool mAllFrames = false;
|
bool mAllFrames = false;
|
||||||
bool mIncludeChrome = false;
|
bool mIncludeChrome = false;
|
||||||
nsTArray<nsString> mMatches;
|
nsTArray<nsString> mMatches;
|
||||||
@ -103,11 +103,11 @@ class JSWindowActorService final {
|
|||||||
|
|
||||||
static already_AddRefed<JSWindowActorService> GetSingleton();
|
static already_AddRefed<JSWindowActorService> GetSingleton();
|
||||||
|
|
||||||
void RegisterWindowActor(const nsAString& aName,
|
void RegisterWindowActor(const nsACString& aName,
|
||||||
const WindowActorOptions& aOptions,
|
const WindowActorOptions& aOptions,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
void UnregisterWindowActor(const nsAString& aName);
|
void UnregisterWindowActor(const nsACString& aName);
|
||||||
|
|
||||||
// Register child's Window Actor from JSWindowActorInfos for content process.
|
// Register child's Window Actor from JSWindowActorInfos for content process.
|
||||||
void LoadJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);
|
void LoadJSWindowActorInfos(nsTArray<JSWindowActorInfo>& aInfos);
|
||||||
@ -122,14 +122,14 @@ class JSWindowActorService final {
|
|||||||
// NOTE: This method is static, as it may be called during shutdown.
|
// NOTE: This method is static, as it may be called during shutdown.
|
||||||
static void UnregisterChromeEventTarget(EventTarget* aTarget);
|
static void UnregisterChromeEventTarget(EventTarget* aTarget);
|
||||||
|
|
||||||
already_AddRefed<JSWindowActorProtocol> GetProtocol(const nsAString& aName);
|
already_AddRefed<JSWindowActorProtocol> GetProtocol(const nsACString& aName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
JSWindowActorService();
|
JSWindowActorService();
|
||||||
~JSWindowActorService();
|
~JSWindowActorService();
|
||||||
|
|
||||||
nsTArray<EventTarget*> mChromeEventTargets;
|
nsTArray<EventTarget*> mChromeEventTargets;
|
||||||
nsRefPtrHashtable<nsStringHashKey, JSWindowActorProtocol> mDescriptors;
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorProtocol> mDescriptors;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
|
@ -244,7 +244,7 @@ struct JSWindowActorEventDecl
|
|||||||
|
|
||||||
struct JSWindowActorInfo
|
struct JSWindowActorInfo
|
||||||
{
|
{
|
||||||
nsString name;
|
nsCString name;
|
||||||
bool allFrames;
|
bool allFrames;
|
||||||
nsCString? url;
|
nsCString? url;
|
||||||
|
|
||||||
@ -618,7 +618,7 @@ child:
|
|||||||
/**
|
/**
|
||||||
* Unregister a previously registered JSWindowActor in the child process.
|
* Unregister a previously registered JSWindowActor in the child process.
|
||||||
*/
|
*/
|
||||||
async UnregisterJSWindowActor(nsString name);
|
async UnregisterJSWindowActor(nsCString name);
|
||||||
|
|
||||||
async SetXPCOMProcessAttributes(XPCOMInitData xpcomInit,
|
async SetXPCOMProcessAttributes(XPCOMInitData xpcomInit,
|
||||||
StructuredCloneData initialData,
|
StructuredCloneData initialData,
|
||||||
|
@ -25,7 +25,7 @@ namespace mozilla {
|
|||||||
namespace dom {
|
namespace dom {
|
||||||
|
|
||||||
struct JSWindowActorMessageMeta {
|
struct JSWindowActorMessageMeta {
|
||||||
nsString actorName;
|
nsCString actorName;
|
||||||
nsString messageName;
|
nsString messageName;
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
JSWindowActorMessageKind kind;
|
JSWindowActorMessageKind kind;
|
||||||
|
@ -37,7 +37,7 @@ WindowGlobalInit WindowGlobalActor::AboutBlankInitializer(
|
|||||||
outerWindowId);
|
outerWindowId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowGlobalActor::ConstructActor(const nsAString& aName,
|
void WindowGlobalActor::ConstructActor(const nsACString& aName,
|
||||||
JS::MutableHandleObject aActor,
|
JS::MutableHandleObject aActor,
|
||||||
ErrorResult& aRv) {
|
ErrorResult& aRv) {
|
||||||
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
||||||
@ -113,19 +113,17 @@ void WindowGlobalActor::ConstructActor(const nsAString& aName,
|
|||||||
|
|
||||||
// Load the specific property from our module.
|
// Load the specific property from our module.
|
||||||
JS::RootedValue ctor(cx);
|
JS::RootedValue ctor(cx);
|
||||||
nsAutoString ctorName(aName);
|
nsAutoCString ctorName(aName);
|
||||||
ctorName.Append(actorType == JSWindowActor::Type::Parent
|
ctorName.AppendASCII(actorType == JSWindowActor::Type::Parent ? "Parent"
|
||||||
? NS_LITERAL_STRING("Parent")
|
: "Child");
|
||||||
: NS_LITERAL_STRING("Child"));
|
if (!JS_GetProperty(cx, exports, ctorName.get(), &ctor)) {
|
||||||
if (!JS_GetUCProperty(cx, exports, ctorName.get(), ctorName.Length(),
|
|
||||||
&ctor)) {
|
|
||||||
aRv.NoteJSContextException(cx);
|
aRv.NoteJSContextException(cx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_WARN_IF(!ctor.isObject())) {
|
if (NS_WARN_IF(!ctor.isObject())) {
|
||||||
nsPrintfCString message("Could not find actor constructor '%s'",
|
nsPrintfCString message("Could not find actor constructor '%s'",
|
||||||
NS_ConvertUTF16toUTF8(ctorName).get());
|
ctorName.get());
|
||||||
aRv.ThrowNotFoundError(message);
|
aRv.ThrowNotFoundError(message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class WindowGlobalActor : public nsISupports {
|
|||||||
// Load the module for the named Window Actor and contruct it.
|
// Load the module for the named Window Actor and contruct it.
|
||||||
// This method will not initialize the actor or set its manager,
|
// This method will not initialize the actor or set its manager,
|
||||||
// which is handled by callers.
|
// which is handled by callers.
|
||||||
void ConstructActor(const nsAString& aName, JS::MutableHandleObject aActor,
|
void ConstructActor(const nsACString& aName, JS::MutableHandleObject aActor,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
virtual nsIURI* GetDocumentURI() = 0;
|
virtual nsIURI* GetDocumentURI() = 0;
|
||||||
virtual const nsAString& GetRemoteType() = 0;
|
virtual const nsAString& GetRemoteType() = 0;
|
||||||
|
@ -471,7 +471,7 @@ const nsAString& WindowGlobalChild::GetRemoteType() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JSWindowActorChild> WindowGlobalChild::GetActor(
|
already_AddRefed<JSWindowActorChild> WindowGlobalChild::GetActor(
|
||||||
const nsAString& aName, ErrorResult& aRv) {
|
const nsACString& aName, ErrorResult& aRv) {
|
||||||
if (!CanSend()) {
|
if (!CanSend()) {
|
||||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -513,7 +513,7 @@ void WindowGlobalChild::ActorDestroy(ActorDestroyReason aWhy) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Destroy our JSWindowActors, and reject any pending queries.
|
// Destroy our JSWindowActors, and reject any pending queries.
|
||||||
nsRefPtrHashtable<nsStringHashKey, JSWindowActorChild> windowActors;
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorChild> windowActors;
|
||||||
mWindowActors.SwapElements(windowActors);
|
mWindowActors.SwapElements(windowActors);
|
||||||
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {
|
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {
|
||||||
iter.Data()->RejectPendingQueries();
|
iter.Data()->RejectPendingQueries();
|
||||||
|
@ -94,7 +94,7 @@ class WindowGlobalChild final : public WindowGlobalActor,
|
|||||||
ipc::StructuredCloneData&& aStack);
|
ipc::StructuredCloneData&& aStack);
|
||||||
|
|
||||||
// Get a JS actor object by name.
|
// Get a JS actor object by name.
|
||||||
already_AddRefed<JSWindowActorChild> GetActor(const nsAString& aName,
|
already_AddRefed<JSWindowActorChild> GetActor(const nsACString& aName,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
// Create and initialize the WindowGlobalChild object.
|
// Create and initialize the WindowGlobalChild object.
|
||||||
@ -150,7 +150,7 @@ class WindowGlobalChild final : public WindowGlobalActor,
|
|||||||
RefPtr<nsGlobalWindowInner> mWindowGlobal;
|
RefPtr<nsGlobalWindowInner> mWindowGlobal;
|
||||||
RefPtr<dom::BrowsingContext> mBrowsingContext;
|
RefPtr<dom::BrowsingContext> mBrowsingContext;
|
||||||
RefPtr<dom::WindowContext> mWindowContext;
|
RefPtr<dom::WindowContext> mWindowContext;
|
||||||
nsRefPtrHashtable<nsStringHashKey, JSWindowActorChild> mWindowActors;
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorChild> mWindowActors;
|
||||||
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
|
||||||
nsCOMPtr<nsIURI> mDocumentURI;
|
nsCOMPtr<nsIURI> mDocumentURI;
|
||||||
uint64_t mInnerWindowId;
|
uint64_t mInnerWindowId;
|
||||||
|
@ -414,7 +414,7 @@ void WindowGlobalParent::NotifyContentBlockingEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<JSWindowActorParent> WindowGlobalParent::GetActor(
|
already_AddRefed<JSWindowActorParent> WindowGlobalParent::GetActor(
|
||||||
const nsAString& aName, ErrorResult& aRv) {
|
const nsACString& aName, ErrorResult& aRv) {
|
||||||
if (!CanSend()) {
|
if (!CanSend()) {
|
||||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -671,7 +671,7 @@ void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Destroy our JSWindowActors, and reject any pending queries.
|
// Destroy our JSWindowActors, and reject any pending queries.
|
||||||
nsRefPtrHashtable<nsStringHashKey, JSWindowActorParent> windowActors;
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorParent> windowActors;
|
||||||
mWindowActors.SwapElements(windowActors);
|
mWindowActors.SwapElements(windowActors);
|
||||||
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {
|
for (auto iter = windowActors.Iter(); !iter.Done(); iter.Next()) {
|
||||||
iter.Data()->RejectPendingQueries();
|
iter.Data()->RejectPendingQueries();
|
||||||
|
@ -74,7 +74,7 @@ class WindowGlobalParent final : public WindowContext,
|
|||||||
already_AddRefed<WindowGlobalChild> GetChildActor();
|
already_AddRefed<WindowGlobalChild> GetChildActor();
|
||||||
|
|
||||||
// Get a JS actor object by name.
|
// Get a JS actor object by name.
|
||||||
already_AddRefed<JSWindowActorParent> GetActor(const nsAString& aName,
|
already_AddRefed<JSWindowActorParent> GetActor(const nsACString& aName,
|
||||||
ErrorResult& aRv);
|
ErrorResult& aRv);
|
||||||
|
|
||||||
// Get this actor's manager if it is not an in-process actor. Returns
|
// Get this actor's manager if it is not an in-process actor. Returns
|
||||||
@ -233,7 +233,7 @@ class WindowGlobalParent final : public WindowContext,
|
|||||||
nsCOMPtr<nsIURI> mDocumentURI;
|
nsCOMPtr<nsIURI> mDocumentURI;
|
||||||
nsString mDocumentTitle;
|
nsString mDocumentTitle;
|
||||||
|
|
||||||
nsRefPtrHashtable<nsStringHashKey, JSWindowActorParent> mWindowActors;
|
nsRefPtrHashtable<nsCStringHashKey, JSWindowActorParent> mWindowActors;
|
||||||
bool mInProcess;
|
bool mInProcess;
|
||||||
bool mIsInitialDocument;
|
bool mIsInitialDocument;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
// only has any use within a child process.
|
// only has any use within a child process.
|
||||||
class MOZ_STACK_CLASS nsQueryActorChild final : public nsCOMPtr_helper {
|
class MOZ_STACK_CLASS nsQueryActorChild final : public nsCOMPtr_helper {
|
||||||
public:
|
public:
|
||||||
nsQueryActorChild(const nsLiteralString aActorName,
|
nsQueryActorChild(const nsLiteralCString aActorName,
|
||||||
nsPIDOMWindowOuter* aWindow)
|
nsPIDOMWindowOuter* aWindow)
|
||||||
: mActorName(aActorName), mWindow(aWindow) {}
|
: mActorName(aActorName), mWindow(aWindow) {}
|
||||||
|
|
||||||
@ -43,21 +43,21 @@ class MOZ_STACK_CLASS nsQueryActorChild final : public nsCOMPtr_helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const nsLiteralString mActorName;
|
const nsLiteralCString mActorName;
|
||||||
nsPIDOMWindowOuter* mWindow;
|
nsPIDOMWindowOuter* mWindow;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t length>
|
template <size_t length>
|
||||||
inline nsQueryActorChild do_QueryActor(const char16_t (&aActorName)[length],
|
inline nsQueryActorChild do_QueryActor(const char (&aActorName)[length],
|
||||||
nsPIDOMWindowOuter* aWindow) {
|
nsPIDOMWindowOuter* aWindow) {
|
||||||
return nsQueryActorChild(nsLiteralString(aActorName), aWindow);
|
return nsQueryActorChild(nsLiteralCString(aActorName), aWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This type is used to get an actor given a CanonicalBrowsingContext. It
|
// This type is used to get an actor given a CanonicalBrowsingContext. It
|
||||||
// is only useful in the parent process.
|
// is only useful in the parent process.
|
||||||
class MOZ_STACK_CLASS nsQueryActorParent final : public nsCOMPtr_helper {
|
class MOZ_STACK_CLASS nsQueryActorParent final : public nsCOMPtr_helper {
|
||||||
public:
|
public:
|
||||||
nsQueryActorParent(nsLiteralString aActorName,
|
nsQueryActorParent(nsLiteralCString aActorName,
|
||||||
mozilla::dom::CanonicalBrowsingContext* aBrowsingContext)
|
mozilla::dom::CanonicalBrowsingContext* aBrowsingContext)
|
||||||
: mActorName(aActorName), mBrowsingContext(aBrowsingContext) {}
|
: mActorName(aActorName), mBrowsingContext(aBrowsingContext) {}
|
||||||
|
|
||||||
@ -83,15 +83,15 @@ class MOZ_STACK_CLASS nsQueryActorParent final : public nsCOMPtr_helper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const nsLiteralString mActorName;
|
const nsLiteralCString mActorName;
|
||||||
mozilla::dom::CanonicalBrowsingContext* mBrowsingContext;
|
mozilla::dom::CanonicalBrowsingContext* mBrowsingContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <size_t length>
|
template <size_t length>
|
||||||
inline nsQueryActorParent do_QueryActor(
|
inline nsQueryActorParent do_QueryActor(
|
||||||
const char16_t (&aActorName)[length],
|
const char (&aActorName)[length],
|
||||||
mozilla::dom::CanonicalBrowsingContext* aBrowsingContext) {
|
mozilla::dom::CanonicalBrowsingContext* aBrowsingContext) {
|
||||||
return nsQueryActorParent(nsLiteralString(aActorName), aBrowsingContext);
|
return nsQueryActorParent(nsLiteralCString(aActorName), aBrowsingContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // defined nsQueryActor_h
|
#endif // defined nsQueryActor_h
|
||||||
|
@ -84,7 +84,7 @@ nsContentTreeOwner::GetWebBrowserChrome() {
|
|||||||
|
|
||||||
nsCOMPtr<nsPIDOMWindowOuter> outer(docShell->GetWindow());
|
nsCOMPtr<nsPIDOMWindowOuter> outer(docShell->GetWindow());
|
||||||
if (nsCOMPtr<nsIWebBrowserChrome3> chrome =
|
if (nsCOMPtr<nsIWebBrowserChrome3> chrome =
|
||||||
do_QueryActor(u"WebBrowserChrome", outer)) {
|
do_QueryActor("WebBrowserChrome", outer)) {
|
||||||
return chrome.forget();
|
return chrome.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user