mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 14:22:01 +00:00
Bug 1133594 - Add support for message manager process scripts (r=smaug)
This commit is contained in:
parent
e310fd9b2a
commit
989fdd3474
102
dom/base/ProcessGlobal.cpp
Normal file
102
dom/base/ProcessGlobal.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*- */
|
||||
/* vim: set sw=4 ts=8 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/. */
|
||||
|
||||
#include "ProcessGlobal.h"
|
||||
|
||||
#include "nsContentCID.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
ProcessGlobal::ProcessGlobal(nsFrameMessageManager* aMessageManager)
|
||||
: mInitialized(false),
|
||||
mMessageManager(aMessageManager)
|
||||
{
|
||||
SetIsNotDOMBinding();
|
||||
mozilla::HoldJSObjects(this);
|
||||
}
|
||||
|
||||
ProcessGlobal::~ProcessGlobal()
|
||||
{
|
||||
mAnonymousGlobalScopes.Clear();
|
||||
mozilla::DropJSObjects(this);
|
||||
}
|
||||
|
||||
ProcessGlobal*
|
||||
ProcessGlobal::Get()
|
||||
{
|
||||
nsCOMPtr<nsISyncMessageSender> service = do_GetService(NS_CHILDPROCESSMESSAGEMANAGER_CONTRACTID);
|
||||
if (!service) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<ProcessGlobal*>(service.get());
|
||||
}
|
||||
|
||||
/* [notxpcom] boolean markForCC (); */
|
||||
// This method isn't automatically forwarded safely because it's notxpcom, so
|
||||
// the IDL binding doesn't know what value to return.
|
||||
NS_IMETHODIMP_(bool)
|
||||
ProcessGlobal::MarkForCC()
|
||||
{
|
||||
return mMessageManager ? mMessageManager->MarkForCC() : false;
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(ProcessGlobal)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(ProcessGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(ProcessGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER
|
||||
for (uint32_t i = 0; i < tmp->mAnonymousGlobalScopes.Length(); ++i) {
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mAnonymousGlobalScopes[i])
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ProcessGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnonymousGlobalScopes)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(ProcessGlobal)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentProcessMessageManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMessageListenerManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIMessageSender)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISyncMessageSender)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIContentProcessMessageManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentProcessMessageManager)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(ProcessGlobal)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(ProcessGlobal)
|
||||
|
||||
bool
|
||||
ProcessGlobal::Init()
|
||||
{
|
||||
if (mInitialized) {
|
||||
return true;
|
||||
}
|
||||
mInitialized = true;
|
||||
|
||||
nsISupports* scopeSupports = NS_ISUPPORTS_CAST(nsIContentProcessMessageManager*, this);
|
||||
return InitChildGlobalInternal(scopeSupports, NS_LITERAL_CSTRING("processChildGlobal"));
|
||||
}
|
||||
|
||||
void
|
||||
ProcessGlobal::LoadScript(const nsAString& aURL)
|
||||
{
|
||||
Init();
|
||||
LoadScriptInternal(aURL, false);
|
||||
}
|
77
dom/base/ProcessGlobal.h
Normal file
77
dom/base/ProcessGlobal.h
Normal file
@ -0,0 +1,77 @@
|
||||
/* -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 8; -*- */
|
||||
/* vim: set sw=4 ts=8 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/. */
|
||||
|
||||
#ifndef mozilla_dom_ProcessGlobal_h
|
||||
#define mozilla_dom_ProcessGlobal_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsFrameMessageManager.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIClassInfo.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsIScriptObjectPrincipal.h"
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ProcessGlobal :
|
||||
public nsMessageManagerScriptExecutor,
|
||||
public nsIContentProcessMessageManager,
|
||||
public nsIGlobalObject,
|
||||
public nsIScriptObjectPrincipal,
|
||||
public nsSupportsWeakReference,
|
||||
public mozilla::dom::ipc::MessageManagerCallback,
|
||||
public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
explicit ProcessGlobal(nsFrameMessageManager* aMessageManager);
|
||||
|
||||
bool Init();
|
||||
|
||||
static ProcessGlobal* Get();
|
||||
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ProcessGlobal, nsIContentProcessMessageManager)
|
||||
|
||||
NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager)
|
||||
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
|
||||
NS_FORWARD_SAFE_NSISYNCMESSAGESENDER(mMessageManager)
|
||||
NS_FORWARD_SAFE_NSIMESSAGEMANAGERGLOBAL(mMessageManager)
|
||||
|
||||
virtual void LoadScript(const nsAString& aURL);
|
||||
|
||||
virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE
|
||||
{
|
||||
if (!mGlobal) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mGlobal->GetJSObject();
|
||||
}
|
||||
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; }
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE
|
||||
{
|
||||
MOZ_CRASH("ProcessGlobal doesn't use DOM bindings!");
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~ProcessGlobal();
|
||||
|
||||
private:
|
||||
bool mInitialized;
|
||||
nsRefPtr<nsFrameMessageManager> mMessageManager;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_ProcessGlobal_h
|
@ -183,6 +183,7 @@ EXPORTS.mozilla.dom += [
|
||||
'PerformanceMark.h',
|
||||
'PerformanceMeasure.h',
|
||||
'PerformanceResourceTiming.h',
|
||||
'ProcessGlobal.h',
|
||||
'ResponsiveImageSelector.h',
|
||||
'ScreenOrientation.h',
|
||||
'ScriptSettings.h',
|
||||
@ -318,6 +319,7 @@ UNIFIED_SOURCES += [
|
||||
'PerformanceMark.cpp',
|
||||
'PerformanceMeasure.cpp',
|
||||
'PerformanceResourceTiming.cpp',
|
||||
'ProcessGlobal.cpp',
|
||||
'ResponsiveImageSelector.cpp',
|
||||
'ScriptSettings.cpp',
|
||||
'ShadowRoot.cpp',
|
||||
|
@ -260,6 +260,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentFrameMessageManager, nsEventTargetSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS |
|
||||
nsIXPCScriptable::IS_GLOBAL_OBJECT)
|
||||
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ContentProcessMessageManager, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS |
|
||||
nsIXPCScriptable::IS_GLOBAL_OBJECT)
|
||||
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageBroadcaster, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CHROME_ONLY_CLASSINFO_DATA(ChromeMessageSender, nsDOMGenericSH,
|
||||
@ -674,8 +677,16 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIContentFrameMessageManager)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ContentProcessMessageManager, nsISupports)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsISyncMessageSender)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIContentProcessMessageManager)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageBroadcaster, nsISupports)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageBroadcaster)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
@ -683,6 +694,7 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_BEGIN_NO_CLASS_IF(ChromeMessageSender, nsISupports)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIProcessChecker)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIFrameScriptLoader)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIProcessScriptLoader)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageListenerManager)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIMessageSender)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
@ -40,6 +40,7 @@ DOMCI_CLASS(MozMobileMessageThread)
|
||||
DOMCI_CLASS(CSSFontFaceRule)
|
||||
|
||||
DOMCI_CLASS(ContentFrameMessageManager)
|
||||
DOMCI_CLASS(ContentProcessMessageManager)
|
||||
DOMCI_CLASS(ChromeMessageBroadcaster)
|
||||
DOMCI_CLASS(ChromeMessageSender)
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/nsIContentParent.h"
|
||||
#include "mozilla/dom/PermissionMessageUtils.h"
|
||||
#include "mozilla/dom/ProcessGlobal.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/StructuredCloneUtils.h"
|
||||
#include "mozilla/dom/ipc/BlobChild.h"
|
||||
@ -121,6 +122,10 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFrameMessageManager)
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFrameScriptLoader,
|
||||
mChrome && !mIsProcessManager)
|
||||
|
||||
/* Process message managers (process message managers) support nsIProcessScriptLoader. */
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIProcessScriptLoader,
|
||||
mChrome && mIsProcessManager)
|
||||
|
||||
/* Message senders in the chrome process support nsIProcessChecker. */
|
||||
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIProcessChecker,
|
||||
mChrome && !mIsBroadcaster)
|
||||
@ -432,9 +437,9 @@ nsFrameMessageManager::RemoveWeakMessageListener(const nsAString& aMessage,
|
||||
// nsIFrameScriptLoader
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::LoadFrameScript(const nsAString& aURL,
|
||||
bool aAllowDelayedLoad,
|
||||
bool aRunInGlobalScope)
|
||||
nsFrameMessageManager::LoadScript(const nsAString& aURL,
|
||||
bool aAllowDelayedLoad,
|
||||
bool aRunInGlobalScope)
|
||||
{
|
||||
if (aAllowDelayedLoad) {
|
||||
if (IsGlobal() || IsBroadcaster()) {
|
||||
@ -463,14 +468,14 @@ nsFrameMessageManager::LoadFrameScript(const nsAString& aURL,
|
||||
if (mm) {
|
||||
// Use false here, so that child managers don't cache the script, which
|
||||
// is already cached in the parent.
|
||||
mm->LoadFrameScript(aURL, false, aRunInGlobalScope);
|
||||
mm->LoadScript(aURL, false, aRunInGlobalScope);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::RemoveDelayedFrameScript(const nsAString& aURL)
|
||||
nsFrameMessageManager::RemoveDelayedScript(const nsAString& aURL)
|
||||
{
|
||||
for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
|
||||
if (mPendingScripts[i] == aURL) {
|
||||
@ -483,7 +488,7 @@ nsFrameMessageManager::RemoveDelayedFrameScript(const nsAString& aURL)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::GetDelayedFrameScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList)
|
||||
nsFrameMessageManager::GetDelayedScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList)
|
||||
{
|
||||
// Frame message managers may return an incomplete list because scripts
|
||||
// that were loaded after it was connected are not added to the list.
|
||||
@ -517,6 +522,49 @@ nsFrameMessageManager::GetDelayedFrameScripts(JSContext* aCx, JS::MutableHandle<
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIFrameScriptLoader
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::LoadFrameScript(const nsAString& aURL,
|
||||
bool aAllowDelayedLoad,
|
||||
bool aRunInGlobalScope)
|
||||
{
|
||||
return LoadScript(aURL, aAllowDelayedLoad, aRunInGlobalScope);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::RemoveDelayedFrameScript(const nsAString& aURL)
|
||||
{
|
||||
return RemoveDelayedScript(aURL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::GetDelayedFrameScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList)
|
||||
{
|
||||
return GetDelayedScripts(aCx, aList);
|
||||
}
|
||||
|
||||
// nsIProcessScriptLoader
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::LoadProcessScript(const nsAString& aURL,
|
||||
bool aAllowDelayedLoad)
|
||||
{
|
||||
return LoadScript(aURL, aAllowDelayedLoad, false);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::RemoveDelayedProcessScript(const nsAString& aURL)
|
||||
{
|
||||
return RemoveDelayedScript(aURL);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::GetDelayedProcessScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList)
|
||||
{
|
||||
return GetDelayedScripts(aCx, aList);
|
||||
}
|
||||
|
||||
static bool
|
||||
JSONCreator(const char16_t* aBuf, uint32_t aLen, void* aData)
|
||||
{
|
||||
@ -1678,6 +1726,15 @@ public:
|
||||
MOZ_COUNT_DTOR(SameParentProcessMessageManagerCallback);
|
||||
}
|
||||
|
||||
virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
|
||||
bool aRunInGlobalScope) MOZ_OVERRIDE
|
||||
{
|
||||
ProcessGlobal* global = ProcessGlobal::Get();
|
||||
MOZ_ASSERT(!aRunInGlobalScope);
|
||||
global->LoadScript(aURL);
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
||||
const nsAString& aMessage,
|
||||
const StructuredCloneData& aData,
|
||||
@ -1934,7 +1991,10 @@ NS_NewChildProcessMessageManager(nsISyncMessageSender** aResult)
|
||||
nullptr,
|
||||
MM_PROCESSMANAGER | MM_OWNSCALLBACK);
|
||||
nsFrameMessageManager::SetChildProcessManager(mm);
|
||||
return CallQueryInterface(mm, aResult);
|
||||
ProcessGlobal* global = new ProcessGlobal(mm);
|
||||
NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED);
|
||||
return CallQueryInterface(global, aResult);
|
||||
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
|
@ -154,6 +154,7 @@ private:
|
||||
class nsFrameMessageManager MOZ_FINAL : public nsIContentFrameMessageManager,
|
||||
public nsIMessageBroadcaster,
|
||||
public nsIFrameScriptLoader,
|
||||
public nsIProcessScriptLoader,
|
||||
public nsIProcessChecker
|
||||
{
|
||||
friend class mozilla::dom::MessageManagerReporter;
|
||||
@ -220,6 +221,7 @@ public:
|
||||
NS_DECL_NSIMESSAGEMANAGERGLOBAL
|
||||
NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER
|
||||
NS_DECL_NSIFRAMESCRIPTLOADER
|
||||
NS_DECL_NSIPROCESSSCRIPTLOADER
|
||||
NS_DECL_NSIPROCESSCHECKER
|
||||
|
||||
static nsFrameMessageManager*
|
||||
@ -287,6 +289,13 @@ private:
|
||||
uint8_t aArgc,
|
||||
JS::MutableHandle<JS::Value> aRetval,
|
||||
bool aIsSync);
|
||||
|
||||
NS_IMETHOD LoadScript(const nsAString& aURL,
|
||||
bool aAllowDelayedLoad,
|
||||
bool aRunInGlobalScope);
|
||||
NS_IMETHOD RemoveDelayedScript(const nsAString& aURL);
|
||||
NS_IMETHOD GetDelayedScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList);
|
||||
|
||||
protected:
|
||||
friend class MMListenerRemover;
|
||||
// We keep the message listeners as arrays in a hastable indexed by the
|
||||
|
@ -382,6 +382,11 @@ interface nsIInProcessContentFrameMessageManager : nsIContentFrameMessageManager
|
||||
[notxpcom] nsIContent getOwnerContent();
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(9ca95410-b253-11e4-ab27-0800200c9a66)]
|
||||
interface nsIContentProcessMessageManager : nsIMessageManagerGlobal
|
||||
{
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(6fb78110-45ae-11e3-8f96-0800200c9a66)]
|
||||
interface nsIFrameScriptLoader : nsISupports
|
||||
{
|
||||
@ -409,6 +414,31 @@ interface nsIFrameScriptLoader : nsISupports
|
||||
jsval getDelayedFrameScripts();
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(7e1e1a20-b24f-11e4-ab27-0800200c9a66)]
|
||||
interface nsIProcessScriptLoader : nsISupports
|
||||
{
|
||||
/**
|
||||
* Load a script in the (remote) frame. aURL must be the absolute URL.
|
||||
* data: URLs are also supported. For example data:,dump("foo\n");
|
||||
* If aAllowDelayedLoad is true, script will be loaded when the
|
||||
* remote frame becomes available. Otherwise the script will be loaded
|
||||
* only if the frame is already available.
|
||||
*/
|
||||
void loadProcessScript(in AString aURL, in boolean aAllowDelayedLoad);
|
||||
|
||||
/**
|
||||
* Removes aURL from the list of scripts which support delayed load.
|
||||
*/
|
||||
void removeDelayedProcessScript(in AString aURL);
|
||||
|
||||
/**
|
||||
* Returns all delayed scripts that will be loaded once a (remote)
|
||||
* frame becomes available. The return value is a list of URLs.
|
||||
*/
|
||||
[implicit_jscontext]
|
||||
jsval getDelayedProcessScripts();
|
||||
};
|
||||
|
||||
[scriptable, builtinclass, uuid(637e8538-4f8f-4a3d-8510-e74386233e19)]
|
||||
interface nsIProcessChecker : nsISupports
|
||||
{
|
||||
|
@ -17,6 +17,7 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class TabChildGlobal;
|
||||
class ProcessGlobal;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
class SandboxPrivate;
|
||||
@ -263,6 +264,7 @@ protected:
|
||||
|
||||
private:
|
||||
friend class mozilla::dom::TabChildGlobal;
|
||||
friend class mozilla::dom::ProcessGlobal;
|
||||
friend class SandboxPrivate;
|
||||
friend class nsInProcessTabChildGlobal;
|
||||
friend class nsWindowRoot;
|
||||
|
@ -4,6 +4,7 @@
|
||||
skip-if = e10s # Bug ?????? - test directly touches content (contentWindow.iframe.addEventListener)
|
||||
[browser_bug902350.js]
|
||||
skip-if = e10s # Bug ?????? - test e10s utils don't support load events from iframe etc, which this test relies on.
|
||||
[browser_messagemanager_loadprocessscript.js]
|
||||
[browser_state_notifications.js]
|
||||
# skip-if = e10s # Bug ?????? - content-document-* notifications come while document's URI is still about:blank, but test expects real URL.
|
||||
skip-if = true # Intermittent failures - bug 987493. Restore the skip-if above once fixed
|
||||
|
44
dom/base/test/browser_messagemanager_loadprocessscript.js
Normal file
44
dom/base/test/browser_messagemanager_loadprocessscript.js
Normal file
@ -0,0 +1,44 @@
|
||||
let ppmm = Cc["@mozilla.org/parentprocessmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageBroadcaster);
|
||||
ppmm.QueryInterface(Ci.nsIProcessScriptLoader);
|
||||
|
||||
function processScript() {
|
||||
let cpmm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]
|
||||
.getService(Components.interfaces.nsISyncMessageSender);
|
||||
if (cpmm !== this) {
|
||||
dump("Test failed: wrong global object\n");
|
||||
return;
|
||||
}
|
||||
|
||||
this.cpmm = cpmm;
|
||||
|
||||
addMessageListener("ProcessTest:Reply", function listener(msg) {
|
||||
removeMessageListener("ProcessTest:Reply", listener);
|
||||
sendAsyncMessage("ProcessTest:Finished");
|
||||
});
|
||||
sendSyncMessage("ProcessTest:Loaded");
|
||||
}
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
|
||||
let replyCount = 0;
|
||||
|
||||
function loadListener(msg) {
|
||||
replyCount++;
|
||||
msg.target.sendAsyncMessage("ProcessTest:Reply");
|
||||
}
|
||||
|
||||
ppmm.addMessageListener("ProcessTest:Loaded", loadListener);
|
||||
ppmm.addMessageListener("ProcessTest:Finished", function finishListener(msg) {
|
||||
if (replyCount < ppmm.childCount) {
|
||||
return;
|
||||
}
|
||||
info("Got " + replyCount + " replies");
|
||||
ok(replyCount, "Got message reply");
|
||||
ppmm.removeMessageListener("ProcessTest:Loaded", loadListener);
|
||||
ppmm.removeMessageListener("ProcessTest:Finished", finishListener);
|
||||
finish();
|
||||
});
|
||||
ppmm.loadProcessScript("data:,(" + processScript.toString() + ")()", true);
|
||||
}
|
@ -31,6 +31,7 @@
|
||||
#include "mozilla/dom/DOMStorageIPC.h"
|
||||
#include "mozilla/dom/ExternalHelperAppChild.h"
|
||||
#include "mozilla/dom/PCrashReporterChild.h"
|
||||
#include "mozilla/dom/ProcessGlobal.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/asmjscache/AsmJSCache.h"
|
||||
#include "mozilla/dom/asmjscache/PAsmJSCacheEntryChild.h"
|
||||
@ -1913,6 +1914,14 @@ ContentChild::RecvNotifyVisited(const URIParams& aURI)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvLoadProcessScript(const nsString& aURL)
|
||||
{
|
||||
ProcessGlobal* global = ProcessGlobal::Get();
|
||||
global->LoadScript(aURL);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentChild::RecvAsyncMessage(const nsString& aMsg,
|
||||
const ClonedMessageData& aData,
|
||||
|
@ -304,6 +304,8 @@ public:
|
||||
virtual bool RecvNotifyAlertsObserver(const nsCString& aType,
|
||||
const nsString& aData) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool RecvLoadProcessScript(const nsString& aURL) MOZ_OVERRIDE;
|
||||
|
||||
virtual bool RecvAsyncMessage(const nsString& aMsg,
|
||||
const ClonedMessageData& aData,
|
||||
InfallibleTArray<CpowEntry>&& aCpows,
|
||||
|
@ -4179,6 +4179,14 @@ ContentParent::RecvPrivateDocShellsExist(const bool& aExist)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::DoLoadMessageManagerScript(const nsAString& aURL,
|
||||
bool aRunInGlobalScope)
|
||||
{
|
||||
MOZ_ASSERT(!aRunInGlobalScope);
|
||||
return SendLoadProcessScript(nsString(aURL));
|
||||
}
|
||||
|
||||
bool
|
||||
ContentParent::DoSendAsyncMessage(JSContext* aCx,
|
||||
const nsAString& aMessage,
|
||||
|
@ -169,6 +169,8 @@ public:
|
||||
/**
|
||||
* MessageManagerCallback methods that we override.
|
||||
*/
|
||||
virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
|
||||
bool aRunInGlobalScope) MOZ_OVERRIDE;
|
||||
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
||||
const nsAString& aMessage,
|
||||
const mozilla::dom::StructuredCloneData& aData,
|
||||
|
@ -553,6 +553,8 @@ child:
|
||||
*/
|
||||
async Shutdown();
|
||||
|
||||
async LoadProcessScript(nsString url);
|
||||
|
||||
parent:
|
||||
/**
|
||||
* Tell the parent process a new accessible document has been created.
|
||||
|
Loading…
Reference in New Issue
Block a user