From 22eb6b83af864d37d6f885043d577466e3d80936 Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Tue, 17 Jun 2014 11:01:28 -0700 Subject: [PATCH] Bug 1025082 - ServiceWorker related WebIDL changes. r=ehsan,jst --HG-- extra : amend_source : c8d89097ddfb423ba2eb39beb469c48b69944a89 --- content/base/src/nsGkAtomList.h | 2 +- dom/webidl/ServiceWorker.webidl | 1 - dom/webidl/ServiceWorkerContainer.webidl | 17 ++++++++++------- dom/workers/RuntimeService.cpp | 3 --- dom/workers/ServiceWorkerContainer.cpp | 18 +++++++++++++----- dom/workers/ServiceWorkerContainer.h | 9 ++++++--- .../test/serviceworkers/test_navigator.html | 9 +++++---- 7 files changed, 35 insertions(+), 24 deletions(-) diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index 7c1ddf2f64c..e3354c66d76 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -1945,8 +1945,8 @@ GK_ATOM(onratechange, "onratechange") GK_ATOM(ondurationchange, "ondurationchange") GK_ATOM(onvolumechange, "onvolumechange") GK_ATOM(onaddtrack, "onaddtrack") +GK_ATOM(oncontrollerchange, "oncontrollerchange") GK_ATOM(oncuechange, "oncuechange") -GK_ATOM(oncurrentchange, "oncurrentchange") GK_ATOM(onenter, "onenter") GK_ATOM(onexit, "onexit") GK_ATOM(onneedkey, "onneedkey") diff --git a/dom/webidl/ServiceWorker.webidl b/dom/webidl/ServiceWorker.webidl index 0bab287ec74..d3f9100a6f6 100644 --- a/dom/webidl/ServiceWorker.webidl +++ b/dom/webidl/ServiceWorker.webidl @@ -22,7 +22,6 @@ interface ServiceWorker : EventTarget { ServiceWorker implements AbstractWorker; enum ServiceWorkerState { - "parsed", "installing", "installed", "activating", diff --git a/dom/webidl/ServiceWorkerContainer.webidl b/dom/webidl/ServiceWorkerContainer.webidl index 0f189bde427..902a35d8295 100644 --- a/dom/webidl/ServiceWorkerContainer.webidl +++ b/dom/webidl/ServiceWorkerContainer.webidl @@ -15,23 +15,26 @@ interface ServiceWorkerContainer { // and discussion at https://etherpad.mozilla.org/serviceworker07apr [Unforgeable] readonly attribute ServiceWorker? installing; [Unforgeable] readonly attribute ServiceWorker? waiting; - [Unforgeable] readonly attribute ServiceWorker? current; + [Unforgeable] readonly attribute ServiceWorker? active; + [Unforgeable] readonly attribute ServiceWorker? controller; + // Promise + readonly attribute Promise ready; + + // Promise?> [Throws] Promise getAll(); + // Promise [Throws] Promise register(DOMString url, optional RegistrationOptionList options); + // Promise [Throws] Promise unregister(DOMString? scope); - // Promise - [Throws] - Promise whenReady(); - attribute EventHandler onupdatefound; - attribute EventHandler oncurrentchange; + attribute EventHandler oncontrollerchange; attribute EventHandler onreloadpage; attribute EventHandler onerror; }; @@ -46,5 +49,5 @@ partial interface ServiceWorkerContainer { }; dictionary RegistrationOptionList { - DOMString scope = "*"; + DOMString scope = "/*"; }; diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index c65784f63b0..a693d515ffe 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -2100,9 +2100,6 @@ RuntimeService::CreateServiceWorker(const GlobalObject& aGlobal, nsRefPtr serviceWorker = new ServiceWorker(window, sharedWorker); - // While it hasn't been parsed, the intention is to only expose ServiceWorkers - // to content after it has indeed been parsed. - serviceWorker->mState = ServiceWorkerState::Parsed; serviceWorker->mURL = aScriptURL; serviceWorker->mScope = NS_ConvertUTF8toUTF16(aScope); diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index 064b49eec09..e8198965022 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -97,7 +97,14 @@ ServiceWorkerContainer::GetWaiting() } already_AddRefed -ServiceWorkerContainer::GetCurrent() +ServiceWorkerContainer::GetActive() +{ + // FIXME(nsm): Bug 1002570 + return nullptr; +} + +already_AddRefed +ServiceWorkerContainer::GetController() { // FIXME(nsm): Bug 1002570 return nullptr; @@ -112,11 +119,12 @@ ServiceWorkerContainer::GetAll(ErrorResult& aRv) } already_AddRefed -ServiceWorkerContainer::WhenReady(ErrorResult& aRv) +ServiceWorkerContainer::Ready() { - // FIXME(nsm): Bug 984048 - aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); - return nullptr; + // FIXME(nsm): Bug 1025077 + nsCOMPtr global = do_QueryInterface(mWindow); + nsRefPtr promise = new Promise(global); + return promise.forget(); } // Testing only. diff --git a/dom/workers/ServiceWorkerContainer.h b/dom/workers/ServiceWorkerContainer.h index 62cf01ee355..875c55df165 100644 --- a/dom/workers/ServiceWorkerContainer.h +++ b/dom/workers/ServiceWorkerContainer.h @@ -29,7 +29,7 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServiceWorkerContainer, DOMEventTargetHelper) IMPL_EVENT_HANDLER(updatefound) - IMPL_EVENT_HANDLER(currentchange) + IMPL_EVENT_HANDLER(controllerchange) IMPL_EVENT_HANDLER(reloadpage) IMPL_EVENT_HANDLER(error) @@ -64,13 +64,16 @@ public: GetWaiting(); already_AddRefed - GetCurrent(); + GetActive(); + + already_AddRefed + GetController(); already_AddRefed GetAll(ErrorResult& aRv); already_AddRefed - WhenReady(ErrorResult& aRv); + Ready(); // Testing only. already_AddRefed diff --git a/dom/workers/test/serviceworkers/test_navigator.html b/dom/workers/test/serviceworkers/test_navigator.html index b11732b56bf..2b3ad7ed87e 100644 --- a/dom/workers/test/serviceworkers/test_navigator.html +++ b/dom/workers/test/serviceworkers/test_navigator.html @@ -20,10 +20,11 @@ ok(typeof navigator.serviceWorker.register === "function", "navigator.serviceWorker.register() should be a function."); ok(typeof navigator.serviceWorker.unregister === "function", "navigator.serviceWorker.unregister() should be a function."); ok(typeof navigator.serviceWorker.getAll === "function", "navigator.serviceWorker.getAll() should be a function."); - ok(typeof navigator.serviceWorker.whenReady === "function", "navigator.serviceWorker.whenReady() should be a function."); - ok(navigator.serviceWorker.installing === null, "There should be no installing worker for an uncontrolled document."); - ok(navigator.serviceWorker.waiting === null, "There should be no waiting worker for an uncontrolled document."); - ok(navigator.serviceWorker.current === null, "There should be no current worker for an uncontrolled document."); + ok(navigator.serviceWorker.ready instanceof Promise, "navigator.serviceWorker.ready should be a Promise."); + ok(navigator.serviceWorker.installing === null, "There should be no installing worker for an uncontrolled scope."); + ok(navigator.serviceWorker.waiting === null, "There should be no waiting worker for an uncontrolled scope."); + ok(navigator.serviceWorker.active === null, "There should be no active worker for an uncontrolled scope."); + ok(navigator.serviceWorker.controller === null, "There should be no active worker for an uncontrolled document."); } SimpleTest.waitForExplicitFinish();