Bug 1820641: Make a test that calls window.restore handle zoomed windows. r=mstange
[gecko.git] / toolkit / actors / ThumbnailsChild.jsm
blob2db728c734d38b016e836c628c4aec92a2b89643
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/. */
5 "use strict";
7 var EXPORTED_SYMBOLS = ["ThumbnailsChild"];
9 const lazy = {};
11 ChromeUtils.defineModuleGetter(
12   lazy,
13   "PageThumbUtils",
14   "resource://gre/modules/PageThumbUtils.jsm"
17 class ThumbnailsChild extends JSWindowActorChild {
18   receiveMessage(message) {
19     switch (message.name) {
20       case "Browser:Thumbnail:ContentInfo": {
21         let [width, height] = lazy.PageThumbUtils.getContentSize(
22           this.contentWindow
23         );
24         return { width, height };
25       }
26       case "Browser:Thumbnail:CheckState": {
27         /**
28          * Remote isSafeForCapture request handler for PageThumbs.
29          */
30         return new Promise(resolve =>
31           Services.tm.idleDispatchToMainThread(() => {
32             if (!this.manager) {
33               // If we have no manager, our actor has been destroyed, which
34               // means we can't respond, and trying to touch
35               // `this.contentWindow` or `this.browsingContext` will throw.
36               // The `sendQuery` call in the parent will already have been
37               // rejected when the actor was destroyed, so there's no need to
38               // reject our promise or log an additional error.
39               return;
40             }
42             let result = lazy.PageThumbUtils.shouldStoreContentThumbnail(
43               this.contentWindow,
44               this.browsingContext.docShell
45             );
46             resolve(result);
47           })
48         );
49       }
50       case "Browser:Thumbnail:GetOriginalURL": {
51         /**
52          * Remote GetOriginalURL request handler for PageThumbs.
53          */
54         let channel = this.browsingContext.docShell.currentDocumentChannel;
55         let channelError = lazy.PageThumbUtils.isChannelErrorResponse(channel);
56         let originalURL;
57         try {
58           originalURL = channel.originalURI.spec;
59         } catch (ex) {}
60         return { channelError, originalURL };
61       }
62     }
63     return undefined;
64   }