Bug 1852740: add tests for the `fetchpriority` attribute in Link headers. r=necko...
[gecko.git] / dom / base / WindowProxyHolder.h
blobb2887f236cb033ae4cdf98e7349c9f8fa804b264
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"
12 struct JSContext;
13 class JSObject;
15 namespace JS {
16 template <typename T>
17 class MutableHandle;
18 } // namespace JS
20 namespace mozilla::dom {
22 /**
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 {
30 public:
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.");
42 return *this;
44 WindowProxyHolder& operator=(RefPtr<BrowsingContext>&& aBC) {
45 mBrowsingContext = std::move(aBC);
46 MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null.");
47 return *this;
50 BrowsingContext* get() const {
51 MOZ_ASSERT(mBrowsingContext, "WindowProxyHolder hasn't been initialized.");
52 return mBrowsingContext;
55 private:
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__ */