Bug 1784590 - Part 2: Add use counters for unsupported APIs in PBM r=asuth

Depends on D154578

Differential Revision: https://phabricator.services.mozilla.com/D154579
This commit is contained in:
Kagami Sascha Rosylight 2022-08-22 18:48:12 +00:00
Родитель bfc04ec1a4
Коммит 695e5e60df
6 изменённых файлов: 59 добавлений и 7 удалений

Просмотреть файл

@ -1818,6 +1818,12 @@ network::Connection* Navigator::GetConnection(ErrorResult& aRv) {
already_AddRefed<ServiceWorkerContainer> Navigator::ServiceWorker() {
MOZ_ASSERT(mWindow);
if (mWindow->AsGlobal()->GetStorageAccess() ==
StorageAccess::ePrivateBrowsing) {
SetUseCounter(mWindow->AsGlobal()->GetGlobalJSObject(),
eUseCounter_custom_PrivateBrowsingNavigatorServiceWorker);
}
if (!mServiceWorkerContainer) {
mServiceWorkerContainer =
ServiceWorkerContainer::Create(mWindow->AsGlobal());

Просмотреть файл

@ -404,5 +404,15 @@ method Element.setHTML
// Features that might be deprecated in the future
custom WindowOpenEmptyUrl calls window.open with an empty url argument
// Unsupported web APIs in Private Browsing Mode
custom PrivateBrowsingIDBFactoryOpen calls indexedDB.open in Private Browsing Mode
custom PrivateBrowsingIDBFactoryDeleteDatabase calls indexedDB.deleteDatabase in Private Browsing Mode
custom PrivateBrowsingCachesMatch calls caches.match in Private Browsing Mode
custom PrivateBrowsingCachesHas calls caches.has in Private Browsing Mode
custom PrivateBrowsingCachesOpen calls caches.open in Private Browsing Mode
custom PrivateBrowsingCachesDelete calls caches.delete in Private Browsing Mode
custom PrivateBrowsingCachesKeys calls caches.keys in Private Browsing Mode
custom PrivateBrowsingNavigatorServiceWorker accesses navigator.serviceWorker in Private Browsing Mode
// NOTE: Adding use counters requires data review, see
// https://wiki.mozilla.org/Data_Collection

Просмотреть файл

@ -65,3 +65,11 @@ method console.timeStamp
method console.profile
method console.profileEnd
// Unsupported web APIs in Private Browsing Mode
custom PrivateBrowsingIDBFactoryOpen calls indexedDB.open in Private Browsing Mode
custom PrivateBrowsingIDBFactoryDeleteDatabase calls indexedDB.deleteDatabase in Private Browsing Mode
custom PrivateBrowsingCachesMatch calls caches.match in Private Browsing Mode
custom PrivateBrowsingCachesHas calls caches.has in Private Browsing Mode
custom PrivateBrowsingCachesOpen calls caches.open in Private Browsing Mode
custom PrivateBrowsingCachesDelete calls caches.delete in Private Browsing Mode
custom PrivateBrowsingCachesKeys calls caches.keys in Private Browsing Mode

25
dom/cache/CacheStorage.cpp поставляемый
Просмотреть файл

@ -301,7 +301,8 @@ already_AddRefed<Promise> CacheStorage::Match(
const MultiCacheQueryOptions& aOptions, ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (!HasStorageAccess()) {
if (!HasStorageAccess(eUseCounter_custom_PrivateBrowsingCachesMatch,
UseCounterWorker::Custom_PrivateBrowsingCachesMatch)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
@ -339,7 +340,8 @@ already_AddRefed<Promise> CacheStorage::Has(const nsAString& aKey,
ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (!HasStorageAccess()) {
if (!HasStorageAccess(eUseCounter_custom_PrivateBrowsingCachesHas,
UseCounterWorker::Custom_PrivateBrowsingCachesHas)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
@ -367,7 +369,8 @@ already_AddRefed<Promise> CacheStorage::Open(const nsAString& aKey,
ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (!HasStorageAccess()) {
if (!HasStorageAccess(eUseCounter_custom_PrivateBrowsingCachesOpen,
UseCounterWorker::Custom_PrivateBrowsingCachesOpen)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
@ -395,7 +398,8 @@ already_AddRefed<Promise> CacheStorage::Delete(const nsAString& aKey,
ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (!HasStorageAccess()) {
if (!HasStorageAccess(eUseCounter_custom_PrivateBrowsingCachesDelete,
UseCounterWorker::Custom_PrivateBrowsingCachesDelete)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
@ -422,7 +426,8 @@ already_AddRefed<Promise> CacheStorage::Delete(const nsAString& aKey,
already_AddRefed<Promise> CacheStorage::Keys(ErrorResult& aRv) {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (!HasStorageAccess()) {
if (!HasStorageAccess(eUseCounter_custom_PrivateBrowsingCachesKeys,
UseCounterWorker::Custom_PrivateBrowsingCachesKeys)) {
aRv.Throw(NS_ERROR_DOM_SECURITY_ERR);
return nullptr;
}
@ -553,13 +558,21 @@ OpenMode CacheStorage::GetOpenMode() const {
return mNamespace == CHROME_ONLY_NAMESPACE ? OpenMode::Eager : OpenMode::Lazy;
}
bool CacheStorage::HasStorageAccess() const {
bool CacheStorage::HasStorageAccess(UseCounter aLabel,
UseCounterWorker aLabelWorker) const {
NS_ASSERT_OWNINGTHREAD(CacheStorage);
if (NS_WARN_IF(!mGlobal)) {
return false;
}
StorageAccess access = mGlobal->GetStorageAccess();
if (access == StorageAccess::ePrivateBrowsing) {
if (NS_IsMainThread()) {
SetUseCounter(mGlobal->GetGlobalJSObject(), aLabel);
} else {
SetUseCounter(aLabelWorker);
}
}
return access > StorageAccess::ePrivateBrowsing ||
(StaticPrefs::
privacy_partition_always_partition_third_party_non_cookie_storage() &&

2
dom/cache/CacheStorage.h поставляемый
Просмотреть файл

@ -95,7 +95,7 @@ class CacheStorage final : public nsISupports,
OpenMode GetOpenMode() const;
bool HasStorageAccess() const;
bool HasStorageAccess(UseCounter aLabel, UseCounterWorker aLabelWorker) const;
const Namespace mNamespace;
nsCOMPtr<nsIGlobalObject> mGlobal;

Просмотреть файл

@ -401,6 +401,7 @@ RefPtr<IDBOpenDBRequest> IDBFactory::Open(JSContext* aCx,
const IDBOpenDBOptions& aOptions,
CallerType aCallerType,
ErrorResult& aRv) {
// This overload is nonstandard, see bug 1275496.
// Ignore calls with empty options for telemetry of usage count.
// Unfortunately, we cannot distinguish between the use of the method with
// only a single argument (which actually is a standard overload we don't want
@ -536,6 +537,20 @@ RefPtr<IDBOpenDBRequest> IDBFactory::OpenInternal(
return nullptr;
}
} else {
if (mGlobal->GetStorageAccess() == StorageAccess::ePrivateBrowsing) {
if (NS_IsMainThread()) {
SetUseCounter(
mGlobal->GetGlobalJSObject(),
aDeleting
? eUseCounter_custom_PrivateBrowsingIDBFactoryOpen
: eUseCounter_custom_PrivateBrowsingIDBFactoryDeleteDatabase);
} else {
SetUseCounter(
aDeleting ? UseCounterWorker::Custom_PrivateBrowsingIDBFactoryOpen
: UseCounterWorker::
Custom_PrivateBrowsingIDBFactoryDeleteDatabase);
}
}
principalInfo = *mPrincipalInfo;
}