Commit 54740478 authored by Ehsan Akhgari's avatar Ehsan Akhgari
Browse files

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

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.
parent 4fffaa9e
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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();
}
+2 −0
Original line number Diff line number Diff line
@@ -2439,6 +2439,8 @@ public:
                                                nsIDocument* aDoc,
                                                nsIHttpChannel* aChannel);

  static bool PushEnabled(JSContext* aCx, JSObject* aObj);

private:
  static bool InitializeEventTable();

+0 −17
Original line number Diff line number Diff line
@@ -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)
{
+0 −3
Original line number Diff line number Diff line
@@ -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*
+4 −2
Original line number Diff line number Diff line
@@ -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;
};
Loading