/* -*- 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 "nsFrameLoader.h" #include "xpcpublic.h" #include "nsIMozBrowserFrame.h" #include "nsDOMClassInfoID.h" #include "mozilla/EventDispatcher.h" #include "mozilla/dom/SameProcessMessageQueue.h" #include "mozilla/dom/ScriptLoader.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 aCpows, nsIPrincipal* aPrincipal, nsTArray* aRetVal, bool aIsSync) { SameProcessMessageQueue* queue = SameProcessMessageQueue::Get(); queue->Flush(); if (mChromeMessageManager) { SameProcessCpowHolder cpows(JS::RootingContext::get(aCx), aCpows); RefPtr mm = mChromeMessageManager; nsCOMPtr fl = GetFrameLoader(); mm->ReceiveMessage(mOwner, fl, aMessage, true, &aData, &cpows, aPrincipal, aRetVal); } return true; } class nsAsyncMessageToParent : public nsSameProcessAsyncMessageBase, public SameProcessMessageQueue::Runnable { public: nsAsyncMessageToParent(JS::RootingContext* aRootingCx, JS::Handle aCpows, nsInProcessTabChildGlobal* aTabChild) : nsSameProcessAsyncMessageBase(aRootingCx, aCpows) , mTabChild(aTabChild) { } virtual nsresult HandleMessage() override { nsCOMPtr fl = mTabChild->GetFrameLoader(); ReceiveMessage(mTabChild->mOwner, fl, mTabChild->mChromeMessageManager); return NS_OK; } RefPtr mTabChild; }; nsresult nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx, const nsAString& aMessage, StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal) { SameProcessMessageQueue* queue = SameProcessMessageQueue::Get(); JS::RootingContext* rcx = JS::RootingContext::get(aCx); RefPtr ev = new nsAsyncMessageToParent(rcx, aCpows, this); nsresult rv = ev->Init(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