mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
139dd41f0f
- Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 1 - WindowID added into WebSocketChannel, r=michal (80cae04416) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 2 - WebSocketFrameService, r=michal (66e1935806) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 3 - timestamp, r=michal (1ee78cbab5) - Bug 1203802 - Websocket Frame Listener API for devtool Network Inspector - part 4 - IPC, r=michal (651d908780) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 1 - Renaming WebSocketFrameService, r=michal (c215f04303) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 2 - Unique Serial number for WebSocketChannel in IPC, r=michal (9a42b6b898) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 3 - Events, r=michal (3e22a9b8a9) - Bug 1215092 - WebSocketEventService and WebSocket discovering - part 4 - MessageAvailable event, r=michal (03606add66) - Bug 1185351 - Don't force inline style CSP checks on native anonymous content; r=ckerschb (51deea3648) - Bug 1212477 - Needs a way to access to <canvas>'s context (2d, webgl) from Anonymous Content API; r=roc;r=smaug (ed3335513d) - Bug 1119692 - Part 1: Get cached jar file fd if it exists instead of always openning it. r=smaug, r=jduell (399a3701dd) - Bug 1119692 - Part 2: Always use scheme jar:remoteopenfile: for out-of-process apps to ease sandboxing code. r=fabrice (d3783120a9) - Bug 1212244 - Same-process sendAsyncMessage can now throw instead of OOM. r=smaug (f22bbeb173) - Bug 1207752 - Increase how long we let incremental GC run before forcing it to finish. r=smaug (ef731501a0) - Bug 1213019. Get UnmapBuffer as part of MapBufferRanges features. r=jgilbert (0e1a1d7ffd) - Bug 941858 - Do not scale down elements passed to setDragImage. r=roc (7c1f18056e) - Bug 1212027 - part 1 - rename ipdl lowering helpers to reflect intent, not function; r=jld (f2c80853a7) - Bug 1212027 - part 2 - add a C++ AST type for 'auto'; r=jld (480120b163) - Bug 1212027 - part 3 - use class interfaces when cloning managees; r=jld (98d8aa9322) - Bug 1212027 - part 4 - use class interfaces when destroying managees; r=jld (2ed9d48242) - Add default initializers for primitive fields in IPDL structs. (bug 1154522, r=billm) (981f0e0d82) - Bug 1158905 - remove dead code from protocol Transition functions; r=bent (e4a43b880a) - Bug 1207921 - Call makeReply before dtorEpilogue so that we don't end up with a nullptr deref r=billm (f7d4530a72) - Bug 1212248 - Align the creation of cpow in ContentBridgeParent to ContentParent. r=khuey (ace596456a) - Bug 1212027 - part 5 - add LoneManagedOrNull for simplifying a lot of upcoming code; r=jld (6aec494580) - Bug 1212027 - part 6 - add an IsEmpty method to nsTHashtable; r=erahm (cabe26f3d6) - bug 1209615 - use TabParent::GetTopLevelDocAccessible() in OuterDocAccessible::RemoteChildDoc() r=davidb (0765f27bb5) - Bug 1214316 - Improve assertions on top level remote accessible doc handling, r=tbsaunde (257c6c8ef6) - Bug 1212027 - part 7 - modify IPDL codegen to store sub-protocols in a hashtable rather than an array; r=jld,nical,cpearce,billm (99dd4fa79c) - Bug 1212027 - followup - qualify PBrowserParent in GonkPermission.cpp; r=me (051e7e1bde) - Bug 1217250 - Fix some IPDL tests that were broken by bug 1212027; r=froydnj (d368b3aa02) - Bug 1202634 - Make sure TabParent LoadContext for pop-ups shares private browsing state of opener. r=billm (b347018487) - Bug 1191740 - Add originAttributes in TabContext. r=bholley (43ea8ca527) - Bug 1191740 - Factor out nsFrameLoader::GetNewTabContext. r=bholley (3311ab7287) - Bug 1180088 - Use origin-based permission check on parent side for signed packaged web app. r=kanru. (01659e2906) - Bug 1205399 - Backend for disabling of notifications for a site from the UI. r=nsm (6380757077) - Bug 1208295 - Dispatch notifications-open-settings upon receiving alertsettingscallback so UI can open notification settings. r=nsm (776ab25c91) - Bug 1212129 - e10s support for disabling site notifications. r=wchen (e896f87940) - Bug 1208622 - Separate API entry points. r=bz (a324f95322)
354 lines
11 KiB
C++
354 lines
11 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "nsInProcessTabChildGlobal.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsIScriptSecurityManager.h"
|
|
#include "nsIInterfaceRequestorUtils.h"
|
|
#include "nsIComponentManager.h"
|
|
#include "nsIServiceManager.h"
|
|
#include "nsComponentManagerUtils.h"
|
|
#include "nsScriptLoader.h"
|
|
#include "nsFrameLoader.h"
|
|
#include "xpcpublic.h"
|
|
#include "nsIMozBrowserFrame.h"
|
|
#include "nsDOMClassInfoID.h"
|
|
#include "mozilla/EventDispatcher.h"
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
using namespace mozilla::dom::ipc;
|
|
|
|
bool
|
|
nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
JS::Handle<JSObject *> aCpows,
|
|
nsIPrincipal* aPrincipal,
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
|
bool aIsSync)
|
|
{
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
|
queue->Flush();
|
|
|
|
if (mChromeMessageManager) {
|
|
SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows);
|
|
RefPtr<nsFrameMessageManager> mm = mChromeMessageManager;
|
|
nsCOMPtr<nsIFrameLoader> fl = GetFrameLoader();
|
|
mm->ReceiveMessage(mOwner, fl, aMessage, true, &aData, &cpows, aPrincipal,
|
|
aRetVal);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
class nsAsyncMessageToParent : public nsSameProcessAsyncMessageBase,
|
|
public SameProcessMessageQueue::Runnable
|
|
{
|
|
public:
|
|
nsAsyncMessageToParent(JSContext* aCx, JS::Handle<JSObject*> aCpows, nsInProcessTabChildGlobal* aTabChild)
|
|
: nsSameProcessAsyncMessageBase(aCx, aCpows)
|
|
, mTabChild(aTabChild)
|
|
{ }
|
|
|
|
virtual nsresult HandleMessage() override
|
|
{
|
|
nsCOMPtr<nsIFrameLoader> fl = mTabChild->GetFrameLoader();
|
|
ReceiveMessage(mTabChild->mOwner, fl, mTabChild->mChromeMessageManager);
|
|
return NS_OK;
|
|
}
|
|
RefPtr<nsInProcessTabChildGlobal> mTabChild;
|
|
};
|
|
|
|
nsresult
|
|
nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx,
|
|
const nsAString& aMessage,
|
|
StructuredCloneData& aData,
|
|
JS::Handle<JSObject *> aCpows,
|
|
nsIPrincipal* aPrincipal)
|
|
{
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
|
RefPtr<nsAsyncMessageToParent> ev =
|
|
new nsAsyncMessageToParent(aCx, aCpows, this);
|
|
|
|
nsresult rv = ev->Init(aCx, aMessage, aData, aPrincipal);
|
|
if (NS_FAILED(rv)) {
|
|
return rv;
|
|
}
|
|
|
|
queue->Push(ev);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell,
|
|
nsIContent* aOwner,
|
|
nsFrameMessageManager* aChrome)
|
|
: mDocShell(aShell), mInitialized(false), mLoadingScript(false),
|
|
mPreventEventsEscaping(false),
|
|
mOwner(aOwner), mChromeMessageManager(aChrome)
|
|
{
|
|
SetIsNotDOMBinding();
|
|
mozilla::HoldJSObjects(this);
|
|
|
|
// If owner corresponds to an <iframe mozbrowser> or <iframe mozapp>, we'll
|
|
// have to tweak our PreHandleEvent implementation.
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(mOwner);
|
|
if (browserFrame) {
|
|
mIsBrowserOrAppFrame = browserFrame->GetReallyIsBrowserOrApp();
|
|
}
|
|
else {
|
|
mIsBrowserOrAppFrame = false;
|
|
}
|
|
}
|
|
|
|
nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal()
|
|
{
|
|
mAnonymousGlobalScopes.Clear();
|
|
mozilla::DropJSObjects(this);
|
|
}
|
|
|
|
// This method isn't automatically forwarded safely because it's notxpcom, so
|
|
// the IDL binding doesn't know what value to return.
|
|
NS_IMETHODIMP_(bool)
|
|
nsInProcessTabChildGlobal::MarkForCC()
|
|
{
|
|
MarkScopesForCC();
|
|
return mMessageManager ? mMessageManager->MarkForCC() : false;
|
|
}
|
|
|
|
nsresult
|
|
nsInProcessTabChildGlobal::Init()
|
|
{
|
|
#ifdef DEBUG
|
|
nsresult rv =
|
|
#endif
|
|
InitTabChildGlobal();
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
"Couldn't initialize nsInProcessTabChildGlobal");
|
|
mMessageManager = new nsFrameMessageManager(this,
|
|
nullptr,
|
|
dom::ipc::MM_CHILD);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsInProcessTabChildGlobal)
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsInProcessTabChildGlobal,
|
|
DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMessageManager)
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
|
|
tmp->TraverseHostObjectURIs(cb);
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsInProcessTabChildGlobal,
|
|
DOMEventTargetHelper)
|
|
for (uint32_t i = 0; i < tmp->mAnonymousGlobalScopes.Length(); ++i) {
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_JS_MEMBER_CALLBACK(mAnonymousGlobalScopes[i])
|
|
}
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsInProcessTabChildGlobal,
|
|
DOMEventTargetHelper)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mMessageManager)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mGlobal)
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnonymousGlobalScopes)
|
|
tmp->UnlinkHostObjectURIs();
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsInProcessTabChildGlobal)
|
|
NS_INTERFACE_MAP_ENTRY(nsIMessageListenerManager)
|
|
NS_INTERFACE_MAP_ENTRY(nsIMessageSender)
|
|
NS_INTERFACE_MAP_ENTRY(nsISyncMessageSender)
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentFrameMessageManager)
|
|
NS_INTERFACE_MAP_ENTRY(nsIInProcessContentFrameMessageManager)
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentFrameMessageManager)
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsInProcessTabChildGlobal, DOMEventTargetHelper)
|
|
NS_IMPL_RELEASE_INHERITED(nsInProcessTabChildGlobal, DOMEventTargetHelper)
|
|
|
|
void
|
|
nsInProcessTabChildGlobal::CacheFrameLoader(nsIFrameLoader* aFrameLoader)
|
|
{
|
|
mFrameLoader = aFrameLoader;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsInProcessTabChildGlobal::GetContent(nsIDOMWindow** aContent)
|
|
{
|
|
*aContent = nullptr;
|
|
if (!mDocShell) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<nsIDOMWindow> window = mDocShell->GetWindow();
|
|
window.swap(*aContent);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsInProcessTabChildGlobal::GetDocShell(nsIDocShell** aDocShell)
|
|
{
|
|
NS_IF_ADDREF(*aDocShell = mDocShell);
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsInProcessTabChildGlobal::FireUnloadEvent()
|
|
{
|
|
// We're called from nsDocument::MaybeInitializeFinalizeFrameLoaders, so it
|
|
// should be safe to run script.
|
|
MOZ_ASSERT(nsContentUtils::IsSafeToRunScript());
|
|
|
|
// Don't let the unload event propagate to chrome event handlers.
|
|
mPreventEventsEscaping = true;
|
|
DOMEventTargetHelper::DispatchTrustedEvent(NS_LITERAL_STRING("unload"));
|
|
|
|
// Allow events fired during docshell destruction (pagehide, unload) to
|
|
// propagate to the <browser> element since chrome code depends on this.
|
|
mPreventEventsEscaping = false;
|
|
}
|
|
|
|
void
|
|
nsInProcessTabChildGlobal::DisconnectEventListeners()
|
|
{
|
|
if (mDocShell) {
|
|
nsCOMPtr<nsPIDOMWindow> win = mDocShell->GetWindow();
|
|
if (win) {
|
|
MOZ_ASSERT(win->IsOuterWindow());
|
|
win->SetChromeEventHandler(win->GetChromeEventHandler());
|
|
}
|
|
}
|
|
if (mListenerManager) {
|
|
mListenerManager->Disconnect();
|
|
}
|
|
|
|
mDocShell = nullptr;
|
|
}
|
|
|
|
void
|
|
nsInProcessTabChildGlobal::Disconnect()
|
|
{
|
|
mChromeMessageManager = nullptr;
|
|
mOwner = nullptr;
|
|
if (mMessageManager) {
|
|
static_cast<nsFrameMessageManager*>(mMessageManager.get())->Disconnect();
|
|
mMessageManager = nullptr;
|
|
}
|
|
}
|
|
|
|
NS_IMETHODIMP_(nsIContent *)
|
|
nsInProcessTabChildGlobal::GetOwnerContent()
|
|
{
|
|
return mOwner;
|
|
}
|
|
|
|
nsresult
|
|
nsInProcessTabChildGlobal::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
|
{
|
|
aVisitor.mCanHandle = true;
|
|
|
|
#ifdef DEBUG
|
|
if (mOwner) {
|
|
nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface(mOwner);
|
|
RefPtr<nsFrameLoader> fl = owner->GetFrameLoader();
|
|
if (fl) {
|
|
NS_ASSERTION(this == fl->GetTabChildGlobalAsEventTarget(),
|
|
"Wrong event target!");
|
|
NS_ASSERTION(fl->mMessageManager == mChromeMessageManager,
|
|
"Wrong message manager!");
|
|
}
|
|
}
|
|
#endif
|
|
|
|
if (mPreventEventsEscaping) {
|
|
aVisitor.mParentTarget = nullptr;
|
|
return NS_OK;
|
|
}
|
|
|
|
if (mIsBrowserOrAppFrame &&
|
|
(!mOwner || !nsContentUtils::IsInChromeDocshell(mOwner->OwnerDoc()))) {
|
|
if (mOwner) {
|
|
nsPIDOMWindow* innerWindow = mOwner->OwnerDoc()->GetInnerWindow();
|
|
if (innerWindow) {
|
|
aVisitor.mParentTarget = innerWindow->GetParentTarget();
|
|
}
|
|
}
|
|
} else {
|
|
aVisitor.mParentTarget = mOwner;
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsInProcessTabChildGlobal::InitTabChildGlobal()
|
|
{
|
|
// If you change this, please change GetCompartmentName() in XPCJSRuntime.cpp
|
|
// accordingly.
|
|
nsAutoCString id;
|
|
id.AssignLiteral("inProcessTabChildGlobal");
|
|
nsIURI* uri = mOwner->OwnerDoc()->GetDocumentURI();
|
|
if (uri) {
|
|
nsAutoCString u;
|
|
uri->GetSpec(u);
|
|
id.AppendLiteral("?ownedBy=");
|
|
id.Append(u);
|
|
}
|
|
nsISupports* scopeSupports = NS_ISUPPORTS_CAST(EventTarget*, this);
|
|
NS_ENSURE_STATE(InitChildGlobalInternal(scopeSupports, id));
|
|
return NS_OK;
|
|
}
|
|
|
|
class nsAsyncScriptLoad : public nsRunnable
|
|
{
|
|
public:
|
|
nsAsyncScriptLoad(nsInProcessTabChildGlobal* aTabChild, const nsAString& aURL,
|
|
bool aRunInGlobalScope)
|
|
: mTabChild(aTabChild), mURL(aURL), mRunInGlobalScope(aRunInGlobalScope) {}
|
|
|
|
NS_IMETHOD Run()
|
|
{
|
|
mTabChild->LoadFrameScript(mURL, mRunInGlobalScope);
|
|
return NS_OK;
|
|
}
|
|
RefPtr<nsInProcessTabChildGlobal> mTabChild;
|
|
nsString mURL;
|
|
bool mRunInGlobalScope;
|
|
};
|
|
|
|
void
|
|
nsInProcessTabChildGlobal::LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope)
|
|
{
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
|
nsContentUtils::AddScriptRunner(new nsAsyncScriptLoad(this, aURL, aRunInGlobalScope));
|
|
return;
|
|
}
|
|
if (!mInitialized) {
|
|
mInitialized = true;
|
|
Init();
|
|
}
|
|
bool tmp = mLoadingScript;
|
|
mLoadingScript = true;
|
|
LoadScriptInternal(aURL, aRunInGlobalScope);
|
|
mLoadingScript = tmp;
|
|
}
|
|
|
|
already_AddRefed<nsIFrameLoader>
|
|
nsInProcessTabChildGlobal::GetFrameLoader()
|
|
{
|
|
nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface(mOwner);
|
|
nsCOMPtr<nsIFrameLoader> fl = owner ? owner->GetFrameLoader() : nullptr;
|
|
if (!fl) {
|
|
fl = mFrameLoader;
|
|
}
|
|
return fl.forget();
|
|
}
|