Skip to content

Commit acefe30

Browse files
committed
Bug 1717672 - Fix webcompat uuid r=denschub,rpl,webcompat-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D253565
1 parent d9f1b31 commit acefe30

File tree

5 files changed

+69
-1
lines changed

5 files changed

+69
-1
lines changed

browser/extensions/webcompat/moz.build

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ XPCOM_MANIFESTS += [
1212
"components.conf",
1313
]
1414

15-
BROWSER_CHROME_MANIFESTS += ["tests/browser/browser.toml"]
15+
BROWSER_CHROME_MANIFESTS += [
16+
"tests/browser/browser.toml",
17+
"tests/browser/browser_uuid_migration.toml",
18+
]
1619

1720
with Files("**"):
1821
BUG_COMPONENT = ("Web Compatibility", "Tooling & Investigations")

browser/extensions/webcompat/tests/browser/browser_aboutcompat.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ add_task(async function test_about_compat_loads_properly() {
88
});
99

1010
await SpecialPowers.spawn(tab.linkedBrowser, [], async function () {
11+
is(
12+
content.origin,
13+
"moz-extension://9a310967-e580-48bf-b3e8-4eafebbc122d",
14+
"Expected origin of about:compat"
15+
);
16+
1117
await ContentTaskUtils.waitForCondition(
1218
() => content.document.querySelector("#interventions tr[data-id]"),
1319
"interventions are listed"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"use strict";
2+
3+
// Sanity check: The setup in the toml file is effective at fixing the uuid
4+
// for at least one extension.
5+
add_task(async function test_sanity_check_uuid_fixed_by_pref() {
6+
is(
7+
WebExtensionPolicy.getByID("pictureinpicture@mozilla.org")
8+
.mozExtensionHostname,
9+
"f00df00d-2222-f00d-8888-012345678900",
10+
"Non-webcompat uuid is fixed by pref in browser_uuid_migration.toml"
11+
);
12+
});
13+
14+
add_task(async function test_webcompat_migrates_existing_uuid_pref() {
15+
const expectedWebCompatUUID = "9a310967-e580-48bf-b3e8-4eafebbc122d";
16+
Assert.notEqual(
17+
expectedWebCompatUUID,
18+
"f00df00d-1111-f00d-8888-012345678900",
19+
"Sanity check: Expected UUID differs from browser_uuid_migration.toml"
20+
);
21+
22+
is(
23+
WebExtensionPolicy.getByID("webcompat@mozilla.org").mozExtensionHostname,
24+
expectedWebCompatUUID,
25+
"webcompat add-on has fixed UUID"
26+
);
27+
28+
let uuids = Services.prefs.getStringPref("extensions.webextensions.uuids");
29+
ok(
30+
uuids.includes(`"webcompat@mozilla.org":"${expectedWebCompatUUID}"`),
31+
`Pref value (${uuids}) should contain: ${expectedWebCompatUUID}`
32+
);
33+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[DEFAULT]
2+
tags = "webextensions"
3+
# Must be set in [DEFAULT] to ensure that the pref is set before the browser starts.
4+
# We choose two built-in extensions here: webcompat and another built-in extension.
5+
prefs = ['extensions.webextensions.uuids={"webcompat@mozilla.org":"f00df00d-1111-f00d-8888-012345678900","pictureinpicture@mozilla.org":"f00df00d-2222-f00d-8888-012345678900"}']
6+
7+
["browser_uuid_migration.js"]

toolkit/components/extensions/Extension.sys.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ const LOGGER_ID_BASE = "addons.webextension.";
391391
const UUID_MAP_PREF = "extensions.webextensions.uuids";
392392
const LEAVE_STORAGE_PREF = "extensions.webextensions.keepStorageOnUninstall";
393393
const LEAVE_UUID_PREF = "extensions.webextensions.keepUuidOnUninstall";
394+
const WEBCOMPAT_ADDON_ID = "webcompat@mozilla.org";
395+
const WEBCOMPAT_UUID = "9a310967-e580-48bf-b3e8-4eafebbc122d";
394396

395397
// All moz-extension URIs use a machine-specific UUID rather than the
396398
// extension's own ID in the host component. This makes it more
@@ -416,6 +418,23 @@ var UUIDMap = {
416418
get(id, create = true) {
417419
let map = this._read();
418420

421+
// In general, the UUID should not change once assigned because it may be
422+
// stored elsewhere within the profile directory, when the extension URL is
423+
// exposed (e.g. history, bookmarks, site permissions, web or extension
424+
// APIs that associate data with the extension principal or origin).
425+
// The webcompat add-on does not rely on the persisted uuid, so we can
426+
// simply migrate the uuid below, see bug 1717672.
427+
if (id === WEBCOMPAT_ADDON_ID) {
428+
if (!create && !(id in map)) {
429+
return null;
430+
}
431+
if (map[id] !== WEBCOMPAT_UUID) {
432+
map[id] = WEBCOMPAT_UUID;
433+
this._write(map);
434+
}
435+
return WEBCOMPAT_UUID;
436+
}
437+
419438
if (id in map) {
420439
return map[id];
421440
}

0 commit comments

Comments
 (0)