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"
|
2017-06-16 23:34:12 +03:00
|
|
|
#include "GeckoProfiler.h"
|
2017-05-10 20:12:36 +03:00
|
|
|
#include "nsASCIIMask.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsIXPConnect.h"
|
|
|
|
#include "jsapi.h"
|
2014-06-13 21:56:38 +04:00
|
|
|
#include "jsfriendapi.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsJSUtils.h"
|
2012-03-09 13:48:50 +04:00
|
|
|
#include "nsJSPrincipals.h"
|
2010-08-10 21:18:26 +04:00
|
|
|
#include "nsNetUtil.h"
|
2017-05-08 09:24:22 +03:00
|
|
|
#include "mozilla/dom/ScriptLoader.h"
|
2012-09-28 09:43:12 +04:00
|
|
|
#include "nsFrameLoader.h"
|
2017-02-16 20:26:38 +03:00
|
|
|
#include "nsIInputStream.h"
|
2010-08-31 22:58:35 +04:00
|
|
|
#include "nsIXULRuntime.h"
|
2011-03-18 07:08:18 +03:00
|
|
|
#include "nsIScriptError.h"
|
|
|
|
#include "nsIConsoleService.h"
|
2014-03-05 03:39:42 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2011-05-19 18:48:17 +04:00
|
|
|
#include "nsIProtocolHandler.h"
|
2011-11-30 19:51:40 +04:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "xpcpublic.h"
|
2018-08-25 06:51:49 +03:00
|
|
|
#include "js/CompilationAndEvaluation.h"
|
2018-08-20 17:54:45 +03:00
|
|
|
#include "js/JSON.h"
|
2018-11-09 05:42:48 +03:00
|
|
|
#include "js/SourceText.h"
|
2018-02-14 19:35:39 +03:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2016-09-14 16:47:32 +03:00
|
|
|
#include "mozilla/CycleCollectedJSContext.h"
|
2012-06-07 06:52:14 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2017-05-03 01:16:55 +03:00
|
|
|
#include "mozilla/ScriptPreloader.h"
|
2015-10-07 13:42:43 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2017-06-14 17:44:17 +03:00
|
|
|
#include "mozilla/dom/ChildProcessMessageManager.h"
|
|
|
|
#include "mozilla/dom/ChromeMessageBroadcaster.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2017-06-20 12:09:50 +03:00
|
|
|
#include "mozilla/dom/MessageManagerBinding.h"
|
2016-02-01 00:48:00 +03:00
|
|
|
#include "mozilla/dom/MessagePort.h"
|
2017-02-21 13:27:23 +03:00
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2018-08-03 01:03:50 +03:00
|
|
|
#include "mozilla/dom/ContentProcessMessageManager.h"
|
2018-04-16 16:18:48 +03:00
|
|
|
#include "mozilla/dom/ParentProcessMessageManager.h"
|
2014-06-11 09:44:03 +04:00
|
|
|
#include "mozilla/dom/PermissionMessageUtils.h"
|
2018-04-16 16:18:48 +03:00
|
|
|
#include "mozilla/dom/ProcessMessageManager.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"
|
2017-06-20 12:09:50 +03:00
|
|
|
#include "mozilla/dom/ToJSValue.h"
|
2018-06-23 06:35:49 +03:00
|
|
|
#include "mozilla/dom/ipc/SharedMap.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"
|
2018-09-03 01:38:24 +03:00
|
|
|
#include "mozilla/recordreplay/ParentIPC.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"
|
2017-06-20 12:09:50 +03:00
|
|
|
#include "xpcprivate.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
|
|
|
|
2012-08-07 00:41:40 +04:00
|
|
|
#ifdef XP_WIN
|
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
|
|
|
|
2017-03-01 03:24:43 +03:00
|
|
|
#ifdef FUZZING
|
|
|
|
# include "MessageManagerFuzzer.h"
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
nsFrameMessageManager::nsFrameMessageManager(MessageManagerCallback* aCallback,
|
|
|
|
MessageManagerFlags aFlags)
|
|
|
|
: mChrome(aFlags & MessageManagerFlags::MM_CHROME),
|
|
|
|
mGlobal(aFlags & MessageManagerFlags::MM_GLOBAL),
|
|
|
|
mIsProcessManager(aFlags & MessageManagerFlags::MM_PROCESSMANAGER),
|
|
|
|
mIsBroadcaster(aFlags & MessageManagerFlags::MM_BROADCASTER),
|
|
|
|
mOwnsCallback(aFlags & MessageManagerFlags::MM_OWNSCALLBACK),
|
2017-06-20 12:09:50 +03:00
|
|
|
mHandlingMessage(false),
|
|
|
|
mClosed(false),
|
|
|
|
mDisconnected(false),
|
|
|
|
mCallback(aCallback) {
|
2015-05-01 04:20:51 +03:00
|
|
|
NS_ASSERTION(!mIsBroadcaster || !mCallback,
|
|
|
|
"Broadcasters cannot have callbacks!");
|
|
|
|
if (mOwnsCallback) {
|
|
|
|
mOwnedCallback = aCallback;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFrameMessageManager::~nsFrameMessageManager() {
|
2017-06-20 12:09:50 +03:00
|
|
|
for (int32_t i = mChildManagers.Length(); i > 0; --i) {
|
|
|
|
mChildManagers[i - 1]->Disconnect(false);
|
2015-05-01 04:20:51 +03:00
|
|
|
}
|
|
|
|
if (mIsProcessManager) {
|
|
|
|
if (this == sParentProcessManager) {
|
|
|
|
sParentProcessManager = nullptr;
|
|
|
|
}
|
|
|
|
if (this == sChildProcessManager) {
|
|
|
|
sChildProcessManager = nullptr;
|
|
|
|
delete mozilla::dom::SameProcessMessageQueue::Get();
|
|
|
|
}
|
|
|
|
if (this == sSameProcessParentManager) {
|
|
|
|
sSameProcessParentManager = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
inline void ImplCycleCollectionTraverse(
|
|
|
|
nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
nsMessageListenerInfo& aField, const char* aName, uint32_t aFlags = 0) {
|
|
|
|
ImplCycleCollectionTraverse(aCallback, aField.mStrongListener, aName, aFlags);
|
|
|
|
ImplCycleCollectionTraverse(aCallback, aField.mWeakListener, aName, aFlags);
|
|
|
|
}
|
|
|
|
|
2013-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)
|
2017-06-20 12:09:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mListeners)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mChildManagers)
|
2018-07-27 00:36:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mSharedData)
|
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)
|
2017-06-20 12:09:50 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListeners)
|
|
|
|
for (int32_t i = tmp->mChildManagers.Length(); i > 0; --i) {
|
|
|
|
tmp->mChildManagers[i - 1]->Disconnect(false);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mChildManagers)
|
2018-07-27 00:36:57 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mSharedData)
|
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)
|
2018-08-03 06:49:09 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2012-08-27 18:13:02 +04:00
|
|
|
|
2018-02-10 13:20:51 +03:00
|
|
|
/* Message managers in child process implement nsIMessageSender.
|
|
|
|
Message managers in the chrome process are
|
2012-08-27 18:13:02 +04:00
|
|
|
either broadcasters (if they have subordinate/child message
|
|
|
|
managers) or they're simple message senders. */
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIMessageSender,
|
|
|
|
!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
|
|
|
|
2018-05-17 17:42:13 +03:00
|
|
|
void MessageManagerCallback::DoGetRemoteType(nsAString& aRemoteType,
|
|
|
|
ErrorResult& aError) const {
|
2018-02-16 12:34:21 +03:00
|
|
|
aRemoteType.Truncate();
|
2018-04-16 16:18:48 +03:00
|
|
|
mozilla::dom::ProcessMessageManager* parent = GetProcessMessageManager();
|
2018-02-16 12:34:21 +03:00
|
|
|
if (!parent) {
|
2018-05-17 17:42:13 +03:00
|
|
|
return;
|
2018-02-16 12:34:21 +03:00
|
|
|
}
|
|
|
|
|
2018-05-17 17:42:13 +03:00
|
|
|
parent->GetRemoteType(aRemoteType, aError);
|
2018-02-16 12:34:21 +03:00
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:03 +04:00
|
|
|
bool MessageManagerCallback::BuildClonedMessageDataForParent(
|
2015-09-10 23:50:58 +03:00
|
|
|
nsIContentParent* aParent, 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
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:06 +04:00
|
|
|
bool MessageManagerCallback::BuildClonedMessageDataForChild(
|
2015-09-10 23:50:58 +03:00
|
|
|
nsIContentChild* aChild, 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-10 23:50:58 +03:00
|
|
|
void mozilla::dom::ipc::UnpackClonedMessageDataForParent(
|
|
|
|
const ClonedMessageData& aClonedData, StructuredCloneData& aData) {
|
2016-11-07 16:38:02 +03:00
|
|
|
aData.BorrowFromClonedMessageDataForParent(aClonedData);
|
2013-01-24 20:24:19 +04:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
void mozilla::dom::ipc::UnpackClonedMessageDataForChild(
|
|
|
|
const ClonedMessageData& aClonedData, StructuredCloneData& aData) {
|
2016-11-07 16:38:02 +03:00
|
|
|
aData.BorrowFromClonedMessageDataForChild(aClonedData);
|
2013-01-24 20:24:19 +04:00
|
|
|
}
|
|
|
|
|
2013-11-11 12:04:41 +04:00
|
|
|
bool 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);
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::AddMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener,
|
|
|
|
bool aListenWhenClosed,
|
|
|
|
ErrorResult& aError) {
|
2018-02-16 17:28:31 +03:00
|
|
|
auto listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
|
2017-05-03 18:27:11 +03:00
|
|
|
return new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
|
|
|
|
});
|
|
|
|
uint32_t len = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2018-02-16 17:28:31 +03:00
|
|
|
MessageListener* strongListener = listeners->ElementAt(i).mStrongListener;
|
|
|
|
if (strongListener && *strongListener == aListener) {
|
2017-06-20 12:09:50 +03:00
|
|
|
return;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
|
|
|
nsMessageListenerInfo* entry = listeners->AppendElement();
|
2018-02-16 17:28:31 +03:00
|
|
|
entry->mStrongListener = &aListener;
|
2015-02-27 08:35:26 +03:00
|
|
|
entry->mListenWhenClosed = aListenWhenClosed;
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameMessageManager::RemoveMessageListener(const nsAString& aMessageName,
|
|
|
|
MessageListener& aListener,
|
|
|
|
ErrorResult& aError) {
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
2018-02-16 17:28:31 +03:00
|
|
|
mListeners.Get(aMessageName);
|
2017-06-20 12:09:50 +03:00
|
|
|
if (listeners) {
|
|
|
|
uint32_t len = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2018-02-16 17:28:31 +03:00
|
|
|
MessageListener* strongListener = listeners->ElementAt(i).mStrongListener;
|
|
|
|
if (strongListener && *strongListener == aListener) {
|
2017-06-20 12:09:50 +03:00
|
|
|
listeners->RemoveElementAt(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
static already_AddRefed<nsISupports> ToXPCOMMessageListener(
|
2017-06-20 12:09:50 +03:00
|
|
|
MessageListener& aListener) {
|
2018-02-16 17:28:31 +03:00
|
|
|
return CallbackObjectHolder<mozilla::dom::MessageListener, nsISupports>(
|
|
|
|
&aListener)
|
|
|
|
.ToXPCOMCallback();
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsFrameMessageManager::AddWeakMessageListener(
|
|
|
|
const nsAString& aMessageName, MessageListener& aListener,
|
|
|
|
ErrorResult& aError) {
|
2018-02-16 17:28:31 +03:00
|
|
|
nsCOMPtr<nsISupports> listener(ToXPCOMMessageListener(aListener));
|
|
|
|
nsWeakPtr weak = do_GetWeakReference(listener);
|
|
|
|
if (!weak) {
|
|
|
|
aError.Throw(NS_ERROR_NO_INTERFACE);
|
2017-06-20 12:09:50 +03:00
|
|
|
return;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
|
2013-08-08 22:36:56 +04:00
|
|
|
#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.
|
2018-02-16 17:28:31 +03:00
|
|
|
nsCOMPtr<nsISupports> canonical = do_QueryInterface(listener);
|
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
|
|
|
|
|
2018-02-16 17:28:31 +03:00
|
|
|
auto listeners = mListeners.LookupForAdd(aMessageName).OrInsert([]() {
|
2017-05-03 18:27:11 +03:00
|
|
|
return new nsAutoTObserverArray<nsMessageListenerInfo, 1>();
|
|
|
|
});
|
|
|
|
uint32_t len = listeners->Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
if (listeners->ElementAt(i).mWeakListener == weak) {
|
2018-02-16 17:28:31 +03:00
|
|
|
return;
|
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
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::RemoveWeakMessageListener(
|
|
|
|
const nsAString& aMessageName, MessageListener& aListener,
|
|
|
|
ErrorResult& aError) {
|
2018-02-16 17:28:31 +03:00
|
|
|
nsCOMPtr<nsISupports> listener(ToXPCOMMessageListener(aListener));
|
|
|
|
nsWeakPtr weak = do_GetWeakReference(listener);
|
|
|
|
if (!weak) {
|
|
|
|
aError.Throw(NS_ERROR_NO_INTERFACE);
|
2017-06-20 12:09:50 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-05 15:52:04 +04:00
|
|
|
nsAutoTObserverArray<nsMessageListenerInfo, 1>* listeners =
|
2018-02-16 17:28:31 +03:00
|
|
|
mListeners.Get(aMessageName);
|
2013-10-26 01:55:16 +04:00
|
|
|
if (!listeners) {
|
2018-02-16 17:28:31 +03:00
|
|
|
return;
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-02-16 17:28:31 +03:00
|
|
|
return;
|
2013-08-08 22:36:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
void nsFrameMessageManager::LoadScript(const nsAString& aURL,
|
|
|
|
bool aAllowDelayedLoad,
|
2017-06-20 12:09:50 +03:00
|
|
|
bool aRunInGlobalScope,
|
|
|
|
ErrorResult& aError) {
|
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
|
2017-06-20 12:09:50 +03:00
|
|
|
if (!mCallback->DoLoadMessageManagerScript(aURL, aRunInGlobalScope)) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
for (uint32_t i = 0; i < mChildManagers.Length(); ++i) {
|
|
|
|
RefPtr<nsFrameMessageManager> mm = 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.
|
2017-06-20 12:09:50 +03:00
|
|
|
mm->LoadScript(aURL, false, aRunInGlobalScope, IgnoreErrors());
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:13:02 +03:00
|
|
|
void nsFrameMessageManager::RemoveDelayedScript(const nsAString& aURL) {
|
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
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::GetDelayedScripts(
|
|
|
|
JSContext* aCx, nsTArray<nsTArray<JS::Value>>& aList, ErrorResult& aError) {
|
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");
|
2017-06-20 12:09:50 +03:00
|
|
|
aError.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
2013-08-09 06:36:37 +04:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
aError.MightThrowJSException();
|
2013-08-09 06:36:37 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
aList.SetCapacity(mPendingScripts.Length());
|
2013-08-09 06:36:37 +04:00
|
|
|
for (uint32_t i = 0; i < mPendingScripts.Length(); ++i) {
|
2017-06-20 12:09:50 +03:00
|
|
|
JS::Rooted<JS::Value> url(aCx);
|
|
|
|
if (!ToJSValue(aCx, mPendingScripts[i], &url)) {
|
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
return;
|
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
nsTArray<JS::Value>* array = aList.AppendElement(2);
|
|
|
|
array->AppendElement(url);
|
|
|
|
array->AppendElement(JS::BooleanValue(mPendingScriptsGlobalStates[i]));
|
|
|
|
}
|
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2012-08-02 10:02:29 +04:00
|
|
|
static bool GetParamsForMessage(JSContext* aCx, 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) {
|
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,
|
2018-03-13 08:40:38 +03:00
|
|
|
nsIScriptError::warningFlag, "chrome javascript",
|
|
|
|
false /* from private window */);
|
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;
|
2018-08-07 19:01:27 +03:00
|
|
|
NS_ENSURE_TRUE(nsContentUtils::StringifyJSON(aCx, &v, 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
|
|
|
}
|
|
|
|
|
2013-10-01 20:15:06 +04:00
|
|
|
static bool sSendingSyncMessage = false;
|
|
|
|
|
2016-06-09 19:35:19 +03:00
|
|
|
static bool AllowMessage(size_t aDataLength, const nsAString& aMessageName) {
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2017-05-04 11:34:20 +03:00
|
|
|
NS_ConvertUTF16toUTF8 messageName(aMessageName);
|
2017-05-10 20:12:36 +03:00
|
|
|
messageName.StripTaggedASCII(ASCIIMask::Mask0to9());
|
2017-05-04 11:34:20 +03:00
|
|
|
|
2016-06-09 19:35:19 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::REJECTED_MESSAGE_MANAGER_MESSAGE,
|
|
|
|
messageName);
|
|
|
|
|
|
|
|
return false;
|
2016-06-02 01:11:06 +03:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::SendMessage(
|
|
|
|
JSContext* aCx, const nsAString& aMessageName, JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects, nsIPrincipal* aPrincipal, bool aIsSync,
|
|
|
|
nsTArray<JS::Value>& aResult, ErrorResult& aError) {
|
2018-05-17 17:42:13 +03:00
|
|
|
NS_ASSERTION(!IsGlobal(), "Should not call SendSyncMessage in chrome");
|
|
|
|
NS_ASSERTION(!IsBroadcaster(), "Should not call SendSyncMessage in chrome");
|
|
|
|
NS_ASSERTION(!GetParentManager(),
|
|
|
|
"Should not have parent manager in content!");
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING(
|
2018-05-19 00:36:30 +03:00
|
|
|
"nsFrameMessageManager::SendMessage", OTHER, aMessageName);
|
2017-06-20 12:09:50 +03:00
|
|
|
|
|
|
|
if (sSendingSyncMessage && aIsSync) {
|
|
|
|
// No kind of blocking send should be issued on top of a sync message.
|
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StructuredCloneData data;
|
|
|
|
if (!aObj.isUndefined() &&
|
|
|
|
!GetParamsForMessage(aCx, aObj, JS::UndefinedHandleValue, data)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-01 03:24:43 +03:00
|
|
|
#ifdef FUZZING
|
2018-05-17 17:42:13 +03:00
|
|
|
if (data.DataLength() > 0) {
|
2017-03-01 03:24:43 +03:00
|
|
|
MessageManagerFuzzer::TryMutate(aCx, aMessageName, &data,
|
|
|
|
JS::UndefinedHandleValue);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-05-17 17:42:13 +03:00
|
|
|
if (!AllowMessage(data.DataLength(), aMessageName)) {
|
2018-05-16 23:29:37 +03:00
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
if (!mCallback) {
|
|
|
|
aError.Throw(NS_ERROR_NOT_INITIALIZED);
|
|
|
|
return;
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
|
|
|
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData> retval;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2017-03-21 01:18:55 +03:00
|
|
|
TimeStamp start = TimeStamp::Now();
|
2013-10-01 20:15:06 +04:00
|
|
|
sSendingSyncMessage |= aIsSync;
|
2018-05-17 17:42:13 +03:00
|
|
|
bool ok = mCallback->DoSendBlockingMessage(aCx, aMessageName, data, aObjects,
|
2013-11-06 21:21:15 +04:00
|
|
|
aPrincipal, &retval, aIsSync);
|
2013-10-01 20:15:06 +04:00
|
|
|
if (aIsSync) {
|
|
|
|
sSendingSyncMessage = false;
|
|
|
|
}
|
|
|
|
|
2017-03-21 01:18:55 +03:00
|
|
|
uint32_t latencyMs = round((TimeStamp::Now() - start).ToMilliseconds());
|
|
|
|
if (latencyMs >= kMinTelemetrySyncMessageManagerLatencyMs) {
|
2017-03-28 21:19:06 +03:00
|
|
|
NS_ConvertUTF16toUTF8 messageName(aMessageName);
|
|
|
|
// NOTE: We need to strip digit characters from the message name in order to
|
|
|
|
// avoid a large number of buckets due to generated names from addons (such
|
|
|
|
// as "ublock:sb:{N}"). See bug 1348113 comment 10.
|
2017-05-10 20:12:36 +03:00
|
|
|
messageName.StripTaggedASCII(ASCIIMask::Mask0to9());
|
2017-03-21 01:18:55 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::IPC_SYNC_MESSAGE_MANAGER_LATENCY_MS,
|
2017-03-28 21:19:06 +03:00
|
|
|
messageName, latencyMs);
|
2017-03-21 01:18:55 +03:00
|
|
|
}
|
|
|
|
|
2015-09-02 19:20:30 +03:00
|
|
|
if (!ok) {
|
2017-06-20 12:09:50 +03:00
|
|
|
return;
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t len = retval.Length();
|
2017-06-20 12:09:50 +03:00
|
|
|
aResult.SetCapacity(len);
|
2013-10-01 20:15:06 +04:00
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
|
|
|
JS::Rooted<JS::Value> ret(aCx);
|
2017-06-20 12:09:50 +03:00
|
|
|
retval[i].Read(aCx, &ret, aError);
|
|
|
|
if (aError.Failed()) {
|
2015-04-30 06:39:59 +03:00
|
|
|
MOZ_ASSERT(false, "Unable to read structured clone in SendMessage");
|
2017-06-20 12:09:50 +03:00
|
|
|
return;
|
2013-10-01 20:15:06 +04:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
aResult.AppendElement(ret);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-11 02:05:39 +04:00
|
|
|
nsresult nsFrameMessageManager::DispatchAsyncMessageInternal(
|
2015-09-10 23:50:58 +03:00
|
|
|
JSContext* aCx, const nsAString& aMessage, StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject*> aCpows, nsIPrincipal* aPrincipal) {
|
2012-09-28 09:43:12 +04:00
|
|
|
if (mIsBroadcaster) {
|
2017-06-20 12:09:50 +03:00
|
|
|
uint32_t len = mChildManagers.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2015-09-10 23:50:58 +03:00
|
|
|
mChildManagers[i]->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;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::DispatchAsyncMessage(
|
|
|
|
JSContext* aCx, const nsAString& aMessageName, JS::Handle<JS::Value> aObj,
|
|
|
|
JS::Handle<JSObject*> aObjects, nsIPrincipal* aPrincipal,
|
|
|
|
JS::Handle<JS::Value> aTransfers, ErrorResult& aError) {
|
|
|
|
StructuredCloneData data;
|
|
|
|
if (!aObj.isUndefined() &&
|
|
|
|
!GetParamsForMessage(aCx, aObj, aTransfers, data)) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_DATA_CLONE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-16 23:29:37 +03:00
|
|
|
#ifdef FUZZING
|
|
|
|
if (data.DataLength()) {
|
|
|
|
MessageManagerFuzzer::TryMutate(aCx, aMessageName, &data, aTransfers);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!AllowMessage(data.DataLength(), aMessageName)) {
|
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
aError = DispatchAsyncMessageInternal(aCx, aMessageName, data, aObjects,
|
|
|
|
aPrincipal);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2018-07-23 17:50:39 +03:00
|
|
|
// When recording or replaying, return whether a message should be received in
|
|
|
|
// the middleman process instead of the recording/replaying process.
|
|
|
|
static bool DirectMessageToMiddleman(const nsAString& aMessage) {
|
|
|
|
// Middleman processes run developer tools server code and need to receive
|
|
|
|
// debugger related messages. The session store flush message needs to be
|
|
|
|
// received in order to cleanly shutdown the process.
|
2018-09-03 01:38:24 +03:00
|
|
|
return (StringBeginsWith(aMessage, NS_LITERAL_STRING("debug:")) &&
|
|
|
|
recordreplay::parent::DebuggerRunsInMiddleman()) ||
|
2018-07-23 17:50:39 +03:00
|
|
|
aMessage.EqualsLiteral("SessionStore:flush");
|
|
|
|
}
|
2012-08-27 18:13:02 +04:00
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
void nsFrameMessageManager::ReceiveMessage(
|
2018-03-22 05:43:17 +03:00
|
|
|
nsISupports* aTarget, nsFrameLoader* aTargetFrameLoader, bool aTargetClosed,
|
2015-09-10 23:50:58 +03:00
|
|
|
const nsAString& aMessage, bool aIsSync, StructuredCloneData* aCloneData,
|
2015-02-27 08:35:26 +03:00
|
|
|
mozilla::jsipc::CpowHolder* aCpows, nsIPrincipal* aPrincipal,
|
2018-02-16 17:28:31 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal, ErrorResult& aError) {
|
2018-07-23 17:50:39 +03:00
|
|
|
// If we are recording or replaying, we will end up here in both the
|
|
|
|
// middleman process and the recording/replaying process. Ignore the message
|
|
|
|
// in one of the processes, so that it is only received in one place.
|
|
|
|
if (recordreplay::IsRecordingOrReplaying()) {
|
|
|
|
if (DirectMessageToMiddleman(aMessage)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (recordreplay::IsMiddleman()) {
|
|
|
|
if (!DirectMessageToMiddleman(aMessage)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
MOZ_ASSERT(aTarget);
|
|
|
|
|
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) {
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
JS::RootingContext* rcx = RootingCx();
|
|
|
|
JS::Rooted<JSObject*> object(rcx);
|
2018-08-07 12:57:51 +03:00
|
|
|
JS::Rooted<JSObject*> objectGlobal(rcx);
|
2017-06-20 12:09:50 +03:00
|
|
|
|
|
|
|
RefPtr<MessageListener> webIDLListener;
|
2018-02-16 17:28:31 +03:00
|
|
|
if (!weakListener) {
|
|
|
|
webIDLListener = listener.mStrongListener;
|
2017-06-20 12:09:50 +03:00
|
|
|
object = webIDLListener->CallbackOrNull();
|
2018-08-07 12:57:51 +03:00
|
|
|
objectGlobal = webIDLListener->CallbackGlobalOrNull();
|
2017-06-20 12:09:50 +03:00
|
|
|
} else {
|
2018-02-16 17:28:31 +03:00
|
|
|
nsCOMPtr<nsIXPConnectWrappedJS> wrappedJS =
|
|
|
|
do_QueryInterface(weakListener);
|
2017-06-20 12:09:50 +03:00
|
|
|
if (!wrappedJS) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
object = wrappedJS->GetJSObject();
|
2018-08-07 12:57:51 +03:00
|
|
|
objectGlobal = wrappedJS->GetJSObjectGlobal();
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2014-09-15 16:17:32 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
if (!object) {
|
2013-10-26 01:55:16 +04:00
|
|
|
continue;
|
|
|
|
}
|
2014-09-15 16:17:32 +04:00
|
|
|
|
2018-07-25 11:42:27 +03:00
|
|
|
AutoEntryScript aes(js::UncheckedUnwrap(object),
|
|
|
|
"message manager handler");
|
2014-09-15 16:17:32 +04:00
|
|
|
JSContext* cx = aes.cx();
|
2018-03-01 12:51:09 +03:00
|
|
|
|
2018-07-25 11:42:27 +03:00
|
|
|
// We passed the unwrapped object to AutoEntryScript so we now need to
|
2018-08-07 12:57:51 +03:00
|
|
|
// enter the realm of the global object that represents the realm of our
|
2018-08-04 00:11:39 +03:00
|
|
|
// callback.
|
2018-08-07 12:57:51 +03:00
|
|
|
JSAutoRealm ar(cx, objectGlobal);
|
2018-07-25 11:42:27 +03:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
RootedDictionary<ReceiveMessageArgument> argument(cx);
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2014-01-16 23:43:29 +04:00
|
|
|
JS::Rooted<JSObject*> cpows(cx);
|
2018-02-16 17:28:31 +03:00
|
|
|
if (aCpows && !aCpows->ToObject(cx, &cpows)) {
|
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
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) {
|
2018-02-16 17:28:31 +03:00
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2013-07-11 02:05:39 +04:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
argument.mObjects = 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()) {
|
2018-02-16 17:28:31 +03:00
|
|
|
aCloneData->Read(cx, &json, aError);
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
|
|
|
aError.SuppressException();
|
2015-09-02 19:20:30 +03:00
|
|
|
JS_ClearPendingException(cx);
|
2018-02-16 17:28:31 +03:00
|
|
|
return;
|
2015-09-02 19:20:30 +03:00
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
argument.mData = json;
|
|
|
|
argument.mJson = json;
|
2016-02-01 00:48:00 +03:00
|
|
|
|
|
|
|
// Get cloned MessagePort from StructuredCloneData.
|
|
|
|
if (aCloneData) {
|
2017-06-20 12:09:50 +03:00
|
|
|
Sequence<OwningNonNull<MessagePort>> ports;
|
|
|
|
if (!aCloneData->TakeTransferredPortsAsSequence(ports)) {
|
2018-02-16 17:28:31 +03:00
|
|
|
aError.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
argument.mPorts.Construct(std::move(ports));
|
2016-02-01 00:48:00 +03:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
argument.mName = aMessage;
|
|
|
|
argument.mPrincipal = aPrincipal;
|
|
|
|
argument.mSync = aIsSync;
|
|
|
|
argument.mTarget = aTarget;
|
2015-04-16 18:17:54 +03:00
|
|
|
if (aTargetFrameLoader) {
|
2018-03-22 05:43:17 +03:00
|
|
|
argument.mTargetFrameLoader.Construct(*aTargetFrameLoader);
|
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-09-25 15:13:28 +04:00
|
|
|
if (JS::IsCallable(object)) {
|
2013-10-26 01:55:16 +04:00
|
|
|
// A small hack to get 'this' value right on content side where
|
2018-08-11 00:04:23 +03:00
|
|
|
// messageManager is wrapped in TabChildMessageManager's global.
|
2013-10-26 01:55:16 +04:00
|
|
|
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);
|
2018-02-16 17:28:31 +03:00
|
|
|
aError = nsContentUtils::WrapNative(cx, defaultThisValue, &thisValue);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-01-14 10:59:06 +03:00
|
|
|
JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
|
2017-06-20 12:09:50 +03:00
|
|
|
if (webIDLListener) {
|
2018-02-16 17:28:31 +03:00
|
|
|
webIDLListener->ReceiveMessage(thisValue, argument, &rval, aError);
|
|
|
|
if (aError.Failed()) {
|
2017-06-20 12:09:50 +03:00
|
|
|
// At this point the call to ReceiveMessage will have reported any
|
|
|
|
// exceptions (we kept the default of eReportExceptions). We suppress
|
|
|
|
// the failure in the ErrorResult and continue.
|
2018-02-16 17:28:31 +03:00
|
|
|
aError.SuppressException();
|
2017-06-20 12:09:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
JS::Rooted<JS::Value> funval(cx);
|
|
|
|
if (JS::IsCallable(object)) {
|
|
|
|
// If the listener is a JS function:
|
|
|
|
funval.setObject(*object);
|
|
|
|
} else {
|
|
|
|
// If the listener is a JS object which has receiveMessage function:
|
|
|
|
if (!JS_GetProperty(cx, object, "receiveMessage", &funval) ||
|
|
|
|
!funval.isObject()) {
|
2018-02-16 17:28:31 +03:00
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
// Check if the object is even callable.
|
2018-02-16 17:28:31 +03:00
|
|
|
if (!JS::IsCallable(&funval.toObject())) {
|
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
thisValue.setObject(*object);
|
|
|
|
}
|
2010-10-11 02:46:16 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
JS::Rooted<JS::Value> argv(cx);
|
|
|
|
if (!ToJSValue(cx, argument, &argv)) {
|
2018-02-16 17:28:31 +03:00
|
|
|
aError.Throw(NS_ERROR_UNEXPECTED);
|
|
|
|
return;
|
2013-10-26 01:55:16 +04:00
|
|
|
}
|
2010-10-11 02:46:16 +04:00
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
{
|
|
|
|
JS::Rooted<JSObject*> thisObject(cx, thisValue.toObjectOrNull());
|
|
|
|
js::AssertSameCompartment(cx, thisObject);
|
|
|
|
if (!JS_CallFunctionValue(cx, thisObject, funval,
|
|
|
|
JS::HandleValueArray(argv), &rval)) {
|
|
|
|
// Because the AutoEntryScript is inside the loop this continue will
|
|
|
|
// make us report any exceptions (after which we'll move on to the
|
|
|
|
// next listener).
|
2018-03-01 12:51:09 +03:00
|
|
|
continue;
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
|
|
|
|
if (aRetVal) {
|
|
|
|
StructuredCloneData* data = aRetVal->AppendElement();
|
2018-04-03 21:17:33 +03:00
|
|
|
data->InitScope(JS::StructuredCloneScope::DifferentProcess);
|
2018-02-16 17:28:31 +03:00
|
|
|
data->Write(cx, rval, aError);
|
|
|
|
if (NS_WARN_IF(aError.Failed())) {
|
2018-03-21 23:27:21 +03:00
|
|
|
aRetVal->RemoveLastElement();
|
2017-06-20 12:09:50 +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",
|
|
|
|
false /* from private window */);
|
|
|
|
console->LogMessage(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
JS_ClearPendingException(cx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
2016-08-24 21:12:09 +03:00
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
RefPtr<nsFrameMessageManager> kungFuDeathGrip = GetParentManager();
|
2016-08-24 21:12:09 +03:00
|
|
|
if (kungFuDeathGrip) {
|
2018-02-16 17:28:31 +03:00
|
|
|
kungFuDeathGrip->ReceiveMessage(aTarget, aTargetFrameLoader, aTargetClosed,
|
|
|
|
aMessage, aIsSync, aCloneData, aCpows,
|
|
|
|
aPrincipal, aRetVal, aError);
|
2016-08-24 21:12:09 +03:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2014-05-23 16:52:36 +04:00
|
|
|
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.
|
2017-06-14 17:44:17 +03:00
|
|
|
nsFrameMessageManager* parentManager = aManager->GetParentManager();
|
|
|
|
if (parentManager) {
|
|
|
|
LoadPendingScripts(parentManager, 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) {
|
2018-02-10 01:31:39 +03:00
|
|
|
aChildMM->LoadScript(aManager->mPendingScripts[i], false,
|
|
|
|
aManager->mPendingScriptsGlobalStates[i],
|
|
|
|
IgnoreErrors());
|
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);
|
|
|
|
}
|
|
|
|
|
2014-01-31 22:45:54 +04:00
|
|
|
void nsFrameMessageManager::SetCallback(MessageManagerCallback* aCallback) {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
void nsFrameMessageManager::Close() {
|
|
|
|
if (!mClosed) {
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
if (obs) {
|
2018-04-16 16:18:48 +03:00
|
|
|
obs->NotifyObservers(this, "message-manager-close", nullptr);
|
2015-02-27 08:35:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mClosed = true;
|
|
|
|
mCallback = nullptr;
|
|
|
|
mOwnedCallback = nullptr;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void nsFrameMessageManager::Disconnect(bool aRemoveFromParent) {
|
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) {
|
2018-04-16 16:18:48 +03:00
|
|
|
obs->NotifyObservers(this, "message-manager-disconnect", nullptr);
|
2013-07-01 17:46:53 +04:00
|
|
|
}
|
|
|
|
}
|
2017-06-14 17:44:17 +03:00
|
|
|
|
|
|
|
ClearParentManager(aRemoveFromParent);
|
|
|
|
|
2012-01-07 23:20:12 +04:00
|
|
|
mDisconnected = true;
|
|
|
|
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);
|
2017-06-20 12:09:50 +03:00
|
|
|
MOZ_ASSERT(aInitialData.isObject());
|
2015-05-01 04:20:51 +03:00
|
|
|
mInitialProcessData = aInitialData;
|
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::GetInitialProcessData(
|
|
|
|
JSContext* aCx, JS::MutableHandle<JS::Value> aInitialProcessData,
|
|
|
|
ErrorResult& aError) {
|
2015-05-01 04:20:51 +03:00
|
|
|
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
|
2018-05-16 11:53:16 +03:00
|
|
|
// normal realm, that realm would leak until shutdown.
|
2015-05-01 04:20:51 +03:00
|
|
|
JS::RootedObject global(aCx, xpc::PrivilegedJunkScope());
|
2018-08-02 09:48:40 +03:00
|
|
|
JSAutoRealm ar(aCx, global);
|
2015-05-01 04:20:51 +03:00
|
|
|
|
|
|
|
JS::RootedObject obj(aCx, JS_NewPlainObject(aCx));
|
|
|
|
if (!obj) {
|
2017-06-20 12:09:50 +03:00
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
return;
|
2015-05-01 04:20:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2018-02-09 17:59:02 +03:00
|
|
|
// the ppmm. Create it first through do_GetService and use the cached
|
|
|
|
// pointer in sParentProcessManager.
|
|
|
|
nsCOMPtr<nsISupports> ppmm =
|
|
|
|
do_GetService("@mozilla.org/parentprocessmessagemanager;1");
|
|
|
|
sParentProcessManager->GetInitialProcessData(aCx, &init, aError);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-31 01:59:49 +03:00
|
|
|
mInitialProcessData = init;
|
|
|
|
}
|
|
|
|
|
2015-05-01 04:20:51 +03:00
|
|
|
if (!JS_WrapValue(aCx, &init)) {
|
2017-06-20 12:09:50 +03:00
|
|
|
aError.NoteJSContextException(aCx);
|
|
|
|
return;
|
2015-05-01 04:20:51 +03:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
aInitialProcessData.set(init);
|
2015-05-01 04:20:51 +03:00
|
|
|
}
|
|
|
|
|
2018-06-23 06:35:49 +03:00
|
|
|
WritableSharedMap* nsFrameMessageManager::SharedData() {
|
|
|
|
if (!mChrome || !mIsProcessManager) {
|
|
|
|
MOZ_ASSERT(false, "Should only call this binding method on ppmm");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!mSharedData) {
|
|
|
|
mSharedData = new WritableSharedMap();
|
|
|
|
}
|
|
|
|
return mSharedData;
|
|
|
|
}
|
|
|
|
|
2018-04-16 16:18:48 +03:00
|
|
|
already_AddRefed<ProcessMessageManager>
|
2017-06-20 12:09:50 +03:00
|
|
|
nsFrameMessageManager::GetProcessMessageManager(ErrorResult& aError) {
|
2018-04-16 16:18:48 +03:00
|
|
|
RefPtr<ProcessMessageManager> pmm;
|
2016-08-22 11:28:04 +03:00
|
|
|
if (mCallback) {
|
2017-06-20 12:09:50 +03:00
|
|
|
pmm = mCallback->GetProcessMessageManager();
|
2016-08-22 11:28:04 +03:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
return pmm.forget();
|
2016-08-22 11:28:04 +03:00
|
|
|
}
|
|
|
|
|
2017-06-20 12:09:50 +03:00
|
|
|
void nsFrameMessageManager::GetRemoteType(nsAString& aRemoteType,
|
|
|
|
ErrorResult& aError) const {
|
2017-08-14 04:58:23 +03:00
|
|
|
aRemoteType.Truncate();
|
|
|
|
if (mCallback) {
|
2018-05-17 17:42:13 +03:00
|
|
|
mCallback->DoGetRemoteType(aRemoteType, aError);
|
2017-08-14 04:58:23 +03:00
|
|
|
}
|
2017-06-20 12:09:50 +03:00
|
|
|
}
|
|
|
|
|
2013-10-12 03:07:15 +04:00
|
|
|
namespace {
|
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
struct MessageManagerReferentCount {
|
|
|
|
MessageManagerReferentCount() : mStrong(0), mWeakAlive(0), mWeakDead(0) {}
|
|
|
|
size_t mStrong;
|
|
|
|
size_t mWeakAlive;
|
|
|
|
size_t mWeakDead;
|
|
|
|
nsTArray<nsString> mSuspectMessages;
|
|
|
|
nsDataHashtable<nsStringHashKey, uint32_t> mMessageCounter;
|
2013-10-12 03:07:15 +04:00
|
|
|
};
|
|
|
|
|
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 {
|
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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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).
|
2018-11-12 04:51:30 +03:00
|
|
|
if (currentCount >= MessageManagerReporter::kSuspectReferentCount) {
|
2015-11-05 08:35:12 +03:00
|
|
|
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) {
|
2017-06-20 12:09:50 +03:00
|
|
|
RefPtr<nsFrameMessageManager> mm = aMessageManager->mChildManagers[i];
|
2013-10-12 03:07:15 +04:00
|
|
|
CountReferents(mm, aReferentCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void 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));
|
2018-11-30 13:46:48 +03:00
|
|
|
REPORT(
|
2013-10-12 03:07:15 +04:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-02-14 19:35:39 +03:00
|
|
|
static StaticRefPtr<ChromeMessageBroadcaster> sGlobalMessageManager;
|
|
|
|
|
2013-10-12 03:07:15 +04:00
|
|
|
NS_IMETHODIMP
|
2016-08-24 08:23:45 +03:00
|
|
|
MessageManagerReporter::CollectReports(nsIHandleReportCallback* aHandleReport,
|
|
|
|
nsISupports* aData, bool aAnonymize) {
|
2018-02-14 19:35:39 +03:00
|
|
|
if (XRE_IsParentProcess() && sGlobalMessageManager) {
|
|
|
|
MessageManagerReferentCount count;
|
|
|
|
CountReferents(sGlobalMessageManager, &count);
|
|
|
|
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
|
|
|
|
|
2018-02-14 19:35:39 +03:00
|
|
|
already_AddRefed<ChromeMessageBroadcaster>
|
|
|
|
nsFrameMessageManager::GetGlobalMessageManager() {
|
|
|
|
RefPtr<ChromeMessageBroadcaster> mm;
|
|
|
|
if (sGlobalMessageManager) {
|
|
|
|
mm = sGlobalMessageManager;
|
|
|
|
} else {
|
|
|
|
sGlobalMessageManager = mm =
|
|
|
|
new ChromeMessageBroadcaster(MessageManagerFlags::MM_GLOBAL);
|
|
|
|
ClearOnShutdown(&sGlobalMessageManager);
|
|
|
|
RegisterStrongMemoryReporter(new MessageManagerReporter());
|
|
|
|
}
|
|
|
|
return mm.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult NS_NewGlobalMessageManager(nsISupports** aResult) {
|
|
|
|
*aResult = nsFrameMessageManager::GetGlobalMessageManager().take();
|
2015-03-12 20:20:29 +03:00
|
|
|
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
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
void nsMessageManagerScriptExecutor::DidCreateScriptLoader() {
|
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
|
2016-04-13 21:04:11 +03:00
|
|
|
void 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
void nsMessageManagerScriptExecutor::LoadScriptInternal(
|
|
|
|
JS::Handle<JSObject*> aMessageManager, const nsAString& aURL,
|
|
|
|
bool aRunInUniqueScope) {
|
2017-10-13 08:12:57 +03:00
|
|
|
AUTO_PROFILER_LABEL_DYNAMIC_LOSSY_NSSTRING(
|
|
|
|
"nsMessageManagerScriptExecutor::LoadScriptInternal", OTHER, aURL);
|
2017-06-16 23:34:12 +03:00
|
|
|
|
2017-07-19 15:59:02 +03:00
|
|
|
if (!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);
|
2018-08-11 00:03:18 +03:00
|
|
|
if (holder) {
|
2013-11-24 09:32:45 +04:00
|
|
|
script = holder->mScript;
|
|
|
|
} else {
|
2018-08-11 00:03:18 +03:00
|
|
|
TryCacheLoadAndCompileScript(aURL, aRunInUniqueScope, true, aMessageManager,
|
|
|
|
&script);
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
AutoEntryScript aes(aMessageManager, "message manager script load");
|
2017-07-19 15:59:02 +03:00
|
|
|
JSContext* cx = aes.cx();
|
|
|
|
if (script) {
|
2018-08-11 00:03:18 +03:00
|
|
|
if (aRunInUniqueScope) {
|
2017-07-19 15:59:02 +03:00
|
|
|
JS::Rooted<JSObject*> scope(cx);
|
2018-08-11 00:03:18 +03:00
|
|
|
bool ok = js::ExecuteInFrameScriptEnvironment(cx, aMessageManager, script,
|
|
|
|
&scope);
|
2017-07-19 15:59:02 +03:00
|
|
|
if (ok) {
|
|
|
|
// Force the scope to stay alive.
|
|
|
|
mAnonymousGlobalScopes.AppendElement(scope);
|
2013-11-24 09:32:45 +04:00
|
|
|
}
|
2018-08-11 00:03:18 +03:00
|
|
|
} else {
|
|
|
|
JS::RootedValue rval(cx);
|
|
|
|
JS::AutoObjectVector envChain(cx);
|
|
|
|
if (!envChain.append(aMessageManager)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
JS::CloneAndExecuteScript(cx, envChain, script, &rval);
|
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
|
|
|
|
2015-02-20 04:10:44 +03:00
|
|
|
void nsMessageManagerScriptExecutor::TryCacheLoadAndCompileScript(
|
2018-08-11 00:03:18 +03:00
|
|
|
const nsAString& aURL, bool aRunInUniqueScope, bool aShouldCache,
|
|
|
|
JS::Handle<JSObject*> aMessageManager,
|
2015-02-20 04:10:44 +03:00
|
|
|
JS::MutableHandle<JSScript*> aScriptp) {
|
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
|
|
|
|
2018-06-30 04:07:46 +03:00
|
|
|
// If this script won't be cached, or there is only one of this type of
|
|
|
|
// message manager per process, treat this script as run-once. Run-once
|
|
|
|
// scripts can be compiled directly for the target global, and will be dropped
|
|
|
|
// from the preloader cache after they're executed and serialized.
|
|
|
|
bool isRunOnce = !aShouldCache || IsProcessScoped();
|
|
|
|
|
|
|
|
// If the script will be reused in this session, compile it in the compilation
|
|
|
|
// scope instead of the current global to avoid keeping the current
|
|
|
|
// compartment alive.
|
2017-05-03 01:16:55 +03:00
|
|
|
AutoJSAPI jsapi;
|
2018-08-11 00:03:18 +03:00
|
|
|
if (!jsapi.Init(isRunOnce ? aMessageManager : xpc::CompilationScope())) {
|
2017-05-06 12:02:13 +03:00
|
|
|
return;
|
2017-05-03 01:16:55 +03:00
|
|
|
}
|
2017-05-03 01:16:55 +03:00
|
|
|
JSContext* cx = jsapi.cx();
|
|
|
|
JS::Rooted<JSScript*> script(cx);
|
|
|
|
|
2017-05-01 07:54:31 +03:00
|
|
|
script = ScriptPreloader::GetChildSingleton().GetCachedScript(cx, url);
|
2010-08-10 21:18:26 +04:00
|
|
|
|
2017-05-03 01:16:55 +03:00
|
|
|
if (!script) {
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
NS_NewChannel(getter_AddRefs(channel), uri,
|
|
|
|
nsContentUtils::GetSystemPrincipal(),
|
|
|
|
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
|
|
|
|
nsIContentPolicy::TYPE_OTHER);
|
|
|
|
|
|
|
|
if (!channel) {
|
2012-08-11 06:44:11 +04:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 01:16:55 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> input;
|
|
|
|
rv = channel->Open2(getter_AddRefs(input));
|
|
|
|
NS_ENSURE_SUCCESS_VOID(rv);
|
|
|
|
nsString dataString;
|
|
|
|
char16_t* dataStringBuf = nullptr;
|
|
|
|
size_t dataStringLength = 0;
|
2017-11-09 13:18:09 +03:00
|
|
|
if (input) {
|
2017-05-03 01:16:55 +03:00
|
|
|
nsCString buffer;
|
2017-11-09 13:18:09 +03:00
|
|
|
uint64_t written;
|
|
|
|
if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, -1, &written))) {
|
2017-05-03 01:16:55 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-11-09 13:18:09 +03:00
|
|
|
|
|
|
|
uint32_t size = (uint32_t)std::min(written, (uint64_t)UINT32_MAX);
|
|
|
|
ScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), size,
|
2017-05-08 09:24:22 +03:00
|
|
|
EmptyString(), nullptr, dataStringBuf,
|
|
|
|
dataStringLength);
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
|
2017-05-03 01:16:55 +03:00
|
|
|
if (!dataStringBuf || dataStringLength == 0) {
|
2016-03-18 17:48:38 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-05-03 01:16:55 +03:00
|
|
|
|
2018-10-23 22:27:16 +03:00
|
|
|
JS::UniqueTwoByteChars srcChars(dataStringBuf);
|
|
|
|
|
2018-11-09 05:42:48 +03:00
|
|
|
JS::SourceText<char16_t> srcBuf;
|
2018-10-23 22:27:16 +03:00
|
|
|
if (!srcBuf.init(cx, std::move(srcChars), dataStringLength)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-17 14:12:39 +03:00
|
|
|
JS::CompileOptions options(cx);
|
2015-02-09 22:42:20 +03:00
|
|
|
options.setFileAndLine(url.get(), 1);
|
|
|
|
options.setNoScriptRval(true);
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
if (!JS::CompileForNonSyntacticScope(cx, options, srcBuf, &script)) {
|
2015-09-29 18:36:36 +03:00
|
|
|
return;
|
2015-02-09 22:42:20 +03:00
|
|
|
}
|
2017-05-03 01:16:55 +03:00
|
|
|
}
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2017-05-03 01:16:55 +03:00
|
|
|
MOZ_ASSERT(script);
|
|
|
|
aScriptp.set(script);
|
2013-11-24 09:32:45 +04:00
|
|
|
|
2017-05-03 01:16:55 +03:00
|
|
|
nsAutoCString scheme;
|
|
|
|
uri->GetScheme(scheme);
|
|
|
|
// We don't cache data: scripts!
|
|
|
|
if (aShouldCache && !scheme.EqualsLiteral("data")) {
|
2018-06-30 04:07:46 +03:00
|
|
|
ScriptPreloader::GetChildSingleton().NoteScript(url, url, script,
|
|
|
|
isRunOnce);
|
|
|
|
|
|
|
|
// If this script will only run once per process, only cache it in the
|
|
|
|
// preloader cache, not the session cache.
|
|
|
|
if (!isRunOnce) {
|
|
|
|
// Root the object also for caching.
|
2018-08-11 00:03:18 +03:00
|
|
|
auto* holder = new nsMessageManagerScriptHolder(cx, script);
|
2018-06-30 04:07:46 +03:00
|
|
|
sCachedScripts->Put(aURL, holder);
|
|
|
|
}
|
2010-08-10 21:18:26 +04:00
|
|
|
}
|
|
|
|
}
|
2010-08-17 00:05:42 +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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 23:05:18 +03:00
|
|
|
void nsMessageManagerScriptExecutor::Unlink() {
|
|
|
|
ImplCycleCollectionUnlink(mAnonymousGlobalScopes);
|
|
|
|
}
|
|
|
|
|
2018-08-11 00:03:18 +03:00
|
|
|
bool nsMessageManagerScriptExecutor::Init() {
|
|
|
|
DidCreateScriptLoader();
|
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
|
|
|
|
2017-06-14 17:44:17 +03:00
|
|
|
ChildProcessMessageManager* nsFrameMessageManager::sChildProcessManager =
|
|
|
|
nullptr;
|
2018-04-16 16:18:48 +03:00
|
|
|
ParentProcessMessageManager* nsFrameMessageManager::sParentProcessManager =
|
|
|
|
nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
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),
|
2017-06-12 22:34:10 +03:00
|
|
|
mozilla::Runnable("nsAsyncMessageToSameProcessChild") {}
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager* ppm =
|
|
|
|
nsFrameMessageManager::GetChildProcessManager();
|
2018-04-16 16:18:48 +03:00
|
|
|
ReceiveMessage(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 {
|
|
|
|
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 {
|
2018-08-03 01:03:50 +03:00
|
|
|
auto* global = ContentProcessMessageManager::Get();
|
2015-02-20 04:13:02 +03:00
|
|
|
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 {
|
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 {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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) {}
|
2016-11-15 14:09:07 +03:00
|
|
|
nsresult HandleMessage() override {
|
2015-03-24 23:05:39 +03:00
|
|
|
nsFrameMessageManager* ppm =
|
|
|
|
nsFrameMessageManager::sSameProcessParentManager;
|
2018-04-16 16:18:48 +03:00
|
|
|
ReceiveMessage(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 {
|
|
|
|
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 {
|
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;
|
2018-02-16 17:28:31 +03:00
|
|
|
ppm->ReceiveMessage(ppm, nullptr, aMessage, true, &aData, &cpows,
|
|
|
|
aPrincipal, aRetVal, IgnoreErrors());
|
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 {
|
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-08-02 23:57:48 +04:00
|
|
|
// This creates the global parent process message manager.
|
2018-02-14 19:35:39 +03:00
|
|
|
nsresult NS_NewParentProcessMessageManager(nsISupports** aResult) {
|
2010-08-31 22:58:35 +04:00
|
|
|
NS_ASSERTION(!nsFrameMessageManager::sParentProcessManager,
|
|
|
|
"Re-creating sParentProcessManager");
|
2018-04-16 16:18:48 +03:00
|
|
|
RefPtr<ParentProcessMessageManager> mm = new ParentProcessMessageManager();
|
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
|
|
|
}
|
|
|
|
|
2015-03-06 04:03:25 +03:00
|
|
|
ProcessMessageManager* nsFrameMessageManager::NewProcessMessageManager(
|
|
|
|
bool aIsRemote) {
|
2011-08-02 23:57:48 +04:00
|
|
|
if (!nsFrameMessageManager::sParentProcessManager) {
|
2018-02-14 19:35:39 +03:00
|
|
|
nsCOMPtr<nsISupports> dummy =
|
2013-05-23 22:17:57 +04:00
|
|
|
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");
|
2018-04-16 16:18:48 +03:00
|
|
|
ProcessMessageManager* 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.
|
2018-04-16 16:18:48 +03:00
|
|
|
mm = new ProcessMessageManager(
|
|
|
|
nullptr, nsFrameMessageManager::sParentProcessManager);
|
2012-09-28 09:43:12 +04:00
|
|
|
} else {
|
2018-04-16 16:18:48 +03:00
|
|
|
mm =
|
|
|
|
new ProcessMessageManager(new SameParentProcessMessageManagerCallback(),
|
|
|
|
nsFrameMessageManager::sParentProcessManager,
|
|
|
|
MessageManagerFlags::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
|
|
|
|
2018-02-16 12:34:21 +03:00
|
|
|
nsresult NS_NewChildProcessMessageManager(nsISupports** 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
|
|
|
}
|
2017-06-14 17:44:17 +03:00
|
|
|
auto* mm = new ChildProcessMessageManager(cb);
|
2015-02-20 04:12:38 +03:00
|
|
|
nsFrameMessageManager::SetChildProcessManager(mm);
|
2018-08-03 01:03:50 +03:00
|
|
|
auto global = MakeRefPtr<ContentProcessMessageManager>(mm);
|
2015-02-20 04:13:02 +03:00
|
|
|
NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED);
|
2018-02-16 12:34:21 +03:00
|
|
|
return CallQueryInterface(global, aResult);
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
2012-01-26 19:39:23 +04:00
|
|
|
|
2013-10-26 01:55:16 +04:00
|
|
|
void 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++) {
|
2018-02-16 17:28:31 +03:00
|
|
|
MessageListener* strongListener = listeners->ElementAt(i).mStrongListener;
|
2015-11-05 08:35:12 +03:00
|
|
|
if (strongListener) {
|
2018-02-16 17:28:31 +03:00
|
|
|
strongListener->MarkForCC();
|
2015-11-05 08:35:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-26 01:55:16 +04:00
|
|
|
|
2012-10-17 05:22:02 +04:00
|
|
|
if (mRefCnt.IsPurple()) {
|
|
|
|
mRefCnt.RemovePurple();
|
|
|
|
}
|
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)
|
2017-06-08 02:19:07 +03:00
|
|
|
: mCpows(aRootingCx, aCpows)
|
2016-08-12 12:39:16 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
,
|
|
|
|
mCalledInit(false)
|
|
|
|
#endif
|
2014-03-12 18:22:00 +04:00
|
|
|
{
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 12:39:16 +03:00
|
|
|
nsresult nsSameProcessAsyncMessageBase::Init(const nsAString& aMessage,
|
2016-11-15 14:09:07 +03:00
|
|
|
StructuredCloneData& aData,
|
2015-10-07 13:42:43 +03:00
|
|
|
nsIPrincipal* aPrincipal) {
|
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(
|
2018-03-22 05:43:17 +03:00
|
|
|
nsISupports* aTarget, nsFrameLoader* 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) {
|
2017-06-08 02:19:07 +03:00
|
|
|
SameProcessCpowHolder cpows(RootingCx(), 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,
|
2018-02-16 17:28:31 +03:00
|
|
|
&cpows, mPrincipal, nullptr, IgnoreErrors());
|
2014-03-12 18:22:00 +04:00
|
|
|
}
|
|
|
|
}
|