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/. */
7 var EXPORTED_SYMBOLS = ["BackgroundThumbnailsChild"];
8 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
10 ChromeUtils.defineModuleGetter(
13 "resource://gre/modules/PageThumbUtils.jsm"
16 // NOTE: Copied from nsSandboxFlags.h
18 * This flag prevents content from creating new auxiliary browsing contexts,
19 * e.g. using the target attribute, or the window.open() method.
21 const SANDBOXED_AUXILIARY_NAVIGATION = 0x2;
23 class BackgroundThumbnailsChild extends JSWindowActorChild {
24 receiveMessage(message) {
25 switch (message.name) {
26 case "Browser:Thumbnail:ContentInfo": {
28 message.data.isImage ||
29 this.document instanceof this.contentWindow.ImageDocument
31 // To avoid sending additional messages between processes, we return
32 // the image data directly with the size info.
33 return PageThumbUtils.createImageThumbnailCanvas(
35 this.document.location,
36 message.data.targetWidth,
37 message.data.backgroundColor
41 let [width, height] = PageThumbUtils.getContentSize(this.contentWindow);
42 return { width, height };
45 case "Browser:Thumbnail:LoadURL": {
46 let docShell = this.docShell.QueryInterface(Ci.nsIWebNavigation);
48 // We want a low network priority for this service - lower than b/g tabs
49 // etc - so set it to the lowest priority available.
51 .QueryInterface(Ci.nsIDocumentLoader)
52 .loadGroup.QueryInterface(Ci.nsISupportsPriority).priority =
53 Ci.nsISupportsPriority.PRIORITY_LOWEST;
55 docShell.allowMedia = false;
56 docShell.allowPlugins = false;
57 docShell.allowContentRetargeting = false;
59 Ci.nsIRequest.LOAD_ANONYMOUS |
60 Ci.nsIRequest.LOAD_BYPASS_CACHE |
61 Ci.nsIRequest.INHIBIT_CACHING |
62 Ci.nsIWebNavigation.LOAD_FLAGS_BYPASS_HISTORY;
63 docShell.defaultLoadFlags = defaultFlags;
64 this.browsingContext.sandboxFlags |= SANDBOXED_AUXILIARY_NAVIGATION;
65 docShell.useTrackingProtection = true;
67 // Get the document to force a content viewer to be created, otherwise
68 // the first load can fail.
73 let loadURIOptions = {
74 // Bug 1498603 verify usages of systemPrincipal here
75 triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
76 loadFlags: Ci.nsIWebNavigation.LOAD_FLAGS_STOP_CONTENT,
79 docShell.loadURI(message.data.url, loadURIOptions);
92 if (event.type == "DOMDocElementInserted") {
93 // Arrange to prevent (most) popup dialogs for this window - popups done
94 // in the parent (eg, auth) aren't prevented, but alert() etc are.
95 // disableDialogs only works on the current inner window, so it has
96 // to be called every page load, but before scripts run.
97 this.contentWindow.windowUtils.disableDialogs();