2011-10-01 20:14:36 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
|
2012-12-22 15:53:38 +04:00
|
|
|
#include "AppProcessChecker.h"
|
2010-08-31 22:58:35 +04:00
|
|
|
#include "ContentChild.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "jsapi.h"
|
2014-06-13 21:56:38 +04:00
|
|
|
#include "jsfriendapi.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsJSUtils.h"
|
2012-03-09 13:48:50 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
2010-08-10 21:18:26 +04:00
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsScriptLoader.h"
|
2012-09-28 09:43:12 +04:00
|
|
|
#include "nsFrameLoader.h"
|
2010-08-31 22:58:35 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
2011-03-18 07:08:18 +03:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIConsoleService.h"
|
2014-03-05 03:39:42 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2011-05-19 18:48:17 +04:00
|
|
|
#include "nsIProtocolHandler.h"
|
2011-11-30 19:51:40 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIJSRuntimeService.h"
|
2012-08-27 18:13:02 +04:00
|
|
|
#include "nsIDOMClassInfo.h"
|
2011-11-30 19:51:40 +04:00
|
|
|
#include "xpcpublic.h"
|
2014-09-29 17:34:21 +04:00
|
|
|
#include "mozilla/CycleCollectedJSRuntime.h"
|
2015-02-20 04:12:11 +03:00
|
|
|
#include "mozilla/IntentionalCrash.h"
|
2012-06-07 06:52:14 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-11 09:44:03 +04:00
|
|
|
#include "mozilla/dom/nsIContentParent.h"
|
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2015-02-20 04:13:02 +03:00
|
|
|
#include "mozilla/dom/ProcessGlobal.h"
|
2015-03-24 23:05:39 +03:00
|
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
2014-08-15 05:47:15 +04:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2012-08-02 10:02:29 +04:00
|
|
|
#include "mozilla/dom/StructuredCloneUtils.h"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
|
|
|
#include "mozilla/dom/ipc/BlobParent.h"
|
2013-07-09 21:51:03 +04:00
|
|
|
#include "mozilla/dom/DOMStringList.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
2013-10-12 03:07:15 +04:00
|
|
|
#include "nsPrintfCString.h"
|
2014-06-11 09:44:03 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2010-08-31 22:58:35 +04:00
|
|
|
|
2014-02-12 01:01:29 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
#include <android/log.h>
|
|
|
|
#endif
|
2012-08-07 00:41:40 +04:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#include <windows.h>
|
2013-10-01 20:15:06 +04:00
|
|
|
# if defined(SendMessage)
|
|
|
|
# undef SendMessage
|
|
|
|
# endif
|
2012-08-07 00:41:40 +04:00
|
|
|
#endif
|
2011-11-10 04:27:08 +04:00
|
|
|
|
2012-06-07 06:52:14 +04:00
|
|
|
using namespace mozilla;
|
2012-08-02 10:02:29 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-09-28 09:43:12 +04:00
|
|
|
using namespace mozilla::dom::ipc;
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
CycleCollectorTraverseListeners(const nsAString& aKey,
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* aListeners,
|
2013-10-26 01:55:16 +04:00
|
|
|
void* aCb)
|
|
|
|
{
|
|
|
|
nsCycleCollectionTraversalCallback* cb =
|
|
|
|
static_cast<nsCycleCollectionTraversalCallback*> (aCb);
|
|
|
|
uint32_t count = aListeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(*cb, "listeners[i] mStrongListener");
|
2013-11-05 15:52:04 +04:00
|
|
|
cb->NoteXPCOMChild(aListeners->ElementAt(i).mStrongListener.get());
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsFrameMessageManager)
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsFrameMessageManager)
|
2013-10-26 01:55:16 +04:00
|
|
|
tmp->mListeners.EnumerateRead(CycleCollectorTraverseListeners,
|
|
|
|
static_cast<void*>(&cb));
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildManagers)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsFrameMessageManager)
|
|
|
|
tmp->mListeners.Clear();
|
2012-08-27 20:28:11 +04:00
|
|
|
for (int32_t i = tmp->mChildManagers.Count(); i > 0; --i) {
|
2010-05-18 16:28:37 +04:00
|
|
|
static_cast<nsFrameMessageManager*>(tmp->mChildManagers[i - 1])->
|
2011-10-17 18:59:28 +04:00
|
|
|
Disconnect(false);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildManagers)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsFrameMessageManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContentFrameMessageManager)
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
/* nsFrameMessageManager implements nsIMessageSender and nsIMessageBroadcaster,
|
|
|
|
* both of which descend from nsIMessageListenerManager. QI'ing to
|
|
|
|
* nsIMessageListenerManager is therefore ambiguous and needs explicit casts
|
|
|
|
* depending on which child interface applies. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIMessageListenerManager,
|
|
|
|
(mIsBroadcaster ?
|
|
|
|
static_cast<nsIMessageListenerManager*>(
|
|
|
|
static_cast<nsIMessageBroadcaster*>(this)) :
|
|
|
|
static_cast<nsIMessageListenerManager*>(
|
|
|
|
static_cast<nsIMessageSender*>(this))))
|
|
|
|
|
|
|
|
/* Message managers in child process implement nsIMessageSender and
|
|
|
|
nsISyncMessageSender. Message managers in the chrome process are
|
|
|
|
either broadcasters (if they have subordinate/child message
|
|
|
|
managers) or they're simple message senders. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsISyncMessageSender, !mChrome)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMessageSender, !mChrome || !mIsBroadcaster)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMessageBroadcaster, mChrome && mIsBroadcaster)
|
|
|
|
|
2010-08-31 22:58:35 +04:00
|
|
|
/* nsIContentFrameMessageManager is accessible only in TabChildGlobal. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIContentFrameMessageManager,
|
|
|
|
!mChrome && !mIsProcessManager)
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
/* Frame message managers (non-process message managers) support nsIFrameScriptLoader. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFrameScriptLoader,
|
2010-08-31 22:58:35 +04:00
|
|
|
mChrome && !mIsProcessManager)
|
2012-08-27 18:13:02 +04:00
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
/* Process message managers (process message managers) support nsIProcessScriptLoader. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIProcessScriptLoader,
|
|
|
|
mChrome && mIsProcessManager)
|
|
|
|
|
2012-12-22 16:00:10 +04:00
|
|
|
/* Message senders in the chrome process support nsIProcessChecker. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIProcessChecker,
|
2012-09-28 09:43:12 +04:00
|
|
|
mChrome && !mIsBroadcaster)
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(ChromeMessageBroadcaster,
|
|
|
|
mChrome && mIsBroadcaster)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO_CONDITIONAL(ChromeMessageSender,
|
|
|
|
mChrome && !mIsBroadcaster)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 14:11:31 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsFrameMessageManager)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsFrameMessageManager)
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2014-04-24 08:43:57 +04:00
|
|
|
enum ActorFlavorEnum {
|
|
|
|
Parent = 0,
|
|
|
|
Child
|
|
|
|
};
|
|
|
|
|
|
|
|
template <ActorFlavorEnum>
|
|
|
|
struct BlobTraits
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Parent>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::BlobParent BlobType;
|
|
|
|
typedef mozilla::dom::PBlobParent ProtocolType;
|
2014-06-11 09:44:03 +04:00
|
|
|
typedef mozilla::dom::nsIContentParent ConcreteContentManagerType;
|
2014-04-24 08:43:57 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct BlobTraits<Child>
|
|
|
|
{
|
|
|
|
typedef mozilla::dom::BlobChild BlobType;
|
|
|
|
typedef mozilla::dom::PBlobChild ProtocolType;
|
2014-06-11 09:44:06 +04:00
|
|
|
typedef mozilla::dom::nsIContentChild ConcreteContentManagerType;
|
2014-04-24 08:43:57 +04:00
|
|
|
};
|
|
|
|
|
2013-01-24 06:39:27 +04:00
|
|
|
template<ActorFlavorEnum>
|
|
|
|
struct DataBlobs
|
|
|
|
{ };
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct DataBlobs<Parent>
|
|
|
|
{
|
|
|
|
typedef BlobTraits<Parent>::ProtocolType ProtocolType;
|
|
|
|
|
|
|
|
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsParent();
|
|
|
|
}
|
2013-01-24 20:24:19 +04:00
|
|
|
|
|
|
|
static const InfallibleTArray<ProtocolType*>& Blobs(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsParent();
|
|
|
|
}
|
2013-01-24 06:39:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct DataBlobs<Child>
|
|
|
|
{
|
|
|
|
typedef BlobTraits<Child>::ProtocolType ProtocolType;
|
|
|
|
|
|
|
|
static InfallibleTArray<ProtocolType*>& Blobs(ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsChild();
|
|
|
|
}
|
2013-01-24 20:24:19 +04:00
|
|
|
|
|
|
|
static const InfallibleTArray<ProtocolType*>& Blobs(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return aData.blobsChild();
|
|
|
|
}
|
2013-01-24 06:39:27 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
template<ActorFlavorEnum Flavor>
|
|
|
|
static bool
|
|
|
|
BuildClonedMessageData(typename BlobTraits<Flavor>::ConcreteContentManagerType* aManager,
|
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
SerializedStructuredCloneBuffer& buffer = aClonedData.data();
|
|
|
|
buffer.data = aData.mData;
|
|
|
|
buffer.dataLength = aData.mDataLength;
|
2014-10-08 20:15:23 +04:00
|
|
|
const nsTArray<nsRefPtr<File>>& blobs = aData.mClosure.mBlobs;
|
2013-01-24 06:39:27 +04:00
|
|
|
if (!blobs.IsEmpty()) {
|
|
|
|
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
|
|
|
|
InfallibleTArray<ProtocolType*>& blobList = DataBlobs<Flavor>::Blobs(aClonedData);
|
|
|
|
uint32_t length = blobs.Length();
|
|
|
|
blobList.SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2014-04-24 08:43:57 +04:00
|
|
|
typename BlobTraits<Flavor>::BlobType* protocolActor =
|
|
|
|
aManager->GetOrCreateActorForBlob(blobs[i]);
|
2013-01-24 06:39:27 +04:00
|
|
|
if (!protocolActor) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
blobList.AppendElement(protocolActor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-06-11 09:44:03 +04:00
|
|
|
MessageManagerCallback::BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
2013-01-24 06:39:27 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Parent>(aParent, aData, aClonedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-06-11 09:44:06 +04:00
|
|
|
MessageManagerCallback::BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
2013-01-24 06:39:27 +04:00
|
|
|
const StructuredCloneData& aData,
|
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
|
|
|
return BuildClonedMessageData<Child>(aChild, aData, aClonedData);
|
|
|
|
}
|
|
|
|
|
2013-01-24 20:24:19 +04:00
|
|
|
template<ActorFlavorEnum Flavor>
|
|
|
|
static StructuredCloneData
|
|
|
|
UnpackClonedMessageData(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
const SerializedStructuredCloneBuffer& buffer = aData.data();
|
|
|
|
typedef typename BlobTraits<Flavor>::ProtocolType ProtocolType;
|
|
|
|
const InfallibleTArray<ProtocolType*>& blobs = DataBlobs<Flavor>::Blobs(aData);
|
|
|
|
StructuredCloneData cloneData;
|
|
|
|
cloneData.mData = buffer.data;
|
|
|
|
cloneData.mDataLength = buffer.dataLength;
|
|
|
|
if (!blobs.IsEmpty()) {
|
|
|
|
uint32_t length = blobs.Length();
|
|
|
|
cloneData.mClosure.mBlobs.SetCapacity(length);
|
|
|
|
for (uint32_t i = 0; i < length; ++i) {
|
2014-04-24 08:43:57 +04:00
|
|
|
auto* blob =
|
|
|
|
static_cast<typename BlobTraits<Flavor>::BlobType*>(blobs[i]);
|
2013-01-24 20:24:19 +04:00
|
|
|
MOZ_ASSERT(blob);
|
2014-10-08 20:15:22 +04:00
|
|
|
|
2014-10-08 20:15:23 +04:00
|
|
|
nsRefPtr<FileImpl> blobImpl = blob->GetBlobImpl();
|
2014-10-08 20:15:22 +04:00
|
|
|
MOZ_ASSERT(blobImpl);
|
|
|
|
|
|
|
|
// This object will be duplicated with a correct parent before being
|
|
|
|
// exposed to JS.
|
2014-10-08 20:15:23 +04:00
|
|
|
nsRefPtr<File> domBlob = new File(nullptr, blobImpl);
|
2013-01-24 20:24:19 +04:00
|
|
|
cloneData.mClosure.mBlobs.AppendElement(domBlob);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cloneData;
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredCloneData
|
|
|
|
mozilla::dom::ipc::UnpackClonedMessageDataForParent(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return UnpackClonedMessageData<Parent>(aData);
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredCloneData
|
|
|
|
mozilla::dom::ipc::UnpackClonedMessageDataForChild(const ClonedMessageData& aData)
|
|
|
|
{
|
|
|
|
return UnpackClonedMessageData<Child>(aData);
|
|
|
|
}
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
bool
|
2013-11-11 12:04:41 +04:00
|
|
|
SameProcessCpowHolder::ToObject(JSContext* aCx,
|
|
|
|
JS::MutableHandle<JSObject*> aObjp)
|
2013-07-11 02:05:39 +04:00
|
|
|
{
|
|
|
|
if (!mObj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-10-16 04:02:23 +04:00
|
|
|
aObjp.set(mObj);
|
2013-07-11 02:05:39 +04:00
|
|
|
return JS_WrapObject(aCx, aObjp);
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
// nsIMessageListenerManager
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::AddMessageListener(const nsAString& aMessage,
|
2015-02-27 08:35:26 +03:00
|
|
|
nsIMessageListener* aListener,
|
|
|
|
bool aListenWhenClosed)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
mListeners.Get(aMessage);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!listeners) {
|
2013-11-05 15:52:04 +04:00
|
|
|
listeners = new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
|
2013-10-26 01:55:16 +04:00
|
|
|
mListeners.Put(aMessage, listeners);
|
|
|
|
} else {
|
|
|
|
uint32_t len = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (listeners->ElementAt(i).mStrongListener == aListener) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
|
|
|
nsMessageListenerInfo* entry = listeners->AppendElement();
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_ENSURE_TRUE(entry, NS_ERROR_OUT_OF_MEMORY);
|
2013-08-08 22:36:56 +04:00
|
|
|
entry->mStrongListener = aListener;
|
2015-02-27 08:35:26 +03:00
|
|
|
entry->mListenWhenClosed = aListenWhenClosed;
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::RemoveMessageListener(const nsAString& aMessage,
|
2012-08-27 18:13:02 +04:00
|
|
|
nsIMessageListener* aListener)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
mListeners.Get(aMessage);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!listeners) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t len = listeners->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (listeners->ElementAt(i).mStrongListener == aListener) {
|
2013-10-26 01:55:16 +04:00
|
|
|
listeners->RemoveElementAt(i);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> mCanonical;
|
|
|
|
nsWeakPtr mWeak;
|
|
|
|
} CanonicalCheckerParams;
|
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
CanonicalChecker(const nsAString& aKey,
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* aListeners,
|
2013-10-26 01:55:16 +04:00
|
|
|
void* aParams)
|
|
|
|
{
|
|
|
|
CanonicalCheckerParams* params =
|
|
|
|
static_cast<CanonicalCheckerParams*> (aParams);
|
|
|
|
|
|
|
|
uint32_t count = aListeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (!aListeners->ElementAt(i).mWeakListener) {
|
2013-10-26 01:55:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsISupports> otherCanonical =
|
2013-11-05 15:52:04 +04:00
|
|
|
do_QueryReferent(aListeners->ElementAt(i).mWeakListener);
|
2013-10-26 01:55:16 +04:00
|
|
|
MOZ_ASSERT((params->mCanonical == otherCanonical) ==
|
2013-11-05 15:52:04 +04:00
|
|
|
(params->mWeak == aListeners->ElementAt(i).mWeakListener));
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-08 22:36:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::AddWeakMessageListener(const nsAString& aMessage,
|
|
|
|
nsIMessageListener* aListener)
|
|
|
|
{
|
|
|
|
nsWeakPtr weak = do_GetWeakReference(aListener);
|
|
|
|
NS_ENSURE_TRUE(weak, NS_ERROR_NO_INTERFACE);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// It's technically possible that one object X could give two different
|
|
|
|
// nsIWeakReference*'s when you do_GetWeakReference(X). We really don't want
|
|
|
|
// this to happen; it will break e.g. RemoveWeakMessageListener. So let's
|
|
|
|
// check that we're not getting ourselves into that situation.
|
|
|
|
nsCOMPtr<nsISupports> canonical = do_QueryInterface(aListener);
|
2013-10-26 01:55:16 +04:00
|
|
|
CanonicalCheckerParams params;
|
|
|
|
params.mCanonical = canonical;
|
|
|
|
params.mWeak = weak;
|
|
|
|
mListeners.EnumerateRead(CanonicalChecker, (void*)¶ms);
|
2013-08-08 22:36:56 +04:00
|
|
|
#endif
|
|
|
|
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
mListeners.Get(aMessage);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!listeners) {
|
2013-11-05 15:52:04 +04:00
|
|
|
listeners = new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
|
2013-10-26 01:55:16 +04:00
|
|
|
mListeners.Put(aMessage, listeners);
|
|
|
|
} else {
|
|
|
|
uint32_t len = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (listeners->ElementAt(i).mWeakListener == weak) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-08-08 22:36:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
nsMessageListenerInfo* entry = listeners->AppendElement();
|
2013-08-08 22:36:56 +04:00
|
|
|
entry->mWeakListener = weak;
|
2015-02-27 08:35:26 +03:00
|
|
|
entry->mListenWhenClosed = false;
|
2013-08-08 22:36:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::RemoveWeakMessageListener(const nsAString& aMessage,
|
|
|
|
nsIMessageListener* aListener)
|
|
|
|
{
|
|
|
|
nsWeakPtr weak = do_GetWeakReference(aListener);
|
|
|
|
NS_ENSURE_TRUE(weak, NS_OK);
|
|
|
|
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
mListeners.Get(aMessage);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!listeners) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t len = listeners->Length();
|
2013-08-08 22:36:56 +04:00
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (listeners->ElementAt(i).mWeakListener == weak) {
|
2013-10-26 01:55:16 +04:00
|
|
|
listeners->RemoveElementAt(i);
|
2013-08-08 22:36:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
// nsIFrameScriptLoader
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
2015-02-20 04:13:02 +03:00
|
|
|
nsFrameMessageManager::LoadScript(const nsAString& aURL,
|
|
|
|
bool aAllowDelayedLoad,
|
|
|
|
bool aRunInGlobalScope)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2010-06-10 13:26:19 +04:00
|
|
|
if (aAllowDelayedLoad) {
|
2014-05-23 16:52:36 +04:00
|
|
|
if (IsGlobal() || IsBroadcaster()) {
|
2010-06-10 13:26:19 +04:00
|
|
|
// Cache for future windows or frames
|
|
|
|
mPendingScripts.AppendElement(aURL);
|
2013-11-24 09:32:45 +04:00
|
|
|
mPendingScriptsGlobalStates.AppendElement(aRunInGlobalScope);
|
2012-09-28 09:43:12 +04:00
|
|
|
} else if (!mCallback) {
|
2010-06-10 13:26:19 +04:00
|
|
|
// We're frame message manager, which isn't connected yet.
|
|
|
|
mPendingScripts.AppendElement(aURL);
|
2013-11-24 09:32:45 +04:00
|
|
|
mPendingScriptsGlobalStates.AppendElement(aRunInGlobalScope);
|
2010-06-10 13:26:19 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
if (mCallback) {
|
2010-05-18 16:28:37 +04:00
|
|
|
#ifdef DEBUG_smaug
|
|
|
|
printf("Will load %s \n", NS_ConvertUTF16toUTF8(aURL).get());
|
|
|
|
#endif
|
2015-02-20 04:11:32 +03:00
|
|
|
NS_ENSURE_TRUE(mCallback->DoLoadMessageManagerScript(aURL, aRunInGlobalScope),
|
2013-11-24 09:32:45 +04:00
|
|
|
NS_ERROR_FAILURE);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-08-27 20:28:11 +04:00
|
|
|
for (int32_t i = 0; i < mChildManagers.Count(); ++i) {
|
2010-06-10 13:26:19 +04:00
|
|
|
nsRefPtr<nsFrameMessageManager> mm =
|
|
|
|
static_cast<nsFrameMessageManager*>(mChildManagers[i]);
|
2010-05-18 16:28:37 +04:00
|
|
|
if (mm) {
|
2011-10-17 18:59:28 +04:00
|
|
|
// Use false here, so that child managers don't cache the script, which
|
2010-06-10 13:26:19 +04:00
|
|
|
// is already cached in the parent.
|
2015-02-20 04:13:02 +03:00
|
|
|
mm->LoadScript(aURL, false, aRunInGlobalScope);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-24 14:16:29 +04:00
|
|
|
NS_IMETHODIMP
|
2015-02-20 04:13:02 +03:00
|
|
|
nsFrameMessageManager::RemoveDelayedScript(const nsAString& aURL)
|
2011-08-24 14:16:29 +04:00
|
|
|
{
|
2013-11-24 09:32:45 +04:00
|
|
|
for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
|
|
|
|
if (mPendingScripts[i] == aURL) {
|
|
|
|
mPendingScripts.RemoveElementAt(i);
|
|
|
|
mPendingScriptsGlobalStates.RemoveElementAt(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2011-08-24 14:16:29 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-08-09 06:36:37 +04:00
|
|
|
NS_IMETHODIMP
|
2015-02-20 04:13:02 +03:00
|
|
|
nsFrameMessageManager::GetDelayedScripts(JSContext* aCx, JS::MutableHandle<JS::Value> aList)
|
2013-08-09 06:36:37 +04:00
|
|
|
{
|
|
|
|
// Frame message managers may return an incomplete list because scripts
|
|
|
|
// that were loaded after it was connected are not added to the list.
|
2014-05-23 16:52:36 +04:00
|
|
|
if (!IsGlobal() && !IsBroadcaster()) {
|
2013-08-09 06:36:37 +04:00
|
|
|
NS_WARNING("Cannot retrieve list of pending frame scripts for frame"
|
|
|
|
"message managers as it may be incomplete");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2014-02-12 14:50:46 +04:00
|
|
|
JS::Rooted<JSObject*> array(aCx, JS_NewArrayObject(aCx, mPendingScripts.Length()));
|
2013-11-24 09:32:45 +04:00
|
|
|
NS_ENSURE_TRUE(array, NS_ERROR_OUT_OF_MEMORY);
|
2013-08-09 06:36:37 +04:00
|
|
|
|
2013-11-24 09:32:45 +04:00
|
|
|
JS::Rooted<JSString*> url(aCx);
|
|
|
|
JS::Rooted<JSObject*> pair(aCx);
|
2013-08-09 06:36:37 +04:00
|
|
|
for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
|
2013-11-24 09:32:45 +04:00
|
|
|
url = JS_NewUCStringCopyN(aCx, mPendingScripts[i].get(), mPendingScripts[i].Length());
|
|
|
|
NS_ENSURE_TRUE(url, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2014-02-12 14:50:46 +04:00
|
|
|
JS::AutoValueArray<2> pairElts(aCx);
|
|
|
|
pairElts[0].setString(url);
|
|
|
|
pairElts[1].setBoolean(mPendingScriptsGlobalStates[i]);
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2014-02-12 14:50:46 +04:00
|
|
|
pair = JS_NewArrayObject(aCx, pairElts);
|
2013-11-24 09:32:45 +04:00
|
|
|
NS_ENSURE_TRUE(pair, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2015-03-02 16:31:15 +03:00
|
|
|
NS_ENSURE_TRUE(JS_DefineElement(aCx, array, i, pair, JSPROP_ENUMERATE),
|
2013-11-24 09:32:45 +04:00
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
2013-08-09 06:36:37 +04:00
|
|
|
}
|
|
|
|
|
2014-01-09 21:39:36 +04:00
|
|
|
aList.setObject(*array);
|
2013-08-09 06:36:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2013-08-09 02:53:04 +04:00
|
|
|
static bool
|
2014-07-22 08:43:21 +04:00
|
|
|
JSONCreator(const char16_t* aBuf, uint32_t aLen, void* aData)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
nsAString* result = static_cast<nsAString*>(aData);
|
2014-01-04 19:02:17 +04:00
|
|
|
result->Append(static_cast<const char16_t*>(aBuf),
|
2012-08-22 19:56:38 +04:00
|
|
|
static_cast<uint32_t>(aLen));
|
2011-10-01 20:14:36 +04:00
|
|
|
return true;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
static bool
|
|
|
|
GetParamsForMessage(JSContext* aCx,
|
2015-03-20 06:59:00 +03:00
|
|
|
const JS::Value& aData,
|
2012-08-02 10:02:29 +04:00
|
|
|
JSAutoStructuredCloneBuffer& aBuffer,
|
|
|
|
StructuredCloneClosure& aClosure)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-03-20 06:59:00 +03:00
|
|
|
// First try to use structured clone on the whole thing.
|
|
|
|
JS::RootedValue v(aCx, aData);
|
2013-10-23 04:18:32 +04:00
|
|
|
if (WriteStructuredClone(aCx, v, aBuffer, aClosure)) {
|
2012-08-02 10:02:29 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
JS_ClearPendingException(aCx);
|
|
|
|
|
2015-03-20 06:59:00 +03:00
|
|
|
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (console) {
|
|
|
|
nsAutoString filename;
|
|
|
|
uint32_t lineno = 0;
|
|
|
|
nsJSUtils::GetCallingLocation(aCx, filename, &lineno);
|
|
|
|
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
error->Init(NS_LITERAL_STRING("Sending message that cannot be cloned. Are you trying to send an XPCOM object?"),
|
|
|
|
filename, EmptyString(),
|
|
|
|
lineno, 0, nsIScriptError::warningFlag, "chrome javascript");
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
// Not clonable, try JSON
|
|
|
|
//XXX This is ugly but currently structured cloning doesn't handle
|
|
|
|
// properly cases when interface is implemented in JS and used
|
|
|
|
// as a dictionary.
|
|
|
|
nsAutoString json;
|
2013-09-17 05:33:40 +04:00
|
|
|
NS_ENSURE_TRUE(JS_Stringify(aCx, &v, JS::NullPtr(), JS::NullHandleValue,
|
2013-05-31 01:46:48 +04:00
|
|
|
JSONCreator, &json), false);
|
2012-08-02 10:02:29 +04:00
|
|
|
NS_ENSURE_TRUE(!json.IsEmpty(), false);
|
|
|
|
|
2013-05-06 16:30:46 +04:00
|
|
|
JS::Rooted<JS::Value> val(aCx, JS::NullValue());
|
2014-07-22 08:43:21 +04:00
|
|
|
NS_ENSURE_TRUE(JS_ParseJSON(aCx, static_cast<const char16_t*>(json.get()),
|
2013-05-29 12:29:39 +04:00
|
|
|
json.Length(), &val), false);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
|
|
|
return WriteStructuredClone(aCx, val, aBuffer, aClosure);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
// nsISyncMessageSender
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
static bool sSendingSyncMessage = false;
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
2011-10-01 20:14:36 +04:00
|
|
|
nsFrameMessageManager::SendSyncMessage(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,
|
2011-10-01 20:14:36 +04:00
|
|
|
JSContext* aCx,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aArgc,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::MutableHandle<JS::Value> aRetval)
|
2013-10-01 20:15:06 +04:00
|
|
|
{
|
2013-11-06 21:21:15 +04:00
|
|
|
return SendMessage(aMessageName, aJSON, aObjects, aPrincipal, aCx, aArgc,
|
|
|
|
aRetval, true);
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::SendRpcMessage(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
|
|
|
{
|
2013-11-06 21:21:15 +04:00
|
|
|
return SendMessage(aMessageName, aJSON, aObjects, aPrincipal, aCx, aArgc,
|
|
|
|
aRetval, false);
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::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
|
|
|
{
|
2010-06-10 13:26:19 +04:00
|
|
|
NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
|
2014-05-23 16:52:36 +04:00
|
|
|
NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome");
|
2010-06-10 13:26:19 +04:00
|
|
|
NS_ASSERTION(!mParentManager, "Should not have parent manager in content!");
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-01-09 21:39:36 +04:00
|
|
|
aRetval.setUndefined();
|
2012-09-28 09:43:12 +04:00
|
|
|
NS_ENSURE_TRUE(mCallback, NS_ERROR_NOT_INITIALIZED);
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
if (sSendingSyncMessage && aIsSync) {
|
|
|
|
// No kind of blocking send should be issued on top of a sync message.
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
StructuredCloneData data;
|
|
|
|
JSAutoStructuredCloneBuffer buffer;
|
|
|
|
if (aArgc >= 2 &&
|
2013-07-11 02:05:39 +04:00
|
|
|
!GetParamsForMessage(aCx, aJSON, buffer, data.mClosure)) {
|
2012-09-28 09:43:12 +04:00
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
|
|
|
data.mData = buffer.data();
|
|
|
|
data.mDataLength = buffer.nbytes();
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> objects(aCx);
|
2013-07-11 02:05:39 +04:00
|
|
|
if (aArgc >= 3 && aObjects.isObject()) {
|
|
|
|
objects = &aObjects.toObject();
|
|
|
|
}
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
InfallibleTArray<nsString> retval;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
sSendingSyncMessage |= aIsSync;
|
2013-11-06 21:21:15 +04:00
|
|
|
bool rv = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, objects,
|
|
|
|
aPrincipal, &retval, aIsSync);
|
2013-10-01 20:15:06 +04:00
|
|
|
if (aIsSync) {
|
|
|
|
sSendingSyncMessage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rv) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t len = retval.Length();
|
2014-02-12 14:50:46 +04:00
|
|
|
JS::Rooted<JSObject*> dataArray(aCx, JS_NewArrayObject(aCx, len));
|
2013-10-01 20:15:06 +04:00
|
|
|
NS_ENSURE_TRUE(dataArray, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
if (retval[i].IsEmpty()) {
|
|
|
|
continue;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
JS::Rooted<JS::Value> ret(aCx);
|
2014-07-22 08:43:21 +04:00
|
|
|
if (!JS_ParseJSON(aCx, static_cast<const char16_t*>(retval[i].get()),
|
2013-10-01 20:15:06 +04:00
|
|
|
retval[i].Length(), &ret)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-03-02 16:31:15 +03:00
|
|
|
NS_ENSURE_TRUE(JS_DefineElement(aCx, dataArray, i, ret, JSPROP_ENUMERATE),
|
2013-10-01 20:15:06 +04:00
|
|
|
NS_ERROR_OUT_OF_MEMORY);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2013-10-01 20:15:06 +04:00
|
|
|
|
2014-01-09 21:39:36 +04:00
|
|
|
aRetval.setObject(*dataArray);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-07-11 02:05:39 +04:00
|
|
|
nsFrameMessageManager::DispatchAsyncMessageInternal(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2012-09-28 09:43:12 +04:00
|
|
|
if (mIsBroadcaster) {
|
2012-08-27 20:28:11 +04:00
|
|
|
int32_t len = mChildManagers.Count();
|
|
|
|
for (int32_t i = 0; i < len; ++i) {
|
2012-08-27 18:13:02 +04:00
|
|
|
static_cast<nsFrameMessageManager*>(mChildManagers[i])->
|
2013-11-06 21:21:15 +04:00
|
|
|
DispatchAsyncMessageInternal(aCx, aMessage, aData, aCpows, aPrincipal);
|
2012-08-27 18:13:02 +04:00
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(mCallback, NS_ERROR_NOT_INITIALIZED);
|
2013-11-06 21:21:15 +04:00
|
|
|
if (!mCallback->DoSendAsyncMessage(aCx, aMessage, aData, aCpows, aPrincipal)) {
|
2012-09-28 09:43:12 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::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)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2012-08-02 10:02:29 +04:00
|
|
|
StructuredCloneData data;
|
|
|
|
JSAutoStructuredCloneBuffer buffer;
|
|
|
|
|
|
|
|
if (aArgc >= 2 &&
|
2013-07-11 02:05:39 +04:00
|
|
|
!GetParamsForMessage(aCx, aJSON, buffer, data.mClosure)) {
|
2012-08-02 10:02:29 +04:00
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
2011-10-01 20:14:36 +04:00
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2013-11-11 12:04:41 +04:00
|
|
|
JS::Rooted<JSObject*> objects(aCx);
|
2013-07-11 02:05:39 +04:00
|
|
|
if (aArgc >= 3 && aObjects.isObject()) {
|
|
|
|
objects = &aObjects.toObject();
|
|
|
|
}
|
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
data.mData = buffer.data();
|
|
|
|
data.mDataLength = buffer.nbytes();
|
|
|
|
|
2013-11-06 21:21:15 +04:00
|
|
|
return DispatchAsyncMessageInternal(aCx, aMessageName, data, objects,
|
|
|
|
aPrincipal);
|
2012-08-27 18:13:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIMessageSender
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::SendAsyncMessage(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,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc)
|
|
|
|
{
|
2013-11-06 21:21:15 +04:00
|
|
|
return DispatchAsyncMessage(aMessageName, aJSON, aObjects, aPrincipal, aCx,
|
|
|
|
aArgc);
|
2012-08-27 18:13:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIMessageBroadcaster
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::BroadcastAsyncMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aJSON,
|
|
|
|
JS::Handle<JS::Value> aObjects,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc)
|
|
|
|
{
|
2013-11-06 21:21:15 +04:00
|
|
|
return DispatchAsyncMessage(aMessageName, aJSON, aObjects, nullptr, aCx,
|
|
|
|
aArgc);
|
2012-08-27 18:13:02 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::GetChildCount(uint32_t* aChildCount)
|
|
|
|
{
|
2014-02-13 11:38:36 +04:00
|
|
|
*aChildCount = static_cast<uint32_t>(mChildManagers.Count());
|
2012-08-27 18:13:02 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-02-13 11:38:36 +04:00
|
|
|
nsFrameMessageManager::GetChildAt(uint32_t aIndex,
|
2012-08-27 18:13:02 +04:00
|
|
|
nsIMessageListenerManager** aMM)
|
|
|
|
{
|
|
|
|
*aMM = nullptr;
|
|
|
|
nsCOMPtr<nsIMessageListenerManager> mm =
|
|
|
|
do_QueryInterface(mChildManagers.SafeObjectAt(static_cast<uint32_t>(aIndex)));
|
|
|
|
mm.swap(*aMM);
|
|
|
|
return NS_OK;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
// nsIContentFrameMessageManager
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::Dump(const nsAString& aStr)
|
|
|
|
{
|
2014-02-12 01:01:29 +04:00
|
|
|
#ifdef ANDROID
|
|
|
|
__android_log_print(ANDROID_LOG_INFO, "Gecko", "%s", NS_ConvertUTF16toUTF8(aStr).get());
|
|
|
|
#endif
|
|
|
|
#ifdef XP_WIN
|
|
|
|
if (IsDebuggerPresent()) {
|
|
|
|
OutputDebugStringW(PromiseFlatString(aStr).get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(aStr).get(), stdout);
|
|
|
|
fflush(stdout);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-24 16:58:21 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::PrivateNoteIntentionalCrash()
|
|
|
|
{
|
2015-02-20 04:12:11 +03:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Content) {
|
|
|
|
mozilla::NoteIntentionalCrash("tab");
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2010-11-24 16:58:21 +03:00
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::GetContent(nsIDOMWindow** aContent)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aContent = nullptr;
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::GetDocShell(nsIDocShell** aDocShell)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aDocShell = nullptr;
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-25 13:52:00 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::Btoa(const nsAString& aBinaryData,
|
|
|
|
nsAString& aAsciiBase64String)
|
|
|
|
{
|
2015-02-20 04:12:11 +03:00
|
|
|
return nsContentUtils::Btoa(aBinaryData, aAsciiBase64String);
|
2011-06-25 13:52:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::Atob(const nsAString& aAsciiString,
|
|
|
|
nsAString& aBinaryData)
|
|
|
|
{
|
2015-02-20 04:12:11 +03:00
|
|
|
return nsContentUtils::Atob(aAsciiString, aBinaryData);
|
2011-06-25 13:52:00 +04:00
|
|
|
}
|
|
|
|
|
2012-12-22 16:00:10 +04:00
|
|
|
// nsIProcessChecker
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-08-12 16:59:47 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::KillChild(bool *aValid)
|
|
|
|
{
|
|
|
|
if (!mCallback) {
|
|
|
|
*aValid = false;
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aValid = mCallback->KillChild();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-22 16:00:10 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::AssertProcessInternal(ProcessCheckerType aType,
|
|
|
|
const nsAString& aCapability,
|
|
|
|
bool* aValid)
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2012-12-22 16:00:10 +04:00
|
|
|
*aValid = false;
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
// This API is only supported for message senders in the chrome process.
|
|
|
|
if (!mChrome || mIsBroadcaster) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
if (!mCallback) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2012-12-22 16:00:10 +04:00
|
|
|
switch (aType) {
|
|
|
|
case PROCESS_CHECKER_PERMISSION:
|
|
|
|
*aValid = mCallback->CheckPermission(aCapability);
|
|
|
|
break;
|
|
|
|
case PROCESS_CHECKER_MANIFEST_URL:
|
|
|
|
*aValid = mCallback->CheckManifestURL(aCapability);
|
|
|
|
break;
|
2013-01-14 14:08:55 +04:00
|
|
|
case ASSERT_APP_HAS_PERMISSION:
|
|
|
|
*aValid = mCallback->CheckAppHasPermission(aCapability);
|
|
|
|
break;
|
2012-12-22 16:00:10 +04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-27 18:13:02 +04:00
|
|
|
|
2012-12-22 16:00:10 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::AssertPermission(const nsAString& aPermission,
|
|
|
|
bool* aHasPermission)
|
|
|
|
{
|
|
|
|
return AssertProcessInternal(PROCESS_CHECKER_PERMISSION,
|
|
|
|
aPermission,
|
|
|
|
aHasPermission);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::AssertContainApp(const nsAString& aManifestURL,
|
|
|
|
bool* aHasManifestURL)
|
|
|
|
{
|
|
|
|
return AssertProcessInternal(PROCESS_CHECKER_MANIFEST_URL,
|
|
|
|
aManifestURL,
|
|
|
|
aHasManifestURL);
|
|
|
|
}
|
|
|
|
|
2013-01-14 14:08:55 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::AssertAppHasPermission(const nsAString& aPermission,
|
|
|
|
bool* aHasPermission)
|
|
|
|
{
|
|
|
|
return AssertProcessInternal(ASSERT_APP_HAS_PERMISSION,
|
|
|
|
aPermission,
|
|
|
|
aHasPermission);
|
|
|
|
}
|
|
|
|
|
2013-06-29 14:52:16 +04:00
|
|
|
NS_IMETHODIMP
|
2013-12-06 03:12:23 +04:00
|
|
|
nsFrameMessageManager::AssertAppHasStatus(unsigned short aStatus,
|
|
|
|
bool* aHasStatus)
|
2013-06-29 14:52:16 +04:00
|
|
|
{
|
|
|
|
*aHasStatus = false;
|
|
|
|
|
|
|
|
// This API is only supported for message senders in the chrome process.
|
|
|
|
if (!mChrome || mIsBroadcaster) {
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
if (!mCallback) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
*aHasStatus = mCallback->CheckAppHasStatus(aStatus);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-07 23:20:12 +04:00
|
|
|
class MMListenerRemover
|
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit MMListenerRemover(nsFrameMessageManager* aMM)
|
2012-02-21 13:34:01 +04:00
|
|
|
: mWasHandlingMessage(aMM->mHandlingMessage)
|
|
|
|
, mMM(aMM)
|
2012-01-07 23:20:12 +04:00
|
|
|
{
|
|
|
|
mMM->mHandlingMessage = true;
|
|
|
|
}
|
|
|
|
~MMListenerRemover()
|
|
|
|
{
|
|
|
|
if (!mWasHandlingMessage) {
|
|
|
|
mMM->mHandlingMessage = false;
|
|
|
|
if (mMM->mDisconnected) {
|
|
|
|
mMM->mListeners.Clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mWasHandlingMessage;
|
|
|
|
nsRefPtr<nsFrameMessageManager> mMM;
|
|
|
|
};
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
// nsIMessageListener
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
|
|
|
const nsAString& aMessage,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync,
|
2012-08-02 10:02:29 +04:00
|
|
|
const StructuredCloneData* aCloneData,
|
2015-01-27 00:32:18 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-06-30 19:00:18 +04:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal)
|
2015-02-27 08:35:26 +03:00
|
|
|
{
|
|
|
|
return ReceiveMessage(aTarget, mClosed, aMessage, aIsSync,
|
|
|
|
aCloneData, aCpows, aPrincipal, aJSONRetVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
|
|
|
bool aTargetClosed,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
bool aIsSync,
|
|
|
|
const StructuredCloneData* aCloneData,
|
|
|
|
mozilla::jsipc::CpowHolder* aCpows,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
InfallibleTArray<nsString>* aJSONRetVal)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
mListeners.Get(aMessage);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (listeners) {
|
2013-08-08 22:36:56 +04:00
|
|
|
|
2012-01-07 23:20:12 +04:00
|
|
|
MMListenerRemover lr(this);
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>::EndLimitedIterator
|
|
|
|
iter(*listeners);
|
|
|
|
while(iter.HasMore()) {
|
|
|
|
nsMessageListenerInfo& listener = iter.GetNext();
|
2013-08-08 22:36:56 +04:00
|
|
|
// Remove mListeners[i] if it's an expired weak listener.
|
2013-09-25 23:08:04 +04:00
|
|
|
nsCOMPtr<nsISupports> weakListener;
|
2013-11-05 15:52:04 +04:00
|
|
|
if (listener.mWeakListener) {
|
|
|
|
weakListener = do_QueryReferent(listener.mWeakListener);
|
2013-08-08 22:36:56 +04:00
|
|
|
if (!weakListener) {
|
2013-11-05 15:52:04 +04:00
|
|
|
listeners->RemoveElement(listener);
|
2013-08-08 22:36:56 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
if (!listener.mListenWhenClosed && aTargetClosed) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS;
|
|
|
|
if (weakListener) {
|
|
|
|
wrappedJS = do_QueryInterface(weakListener);
|
|
|
|
} else {
|
2013-11-05 15:52:04 +04:00
|
|
|
wrappedJS = do_QueryInterface(listener.mStrongListener);
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!wrappedJS) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-15 16:17:32 +04:00
|
|
|
|
|
|
|
if (!wrappedJS->GetJSObject()) {
|
2013-10-26 01:55:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-15 16:17:32 +04:00
|
|
|
|
|
|
|
// Note - The ergonomics here will get a lot better with bug 971673:
|
|
|
|
//
|
|
|
|
// AutoEntryScript aes;
|
|
|
|
// if (!aes.Init(wrappedJS->GetJSObject())) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// JSContext* cx = aes.cx();
|
|
|
|
nsIGlobalObject* nativeGlobal =
|
2014-09-21 23:31:53 +04:00
|
|
|
xpc::NativeGlobal(js::GetGlobalForObjectCrossCompartment(wrappedJS->GetJSObject()));
|
2015-04-09 04:23:48 +03:00
|
|
|
AutoEntryScript aes(nativeGlobal, "message manager handler");
|
2014-11-13 03:48:51 +03:00
|
|
|
aes.TakeOwnershipOfErrorReporting();
|
2014-09-15 16:17:32 +04:00
|
|
|
JSContext* cx = aes.cx();
|
|
|
|
JS::Rooted<JSObject*> object(cx, wrappedJS->GetJSObject());
|
2013-10-26 01:55:16 +04:00
|
|
|
|
|
|
|
// The parameter for the listener function.
|
2015-01-24 18:38:08 +03:00
|
|
|
JS::Rooted<JSObject*> param(cx, JS_NewPlainObject(cx));
|
2013-10-26 01:55:16 +04:00
|
|
|
NS_ENSURE_TRUE(param, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> targetv(cx);
|
2014-04-10 08:58:41 +04:00
|
|
|
js::AssertSameCompartment(cx, object);
|
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, aTarget, &targetv);
|
2014-01-06 23:54:43 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JSObject*> cpows(cx);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (aCpows) {
|
2014-01-16 23:43:29 +04:00
|
|
|
if (!aCpows->ToObject(cx, &cpows)) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!cpows) {
|
2015-01-24 18:38:08 +03:00
|
|
|
cpows = JS_NewPlainObject(cx);
|
2013-07-11 02:05:39 +04:00
|
|
|
if (!cpows) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2013-07-11 02:05:39 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> cpowsv(cx, JS::ObjectValue(*cpows));
|
2011-06-23 20:46:38 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> json(cx, JS::NullValue());
|
2013-10-26 01:55:16 +04:00
|
|
|
if (aCloneData && aCloneData->mDataLength &&
|
2014-01-16 23:43:29 +04:00
|
|
|
!ReadStructuredClone(cx, *aCloneData, &json)) {
|
|
|
|
JS_ClearPendingException(cx);
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JSString*> jsMessage(cx,
|
|
|
|
JS_NewUCStringCopyN(cx,
|
2014-07-22 08:43:21 +04:00
|
|
|
static_cast<const char16_t*>(aMessage.BeginReading()),
|
2013-10-26 01:55:16 +04:00
|
|
|
aMessage.Length()));
|
|
|
|
NS_ENSURE_TRUE(jsMessage, NS_ERROR_OUT_OF_MEMORY);
|
2014-01-22 06:11:17 +04:00
|
|
|
JS::Rooted<JS::Value> syncv(cx, JS::BooleanValue(aIsSync));
|
2014-11-13 03:59:20 +03:00
|
|
|
bool ok = JS_DefineProperty(cx, param, "target", targetv, JSPROP_ENUMERATE) &&
|
|
|
|
JS_DefineProperty(cx, param, "name", jsMessage, JSPROP_ENUMERATE) &&
|
|
|
|
JS_DefineProperty(cx, param, "sync", syncv, JSPROP_ENUMERATE) &&
|
|
|
|
JS_DefineProperty(cx, param, "json", json, JSPROP_ENUMERATE) && // deprecated
|
|
|
|
JS_DefineProperty(cx, param, "data", json, JSPROP_ENUMERATE) &&
|
|
|
|
JS_DefineProperty(cx, param, "objects", cpowsv, JSPROP_ENUMERATE);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2013-11-06 21:21:15 +04:00
|
|
|
// message.principal == null
|
|
|
|
if (!aPrincipal) {
|
2014-11-13 03:59:20 +03:00
|
|
|
bool ok = JS_DefineProperty(cx, param, "principal",
|
|
|
|
JS::UndefinedHandleValue, JSPROP_ENUMERATE);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
|
2013-11-06 21:21:15 +04:00
|
|
|
}
|
|
|
|
|
2014-08-05 14:54:00 +04:00
|
|
|
// message.principal = the principal
|
2013-11-06 21:21:15 +04:00
|
|
|
else {
|
2014-08-05 14:54:00 +04:00
|
|
|
JS::Rooted<JS::Value> principalValue(cx);
|
2014-11-13 03:59:20 +03:00
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, aPrincipal,
|
|
|
|
&NS_GET_IID(nsIPrincipal),
|
|
|
|
&principalValue);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
bool ok = JS_DefineProperty(cx, param, "principal", principalValue,
|
|
|
|
JSPROP_ENUMERATE);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
|
2013-11-06 21:21:15 +04:00
|
|
|
}
|
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> thisValue(cx, JS::UndefinedValue());
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> funval(cx);
|
2014-09-25 15:13:28 +04:00
|
|
|
if (JS::IsCallable(object)) {
|
2013-10-26 01:55:16 +04:00
|
|
|
// If the listener is a JS function:
|
|
|
|
funval.setObject(*object);
|
|
|
|
|
|
|
|
// A small hack to get 'this' value right on content side where
|
|
|
|
// messageManager is wrapped in TabChildGlobal.
|
|
|
|
nsCOMPtr<nsISupports> defaultThisValue;
|
|
|
|
if (mChrome) {
|
|
|
|
defaultThisValue = do_QueryObject(this);
|
2010-05-18 16:28:37 +04:00
|
|
|
} else {
|
2013-10-26 01:55:16 +04:00
|
|
|
defaultThisValue = aTarget;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2014-04-10 08:58:41 +04:00
|
|
|
js::AssertSameCompartment(cx, object);
|
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, defaultThisValue, &thisValue);
|
2014-01-06 23:54:43 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-10-26 01:55:16 +04:00
|
|
|
} else {
|
|
|
|
// If the listener is a JS object which has receiveMessage function:
|
2014-01-16 23:43:29 +04:00
|
|
|
if (!JS_GetProperty(cx, object, "receiveMessage", &funval) ||
|
2014-11-13 03:59:20 +03:00
|
|
|
!funval.isObject()) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2014-11-13 03:59:20 +03:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
|
|
|
// Check if the object is even callable.
|
2014-09-25 15:13:28 +04:00
|
|
|
NS_ENSURE_STATE(JS::IsCallable(&funval.toObject()));
|
2013-10-26 01:55:16 +04:00
|
|
|
thisValue.setObject(*object);
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-01-14 10:59:06 +03:00
|
|
|
JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JS::Value> argv(cx, JS::ObjectValue(*param));
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
{
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JSObject*> thisObject(cx, thisValue.toObjectOrNull());
|
2010-10-11 02:46:16 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JSAutoCompartment tac(cx, thisObject);
|
|
|
|
if (!JS_WrapValue(cx, &argv)) {
|
2013-10-26 01:55:16 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2010-10-11 02:46:16 +04:00
|
|
|
|
2014-11-13 03:48:51 +03:00
|
|
|
if (!JS_CallFunctionValue(cx, thisObject, funval,
|
|
|
|
JS::HandleValueArray(argv), &rval)) {
|
2014-01-16 23:43:34 +04:00
|
|
|
continue;
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
if (aJSONRetVal) {
|
|
|
|
nsString json;
|
2014-01-16 23:43:34 +04:00
|
|
|
if (!JS_Stringify(cx, &rval, JS::NullPtr(), JS::NullHandleValue,
|
2013-10-26 01:55:16 +04:00
|
|
|
JSONCreator, &json)) {
|
2014-01-16 23:43:34 +04:00
|
|
|
continue;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2014-01-16 23:43:34 +04:00
|
|
|
aJSONRetVal->AppendElement(json);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 22:21:08 +04:00
|
|
|
nsRefPtr<nsFrameMessageManager> kungfuDeathGrip = mParentManager;
|
2015-02-27 08:35:26 +03:00
|
|
|
return mParentManager ? mParentManager->ReceiveMessage(aTarget, aTargetClosed, aMessage,
|
2013-10-01 20:15:06 +04:00
|
|
|
aIsSync, aCloneData,
|
2013-11-06 21:21:15 +04:00
|
|
|
aCpows, aPrincipal,
|
2013-06-30 19:00:19 +04:00
|
|
|
aJSONRetVal) : NS_OK;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-31 22:45:54 +04:00
|
|
|
nsFrameMessageManager::AddChildManager(nsFrameMessageManager* aManager)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
mChildManagers.AppendObject(aManager);
|
2014-01-31 22:45:54 +04:00
|
|
|
|
|
|
|
nsRefPtr<nsFrameMessageManager> kungfuDeathGrip = this;
|
|
|
|
nsRefPtr<nsFrameMessageManager> kungfuDeathGrip2 = aManager;
|
2014-05-23 16:52:36 +04:00
|
|
|
|
|
|
|
LoadPendingScripts(this, aManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameMessageManager::LoadPendingScripts(nsFrameMessageManager* aManager,
|
|
|
|
nsFrameMessageManager* aChildMM)
|
|
|
|
{
|
|
|
|
// We have parent manager if we're a message broadcaster.
|
|
|
|
// In that case we want to load the pending scripts from all parent
|
|
|
|
// message managers in the hierarchy. Process the parent first so
|
|
|
|
// that pending scripts higher up in the hierarchy are loaded before others.
|
|
|
|
if (aManager->mParentManager) {
|
|
|
|
LoadPendingScripts(aManager->mParentManager, aChildMM);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2014-05-23 16:52:36 +04:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aManager->mPendingScripts.Length(); ++i) {
|
|
|
|
aChildMM->LoadFrameScript(aManager->mPendingScripts[i],
|
|
|
|
false,
|
|
|
|
aManager->mPendingScriptsGlobalStates[i]);
|
2014-01-31 22:45:54 +04:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-01-31 22:45:54 +04:00
|
|
|
nsFrameMessageManager::SetCallback(MessageManagerCallback* aCallback)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2014-01-31 22:45:54 +04:00
|
|
|
MOZ_ASSERT(!mIsBroadcaster || !mCallback,
|
|
|
|
"Broadcasters cannot have callbacks!");
|
2012-09-28 09:43:12 +04:00
|
|
|
if (aCallback && mCallback != aCallback) {
|
|
|
|
mCallback = aCallback;
|
|
|
|
if (mOwnsCallback) {
|
|
|
|
mOwnedCallback = aCallback;
|
|
|
|
}
|
2014-01-31 22:45:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsFrameMessageManager::InitWithCallback(MessageManagerCallback* aCallback)
|
|
|
|
{
|
|
|
|
if (mCallback) {
|
|
|
|
// Initialization should only happen once.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCallback(aCallback);
|
|
|
|
|
2014-05-23 16:52:36 +04:00
|
|
|
// First load parent scripts by adding this to parent manager.
|
2014-01-31 22:45:54 +04:00
|
|
|
if (mParentManager) {
|
|
|
|
mParentManager->AddChildManager(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
|
|
|
|
LoadFrameScript(mPendingScripts[i], false, mPendingScriptsGlobalStates[i]);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-07 23:20:26 +04:00
|
|
|
void
|
|
|
|
nsFrameMessageManager::RemoveFromParent()
|
|
|
|
{
|
|
|
|
if (mParentManager) {
|
|
|
|
mParentManager->RemoveChildManager(this);
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mParentManager = nullptr;
|
2012-09-28 09:43:12 +04:00
|
|
|
mCallback = nullptr;
|
|
|
|
mOwnedCallback = nullptr;
|
2012-01-07 23:20:26 +04:00
|
|
|
}
|
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
void
|
|
|
|
nsFrameMessageManager::Close()
|
|
|
|
{
|
|
|
|
if (!mClosed) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(NS_ISUPPORTS_CAST(nsIContentFrameMessageManager*, this),
|
|
|
|
"message-manager-close", nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mClosed = true;
|
|
|
|
mCallback = nullptr;
|
|
|
|
mOwnedCallback = nullptr;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsFrameMessageManager::Disconnect(bool aRemoveFromParent)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-02-27 08:35:26 +03:00
|
|
|
// Notify message-manager-close if we haven't already.
|
|
|
|
Close();
|
|
|
|
|
2013-07-01 17:46:53 +04:00
|
|
|
if (!mDisconnected) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
|
|
|
obs->NotifyObservers(NS_ISUPPORTS_CAST(nsIContentFrameMessageManager*, this),
|
|
|
|
"message-manager-disconnect", nullptr);
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
if (mParentManager && aRemoveFromParent) {
|
|
|
|
mParentManager->RemoveChildManager(this);
|
|
|
|
}
|
2012-01-07 23:20:12 +04:00
|
|
|
mDisconnected = true;
|
2012-07-30 18:20:58 +04:00
|
|
|
mParentManager = nullptr;
|
2012-01-07 23:20:12 +04:00
|
|
|
if (!mHandlingMessage) {
|
|
|
|
mListeners.Clear();
|
|
|
|
}
|
2010-06-10 13:26:19 +04:00
|
|
|
}
|
|
|
|
|
2013-10-12 03:07:15 +04:00
|
|
|
namespace {
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
struct MessageManagerReferentCount
|
|
|
|
{
|
|
|
|
MessageManagerReferentCount() : mStrong(0), mWeakAlive(0), mWeakDead(0) {}
|
|
|
|
size_t mStrong;
|
|
|
|
size_t mWeakAlive;
|
|
|
|
size_t mWeakDead;
|
|
|
|
nsTArray<nsString> mSuspectMessages;
|
|
|
|
nsDataHashtable<nsStringHashKey, uint32_t> mMessageCounter;
|
2013-10-12 03:07:15 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class MessageManagerReporter final : public nsIMemoryReporter
|
2013-10-12 03:07:15 +04:00
|
|
|
{
|
2014-06-25 06:09:15 +04:00
|
|
|
~MessageManagerReporter() {}
|
|
|
|
|
2013-10-12 03:07:15 +04:00
|
|
|
public:
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2013-10-12 03:07:15 +04:00
|
|
|
static const size_t kSuspectReferentCount = 300;
|
2013-10-26 01:55:16 +04:00
|
|
|
protected:
|
2013-10-12 03:07:15 +04:00
|
|
|
void CountReferents(nsFrameMessageManager* aMessageManager,
|
|
|
|
MessageManagerReferentCount* aReferentCount);
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(MessageManagerReporter, nsIMemoryReporter)
|
2013-12-08 09:39:47 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
CollectMessageListenerData(const nsAString& aKey,
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* aListeners,
|
2013-10-26 01:55:16 +04:00
|
|
|
void* aData)
|
2013-10-12 03:07:15 +04:00
|
|
|
{
|
2013-10-26 01:55:16 +04:00
|
|
|
MessageManagerReferentCount* referentCount =
|
|
|
|
static_cast<MessageManagerReferentCount*>(aData);
|
2013-10-12 03:07:15 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
uint32_t listenerCount = aListeners->Length();
|
|
|
|
if (!listenerCount) {
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString key(aKey);
|
|
|
|
uint32_t oldCount = 0;
|
|
|
|
referentCount->mMessageCounter.Get(key, &oldCount);
|
|
|
|
uint32_t currentCount = oldCount + listenerCount;
|
|
|
|
referentCount->mMessageCounter.Put(key, currentCount);
|
|
|
|
|
|
|
|
// Keep track of messages that have a suspiciously large
|
|
|
|
// number of referents (symptom of leak).
|
|
|
|
if (currentCount == MessageManagerReporter::kSuspectReferentCount) {
|
|
|
|
referentCount->mSuspectMessages.AppendElement(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < listenerCount; ++i) {
|
2013-11-05 15:52:04 +04:00
|
|
|
const nsMessageListenerInfo& listenerInfo =
|
|
|
|
aListeners->ElementAt(i);
|
2013-10-12 03:07:15 +04:00
|
|
|
if (listenerInfo.mWeakListener) {
|
|
|
|
nsCOMPtr<nsISupports> referent =
|
|
|
|
do_QueryReferent(listenerInfo.mWeakListener);
|
|
|
|
if (referent) {
|
2013-10-26 01:55:16 +04:00
|
|
|
referentCount->mWeakAlive++;
|
2013-10-12 03:07:15 +04:00
|
|
|
} else {
|
2013-10-26 01:55:16 +04:00
|
|
|
referentCount->mWeakDead++;
|
2013-10-12 03:07:15 +04:00
|
|
|
}
|
|
|
|
} else {
|
2013-10-26 01:55:16 +04:00
|
|
|
referentCount->mStrong++;
|
2013-10-12 03:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MessageManagerReporter::CountReferents(nsFrameMessageManager* aMessageManager,
|
|
|
|
MessageManagerReferentCount* aReferentCount)
|
|
|
|
{
|
|
|
|
aMessageManager->mListeners.EnumerateRead(CollectMessageListenerData,
|
|
|
|
aReferentCount);
|
2013-10-12 03:07:15 +04:00
|
|
|
|
|
|
|
// Add referent count in child managers because the listeners
|
|
|
|
// participate in messages dispatched from parent message manager.
|
2013-10-26 01:55:16 +04:00
|
|
|
for (uint32_t i = 0; i < aMessageManager->mChildManagers.Length(); ++i) {
|
2013-10-12 03:07:15 +04:00
|
|
|
nsRefPtr<nsFrameMessageManager> mm =
|
|
|
|
static_cast<nsFrameMessageManager*>(aMessageManager->mChildManagers[i]);
|
|
|
|
CountReferents(mm, aReferentCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
ReportReferentCount(const char* aManagerType,
|
|
|
|
const MessageManagerReferentCount& aReferentCount,
|
|
|
|
nsIMemoryReporterCallback* aCb,
|
|
|
|
nsISupports* aClosure)
|
|
|
|
{
|
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
nsresult rv; \
|
|
|
|
rv = aCb->Callback(EmptyCString(), _path, \
|
|
|
|
nsIMemoryReporter::KIND_OTHER, \
|
|
|
|
nsIMemoryReporter::UNITS_COUNT, _amount, \
|
|
|
|
_desc, aClosure); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
REPORT(nsPrintfCString("message-manager/referent/%s/strong", aManagerType),
|
2013-10-26 01:55:16 +04:00
|
|
|
aReferentCount.mStrong,
|
2013-10-12 03:07:15 +04:00
|
|
|
nsPrintfCString("The number of strong referents held by the message "
|
|
|
|
"manager in the %s manager.", aManagerType));
|
|
|
|
REPORT(nsPrintfCString("message-manager/referent/%s/weak/alive", aManagerType),
|
2013-10-26 01:55:16 +04:00
|
|
|
aReferentCount.mWeakAlive,
|
2013-10-12 03:07:15 +04:00
|
|
|
nsPrintfCString("The number of weak referents that are still alive "
|
|
|
|
"held by the message manager in the %s manager.",
|
|
|
|
aManagerType));
|
|
|
|
REPORT(nsPrintfCString("message-manager/referent/%s/weak/dead", aManagerType),
|
2013-10-26 01:55:16 +04:00
|
|
|
aReferentCount.mWeakDead,
|
2013-10-12 03:07:15 +04:00
|
|
|
nsPrintfCString("The number of weak referents that are dead "
|
|
|
|
"held by the message manager in the %s manager.",
|
|
|
|
aManagerType));
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
for (uint32_t i = 0; i < aReferentCount.mSuspectMessages.Length(); i++) {
|
2013-10-12 03:07:15 +04:00
|
|
|
uint32_t totalReferentCount = 0;
|
2013-10-26 01:55:16 +04:00
|
|
|
aReferentCount.mMessageCounter.Get(aReferentCount.mSuspectMessages[i],
|
|
|
|
&totalReferentCount);
|
|
|
|
NS_ConvertUTF16toUTF8 suspect(aReferentCount.mSuspectMessages[i]);
|
2013-10-12 03:07:15 +04:00
|
|
|
REPORT(nsPrintfCString("message-manager-suspect/%s/referent(message=%s)",
|
|
|
|
aManagerType, suspect.get()), totalReferentCount,
|
|
|
|
nsPrintfCString("A message in the %s message manager with a "
|
|
|
|
"suspiciously large number of referents (symptom "
|
|
|
|
"of a leak).", aManagerType));
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef REPORT
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MessageManagerReporter::CollectReports(nsIMemoryReporterCallback* aCb,
|
2014-05-21 10:06:54 +04:00
|
|
|
nsISupports* aClosure, bool aAnonymize)
|
2013-10-12 03:07:15 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
|
|
|
nsCOMPtr<nsIMessageBroadcaster> globalmm =
|
|
|
|
do_GetService("@mozilla.org/globalmessagemanager;1");
|
|
|
|
if (globalmm) {
|
|
|
|
nsRefPtr<nsFrameMessageManager> mm =
|
|
|
|
static_cast<nsFrameMessageManager*>(globalmm.get());
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(mm, &count);
|
|
|
|
rv = ReportReferentCount("global-manager", count, aCb, aClosure);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsFrameMessageManager::sParentProcessManager) {
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(nsFrameMessageManager::sParentProcessManager, &count);
|
|
|
|
rv = ReportReferentCount("parent-process-manager", count, aCb, aClosure);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsFrameMessageManager::sChildProcessManager) {
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(nsFrameMessageManager::sChildProcessManager, &count);
|
|
|
|
rv = ReportReferentCount("child-process-manager", count, aCb, aClosure);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2010-06-10 13:26:19 +04:00
|
|
|
nsresult
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult)
|
2010-06-10 13:26:19 +04:00
|
|
|
{
|
2013-06-15 10:40:22 +04:00
|
|
|
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default,
|
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
2015-03-12 20:20:29 +03:00
|
|
|
nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
|
|
|
|
nullptr,
|
|
|
|
MM_CHROME | MM_GLOBAL | MM_BROADCASTER);
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterStrongMemoryReporter(new MessageManagerReporter());
|
2015-03-12 20:20:29 +03:00
|
|
|
mm.forget(aResult);
|
|
|
|
return NS_OK;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>*
|
|
|
|
nsMessageManagerScriptExecutor::sCachedScripts = nullptr;
|
|
|
|
nsScriptCacheCleaner* nsMessageManagerScriptExecutor::sScriptCacheCleaner = nullptr;
|
2010-08-10 21:18:26 +04:00
|
|
|
|
|
|
|
void
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::DidCreateGlobal()
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
2013-06-30 19:00:18 +04:00
|
|
|
NS_ASSERTION(mGlobal, "Should have mGlobal!");
|
2010-08-10 21:18:26 +04:00
|
|
|
if (!sCachedScripts) {
|
|
|
|
sCachedScripts =
|
2015-02-20 04:10:44 +03:00
|
|
|
new nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>;
|
2010-08-17 00:05:42 +04:00
|
|
|
|
2012-10-05 23:10:30 +04:00
|
|
|
nsRefPtr<nsScriptCacheCleaner> scriptCacheCleaner =
|
|
|
|
new nsScriptCacheCleaner();
|
|
|
|
scriptCacheCleaner.forget(&sScriptCacheCleaner);
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashOperator
|
2014-04-16 12:47:53 +04:00
|
|
|
RemoveCachedScriptEntry(const nsAString& aKey,
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptHolder*& aData,
|
2014-04-16 12:47:53 +04:00
|
|
|
void* aUserArg)
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
2011-01-22 01:51:41 +03:00
|
|
|
delete aData;
|
2010-08-10 21:18:26 +04:00
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::Shutdown()
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
|
|
|
if (sCachedScripts) {
|
2013-05-06 17:04:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2013-04-29 22:16:17 +04:00
|
|
|
NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts");
|
2014-04-16 12:47:53 +04:00
|
|
|
sCachedScripts->Enumerate(RemoveCachedScriptEntry, nullptr);
|
2010-08-10 21:18:26 +04:00
|
|
|
|
|
|
|
delete sCachedScripts;
|
2012-07-30 18:20:58 +04:00
|
|
|
sCachedScripts = nullptr;
|
2010-08-17 00:05:42 +04:00
|
|
|
|
2012-10-05 23:10:30 +04:00
|
|
|
nsRefPtr<nsScriptCacheCleaner> scriptCacheCleaner;
|
|
|
|
scriptCacheCleaner.swap(sScriptCacheCleaner);
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::LoadScriptInternal(const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope)
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
2013-06-30 19:00:17 +04:00
|
|
|
if (!mGlobal || !sCachedScripts) {
|
2010-08-10 21:18:26 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-29 17:34:21 +04:00
|
|
|
JSRuntime* rt = CycleCollectedJSRuntime::Get()->Runtime();
|
|
|
|
JS::Rooted<JSScript*> script(rt);
|
2012-08-29 19:26:18 +04:00
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptHolder* holder = sCachedScripts->Get(aURL);
|
2013-11-24 09:32:45 +04:00
|
|
|
if (holder && holder->WillRunInGlobalScope() == aRunInGlobalScope) {
|
|
|
|
script = holder->mScript;
|
|
|
|
} else {
|
|
|
|
// Don't put anything in the cache if we already have an entry
|
|
|
|
// with a different WillRunInGlobalScope() value.
|
|
|
|
bool shouldCache = !holder;
|
|
|
|
TryCacheLoadAndCompileScript(aURL, aRunInGlobalScope,
|
2014-06-13 21:56:38 +04:00
|
|
|
shouldCache, &script);
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
|
|
|
|
2014-09-29 17:34:21 +04:00
|
|
|
JS::Rooted<JSObject*> global(rt, mGlobal->GetJSObject());
|
2013-11-24 09:32:45 +04:00
|
|
|
if (global) {
|
2015-04-09 04:23:48 +03:00
|
|
|
AutoEntryScript aes(xpc::NativeGlobal(global),
|
|
|
|
"message manager script load");
|
2014-09-29 17:34:21 +04:00
|
|
|
aes.TakeOwnershipOfErrorReporting();
|
|
|
|
JSContext* cx = aes.cx();
|
2014-06-13 21:56:38 +04:00
|
|
|
if (script) {
|
|
|
|
if (aRunInGlobalScope) {
|
2015-03-20 07:34:08 +03:00
|
|
|
JS::CloneAndExecuteScript(cx, script);
|
2014-06-13 21:56:38 +04:00
|
|
|
} else {
|
|
|
|
JS::Rooted<JSObject*> scope(cx);
|
2014-09-29 17:34:21 +04:00
|
|
|
bool ok = js::ExecuteInGlobalAndReturnScope(cx, global, script, &scope);
|
|
|
|
if (ok) {
|
2014-06-13 21:56:38 +04:00
|
|
|
// Force the scope to stay alive.
|
|
|
|
mAnonymousGlobalScopes.AppendElement(scope);
|
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
2014-01-16 23:43:01 +04:00
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
2012-08-29 19:26:18 +04:00
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
|
2012-08-29 19:26:18 +04:00
|
|
|
void
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|
|
|
const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope,
|
|
|
|
bool aShouldCache,
|
|
|
|
JS::MutableHandle<JSScript*> aScriptp)
|
2012-08-29 19:26:18 +04:00
|
|
|
{
|
2010-08-10 21:18:26 +04:00
|
|
|
nsCString url = NS_ConvertUTF16toUTF8(aURL);
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), url);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 13:44:19 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hasFlags;
|
2011-05-19 18:48:17 +04:00
|
|
|
rv = NS_URIChainHasFlags(uri,
|
|
|
|
nsIProtocolHandler::URI_IS_LOCAL_RESOURCE,
|
|
|
|
&hasFlags);
|
|
|
|
if (NS_FAILED(rv) || !hasFlags) {
|
|
|
|
NS_WARNING("Will not load a frame script!");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-09 13:44:19 +04:00
|
|
|
|
2010-08-10 21:18:26 +04:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2014-09-21 20:36:25 +04:00
|
|
|
NS_NewChannel(getter_AddRefs(channel),
|
|
|
|
uri,
|
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
|
|
|
nsILoadInfo::SEC_NORMAL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
|
2010-08-10 21:18:26 +04:00
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> input;
|
|
|
|
channel->Open(getter_AddRefs(input));
|
|
|
|
nsString dataString;
|
2014-07-22 08:43:21 +04:00
|
|
|
char16_t* dataStringBuf = nullptr;
|
2014-04-25 18:11:56 +04:00
|
|
|
size_t dataStringLength = 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t avail64 = 0;
|
2012-08-11 06:44:11 +04:00
|
|
|
if (input && NS_SUCCEEDED(input->Available(&avail64)) && avail64) {
|
2012-09-28 10:57:33 +04:00
|
|
|
if (avail64 > UINT32_MAX) {
|
2012-08-11 06:44:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-04-07 04:17:56 +04:00
|
|
|
nsCString buffer;
|
2013-01-15 16:22:03 +04:00
|
|
|
uint32_t avail = (uint32_t)std::min(avail64, (uint64_t)UINT32_MAX);
|
2011-04-07 04:17:56 +04:00
|
|
|
if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) {
|
|
|
|
return;
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
nsScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail,
|
2014-04-25 18:11:56 +04:00
|
|
|
EmptyString(), nullptr,
|
|
|
|
dataStringBuf, dataStringLength);
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
|
2014-04-25 18:11:56 +04:00
|
|
|
JS::SourceBufferHolder srcBuf(dataStringBuf, dataStringLength,
|
|
|
|
JS::SourceBufferHolder::GiveOwnership);
|
|
|
|
|
|
|
|
if (dataStringBuf && dataStringLength > 0) {
|
2013-06-30 19:00:17 +04:00
|
|
|
AutoSafeJSContext cx;
|
2015-02-09 22:42:20 +03:00
|
|
|
// Compile the script in the compilation scope instead of the current global
|
|
|
|
// to avoid keeping the current compartment alive.
|
|
|
|
JS::Rooted<JSObject*> global(cx, xpc::CompilationScope());
|
|
|
|
|
2015-02-09 22:42:20 +03:00
|
|
|
JSAutoCompartment ac(cx, global);
|
|
|
|
JS::CompileOptions options(cx, JSVERSION_LATEST);
|
|
|
|
options.setFileAndLine(url.get(), 1);
|
|
|
|
options.setNoScriptRval(true);
|
|
|
|
JS::Rooted<JSScript*> script(cx);
|
|
|
|
|
|
|
|
if (aRunInGlobalScope) {
|
2015-03-19 17:13:34 +03:00
|
|
|
if (!JS::Compile(cx, options, srcBuf, &script)) {
|
2015-02-09 22:42:20 +03:00
|
|
|
return;
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
2015-02-09 22:42:20 +03:00
|
|
|
} else {
|
2015-03-20 07:34:07 +03:00
|
|
|
// We're going to run these against some non-global scope.
|
2015-04-01 19:05:29 +03:00
|
|
|
options.setHasPollutedScope(true);
|
2015-03-19 17:13:34 +03:00
|
|
|
if (!JS::Compile(cx, options, srcBuf, &script)) {
|
2015-02-09 22:42:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2015-02-09 22:42:20 +03:00
|
|
|
aScriptp.set(script);
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2015-02-09 22:42:20 +03:00
|
|
|
nsAutoCString scheme;
|
|
|
|
uri->GetScheme(scheme);
|
|
|
|
// We don't cache data: scripts!
|
|
|
|
if (aShouldCache && !scheme.EqualsLiteral("data")) {
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptHolder* holder;
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2015-02-09 22:42:20 +03:00
|
|
|
// Root the object also for caching.
|
|
|
|
if (script) {
|
2015-02-20 04:10:44 +03:00
|
|
|
holder = new nsMessageManagerScriptHolder(cx, script, aRunInGlobalScope);
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
2015-02-09 22:42:20 +03:00
|
|
|
sCachedScripts->Put(aURL, holder);
|
2013-04-18 19:36:03 +04:00
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
}
|
2010-08-17 00:05:42 +04:00
|
|
|
|
2013-11-24 09:32:45 +04:00
|
|
|
void
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
|
|
|
const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope)
|
2013-11-24 09:32:45 +04:00
|
|
|
{
|
|
|
|
AutoSafeJSContext cx;
|
|
|
|
JS::Rooted<JSScript*> script(cx);
|
2014-06-13 21:56:38 +04:00
|
|
|
TryCacheLoadAndCompileScript(aURL, aRunInGlobalScope, true, &script);
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
|
|
|
|
2011-11-30 19:51:40 +04:00
|
|
|
bool
|
2015-02-20 04:10:44 +03:00
|
|
|
nsMessageManagerScriptExecutor::InitChildGlobalInternal(
|
|
|
|
nsISupports* aScope,
|
|
|
|
const nsACString& aID)
|
2011-11-30 19:51:40 +04:00
|
|
|
{
|
2013-05-02 13:12:45 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
|
2011-11-30 19:51:40 +04:00
|
|
|
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
|
|
|
NS_ENSURE_TRUE(runtimeSvc, false);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
JSRuntime* rt = nullptr;
|
2011-11-30 19:51:40 +04:00
|
|
|
runtimeSvc->GetRuntime(&rt);
|
|
|
|
NS_ENSURE_TRUE(rt, false);
|
|
|
|
|
2013-06-30 19:00:20 +04:00
|
|
|
AutoSafeJSContext cx;
|
2011-11-30 19:51:40 +04:00
|
|
|
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
|
|
|
|
|
|
|
|
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
2012-09-05 22:32:07 +04:00
|
|
|
const uint32_t flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES;
|
2011-11-30 19:51:40 +04:00
|
|
|
|
2013-06-29 19:11:17 +04:00
|
|
|
JS::CompartmentOptions options;
|
2013-06-29 19:11:18 +04:00
|
|
|
options.setZone(JS::SystemZone)
|
|
|
|
.setVersion(JSVERSION_LATEST);
|
2013-06-30 19:00:20 +04:00
|
|
|
|
2011-11-30 19:51:40 +04:00
|
|
|
nsresult rv =
|
2012-03-06 03:22:44 +04:00
|
|
|
xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal,
|
2013-06-29 19:11:17 +04:00
|
|
|
flags, options, getter_AddRefs(mGlobal));
|
2011-11-30 19:51:40 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
2013-05-09 13:44:19 +04:00
|
|
|
|
2013-05-20 16:44:18 +04:00
|
|
|
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
|
|
|
|
NS_ENSURE_TRUE(global, false);
|
2011-11-30 19:51:40 +04:00
|
|
|
|
2013-02-20 14:39:59 +04:00
|
|
|
// Set the location information for the new global, so that tools like
|
|
|
|
// about:memory may use that information.
|
|
|
|
xpc::SetLocationForGlobal(global, aID);
|
|
|
|
|
2013-06-30 19:00:18 +04:00
|
|
|
DidCreateGlobal();
|
2011-11-30 19:51:40 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-02-25 01:23:53 +03:00
|
|
|
void
|
|
|
|
nsMessageManagerScriptExecutor::MarkScopesForCC()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mAnonymousGlobalScopes.Length(); ++i) {
|
|
|
|
JSObject* obj = mAnonymousGlobalScopes[i];
|
|
|
|
if (obj) {
|
|
|
|
JS::ExposeObjectToActiveJS(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsScriptCacheCleaner, nsIObserver)
|
2010-08-17 00:05:42 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsFrameMessageManager* nsFrameMessageManager::sChildProcessManager = nullptr;
|
|
|
|
nsFrameMessageManager* nsFrameMessageManager::sParentProcessManager = nullptr;
|
|
|
|
nsFrameMessageManager* nsFrameMessageManager::sSameProcessParentManager = nullptr;
|
2010-08-31 22:58:35 +04:00
|
|
|
|
2014-03-12 18:22:00 +04:00
|
|
|
class nsAsyncMessageToSameProcessChild : public nsSameProcessAsyncMessageBase,
|
|
|
|
public nsRunnable
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-07-11 02:05:39 +04:00
|
|
|
nsAsyncMessageToSameProcessChild(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2014-03-12 18:22:00 +04:00
|
|
|
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
|
2012-08-02 10:02:29 +04:00
|
|
|
{
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
|
|
|
|
2011-10-11 14:28:46 +04:00
|
|
|
NS_IMETHOD Run()
|
|
|
|
{
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager* ppm = nsFrameMessageManager::GetChildProcessManager();
|
2014-03-12 18:22:00 +04:00
|
|
|
ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm), ppm);
|
2011-10-11 14:28:46 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Send messages to an imaginary child process in a single-process scenario.
|
|
|
|
*/
|
|
|
|
class SameParentProcessMessageManagerCallback : public MessageManagerCallback
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
2012-09-28 09:43:12 +04:00
|
|
|
public:
|
|
|
|
SameParentProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(SameParentProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
virtual ~SameParentProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(SameParentProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
virtual bool DoLoadMessageManagerScript(const nsAString& aURL,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aRunInGlobalScope) override
|
2015-02-20 04:13:02 +03:00
|
|
|
{
|
|
|
|
ProcessGlobal* global = ProcessGlobal::Get();
|
|
|
|
MOZ_ASSERT(!aRunInGlobalScope);
|
|
|
|
global->LoadScript(aURL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2015-03-17 19:29:17 +03:00
|
|
|
nsCOMPtr<nsIRunnable> ev =
|
2013-11-06 21:21:15 +04:00
|
|
|
new nsAsyncMessageToSameProcessChild(aCx, aMessage, aData, aCpows,
|
|
|
|
aPrincipal);
|
2012-09-28 09:43:12 +04:00
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool CheckPermission(const nsAString& aPermission) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
// In a single-process scenario, the child always has all capabilities.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool CheckManifestURL(const nsAString& aManifestURL) override
|
2012-12-22 16:00:10 +04:00
|
|
|
{
|
|
|
|
// In a single-process scenario, the child always has all capabilities.
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-14 14:08:55 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
bool CheckAppHasPermission(const nsAString& aPermission) override
|
2013-01-14 14:08:55 +04:00
|
|
|
{
|
|
|
|
// In a single-process scenario, the child always has all capabilities.
|
|
|
|
return true;
|
|
|
|
}
|
2013-12-06 03:12:23 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool CheckAppHasStatus(unsigned short aStatus) override
|
2013-12-06 03:12:23 +04:00
|
|
|
{
|
|
|
|
// In a single-process scenario, the child always has all capabilities.
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send messages to the parent process.
|
|
|
|
*/
|
|
|
|
class ChildProcessMessageManagerCallback : public MessageManagerCallback
|
2010-08-31 22:58:35 +04:00
|
|
|
{
|
2012-09-28 09:43:12 +04:00
|
|
|
public:
|
|
|
|
ChildProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(ChildProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
virtual ~ChildProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ChildProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::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,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aIsSync) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
mozilla::dom::ContentChild* cc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
if (!cc) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
ClonedMessageData data;
|
2013-01-24 06:39:27 +04:00
|
|
|
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
|
|
|
|
return false;
|
2012-08-02 10:02:29 +04:00
|
|
|
}
|
2013-07-11 02:05:39 +04:00
|
|
|
InfallibleTArray<mozilla::jsipc::CpowEntry> cpows;
|
2014-10-07 02:45:42 +04:00
|
|
|
if (aCpows && !cc->GetCPOWManager()->Wrap(aCx, aCpows, &cpows)) {
|
2013-07-11 02:05:39 +04:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-01 20:15:06 +04:00
|
|
|
if (aIsSync) {
|
2014-02-25 06:14:22 +04:00
|
|
|
return cc->SendSyncMessage(PromiseFlatString(aMessage), data, cpows,
|
2014-08-05 17:19:51 +04:00
|
|
|
IPC::Principal(aPrincipal), aJSONRetVal);
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
2014-10-08 08:32:45 +04:00
|
|
|
return cc->SendRpcMessage(PromiseFlatString(aMessage), data, cpows,
|
2014-08-05 17:19:51 +04:00
|
|
|
IPC::Principal(aPrincipal), aJSONRetVal);
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
mozilla::dom::ContentChild* cc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
if (!cc) {
|
|
|
|
return true;
|
2011-10-11 14:28:46 +04:00
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
ClonedMessageData data;
|
2013-01-24 06:39:27 +04:00
|
|
|
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
|
|
|
|
return false;
|
2012-08-02 10:02:29 +04:00
|
|
|
}
|
2013-07-11 02:05:39 +04:00
|
|
|
InfallibleTArray<mozilla::jsipc::CpowEntry> cpows;
|
2014-10-07 02:45:42 +04:00
|
|
|
if (aCpows && !cc->GetCPOWManager()->Wrap(aCx, aCpows, &cpows)) {
|
2013-07-11 02:05:39 +04:00
|
|
|
return false;
|
|
|
|
}
|
2014-02-25 06:14:22 +04:00
|
|
|
return cc->SendAsyncMessage(PromiseFlatString(aMessage), data, cpows,
|
2014-08-05 17:19:51 +04:00
|
|
|
IPC::Principal(aPrincipal));
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2010-08-31 22:58:35 +04:00
|
|
|
|
2014-03-12 18:22:00 +04:00
|
|
|
class nsAsyncMessageToSameProcessParent : public nsSameProcessAsyncMessageBase,
|
2015-03-24 23:05:39 +03:00
|
|
|
public SameProcessMessageQueue::Runnable
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-07-11 02:05:39 +04:00
|
|
|
nsAsyncMessageToSameProcessParent(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2014-03-12 18:22:00 +04:00
|
|
|
: nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal)
|
2012-08-02 10:02:29 +04:00
|
|
|
{
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
|
|
|
|
2015-03-24 23:05:39 +03:00
|
|
|
virtual nsresult HandleMessage() override
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
nsFrameMessageManager* ppm = nsFrameMessageManager::sSameProcessParentManager;
|
|
|
|
ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm), ppm);
|
2014-03-12 18:22:00 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-10-11 14:28:46 +04:00
|
|
|
};
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
/**
|
|
|
|
* Send messages to the imaginary parent process in a single-process scenario.
|
|
|
|
*/
|
|
|
|
class SameChildProcessMessageManagerCallback : public MessageManagerCallback
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
2012-09-28 09:43:12 +04:00
|
|
|
public:
|
|
|
|
SameChildProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(SameChildProcessMessageManagerCallback);
|
2011-10-11 14:28:46 +04:00
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
virtual ~SameChildProcessMessageManagerCallback()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(SameChildProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::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,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aIsSync) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
|
|
|
queue->Flush();
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
if (nsFrameMessageManager::sSameProcessParentManager) {
|
2013-07-11 02:05:39 +04:00
|
|
|
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
|
2012-09-28 09:43:12 +04:00
|
|
|
nsRefPtr<nsFrameMessageManager> ppm = nsFrameMessageManager::sSameProcessParentManager;
|
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), aMessage,
|
2013-11-06 21:21:15 +04:00
|
|
|
true, &aData, &cpows, aPrincipal, aJSONRetVal);
|
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,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
|
|
|
nsRefPtr<nsAsyncMessageToSameProcessParent> ev =
|
2013-11-06 21:21:15 +04:00
|
|
|
new nsAsyncMessageToSameProcessParent(aCx, aMessage, aData, aCpows, aPrincipal);
|
2015-03-24 23:05:39 +03:00
|
|
|
queue->Push(ev);
|
2012-09-28 09:43:12 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-10-11 14:28:46 +04:00
|
|
|
|
2011-08-02 23:57:48 +04:00
|
|
|
// This creates the global parent process message manager.
|
2010-08-31 22:58:35 +04:00
|
|
|
nsresult
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_NewParentProcessMessageManager(nsIMessageBroadcaster** aResult)
|
2010-08-31 22:58:35 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!nsFrameMessageManager::sParentProcessManager,
|
|
|
|
"Re-creating sParentProcessManager");
|
2012-09-28 09:43:12 +04:00
|
|
|
nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2012-09-28 09:43:12 +04:00
|
|
|
MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER);
|
2010-08-31 22:58:35 +04:00
|
|
|
nsFrameMessageManager::sParentProcessManager = mm;
|
2015-03-06 04:03:25 +03:00
|
|
|
nsFrameMessageManager::NewProcessMessageManager(false); // Create same process message manager.
|
2015-03-12 20:20:29 +03:00
|
|
|
mm.forget(aResult);
|
|
|
|
return NS_OK;
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2011-08-02 23:57:48 +04:00
|
|
|
nsFrameMessageManager*
|
2015-03-06 04:03:25 +03:00
|
|
|
nsFrameMessageManager::NewProcessMessageManager(bool aIsRemote)
|
2011-08-02 23:57:48 +04:00
|
|
|
{
|
|
|
|
if (!nsFrameMessageManager::sParentProcessManager) {
|
2013-05-23 22:17:57 +04:00
|
|
|
nsCOMPtr<nsIMessageBroadcaster> dummy =
|
|
|
|
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
|
2011-08-02 23:57:48 +04:00
|
|
|
}
|
|
|
|
|
2013-05-23 22:17:57 +04:00
|
|
|
MOZ_ASSERT(nsFrameMessageManager::sParentProcessManager,
|
|
|
|
"parent process manager not created");
|
2012-09-28 09:43:12 +04:00
|
|
|
nsFrameMessageManager* mm;
|
2015-03-06 04:03:25 +03:00
|
|
|
if (aIsRemote) {
|
|
|
|
// Callback is set in ContentParent::InitInternal so that the process has
|
|
|
|
// already started when we send pending scripts.
|
|
|
|
mm = new nsFrameMessageManager(nullptr,
|
2012-09-28 09:43:12 +04:00
|
|
|
nsFrameMessageManager::sParentProcessManager,
|
|
|
|
MM_CHROME | MM_PROCESSMANAGER);
|
|
|
|
} else {
|
|
|
|
mm = new nsFrameMessageManager(new SameParentProcessMessageManagerCallback(),
|
|
|
|
nsFrameMessageManager::sParentProcessManager,
|
|
|
|
MM_CHROME | MM_PROCESSMANAGER | MM_OWNSCALLBACK);
|
2011-10-11 14:28:46 +04:00
|
|
|
sSameProcessParentManager = mm;
|
|
|
|
}
|
2011-08-02 23:57:48 +04:00
|
|
|
return mm;
|
|
|
|
}
|
2010-08-31 22:58:35 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewChildProcessMessageManager(nsISyncMessageSender** aResult)
|
|
|
|
{
|
2015-02-20 04:12:38 +03:00
|
|
|
NS_ASSERTION(!nsFrameMessageManager::GetChildProcessManager(),
|
2010-08-31 22:58:35 +04:00
|
|
|
"Re-creating sChildProcessManager");
|
2012-09-28 09:43:12 +04:00
|
|
|
|
|
|
|
MessageManagerCallback* cb;
|
2013-06-15 10:40:22 +04:00
|
|
|
if (XRE_GetProcessType() == GeckoProcessType_Default) {
|
2012-09-28 09:43:12 +04:00
|
|
|
cb = new SameChildProcessMessageManagerCallback();
|
|
|
|
} else {
|
|
|
|
cb = new ChildProcessMessageManagerCallback();
|
2013-11-07 09:35:30 +04:00
|
|
|
RegisterStrongMemoryReporter(new MessageManagerReporter());
|
2012-09-28 09:43:12 +04:00
|
|
|
}
|
|
|
|
nsFrameMessageManager* mm = new nsFrameMessageManager(cb,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2012-09-28 09:43:12 +04:00
|
|
|
MM_PROCESSMANAGER | MM_OWNSCALLBACK);
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager::SetChildProcessManager(mm);
|
2015-03-12 20:20:29 +03:00
|
|
|
nsRefPtr<ProcessGlobal> global = new ProcessGlobal(mm);
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED);
|
2015-03-12 20:20:29 +03:00
|
|
|
global.forget(aResult);
|
|
|
|
return NS_OK;
|
2015-02-20 04:13:02 +03:00
|
|
|
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
2012-01-26 19:39:23 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
CycleCollectorMarkListeners(const nsAString& aKey,
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* aListeners,
|
2013-10-26 01:55:16 +04:00
|
|
|
void* aData)
|
2012-01-26 19:39:23 +04:00
|
|
|
{
|
2013-10-26 01:55:16 +04:00
|
|
|
uint32_t count = aListeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
2013-11-05 15:52:04 +04:00
|
|
|
if (aListeners->ElementAt(i).mStrongListener) {
|
|
|
|
xpc_TryUnmarkWrappedGrayObject(aListeners->ElementAt(i).mStrongListener);
|
2013-08-08 22:36:56 +04:00
|
|
|
}
|
2012-01-26 19:39:23 +04:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsFrameMessageManager::MarkForCC()
|
|
|
|
{
|
|
|
|
mListeners.EnumerateRead(CycleCollectorMarkListeners, nullptr);
|
|
|
|
|
2012-10-17 05:22:02 +04:00
|
|
|
if (mRefCnt.IsPurple()) {
|
|
|
|
mRefCnt.RemovePurple();
|
|
|
|
}
|
2012-01-26 19:39:23 +04:00
|
|
|
return true;
|
2012-08-06 16:02:08 +04:00
|
|
|
}
|
2014-03-12 18:22:00 +04:00
|
|
|
|
|
|
|
nsSameProcessAsyncMessageBase::nsSameProcessAsyncMessageBase(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
|
|
|
: mRuntime(js::GetRuntime(aCx)),
|
|
|
|
mMessage(aMessage),
|
2014-04-16 12:47:53 +04:00
|
|
|
mCpows(aCx, aCpows),
|
2014-03-12 18:22:00 +04:00
|
|
|
mPrincipal(aPrincipal)
|
|
|
|
{
|
|
|
|
if (aData.mDataLength && !mData.copy(aData.mData, aData.mDataLength)) {
|
|
|
|
NS_RUNTIMEABORT("OOM");
|
|
|
|
}
|
|
|
|
mClosure = aData.mClosure;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSameProcessAsyncMessageBase::ReceiveMessage(nsISupports* aTarget,
|
|
|
|
nsFrameMessageManager* aManager)
|
|
|
|
{
|
|
|
|
if (aManager) {
|
|
|
|
StructuredCloneData data;
|
|
|
|
data.mData = mData.data();
|
|
|
|
data.mDataLength = mData.nbytes();
|
|
|
|
data.mClosure = mClosure;
|
|
|
|
|
2014-04-16 12:47:53 +04:00
|
|
|
SameProcessCpowHolder cpows(mRuntime, mCpows);
|
2014-03-12 18:22:00 +04:00
|
|
|
|
|
|
|
nsRefPtr<nsFrameMessageManager> mm = aManager;
|
|
|
|
mm->ReceiveMessage(aTarget, mMessage, false, &data, &cpows,
|
|
|
|
mPrincipal, nullptr);
|
|
|
|
}
|
|
|
|
}
|