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_WindowProxyHolder_h__
8 #define mozilla_dom_WindowProxyHolder_h__
10 #include "mozilla/dom/BrowsingContext.h"
20 namespace mozilla::dom
{
23 * This class is used for passing arguments and the return value for WebIDL
24 * binding code that takes/returns a WindowProxy object and for WebIDL
25 * unions/dictionaries that contain a WindowProxy member. It should never
26 * contain null; if the value in WebIDL is nullable the binding code will use a
27 * Nullable<WindowProxyHolder>.
29 class WindowProxyHolder
{
31 WindowProxyHolder() = default;
32 explicit WindowProxyHolder(BrowsingContext
* aBC
) : mBrowsingContext(aBC
) {
33 MOZ_ASSERT(mBrowsingContext
, "Don't set WindowProxyHolder to null.");
35 explicit WindowProxyHolder(RefPtr
<BrowsingContext
>&& aBC
)
36 : mBrowsingContext(std::move(aBC
)) {
37 MOZ_ASSERT(mBrowsingContext
, "Don't set WindowProxyHolder to null.");
39 WindowProxyHolder
& operator=(BrowsingContext
* aBC
) {
40 mBrowsingContext
= aBC
;
41 MOZ_ASSERT(mBrowsingContext
, "Don't set WindowProxyHolder to null.");
44 WindowProxyHolder
& operator=(RefPtr
<BrowsingContext
>&& aBC
) {
45 mBrowsingContext
= std::move(aBC
);
46 MOZ_ASSERT(mBrowsingContext
, "Don't set WindowProxyHolder to null.");
50 BrowsingContext
* get() const {
51 MOZ_ASSERT(mBrowsingContext
, "WindowProxyHolder hasn't been initialized.");
52 return mBrowsingContext
;
56 friend void ImplCycleCollectionUnlink(WindowProxyHolder
& aProxy
);
58 RefPtr
<BrowsingContext
> mBrowsingContext
;
61 inline void ImplCycleCollectionTraverse(
62 nsCycleCollectionTraversalCallback
& aCallback
, WindowProxyHolder
& aProxy
,
63 const char* aName
, uint32_t aFlags
= 0) {
64 CycleCollectionNoteChild(aCallback
, aProxy
.get(), "mBrowsingContext", aFlags
);
67 inline void ImplCycleCollectionUnlink(WindowProxyHolder
& aProxy
) {
68 aProxy
.mBrowsingContext
= nullptr;
71 extern bool GetRemoteOuterWindowProxy(JSContext
* aCx
, BrowsingContext
* aContext
,
72 JS::Handle
<JSObject
*> aTransplantTo
,
73 JS::MutableHandle
<JSObject
*> aValue
);
75 } // namespace mozilla::dom
77 #endif /* mozilla_dom_WindowProxyHolder_h__ */