Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 3 - DOM Caches enabled, r=asuth

This commit is contained in:
Andrea Marchesini 2017-11-30 18:16:44 +01:00
parent df66e497b8
commit 6868bd1bd3
11 changed files with 11 additions and 38 deletions

View File

@ -36,6 +36,7 @@ DOMPreferences::DumpEnabled()
#endif
PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
PREF(DOMCachesEnabled, "dom.caches.enabled")
#undef PREF
@ -47,6 +48,7 @@ PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
}
PREF_WEBIDL(ImageBitmapExtensionsEnabled)
PREF_WEBIDL(DOMCachesEnabled)
#undef PREF_WEBIDL

View File

@ -19,6 +19,10 @@ public:
// Returns true if the canvas.imagebitmap_extensions.enabled pref is set.
static bool ImageBitmapExtensionsEnabled();
static bool ImageBitmapExtensionsEnabled(JSContext* aCx, JSObject* aObj);
// Returns true if the dom.caches.enabled pref is set.
static bool DOMCachesEnabled();
static bool DOMCachesEnabled(JSContext* aCx, JSObject* aObj);
};
} // dom namespace

View File

@ -37,6 +37,7 @@
#include "nsSize.h"
#include "mozilla/FlushType.h"
#include "prclist.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/StorageEvent.h"
#include "mozilla/dom/StorageEventBinding.h"

24
dom/cache/Cache.cpp vendored
View File

@ -17,6 +17,7 @@
#include "mozilla/dom/cache/CacheChild.h"
#include "mozilla/dom/cache/CacheWorkerHolder.h"
#include "mozilla/dom/cache/ReadStream.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/Preferences.h"
#include "mozilla/Unused.h"
@ -517,29 +518,6 @@ Cache::Keys(JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
return ExecuteOp(args, aRv);
}
// static
bool
Cache::PrefEnabled(JSContext* aCx, JSObject* aObj)
{
using mozilla::dom::workers::WorkerPrivate;
using mozilla::dom::workers::GetWorkerPrivateFromContext;
// If we're on the main thread, then check the pref directly.
if (NS_IsMainThread()) {
bool enabled = false;
Preferences::GetBool("dom.caches.enabled", &enabled);
return enabled;
}
// Otherwise check the pref via the work private helper
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return false;
}
return workerPrivate->DOMCachesEnabled();
}
nsISupports*
Cache::GetParentObject() const
{

2
dom/cache/Cache.h vendored
View File

@ -68,8 +68,6 @@ public:
const CacheQueryOptions& aParams, ErrorResult& aRv);
// binding methods
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
nsISupports* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;

View File

@ -444,13 +444,6 @@ CacheStorage::Keys(ErrorResult& aRv)
return promise.forget();
}
// static
bool
CacheStorage::PrefEnabled(JSContext* aCx, JSObject* aObj)
{
return Cache::PrefEnabled(aCx, aObj);
}
// static
already_AddRefed<CacheStorage>
CacheStorage::Constructor(const GlobalObject& aGlobal,

View File

@ -73,8 +73,6 @@ public:
nsIPrincipal* aPrincipal, ErrorResult& aRv);
// binding methods
static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
nsISupports* GetParentObject() const;
virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;

View File

@ -11,7 +11,7 @@
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache
[Exposed=(Window,Worker),
Func="mozilla::dom::cache::Cache::PrefEnabled"]
Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"]
interface Cache {
[NewObject]
Promise<Response> match(RequestInfo request, optional CacheQueryOptions options);

View File

@ -14,7 +14,7 @@ interface Principal;
[Exposed=(Window,Worker),
ChromeConstructor(CacheStorageNamespace namespace, Principal principal),
Func="mozilla::dom::cache::CacheStorage::PrefEnabled"]
Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"]
interface CacheStorage {
[NewObject]
Promise<Response> match(RequestInfo request, optional CacheQueryOptions options);

View File

@ -62,7 +62,7 @@ partial interface WindowOrWorkerGlobalScope {
// https://w3c.github.io/ServiceWorker/#self-caches
partial interface WindowOrWorkerGlobalScope {
[Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled", SameObject]
[Throws, Func="mozilla::dom::DOMPreferences::DOMCachesEnabled", SameObject]
readonly attribute CacheStorage caches;
};

View File

@ -21,7 +21,6 @@
// * First argument is the name of the pref.
// * The name of the function that updates the new value of a pref.
WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)
WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED)
WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)