Bug 1188091 - Fix the exposure of Push interfaces; r=dougt,bzbarsky

Currently we don't check the dom.push.enabled pref in some cases for
some of these interfaces.  This patch unifies how all of these
interfaces are exposed to Window, Worker, and ServiceWorker.
This commit is contained in:
Ehsan Akhgari 2015-07-27 15:35:28 -04:00
parent 31d9fa3fe0
commit 6e916540f5
15 changed files with 60 additions and 30 deletions

View File

@ -51,6 +51,7 @@
#include "mozilla/dom/TextDecoder.h"
#include "mozilla/dom/TouchEvent.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/WorkerPrivate.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/EventListenerManager.h"
#include "mozilla/EventStateManager.h"
@ -7973,3 +7974,22 @@ nsContentUtils::SetFetchReferrerURIWithPolicy(nsIPrincipal* aPrincipal,
net::ReferrerPolicy referrerPolicy = aDoc->GetReferrerPolicy();
return aChannel->SetReferrerWithPolicy(referrerURI, referrerPolicy);
}
// static
bool
nsContentUtils::PushEnabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.push.enabled", false);
}
using namespace workers;
// Otherwise, check the pref via the WorkerPrivate
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return false;
}
return workerPrivate->PushEnabled();
}

View File

@ -2439,6 +2439,8 @@ public:
nsIDocument* aDoc,
nsIHttpChannel* aChannel);
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
private:
static bool InitializeEventTable();

View File

@ -129,23 +129,6 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PushSubscription)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_END
// PushManager
// static
bool
PushManager::Enabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.push.enabled", false);
}
// XXXnsm: As of this patch it seems like Push will be enabled before or with
// ServiceWorkers, so this seems OK for now.
ServiceWorkerGlobalScope* scope = nullptr;
nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope_workers,
mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType>(aObj, scope);
return NS_SUCCEEDED(rv);
}
PushManager::PushManager(nsIGlobalObject* aGlobal, const nsAString& aScope)
: mGlobal(aGlobal), mScope(aScope)
{

View File

@ -106,9 +106,6 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(PushManager)
static bool
Enabled(JSContext* aCx, JSObject* aObj);
explicit PushManager(nsIGlobalObject* aGlobal, const nsAString& aScope);
nsIGlobalObject*

View File

@ -7,7 +7,9 @@
* https://w3c.github.io/push-api/
*/
[Constructor(DOMString type, optional PushEventInit eventInitDict), Exposed=ServiceWorker]
[Constructor(DOMString type, optional PushEventInit eventInitDict),
Func="nsContentUtils::PushEnabled",
Exposed=ServiceWorker]
interface PushEvent : ExtendableEvent {
readonly attribute PushMessageData data;
};
@ -16,4 +18,4 @@ typedef USVString PushMessageDataInit;
dictionary PushEventInit : ExtendableEventInit {
PushMessageDataInit data;
};
};

View File

@ -22,7 +22,7 @@ interface PushManagerImpl {
[Func="ServiceWorkerRegistration::WebPushMethodHider"] void setScope(DOMString scope);
};
[Exposed=(Window,Worker), Func="mozilla::dom::PushManager::Enabled"]
[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"]
interface PushManager {
[ChromeOnly, Throws, Exposed=Window]
void setPushManagerImpl(PushManagerImpl store);

View File

@ -7,7 +7,8 @@
* https://w3c.github.io/push-api/
*/
[Exposed=ServiceWorker]
[Func="nsContentUtils::PushEnabled",
Exposed=ServiceWorker]
interface PushMessageData
{
// FIXME(nsm): Bug 1149195.

View File

@ -9,7 +9,7 @@
interface Principal;
[Exposed=(Window,Worker), Func="mozilla::dom::PushManager::Enabled",
[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled",
ChromeConstructor(DOMString pushEndpoint, DOMString scope)]
interface PushSubscription
{

View File

@ -28,7 +28,7 @@ interface ServiceWorkerRegistration : EventTarget {
partial interface ServiceWorkerRegistration {
#ifndef MOZ_SIMPLEPUSH
[Throws, Exposed=(Window,Worker), Func="mozilla::dom::PushManager::Enabled"]
[Throws, Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"]
readonly attribute PushManager pushManager;
#endif
};

View File

@ -165,6 +165,7 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1,
#define PREF_SERVICEWORKERS_TESTING_ENABLED "dom.serviceWorkers.testing.enabled"
#define PREF_INTERCEPTION_ENABLED "dom.serviceWorkers.interception.enabled"
#define PREF_INTERCEPTION_OPAQUE_ENABLED "dom.serviceWorkers.interception.opaque.enabled"
#define PREF_PUSH_ENABLED "dom.push.enabled"
namespace {
@ -1944,6 +1945,10 @@ RuntimeService::Init()
WorkerPrefChanged,
PREF_SERVICEWORKERS_TESTING_ENABLED,
reinterpret_cast<void *>(WORKERPREF_SERVICEWORKERS_TESTING))) ||
NS_FAILED(Preferences::RegisterCallbackAndCall(
WorkerPrefChanged,
PREF_PUSH_ENABLED,
reinterpret_cast<void *>(WORKERPREF_PUSH))) ||
NS_FAILED(Preferences::RegisterCallback(LoadRuntimeOptions,
PREF_JS_OPTIONS_PREFIX,
nullptr)) ||
@ -2167,6 +2172,10 @@ RuntimeService::Cleanup()
WorkerPrefChanged,
PREF_DOM_WORKERNOTIFICATION_ENABLED,
reinterpret_cast<void *>(WORKERPREF_DOM_WORKERNOTIFICATION))) ||
NS_FAILED(Preferences::UnregisterCallback(
WorkerPrefChanged,
PREF_PUSH_ENABLED,
reinterpret_cast<void *>(WORKERPREF_PUSH))) ||
#if DUMP_CONTROLLED_BY_PREF
NS_FAILED(Preferences::UnregisterCallback(
WorkerPrefChanged,
@ -2715,6 +2724,7 @@ RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure)
case WORKERPREF_INTERCEPTION_OPAQUE_ENABLED:
case WORKERPREF_SERVICEWORKERS:
case WORKERPREF_SERVICEWORKERS_TESTING:
case WORKERPREF_PUSH:
sDefaultPreferences[key] = Preferences::GetBool(aPrefName, false);
break;

View File

@ -20,6 +20,7 @@
#endif
#include "nsProxyRelease.h"
#include "nsContentUtils.h"
class nsIInterceptedChannel;

View File

@ -1321,6 +1321,13 @@ public:
return mPreferences[WORKERPREF_DOM_CACHES_TESTING];
}
bool
PushEnabled() const
{
AssertIsOnWorkerThread();
return mPreferences[WORKERPREF_PUSH];
}
bool
OnLine() const
{

View File

@ -205,6 +205,7 @@ enum WorkerPreference
WORKERPREF_DOM_CACHES_TESTING, // dom.caches.testing.enabled
WORKERPREF_SERVICEWORKERS_TESTING, // dom.serviceWorkers.testing.enabled
WORKERPREF_INTERCEPTION_OPAQUE_ENABLED, // dom.serviceWorkers.interception.opaque.enabled
WORKERPREF_PUSH, // dom.push.enabled
WORKERPREF_COUNT
};

View File

@ -48,8 +48,6 @@ var ecmaGlobals =
"Number",
"Object",
"Proxy",
"PushEvent",
"PushMessageData",
"RangeError",
"ReferenceError",
"Reflect",
@ -172,9 +170,13 @@ var interfaceNamesInGlobalScope =
// IMPORTANT: Do not change this list without review from a DOM peer!
"Promise",
// IMPORTANT: Do not change this list without review from a DOM peer!
"PushManager",
{ name: "PushEvent", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
"PushSubscription",
{ name: "PushManager", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "PushMessageData", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "PushSubscription", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
"Request",
// IMPORTANT: Do not change this list without review from a DOM peer!

View File

@ -161,6 +161,10 @@ var interfaceNamesInGlobalScope =
"PerformanceMeasure",
// IMPORTANT: Do not change this list without review from a DOM peer!
"Promise",
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "PushManager", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
{ name: "PushSubscription", b2g: false, android: false, release: false },
// IMPORTANT: Do not change this list without review from a DOM peer!
"Request",
// IMPORTANT: Do not change this list without review from a DOM peer!