tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

PageInfoPreviewChild.sys.mjs (942B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 export class PageInfoPreviewChild extends JSWindowActorChild {
      6  async receiveMessage(message) {
      7    if (message.name === "PageInfoPreview:resize") {
      8      return this.resize(this.contentWindow.document, message.data);
      9    }
     10 
     11    return undefined;
     12  }
     13 
     14  resize(document, data) {
     15    let img = document.querySelector("img");
     16    if (!img) {
     17      return undefined;
     18    }
     19 
     20    const naturalWidth = img.naturalWidth || 0;
     21    const naturalHeight = img.naturalHeight || 0;
     22 
     23    if (data.width !== undefined) {
     24      img.width = data.width;
     25    }
     26    if (data.height !== undefined) {
     27      img.height = data.height;
     28    }
     29 
     30    return {
     31      naturalWidth,
     32      naturalHeight,
     33      width: img.width,
     34      height: img.height,
     35    };
     36  }
     37 }