summaryrefslogtreecommitdiffstats
path: root/dom/canvas/nsICanvasRenderingContextInternal.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/canvas/nsICanvasRenderingContextInternal.cpp
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/nsICanvasRenderingContextInternal.cpp')
-rw-r--r--dom/canvas/nsICanvasRenderingContextInternal.cpp118
1 files changed, 118 insertions, 0 deletions
diff --git a/dom/canvas/nsICanvasRenderingContextInternal.cpp b/dom/canvas/nsICanvasRenderingContextInternal.cpp
new file mode 100644
index 0000000000..c463a00a1a
--- /dev/null
+++ b/dom/canvas/nsICanvasRenderingContextInternal.cpp
@@ -0,0 +1,118 @@
+/* -*- Mode: C++; tab-width: 40; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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 "nsICanvasRenderingContextInternal.h"
+
+#include "mozilla/dom/CanvasUtils.h"
+#include "mozilla/dom/Document.h"
+#include "mozilla/dom/WorkerCommon.h"
+#include "mozilla/dom/WorkerPrivate.h"
+#include "mozilla/PresShell.h"
+#include "nsPIDOMWindow.h"
+#include "nsRefreshDriver.h"
+
+nsICanvasRenderingContextInternal::nsICanvasRenderingContextInternal() =
+ default;
+
+nsICanvasRenderingContextInternal::~nsICanvasRenderingContextInternal() =
+ default;
+
+mozilla::PresShell* nsICanvasRenderingContextInternal::GetPresShell() {
+ if (mCanvasElement) {
+ return mCanvasElement->OwnerDoc()->GetPresShell();
+ }
+ return nullptr;
+}
+
+nsIGlobalObject* nsICanvasRenderingContextInternal::GetParentObject() const {
+ if (mCanvasElement) {
+ return mCanvasElement->OwnerDoc()->GetScopeObject();
+ }
+ if (mOffscreenCanvas) {
+ return mOffscreenCanvas->GetParentObject();
+ }
+ return nullptr;
+}
+
+nsIPrincipal* nsICanvasRenderingContextInternal::PrincipalOrNull() const {
+ if (mCanvasElement) {
+ return mCanvasElement->NodePrincipal();
+ }
+ if (mOffscreenCanvas) {
+ nsIGlobalObject* global = mOffscreenCanvas->GetParentObject();
+ if (global) {
+ return global->PrincipalOrNull();
+ }
+ }
+ return nullptr;
+}
+
+nsICookieJarSettings* nsICanvasRenderingContextInternal::GetCookieJarSettings()
+ const {
+ if (mCanvasElement) {
+ return mCanvasElement->OwnerDoc()->CookieJarSettings();
+ }
+
+ // If there is an offscreen canvas, attempt to retrieve its owner window
+ // and return the cookieJarSettings for the window's document, if available.
+ if (mOffscreenCanvas) {
+ nsCOMPtr<nsPIDOMWindowInner> win =
+ do_QueryInterface(mOffscreenCanvas->GetOwnerGlobal());
+
+ if (win) {
+ return win->GetExtantDoc()->CookieJarSettings();
+ }
+
+ // If the owner window cannot be retrieved, check if there is a current
+ // worker and return its cookie jar settings if available.
+ mozilla::dom::WorkerPrivate* worker =
+ mozilla::dom::GetCurrentThreadWorkerPrivate();
+
+ if (worker) {
+ return worker->CookieJarSettings();
+ }
+ }
+
+ return nullptr;
+}
+
+void nsICanvasRenderingContextInternal::RemovePostRefreshObserver() {
+ if (mRefreshDriver) {
+ mRefreshDriver->RemovePostRefreshObserver(this);
+ mRefreshDriver = nullptr;
+ }
+}
+
+void nsICanvasRenderingContextInternal::AddPostRefreshObserverIfNecessary() {
+ if (!GetPresShell() || !GetPresShell()->GetPresContext() ||
+ !GetPresShell()->GetPresContext()->RefreshDriver()) {
+ return;
+ }
+ mRefreshDriver = GetPresShell()->GetPresContext()->RefreshDriver();
+ mRefreshDriver->AddPostRefreshObserver(this);
+}
+
+void nsICanvasRenderingContextInternal::DoSecurityCheck(
+ nsIPrincipal* aPrincipal, bool aForceWriteOnly, bool aCORSUsed) {
+ if (mCanvasElement) {
+ mozilla::CanvasUtils::DoDrawImageSecurityCheck(mCanvasElement, aPrincipal,
+ aForceWriteOnly, aCORSUsed);
+ } else if (mOffscreenCanvas) {
+ mozilla::CanvasUtils::DoDrawImageSecurityCheck(mOffscreenCanvas, aPrincipal,
+ aForceWriteOnly, aCORSUsed);
+ }
+}
+
+bool nsICanvasRenderingContextInternal::ShouldResistFingerprinting(
+ mozilla::RFPTarget aTarget) const {
+ if (mCanvasElement) {
+ return mCanvasElement->OwnerDoc()->ShouldResistFingerprinting(aTarget);
+ }
+ if (mOffscreenCanvas) {
+ return mOffscreenCanvas->ShouldResistFingerprinting(aTarget);
+ }
+ // Last resort, just check the global preference
+ return nsContentUtils::ShouldResistFingerprinting("Fallback", aTarget);
+}