morgan pushed to branch mullvad-browser-140.5.0esr-15.0-1 at The Tor Project / Applications / Mullvad Browser

Commits:

3 changed files:

Changes:

  • browser/components/mullvad-browser/AboutMullvadBrowserChild.sys.mjs
    ... ... @@ -5,13 +5,34 @@ export class AboutMullvadBrowserChild extends JSWindowActorChild {
    5 5
       handleEvent(event) {
    
    6 6
         switch (event.type) {
    
    7 7
           case "DOMContentLoaded":
    
    8
    -        this.sendQuery("AboutMullvadBrowser:GetUpdateData").then(data => {
    
    9
    -          const updateEvent = new this.contentWindow.CustomEvent("UpdateData", {
    
    10
    -            detail: Cu.cloneInto(data, this.contentWindow),
    
    11
    -          });
    
    12
    -          this.contentWindow.dispatchEvent(updateEvent);
    
    8
    +        this.sendQuery("AboutMullvadBrowser:GetUpdateData").then(response => {
    
    9
    +          if (response.delayed) {
    
    10
    +            // Wait for DelayedUpdateData.
    
    11
    +            return;
    
    12
    +          }
    
    13
    +          this.#dispatchUpdateData(response.updateData);
    
    13 14
             });
    
    14 15
             break;
    
    15 16
         }
    
    16 17
       }
    
    18
    +
    
    19
    +  receiveMessage(message) {
    
    20
    +    switch (message.name) {
    
    21
    +      case "AboutMullvadBrowser:DelayedUpdateData":
    
    22
    +        this.#dispatchUpdateData(message.data);
    
    23
    +        break;
    
    24
    +    }
    
    25
    +  }
    
    26
    +
    
    27
    +  /**
    
    28
    +   * Send the update data to the page.
    
    29
    +   *
    
    30
    +   * @param {object} data - The data to send.
    
    31
    +   */
    
    32
    +  #dispatchUpdateData(data) {
    
    33
    +    const updateEvent = new this.contentWindow.CustomEvent("UpdateData", {
    
    34
    +      detail: Cu.cloneInto(data, this.contentWindow),
    
    35
    +    });
    
    36
    +    this.contentWindow.dispatchEvent(updateEvent);
    
    37
    +  }
    
    17 38
     }

  • browser/components/mullvad-browser/AboutMullvadBrowserParent.sys.mjs
    ... ... @@ -2,30 +2,73 @@
    2 2
      * Actor parent class for the about:mullvad-browser page.
    
    3 3
      */
    
    4 4
     export class AboutMullvadBrowserParent extends JSWindowActorParent {
    
    5
    -  receiveMessage(message) {
    
    5
    +  /**
    
    6
    +   * Whether this instance has a preloaded browser.
    
    7
    +   *
    
    8
    +   * @type {boolean}
    
    9
    +   */
    
    10
    +  #preloaded = false;
    
    11
    +
    
    12
    +  /**
    
    13
    +   * Method to be called when the browser corresponding to this actor has its
    
    14
    +   * preloadedState attribute removed.
    
    15
    +   */
    
    16
    +  preloadedRemoved() {
    
    17
    +    if (!this.#preloaded) {
    
    18
    +      return;
    
    19
    +    }
    
    20
    +    this.#preloaded = false;
    
    21
    +    // Send in the initial data now that the page is actually going to be
    
    22
    +    // visible.
    
    23
    +    this.sendAsyncMessage(
    
    24
    +      "AboutMullvadBrowser:DelayedUpdateData",
    
    25
    +      this.#getUpdateData()
    
    26
    +    );
    
    27
    +  }
    
    28
    +
    
    29
    +  /**
    
    30
    +   * Get the update data for the page.
    
    31
    +   *
    
    32
    +   * @returns {object?} - The update data, or `null` if no update should be
    
    33
    +   *   shown.
    
    34
    +   */
    
    35
    +  #getUpdateData() {
    
    6 36
         const shouldNotifyPref = "mullvadbrowser.post_update.shouldNotify";
    
    37
    +    if (!Services.prefs.getBoolPref(shouldNotifyPref, false)) {
    
    38
    +      return null;
    
    39
    +    }
    
    40
    +    Services.prefs.clearUserPref(shouldNotifyPref);
    
    41
    +    // Try use the same URL as the about dialog. See mullvad-browser#411.
    
    42
    +    let updateURL = Services.urlFormatter.formatURLPref(
    
    43
    +      "app.releaseNotesURL.aboutDialog"
    
    44
    +    );
    
    45
    +    if (updateURL === "about:blank") {
    
    46
    +      updateURL = Services.urlFormatter.formatURLPref(
    
    47
    +        "startup.homepage_override_url"
    
    48
    +      );
    
    49
    +    }
    
    50
    +
    
    51
    +    return {
    
    52
    +      version: Services.prefs.getCharPref(
    
    53
    +        "browser.startup.homepage_override.mullvadbrowser.version"
    
    54
    +      ),
    
    55
    +      url: updateURL,
    
    56
    +    };
    
    57
    +  }
    
    58
    +
    
    59
    +  receiveMessage(message) {
    
    7 60
         switch (message.name) {
    
    8 61
           case "AboutMullvadBrowser:GetUpdateData": {
    
    9
    -        if (!Services.prefs.getBoolPref(shouldNotifyPref, false)) {
    
    10
    -          return Promise.resolve(null);
    
    11
    -        }
    
    12
    -        Services.prefs.clearUserPref(shouldNotifyPref);
    
    13
    -        // Try use the same URL as the about dialog. See mullvad-browser#411.
    
    14
    -        let updateURL = Services.urlFormatter.formatURLPref(
    
    15
    -          "app.releaseNotesURL.aboutDialog"
    
    16
    -        );
    
    17
    -        if (updateURL === "about:blank") {
    
    18
    -          updateURL = Services.urlFormatter.formatURLPref(
    
    19
    -            "startup.homepage_override_url"
    
    20
    -          );
    
    62
    +        const browser = this.browsingContext.top.embedderElement;
    
    63
    +        if (browser?.getAttribute("preloadedState") === "preloaded") {
    
    64
    +          // Wait until the page is actually about to be shown before sending
    
    65
    +          // the initial data.
    
    66
    +          // Otherwise the preloaded page might grab the updateData even though
    
    67
    +          // it won't be shown as the landing page. See mullvad-browser#486.
    
    68
    +          this.#preloaded = true;
    
    69
    +          return Promise.resolve({ delayed: true });
    
    21 70
             }
    
    22
    -
    
    23
    -        return Promise.resolve({
    
    24
    -          version: Services.prefs.getCharPref(
    
    25
    -            "browser.startup.homepage_override.mullvadbrowser.version"
    
    26
    -          ),
    
    27
    -          url: updateURL,
    
    28
    -        });
    
    71
    +        return Promise.resolve({ updateData: this.#getUpdateData() });
    
    29 72
           }
    
    30 73
         }
    
    31 74
         return undefined;
    

  • browser/components/tabbrowser/NewTabPagePreloading.sys.mjs
    ... ... @@ -178,6 +178,17 @@ export let NewTabPagePreloading = {
    178 178
           this.browserCounts[countKey]--;
    
    179 179
           browser.removeAttribute("preloadedState");
    
    180 180
           browser.setAttribute("autocompletepopup", "PopupAutoComplete");
    
    181
    +      // Copied from tor-browser. See mullvad-browser#486.
    
    182
    +      // Let a preloaded about:mullvad-browser page know that it is no longer
    
    183
    +      // preloaded (about to be shown).
    
    184
    +      try {
    
    185
    +        browser.browsingContext?.currentWindowGlobal
    
    186
    +          ?.getActor("AboutMullvadBrowser")
    
    187
    +          .preloadedRemoved();
    
    188
    +      } catch {
    
    189
    +        // Not an about:mullvad-browser page with an AboutMullvadBrowserParent
    
    190
    +        // instance.
    
    191
    +      }
    
    181 192
         }
    
    182 193
     
    
    183 194
         return browser;