2013-11-11 12:04:41 +04: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 15:12:37 +04: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 12:04:41 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
#ifndef nsFrameMessageManager_h__
|
|
|
|
#define nsFrameMessageManager_h__
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
#include "nsIMessageManager.h"
|
2010-08-17 00:40:04 +04:00
|
|
|
#include "nsIObserver.h"
|
2010-05-18 16:28:37 +04: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 21:18:26 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2013-10-26 01:55:16 +04:00
|
|
|
#include "nsClassHashtable.h"
|
2010-08-17 00:40:04 +04:00
|
|
|
#include "mozilla/Services.h"
|
|
|
|
#include "nsIObserverService.h"
|
2011-10-11 14:28:46 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2013-08-08 22:36:56 +04:00
|
|
|
#include "nsWeakPtr.h"
|
2012-06-19 06:30:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-08-18 02:50:18 +04:00
|
|
|
#include "js/RootingAPI.h"
|
2013-11-05 15:52:04 +04:00
|
|
|
#include "nsTObserverArray.h"
|
2014-03-12 18:22:00 +04:00
|
|
|
#include "mozilla/dom/StructuredCloneUtils.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CpowHolder.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2011-08-02 23:57:48 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-06-11 09:44:03 +04:00
|
|
|
class nsIContentParent;
|
2014-06-11 09:44:06 +04:00
|
|
|
class nsIContentChild;
|
2013-01-24 06:39:27 +04:00
|
|
|
class ClonedMessageData;
|
2013-10-12 03:07:15 +04:00
|
|
|
class MessageManagerReporter;
|
2012-09-28 09:43:12 +04: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() {}
|
|
|
|
|
2013-11-24 09:32:45 +04:00
|
|
|
virtual bool DoLoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2013-11-11 12:04:41 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 20:15:06 +04:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal,
|
|
|
|
bool aIsSync)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2013-11-11 12:04:41 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool CheckPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-12-22 16:00:10 +04:00
|
|
|
|
|
|
|
virtual bool CheckManifestURL(const nsAString& aManifestURL)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-14 14:08:55 +04:00
|
|
|
|
|
|
|
virtual bool CheckAppHasPermission(const nsAString& aPermission)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-24 06:39:27 +04:00
|
|
|
|
2013-06-29 14:52:16 +04:00
|
|
|
virtual bool CheckAppHasStatus(unsigned short aStatus)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-08-12 16:59:47 +04:00
|
|
|
virtual bool KillChild()
|
|
|
|
{
|
|
|
|
// By default, does nothing.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-01-24 06:39:27 +04:00
|
|
|
protected:
|
2014-06-11 09:44:03 +04:00
|
|
|
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
2013-07-11 02:05:39 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData);
|
2014-06-11 09:44:06 +04:00
|
|
|
bool BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
2013-07-11 02:05:39 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData);
|
2012-09-28 09:43:12 +04:00
|
|
|
};
|
|
|
|
|
2013-01-24 20:24:19 +04:00
|
|
|
StructuredCloneData UnpackClonedMessageDataForParent(const ClonedMessageData& aData);
|
|
|
|
StructuredCloneData UnpackClonedMessageDataForChild(const ClonedMessageData& aData);
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
} // namespace ipc
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-08-02 23:57:48 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
class nsAXPCNativeCallContext;
|
|
|
|
|
|
|
|
struct nsMessageListenerInfo
|
|
|
|
{
|
2013-11-05 15:52:04 +04:00
|
|
|
bool operator==(const nsMessageListenerInfo& aOther) const
|
|
|
|
{
|
|
|
|
return &aOther == this;
|
|
|
|
}
|
|
|
|
|
2013-08-08 22:36:56 +04:00
|
|
|
// Exactly one of mStrongListener and mWeakListener must be non-null.
|
|
|
|
nsCOMPtr<nsIMessageListener> mStrongListener;
|
|
|
|
nsWeakPtr mWeakListener;
|
2010-05-18 16:28:37 +04:00
|
|
|
};
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
|
2015-01-27 00:32:18 +03:00
|
|
|
class MOZ_STACK_CLASS SameProcessCpowHolder : public mozilla::jsipc::CpowHolder
|
2013-07-11 02:05:39 +04:00
|
|
|
{
|
2013-11-11 12:04:41 +04:00
|
|
|
public:
|
|
|
|
SameProcessCpowHolder(JSRuntime *aRuntime, JS::Handle<JSObject*> aObj)
|
|
|
|
: mObj(aRuntime, aObj)
|
|
|
|
{
|
|
|
|
}
|
2013-07-11 02:05:39 +04:00
|
|
|
|
2015-01-16 00:13:53 +03:00
|
|
|
virtual bool ToObject(JSContext* aCx, JS::MutableHandle<JSObject*> aObjp)
|
|
|
|
MOZ_OVERRIDE;
|
2013-07-11 02:05:39 +04:00
|
|
|
|
2013-11-11 12:04:41 +04:00
|
|
|
private:
|
|
|
|
JS::Rooted<JSObject*> mObj;
|
2013-07-11 02:05:39 +04:00
|
|
|
};
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2012-06-19 06:30:09 +04:00
|
|
|
class nsFrameMessageManager MOZ_FINAL : public nsIContentFrameMessageManager,
|
2012-08-27 18:13:02 +04:00
|
|
|
public nsIMessageBroadcaster,
|
2012-09-28 09:43:12 +04:00
|
|
|
public nsIFrameScriptLoader,
|
2012-12-22 16:00:10 +04:00
|
|
|
public nsIProcessChecker
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2013-10-12 03:07:15 +04:00
|
|
|
friend class mozilla::dom::MessageManagerReporter;
|
2012-08-02 10:02:29 +04:00
|
|
|
typedef mozilla::dom::StructuredCloneData StructuredCloneData;
|
2010-05-18 16:28:37 +04:00
|
|
|
public:
|
2012-09-28 09:43:12 +04:00
|
|
|
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
|
2010-05-18 16:28:37 +04:00
|
|
|
nsFrameMessageManager* aParentManager,
|
2012-09-28 09:43:12 +04: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 18:13:02 +04:00
|
|
|
mHandlingMessage(false),
|
|
|
|
mDisconnected(false),
|
2012-09-28 09:43:12 +04:00
|
|
|
mCallback(aCallback),
|
2013-06-30 19:00:19 +04:00
|
|
|
mParentManager(aParentManager)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2012-09-28 09:43:12 +04:00
|
|
|
NS_ASSERTION(mChrome || !aParentManager, "Should not set parent manager!");
|
|
|
|
NS_ASSERTION(!mIsBroadcaster || !mCallback,
|
|
|
|
"Broadcasters cannot have callbacks!");
|
2010-06-10 13:26:19 +04:00
|
|
|
// This is a bit hackish. When parent manager is global, we want
|
2014-05-23 16:52:36 +04:00
|
|
|
// to attach the message manager to it immediately.
|
2010-06-10 13:26:19 +04:00
|
|
|
// Is it just the frame message manager which waits until the
|
|
|
|
// content process is running.
|
2014-05-23 16:52:36 +04:00
|
|
|
if (mParentManager && (mCallback || IsBroadcaster())) {
|
2010-05-18 16:28:37 +04:00
|
|
|
mParentManager->AddChildManager(this);
|
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
if (mOwnsCallback) {
|
|
|
|
mOwnedCallback = aCallback;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
private:
|
2010-05-18 16:28:37 +04:00
|
|
|
~nsFrameMessageManager()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = mChildManagers.Count(); i > 0; --i) {
|
2010-05-18 16:28:37 +04:00
|
|
|
static_cast<nsFrameMessageManager*>(mChildManagers[i - 1])->
|
2011-10-17 18:59:28 +04:00
|
|
|
Disconnect(false);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2010-08-31 22:58:35 +04:00
|
|
|
if (mIsProcessManager) {
|
|
|
|
if (this == sParentProcessManager) {
|
2012-07-30 18:20:58 +04:00
|
|
|
sParentProcessManager = nullptr;
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
if (this == sChildProcessManager) {
|
2012-07-30 18:20:58 +04:00
|
|
|
sChildProcessManager = nullptr;
|
2015-02-18 22:47:27 +03:00
|
|
|
delete sPendingSameProcessAsyncMessages;
|
|
|
|
sPendingSameProcessAsyncMessages = nullptr;
|
2011-10-11 14:28:46 +04:00
|
|
|
}
|
|
|
|
if (this == sSameProcessParentManager) {
|
2012-07-30 18:20:58 +04:00
|
|
|
sSameProcessParentManager = nullptr;
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
public:
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsFrameMessageManager,
|
|
|
|
nsIContentFrameMessageManager)
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_DECL_NSIMESSAGELISTENERMANAGER
|
|
|
|
NS_DECL_NSIMESSAGESENDER
|
|
|
|
NS_DECL_NSIMESSAGEBROADCASTER
|
2010-08-31 22:58:35 +04:00
|
|
|
NS_DECL_NSISYNCMESSAGESENDER
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_DECL_NSIFRAMESCRIPTLOADER
|
2012-12-22 16:00:10 +04:00
|
|
|
NS_DECL_NSIPROCESSCHECKER
|
2011-08-02 23:57:48 +04:00
|
|
|
|
|
|
|
static nsFrameMessageManager*
|
2014-06-11 09:44:03 +04:00
|
|
|
NewProcessMessageManager(mozilla::dom::nsIContentParent* aProcess);
|
2010-05-18 16:28:37 +04:00
|
|
|
|
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, const nsAString& aMessage,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync, const StructuredCloneData* aCloneData,
|
2015-01-27 00:32:18 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
2013-06-30 19:00:18 +04:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2014-01-31 22:45:54 +04:00
|
|
|
void AddChildManager(nsFrameMessageManager* aManager);
|
2010-05-18 16:28:37 +04:00
|
|
|
void RemoveChildManager(nsFrameMessageManager* aManager)
|
|
|
|
{
|
|
|
|
mChildManagers.RemoveObject(aManager);
|
|
|
|
}
|
2012-09-28 17:08:04 +04:00
|
|
|
void Disconnect(bool aRemoveFromParent = true);
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-01-31 22:45:54 +04:00
|
|
|
void InitWithCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
|
|
|
void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
2012-09-28 09:43:12 +04:00
|
|
|
mozilla::dom::ipc::MessageManagerCallback* GetCallback()
|
|
|
|
{
|
|
|
|
return mCallback;
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
nsresult DispatchAsyncMessage(const nsAString& aMessageName,
|
2013-07-11 02:05:39 +04:00
|
|
|
const JS::Value& aJSON,
|
|
|
|
const JS::Value& aObjects,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
2012-09-28 09:43:12 +04:00
|
|
|
uint8_t aArgc);
|
2013-07-11 02:05:39 +04:00
|
|
|
nsresult DispatchAsyncMessageInternal(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal);
|
2012-01-07 23:20:26 +04:00
|
|
|
void RemoveFromParent();
|
2010-05-18 16:28:37 +04: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 10:19:26 +04:00
|
|
|
bool IsGlobal() { return mGlobal; }
|
2014-05-23 16:52:36 +04:00
|
|
|
bool IsBroadcaster() { return mIsBroadcaster; }
|
2010-08-31 22:58:35 +04:00
|
|
|
|
|
|
|
static nsFrameMessageManager* GetParentProcessManager()
|
|
|
|
{
|
|
|
|
return sParentProcessManager;
|
|
|
|
}
|
|
|
|
static nsFrameMessageManager* GetChildProcessManager()
|
|
|
|
{
|
|
|
|
return sChildProcessManager;
|
|
|
|
}
|
2013-10-01 20:15:06 +04:00
|
|
|
private:
|
|
|
|
nsresult SendMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aJSON,
|
|
|
|
JS::Handle<JS::Value> aObjects,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 20:15:06 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync);
|
2010-05-18 16:28:37 +04:00
|
|
|
protected:
|
2012-01-07 23:20:12 +04:00
|
|
|
friend class MMListenerRemover;
|
2013-10-26 01:55:16 +04: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 15:52:04 +04:00
|
|
|
nsClassHashtable<nsStringHashKey,
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>> mListeners;
|
2010-05-18 16:28:37 +04:00
|
|
|
nsCOMArray<nsIContentFrameMessageManager> mChildManagers;
|
2012-08-27 18:13:02 +04:00
|
|
|
bool mChrome; // true if we're in the chrome process
|
2012-09-28 09:43:12 +04:00
|
|
|
bool mGlobal; // true if we're the global frame message manager
|
2012-08-27 18:13:02 +04: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 09:43:12 +04:00
|
|
|
bool mOwnsCallback;
|
2012-01-07 23:20:12 +04:00
|
|
|
bool mHandlingMessage;
|
|
|
|
bool mDisconnected;
|
2012-09-28 09:43:12 +04:00
|
|
|
mozilla::dom::ipc::MessageManagerCallback* mCallback;
|
|
|
|
nsAutoPtr<mozilla::dom::ipc::MessageManagerCallback> mOwnedCallback;
|
2010-05-18 16:28:37 +04:00
|
|
|
nsFrameMessageManager* mParentManager;
|
|
|
|
nsTArray<nsString> mPendingScripts;
|
2013-11-24 09:32:45 +04:00
|
|
|
nsTArray<bool> mPendingScriptsGlobalStates;
|
2014-05-23 16:52:36 +04:00
|
|
|
|
|
|
|
void LoadPendingScripts(nsFrameMessageManager* aManager,
|
|
|
|
nsFrameMessageManager* aChildMM);
|
2010-08-31 22:58:35 +04:00
|
|
|
public:
|
|
|
|
static nsFrameMessageManager* sParentProcessManager;
|
|
|
|
static nsFrameMessageManager* sChildProcessManager;
|
2011-10-11 14:28:46 +04:00
|
|
|
static nsFrameMessageManager* sSameProcessParentManager;
|
|
|
|
static nsTArray<nsCOMPtr<nsIRunnable> >* sPendingSameProcessAsyncMessages;
|
2012-12-22 16:00:10 +04:00
|
|
|
private:
|
|
|
|
enum ProcessCheckerType {
|
|
|
|
PROCESS_CHECKER_PERMISSION,
|
2013-01-14 14:08:55 +04:00
|
|
|
PROCESS_CHECKER_MANIFEST_URL,
|
|
|
|
ASSERT_APP_HAS_PERMISSION
|
2012-12-22 16:00:10 +04:00
|
|
|
};
|
|
|
|
nsresult AssertProcessInternal(ProcessCheckerType aType,
|
|
|
|
const nsAString& aCapability,
|
|
|
|
bool* aValid);
|
2010-05-18 16:28:37 +04:00
|
|
|
};
|
|
|
|
|
2014-03-12 18:22:00 +04: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);
|
|
|
|
|
|
|
|
void ReceiveMessage(nsISupports* aTarget, nsFrameMessageManager* aManager);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsSameProcessAsyncMessageBase(const nsSameProcessAsyncMessageBase&);
|
|
|
|
|
|
|
|
JSRuntime* mRuntime;
|
|
|
|
nsString mMessage;
|
|
|
|
JSAutoStructuredCloneBuffer mData;
|
|
|
|
StructuredCloneClosure mClosure;
|
2014-04-16 12:47:53 +04:00
|
|
|
JS::PersistentRooted<JSObject*> mCpows;
|
2014-03-12 18:22:00 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
};
|
|
|
|
|
2010-08-17 00:40:04 +04:00
|
|
|
class nsScriptCacheCleaner;
|
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
struct nsMessageManagerScriptHolder
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptHolder(JSContext* aCx,
|
|
|
|
JSScript* aScript,
|
|
|
|
bool aRunInGlobalScope)
|
2014-06-13 21:56:38 +04:00
|
|
|
: mScript(aCx, aScript), mRunInGlobalScope(aRunInGlobalScope)
|
2015-02-20 04:10:44 +03:00
|
|
|
{ MOZ_COUNT_CTOR(nsMessageManagerScriptHolder); }
|
2014-04-16 12:47:53 +04:00
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
~nsMessageManagerScriptHolder()
|
|
|
|
{ MOZ_COUNT_DTOR(nsMessageManagerScriptHolder); }
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2014-06-13 21:56:38 +04:00
|
|
|
bool WillRunInGlobalScope() { return mRunInGlobalScope; }
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2014-04-16 12:47:53 +04:00
|
|
|
JS::PersistentRooted<JSScript*> mScript;
|
2014-06-13 21:56:38 +04:00
|
|
|
bool mRunInGlobalScope;
|
2010-08-10 21:18:26 +04:00
|
|
|
};
|
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
class nsMessageManagerScriptExecutor
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void Shutdown();
|
2013-06-30 19:00:18 +04:00
|
|
|
already_AddRefed<nsIXPConnectJSObjectHolder> GetGlobal()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> ref = mGlobal;
|
|
|
|
return ref.forget();
|
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
protected:
|
2015-02-20 04:10:44 +03:00
|
|
|
friend class nsMessageManagerScriptCx;
|
|
|
|
nsMessageManagerScriptExecutor() { MOZ_COUNT_CTOR(nsMessageManagerScriptExecutor); }
|
|
|
|
~nsMessageManagerScriptExecutor() { MOZ_COUNT_DTOR(nsMessageManagerScriptExecutor); }
|
2014-06-13 21:56:38 +04:00
|
|
|
|
2013-06-30 19:00:18 +04:00
|
|
|
void DidCreateGlobal();
|
2015-02-20 04:10:44 +03:00
|
|
|
void LoadScriptInternal(const nsAString& aURL, bool aRunInGlobalScope);
|
2013-11-24 09:32:45 +04:00
|
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope,
|
|
|
|
bool aShouldCache,
|
2014-06-13 21:56:38 +04:00
|
|
|
JS::MutableHandle<JSScript*> aScriptp);
|
2012-08-29 19:26:18 +04:00
|
|
|
void TryCacheLoadAndCompileScript(const nsAString& aURL,
|
2013-11-24 09:32:45 +04:00
|
|
|
bool aRunInGlobalScope);
|
2015-02-20 04:10:44 +03:00
|
|
|
bool InitChildGlobalInternal(nsISupports* aScope, const nsACString& aID);
|
2010-08-10 21:18:26 +04:00
|
|
|
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2014-06-13 21:56:38 +04:00
|
|
|
nsAutoTArray<JS::Heap<JSObject*>, 2> mAnonymousGlobalScopes;
|
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
static nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* sCachedScripts;
|
2012-10-05 23:10:30 +04:00
|
|
|
static nsScriptCacheCleaner* sScriptCacheCleaner;
|
2010-08-17 00:40:04 +04:00
|
|
|
};
|
|
|
|
|
2012-06-19 06:30:09 +04:00
|
|
|
class nsScriptCacheCleaner MOZ_FINAL : public nsIObserver
|
2010-08-17 00:40:04 +04:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
~nsScriptCacheCleaner() {}
|
|
|
|
|
2010-08-17 00:40:04 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsScriptCacheCleaner()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
|
|
|
|
if (obsSvc)
|
2011-10-17 18:59:28 +04:00
|
|
|
obsSvc->AddObserver(this, "xpcom-shutdown", false);
|
2010-08-17 00:40:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
2015-01-03 05:13:39 +03:00
|
|
|
const char16_t *aData) MOZ_OVERRIDE
|
2010-08-17 00:40:04 +04:00
|
|
|
{
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::Shutdown();
|
2010-08-17 00:40:04 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
};
|
|
|
|
|
2012-09-11 21:59:10 +04:00
|
|
|
#endif
|