Bug 1888590 - Mark some subtests on trusted-types-event-handlers.html as failing...
[gecko.git] / toolkit / actors / ThumbnailsChild.sys.mjs
blob9ab6fc3b08fdf4e11f5b403e8da5dcd2dfe58fed
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/. */
6 const lazy = {};
8 ChromeUtils.defineESModuleGetters(lazy, {
9   PageThumbUtils: "resource://gre/modules/PageThumbUtils.sys.mjs",
10 });
12 export class ThumbnailsChild extends JSWindowActorChild {
13   receiveMessage(message) {
14     switch (message.name) {
15       case "Browser:Thumbnail:ContentInfo": {
16         let [width, height] = lazy.PageThumbUtils.getContentSize(
17           this.contentWindow
18         );
19         return { width, height };
20       }
21       case "Browser:Thumbnail:CheckState": {
22         /**
23          * Remote isSafeForCapture request handler for PageThumbs.
24          */
25         return new Promise(resolve =>
26           Services.tm.idleDispatchToMainThread(() => {
27             if (!this.manager) {
28               // If we have no manager, our actor has been destroyed, which
29               // means we can't respond, and trying to touch
30               // `this.contentWindow` or `this.browsingContext` will throw.
31               // The `sendQuery` call in the parent will already have been
32               // rejected when the actor was destroyed, so there's no need to
33               // reject our promise or log an additional error.
34               return;
35             }
37             let result = lazy.PageThumbUtils.shouldStoreContentThumbnail(
38               this.contentWindow,
39               this.browsingContext.docShell
40             );
41             resolve(result);
42           })
43         );
44       }
45       case "Browser:Thumbnail:GetOriginalURL": {
46         /**
47          * Remote GetOriginalURL request handler for PageThumbs.
48          */
49         let channel = this.browsingContext.docShell.currentDocumentChannel;
50         let channelError = lazy.PageThumbUtils.isChannelErrorResponse(channel);
51         let originalURL;
52         try {
53           originalURL = channel.originalURI.spec;
54         } catch (ex) {}
55         return { channelError, originalURL };
56       }
57     }
58     return undefined;
59   }