2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
#include "base/basictypes.h"
|
|
|
|
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
|
2010-08-31 22:58:35 +04:00
|
|
|
#include "ContentChild.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsContentUtils.h"
|
2016-02-14 17:59:48 +03:00
|
|
|
#include "nsDOMClassInfoID.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"
|
2012-08-27 18:13:02 +04:00
|
|
|
#include "nsIDOMClassInfo.h"
|
2011-11-30 19:51:40 +04:00
|
|
|
#include "xpcpublic.h"
|
2016-09-14 16:47:32 +03:00
|
|
|
#include "mozilla/CycleCollectedJSContext.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"
|
2015-10-07 13:42:43 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2016-02-01 00:48:00 +03:00
|
|
|
#include "mozilla/dom/MessagePort.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"
|
2014-09-27 03:21:57 +04:00
|
|
|
#include "mozilla/dom/ipc/BlobChild.h"
|
|
|
|
#include "mozilla/dom/ipc/BlobParent.h"
|
2015-09-10 23:50:58 +03:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.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"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2016-06-09 19:35:19 +03:00
|
|
|
#include "chrome/common/ipc_channel.h" // for IPC::Channel::kMaximumMessageSize
|
2010-08-31 22:58:35 +04:00
|
|
|
|
2015-07-22 20:43:02 +03:00
|
|
|
#ifdef MOZ_CRASHREPORTER
|
|
|
|
#include "nsExceptionHandler.h"
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
nsFrameMessageManager::nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
|
|
|
|
nsFrameMessageManager* aParentManager,
|
|
|
|
/* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags)
|
|
|
|
: mChrome(!!(aFlags & mozilla::dom::ipc::MM_CHROME)),
|
|
|
|
mGlobal(!!(aFlags & mozilla::dom::ipc::MM_GLOBAL)),
|
|
|
|
mIsProcessManager(!!(aFlags & mozilla::dom::ipc::MM_PROCESSMANAGER)),
|
|
|
|
mIsBroadcaster(!!(aFlags & mozilla::dom::ipc::MM_BROADCASTER)),
|
|
|
|
mOwnsCallback(!!(aFlags & mozilla::dom::ipc::MM_OWNSCALLBACK)),
|
|
|
|
mHandlingMessage(false),
|
|
|
|
mClosed(false),
|
|
|
|
mDisconnected(false),
|
|
|
|
mCallback(aCallback),
|
|
|
|
mParentManager(aParentManager)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mChrome || !aParentManager, "Should not set parent manager!");
|
|
|
|
NS_ASSERTION(!mIsBroadcaster || !mCallback,
|
|
|
|
"Broadcasters cannot have callbacks!");
|
|
|
|
if (mIsProcessManager && (!mChrome || IsBroadcaster())) {
|
|
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
}
|
|
|
|
// This is a bit hackish. When parent manager is global, we want
|
|
|
|
// to attach the message manager to it immediately.
|
|
|
|
// Is it just the frame message manager which waits until the
|
|
|
|
// content process is running.
|
|
|
|
if (mParentManager && (mCallback || IsBroadcaster())) {
|
|
|
|
mParentManager->AddChildManager(this);
|
|
|
|
}
|
|
|
|
if (mOwnsCallback) {
|
|
|
|
mOwnedCallback = aCallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameMessageManager::~nsFrameMessageManager()
|
|
|
|
{
|
|
|
|
if (mIsProcessManager && (!mChrome || IsBroadcaster())) {
|
|
|
|
mozilla::DropJSObjects(this);
|
|
|
|
}
|
|
|
|
for (int32_t i = mChildManagers.Count(); i > 0; --i) {
|
|
|
|
static_cast<nsFrameMessageManager*>(mChildManagers[i - 1])->
|
|
|
|
Disconnect(false);
|
|
|
|
}
|
|
|
|
if (mIsProcessManager) {
|
|
|
|
if (this == sParentProcessManager) {
|
|
|
|
sParentProcessManager = nullptr;
|
|
|
|
}
|
|
|
|
if (this == sChildProcessManager) {
|
|
|
|
sChildProcessManager = nullptr;
|
|
|
|
delete mozilla::dom::SameProcessMessageQueue::Get();
|
|
|
|
}
|
|
|
|
if (this == sSameProcessParentManager) {
|
|
|
|
sSameProcessParentManager = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)
|
2015-11-05 06:43:45 +03:00
|
|
|
for (auto iter = tmp->mListeners.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners = iter.UserData();
|
|
|
|
uint32_t count = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "listeners[i] mStrongListener");
|
|
|
|
cb.NoteXPCOMChild(listeners->ElementAt(i).mStrongListener.get());
|
|
|
|
}
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildManagers)
|
2015-07-06 14:06:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mParentManager)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsFrameMessageManager)
|
2016-02-22 21:11:02 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mInitialProcessData)
|
2015-05-01 04:20:51 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
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)
|
2015-07-06 14:06:00 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mParentManager)
|
2015-05-01 04:20:51 +03:00
|
|
|
tmp->mInitialProcessData.setNull();
|
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)
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
/* Global process message managers (process message managers) support nsIGlobalProcessScriptLoader. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIGlobalProcessScriptLoader,
|
|
|
|
mChrome && mIsProcessManager && 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
|
|
|
|
2013-01-24 06:39:27 +04:00
|
|
|
bool
|
2014-06-11 09:44:03 +04:00
|
|
|
MessageManagerCallback::BuildClonedMessageDataForParent(nsIContentParent* aParent,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-01-24 06:39:27 +04:00
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
2016-11-07 16:38:02 +03:00
|
|
|
return aData.BuildClonedMessageDataForParent(aParent, aClonedData);
|
2013-01-24 06:39:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-06-11 09:44:06 +04:00
|
|
|
MessageManagerCallback::BuildClonedMessageDataForChild(nsIContentChild* aChild,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-01-24 06:39:27 +04:00
|
|
|
ClonedMessageData& aClonedData)
|
|
|
|
{
|
2016-11-07 16:38:02 +03:00
|
|
|
return aData.BuildClonedMessageDataForChild(aChild, aClonedData);
|
2013-01-24 20:24:19 +04:00
|
|
|
}
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
void
|
2015-09-10 23:50:58 +03:00
|
|
|
mozilla::dom::ipc::UnpackClonedMessageDataForParent(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
2013-01-24 20:24:19 +04:00
|
|
|
{
|
2016-11-07 16:38:02 +03:00
|
|
|
aData.BorrowFromClonedMessageDataForParent(aClonedData);
|
2013-01-24 20:24:19 +04:00
|
|
|
}
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
void
|
2015-09-10 23:50:58 +03:00
|
|
|
mozilla::dom::ipc::UnpackClonedMessageDataForChild(const ClonedMessageData& aClonedData,
|
|
|
|
StructuredCloneData& aData)
|
2013-01-24 20:24:19 +04:00
|
|
|
{
|
2016-11-07 16:38:02 +03:00
|
|
|
aData.BorrowFromClonedMessageDataForChild(aClonedData);
|
2013-01-24 20:24:19 +04:00
|
|
|
}
|
|
|
|
|
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-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
|
2015-07-27 09:00:29 +03:00
|
|
|
// 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);
|
2015-11-05 06:43:45 +03:00
|
|
|
for (auto iter = mListeners.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners = iter.UserData();
|
|
|
|
uint32_t count = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
nsWeakPtr weakListener = listeners->ElementAt(i).mWeakListener;
|
|
|
|
if (weakListener) {
|
|
|
|
nsCOMPtr<nsISupports> otherCanonical = do_QueryReferent(weakListener);
|
|
|
|
MOZ_ASSERT((canonical == otherCanonical) == (weak == weakListener));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2015-09-16 11:06:30 +03:00
|
|
|
// Cache for future windows or frames
|
|
|
|
mPendingScripts.AppendElement(aURL);
|
|
|
|
mPendingScriptsGlobalStates.AppendElement(aRunInGlobalScope);
|
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) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm =
|
2010-06-10 13:26:19 +04:00
|
|
|
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-09-10 23:50:58 +03:00
|
|
|
const JS::Value& aValue,
|
2016-02-01 00:48:00 +03:00
|
|
|
const JS::Value& aTransfer,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData)
|
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.
|
2015-09-10 23:50:58 +03:00
|
|
|
JS::RootedValue v(aCx, aValue);
|
2016-02-01 00:48:00 +03:00
|
|
|
JS::RootedValue t(aCx, aTransfer);
|
2015-09-02 19:20:30 +03:00
|
|
|
ErrorResult rv;
|
2016-02-01 00:48:00 +03:00
|
|
|
aData.Write(aCx, v, t, rv);
|
2015-09-02 19:20:30 +03:00
|
|
|
if (!rv.Failed()) {
|
2012-08-02 10:02:29 +04:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-02 19:20:30 +03:00
|
|
|
|
|
|
|
rv.SuppressException();
|
2012-08-02 10:02:29 +04:00
|
|
|
JS_ClearPendingException(aCx);
|
|
|
|
|
2015-03-20 06:59:00 +03:00
|
|
|
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (console) {
|
|
|
|
nsAutoString filename;
|
2015-09-02 03:56:03 +03:00
|
|
|
uint32_t lineno = 0, column = 0;
|
|
|
|
nsJSUtils::GetCallingLocation(aCx, filename, &lineno, &column);
|
2015-03-20 06:59:00 +03:00
|
|
|
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?"),
|
2015-09-02 03:56:03 +03:00
|
|
|
filename, EmptyString(), lineno, column,
|
|
|
|
nsIScriptError::warningFlag, "chrome javascript");
|
2015-03-20 06:59:00 +03:00
|
|
|
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;
|
2015-05-14 00:07:34 +03:00
|
|
|
NS_ENSURE_TRUE(JS_Stringify(aCx, &v, 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
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
aData.Write(aCx, val, rv);
|
2015-09-02 19:20:30 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
rv.SuppressException();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
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
|
|
|
}
|
|
|
|
|
2016-06-09 19:35:19 +03:00
|
|
|
static bool
|
|
|
|
AllowMessage(size_t aDataLength, const nsAString& aMessageName)
|
2016-06-02 01:11:06 +03:00
|
|
|
{
|
|
|
|
static const size_t kMinTelemetryMessageSize = 8192;
|
|
|
|
|
|
|
|
if (aDataLength < kMinTelemetryMessageSize) {
|
2016-06-09 19:35:19 +03:00
|
|
|
return true;
|
2016-06-02 01:11:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ConvertUTF16toUTF8 messageName(aMessageName);
|
2016-06-02 01:11:06 +03:00
|
|
|
messageName.StripChars("0123456789");
|
2016-06-02 01:11:06 +03:00
|
|
|
|
2016-06-02 01:11:06 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MESSAGE_MANAGER_MESSAGE_SIZE2, messageName,
|
2016-06-02 01:11:06 +03:00
|
|
|
aDataLength);
|
2016-06-09 19:35:19 +03:00
|
|
|
|
|
|
|
// A message includes more than structured clone data, so subtract
|
|
|
|
// 20KB to make it more likely that a message within this bound won't
|
|
|
|
// result in an overly large IPC message.
|
|
|
|
static const size_t kMaxMessageSize = IPC::Channel::kMaximumMessageSize - 20 * 1024;
|
|
|
|
if (aDataLength < kMaxMessageSize) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Telemetry::Accumulate(Telemetry::REJECTED_MESSAGE_MANAGER_MESSAGE,
|
|
|
|
messageName);
|
|
|
|
|
|
|
|
return false;
|
2016-06-02 01:11:06 +03:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData data;
|
2016-02-01 00:48:00 +03:00
|
|
|
if (aArgc >= 2 && !GetParamsForMessage(aCx, aJSON, JS::UndefinedHandleValue, data)) {
|
2012-09-28 09:43:12 +04:00
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2016-06-09 19:35:19 +03:00
|
|
|
if (!AllowMessage(data.DataLength(), aMessageName)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-03-31 01:25:54 +03: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();
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData> retval;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
sSendingSyncMessage |= aIsSync;
|
2015-09-10 23:50:58 +03:00
|
|
|
bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, objects,
|
2013-11-06 21:21:15 +04:00
|
|
|
aPrincipal, &retval, aIsSync);
|
2013-10-01 20:15:06 +04:00
|
|
|
if (aIsSync) {
|
|
|
|
sSendingSyncMessage = false;
|
|
|
|
}
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
if (!ok) {
|
2013-10-01 20:15:06 +04:00
|
|
|
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) {
|
|
|
|
JS::Rooted<JS::Value> ret(aCx);
|
2015-09-09 10:10:32 +03:00
|
|
|
ErrorResult rv;
|
|
|
|
retval[i].Read(aCx, &ret, rv);
|
|
|
|
if (rv.Failed()) {
|
2015-04-30 06:39:59 +03:00
|
|
|
MOZ_ASSERT(false, "Unable to read structured clone in SendMessage");
|
2016-07-22 17:50:10 +03:00
|
|
|
rv.SuppressException();
|
2013-10-01 20:15:06 +04:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2015-04-30 06:39:59 +03:00
|
|
|
|
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,
|
2015-09-10 23:50:58 +03:00
|
|
|
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])->
|
2015-09-10 23:50:58 +03: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;
|
|
|
|
}
|
|
|
|
|
2015-07-15 03:21:49 +03:00
|
|
|
if (!mCallback) {
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2015-10-07 13:42:43 +03:00
|
|
|
nsresult rv = mCallback->DoSendAsyncMessage(aCx, aMessage, aData, aCpows, aPrincipal);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
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,
|
2016-02-01 00:48:00 +03:00
|
|
|
const JS::Value& aTransfers,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
2012-09-28 09:43:12 +04:00
|
|
|
uint8_t aArgc)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData data;
|
2016-02-01 00:48:00 +03:00
|
|
|
if (aArgc >= 2 && !GetParamsForMessage(aCx, aJSON, aTransfers, data)) {
|
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
|
|
|
|
2016-06-09 19:35:19 +03:00
|
|
|
if (!AllowMessage(data.DataLength(), aMessageName)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2016-03-31 01:25:54 +03: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();
|
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
return DispatchAsyncMessageInternal(aCx, aMessageName, data, objects,
|
2013-11-06 21:21:15 +04:00
|
|
|
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,
|
2016-02-01 00:48:00 +03:00
|
|
|
JS::Handle<JS::Value> aTransfers,
|
2012-08-27 18:13:02 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc)
|
|
|
|
{
|
2016-02-01 00:48:00 +03:00
|
|
|
return DispatchAsyncMessage(aMessageName, aJSON, aObjects, aPrincipal,
|
|
|
|
aTransfers, 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)
|
|
|
|
{
|
2016-02-01 00:48:00 +03:00
|
|
|
return DispatchAsyncMessage(aMessageName, aJSON, aObjects, nullptr,
|
|
|
|
JS::UndefinedHandleValue, 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-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
2015-02-20 04:12:11 +03:00
|
|
|
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
|
2016-01-30 20:05:36 +03:00
|
|
|
nsFrameMessageManager::GetContent(mozIDOMWindowProxy** aContent)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
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-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;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mMM;
|
2012-01-07 23:20:12 +04:00
|
|
|
};
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
|
|
|
|
// nsIMessageListener
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
2015-04-16 18:17:54 +03:00
|
|
|
nsIFrameLoader* aTargetFrameLoader,
|
2010-05-18 16:28:37 +04:00
|
|
|
const nsAString& aMessage,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData* aCloneData,
|
2015-01-27 00:32:18 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal)
|
2015-02-27 08:35:26 +03:00
|
|
|
{
|
2015-04-16 18:17:54 +03:00
|
|
|
return ReceiveMessage(aTarget, aTargetFrameLoader, mClosed, aMessage, aIsSync,
|
2015-09-10 23:50:58 +03:00
|
|
|
aCloneData, aCpows, aPrincipal, aRetVal);
|
2015-02-27 08:35:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
|
2015-04-16 18:17:54 +03:00
|
|
|
nsIFrameLoader* aTargetFrameLoader,
|
2015-02-27 08:35:26 +03:00
|
|
|
bool aTargetClosed,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
bool aIsSync,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData* aCloneData,
|
2015-02-27 08:35:26 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows,
|
|
|
|
nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal)
|
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
|
|
|
|
2016-03-09 23:28:26 +03:00
|
|
|
AutoEntryScript aes(wrappedJS->GetJSObject(), "message manager handler");
|
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());
|
2015-09-10 23:50:58 +03:00
|
|
|
if (aCloneData && aCloneData->DataLength()) {
|
2015-09-02 19:20:30 +03:00
|
|
|
ErrorResult rv;
|
2015-09-10 23:50:58 +03:00
|
|
|
aCloneData->Read(cx, &json, rv);
|
2015-09-02 19:20:30 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
rv.SuppressException();
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2016-02-01 00:48:00 +03:00
|
|
|
|
|
|
|
// Get cloned MessagePort from StructuredCloneData.
|
|
|
|
nsTArray<RefPtr<mozilla::dom::MessagePort>> ports;
|
|
|
|
if (aCloneData) {
|
|
|
|
ports = aCloneData->TakeTransferredPorts();
|
|
|
|
}
|
|
|
|
|
2016-10-13 16:19:52 +03:00
|
|
|
JS::Rooted<JS::Value> transferredList(cx);
|
|
|
|
if (NS_WARN_IF(!ToJSValue(cx, ports, &transferredList))) {
|
2016-02-01 00:48:00 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
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) &&
|
2016-02-01 00:48:00 +03:00
|
|
|
JS_DefineProperty(cx, param, "objects", cpowsv, JSPROP_ENUMERATE) &&
|
|
|
|
JS_DefineProperty(cx, param, "ports", transferredList, JSPROP_ENUMERATE);
|
|
|
|
|
2014-11-13 03:59:20 +03:00
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
if (aTargetFrameLoader) {
|
|
|
|
JS::Rooted<JS::Value> targetFrameLoaderv(cx);
|
|
|
|
nsresult rv = nsContentUtils::WrapNative(cx, aTargetFrameLoader, &targetFrameLoaderv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
ok = JS_DefineProperty(cx, param, "targetFrameLoader", targetFrameLoaderv,
|
|
|
|
JSPROP_ENUMERATE);
|
|
|
|
NS_ENSURE_TRUE(ok, NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2015-04-30 06:39:59 +03:00
|
|
|
if (aRetVal) {
|
2015-09-09 10:10:32 +03:00
|
|
|
ErrorResult rv;
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData* data = aRetVal->AppendElement();
|
|
|
|
data->Write(cx, rval, rv);
|
2015-09-09 10:10:32 +03:00
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
|
|
|
aRetVal->RemoveElementAt(aRetVal->Length() - 1);
|
2015-04-30 06:39:59 +03:00
|
|
|
nsString msg = aMessage + NS_LITERAL_STRING(": message reply cannot be cloned. Are you trying to send an XPCOM object?");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIConsoleService> console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
|
|
|
if (console) {
|
|
|
|
nsCOMPtr<nsIScriptError> error(do_CreateInstance(NS_SCRIPTERROR_CONTRACTID));
|
|
|
|
error->Init(msg, EmptyString(), EmptyString(),
|
|
|
|
0, 0, nsIScriptError::warningFlag, "chrome javascript");
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ClearPendingException(cx);
|
2014-01-16 23:43:34 +04:00
|
|
|
continue;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-24 21:12:09 +03:00
|
|
|
|
|
|
|
RefPtr<nsFrameMessageManager> kungFuDeathGrip = mParentManager;
|
|
|
|
if (kungFuDeathGrip) {
|
|
|
|
return kungFuDeathGrip->ReceiveMessage(aTarget, aTargetFrameLoader,
|
|
|
|
aTargetClosed, aMessage,
|
|
|
|
aIsSync, aCloneData,
|
|
|
|
aCpows, aPrincipal,
|
|
|
|
aRetVal);
|
|
|
|
}
|
|
|
|
return 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
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> kungfuDeathGrip = this;
|
|
|
|
RefPtr<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
|
|
|
}
|
|
|
|
|
2015-09-08 10:31:40 +03:00
|
|
|
void
|
|
|
|
nsFrameMessageManager::LoadPendingScripts()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> kungfuDeathGrip = this;
|
2015-09-08 10:31:40 +03:00
|
|
|
LoadPendingScripts(this, this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
void
|
|
|
|
nsFrameMessageManager::SetInitialProcessData(JS::HandleValue aInitialData)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mChrome);
|
|
|
|
MOZ_ASSERT(mIsProcessManager);
|
|
|
|
mInitialProcessData = aInitialData;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::GetInitialProcessData(JSContext* aCx, JS::MutableHandleValue aResult)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsProcessManager);
|
|
|
|
MOZ_ASSERT_IF(mChrome, IsBroadcaster());
|
|
|
|
|
|
|
|
JS::RootedValue init(aCx, mInitialProcessData);
|
|
|
|
if (mChrome && init.isUndefined()) {
|
|
|
|
// We create the initial object in the junk scope. If we created it in a
|
|
|
|
// normal compartment, that compartment would leak until shutdown.
|
|
|
|
JS::RootedObject global(aCx, xpc::PrivilegedJunkScope());
|
|
|
|
JSAutoCompartment ac(aCx, global);
|
|
|
|
|
|
|
|
JS::RootedObject obj(aCx, JS_NewPlainObject(aCx));
|
|
|
|
if (!obj) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInitialProcessData.setObject(*obj);
|
|
|
|
init.setObject(*obj);
|
|
|
|
}
|
|
|
|
|
2015-07-31 01:59:49 +03:00
|
|
|
if (!mChrome && XRE_IsParentProcess()) {
|
|
|
|
// This is the cpmm in the parent process. We should use the same object as the ppmm.
|
|
|
|
nsCOMPtr<nsIGlobalProcessScriptLoader> ppmm =
|
|
|
|
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
|
|
|
|
ppmm->GetInitialProcessData(aCx, &init);
|
|
|
|
mInitialProcessData = init;
|
|
|
|
}
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
if (!JS_WrapValue(aCx, &init)) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
aResult.set(init);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-22 11:28:04 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFrameMessageManager::GetProcessMessageManager(nsIMessageSender** aPMM)
|
|
|
|
{
|
|
|
|
*aPMM = nullptr;
|
|
|
|
if (mCallback) {
|
|
|
|
nsCOMPtr<nsIMessageSender> pmm = mCallback->GetProcessMessageManager();
|
|
|
|
pmm.swap(*aPMM);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace
|
2013-10-12 03:07:15 +04:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2016-11-14 12:40:37 +03:00
|
|
|
~MessageManagerReporter() = default;
|
2014-06-25 06:09:15 +04:00
|
|
|
|
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
|
|
|
|
2015-07-27 09:00:29 +03:00
|
|
|
void
|
|
|
|
MessageManagerReporter::CountReferents(nsFrameMessageManager* aMessageManager,
|
|
|
|
MessageManagerReferentCount* aReferentCount)
|
|
|
|
{
|
2015-11-05 08:35:12 +03:00
|
|
|
for (auto it = aMessageManager->mListeners.Iter(); !it.Done(); it.Next()) {
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
|
|
|
it.UserData();
|
|
|
|
uint32_t listenerCount = listeners->Length();
|
|
|
|
if (listenerCount == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString key(it.Key());
|
|
|
|
uint32_t oldCount = 0;
|
|
|
|
aReferentCount->mMessageCounter.Get(key, &oldCount);
|
|
|
|
uint32_t currentCount = oldCount + listenerCount;
|
|
|
|
aReferentCount->mMessageCounter.Put(key, currentCount);
|
|
|
|
|
|
|
|
// Keep track of messages that have a suspiciously large
|
|
|
|
// number of referents (symptom of leak).
|
|
|
|
if (currentCount == MessageManagerReporter::kSuspectReferentCount) {
|
|
|
|
aReferentCount->mSuspectMessages.AppendElement(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < listenerCount; ++i) {
|
|
|
|
const nsMessageListenerInfo& listenerInfo = listeners->ElementAt(i);
|
|
|
|
if (listenerInfo.mWeakListener) {
|
|
|
|
nsCOMPtr<nsISupports> referent =
|
|
|
|
do_QueryReferent(listenerInfo.mWeakListener);
|
|
|
|
if (referent) {
|
|
|
|
aReferentCount->mWeakAlive++;
|
|
|
|
} else {
|
|
|
|
aReferentCount->mWeakDead++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aReferentCount->mStrong++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm =
|
2013-10-12 03:07:15 +04:00
|
|
|
static_cast<nsFrameMessageManager*>(aMessageManager->mChildManagers[i]);
|
|
|
|
CountReferents(mm, aReferentCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-24 08:23:45 +03:00
|
|
|
static void
|
2013-10-12 03:07:15 +04:00
|
|
|
ReportReferentCount(const char* aManagerType,
|
|
|
|
const MessageManagerReferentCount& aReferentCount,
|
2016-08-24 08:23:45 +03:00
|
|
|
nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData)
|
|
|
|
{
|
|
|
|
#define REPORT(_path, _amount, _desc) \
|
|
|
|
do { \
|
|
|
|
aHandleReport->Callback(EmptyCString(), _path, \
|
|
|
|
nsIMemoryReporter::KIND_OTHER, \
|
|
|
|
nsIMemoryReporter::UNITS_COUNT, _amount, \
|
|
|
|
_desc, aData); \
|
2013-10-12 03:07:15 +04:00
|
|
|
} 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
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2016-08-24 08:23:45 +03:00
|
|
|
MessageManagerReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize)
|
2013-10-12 03:07:15 +04:00
|
|
|
{
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
2013-10-12 03:07:15 +04:00
|
|
|
nsCOMPtr<nsIMessageBroadcaster> globalmm =
|
|
|
|
do_GetService("@mozilla.org/globalmessagemanager;1");
|
|
|
|
if (globalmm) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm =
|
2013-10-12 03:07:15 +04:00
|
|
|
static_cast<nsFrameMessageManager*>(globalmm.get());
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(mm, &count);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportReferentCount("global-manager", count, aHandleReport, aData);
|
2013-10-12 03:07:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsFrameMessageManager::sParentProcessManager) {
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(nsFrameMessageManager::sParentProcessManager, &count);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportReferentCount("parent-process-manager", count, aHandleReport, aData);
|
2013-10-12 03:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nsFrameMessageManager::sChildProcessManager) {
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(nsFrameMessageManager::sChildProcessManager, &count);
|
2016-08-24 08:23:45 +03:00
|
|
|
ReportReferentCount("child-process-manager", count, aHandleReport, aData);
|
2013-10-12 03:07:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2015-07-04 04:29:00 +03:00
|
|
|
NS_ENSURE_TRUE(XRE_IsParentProcess(),
|
2013-06-15 10:40:22 +04:00
|
|
|
NS_ERROR_NOT_AVAILABLE);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
|
2015-03-12 20:20:29 +03:00
|
|
|
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;
|
2016-07-21 19:54:16 +03:00
|
|
|
StaticRefPtr<nsScriptCacheCleaner> nsMessageManagerScriptExecutor::sScriptCacheCleaner;
|
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*>;
|
2016-07-21 19:54:16 +03:00
|
|
|
sScriptCacheCleaner = new nsScriptCacheCleaner();
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
2016-04-13 21:04:11 +03:00
|
|
|
nsMessageManagerScriptExecutor::PurgeCache()
|
2010-08-10 21:18:26 +04:00
|
|
|
{
|
|
|
|
if (sCachedScripts) {
|
2013-04-29 22:16:17 +04:00
|
|
|
NS_ASSERTION(sCachedScripts != nullptr, "Need cached scripts");
|
2016-01-29 01:08:19 +03:00
|
|
|
for (auto iter = sCachedScripts->Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
delete iter.Data();
|
|
|
|
iter.Remove();
|
|
|
|
}
|
2016-04-13 21:04:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsMessageManagerScriptExecutor::Shutdown()
|
|
|
|
{
|
|
|
|
if (sCachedScripts) {
|
|
|
|
PurgeCache();
|
2010-08-10 21:18:26 +04:00
|
|
|
|
|
|
|
delete sCachedScripts;
|
2012-07-30 18:20:58 +04:00
|
|
|
sCachedScripts = nullptr;
|
2016-07-21 19:54:16 +03:00
|
|
|
sScriptCacheCleaner = nullptr;
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
JS::RootingContext* rcx = RootingCx();
|
2016-08-11 15:39:22 +03:00
|
|
|
JS::Rooted<JSScript*> script(rcx);
|
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
|
|
|
}
|
|
|
|
|
2016-08-11 15:39:22 +03:00
|
|
|
JS::Rooted<JSObject*> global(rcx, mGlobal->GetJSObject());
|
2013-11-24 09:32:45 +04:00
|
|
|
if (global) {
|
2016-03-09 23:28:26 +03:00
|
|
|
AutoEntryScript aes(global, "message manager script load");
|
2014-09-29 17:34:21 +04:00
|
|
|
JSContext* cx = aes.cx();
|
2014-06-13 21:56:38 +04:00
|
|
|
if (script) {
|
|
|
|
if (aRunInGlobalScope) {
|
2016-06-01 06:34:40 +03:00
|
|
|
JS::RootedValue rval(cx);
|
|
|
|
JS::CloneAndExecuteScript(cx, script, &rval);
|
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(),
|
2015-08-22 06:33:23 +03:00
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
2014-09-21 20:36:25 +04:00
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
|
2010-08-10 21:18:26 +04:00
|
|
|
if (!channel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> input;
|
2015-08-22 06:33:23 +03:00
|
|
|
rv = channel->Open2(getter_AddRefs(input));
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
2010-08-10 21:18:26 +04:00
|
|
|
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) {
|
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.
|
2016-03-18 17:48:38 +03:00
|
|
|
AutoJSAPI jsapi;
|
|
|
|
if (!jsapi.Init(xpc::CompilationScope())) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JSContext* cx = jsapi.cx();
|
2015-02-09 22:42:20 +03:00
|
|
|
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-09-29 18:36:36 +03:00
|
|
|
// We're going to run these against some non-global scope.
|
|
|
|
} else if (!JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script)) {
|
|
|
|
return;
|
2015-02-09 22:42:20 +03:00
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2015-09-29 18:36:36 +03:00
|
|
|
MOZ_ASSERT(script);
|
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")) {
|
|
|
|
// Root the object also for caching.
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* holder = new nsMessageManagerScriptHolder(cx, script, aRunInGlobalScope);
|
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
|
|
|
{
|
2016-08-11 15:39:23 +03:00
|
|
|
JS::Rooted<JSScript*> script(RootingCx());
|
2014-06-13 21:56:38 +04:00
|
|
|
TryCacheLoadAndCompileScript(aURL, aRunInGlobalScope, true, &script);
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
|
|
|
|
2016-02-10 01:08:53 +03:00
|
|
|
void
|
|
|
|
nsMessageManagerScriptExecutor::Trace(const TraceCallbacks& aCallbacks, void* aClosure)
|
|
|
|
{
|
|
|
|
for (size_t i = 0, length = mAnonymousGlobalScopes.Length(); i < length; ++i) {
|
|
|
|
aCallbacks.Trace(&mAnonymousGlobalScopes[i], "mAnonymousGlobalScopes[i]", aClosure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-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;
|
2017-02-11 02:47:50 +03:00
|
|
|
options.creationOptions().setSystemZone();
|
2015-12-29 01:15:52 +03:00
|
|
|
options.behaviors().setVersion(JSVERSION_LATEST);
|
2013-06-30 19:00:20 +04:00
|
|
|
|
2016-01-06 18:31:38 +03:00
|
|
|
if (xpc::SharedMemoryEnabled()) {
|
|
|
|
options.creationOptions().setSharedMemoryAndAtomicsEnabled(true);
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-10-18 19:58:19 +03:00
|
|
|
mAnonymousGlobalScopes[i].exposeToActiveJS();
|
2015-02-25 01:23:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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,
|
2016-04-26 03:23:21 +03:00
|
|
|
public Runnable
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-08-12 12:39:16 +03:00
|
|
|
nsAsyncMessageToSameProcessChild(JS::RootingContext* aRootingCx,
|
|
|
|
JS::Handle<JSObject*> aCpows)
|
|
|
|
: nsSameProcessAsyncMessageBase(aRootingCx, aCpows)
|
2015-10-07 13:42:43 +03:00
|
|
|
{ }
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager* ppm = nsFrameMessageManager::GetChildProcessManager();
|
2015-04-16 18:17:54 +03:00
|
|
|
ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm), nullptr, 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);
|
|
|
|
}
|
2016-11-15 14:09:07 +03:00
|
|
|
~SameParentProcessMessageManagerCallback() override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(SameParentProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
bool DoLoadMessageManagerScript(const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope) override
|
2015-02-20 04:13:02 +03:00
|
|
|
{
|
|
|
|
ProcessGlobal* global = ProcessGlobal::Get();
|
|
|
|
MOZ_ASSERT(!aRunInGlobalScope);
|
|
|
|
global->LoadScript(aURL);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2016-08-12 12:39:16 +03:00
|
|
|
JS::RootingContext* rcx = JS::RootingContext::get(aCx);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncMessageToSameProcessChild> ev =
|
2016-08-12 12:39:16 +03:00
|
|
|
new nsAsyncMessageToSameProcessChild(rcx, aCpows);
|
2015-10-07 13:42:43 +03:00
|
|
|
|
2016-08-12 12:39:16 +03:00
|
|
|
nsresult rv = ev->Init(aMessage, aData, aPrincipal);
|
2015-10-07 13:42:43 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
rv = NS_DispatchToCurrentThread(ev);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
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);
|
|
|
|
}
|
2016-11-15 14:09:07 +03:00
|
|
|
~ChildProcessMessageManagerCallback() override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(ChildProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
|
|
|
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;
|
2015-09-10 23:50:58 +03:00
|
|
|
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
|
2013-01-24 06:39:27 +04:00
|
|
|
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,
|
2015-04-30 06:39:59 +03:00
|
|
|
IPC::Principal(aPrincipal), aRetVal);
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
2014-10-08 08:32:45 +04:00
|
|
|
return cc->SendRpcMessage(PromiseFlatString(aMessage), data, cpows,
|
2015-04-30 06:39:59 +03:00
|
|
|
IPC::Principal(aPrincipal), aRetVal);
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
mozilla::dom::ContentChild* cc =
|
|
|
|
mozilla::dom::ContentChild::GetSingleton();
|
|
|
|
if (!cc) {
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_OK;
|
2011-10-11 14:28:46 +04:00
|
|
|
}
|
2012-08-02 10:02:29 +04:00
|
|
|
ClonedMessageData data;
|
2015-09-10 23:50:58 +03:00
|
|
|
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_ERROR_DOM_DATA_CLONE_ERR;
|
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)) {
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2016-04-09 16:50:59 +03:00
|
|
|
if (!cc->SendAsyncMessage(PromiseFlatString(aMessage), cpows,
|
|
|
|
IPC::Principal(aPrincipal), data)) {
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-09-28 09:43:12 +04:00
|
|
|
};
|
|
|
|
|
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:
|
2016-08-12 12:39:16 +03:00
|
|
|
nsAsyncMessageToSameProcessParent(JS::RootingContext* aRootingCx,
|
|
|
|
JS::Handle<JSObject*> aCpows)
|
|
|
|
: nsSameProcessAsyncMessageBase(aRootingCx, aCpows)
|
2015-10-07 13:42:43 +03:00
|
|
|
{ }
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult HandleMessage() override
|
2011-10-11 14:28:46 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
nsFrameMessageManager* ppm = nsFrameMessageManager::sSameProcessParentManager;
|
2015-04-16 18:17:54 +03:00
|
|
|
ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm), nullptr, 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
|
|
|
}
|
2016-11-15 14:09:07 +03:00
|
|
|
~SameChildProcessMessageManagerCallback() override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(SameChildProcessMessageManagerCallback);
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal,
|
|
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
|
|
|
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) {
|
2016-08-12 12:39:16 +03:00
|
|
|
SameProcessCpowHolder cpows(JS::RootingContext::get(aCx), aCpows);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> ppm = nsFrameMessageManager::sSameProcessParentManager;
|
2015-04-16 18:17:54 +03:00
|
|
|
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), nullptr, aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
true, &aData, &cpows, aPrincipal, aRetVal);
|
2012-09-28 09:43:12 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal) override
|
2012-09-28 09:43:12 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
2016-08-12 12:39:16 +03:00
|
|
|
JS::RootingContext* rcx = JS::RootingContext::get(aCx);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsAsyncMessageToSameProcessParent> ev =
|
2016-08-12 12:39:16 +03:00
|
|
|
new nsAsyncMessageToSameProcessParent(rcx, aCpows);
|
|
|
|
nsresult rv = ev->Init(aMessage, aData, aPrincipal);
|
2015-10-07 13:42:43 +03:00
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-03-24 23:05:39 +03:00
|
|
|
queue->Push(ev);
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_OK;
|
2012-09-28 09:43:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
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");
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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;
|
2015-07-04 04:29:00 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
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
|
|
|
}
|
2016-11-14 12:35:58 +03:00
|
|
|
auto* mm = new nsFrameMessageManager(cb, nullptr,
|
|
|
|
MM_PROCESSMANAGER | MM_OWNSCALLBACK);
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager::SetChildProcessManager(mm);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<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;
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
2012-01-26 19:39:23 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
bool
|
|
|
|
nsFrameMessageManager::MarkForCC()
|
|
|
|
{
|
2015-11-05 08:35:12 +03:00
|
|
|
for (auto iter = mListeners.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners = iter.UserData();
|
|
|
|
uint32_t count = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < count; i++) {
|
|
|
|
nsCOMPtr<nsIMessageListener> strongListener =
|
|
|
|
listeners->ElementAt(i).mStrongListener;
|
|
|
|
if (strongListener) {
|
|
|
|
xpc_TryUnmarkWrappedGrayObject(strongListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
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
|
|
|
|
2016-08-12 12:39:16 +03:00
|
|
|
nsSameProcessAsyncMessageBase::nsSameProcessAsyncMessageBase(JS::RootingContext* aRootingCx,
|
|
|
|
JS::Handle<JSObject*> aCpows)
|
|
|
|
: mRootingCx(aRootingCx)
|
|
|
|
, mCpows(aRootingCx, aCpows)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mCalledInit(false)
|
|
|
|
#endif
|
2015-10-07 13:42:43 +03:00
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2016-08-12 12:39:16 +03:00
|
|
|
nsSameProcessAsyncMessageBase::Init(const nsAString& aMessage,
|
2015-10-07 13:42:43 +03:00
|
|
|
StructuredCloneData& aData,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2014-03-12 18:22:00 +04:00
|
|
|
{
|
2015-09-10 23:50:58 +03:00
|
|
|
if (!mData.Copy(aData)) {
|
2015-10-07 13:42:43 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IPC_SAME_PROCESS_MESSAGE_COPY_OOM_KB, aData.DataLength());
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2014-03-12 18:22:00 +04:00
|
|
|
}
|
2015-10-07 13:42:43 +03:00
|
|
|
|
|
|
|
mMessage = aMessage;
|
|
|
|
mPrincipal = aPrincipal;
|
2016-08-12 12:39:16 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
mCalledInit = true;
|
|
|
|
#endif
|
2015-10-07 13:42:43 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2014-03-12 18:22:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsSameProcessAsyncMessageBase::ReceiveMessage(nsISupports* aTarget,
|
2015-04-16 18:17:54 +03:00
|
|
|
nsIFrameLoader* aTargetFrameLoader,
|
2014-03-12 18:22:00 +04:00
|
|
|
nsFrameMessageManager* aManager)
|
|
|
|
{
|
2015-10-07 13:42:43 +03:00
|
|
|
// Make sure that we have called Init() and it has succeeded.
|
2016-08-12 12:39:16 +03:00
|
|
|
MOZ_ASSERT(mCalledInit);
|
2014-03-12 18:22:00 +04:00
|
|
|
if (aManager) {
|
2016-08-12 12:39:16 +03:00
|
|
|
SameProcessCpowHolder cpows(mRootingCx, mCpows);
|
2014-03-12 18:22:00 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm = aManager;
|
2015-09-10 23:50:58 +03:00
|
|
|
mm->ReceiveMessage(aTarget, aTargetFrameLoader, mMessage, false, &mData,
|
2015-09-02 19:20:30 +03:00
|
|
|
&cpows, mPrincipal, nullptr);
|
2014-03-12 18:22:00 +04:00
|
|
|
}
|
|
|
|
}
|