Commit Graph

550 Commits

Author SHA1 Message Date
Harveer Singh
479b5b0f5a Bug 1958090: Make PermissionManager thread-safe.r=edenchuang,permissions-reviewers,timhuang
This class is used by both parent and child processes. It's more heavily used on the parent vs the child side.
With this change, even though the PermissionManager class should itself be now thread-safe, I have still
kept assertions on most of it's public methods for main thread in place because I wanted to keep the regression
risk minimal with this change while still satisfying my criteria about allowing some operations like adding new
and reading existing permissions thread-safe such that they can be performed off-main thread.

There might be some permission manager callers here which previously needed to switch to main thread in order to
invoke operations; they would no longer need to do that. After gaining some confidence with this limited exposure
maybe we can slowly start looking into the callers and see if they can benefit from this thread-safety now i.e.
if they do not need to switch to main thread just for the sake of PermissionManager usage.

Since, this is a singleton class; ofcourse, the creation, initialization, etc. are still main thread only. Also,
any DB operation can also only be performed on the corresponding thread only.

Differential Revision: https://phabricator.services.mozilla.com/D244608
2025-04-16 16:45:49 +00:00
Joel Maher
98ece24bd5 Bug 1959821 - cleanup and standardize remaining xpcshell.toml files. r=aryx,sync-reviewers,markh
Differential Revision: https://phabricator.services.mozilla.com/D245147
2025-04-15 20:24:35 +00:00
Malte Jürgens
020db4941e Bug 1839479 - Clear pb permissions on last-pb-context-exited r=emz,permissions-reviewers
- Pass through principal as lambda argument in internal RemovePermissionEntries
  permission manager function
- Add new permission manager internal function RemoveAllForPrivateBrowsing,
  which removes all permission manager entries with a private browsing principal
- Call RemoveAllForPrivateBrowsing on `last-pb-context-exited` event

Differential Revision: https://phabricator.services.mozilla.com/D244787
2025-04-14 12:22:34 +00:00
Florian Quèze
1cb736cf28 Bug 1956726 - Migrate histograms to use Glean APIs in extensions/permissions/, r=chutten,permissions-reviewers,emz.
Differential Revision: https://phabricator.services.mozilla.com/D244169
2025-04-03 17:30:10 +00:00
Magnus Melin
27f621588e Bug 1948550 - test_permmanager_remote.js needs to account for shipped remote settings. r=maltejur
If Thunderbird ships permissions, this test fails since the test doesn't account for that.
Firefox runs the test without Firefox profile settings (meaning no remote settings available) so
it's not a problem there.

Differential Revision: https://phabricator.services.mozilla.com/D239492
2025-02-25 19:53:28 +00:00
Malte Jürgens
a4269b7fe1 Bug 1942810 - Initialize remote permission service directly on "profile-after-change" r=asuth,permissions-reviewers,emz
With the previous implementation, the permission manager may miss the
"profile-after-change" event and won't start the remote permission service.

Differential Revision: https://phabricator.services.mozilla.com/D235169
2025-02-05 11:41:26 +00:00
Valentin Gosu
0461ae216d Bug 1943262 - Refactor instantiation of nsEffectiveTLDService r=cookie-reviewers,anti-tracking-reviewers,permissions-reviewers,emz
This ensures that the instantiation of the service always returns the
same singleton. I also changed calls to nsEffectiveTLDService::GetInstance
to use mozilla::components::EffectiveTLD::Service() instead.

Differential Revision: https://phabricator.services.mozilla.com/D235288
2025-01-28 10:56:50 +00:00
Malte Jürgens
421f16f86b Bug 1925553 - Document Permission Manager and Remote Permissions in Source Docs r=emz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D234167
2025-01-27 16:16:28 +00:00
Jens Stutte
706548fa4f Bug 1745056 - Make PermissionManager lifecycle truely thread safe. r=asuth,cookie-reviewers,anti-tracking-reviewers,permissions-reviewers,valentin,timhuang
This patch makes PermissionManager::GetInstance do the instantiation
work and GetXPCOMSingleton just uses it.
We always acquire the creation mutex and return an already_AddRefed to
avoid any possible race. We count on callers of GetInstance to
(shortly) keep a local reference if they have more work to do.
On async shutdown in the parent process, we first mark our singleton
dead, then close all our resources async and finally null our instance
holder only after the async shutdown has finished.

Differential Revision: https://phabricator.services.mozilla.com/D233816
2025-01-15 17:00:25 +00:00
Malte Jürgens
8fdb805c76 Bug 1935637 - Force-enable remote permission service in test_permmanager_remote.js r=permissions-reviewers,pbz
Otherwise this test will fail in beta and release, as the remote permission
service is still preffed off there.

Differential Revision: https://phabricator.services.mozilla.com/D231424
2024-12-09 13:30:20 +00:00
Magnus Melin
06fbc00787 Bug 1935448 - Follow-up to bug 1919558: make test_permmanager_remote.js defaults be explicitely empty. r=maltejur
Differential Revision: https://phabricator.services.mozilla.com/D231491
2024-12-09 10:42:53 +00:00
Malte Jürgens
57572799b4 Bug 1816449 - Part 8: Allow HTTPS-First exceptions to be set through the RemotePermissionService r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D222648
2024-12-04 16:45:04 +00:00
Malte Jürgens
6960344d03 Bug 1919558 - Part 7: Add test for remote permission service r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D225049
2024-12-04 16:45:03 +00:00
Malte Jürgens
c56f4c91eb Bug 1919558 - Part 6: Add RemotePermissionService to get default permissions from remote settings r=pbz,permissions-reviewers
This is adding the RemotePermissionService xpcom js service for the purpose of
importing default permission manager entries from remote settings. This service
will be initialized by the permission manager after it has read all its
permissions from disk and is fully initialized.

When being initialized, the service will at first get all the current default
remote permissions from the remote settings client, and add them as default
permissions through the `AddDefaultFromPrincipal` method added in D222650. An
event listener is then also set up to keep the default entries in the permission
manager in sync with remote settings.

All of this is guarded behind a whitelist in the the `ALLOWED_PERMISSION_VALUES`
variable, ensuring only specific permission types and values can be imported
through this mechanism.

Differential Revision: https://phabricator.services.mozilla.com/D222649
2024-12-04 16:45:03 +00:00
Malte Jürgens
5a1f76d299 Bug 1919558 - Part 5: Add AddDefaultFromPrincipal method to permission manager r=pbz,permissions-reviewers
This method will later be used to import default permissions from remote
settings through the remote permission manager.

Differential Revision: https://phabricator.services.mozilla.com/D222650
2024-12-04 16:45:02 +00:00
Malte Jürgens
424364d46f Bug 1919558 - Part 4: Allow default permissions to be modified through AddInternal in permission manager r=pbz,permissions-reviewers
Allow default permissions to be deleted by adding a new permission with same
origin and type, and value UNKNOWN_ACTION, analogous to how normal permissions
currently already get deleted. This can then later be used by the remote
permission service (D222649) to remove default permissions it previously added
if they have been removed in remote settings.

Also add brackets to make clang-tidy happy.

Differential Revision: https://phabricator.services.mozilla.com/D222651
2024-12-04 16:45:02 +00:00
Malte Jürgens
bfc438acee Bug 1919558 - Part 3: Move logic to restore default permission entries into AddInternal in permission manager r=pbz,permissions-reviewers
This makes sure default permissions are always restored when a previously
overriding user permission gets deleted with AddInternal.

Differential Revision: https://phabricator.services.mozilla.com/D222652
2024-12-04 16:45:02 +00:00
Malte Jürgens
4e48d62856 Bug 1919558 - Part 2: Separate out logic for importing DefaultEntry into own method in permission manager r=pbz,permissions-reviewers
This will allow us to call the same logic for a single default entry.

Differential Revision: https://phabricator.services.mozilla.com/D222653
2024-12-04 16:45:01 +00:00
Malte Jürgens
baf5dbd3e7 Bug 1919558 - Part 1: Convert host to origin before storing it as a DefaultEntry in the permission manager r=pbz,permissions-reviewers
This just simplifies the code for later use and should not change any behaviour
beside the following:

If `permissions.manager.defaultsUrl` is customized and contains a legacy `host`
entry, removes the history lookup to determine known origins for a given host.
Instead, only entries for http:// and https:// on the default ports will be
added. This is because with the changes in this patch,
`UpgradeHostToOriginAndInsert` is moved off the main thread, and a history
lookup is only allowed on the main thread.

Also rename `mDefaultEntries` to `mDefaultEntriesForImport` to better reflect
what this array is actually for: Storing the defaults so that they can be
(re-)imported into the permission manager, and not being the primary location
where the default permissions are stored.

Differential Revision: https://phabricator.services.mozilla.com/D222654
2024-12-04 16:45:01 +00:00
Sandor Molnar
264568af9c Backed out 8 changesets (bug 1919558, bug 1816449) for causing mochitest failures @ test_refresh_firefox.py
Backed out changeset a194f41588e9 (bug 1816449)
Backed out changeset 10643d7c7a78 (bug 1919558)
Backed out changeset b346a2a2bfdc (bug 1919558)
Backed out changeset 507f18e7103d (bug 1919558)
Backed out changeset 4d0d9f72bc2a (bug 1919558)
Backed out changeset 65d9270f0991 (bug 1919558)
Backed out changeset fe95b9e6ff13 (bug 1919558)
Backed out changeset ea6ffcb0e334 (bug 1919558)
2024-11-13 18:22:41 +02:00
Malte Jürgens
b65afe7801 Bug 1816449 - Part 8: Allow HTTPS-First exceptions to be set through the RemotePermissionService r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D222648
2024-11-13 14:00:10 +00:00
Malte Jürgens
498e61caf7 Bug 1919558 - Part 7: Add test for remote permission service r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D225049
2024-11-13 14:00:09 +00:00
Malte Jürgens
005d8506f2 Bug 1919558 - Part 6: Add RemotePermissionService to get default permissions from remote settings r=pbz,permissions-reviewers
This is adding the RemotePermissionService xpcom js service for the purpose of
importing default permission manager entries from remote settings. This service
will be initialized by the permission manager after it has read all its
permissions from disk and is fully initialized.

When being initialized, the service will at first get all the current default
remote permissions from the remote settings client, and add them as default
permissions through the `AddDefaultFromPrincipal` method added in D222650. An
event listener is then also set up to keep the default entries in the permission
manager in sync with remote settings.

All of this is guarded behind a whitelist in the the `ALLOWED_PERMISSION_VALUES`
variable, ensuring only specific permission types and values can be imported
through this mechanism.

Differential Revision: https://phabricator.services.mozilla.com/D222649
2024-11-13 14:00:09 +00:00
Malte Jürgens
8fbc2bae7f Bug 1919558 - Part 5: Add AddDefaultFromPrincipal method to permission manager r=pbz,permissions-reviewers
This method will later be used to import default permissions from remote
settings through the remote permission manager.

Differential Revision: https://phabricator.services.mozilla.com/D222650
2024-11-13 14:00:09 +00:00
Malte Jürgens
25a74565ea Bug 1919558 - Part 4: Allow default permissions to be modified through AddInternal in permission manager r=pbz,permissions-reviewers
Allow default permissions to be deleted by adding a new permission with same
origin and type, and value UNKNOWN_ACTION, analogous to how normal permissions
currently already get deleted. This can then later be used by the remote
permission service (D222649) to remove default permissions it previously added
if they have been removed in remote settings.

Also add brackets to make clang-tidy happy.

Differential Revision: https://phabricator.services.mozilla.com/D222651
2024-11-13 14:00:08 +00:00
Malte Jürgens
dc4986f63e Bug 1919558 - Part 3: Move logic to restore default permission entries into AddInternal in permission manager r=pbz,permissions-reviewers
This makes sure default permissions are always restored when a previously
overriding user permission gets deleted with AddInternal.

Differential Revision: https://phabricator.services.mozilla.com/D222652
2024-11-13 14:00:08 +00:00
Malte Jürgens
d6e5c2692c Bug 1919558 - Part 2: Separate out logic for importing DefaultEntry into own method in permission manager r=pbz,permissions-reviewers
This will allow us to call the same logic for a single default entry.

Differential Revision: https://phabricator.services.mozilla.com/D222653
2024-11-13 14:00:07 +00:00
Malte Jürgens
2653d68ae7 Bug 1919558 - Part 1: Convert host to origin before storing it as a DefaultEntry in the permission manager r=pbz,permissions-reviewers
This just simplifies the code for later use and should not change any behaviour
beside the following:

If `permissions.manager.defaultsUrl` is customized and contains a legacy `host`
entry, removes the history lookup to determine known origins for a given host.
Instead, only entries for http:// and https:// on the default ports will be
added. This is because with the changes in this patch,
`UpgradeHostToOriginAndInsert` is moved off the main thread, and a history
lookup is only allowed on the main thread.

Also rename `mDefaultEntries` to `mDefaultEntriesForImport` to better reflect
what this array is actually for: Storing the defaults so that they can be
(re-)imported into the permission manager, and not being the primary location
where the default permissions are stored.

Differential Revision: https://phabricator.services.mozilla.com/D222654
2024-11-13 14:00:07 +00:00
Butkovits Atila
c4367fe4d4 Backed out 8 changesets (bug 1919558, bug 1816449) for causing failures at test_open_and_databases.js
Backed out changeset 5f7eab80a48b (bug 1816449)
Backed out changeset 2800d22d0532 (bug 1919558)
Backed out changeset c95f84d96d07 (bug 1919558)
Backed out changeset b61736ed0836 (bug 1919558)
Backed out changeset bc6e1e325e17 (bug 1919558)
Backed out changeset 22967ce2bce2 (bug 1919558)
Backed out changeset cd0a6dffb4e2 (bug 1919558)
Backed out changeset cb5b83cd5d65 (bug 1919558)
2024-11-08 21:20:45 +02:00
Malte Jürgens
1ced0ba54e Bug 1816449 - Part 8: Allow HTTPS-First exceptions to be set through the RemotePermissionService r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D222648
2024-11-08 15:08:33 +00:00
Malte Jürgens
9c78b26d3c Bug 1919558 - Part 7: Add test for remote permission service r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D225049
2024-11-08 15:08:33 +00:00
Malte Jürgens
ab5870e961 Bug 1919558 - Part 6: Add RemotePermissionService to get default permissions from remote settings r=pbz,permissions-reviewers
This is adding the RemotePermissionService xpcom js service for the purpose of
importing default permission manager entries from remote settings. This service
will be initialized by the permission manager after it has read all its
permissions from disk and is fully initialized.

When being initialized, the service will at first get all the current default
remote permissions from the remote settings client, and add them as default
permissions through the `AddDefaultFromPrincipal` method added in D222650. An
event listener is then also set up to keep the default entries in the permission
manager in sync with remote settings.

All of this is guarded behind a whitelist in the the `ALLOWED_PERMISSION_VALUES`
variable, ensuring only specific permission types and values can be imported
through this mechanism.

Differential Revision: https://phabricator.services.mozilla.com/D222649
2024-11-08 15:08:33 +00:00
Malte Jürgens
4d4e67d61f Bug 1919558 - Part 5: Add AddDefaultFromPrincipal method to permission manager r=pbz,permissions-reviewers
This method will later be used to import default permissions from remote
settings through the remote permission manager.

Differential Revision: https://phabricator.services.mozilla.com/D222650
2024-11-08 15:08:32 +00:00
Malte Jürgens
cef2e4d5b6 Bug 1919558 - Part 4: Allow default permissions to be modified through AddInternal in permission manager r=pbz,permissions-reviewers
Allow default permissions to be deleted by adding a new permission with same
origin and type, and value UNKNOWN_ACTION, analogous to how normal permissions
currently already get deleted. This can then later be used by the remote
permission service (D222649) to remove default permissions it previously added
if they have been removed in remote settings.

Also add brackets to make clang-tidy happy.

Differential Revision: https://phabricator.services.mozilla.com/D222651
2024-11-08 15:08:32 +00:00
Malte Jürgens
03bbd34260 Bug 1919558 - Part 3: Move logic to restore default permission entries into AddInternal in permission manager r=pbz,permissions-reviewers
This makes sure default permissions are always restored when a previously
overriding user permission gets deleted with AddInternal.

Differential Revision: https://phabricator.services.mozilla.com/D222652
2024-11-08 15:08:31 +00:00
Malte Jürgens
67afaa14ca Bug 1919558 - Part 2: Separate out logic for importing DefaultEntry into own method in permission manager r=pbz,permissions-reviewers
This will allow us to call the same logic for a single default entry.

Differential Revision: https://phabricator.services.mozilla.com/D222653
2024-11-08 15:08:31 +00:00
Malte Jürgens
c98108dc2c Bug 1919558 - Part 1: Convert host to origin before storing it as a DefaultEntry in the permission manager r=pbz,permissions-reviewers
This just simplifies the code for later use and should not change any behaviour
beside the following:

If `permissions.manager.defaultsUrl` is customized and contains a legacy `host`
entry, removes the history lookup to determine known origins for a given host.
Instead, only entries for http:// and https:// on the default ports will be
added. This is because with the changes in this patch,
`UpgradeHostToOriginAndInsert` is moved off the main thread, and a history
lookup is only allowed on the main thread.

Also rename `mDefaultEntries` to `mDefaultEntriesForImport` to better reflect
what this array is actually for: Storing the defaults so that they can be
(re-)imported into the permission manager, and not being the primary location
where the default permissions are stored.

Differential Revision: https://phabricator.services.mozilla.com/D222654
2024-11-08 15:08:31 +00:00
Norisz Fay
b6201c0222 Backed out 8 changesets (bug 1816449, bug 1919558) for causing xpcshell and mochitest failures
Backed out changeset 69d226857a48 (bug 1816449)
Backed out changeset da7afd485891 (bug 1919558)
Backed out changeset 1bedb67e8801 (bug 1919558)
Backed out changeset 361ef2b4da96 (bug 1919558)
Backed out changeset ae8f8083b580 (bug 1919558)
Backed out changeset 8930087e61a2 (bug 1919558)
Backed out changeset da39116b6d9e (bug 1919558)
Backed out changeset a200e5113a25 (bug 1919558)
2024-11-05 13:44:46 +02:00
Malte Jürgens
c00d6eb48a Bug 1816449 - Part 8: Allow HTTPS-First exceptions to be set through the RemotePermissionService r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D222648
2024-11-05 10:17:44 +00:00
Malte Jürgens
8e1b4a655f Bug 1919558 - Part 7: Add test for remote permission service r=pbz,permissions-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D225049
2024-11-05 10:17:43 +00:00
Malte Jürgens
e90cd4ab92 Bug 1919558 - Part 6: Add RemotePermissionService to get default permissions from remote settings r=pbz,permissions-reviewers
This is adding the RemotePermissionService xpcom js service for the purpose of
importing default permission manager entries from remote settings. This service
will be initialized by the permission manager after it has read all its
permissions from disk and is fully initialized.

When being initialized, the service will at first get all the current default
remote permissions from the remote settings client, and add them as default
permissions through the `AddDefaultFromPrincipal` method added in D222650. An
event listener is then also set up to keep the default entries in the permission
manager in sync with remote settings.

All of this is guarded behind a whitelist in the the `ALLOWED_PERMISSION_VALUES`
variable, ensuring only specific permission types and values can be imported
through this mechanism.

Differential Revision: https://phabricator.services.mozilla.com/D222649
2024-11-05 10:17:43 +00:00
Malte Jürgens
83f02b25dd Bug 1919558 - Part 5: Add AddDefaultFromPrincipal method to permission manager r=pbz,permissions-reviewers
This method will later be used to import default permissions from remote
settings through the remote permission manager.

Differential Revision: https://phabricator.services.mozilla.com/D222650
2024-11-05 10:17:42 +00:00
Malte Jürgens
a9f138549d Bug 1919558 - Part 4: Allow default permissions to be modified through AddInternal in permission manager r=pbz,permissions-reviewers
Allow default permissions to be deleted by adding a new permission with same
origin and type, and value UNKNOWN_ACTION, analogous to how normal permissions
currently already get deleted. This can then later be used by the remote
permission service (D222649) to remove default permissions it previously added
if they have been removed in remote settings.

Also add brackets to make clang-tidy happy.

Differential Revision: https://phabricator.services.mozilla.com/D222651
2024-11-05 10:17:42 +00:00
Malte Jürgens
3e04951bf6 Bug 1919558 - Part 3: Move logic to restore default permission entries into AddInternal in permission manager r=pbz,permissions-reviewers
This makes sure default permissions are always restored when a previously
overriding user permission gets deleted with AddInternal.

Differential Revision: https://phabricator.services.mozilla.com/D222652
2024-11-05 10:17:41 +00:00
Malte Jürgens
8f9d85d3b4 Bug 1919558 - Part 2: Separate out logic for importing DefaultEntry into own method in permission manager r=pbz,permissions-reviewers
This will allow us to call the same logic for a single default entry.

Differential Revision: https://phabricator.services.mozilla.com/D222653
2024-11-05 10:17:41 +00:00
Malte Jürgens
b06d16f4c3 Bug 1919558 - Part 1: Convert host to origin before storing it as a DefaultEntry in the permission manager r=pbz,permissions-reviewers
This just simplifies the code for later use and should not change any behaviour
beside the following:

If `permissions.manager.defaultsUrl` is customized and contains a legacy `host`
entry, removes the history lookup to determine known origins for a given host.
Instead, only entries for http:// and https:// on the default ports will be
added. This is because with the changes in this patch,
`UpgradeHostToOriginAndInsert` is moved off the main thread, and a history
lookup is only allowed on the main thread.

Also rename `mDefaultEntries` to `mDefaultEntriesForImport` to better reflect
what this array is actually for: Storing the defaults so that they can be
(re-)imported into the permission manager, and not being the primary location
where the default permissions are stored.

Differential Revision: https://phabricator.services.mozilla.com/D222654
2024-11-05 10:17:41 +00:00
Joel Maher
fd82f48683 Bug 1922146 - Adjust xpcshell skip-if conditions for mac to include os_version/processor. r=aryx,necko-reviewers,anti-tracking-reviewers,kershaw,bvandersloot
Differential Revision: https://phabricator.services.mozilla.com/D224269
2024-10-04 12:18:36 +00:00
William Wen
b67b674246 Bug 1904095 - Add tests for new permission manager functionality. r=pbz
Differential Revision: https://phabricator.services.mozilla.com/D214729
2024-07-26 12:16:52 +00:00
Jan-Ivar Bruaroey
98d2685eea Bug 1904632 - validate permissions.default.* prefs r=pbz,necko-reviewers,kershaw
Differential Revision: https://phabricator.services.mozilla.com/D216856
2024-07-22 14:42:46 +00:00
William Wen
6aad46ac21 Bug 1658094 - Add new cleaner for "cookie" permissions. r=pbz
Differential Revision: https://phabricator.services.mozilla.com/D212057
2024-06-24 15:14:45 +00:00