Commit 17884fe1 authored by Thomas Wisniewski's avatar Thomas Wisniewski
Browse files

Bug 1705452 - correctly pass in the set of hosts for which the user has opted...

Bug 1705452 - correctly pass in the set of hosts for which the user has opted in to bypassing shims, so that we may call allow or replace on channels appropriately; r=pbz,webcompat-reviewers,denschub

Differential Revision: https://phabricator.services.mozilla.com/D112215
parent 79169306
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -43,17 +43,17 @@ class Manager {
          }
          for (const allowList of this._allowLists.values()) {
            for (const entry of allowList.values()) {
              const { matcher, hosts, notHosts, willBeShimming } = entry;
              const { matcher, hosts, notHosts, hostOptIns } = entry;
              if (matcher.matches(url)) {
                if (
                  !notHosts?.has(topHost) &&
                  (hosts === true || hosts.has(topHost))
                ) {
                  this._unblockedChannelIds.add(channelId);
                  if (willBeShimming) {
                    channel.replace();
                  if (hostOptIns.has(topHost)) {
                    channel.allow(); // we just allow the request
                  } else {
                    channel.allow();
                    channel.replace(); // we will be shimming
                  }
                  return;
                }
@@ -86,7 +86,7 @@ class Manager {
    return this._unblockedChannelIds?.has(channelId);
  }

  allow(allowListId, patterns, { hosts, notHosts, willBeShimming }) {
  allow(allowListId, patterns, { hosts, notHosts, hostOptIns = [] }) {
    this._ensureStarted();

    if (!this._allowLists.has(allowListId)) {
@@ -97,10 +97,13 @@ class Manager {
      if (!allowList.has(pattern)) {
        allowList.set(pattern, {
          matcher: new MatchPattern(pattern),
          hostOptIns: new Set(),
        });
      }
      const allowListPattern = allowList.get(pattern);
      allowListPattern.willBeShimming = willBeShimming;
      for (const host of hostOptIns) {
        allowListPattern.hostOptIns.add(host);
      }
      if (!hosts) {
        allowListPattern.hosts = true;
      } else if (allowListPattern.hosts !== true) {
+7 −3
Original line number Diff line number Diff line
@@ -41,10 +41,14 @@
                },
                "optional": true
              },
              "willBeShimming": {
                "description": "Whether requests are allowed for shimming",
              "hostOptIns": {
                "description": "Hosts where a shim should not be used, but the requests should be allowed after user opt-in.",
                "type": "boolean",
                "optional": false
                "type": "array",
                "items": {
                  "type": "string"
                },
                "optional": true
              }
            }
          }
+4 −5
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ class Shim {
    this.needsShimHelpers = opts.needsShimHelpers;
    this.platform = opts.platform || "all";
    this.unblocksOnOptIn = unblocksOnOptIn;
    this.userHasOptedIn = false;

    this._hostOptIns = new Set();

@@ -146,7 +145,7 @@ class Shim {
    return browser.trackingProtection.allow(this.id, this.matches, {
      hosts: this.hosts,
      notHosts: this.notHosts,
      willBeShimming: !this.userHasOptedIn,
      hostOptIns: Array.from(this._hostOptIns),
    });
  }

@@ -185,8 +184,8 @@ class Shim {
      this.userHasOptedIn = true;
      const toUnblock = matches.concat(unblocksOnOptIn);
      await browser.trackingProtection.allow(this.id, toUnblock, {
        hosts: [host],
        willBeShimming: false,
        hosts: this.hosts,
        hostOptIns: [host],
      });
    }

@@ -241,7 +240,7 @@ class Shims {
      return;
    }

    const urls = [...allShimPatterns];
    const urls = Array.from(allShimPatterns);
    debug("Shimming these match patterns", urls);

    browser.webRequest.onBeforeRequest.addListener(
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
  "manifest_version": 2,
  "name": "Web Compatibility Interventions",
  "description": "Urgent post-release fixes for web compatibility.",
  "version": "21.4.0",
  "version": "21.5.0",

  "applications": {
    "gecko": {