/* -*- 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" #include "mozilla/dom/StructuredCloneUtils.h" #include "js/StructuredClone.h" using mozilla::dom::StructuredCloneData; using mozilla::dom::StructuredCloneClosure; using namespace mozilla; using namespace mozilla::dom; bool nsInProcessTabChildGlobal::DoSendBlockingMessage(JSContext* aCx, const nsAString& aMessage, const dom::StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal, nsTArray* aRetVal, bool aIsSync) { SameProcessMessageQueue* queue = SameProcessMessageQueue::Get(); queue->Flush(); if (mChromeMessageManager) { SameProcessCpowHolder cpows(js::GetRuntime(aCx), aCpows); nsRefPtr 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(JSContext* aCx, nsInProcessTabChildGlobal* aTabChild, const nsAString& aMessage, const StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal) : nsSameProcessAsyncMessageBase(aCx, aMessage, aData, aCpows, aPrincipal), mTabChild(aTabChild) { } virtual nsresult HandleMessage() override { nsCOMPtr fl = mTabChild->GetFrameLoader(); ReceiveMessage(mTabChild->mOwner, fl, mTabChild->mChromeMessageManager); return NS_OK; } nsRefPtr mTabChild; }; bool nsInProcessTabChildGlobal::DoSendAsyncMessage(JSContext* aCx, const nsAString& aMessage, const StructuredCloneData& aData, JS::Handle aCpows, nsIPrincipal* aPrincipal) { SameProcessMessageQueue* queue = SameProcessMessageQueue::Get(); nsRefPtr ev = new nsAsyncMessageToParent(aCx, this, aMessage, aData, aCpows, aPrincipal); queue->Push(ev); return true; } 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