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"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#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"
|
2016-07-21 19:54:16 +03:00
|
|
|
#include "mozilla/StaticPtr.h"
|
2010-08-17 00:40:04 +04:00
|
|
|
#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"
|
2017-06-14 17:44:17 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2017-06-20 12:09:50 +03:00
|
|
|
#include "mozilla/dom/CallbackObject.h"
|
2015-03-24 23:05:39 +03:00
|
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
2015-09-10 23:50:58 +03:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CpowHolder.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
class nsIFrameLoader;
|
|
|
|
|
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;
|
2017-06-14 17:44:17 +03:00
|
|
|
class ChildProcessMessageManager;
|
|
|
|
class ChromeMessageSender;
|
2013-01-24 06:39:27 +04:00
|
|
|
class ClonedMessageData;
|
2017-06-20 12:09:50 +03:00
|
|
|
class MessageListener;
|
|
|
|
class MessageListenerManager;
|
2013-10-12 03:07:15 +04:00
|
|
|
class MessageManagerReporter;
|
2017-06-20 12:09:50 +03:00
|
|
|
template<typename T> class Optional;
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
|
2017-03-21 01:18:55 +03:00
|
|
|
// Note: we round the time we spend to the nearest millisecond. So a min value
|
|
|
|
// of 1 ms actually captures from 500us and above.
|
|
|
|
static const uint32_t kMinTelemetrySyncMessageManagerLatencyMs = 1;
|
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
enum class MessageManagerFlags {
|
|
|
|
MM_NONE = 0,
|
2012-09-28 09:43:12 +04:00
|
|
|
MM_CHROME = 1,
|
|
|
|
MM_GLOBAL = 2,
|
|
|
|
MM_PROCESSMANAGER = 4,
|
|
|
|
MM_BROADCASTER = 8,
|
|
|
|
MM_OWNSCALLBACK = 16
|
|
|
|
};
|
2017-06-14 17:44:17 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(MessageManagerFlags);
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
class MessageManagerCallback
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~MessageManagerCallback() {}
|
|
|
|
|
2015-02-20 04:11:32 +03:00
|
|
|
virtual bool DoLoadMessageManagerScript(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,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-10-07 13:42:43 +03:00
|
|
|
virtual nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_OK;
|
2012-09-28 09:43:12 +04:00
|
|
|
}
|
|
|
|
|
2016-08-22 11:28:04 +03:00
|
|
|
virtual nsIMessageSender* GetProcessMessageManager() const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-08-14 04:58:23 +03:00
|
|
|
virtual nsresult DoGetRemoteType(nsAString& aRemoteType) const
|
|
|
|
{
|
|
|
|
aRemoteType.Truncate();
|
|
|
|
nsIMessageSender* parent = GetProcessMessageManager();
|
|
|
|
if (parent) {
|
|
|
|
return parent->GetRemoteType(aRemoteType);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-01-24 06:39:27 +04:00
|
|
|
protected:
|
2014-06-11 09:44:03 +04:00
|
|
|
bool BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-07-11 02:05:39 +04:00
|
|
|
ClonedMessageData& aClonedData);
|
2014-06-11 09:44:06 +04:00
|
|
|
bool BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-07-11 02:05:39 +04:00
|
|
|
ClonedMessageData& aClonedData);
|
2012-09-28 09:43:12 +04:00
|
|
|
};
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
void UnpackClonedMessageDataForParent(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData);
|
2015-09-02 19:20:30 +03:00
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
void UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData);
|
2013-01-24 20:24:19 +04:00
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
} // namespace ipc
|
2017-06-20 12:09:50 +03:00
|
|
|
|
|
|
|
typedef CallbackObjectHolder<mozilla::dom::MessageListener,
|
|
|
|
nsIMessageListener> MessageListenerHolder;
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2011-08-02 23:57:48 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
struct nsMessageListenerInfo
|
|
|
|
{
|
2013-11-05 15:52:04 +04:00
|
|
|
bool operator==(const nsMessageListenerInfo& aOther) const
|
|
|
|
{
|
|
|
|
return &aOther == this;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
// If mWeakListener is null then mStrongListener holds either a MessageListener or an
|
|
|
|
// nsIMessageListener. If mWeakListener is non-null then mStrongListener contains null.
|
|
|
|
mozilla::dom::MessageListenerHolder mStrongListener;
|
2013-08-08 22:36:56 +04:00
|
|
|
nsWeakPtr mWeakListener;
|
2015-02-27 08:35:26 +03:00
|
|
|
bool mListenWhenClosed;
|
2010-05-18 16:28:37 +04:00
|
|
|
};
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
inline void
|
|
|
|
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
nsMessageListenerInfo& aField,
|
|
|
|
const char* aName,
|
|
|
|
uint32_t aFlags = 0)
|
|
|
|
{
|
|
|
|
ImplCycleCollectionTraverse(aCallback, aField.mStrongListener, aName, aFlags);
|
|
|
|
ImplCycleCollectionTraverse(aCallback, aField.mWeakListener, aName, aFlags);
|
|
|
|
}
|
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:
|
2016-08-12 12:39:16 +03:00
|
|
|
SameProcessCpowHolder(JS::RootingContext* aRootingCx, JS::Handle<JSObject*> aObj)
|
|
|
|
: mObj(aRootingCx, aObj)
|
2013-11-11 12:04:41 +04:00
|
|
|
{
|
|
|
|
}
|
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)
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
class nsFrameMessageManager : public nsIContentFrameMessageManager,
|
|
|
|
public nsIMessageBroadcaster,
|
|
|
|
public nsIFrameScriptLoader,
|
|
|
|
public nsIGlobalProcessScriptLoader
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2013-10-12 03:07:15 +04:00
|
|
|
friend class mozilla::dom::MessageManagerReporter;
|
2015-09-10 23:50:58 +03:00
|
|
|
typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
|
2017-06-14 17:44:17 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
typedef mozilla::dom::ipc::MessageManagerFlags MessageManagerFlags;
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
|
2017-06-14 17:44:17 +03:00
|
|
|
MessageManagerFlags aFlags);
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
virtual ~nsFrameMessageManager();
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2014-06-25 06:09:15 +04:00
|
|
|
public:
|
2017-06-14 17:44:17 +03:00
|
|
|
explicit nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback)
|
|
|
|
: nsFrameMessageManager(aCallback, MessageManagerFlags::MM_NONE)
|
|
|
|
{}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
2015-05-01 04:20:51 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsFrameMessageManager,
|
|
|
|
nsIContentFrameMessageManager)
|
2017-06-20 12:09:50 +03:00
|
|
|
|
|
|
|
// MessageListenerManager
|
|
|
|
void AddMessageListener(const nsAString& aMessageName,
|
|
|
|
mozilla::dom::MessageListener& aListener,
|
|
|
|
bool aListenWhenClosed,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void RemoveMessageListener(const nsAString& aMessageName,
|
|
|
|
mozilla::dom::MessageListener& aListener,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void AddWeakMessageListener(const nsAString& aMessageName,
|
|
|
|
mozilla::dom::MessageListener& aListener,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void RemoveWeakMessageListener(const nsAString& aMessageName,
|
|
|
|
mozilla::dom::MessageListener& aListener,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
|
|
|
|
// MessageSender
|
|
|
|
void SendAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
JS::Handle<JS::Value> aTransfers,
|
|
|
|
mozilla::ErrorResult& aError)
|
|
|
|
{
|
|
|
|
DispatchAsyncMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, aTransfers,
|
|
|
|
aError);
|
|
|
|
}
|
|
|
|
already_AddRefed<nsIMessageSender>
|
|
|
|
GetProcessMessageManager(mozilla::ErrorResult& aError);
|
|
|
|
void GetRemoteType(nsAString& aRemoteType, mozilla::ErrorResult& aError) const;
|
|
|
|
|
|
|
|
// SyncMessageSender
|
|
|
|
void SendSyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsTArray<JS::Value>& aResult,
|
|
|
|
mozilla::ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SendMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, true, aResult, aError);
|
|
|
|
}
|
|
|
|
void SendRpcMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsTArray<JS::Value>& aResult,
|
|
|
|
mozilla::ErrorResult& aError)
|
|
|
|
{
|
|
|
|
SendMessage(aCx, aMessageName, aObj, aObjects, aPrincipal, false, aResult, aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
// GlobalProcessScriptLoader
|
|
|
|
void GetInitialProcessData(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aInitialProcessData,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
|
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
|
2015-02-20 04:12:11 +03:00
|
|
|
NS_DECL_NSIMESSAGEMANAGERGLOBAL
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_NSICONTENTFRAMEMESSAGEMANAGER
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_DECL_NSIFRAMESCRIPTLOADER
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_DECL_NSIPROCESSSCRIPTLOADER
|
2015-05-01 04:20:51 +03:00
|
|
|
NS_DECL_NSIGLOBALPROCESSSCRIPTLOADER
|
2011-08-02 23:57:48 +04:00
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
static mozilla::dom::ChromeMessageSender*
|
2015-03-06 04:03:25 +03:00
|
|
|
NewProcessMessageManager(bool aIsRemote);
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
bool aIsSync, StructuredCloneData* aCloneData,
|
2015-01-27 00:32:18 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void AddChildManager(mozilla::dom::MessageListenerManager* aManager);
|
|
|
|
void RemoveChildManager(mozilla::dom::MessageListenerManager* aManager);
|
2012-09-28 17:08:04 +04:00
|
|
|
void Disconnect(bool aRemoveFromParent = true);
|
2015-02-27 08:35:26 +03:00
|
|
|
void Close();
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-01-31 22:45:54 +04:00
|
|
|
void SetCallback(mozilla::dom::ipc::MessageManagerCallback* aCallback);
|
2016-08-22 11:28:04 +03:00
|
|
|
|
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,
|
2016-02-01 00:48:00 +03:00
|
|
|
const JS::Value& aTransfers,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
2012-09-28 09:43:12 +04:00
|
|
|
uint8_t aArgc);
|
2016-02-01 00:48:00 +03:00
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
nsresult DispatchAsyncMessageInternal(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Handle<JSObject*> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal);
|
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;
|
|
|
|
}
|
2017-06-14 17:44:17 +03:00
|
|
|
static mozilla::dom::ChildProcessMessageManager* GetChildProcessManager()
|
2010-08-31 22:58:35 +04:00
|
|
|
{
|
|
|
|
return sChildProcessManager;
|
|
|
|
}
|
2017-06-14 17:44:17 +03:00
|
|
|
static void SetChildProcessManager(mozilla::dom::ChildProcessMessageManager* aManager)
|
2015-02-20 04:12:38 +03:00
|
|
|
{
|
|
|
|
sChildProcessManager = aManager;
|
|
|
|
}
|
2015-05-01 04:20:51 +03:00
|
|
|
|
|
|
|
void SetInitialProcessData(JS::HandleValue aInitialData);
|
|
|
|
|
2015-09-08 10:31:40 +03:00
|
|
|
void LoadPendingScripts();
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
protected:
|
|
|
|
friend class MMListenerRemover;
|
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
virtual nsFrameMessageManager* GetParentManager()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual void ClearParentManager(bool aRemove)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void DispatchAsyncMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
JS::Handle<JS::Value> aTransfers,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
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);
|
2017-06-20 12:09:50 +03:00
|
|
|
void SendMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
JS::Handle<JS::Value> aObj, JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal, bool aIsSync, nsTArray<JS::Value>& aResult,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
void SendMessage(JSContext* aCx, const nsAString& aMessageName,
|
|
|
|
StructuredCloneData& aData, JS::Handle<JSObject*> aObjects,
|
|
|
|
nsIPrincipal* aPrincipal, bool aIsSync,
|
|
|
|
nsTArray<JS::Value>& aResult, mozilla::ErrorResult& aError);
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
nsresult ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
bool aTargetClosed, const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
bool aIsSync, StructuredCloneData* aCloneData,
|
2015-02-27 08:35:26 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal);
|
2015-02-27 08:35:26 +03:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void LoadScript(const nsAString& aURL, bool aAllowDelayedLoad,
|
|
|
|
bool aRunInGlobalScope, mozilla::ErrorResult& aError);
|
|
|
|
void RemoveDelayedScript(const nsAString& aURL);
|
|
|
|
nsresult GetDelayedScripts(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JS::Value> aList);
|
|
|
|
void GetDelayedScripts(JSContext* aCx, nsTArray<nsTArray<JS::Value>>& aList,
|
|
|
|
mozilla::ErrorResult& aError);
|
|
|
|
|
|
|
|
enum ProcessCheckerType {
|
|
|
|
PROCESS_CHECKER_PERMISSION,
|
|
|
|
PROCESS_CHECKER_MANIFEST_URL,
|
|
|
|
ASSERT_APP_HAS_PERMISSION
|
|
|
|
};
|
|
|
|
bool AssertProcessInternal(ProcessCheckerType aType,
|
|
|
|
const nsAString& aCapability,
|
|
|
|
mozilla::ErrorResult& aError);
|
2015-02-20 04:13:02 +03:00
|
|
|
|
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;
|
2017-06-20 12:09:50 +03:00
|
|
|
nsTArray<RefPtr<mozilla::dom::MessageListenerManager>> 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;
|
2015-02-27 08:35:26 +03:00
|
|
|
bool mClosed; // true if we can no longer send messages
|
2012-01-07 23:20:12 +04:00
|
|
|
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
|
|
|
nsTArray<nsString> mPendingScripts;
|
2013-11-24 09:32:45 +04:00
|
|
|
nsTArray<bool> mPendingScriptsGlobalStates;
|
2015-05-01 04:20:51 +03:00
|
|
|
JS::Heap<JS::Value> mInitialProcessData;
|
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;
|
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:
|
2017-06-20 12:09:50 +03:00
|
|
|
void AddMessageListener(const nsAString& aMessageName,
|
|
|
|
mozilla::dom::MessageListenerHolder&& aListener,
|
|
|
|
bool aListenWhenClosed);
|
|
|
|
void RemoveMessageListener(const nsAString& aMessageName,
|
|
|
|
const mozilla::dom::MessageListenerHolder& aListener);
|
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
static mozilla::dom::ChildProcessMessageManager* sChildProcessManager;
|
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:
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class MyAsyncMessage : public nsSameProcessAsyncMessageBase, public Runnable
|
2014-03-12 18:22:00 +04:00
|
|
|
{
|
2017-11-06 06:37:28 +03:00
|
|
|
NS_IMETHOD Run() {
|
2014-03-12 18:22:00 +04:00
|
|
|
ReceiveMessage(..., ...);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
2015-10-07 13:42:43 +03:00
|
|
|
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsSameProcessAsyncMessageBase> ev = new MyAsyncMessage();
|
2015-10-07 13:42:43 +03:00
|
|
|
nsresult rv = ev->Init(...);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
NS_DispatchToMainThread(ev);
|
|
|
|
}
|
|
|
|
*/
|
2014-03-12 18:22:00 +04:00
|
|
|
class nsSameProcessAsyncMessageBase
|
|
|
|
{
|
|
|
|
public:
|
2015-09-10 23:50:58 +03:00
|
|
|
typedef mozilla::dom::ipc::StructuredCloneData StructuredCloneData;
|
2014-03-12 18:22:00 +04:00
|
|
|
|
2016-08-12 12:39:16 +03:00
|
|
|
nsSameProcessAsyncMessageBase(JS::RootingContext* aRootingCx,
|
|
|
|
JS::Handle<JSObject*> aCpows);
|
|
|
|
nsresult Init(const nsAString& aMessage,
|
2015-10-07 13:42:43 +03:00
|
|
|
StructuredCloneData& aData,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2014-03-12 18:22:00 +04:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
void ReceiveMessage(nsISupports* aTarget, nsIFrameLoader* aTargetFrameLoader,
|
|
|
|
nsFrameMessageManager* aManager);
|
2014-03-12 18:22:00 +04:00
|
|
|
private:
|
|
|
|
nsSameProcessAsyncMessageBase(const nsSameProcessAsyncMessageBase&);
|
|
|
|
|
|
|
|
nsString mMessage;
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData mData;
|
2014-04-16 12:47:53 +04:00
|
|
|
JS::PersistentRooted<JSObject*> mCpows;
|
2014-03-12 18:22:00 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2016-08-12 12:39:16 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mCalledInit;
|
|
|
|
#endif
|
2014-03-12 18:22:00 +04:00
|
|
|
};
|
|
|
|
|
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:
|
2016-04-13 21:04:11 +03:00
|
|
|
static void PurgeCache();
|
2010-08-10 21:18:26 +04:00
|
|
|
static void Shutdown();
|
2015-02-25 01:23:53 +03:00
|
|
|
|
|
|
|
void MarkScopesForCC();
|
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();
|
2017-07-19 15:59:02 +03:00
|
|
|
void LoadScriptInternal(JS::Handle<JSObject*> aGlobal, 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);
|
2017-07-19 15:59:02 +03:00
|
|
|
bool InitChildGlobalInternal(const nsACString& aID);
|
|
|
|
virtual bool WrapGlobalObject(JSContext* aCx,
|
|
|
|
JS::CompartmentOptions& aOptions,
|
|
|
|
JS::MutableHandle<JSObject*> aReflector) = 0;
|
2016-02-10 01:08:53 +03:00
|
|
|
void Trace(const TraceCallbacks& aCallbacks, void* aClosure);
|
2017-05-15 23:05:18 +03:00
|
|
|
void Unlink();
|
2010-08-10 21:18:26 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<JS::Heap<JSObject*>, 2> mAnonymousGlobalScopes;
|
2014-06-13 21:56:38 +04:00
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
static nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* sCachedScripts;
|
2016-07-21 19:54:16 +03:00
|
|
|
static mozilla::StaticRefPtr<nsScriptCacheCleaner> sScriptCacheCleaner;
|
2010-08-17 00:40:04 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsScriptCacheCleaner 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();
|
2016-04-13 21:04:11 +03:00
|
|
|
if (obsSvc) {
|
|
|
|
obsSvc->AddObserver(this, "message-manager-flush-caches", false);
|
2011-10-17 18:59:28 +04:00
|
|
|
obsSvc->AddObserver(this, "xpcom-shutdown", false);
|
2016-04-13 21:04:11 +03:00
|
|
|
}
|
2010-08-17 00:40:04 +04:00
|
|
|
}
|
|
|
|
|
2016-08-08 03:54:47 +03:00
|
|
|
NS_IMETHOD Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const char16_t *aData) override
|
2010-08-17 00:40:04 +04:00
|
|
|
{
|
2016-04-13 21:04:11 +03:00
|
|
|
if (strcmp("message-manager-flush-caches", aTopic) == 0) {
|
|
|
|
nsMessageManagerScriptExecutor::PurgeCache();
|
|
|
|
} else if (strcmp("xpcom-shutdown", aTopic) == 0) {
|
|
|
|
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
|