2010-05-18 16:28:37 +04:00
|
|
|
/* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 8; -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et 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
|
|
|
|
|
|
|
#ifndef nsInProcessTabChildGlobal_h
|
|
|
|
#define nsInProcessTabChildGlobal_h
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrameMessageManager.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIClassInfo.h"
|
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsCOMArray.h"
|
2013-09-19 17:54:39 +04:00
|
|
|
#include "nsIRunnable.h"
|
2013-04-04 13:27:06 +04:00
|
|
|
#include "nsIGlobalObject.h"
|
2013-09-09 07:28:48 +04:00
|
|
|
#include "nsIScriptObjectPrincipal.h"
|
2013-04-04 13:27:40 +04:00
|
|
|
#include "nsWeakReference.h"
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class EventChainPreVisitor;
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
class nsInProcessTabChildGlobal : public mozilla::DOMEventTargetHelper,
|
2015-02-20 04:10:44 +03:00
|
|
|
public nsMessageManagerScriptExecutor,
|
2010-05-18 16:28:37 +04:00
|
|
|
public nsIInProcessContentFrameMessageManager,
|
2013-04-04 13:27:06 +04:00
|
|
|
public nsIGlobalObject,
|
2013-09-09 07:28:48 +04:00
|
|
|
public nsIScriptObjectPrincipal,
|
2013-04-04 13:27:40 +04:00
|
|
|
public nsSupportsWeakReference,
|
2012-09-28 09:43:12 +04:00
|
|
|
public mozilla::dom::ipc::MessageManagerCallback
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsInProcessTabChildGlobal(nsIDocShell* aShell, nsIContent* aOwner,
|
|
|
|
nsFrameMessageManager* aChrome);
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2014-06-13 21:56:38 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(nsInProcessTabChildGlobal,
|
|
|
|
mozilla::DOMEventTargetHelper)
|
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
NS_FORWARD_SAFE_NSIMESSAGELISTENERMANAGER(mMessageManager)
|
|
|
|
NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)
|
2011-10-01 20:14:36 +04:00
|
|
|
NS_IMETHOD SendSyncMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2011-10-01 20:14:36 +04:00
|
|
|
JSContext* aCx,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t aArgc,
|
2015-01-03 05:13:39 +03:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) MOZ_OVERRIDE
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2011-10-01 20:14:36 +04:00
|
|
|
return mMessageManager
|
2013-11-06 21:21:15 +04:00
|
|
|
? mMessageManager->SendSyncMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2011-10-01 20:14:36 +04:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2013-10-01 20:15:06 +04:00
|
|
|
NS_IMETHOD SendRpcMessage(const nsAString& aMessageName,
|
2014-01-09 21:39:36 +04:00
|
|
|
JS::Handle<JS::Value> aObject,
|
|
|
|
JS::Handle<JS::Value> aRemote,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 20:15:06 +04:00
|
|
|
JSContext* aCx,
|
|
|
|
uint8_t aArgc,
|
2015-01-03 05:13:39 +03:00
|
|
|
JS::MutableHandle<JS::Value> aRetval) MOZ_OVERRIDE
|
2013-10-01 20:15:06 +04:00
|
|
|
{
|
|
|
|
return mMessageManager
|
2013-11-06 21:21:15 +04:00
|
|
|
? mMessageManager->SendRpcMessage(aMessageName, aObject, aRemote,
|
|
|
|
aPrincipal, aCx, aArgc, aRetval)
|
2013-10-01 20:15:06 +04:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD GetContent(nsIDOMWindow** aContent) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetDocShell(nsIDocShell** aDocShell) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD Dump(const nsAString& aStr) MOZ_OVERRIDE
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
return mMessageManager ? mMessageManager->Dump(aStr) : NS_OK;
|
|
|
|
}
|
2013-05-30 00:43:41 +04:00
|
|
|
NS_IMETHOD PrivateNoteIntentionalCrash() MOZ_OVERRIDE;
|
2011-06-25 13:52:00 +04:00
|
|
|
NS_IMETHOD Btoa(const nsAString& aBinaryData,
|
2013-05-30 00:43:41 +04:00
|
|
|
nsAString& aAsciiBase64String) MOZ_OVERRIDE;
|
2011-06-25 13:52:00 +04:00
|
|
|
NS_IMETHOD Atob(const nsAString& aAsciiString,
|
2013-05-30 00:43:41 +04:00
|
|
|
nsAString& aBinaryData) MOZ_OVERRIDE;
|
2011-06-25 13:52:00 +04:00
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_DECL_NSIINPROCESSCONTENTFRAMEMESSAGEMANAGER
|
|
|
|
|
2012-09-28 09:43:12 +04:00
|
|
|
/**
|
|
|
|
* MessageManagerCallback methods that we override.
|
|
|
|
*/
|
2013-10-01 20:15:06 +04:00
|
|
|
virtual bool DoSendBlockingMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
|
|
|
JS::Handle<JSObject *> aCpows,
|
2013-11-06 21:21:15 +04:00
|
|
|
nsIPrincipal* aPrincipal,
|
2013-10-01 20:15:06 +04:00
|
|
|
InfallibleTArray<nsString>* aJSONRetVal,
|
|
|
|
bool aIsSync) MOZ_OVERRIDE;
|
2013-07-11 02:05:39 +04:00
|
|
|
virtual bool DoSendAsyncMessage(JSContext* aCx,
|
|
|
|
const nsAString& aMessage,
|
|
|
|
const mozilla::dom::StructuredCloneData& aData,
|
2013-11-06 21:21:15 +04:00
|
|
|
JS::Handle<JSObject *> aCpows,
|
|
|
|
nsIPrincipal* aPrincipal) MOZ_OVERRIDE;
|
2012-09-28 09:43:12 +04:00
|
|
|
|
2014-03-18 08:48:19 +04:00
|
|
|
virtual nsresult PreHandleEvent(
|
|
|
|
mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
|
2010-05-18 16:28:37 +04:00
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseCapture)
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
|
|
|
// By default add listeners only for trusted events!
|
2014-04-01 10:13:50 +04:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture, false,
|
|
|
|
2);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
|
|
|
NS_IMETHOD AddEventListener(const nsAString& aType,
|
|
|
|
nsIDOMEventListener* aListener,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseCapture, bool aWantsUntrusted,
|
2013-05-30 00:43:41 +04:00
|
|
|
uint8_t optional_argc) MOZ_OVERRIDE
|
2010-05-18 16:28:37 +04:00
|
|
|
{
|
2014-04-01 10:13:50 +04:00
|
|
|
return mozilla::DOMEventTargetHelper::AddEventListener(aType, aListener,
|
|
|
|
aUseCapture,
|
|
|
|
aWantsUntrusted,
|
|
|
|
optional_argc);
|
2010-05-18 16:28:37 +04:00
|
|
|
}
|
2014-04-01 10:13:50 +04:00
|
|
|
using mozilla::DOMEventTargetHelper::AddEventListener;
|
2010-05-18 16:28:37 +04:00
|
|
|
|
2013-06-30 19:00:19 +04:00
|
|
|
virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); }
|
2013-05-30 00:43:41 +04:00
|
|
|
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; }
|
2013-11-24 09:32:45 +04:00
|
|
|
void LoadFrameScript(const nsAString& aURL, bool aRunInGlobalScope);
|
2010-05-18 16:28:37 +04:00
|
|
|
void Disconnect();
|
2011-09-29 10:19:26 +04:00
|
|
|
void SendMessageToParent(const nsString& aMessage, bool aSync,
|
2010-05-18 16:28:37 +04:00
|
|
|
const nsString& aJSON,
|
|
|
|
nsTArray<nsString>* aJSONRetVal);
|
|
|
|
nsFrameMessageManager* GetInnerManager()
|
|
|
|
{
|
|
|
|
return static_cast<nsFrameMessageManager*>(mMessageManager.get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetOwner(nsIContent* aOwner) { mOwner = aOwner; }
|
|
|
|
nsFrameMessageManager* GetChromeMessageManager()
|
|
|
|
{
|
|
|
|
return mChromeMessageManager;
|
|
|
|
}
|
|
|
|
void SetChromeMessageManager(nsFrameMessageManager* aParent)
|
|
|
|
{
|
|
|
|
mChromeMessageManager = aParent;
|
|
|
|
}
|
2010-08-12 20:47:22 +04:00
|
|
|
|
|
|
|
void DelayedDisconnect();
|
2013-04-04 13:27:06 +04:00
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
virtual JSObject* GetGlobalJSObject() MOZ_OVERRIDE {
|
2013-04-04 13:27:06 +04:00
|
|
|
if (!mGlobal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-20 16:44:18 +04:00
|
|
|
return mGlobal->GetJSObject();
|
2013-04-04 13:27:06 +04:00
|
|
|
}
|
2014-10-07 13:44:48 +04:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx) MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
MOZ_CRASH("nsInProcessTabChildGlobal doesn't use DOM bindings!");
|
|
|
|
}
|
2010-05-18 16:28:37 +04:00
|
|
|
protected:
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~nsInProcessTabChildGlobal();
|
|
|
|
|
2010-05-18 16:28:37 +04:00
|
|
|
nsresult Init();
|
|
|
|
nsresult InitTabChildGlobal();
|
|
|
|
nsCOMPtr<nsIContentFrameMessageManager> mMessageManager;
|
|
|
|
nsCOMPtr<nsIDocShell> mDocShell;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mInitialized;
|
|
|
|
bool mLoadingScript;
|
2012-05-08 20:20:35 +04:00
|
|
|
|
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
|
|
|
// Is this the message manager for an in-process <iframe mozbrowser> or
|
|
|
|
// <iframe mozapp>? This affects where events get sent, so it affects
|
|
|
|
// PreHandleEvent.
|
|
|
|
bool mIsBrowserOrAppFrame;
|
2010-05-18 16:28:37 +04:00
|
|
|
public:
|
|
|
|
nsIContent* mOwner;
|
|
|
|
nsFrameMessageManager* mChromeMessageManager;
|
2015-02-18 22:47:27 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIRunnable> > mASyncMessages;
|
2010-05-18 16:28:37 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|