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
|
|
|
|
|
|
|
#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"
|
2011-01-15 01:03:21 +03:00
|
|
|
#include "xpcpublic.h"
|
2012-05-08 20:20:35 +04:00
|
|
|
#include "nsIMozBrowserFrame.h"
|
2012-07-20 20:42:08 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2015-03-24 23:05:39 +03:00
|
|
|
#include "mozilla/dom/SameProcessMessageQueue.h"
|
2012-08-02 10:02:29 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
using namespace mozilla;
|
2015-05-13 08:36:00 +03:00
|
|
|
using namespace mozilla::dom;
|
2015-09-10 23:50:58 +03:00
|
|
|
using namespace mozilla::dom::ipc;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
bool
|
2013-10-01 20:15:06 +04:00
|
|
|
nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-10-01 20:15:06 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetVal,
|
2013-10-01 20:15:06 +04:00
|
|
|
bool aIsSync)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-03-24 23:05:39 +03:00
|
|
|
SameProcessMessageQueue* queue = SameProcessMessageQueue::Get();
|
|
|
|
queue->Flush();
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
if (mChromeMessageManager) {
|
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> mm = mChromeMessageManager;
|
2015-04-16 18:17:54 +03:00
|
|
|
nsCOMPtr<nsIFrameLoader> fl = GetFrameLoader();
|
2015-09-10 23:50:58 +03:00
|
|
|
mm->ReceiveMessage(mOwner, fl, aMessage, true, &aData, &cpows, aPrincipal,
|
2015-04-30 06:39:59 +03:00
|
|
|
aRetVal);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-03-12 18:22:00 +04:00
|
|
|
class nsAsyncMessageToParent : public nsSameProcessAsyncMessageBase,
|
2015-03-24 23:05:39 +03:00
|
|
|
public SameProcessMessageQueue::Runnable
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
public:
|
2016-08-12 12:39:16 +03:00
|
|
|
nsAsyncMessageToParent(JS::RootingContext* aRootingCx,
|
|
|
|
JS::Handle<JSObject*> aCpows,
|
|
|
|
nsInProcessTabChildGlobal* aTabChild)
|
|
|
|
: nsSameProcessAsyncMessageBase(aRootingCx, aCpows)
|
2015-10-07 13:42:43 +03:00
|
|
|
, mTabChild(aTabChild)
|
|
|
|
{ }
|
2013-07-11 02:05:39 +04:00
|
|
|
|
2015-03-24 23:05:39 +03:00
|
|
|
virtual nsresult HandleMessage() override
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-04-16 18:17:54 +03:00
|
|
|
nsCOMPtr<nsIFrameLoader> fl = mTabChild->GetFrameLoader();
|
|
|
|
ReceiveMessage(mTabChild->mOwner, fl, mTabChild->mChromeMessageManager);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsInProcessTabChildGlobal> mTabChild;
|
2010-05-18 16:28:37 +04:00
|
|
|
};
|
|
|
|
|
2015-10-07 13:42:43 +03:00
|
|
|
nsresult
|
2013-07-11 02:05:39 +04:00
|
|
|
nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
2015-09-10 23:50:58 +03:00
|
|
|
StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
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<nsAsyncMessageToParent> ev =
|
2016-08-12 12:39:16 +03:00
|
|
|
new nsAsyncMessageToParent(rcx, aCpows, this);
|
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;
|
|
|
|
}
|
|
|
|
|
2015-03-24 23:05:39 +03:00
|
|
|
queue->Push(ev);
|
2015-10-07 13:42:43 +03:00
|
|
|
return NS_OK;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell,
|
|
|
|
nsIContent* aOwner,
|
|
|
|
nsFrameMessageManager* aChrome)
|
2011-10-17 18:59:28 +04:00
|
|
|
: mDocShell(aShell), mInitialized(false), mLoadingScript(false),
|
2015-02-27 08:35:26 +03:00
|
|
|
mPreventEventsEscaping(false),
|
2014-04-19 03:00:06 +04:00
|
|
|
mOwner(aOwner), mChromeMessageManager(aChrome)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2014-10-07 13:44:48 +04:00
|
|
|
SetIsNotDOMBinding();
|
2014-06-13 21:56:38 +04:00
|
|
|
mozilla::HoldJSObjects(this);
|
2012-05-08 20:20:35 +04:00
|
|
|
|
2016-10-15 04:46:26 +03:00
|
|
|
// If owner corresponds to an <iframe mozbrowser>, we'll have to tweak our
|
2016-10-21 05:11:07 +03:00
|
|
|
// GetEventTargetParent implementation.
|
2012-05-08 20:20:35 +04:00
|
|
|
nsCOMPtr<nsIMozBrowserFrame> browserFrame = do_QueryInterface(mOwner);
|
|
|
|
if (browserFrame) {
|
2016-10-15 04:46:26 +03:00
|
|
|
mIsBrowserFrame = browserFrame->GetReallyIsBrowser();
|
Bug 802366 - The main event: Let a browser process inherit its app's id. r=bz,cjones
The main bug fixed here is that in half of our interfaces, we use "is browser frame/element" to mean "browser or app", and in the other half, we use it to mean "is browser not app".
There's a related, functional bug also fixed here, which is that a browser process doesn't inherit its parent's app-id. This causes problems e.g. for IndexedDB: If a browser inside an app uses IndexedDB, the DB should have the app's app-id.
I also modified Tab{Parent,Child} and nsFrameLoader to call "app" "ownOrContainingApp", to emphasize that we might have inherited the app from a parent process. I left nsIDocShell::appId alone, because changing that would have necessitated changing nsILoadGroup and therefore a /lot/ of users in Necko; it's also not clear it would have clarified anything in those cases.
2012-11-10 22:32:37 +04:00
|
|
|
}
|
|
|
|
else {
|
2016-10-15 04:46:26 +03:00
|
|
|
mIsBrowserFrame = false;
|
2012-05-08 20:20:35 +04:00
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal()
|
|
|
|
{
|
2014-06-13 21:56:38 +04:00
|
|
|
mAnonymousGlobalScopes.Clear();
|
|
|
|
mozilla::DropJSObjects(this);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
|
2012-08-09 12:33:38 +04:00
|
|
|
// 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()
|
|
|
|
{
|
2015-02-25 01:23:53 +03:00
|
|
|
MarkScopesForCC();
|
2012-08-09 12:33:38 +04:00
|
|
|
return mMessageManager ? mMessageManager->MarkForCC() : false;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsresult
|
|
|
|
nsInProcessTabChildGlobal::Init()
|
|
|
|
{
|
2011-04-14 16:04:12 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
InitTabChildGlobal();
|
2016-09-01 08:01:16 +03:00
|
|
|
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
|
|
|
|
"Couldn't initialize nsInProcessTabChildGlobal");
|
2012-09-28 09:43:12 +04:00
|
|
|
mMessageManager = new nsFrameMessageManager(this,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr,
|
2014-03-18 08:48:19 +04:00
|
|
|
dom::ipc::MM_CHILD);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-13 21:56:38 +04:00
|
|
|
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)
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->TraverseHostObjectURIs(cb);
|
2014-06-13 21:56:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(nsInProcessTabChildGlobal,
|
|
|
|
DOMEventTargetHelper)
|
2016-02-10 01:08:53 +03:00
|
|
|
tmp->nsMessageManagerScriptExecutor::Trace(aCallbacks, aClosure);
|
2014-06-13 21:56:38 +04:00
|
|
|
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)
|
2015-05-07 10:05:43 +03:00
|
|
|
tmp->UnlinkHostObjectURIs();
|
2014-06-13 21:56:38 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2010-05-18 16:28:37 +04:00
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsInProcessTabChildGlobal)
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMessageListenerManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMessageSender)
|
2010-08-31 22:58:35 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISyncMessageSender)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContentFrameMessageManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIInProcessContentFrameMessageManager)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
|
2013-04-04 13:27:06 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIGlobalObject)
|
2013-04-04 13:27:40 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(ContentFrameMessageManager)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsInProcessTabChildGlobal, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsInProcessTabChildGlobal, DOMEventTargetHelper)
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2015-04-16 18:17:54 +03:00
|
|
|
void
|
|
|
|
nsInProcessTabChildGlobal::CacheFrameLoader(nsIFrameLoader* aFrameLoader)
|
|
|
|
{
|
|
|
|
mFrameLoader = aFrameLoader;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHODIMP
|
2016-01-30 20:05:36 +03:00
|
|
|
nsInProcessTabChildGlobal::GetContent(mozIDOMWindowProxy** aContent)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aContent = nullptr;
|
2014-01-10 06:03:47 +04:00
|
|
|
if (!mDocShell) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = mDocShell->GetWindow();
|
|
|
|
window.forget(aContent);
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsInProcessTabChildGlobal::GetDocShell(nsIDocShell** aDocShell)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aDocShell = mDocShell);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 08:35:26 +03:00
|
|
|
nsInProcessTabChildGlobal::FireUnloadEvent()
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-02-27 08:35:26 +03:00
|
|
|
// 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;
|
2010-08-12 20:47:22 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-02-27 08:35:26 +03:00
|
|
|
nsInProcessTabChildGlobal::DisconnectEventListeners()
|
2010-08-12 20:47:22 +04:00
|
|
|
{
|
2014-01-10 06:03:47 +04:00
|
|
|
if (mDocShell) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> win = mDocShell->GetWindow()) {
|
2014-01-10 06:03:47 +04:00
|
|
|
MOZ_ASSERT(win->IsOuterWindow());
|
|
|
|
win->SetChromeEventHandler(win->GetChromeEventHandler());
|
|
|
|
}
|
2010-06-16 15:42:42 +04:00
|
|
|
}
|
2015-02-27 08:35:26 +03:00
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
mDocShell = nullptr;
|
2015-02-27 08:35:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsInProcessTabChildGlobal::Disconnect()
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
mChromeMessageManager = nullptr;
|
2015-02-27 08:35:26 +03:00
|
|
|
mOwner = nullptr;
|
2010-05-18 16:28:37 +04:00
|
|
|
if (mMessageManager) {
|
|
|
|
static_cast<nsFrameMessageManager*>(mMessageManager.get())->Disconnect();
|
2012-07-30 18:20:58 +04:00
|
|
|
mMessageManager = nullptr;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(nsIContent *)
|
|
|
|
nsInProcessTabChildGlobal::GetOwnerContent()
|
|
|
|
{
|
|
|
|
return mOwner;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
nsInProcessTabChildGlobal::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2015-04-03 02:15:00 +03:00
|
|
|
aVisitor.mForceContentDispatch = true;
|
2011-10-17 18:59:28 +04:00
|
|
|
aVisitor.mCanHandle = true;
|
2012-05-08 20:20:35 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (mOwner) {
|
|
|
|
nsCOMPtr<nsIFrameLoaderOwner> owner = do_QueryInterface(mOwner);
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsFrameLoader> fl = owner->GetFrameLoader();
|
2010-05-18 16:28:37 +04:00
|
|
|
if (fl) {
|
|
|
|
NS_ASSERTION(this == fl->GetTabChildGlobalAsEventTarget(),
|
|
|
|
"Wrong event target!");
|
|
|
|
NS_ASSERTION(fl->mMessageManager == mChromeMessageManager,
|
|
|
|
"Wrong message manager!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-27 08:35:26 +03:00
|
|
|
if (mPreventEventsEscaping) {
|
|
|
|
aVisitor.mParentTarget = nullptr;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-15 04:46:26 +03:00
|
|
|
if (mIsBrowserFrame &&
|
2015-02-27 08:35:26 +03:00
|
|
|
(!mOwner || !nsContentUtils::IsInChromeDocshell(mOwner->OwnerDoc()))) {
|
|
|
|
if (mOwner) {
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* innerWindow = mOwner->OwnerDoc()->GetInnerWindow()) {
|
2015-02-27 08:35:26 +03:00
|
|
|
aVisitor.mParentTarget = innerWindow->GetParentTarget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
aVisitor.mParentTarget = mOwner;
|
|
|
|
}
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsInProcessTabChildGlobal::InitTabChildGlobal()
|
|
|
|
{
|
2016-09-14 16:48:17 +03:00
|
|
|
// If you change this, please change GetCompartmentName() in XPCJSContext.cpp
|
2014-09-25 06:08:20 +04:00
|
|
|
// accordingly.
|
2013-02-20 14:39:59 +04:00
|
|
|
nsAutoCString id;
|
|
|
|
id.AssignLiteral("inProcessTabChildGlobal");
|
|
|
|
nsIURI* uri = mOwner->OwnerDoc()->GetDocumentURI();
|
|
|
|
if (uri) {
|
|
|
|
nsAutoCString u;
|
2016-09-08 07:17:58 +03:00
|
|
|
nsresult rv = uri->GetSpec(u);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2013-02-20 14:39:59 +04:00
|
|
|
id.AppendLiteral("?ownedBy=");
|
|
|
|
id.Append(u);
|
|
|
|
}
|
2013-04-20 02:18:33 +04:00
|
|
|
nsISupports* scopeSupports = NS_ISUPPORTS_CAST(EventTarget*, this);
|
2015-02-20 04:10:44 +03:00
|
|
|
NS_ENSURE_STATE(InitChildGlobalInternal(scopeSupports, id));
|
2010-05-18 16:28:37 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsAsyncScriptLoad : public Runnable
|
2011-05-19 18:48:17 +04:00
|
|
|
{
|
|
|
|
public:
|
2013-11-24 09:32:45 +04:00
|
|
|
nsAsyncScriptLoad(nsInProcessTabChildGlobal* aTabChild, const nsAString& aURL,
|
|
|
|
bool aRunInGlobalScope)
|
|
|
|
: mTabChild(aTabChild), mURL(aURL), mRunInGlobalScope(aRunInGlobalScope) {}
|
2011-05-19 18:48:17 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override
|
2011-05-19 18:48:17 +04:00
|
|
|
{
|
2013-11-24 09:32:45 +04:00
|
|
|
mTabChild->LoadFrameScript(mURL, mRunInGlobalScope);
|
2011-05-19 18:48:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsInProcessTabChildGlobal> mTabChild;
|
2011-05-19 18:48:17 +04:00
|
|
|
nsString mURL;
|
2013-11-24 09:32:45 +04:00
|
|
|
bool mRunInGlobalScope;
|
2011-05-19 18:48:17 +04:00
|
|
|
};
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
void
|
2013-11-24 09:32:45 +04:00
|
|
|
nsInProcessTabChildGlobal::LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2011-05-19 18:48:17 +04:00
|
|
|
if (!nsContentUtils::IsSafeToRunScript()) {
|
2013-11-24 09:32:45 +04:00
|
|
|
nsContentUtils::AddScriptRunner(new nsAsyncScriptLoad(this, aURL, aRunInGlobalScope));
|
2011-05-19 18:48:17 +04:00
|
|
|
return;
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
if (!mInitialized) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mInitialized = true;
|
2010-05-18 16:28:37 +04:00
|
|
|
Init();
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool tmp = mLoadingScript;
|
2011-10-17 18:59:28 +04:00
|
|
|
mLoadingScript = true;
|
2015-02-20 04:10:44 +03:00
|
|
|
LoadScriptInternal(aURL, aRunInGlobalScope);
|
2010-08-10 21:18:26 +04:00
|
|
|
mLoadingScript = tmp;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2015-04-16 18:17:54 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|