summaryrefslogtreecommitdiffstats
path: root/dom/base/BarProps.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/base/BarProps.cpp
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/base/BarProps.cpp')
-rw-r--r--dom/base/BarProps.cpp242
1 files changed, 242 insertions, 0 deletions
diff --git a/dom/base/BarProps.cpp b/dom/base/BarProps.cpp
new file mode 100644
index 0000000000..6b72817320
--- /dev/null
+++ b/dom/base/BarProps.cpp
@@ -0,0 +1,242 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "mozilla/dom/BarProps.h"
+#include "mozilla/dom/BarPropBinding.h"
+#include "nsContentUtils.h"
+#include "nsDocShell.h"
+#include "nsGlobalWindow.h"
+#include "nsIWebBrowserChrome.h"
+
+namespace mozilla::dom {
+
+//
+// Basic (virtual) BarProp class implementation
+//
+BarProp::BarProp(nsGlobalWindowInner* aWindow) : mDOMWindow(aWindow) {}
+
+BarProp::~BarProp() = default;
+
+nsPIDOMWindowInner* BarProp::GetParentObject() const { return mDOMWindow; }
+
+JSObject* BarProp::WrapObject(JSContext* aCx,
+ JS::Handle<JSObject*> aGivenProto) {
+ return BarProp_Binding::Wrap(aCx, this, aGivenProto);
+}
+
+NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BarProp, mDOMWindow)
+NS_IMPL_CYCLE_COLLECTING_ADDREF(BarProp)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(BarProp)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BarProp)
+ NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
+ NS_INTERFACE_MAP_ENTRY(nsISupports)
+NS_INTERFACE_MAP_END
+
+bool BarProp::GetVisibleByIsPopup() {
+ // For web content, return the value defined by the spec, instead of
+ // the actual visibility of each bar.
+ //
+ // If this browsing context is created by requesting a popup, all
+ // `BarProp.visible` should return false.
+ RefPtr<BrowsingContext> bc = GetBrowsingContext();
+ if (!bc || bc->IsDiscarded()) {
+ return true;
+ }
+ bc = bc->Top();
+ bool isPopup = bc->GetIsPopupRequested();
+ return !isPopup;
+}
+
+bool BarProp::GetVisibleByFlag(uint32_t aChromeFlag, CallerType aCallerType,
+ ErrorResult& aRv) {
+ if (aCallerType != CallerType::System) {
+ return GetVisibleByIsPopup();
+ }
+
+ nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
+ NS_ENSURE_TRUE(browserChrome, false);
+
+ uint32_t chromeFlags;
+
+ if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ return false;
+ }
+
+ return (chromeFlags & aChromeFlag);
+}
+
+void BarProp::SetVisibleByFlag(bool aVisible, uint32_t aChromeFlag,
+ CallerType aCallerType, ErrorResult& aRv) {
+ nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
+ NS_ENSURE_TRUE_VOID(browserChrome);
+
+ if (aCallerType != CallerType::System) {
+ return;
+ }
+
+ uint32_t chromeFlags;
+
+ if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ return;
+ }
+
+ if (aVisible)
+ chromeFlags |= aChromeFlag;
+ else
+ chromeFlags &= ~aChromeFlag;
+
+ if (NS_FAILED(browserChrome->SetChromeFlags(chromeFlags))) {
+ aRv.Throw(NS_ERROR_FAILURE);
+ }
+}
+
+already_AddRefed<nsIWebBrowserChrome> BarProp::GetBrowserChrome() {
+ if (!mDOMWindow) {
+ return nullptr;
+ }
+
+ return mDOMWindow->GetWebBrowserChrome();
+}
+
+BrowsingContext* BarProp::GetBrowsingContext() {
+ if (!mDOMWindow) {
+ return nullptr;
+ }
+
+ return mDOMWindow->GetBrowsingContext();
+}
+
+//
+// MenubarProp class implementation
+//
+
+MenubarProp::MenubarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
+
+MenubarProp::~MenubarProp() = default;
+
+bool MenubarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_MENUBAR,
+ aCallerType, aRv);
+}
+
+void MenubarProp::SetVisible(bool aVisible, CallerType aCallerType,
+ ErrorResult& aRv) {
+ BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_MENUBAR,
+ aCallerType, aRv);
+}
+
+//
+// ToolbarProp class implementation
+//
+
+ToolbarProp::ToolbarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
+
+ToolbarProp::~ToolbarProp() = default;
+
+bool ToolbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_TOOLBAR,
+ aCallerType, aRv);
+}
+
+void ToolbarProp::SetVisible(bool aVisible, CallerType aCallerType,
+ ErrorResult& aRv) {
+ BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_TOOLBAR,
+ aCallerType, aRv);
+}
+
+//
+// LocationbarProp class implementation
+//
+
+LocationbarProp::LocationbarProp(nsGlobalWindowInner* aWindow)
+ : BarProp(aWindow) {}
+
+LocationbarProp::~LocationbarProp() = default;
+
+bool LocationbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_LOCATIONBAR,
+ aCallerType, aRv);
+}
+
+void LocationbarProp::SetVisible(bool aVisible, CallerType aCallerType,
+ ErrorResult& aRv) {
+ BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_LOCATIONBAR,
+ aCallerType, aRv);
+}
+
+//
+// PersonalbarProp class implementation
+//
+
+PersonalbarProp::PersonalbarProp(nsGlobalWindowInner* aWindow)
+ : BarProp(aWindow) {}
+
+PersonalbarProp::~PersonalbarProp() = default;
+
+bool PersonalbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
+ aCallerType, aRv);
+}
+
+void PersonalbarProp::SetVisible(bool aVisible, CallerType aCallerType,
+ ErrorResult& aRv) {
+ BarProp::SetVisibleByFlag(
+ aVisible, nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR, aCallerType, aRv);
+}
+
+//
+// StatusbarProp class implementation
+//
+
+StatusbarProp::StatusbarProp(nsGlobalWindowInner* aWindow) : BarProp(aWindow) {}
+
+StatusbarProp::~StatusbarProp() = default;
+
+bool StatusbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_STATUSBAR,
+ aCallerType, aRv);
+}
+
+void StatusbarProp::SetVisible(bool aVisible, CallerType aCallerType,
+ ErrorResult& aRv) {
+ return BarProp::SetVisibleByFlag(
+ aVisible, nsIWebBrowserChrome::CHROME_STATUSBAR, aCallerType, aRv);
+}
+
+//
+// ScrollbarsProp class implementation
+//
+
+ScrollbarsProp::ScrollbarsProp(nsGlobalWindowInner* aWindow)
+ : BarProp(aWindow) {}
+
+ScrollbarsProp::~ScrollbarsProp() = default;
+
+bool ScrollbarsProp::GetVisible(CallerType aCallerType, ErrorResult& aRv) {
+ if (aCallerType != CallerType::System) {
+ return BarProp::GetVisibleByIsPopup();
+ }
+
+ if (!mDOMWindow) {
+ return true;
+ }
+
+ nsIDocShell* ds = mDOMWindow->GetDocShell();
+ if (!ds) {
+ return true;
+ }
+
+ ScrollbarPreference pref = nsDocShell::Cast(ds)->ScrollbarPreference();
+ return pref != ScrollbarPreference::Never;
+}
+
+void ScrollbarsProp::SetVisible(bool aVisible, CallerType, ErrorResult&) {
+ /* Do nothing */
+}
+
+} // namespace mozilla::dom