From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- toolkit/actors/BackgroundThumbnailsChild.sys.mjs | 101 +++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 toolkit/actors/BackgroundThumbnailsChild.sys.mjs (limited to 'toolkit/actors/BackgroundThumbnailsChild.sys.mjs') diff --git a/toolkit/actors/BackgroundThumbnailsChild.sys.mjs b/toolkit/actors/BackgroundThumbnailsChild.sys.mjs new file mode 100644 index 0000000000..d2d168cda4 --- /dev/null +++ b/toolkit/actors/BackgroundThumbnailsChild.sys.mjs @@ -0,0 +1,101 @@ +/* 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.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(); + } + } +} -- cgit v1.2.3