2013-11-11 08:04:41 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2013-11-11 08:04:41 +00:00
|
|
|
|
2010-05-18 12:28:37 +00:00
|
|
|
#ifndef nsFrameMessageManager_h__
|
|
|
|
#define nsFrameMessageManager_h__
|
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
#include "nsIMessageManager.h"
|
2010-08-16 20:40:04 +00:00
|
|
|
#include "nsIObserver.h"
|
2010-05-18 12:28:37 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMArray.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsTArray.h"
|
2010-08-10 17:18:26 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2013-10-25 21:55:16 +00:00
|
|
|
#include "nsClassHashtable.h"
|
2010-08-16 20:40:04 +00:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2011-10-11 10:28:46 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2013-08-08 18:36:56 +00:00
|
|
|
#include "nsWeakPtr.h"
|
2012-06-19 02:30:09 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-17 22:50:18 +00:00
|
|
|
#include "js/RootingAPI.h"
|
2013-11-05 11:52:04 +00:00
|
|
|
#include "nsTObserverArray.h"
|
2015-03-24 20:05:39 +00:00
|
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
2014-03-12 14:22:00 +00:00
|
|
|
#include "mozilla/dom/StructuredCloneUtils.h"
|
2015-01-26 21:32:18 +00:00
|
|
|
#include "mozilla/jsipc/CpowHolder.h"
|
2010-05-18 12:28:37 +00:00
|
|
|
|
2015-04-16 15:17:54 +00:00
|
|
|
class nsIFrameLoader;
|
|
|
|
|
2011-08-02 19:57:48 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2012-09-28 05:43:12 +00:00
|
|
|
|
2014-06-11 05:44:03 +00:00
|
|
|
class nsIContentParent;
|
2014-06-11 05:44:06 +00:00
|
|
|
class nsIContentChild;
|
2013-01-24 02:39:27 +00:00
|
|
|
class ClonedMessageData;
|
2013-10-11 23:07:15 +00:00
|
|
|
class MessageManagerReporter;
|
2012-09-28 05:43:12 +00:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
enum MessageManagerFlags {
|
|
|
|
MM_CHILD = 0,
|
|
|
|
MM_CHROME = 1,
|
|
|
|
MM_GLOBAL = 2,
|
|
|
|
MM_PROCESSMANAGER = 4,
|
|
|
|
MM_BROADCASTER = 8,
|
|
|
|
MM_OWNSCALLBACK = 16
|
|
|
|
};
|
|
|
|
|
|
|
|
class MessageManagerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~MessageManagerCallback() {}
|
|
|
|
|
2015-02-20 01:11:32 +00:00
|
|
|
virtual bool DoLoadMessageManagerScript(const nsAString& aURL, bool aRunInGlobalScope)
|
2012-09-28 05:43:12 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-01 16:15:06 +00:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2013-11-11 08:04:41 +00:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 17:21:15 +00:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 16:15:06 +00:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal,
|
|
|
|
bool aIsSync)
|
2012-09-28 05:43:12 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-10 22:05:39 +00:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2013-11-11 08:04:41 +00:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 17:21:15 +00:00
|
|
|
nsIPrincipal* aPrincipal)
|
2012-09-28 05:43:12 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CheckPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-22 12:00:10 +00:00
|
|
|
|
|
|
|
virtual bool CheckManifestURL(const nsAString& aManifestURL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-14 10:08:55 +00:00
|
|
|
|
|
|
|
virtual bool CheckAppHasPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-24 02:39:27 +00:00
|
|
|
|
2013-06-29 10:52:16 +00:00
|
|
|
virtual bool CheckAppHasStatus(unsigned short aStatus)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-12 12:59:47 +00:00
|
|
|
virtual bool KillChild()
|
|
|
|
{
|
|
|
|
// By default, does nothing.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-24 02:39:27 +00:00
|
|
|
protected:
|
2014-06-11 05:44:03 +00:00
|
|
|
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
2013-07-10 22:05:39 +00:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData);
|
2014-06-11 05:44:06 +00:00
|
|
|
bool BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
2013-07-10 22:05:39 +00:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData);
|
2012-09-28 05:43:12 +00:00
|
|
|
};
|
|
|
|
|
2013-01-24 16:24:19 +00:00
|
|
|
StructuredCloneData UnpackClonedMessageDataForParent(const ClonedMessageData& aData);
|
|
|
|
StructuredCloneData UnpackClonedMessageDataForChild(const ClonedMessageData& aData);
|
|
|
|
|
2012-09-28 05:43:12 +00:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-08-02 19:57:48 +00:00
|
|
|
|
2010-05-18 12:28:37 +00:00
|
|
|
struct nsMessageListenerInfo
|
|
|
|
{
|
2013-11-05 11:52:04 +00:00
|
|
|
bool operator==(const nsMessageListenerInfo& aOther) const
|
|
|
|
{
|
|
|
|
return &aOther == this;
|
|
|
|
}
|
|
|
|
|
2013-08-08 18:36:56 +00:00
|
|
|
// Exactly one of mStrongListener and mWeakListener must be non-null.
|
|
|
|
nsCOMPtr<nsIMessageListener> mStrongListener;
|
|
|
|
nsWeakPtr mWeakListener;
|
2015-02-27 05:35:26 +00:00
|
|
|
bool mListenWhenClosed;
|
2010-05-18 12:28:37 +00:00
|
|
|
};
|
|
|
|
|
2013-07-10 22:05:39 +00:00
|
|
|
|
2015-01-26 21:32:18 +00:00
|
|
|
class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder
|
2013-07-10 22:05:39 +00:00
|
|
|
{
|
2013-11-11 08:04:41 +00:00
|
|
|
public:
|
|
|
|
SameProcessCpowHolder(JSRuntime *aRuntime, JS::Handle<JSObject*> aObj)
|
|
|
|
: mObj(aRuntime, aObj)
|
|
|
|
{
|
|
|
|
}
|
2013-07-10 22:05:39 +00:00
|
|
|
|
2015-01-15 21:13:53 +00:00
|
|
|
virtual bool ToObject(JSContext* aCx, JS::MutableHandle<JSObject*> aObjp)
|
2015-03-21 16:28:04 +00:00
|
|
|
override;
|
2013-07-10 22:05:39 +00:00
|
|
|
|
2013-11-11 08:04:41 +00:00
|
|
|
private:
|
|
|
|
JS::Rooted<JSObject*> mObj;
|
2013-07-10 22:05:39 +00:00
|
|
|
};
|
2010-05-18 12:28:37 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsFrameMessageManager final : public nsIContentFrameMessageManager,
|
2015-03-27 18:52:19 +00:00
|
|
|
public nsIMessageBroadcaster,
|
|
|
|
public nsIFrameScriptLoader,
|
|
|
|
public nsIProcessScriptLoader,
|
|
|
|
public nsIProcessChecker
|
2010-05-18 12:28:37 +00:00
|
|
|
{
|
2013-10-11 23:07:15 +00:00
|
|
|
friend class mozilla::dom::MessageManagerReporter;
|
2012-08-02 06:02:29 +00:00
|
|
|
typedef mozilla::dom::StructuredCloneData StructuredCloneData;
|
2010-05-18 12:28:37 +00:00
|
|
|
public:
|
2012-09-28 05:43:12 +00:00
|
|
|
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
|
2010-05-18 12:28:37 +00:00
|
|
|
nsFrameMessageManager* aParentManager,
|
2012-09-28 05:43:12 +00:00
|
|
|
/* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags)
|
|
|
|
: mChrome(!!(aFlags & mozilla::dom::ipc::MM_CHROME)),
|
|
|
|
mGlobal(!!(aFlags & mozilla::dom::ipc::MM_GLOBAL)),
|
|
|
|
mIsProcessManager(!!(aFlags & mozilla::dom::ipc::MM_PROCESSMANAGER)),
|
|
|
|
mIsBroadcaster(!!(aFlags & mozilla::dom::ipc::MM_BROADCASTER)),
|
|
|
|
mOwnsCallback(!!(aFlags & mozilla::dom::ipc::MM_OWNSCALLBACK)),
|
2012-08-27 14:13:02 +00:00
|
|
|
mHandlingMessage(false),
|
2015-02-27 05:35:26 +00:00
|
|
|
mClosed(false),
|
2012-08-27 14:13:02 +00:00
|
|
|
mDisconnected(false),
|
2012-09-28 05:43:12 +00:00
|
|
|
mCallback(aCallback),
|
2013-06-30 15:00:19 +00:00
|
|
|
mParentManager(aParentManager)
|
2010-05-18 12:28:37 +00:00
|
|
|
{
|
2012-09-28 05:43:12 +00:00
|
|
|
NS_ASSERTION(mChrome || !aParentManager, "Should not set parent manager!");
|
|
|
|
NS_ASSERTION(!mIsBroadcaster || !mCallback,
|
|
|
|
"Broadcasters cannot have callbacks!");
|
2010-06-10 09:26:19 +00:00
|
|
|
// This is a bit hackish. When parent manager is global, we want
|
2014-05-23 12:52:36 +00:00
|
|
|
// to attach the message manager to it immediately.
|
2010-06-10 09:26:19 +00:00
|
|
|
// Is it just the frame message manager which waits until the
|
|
|
|
// content process is running.
|
2014-05-23 12:52:36 +00:00
|
|
|
if (mParentManager && (mCallback || IsBroadcaster())) {
|
2010-05-18 12:28:37 +00:00
|
|
|
mParentManager->AddChildManager(this);
|
|
|
|
}
|
2012-09-28 05:43:12 +00:00
|
|
|
if (mOwnsCallback) {
|
|
|
|
mOwnedCallback = aCallback;
|
|
|
|
}
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 02:09:15 +00:00
|
|
|
private:
|
2010-05-18 12:28:37 +00:00
|
|
|
~nsFrameMessageManager()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = mChildManagers.Count(); i > 0; --i) {
|
2010-05-18 12:28:37 +00:00
|
|
|
static_cast<nsFrameMessageManager*>(mChildManagers[i - 1])->
|
2011-10-17 14:59:28 +00:00
|
|
|
Disconnect(false);
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
2010-08-31 18:58:35 +00:00
|
|
|
if (mIsProcessManager) {
|
|
|
|
if (this == sParentProcessManager) {
|
2012-07-30 14:20:58 +00:00
|
|
|
sParentProcessManager = nullptr;
|
2010-08-31 18:58:35 +00:00
|
|
|
}
|
|
|
|
if (this == sChildProcessManager) {
|
2012-07-30 14:20:58 +00:00
|
|
|
sChildProcessManager = nullptr;
|
2015-03-24 20:05:39 +00:00
|
|
|
delete mozilla::dom::SameProcessMessageQueue::Get();
|
2011-10-11 10:28:46 +00:00
|
|
|
}
|
|
|
|
if (this == sSameProcessParentManager) {
|
2012-07-30 14:20:58 +00:00
|
|
|
sSameProcessParentManager = nullptr;
|
2010-08-31 18:58:35 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 12:28:37 +00:00
|
|
|
}
|
|
|
|
|
2014-06-25 02:09:15 +00:00
|
|
|
public:
|
2010-05-18 12:28:37 +00:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFrameMessageManager,
|
|
|
|
nsIContentFrameMessageManager)
|
2012-08-27 14:13:02 +00:00
|
|
|
NS_DECL_NSIMESSAGELISTENERMANAGER
|
|
|
|
NS_DECL_NSIMESSAGESENDER
|
|
|
|
NS_DECL_NSIMESSAGEBROADCASTER
|
2010-08-31 18:58:35 +00:00
|
|
|
NS_DECL_NSISYNCMESSAGESENDER
|
2015-02-20 01:12:11 +00:00
|
|
|
NS_DECL_NSIMESSAGEMANAGERGLOBAL
|
2010-05-18 12:28:37 +00:00
|
|
|
NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER
|
2012-08-27 14:13:02 +00:00
|
|
|
NS_DECL_NSIFRAMESCRIPTLOADER
|
2015-02-20 01:13:02 +00:00
|
|
|
NS_DECL_NSIPROCESSSCRIPTLOADER
|
2012-12-22 12:00:10 +00:00
|
|
|
NS_DECL_NSIPROCESSCHECKER
|
2011-08-02 19:57:48 +00:00
|
|
|
|
|
|
|
static nsFrameMessageManager*
|
2015-03-06 01:03:25 +00:00
|
|
|
NewProcessMessageManager(bool aIsRemote);
|
2010-05-18 12:28:37 +00:00
|
|
|
|
2015-04-16 15:17:54 +00:00
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
const nsAString& aMessage,
|
2013-10-01 16:15:06 +00:00
|
|
|
bool aIsSync, const StructuredCloneData* aCloneData,
|
2015-01-26 21:32:18 +00:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
2013-06-30 15:00:18 +00:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal);
|
2012-08-02 06:02:29 +00:00
|
|
|
|
2014-01-31 18:45:54 +00:00
|
|
|
void AddChildManager(nsFrameMessageManager* aManager);
|
2010-05-18 12:28:37 +00:00
|
|
|
void RemoveChildManager(nsFrameMessageManager* aManager)
|
|
|
|
{
|
|
|
|
mChildManagers.RemoveObject(aManager);
|
|
|
|
}
|
2012-09-28 13:08:04 +00:00
|
|
|
void Disconnect(bool aRemoveFromParent = true);
|
2015-02-27 05:35:26 +00:00
|
|
|
void Close();
|
2012-09-28 05:43:12 +00:00
|
|
|
|
2014-01-31 18:45:54 +00:00
|
|
|
void InitWithCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
|
|
|
void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
2012-09-28 05:43:12 +00:00
|
|
|
mozilla::dom::ipc::MessageManagerCallback* GetCallback()
|
|
|
|
{
|
|
|
|
return mCallback;
|
|
|
|
}
|
|
|
|
|
2012-08-27 14:13:02 +00:00
|
|
|
nsresult DispatchAsyncMessage(const nsAString& aMessageName,
|
2013-07-10 22:05:39 +00:00
|
|
|
const JS::Value& aJSON,
|
|
|
|
const JS::Value& aObjects,
|
2013-11-06 17:21:15 +00:00
|
|
|
nsIPrincipal* aPrincipal,
|
2012-08-27 14:13:02 +00:00
|
|
|
JSContext* aCx,
|
2012-09-28 05:43:12 +00:00
|
|
|
uint8_t aArgc);
|
2013-07-10 22:05:39 +00:00
|
|
|
nsresult DispatchAsyncMessageInternal(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-11 08:04:41 +00:00
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 17:21:15 +00:00
|
|
|
nsIPrincipal* aPrincipal);
|
2012-01-07 19:20:26 +00:00
|
|
|
void RemoveFromParent();
|
2010-05-18 12:28:37 +00:00
|
|
|
nsFrameMessageManager* GetParentManager() { return mParentManager; }
|
|
|
|
void SetParentManager(nsFrameMessageManager* aParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mParentManager, "We have parent manager already!");
|
|
|
|
NS_ASSERTION(mChrome, "Should not set parent manager!");
|
|
|
|
mParentManager = aParent;
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
bool IsGlobal() { return mGlobal; }
|
2014-05-23 12:52:36 +00:00
|
|
|
bool IsBroadcaster() { return mIsBroadcaster; }
|
2010-08-31 18:58:35 +00:00
|
|
|
|
|
|
|
static nsFrameMessageManager* GetParentProcessManager()
|
|
|
|
{
|
|
|
|
return sParentProcessManager;
|
|
|
|
}
|
|
|
|
static nsFrameMessageManager* GetChildProcessManager()
|
|
|
|
{
|
|
|
|
return sChildProcessManager;
|
|
|
|
}
|
2015-02-20 01:12:38 +00:00
|
|
|
static void SetChildProcessManager(nsFrameMessageManager* aManager)
|
|
|
|
{
|
|
|
|
sChildProcessManager = aManager;
|
|
|
|
}
|
2013-10-01 16:15:06 +00:00
|
|
|
private:
|
|
|
|
nsresult SendMessage(const nsAString& aMessageName,
|
2014-01-09 17:39:36 +00:00
|
|
|
JS::Handle<JS::Value> aJSON,
|
|
|
|
JS::Handle<JS::Value> aObjects,
|
2013-11-06 17:21:15 +00:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 16:15:06 +00:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc,
|
2014-01-09 17:39:36 +00:00
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
2013-10-01 16:15:06 +00:00
|
|
|
bool aIsSync);
|
2015-02-20 01:13:02 +00:00
|
|
|
|
2015-04-16 15:17:54 +00:00
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
bool aTargetClosed, const nsAString& aMessage,
|
2015-02-27 05:35:26 +00:00
|
|
|
bool aIsSync, const StructuredCloneData* aCloneData,
|
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
|
|
|
InfallibleTArray<nsString>* aJSONRetVal);
|
|
|
|
|
2015-02-20 01:13:02 +00:00
|
|
|
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);
|
|
|
|
|
2010-05-18 12:28:37 +00:00
|
|
|
protected:
|
2012-01-07 19:20:12 +00:00
|
|
|
friend class MMListenerRemover;
|
2013-10-25 21:55:16 +00:00
|
|
|
// We keep the message listeners as arrays in a hastable indexed by the
|
|
|
|
// message name. That gives us fast lookups in ReceiveMessage().
|
2013-11-05 11:52:04 +00:00
|
|
|
nsClassHashtable<nsStringHashKey,
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>> mListeners;
|
2010-05-18 12:28:37 +00:00
|
|
|
nsCOMArray<nsIContentFrameMessageManager> mChildManagers;
|
2012-08-27 14:13:02 +00:00
|
|
|
bool mChrome; // true if we're in the chrome process
|
2012-09-28 05:43:12 +00:00
|
|
|
bool mGlobal; // true if we're the global frame message manager
|
2012-08-27 14:13:02 +00:00
|
|
|
bool mIsProcessManager; // true if the message manager belongs to the process realm
|
|
|
|
bool mIsBroadcaster; // true if the message manager is a broadcaster
|
2012-09-28 05:43:12 +00:00
|
|
|
bool mOwnsCallback;
|
2012-01-07 19:20:12 +00:00
|
|
|
bool mHandlingMessage;
|
2015-02-27 05:35:26 +00:00
|
|
|
bool mClosed; // true if we can no longer send messages
|
2012-01-07 19:20:12 +00:00
|
|
|
bool mDisconnected;
|
2012-09-28 05:43:12 +00:00
|
|
|
mozilla::dom::ipc::MessageManagerCallback* mCallback;
|
|
|
|
nsAutoPtr<mozilla::dom::ipc::MessageManagerCallback> mOwnedCallback;
|
2010-05-18 12:28:37 +00:00
|
|
|
nsFrameMessageManager* mParentManager;
|
|
|
|
nsTArray<nsString> mPendingScripts;
|
2013-11-24 05:32:45 +00:00
|
|
|
nsTArray<bool> mPendingScriptsGlobalStates;
|
2014-05-23 12:52:36 +00:00
|
|
|
|
|
|
|
void LoadPendingScripts(nsFrameMessageManager* aManager,
|
|
|
|
nsFrameMessageManager* aChildMM);
|
2010-08-31 18:58:35 +00:00
|
|
|
public:
|
|
|
|
static nsFrameMessageManager* sParentProcessManager;
|
2011-10-11 10:28:46 +00:00
|
|
|
static nsFrameMessageManager* sSameProcessParentManager;
|
|
|
|
static nsTArray<nsCOMPtr<nsIRunnable> >* sPendingSameProcessAsyncMessages;
|
2012-12-22 12:00:10 +00:00
|
|
|
private:
|
2015-02-20 01:12:38 +00:00
|
|
|
static nsFrameMessageManager* sChildProcessManager;
|
2012-12-22 12:00:10 +00:00
|
|
|
enum ProcessCheckerType {
|
|
|
|
PROCESS_CHECKER_PERMISSION,
|
2013-01-14 10:08:55 +00:00
|
|
|
PROCESS_CHECKER_MANIFEST_URL,
|
|
|
|
ASSERT_APP_HAS_PERMISSION
|
2012-12-22 12:00:10 +00:00
|
|
|
};
|
|
|
|
nsresult AssertProcessInternal(ProcessCheckerType aType,
|
|
|
|
const nsAString& aCapability,
|
|
|
|
bool* aValid);
|
2010-05-18 12:28:37 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 14:22:00 +00:00
|
|
|
/* A helper class for taking care of many details for async message sending
|
|
|
|
within a single process. Intended to be used like so:
|
|
|
|
|
|
|
|
class MyAsyncMessage : public nsSameProcessAsyncMessageBase, public nsRunnable
|
|
|
|
{
|
|
|
|
// Initialize nsSameProcessAsyncMessageBase...
|
|
|
|
|
|
|
|
NS_IMETHOD Run() {
|
|
|
|
ReceiveMessage(..., ...);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
class nsSameProcessAsyncMessageBase
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::StructuredCloneClosure StructuredCloneClosure;
|
|
|
|
|
|
|
|
public:
|
|
|
|
typedef mozilla::dom::StructuredCloneData StructuredCloneData;
|
|
|
|
|
|
|
|
nsSameProcessAsyncMessageBase(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal);
|
|
|
|
|
2015-04-16 15:17:54 +00:00
|
|
|
void ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
nsFrameMessageManager* aManager);
|
2014-03-12 14:22:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsSameProcessAsyncMessageBase(const nsSameProcessAsyncMessageBase&);
|
|
|
|
|
|
|
|
JSRuntime* mRuntime;
|
|
|
|
nsString mMessage;
|
|
|
|
JSAutoStructuredCloneBuffer mData;
|
|
|
|
StructuredCloneClosure mClosure;
|
2014-04-16 08:47:53 +00:00
|
|
|
JS::PersistentRooted<JSObject*> mCpows;
|
2014-03-12 14:22:00 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
};
|
|
|
|
|
2010-08-16 20:40:04 +00:00
|
|
|
class nsScriptCacheCleaner;
|
|
|
|
|
2015-02-20 01:10:44 +00:00
|
|
|
struct nsMessageManagerScriptHolder
|
2010-08-10 17:18:26 +00:00
|
|
|
{
|
2015-02-20 01:10:44 +00:00
|
|
|
nsMessageManagerScriptHolder(JSContext* aCx,
|
|
|
|
JSScript* aScript,
|
|
|
|
bool aRunInGlobalScope)
|
2014-06-13 17:56:38 +00:00
|
|
|
: mScript(aCx, aScript), mRunInGlobalScope(aRunInGlobalScope)
|
2015-02-20 01:10:44 +00:00
|
|
|
{ MOZ_COUNT_CTOR(nsMessageManagerScriptHolder); }
|
2014-04-16 08:47:53 +00:00
|
|
|
|
2015-02-20 01:10:44 +00:00
|
|
|
~nsMessageManagerScriptHolder()
|
|
|
|
{ MOZ_COUNT_DTOR(nsMessageManagerScriptHolder); }
|
2013-11-24 05:32:45 +00:00
|
|
|
|
2014-06-13 17:56:38 +00:00
|
|
|
bool WillRunInGlobalScope() { return mRunInGlobalScope; }
|
2013-11-24 05:32:45 +00:00
|
|
|
|
2014-04-16 08:47:53 +00:00
|
|
|
JS::PersistentRooted<JSScript*> mScript;
|
2014-06-13 17:56:38 +00:00
|
|
|
bool mRunInGlobalScope;
|
2010-08-10 17:18:26 +00:00
|
|
|
};
|
|
|
|
|
2015-02-20 01:10:44 +00:00
|
|
|
class nsMessageManagerScriptExecutor
|
2010-08-10 17:18:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void Shutdown();
|
2013-06-30 15:00:18 +00:00
|
|
|
already_AddRefed<nsIXPConnectJSObjectHolder> GetGlobal()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> ref = mGlobal;
|
|
|
|
return ref.forget();
|
|
|
|
}
|
2015-02-24 22:23:53 +00:00
|
|
|
|
|
|
|
void MarkScopesForCC();
|
2010-08-10 17:18:26 +00:00
|
|
|
protected:
|
2015-02-20 01:10:44 +00:00
|
|
|
friend class nsMessageManagerScriptCx;
|
|
|
|
nsMessageManagerScriptExecutor() { MOZ_COUNT_CTOR(nsMessageManagerScriptExecutor); }
|
|
|
|
~nsMessageManagerScriptExecutor() { MOZ_COUNT_DTOR(nsMessageManagerScriptExecutor); }
|
2014-06-13 17:56:38 +00:00
|
|
|
|
2013-06-30 15:00:18 +00:00
|
|
|
void DidCreateGlobal();
|
2015-02-20 01:10:44 +00:00
|
|
|
void LoadScriptInternal(const nsAString& aURL, bool aRunInGlobalScope);
|
2013-11-24 05:32:45 +00:00
|
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope,
|
|
|
|
bool aShouldCache,
|
2014-06-13 17:56:38 +00:00
|
|
|
JS::MutableHandle<JSScript*> aScriptp);
|
2012-08-29 15:26:18 +00:00
|
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
2013-11-24 05:32:45 +00:00
|
|
|
bool aRunInGlobalScope);
|
2015-02-20 01:10:44 +00:00
|
|
|
bool InitChildGlobalInternal(nsISupports* aScope, const nsACString& aID);
|
2010-08-10 17:18:26 +00:00
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2014-06-13 17:56:38 +00:00
|
|
|
nsAutoTArray<JS::Heap<JSObject*>, 2> mAnonymousGlobalScopes;
|
|
|
|
|
2015-02-20 01:10:44 +00:00
|
|
|
static nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* sCachedScripts;
|
2012-10-05 19:10:30 +00:00
|
|
|
static nsScriptCacheCleaner* sScriptCacheCleaner;
|
2010-08-16 20:40:04 +00:00
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class nsScriptCacheCleaner final : public nsIObserver
|
2010-08-16 20:40:04 +00:00
|
|
|
{
|
2014-06-25 02:09:15 +00:00
|
|
|
~nsScriptCacheCleaner() {}
|
|
|
|
|
2010-08-16 20:40:04 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsScriptCacheCleaner()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
|
|
|
if (obsSvc)
|
2011-10-17 14:59:28 +00:00
|
|
|
obsSvc->AddObserver(this, "xpcom-shutdown", false);
|
2010-08-16 20:40:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2015-03-21 16:28:04 +00:00
|
|
|
const char16_t *aData) override
|
2010-08-16 20:40:04 +00:00
|
|
|
{
|
2015-02-20 01:10:44 +00:00
|
|
|
nsMessageManagerScriptExecutor::Shutdown();
|
2010-08-16 20:40:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-10 17:18:26 +00:00
|
|
|
};
|
|
|
|
|
2012-09-11 17:59:10 +00:00
|
|
|
#endif
|