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 #include "nsOpenWindowInfo.h"
8 #include "mozilla/OriginAttributes.h"
9 #include "mozilla/dom/ToJSValue.h"
10 #include "mozilla/dom/BrowserParent.h"
11
NS_IMPL_ISUPPORTS(nsOpenWindowInfo,nsIOpenWindowInfo)12 NS_IMPL_ISUPPORTS(nsOpenWindowInfo, nsIOpenWindowInfo)
13
14 NS_IMETHODIMP nsOpenWindowInfo::GetParent(
15 mozilla::dom::BrowsingContext** aParent) {
16 *aParent = do_AddRef(mParent).take();
17 return NS_OK;
18 }
19
GetIsRemote(bool * aIsRemote)20 NS_IMETHODIMP nsOpenWindowInfo::GetIsRemote(bool* aIsRemote) {
21 *aIsRemote = mIsRemote;
22 return NS_OK;
23 }
24
GetForceNoOpener(bool * aForceNoOpener)25 NS_IMETHODIMP nsOpenWindowInfo::GetForceNoOpener(bool* aForceNoOpener) {
26 *aForceNoOpener = mForceNoOpener;
27 return NS_OK;
28 }
29
GetScriptableOriginAttributes(JSContext * aCx,JS::MutableHandle<JS::Value> aAttrs)30 NS_IMETHODIMP nsOpenWindowInfo::GetScriptableOriginAttributes(
31 JSContext* aCx, JS::MutableHandle<JS::Value> aAttrs) {
32 bool ok = ToJSValue(aCx, mOriginAttributes, aAttrs);
33 NS_ENSURE_TRUE(ok, NS_ERROR_FAILURE);
34 return NS_OK;
35 }
36
GetOriginAttributes()37 const OriginAttributes& nsOpenWindowInfo::GetOriginAttributes() {
38 return mOriginAttributes;
39 }
40
GetNextRemoteBrowser()41 BrowserParent* nsOpenWindowInfo::GetNextRemoteBrowser() {
42 return mNextRemoteBrowser;
43 }
44
45 nsIBrowsingContextReadyCallback*
BrowsingContextReadyCallback()46 nsOpenWindowInfo::BrowsingContextReadyCallback() {
47 return mBrowsingContextReadyCallback;
48 }
49
NS_IMPL_ISUPPORTS(nsBrowsingContextReadyCallback,nsIBrowsingContextReadyCallback)50 NS_IMPL_ISUPPORTS(nsBrowsingContextReadyCallback,
51 nsIBrowsingContextReadyCallback)
52
53 nsBrowsingContextReadyCallback::nsBrowsingContextReadyCallback(
54 RefPtr<BrowsingContextCallbackReceivedPromise::Private> aPromise)
55 : mPromise(std::move(aPromise)) {}
56
~nsBrowsingContextReadyCallback()57 nsBrowsingContextReadyCallback::~nsBrowsingContextReadyCallback() {
58 if (mPromise) {
59 mPromise->Reject(NS_ERROR_FAILURE, __func__);
60 }
61 mPromise = nullptr;
62 }
63
BrowsingContextReady(BrowsingContext * aBC)64 NS_IMETHODIMP nsBrowsingContextReadyCallback::BrowsingContextReady(
65 BrowsingContext* aBC) {
66 MOZ_DIAGNOSTIC_ASSERT(mPromise,
67 "The 'browsing context ready' callback is null");
68 if (!mPromise) {
69 return NS_OK;
70 }
71 if (aBC) {
72 mPromise->Resolve(aBC, __func__);
73 } else {
74 mPromise->Reject(NS_ERROR_FAILURE, __func__);
75 }
76 mPromise = nullptr;
77 return NS_OK;
78 }
79