summaryrefslogtreecommitdiffstats
path: root/toolkit/actors/BackgroundThumbnailsChild.sys.mjs
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 /toolkit/actors/BackgroundThumbnailsChild.sys.mjs
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--toolkit/actors/BackgroundThumbnailsChild.sys.mjs102
1 files changed, 102 insertions, 0 deletions
diff --git a/toolkit/actors/BackgroundThumbnailsChild.sys.mjs b/toolkit/actors/BackgroundThumbnailsChild.sys.mjs
new file mode 100644
index 0000000000..3af51b3b80
--- /dev/null
+++ b/toolkit/actors/BackgroundThumbnailsChild.sys.mjs
@@ -0,0 +1,102 @@
+/* vim: set ts=2 sw=2 sts=2 et 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/. */
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ PageThumbUtils: "resource://gre/modules/PageThumbUtils.sys.mjs",
+});
+
+// NOTE: Copied from nsSandboxFlags.h
+/**
+ * This flag prevents content from creating new auxiliary browsing contexts,
+ * e.g. using the target attribute, or the window.open() method.
+ */
+const SANDBOXED_AUXILIARY_NAVIGATION = 0x2;
+
+export class BackgroundThumbnailsChild extends JSWindowActorChild {
+ receiveMessage(message) {
+ switch (message.name) {
+ case "Browser:Thumbnail:ContentInfo": {
+ if (
+ message.data.isImage ||
+ this.contentWindow.ImageDocument.isInstance(this.document)
+ ) {
+ // To avoid sending additional messages between processes, we return
+ // the image data directly with the size info.
+ return lazy.PageThumbUtils.createImageThumbnailCanvas(
+ this.contentWindow,
+ this.document.location,
+ message.data.targetWidth,
+ message.data.backgroundColor
+ );
+ }
+
+ let [width, height] = lazy.PageThumbUtils.getContentSize(
+ this.contentWindow
+ );
+ return { width, height };
+ }
+
+ case "Browser:Thumbnail:LoadURL": {
+ let docShell = this.docShell.QueryInterface(Ci.nsIWebNavigation);
+
+ // We want a low network priority for this service - lower than b/g tabs
+ // etc - so set it to the lowest priority available.
+ docShell
+ .QueryInterface(Ci.nsIDocumentLoader)
+ .loadGroup.QueryInterface(Ci.nsISupportsPriority).priority =
+ Ci.nsISupportsPriority.PRIORITY_LOWEST;
+
+ docShell.allowMedia = false;
+ docShell.allowPlugins = false;
+ docShell.allowContentRetargeting = false;
+ let defaultFlags =
+ Ci.nsIRequest.LOAD_ANONYMOUS |
+ Ci.nsIRequest.LOAD_BYPASS_CACHE |
+ Ci.nsIRequest.INHIBIT_CACHING |
+ Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY;
+ docShell.defaultLoadFlags = defaultFlags;
+ this.browsingContext.sandboxFlags |= SANDBOXED_AUXILIARY_NAVIGATION;
+ docShell.useTrackingProtection = true;
+
+ // Get the document to force a content viewer to be created, otherwise
+ // the first load can fail.
+ if (!this.document) {
+ return false;
+ }
+
+ let loadURIOptions = {
+ // Bug 1498603 verify usages of systemPrincipal here
+ triggeringPrincipal:
+ Services.scriptSecurityManager.getSystemPrincipal(),
+ loadFlags: Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT,
+ };
+ try {
+ docShell.loadURI(
+ Services.io.newURI(message.data.url),
+ loadURIOptions
+ );
+ } catch (ex) {
+ return false;
+ }
+
+ return true;
+ }
+ }
+
+ return undefined;
+ }
+
+ handleEvent(event) {
+ if (event.type == "DOMDocElementInserted") {
+ // Arrange to prevent (most) popup dialogs for this window - popups done
+ // in the parent (eg, auth) aren't prevented, but alert() etc are.
+ // disableDialogs only works on the current inner window, so it has
+ // to be called every page load, but before scripts run.
+ this.contentWindow.windowUtils.disableDialogs();
+ }
+ }
+}