Bug 1113621 - Rename InstallPhaseEvent to ExtendableEvent. r=baku relanding because it wasn't supposed to be backed out on a CLOSED TREE
authorNikhil Marathe <nsm.nikhil@gmail.com>
Thu, 06 Nov 2014 07:57:57 -0800
changeset 225506 fbf421e77962aaa7f9d64bee8a9438e6263f2fd2
parent 225505 e9d37cd95335336532e6e5d1b32207e31ccc7a51
child 225507 f86ce04bcdd906c690be861852f3bb03e20e3dba
push id28163
push userphilringnalda@gmail.com
push dateSat, 24 Jan 2015 16:27:39 +0000
treeherdermozilla-central@1cf171c1a177 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1113621
milestone38.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1113621 - Rename InstallPhaseEvent to ExtendableEvent. r=baku relanding because it wasn't supposed to be backed out on a CLOSED TREE Change Exposed=ServiceWorker for all ServiceWorker events. Move Func= exposure check to ServiceWorker.
dom/bindings/Bindings.conf
dom/webidl/ExtendableEvent.webidl
dom/webidl/InstallEvent.webidl
dom/webidl/InstallPhaseEvent.webidl
dom/webidl/ServiceWorker.webidl
dom/webidl/moz.build
dom/workers/ServiceWorker.cpp
dom/workers/ServiceWorker.h
dom/workers/ServiceWorkerEvents.cpp
dom/workers/ServiceWorkerEvents.h
dom/workers/ServiceWorkerManager.cpp
dom/workers/moz.build
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -404,16 +404,21 @@ DOMInterfaces = {
 
 'Exception': {
     'headerFile': 'mozilla/dom/DOMException.h',
     'binaryNames': {
         'message': 'messageMoz',
     },
 },
 
+'ExtendableEvent': {
+    'headerFile': 'mozilla/dom/ServiceWorkerEvents.h',
+    'nativeType': 'mozilla::dom::workers::ExtendableEvent',
+},
+
 'FileList': {
     'headerFile': 'mozilla/dom/File.h',
 },
 
 'FileReader': {
     'nativeType': 'nsDOMFileReader',
     'implicitJSContext': [ 'readAsArrayBuffer' ],
 },
@@ -600,21 +605,16 @@ DOMInterfaces = {
 {
     'nativeType': 'nsIInputStream',
     'notflattened': True
 },
 {
     'workers': True,
 }],
 
-'InstallPhaseEvent': {
-    'headerFile': 'ServiceWorkerEvents.h',
-    'nativeType': 'mozilla::dom::workers::InstallPhaseEvent',
-},
-
 'InstallEvent': {
     'headerFile': 'ServiceWorkerEvents.h',
     'nativeType': 'mozilla::dom::workers::InstallEvent',
 },
 
 'KeyEvent': {
     'concrete': False
 },
rename from dom/webidl/InstallPhaseEvent.webidl
rename to dom/webidl/ExtendableEvent.webidl
--- a/dom/webidl/InstallPhaseEvent.webidl
+++ b/dom/webidl/ExtendableEvent.webidl
@@ -2,17 +2,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * For more information on this interface, please see
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  */
 
-// While not explicitly restricted to ServiceWorkerGlobalScope, it probably
-// should be. https://github.com/slightlyoff/ServiceWorker/issues/254
-[Constructor(DOMString type, optional EventInit eventInitDict),
- Func="mozilla::dom::workers::ServiceWorkerEventsVisible",
- Exposed=(ServiceWorker,Window)]
-interface InstallPhaseEvent : Event {
+[Constructor(DOMString type, optional ExtendableEventInit eventInitDict),
+ Exposed=ServiceWorker]
+interface ExtendableEvent : Event {
   // https://github.com/slightlyoff/ServiceWorker/issues/261
   void waitUntil(Promise<any> p);
 };
+
+dictionary ExtendableEventInit : EventInit {
+  // Defined for the forward compatibility across the derived events
+};
--- a/dom/webidl/InstallEvent.webidl
+++ b/dom/webidl/InstallEvent.webidl
@@ -2,30 +2,19 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * For more information on this interface, please see
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  */
 
-// While not explicitly restricted to ServiceWorkerGlobalScope, it probably
-// should be. https://github.com/slightlyoff/ServiceWorker/issues/254
 [Constructor(DOMString type, optional InstallEventInit eventInitDict),
- Func="mozilla::dom::workers::ServiceWorkerEventsVisible",
- // XXXbz I have no idea where this should be exposed.  The spec makes
- // no sense.  But since it returns a ServiceWorker and that's only
- // exposed in Window, let's say Window.
- Exposed=Window]
-interface InstallEvent : InstallPhaseEvent {
-  // The currently active worker for this scope when this worker is asked to
-  // install itself.
-  // This may be null when a ServiceWorker is being installed for a previously
-  // uncontrolled scope.
-  // https://github.com/slightlyoff/ServiceWorker/issues/260
+ Exposed=ServiceWorker]
+interface InstallEvent : ExtendableEvent {
   readonly attribute ServiceWorker? activeWorker;
   void replace();
 };
 
 // Should be in the spec soon to satisfy conventions about events.
 // https://github.com/slightlyoff/ServiceWorker/issues/216.
 dictionary InstallEventInit : EventInit {
   ServiceWorker? activeWorker = null;
--- a/dom/webidl/ServiceWorker.webidl
+++ b/dom/webidl/ServiceWorker.webidl
@@ -5,19 +5,19 @@
  *
  * The origin of this IDL file is
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-obj
  *
  */
 
 // Still unclear what should be subclassed.
 // https://github.com/slightlyoff/ServiceWorker/issues/189
-[Pref="dom.serviceWorkers.enabled",
- // FIXME(nsm): Bug 1113522. Should also be exposed on Workers too.
- Exposed=Window]
+[Func="mozilla::dom::workers::ServiceWorkerVisible",
+ // FIXME(nsm): Bug 1113522. This is exposed to satisfy webidl constraints, but it won't actually work.
+ Exposed=(ServiceWorker,Window)]
 interface ServiceWorker : EventTarget {
   readonly attribute USVString scriptURL;
   readonly attribute ServiceWorkerState state;
 
   attribute EventHandler onstatechange;
 };
 
 ServiceWorker implements AbstractWorker;
--- a/dom/webidl/moz.build
+++ b/dom/webidl/moz.build
@@ -125,16 +125,17 @@ WEBIDL_FILES = [
     'DynamicsCompressorNode.webidl',
     'Element.webidl',
     'EngineeringMode.webidl',
     'Event.webidl',
     'EventHandler.webidl',
     'EventListener.webidl',
     'EventSource.webidl',
     'EventTarget.webidl',
+    'ExtendableEvent.webidl',
     'Fetch.webidl',
     'File.webidl',
     'FileList.webidl',
     'FileMode.webidl',
     'FileReader.webidl',
     'FileReaderSync.webidl',
     'FocusEvent.webidl',
     'FontFace.webidl',
@@ -240,17 +241,16 @@ WEBIDL_FILES = [
     'Identity.webidl',
     'ImageCapture.webidl',
     'ImageData.webidl',
     'ImageDocument.webidl',
     'InputEvent.webidl',
     'InputMethod.webidl',
     'InspectorUtils.webidl',
     'InstallEvent.webidl',
-    'InstallPhaseEvent.webidl',
     'InterAppConnection.webidl',
     'InterAppConnectionRequest.webidl',
     'InterAppMessagePort.webidl',
     'KeyAlgorithm.webidl',
     'KeyboardEvent.webidl',
     'KeyEvent.webidl',
     'LegacyQueryInterface.webidl',
     'LinkStyle.webidl',
--- a/dom/workers/ServiceWorker.cpp
+++ b/dom/workers/ServiceWorker.cpp
@@ -4,20 +4,38 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "ServiceWorker.h"
 
 #include "nsPIDOMWindow.h"
 #include "SharedWorker.h"
 #include "WorkerPrivate.h"
 
+#include "mozilla/Preferences.h"
 #include "mozilla/dom/Promise.h"
+#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
 
 using namespace mozilla::dom;
-USING_WORKERS_NAMESPACE
+
+namespace mozilla {
+namespace dom {
+namespace workers {
+
+bool
+ServiceWorkerVisible(JSContext* aCx, JSObject* aObj)
+{
+  if (NS_IsMainThread()) {
+    return Preferences::GetBool("dom.serviceWorkers.enabled", false);
+  }
+
+  ServiceWorkerGlobalScope* scope = nullptr;
+  nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope_workers,
+                             mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType>(aObj, scope);
+  return NS_SUCCEEDED(rv);
+}
 
 ServiceWorker::ServiceWorker(nsPIDOMWindow* aWindow,
                              SharedWorker* aSharedWorker)
   : DOMEventTargetHelper(aWindow),
     mState(ServiceWorkerState::Installing),
     mSharedWorker(aSharedWorker)
 {
   AssertIsOnMainThread();
@@ -50,8 +68,12 @@ WorkerPrivate*
 ServiceWorker::GetWorkerPrivate() const
 {
   // At some point in the future, this may be optimized to terminate a worker
   // that hasn't been used in a certain amount of time or when there is memory
   // pressure or similar.
   MOZ_ASSERT(mSharedWorker);
   return mSharedWorker->GetWorkerPrivate();
 }
+
+} // namespace workers
+} // namespace dom
+} // namespace mozilla
--- a/dom/workers/ServiceWorker.h
+++ b/dom/workers/ServiceWorker.h
@@ -16,16 +16,19 @@ namespace mozilla {
 namespace dom {
 
 class Promise;
 
 namespace workers {
 
 class SharedWorker;
 
+bool
+ServiceWorkerVisible(JSContext* aCx, JSObject* aObj);
+
 class ServiceWorker MOZ_FINAL : public DOMEventTargetHelper
 {
   friend class RuntimeService;
 public:
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorker, DOMEventTargetHelper)
 
   IMPL_EVENT_HANDLER(statechange)
--- a/dom/workers/ServiceWorkerEvents.cpp
+++ b/dom/workers/ServiceWorkerEvents.cpp
@@ -6,62 +6,52 @@
 
 #include "ServiceWorkerEvents.h"
 
 #include "nsContentUtils.h"
 
 #include "mozilla/dom/Promise.h"
 #include "mozilla/dom/WorkerScope.h"
 #include "mozilla/dom/workers/bindings/ServiceWorker.h"
-#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
 
 using namespace mozilla::dom;
 
 BEGIN_WORKERS_NAMESPACE
 
-bool
-ServiceWorkerEventsVisible(JSContext* aCx, JSObject* aObj)
-{
-  ServiceWorkerGlobalScope* scope = nullptr;
-  nsresult rv = UnwrapObject<prototypes::id::ServiceWorkerGlobalScope_workers,
-                             mozilla::dom::ServiceWorkerGlobalScopeBinding_workers::NativeType>(aObj, scope);
-  return NS_SUCCEEDED(rv) && scope;
-}
-
-InstallPhaseEvent::InstallPhaseEvent(EventTarget* aOwner)
+ExtendableEvent::ExtendableEvent(EventTarget* aOwner)
   : Event(aOwner, nullptr, nullptr)
 {
 }
 
 void
-InstallPhaseEvent::WaitUntil(Promise& aPromise)
+ExtendableEvent::WaitUntil(Promise& aPromise)
 {
   MOZ_ASSERT(!NS_IsMainThread());
 
   // Only first caller counts.
   if (EventPhase() == AT_TARGET && !mPromise) {
     mPromise = &aPromise;
   }
 }
 
-NS_IMPL_ADDREF_INHERITED(InstallPhaseEvent, Event)
-NS_IMPL_RELEASE_INHERITED(InstallPhaseEvent, Event)
+NS_IMPL_ADDREF_INHERITED(ExtendableEvent, Event)
+NS_IMPL_RELEASE_INHERITED(ExtendableEvent, Event)
 
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent)
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(ExtendableEvent)
 NS_INTERFACE_MAP_END_INHERITING(Event)
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallPhaseEvent, Event, mPromise)
+NS_IMPL_CYCLE_COLLECTION_INHERITED(ExtendableEvent, Event, mPromise)
 
 InstallEvent::InstallEvent(EventTarget* aOwner)
-  : InstallPhaseEvent(aOwner)
+  : ExtendableEvent(aOwner)
   , mActivateImmediately(false)
 {
 }
 
-NS_IMPL_ADDREF_INHERITED(InstallEvent, InstallPhaseEvent)
-NS_IMPL_RELEASE_INHERITED(InstallEvent, InstallPhaseEvent)
+NS_IMPL_ADDREF_INHERITED(InstallEvent, ExtendableEvent)
+NS_IMPL_RELEASE_INHERITED(InstallEvent, ExtendableEvent)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(InstallEvent)
-NS_INTERFACE_MAP_END_INHERITING(InstallPhaseEvent)
+NS_INTERFACE_MAP_END_INHERITING(ExtendableEvent)
 
-NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent, InstallPhaseEvent, mActiveWorker)
+NS_IMPL_CYCLE_COLLECTION_INHERITED(InstallEvent, ExtendableEvent, mActiveWorker)
 
 END_WORKERS_NAMESPACE
--- a/dom/workers/ServiceWorkerEvents.h
+++ b/dom/workers/ServiceWorkerEvents.h
@@ -2,63 +2,60 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef mozilla_dom_workers_serviceworkerevents_h__
 #define mozilla_dom_workers_serviceworkerevents_h__
 
 #include "mozilla/dom/Event.h"
-#include "mozilla/dom/InstallPhaseEventBinding.h"
+#include "mozilla/dom/ExtendableEventBinding.h"
 #include "mozilla/dom/InstallEventBinding.h"
 
 namespace mozilla {
 namespace dom {
   class Promise;
 } // namespace dom
 } // namespace mozilla
 
 BEGIN_WORKERS_NAMESPACE
 
 class ServiceWorker;
 
-bool
-ServiceWorkerEventsVisible(JSContext* aCx, JSObject* aObj);
-
-class InstallPhaseEvent : public Event
+class ExtendableEvent : public Event
 {
   nsRefPtr<Promise> mPromise;
 
 protected:
-  explicit InstallPhaseEvent(mozilla::dom::EventTarget* aOwner);
-  ~InstallPhaseEvent() {}
+  explicit ExtendableEvent(mozilla::dom::EventTarget* aOwner);
+  ~ExtendableEvent() {}
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallPhaseEvent, Event)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ExtendableEvent, Event)
   NS_FORWARD_TO_EVENT
 
   virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
   {
-    return mozilla::dom::InstallPhaseEventBinding::Wrap(aCx, this);
+    return mozilla::dom::ExtendableEventBinding::Wrap(aCx, this);
   }
 
-  static already_AddRefed<InstallPhaseEvent>
+  static already_AddRefed<ExtendableEvent>
   Constructor(mozilla::dom::EventTarget* aOwner,
               const nsAString& aType,
               const EventInit& aOptions)
   {
-    nsRefPtr<InstallPhaseEvent> e = new InstallPhaseEvent(aOwner);
+    nsRefPtr<ExtendableEvent> e = new ExtendableEvent(aOwner);
     bool trusted = e->Init(aOwner);
     e->InitEvent(aType, aOptions.mBubbles, aOptions.mCancelable);
     e->SetTrusted(trusted);
     return e.forget();
   }
 
-  static already_AddRefed<InstallPhaseEvent>
+  static already_AddRefed<ExtendableEvent>
   Constructor(const GlobalObject& aGlobal,
               const nsAString& aType,
               const EventInit& aOptions,
               ErrorResult& aRv)
   {
     nsCOMPtr<EventTarget> target = do_QueryInterface(aGlobal.GetAsSupports());
     return Constructor(target, aType, aOptions);
   }
@@ -69,29 +66,29 @@ public:
   already_AddRefed<Promise>
   GetPromise() const
   {
     nsRefPtr<Promise> p = mPromise;
     return p.forget();
   }
 };
 
-class InstallEvent MOZ_FINAL : public InstallPhaseEvent
+class InstallEvent MOZ_FINAL : public ExtendableEvent
 {
   // FIXME(nsm): Bug 982787 will allow actually populating this.
   nsRefPtr<ServiceWorker> mActiveWorker;
   bool mActivateImmediately;
 
 protected:
   explicit InstallEvent(mozilla::dom::EventTarget* aOwner);
   ~InstallEvent() {}
 
 public:
   NS_DECL_ISUPPORTS_INHERITED
-  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, InstallPhaseEvent)
+  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(InstallEvent, ExtendableEvent)
   NS_FORWARD_TO_EVENT
 
   virtual JSObject* WrapObjectInternal(JSContext* aCx) MOZ_OVERRIDE
   {
     return mozilla::dom::InstallEventBinding::Wrap(aCx, this);
   }
 
   static already_AddRefed<InstallEvent>
--- a/dom/workers/ServiceWorkerManager.cpp
+++ b/dom/workers/ServiceWorkerManager.cpp
@@ -1038,18 +1038,18 @@ private:
   {
     MOZ_ASSERT(aWorkerPrivate->IsServiceWorker());
     nsRefPtr<EventTarget> target = do_QueryObject(aWorkerPrivate->GlobalScope());
 
     // FIXME(nsm): Set activeWorker to the correct thing.
     EventInit init;
     init.mBubbles = false;
     init.mCancelable = true;
-    nsRefPtr<InstallPhaseEvent> event =
-      InstallPhaseEvent::Constructor(target, NS_LITERAL_STRING("activate"), init);
+    nsRefPtr<ExtendableEvent> event =
+      ExtendableEvent::Constructor(target, NS_LITERAL_STRING("activate"), init);
 
     event->SetTrusted(true);
 
     nsRefPtr<Promise> waitUntilPromise;
 
     // FIXME(nsm): Install error handler for any listener errors.
     ErrorResult result;
     result = target->DispatchDOMEvent(nullptr, event, nullptr, nullptr);
--- a/dom/workers/moz.build
+++ b/dom/workers/moz.build
@@ -3,16 +3,17 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # Public stuff.
 EXPORTS.mozilla.dom += [
     'ServiceWorkerCommon.h',
     'ServiceWorkerContainer.h',
+    'ServiceWorkerEvents.h',
     'ServiceWorkerRegistration.h',
     'WorkerPrivate.h',
     'WorkerRunnable.h',
     'WorkerScope.h',
 ]
 
 EXPORTS.mozilla.dom.workers += [
     'ServiceWorkerManager.h',