1 /* vim: set ts=2 sw=2 sts=2 et tw=80: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 ChromeUtils.defineESModuleGetters(lazy, {
9 PageThumbUtils: "resource://gre/modules/PageThumbUtils.sys.mjs",
12 // NOTE: Copied from nsSandboxFlags.h
14 * This flag prevents content from creating new auxiliary browsing contexts,
15 * e.g. using the target attribute, or the window.open() method.
17 const SANDBOXED_AUXILIARY_NAVIGATION = 0x2;
19 export class BackgroundThumbnailsChild extends JSWindowActorChild {
20 receiveMessage(message) {
21 switch (message.name) {
22 case "Browser:Thumbnail:ContentInfo": {
24 message.data.isImage ||
25 this.contentWindow.ImageDocument.isInstance(this.document)
27 // To avoid sending additional messages between processes, we return
28 // the image data directly with the size info.
29 return lazy.PageThumbUtils.createImageThumbnailCanvas(
31 this.document.location,
32 message.data.targetWidth,
33 message.data.backgroundColor
37 let [width, height] = lazy.PageThumbUtils.getContentSize(
40 return { width, height };
43 case "Browser:Thumbnail:LoadURL": {
44 let docShell = this.docShell.QueryInterface(Ci.nsIWebNavigation);
46 // We want a low network priority for this service - lower than b/g tabs
47 // etc - so set it to the lowest priority available.
49 .QueryInterface(Ci.nsIDocumentLoader)
50 .loadGroup.QueryInterface(Ci.nsISupportsPriority).priority =
51 Ci.nsISupportsPriority.PRIORITY_LOWEST;
53 docShell.allowMedia = false;
54 docShell.allowPlugins = false;
55 docShell.allowContentRetargeting = false;
57 Ci.nsIRequest.LOAD_ANONYMOUS |
58 Ci.nsIRequest.LOAD_BYPASS_CACHE |
59 Ci.nsIRequest.INHIBIT_CACHING |
60 Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY;
61 docShell.defaultLoadFlags = defaultFlags;
62 this.browsingContext.sandboxFlags |= SANDBOXED_AUXILIARY_NAVIGATION;
63 docShell.useTrackingProtection = true;
65 // Get the document to force a content viewer to be created, otherwise
66 // the first load can fail.
71 let loadURIOptions = {
72 // Bug 1498603 verify usages of systemPrincipal here
74 Services.scriptSecurityManager.getSystemPrincipal(),
75 loadFlags: Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT,
79 Services.io.newURI(message.data.url),
94 if (event.type == "DOMDocElementInserted") {
95 // Arrange to prevent (most) popup dialogs for this window - popups done
96 // in the parent (eg, auth) aren't prevented, but alert() etc are.
97 // disableDialogs only works on the current inner window, so it has
98 // to be called every page load, but before scripts run.
99 this.contentWindow.windowUtils.disableDialogs();