Bug 1665252 - remove allowpaymentrequest attribute from HTMLIFrameElement r=dom-worke...
[gecko.git] / dom / base / BarProps.cpp
blobf1c687c2597163b092b8e6c0b0aa1ecceb6feccf
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 #include "mozilla/dom/BarProps.h"
8 #include "mozilla/dom/BarPropBinding.h"
9 #include "nsContentUtils.h"
10 #include "nsDocShell.h"
11 #include "nsGlobalWindow.h"
12 #include "nsIWebBrowserChrome.h"
14 namespace mozilla {
15 namespace dom {
18 // Basic (virtual) BarProp class implementation
20 BarProp::BarProp(nsGlobalWindowInner* aWindow) : mDOMWindow(aWindow) {}
22 BarProp::~BarProp() = default;
24 nsPIDOMWindowInner* BarProp::GetParentObject() const { return mDOMWindow; }
26 JSObject* BarProp::WrapObject(JSContext* aCx,
27 JS::Handle<JSObject*> aGivenProto) {
28 return BarProp_Binding::Wrap(aCx, this, aGivenProto);
31 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BarProp, mDOMWindow)
32 NS_IMPL_CYCLE_COLLECTING_ADDREF(BarProp)
33 NS_IMPL_CYCLE_COLLECTING_RELEASE(BarProp)
34 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BarProp)
35 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
36 NS_INTERFACE_MAP_ENTRY(nsISupports)
37 NS_INTERFACE_MAP_END
39 bool BarProp::GetVisibleByFlag(uint32_t aChromeFlag, ErrorResult& aRv) {
40 nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
41 NS_ENSURE_TRUE(browserChrome, false);
43 uint32_t chromeFlags;
45 if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
46 aRv.Throw(NS_ERROR_FAILURE);
47 return false;
50 return (chromeFlags & aChromeFlag);
53 void BarProp::SetVisibleByFlag(bool aVisible, uint32_t aChromeFlag,
54 CallerType aCallerType, ErrorResult& aRv) {
55 nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
56 NS_ENSURE_TRUE_VOID(browserChrome);
58 if (aCallerType != CallerType::System) {
59 return;
62 uint32_t chromeFlags;
64 if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
65 aRv.Throw(NS_ERROR_FAILURE);
66 return;
69 if (aVisible)
70 chromeFlags |= aChromeFlag;
71 else
72 chromeFlags &= ~aChromeFlag;
74 if (NS_FAILED(browserChrome->SetChromeFlags(chromeFlags))) {
75 aRv.Throw(NS_ERROR_FAILURE);
79 already_AddRefed<nsIWebBrowserChrome> BarProp::GetBrowserChrome() {
80 if (!mDOMWindow) {
81 return nullptr;
84 return mDOMWindow->GetWebBrowserChrome();
88 // MenubarProp class implementation
91 MenubarProp::MenubarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
93 MenubarProp::~MenubarProp() = default;
95 bool MenubarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
96 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_MENUBAR, aRv);
99 void MenubarProp::SetVisible(bool aVisible, CallerType aCallerType,
100 ErrorResult& aRv) {
101 BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_MENUBAR,
102 aCallerType, aRv);
106 // ToolbarProp class implementation
109 ToolbarProp::ToolbarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
111 ToolbarProp::~ToolbarProp() = default;
113 bool ToolbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
114 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_TOOLBAR, aRv);
117 void ToolbarProp::SetVisible(bool aVisible, CallerType aCallerType,
118 ErrorResult& aRv) {
119 BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_TOOLBAR,
120 aCallerType, aRv);
124 // LocationbarProp class implementation
127 LocationbarProp::LocationbarProp(nsGlobalWindowInner* aWindow)
128 : BarProp(aWindow) {}
130 LocationbarProp::~LocationbarProp() = default;
132 bool LocationbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
133 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_LOCATIONBAR,
134 aRv);
137 void LocationbarProp::SetVisible(bool aVisible, CallerType aCallerType,
138 ErrorResult& aRv) {
139 BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_LOCATIONBAR,
140 aCallerType, aRv);
144 // PersonalbarProp class implementation
147 PersonalbarProp::PersonalbarProp(nsGlobalWindowInner* aWindow)
148 : BarProp(aWindow) {}
150 PersonalbarProp::~PersonalbarProp() = default;
152 bool PersonalbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
153 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
154 aRv);
157 void PersonalbarProp::SetVisible(bool aVisible, CallerType aCallerType,
158 ErrorResult& aRv) {
159 BarProp::SetVisibleByFlag(
160 aVisible, nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR, aCallerType, aRv);
164 // StatusbarProp class implementation
167 StatusbarProp::StatusbarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
169 StatusbarProp::~StatusbarProp() = default;
171 bool StatusbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
172 return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_STATUSBAR, aRv);
175 void StatusbarProp::SetVisible(bool aVisible, CallerType aCallerType,
176 ErrorResult& aRv) {
177 return BarProp::SetVisibleByFlag(
178 aVisible, nsIWebBrowserChrome::CHROME_STATUSBAR, aCallerType, aRv);
182 // ScrollbarsProp class implementation
185 ScrollbarsProp::ScrollbarsProp(nsGlobalWindowInner* aWindow)
186 : BarProp(aWindow) {}
188 ScrollbarsProp::~ScrollbarsProp() = default;
190 bool ScrollbarsProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
191 if (!mDOMWindow) {
192 return true;
195 nsIDocShell* ds = mDOMWindow->GetDocShell();
196 if (!ds) {
197 return true;
200 ScrollbarPreference pref = nsDocShell::Cast(ds)->ScrollbarPreference();
201 return pref != ScrollbarPreference::Never;
204 void ScrollbarsProp::SetVisible(bool aVisible, CallerType, ErrorResult&) {
205 /* Do nothing */
208 } // namespace dom
209 } // namespace mozilla