1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_CanonicalBrowsingContext_h
8 #define mozilla_dom_CanonicalBrowsingContext_h
10 #include "mozilla/dom/BrowsingContext.h"
11 #include "mozilla/RefPtr.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsWrapperCache.h"
14 #include "nsTHashtable.h"
15 #include "nsHashKeys.h"
22 class WindowGlobalParent
;
24 // CanonicalBrowsingContext is a BrowsingContext living in the parent
25 // process, with whatever extra data that a BrowsingContext in the
27 class CanonicalBrowsingContext final
: public BrowsingContext
{
29 static void CleanupContexts(uint64_t aProcessId
);
30 static already_AddRefed
<CanonicalBrowsingContext
> Get(uint64_t aId
);
31 static CanonicalBrowsingContext
* Cast(BrowsingContext
* aContext
);
32 static const CanonicalBrowsingContext
* Cast(const BrowsingContext
* aContext
);
34 bool IsOwnedByProcess(uint64_t aProcessId
) const {
35 return mProcessId
== aProcessId
;
37 uint64_t OwnerProcessId() const { return mProcessId
; }
39 void GetWindowGlobals(nsTArray
<RefPtr
<WindowGlobalParent
>>& aWindows
);
41 // Called by WindowGlobalParent to register and unregister window globals.
42 void RegisterWindowGlobal(WindowGlobalParent
* aGlobal
);
43 void UnregisterWindowGlobal(WindowGlobalParent
* aGlobal
);
45 // The current active WindowGlobal.
46 WindowGlobalParent
* GetCurrentWindowGlobal() const {
47 return mCurrentWindowGlobal
;
49 void SetCurrentWindowGlobal(WindowGlobalParent
* aGlobal
);
51 JSObject
* WrapObject(JSContext
* aCx
,
52 JS::Handle
<JSObject
*> aGivenProto
) override
;
54 // This functions would set/reset its user gesture activation flag and then
55 // notify other browsing contexts which are not the one related with the
56 // current window global to set/reset the flag. (the corresponding browsing
57 // context of the current global window has been set/reset before calling this
59 void NotifySetUserGestureActivationFromIPC(bool aIsUserGestureActivation
);
62 void Traverse(nsCycleCollectionTraversalCallback
& cb
);
65 using Type
= BrowsingContext::Type
;
66 CanonicalBrowsingContext(BrowsingContext
* aParent
, BrowsingContext
* aOpener
,
67 const nsAString
& aName
, uint64_t aBrowsingContextId
,
68 uint64_t aProcessId
, Type aType
= Type::Chrome
);
71 friend class BrowsingContext
;
73 // XXX(farre): Store a ContentParent pointer here rather than mProcessId?
74 // Indicates which process owns the docshell.
77 // All live window globals within this browsing context.
78 nsTHashtable
<nsRefPtrHashKey
<WindowGlobalParent
>> mWindowGlobals
;
79 RefPtr
<WindowGlobalParent
> mCurrentWindowGlobal
;
83 } // namespace mozilla
85 #endif // !defined(mozilla_dom_CanonicalBrowsingContext_h)