WindowProxyHolder.h (2657B)
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/. */ 6 7 #ifndef mozilla_dom_WindowProxyHolder_h__ 8 #define mozilla_dom_WindowProxyHolder_h__ 9 10 #include "mozilla/dom/BrowsingContext.h" 11 12 struct JSContext; 13 class JSObject; 14 15 namespace JS { 16 template <typename T> 17 class MutableHandle; 18 } // namespace JS 19 20 namespace mozilla::dom { 21 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>. 28 */ 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."); 34 } 35 explicit WindowProxyHolder(RefPtr<BrowsingContext>&& aBC) 36 : mBrowsingContext(std::move(aBC)) { 37 MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null."); 38 } 39 WindowProxyHolder& operator=(BrowsingContext* aBC) { 40 mBrowsingContext = aBC; 41 MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null."); 42 return *this; 43 } 44 WindowProxyHolder& operator=(RefPtr<BrowsingContext>&& aBC) { 45 mBrowsingContext = std::move(aBC); 46 MOZ_ASSERT(mBrowsingContext, "Don't set WindowProxyHolder to null."); 47 return *this; 48 } 49 50 BrowsingContext* get() const { 51 MOZ_ASSERT(mBrowsingContext, "WindowProxyHolder hasn't been initialized."); 52 return mBrowsingContext; 53 } 54 55 private: 56 friend void ImplCycleCollectionUnlink(WindowProxyHolder& aProxy); 57 58 RefPtr<BrowsingContext> mBrowsingContext; 59 }; 60 61 inline void ImplCycleCollectionTraverse( 62 nsCycleCollectionTraversalCallback& aCallback, WindowProxyHolder& aProxy, 63 const char* aName, uint32_t aFlags = 0) { 64 CycleCollectionNoteChild(aCallback, aProxy.get(), "mBrowsingContext", aFlags); 65 } 66 67 inline void ImplCycleCollectionUnlink(WindowProxyHolder& aProxy) { 68 aProxy.mBrowsingContext = nullptr; 69 } 70 71 extern bool GetRemoteOuterWindowProxy(JSContext* aCx, BrowsingContext* aContext, 72 JS::Handle<JSObject*> aTransplantTo, 73 JS::MutableHandle<JSObject*> aValue); 74 75 } // namespace mozilla::dom 76 77 #endif /* mozilla_dom_WindowProxyHolder_h__ */