Auto merge of #11114 - creativcoder:nav-sw, r=jdm

implement related service worker interface and register method

Fixes  #11091

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11114)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-06-02 06:18:59 -05:00
commit cc017fc0b8
33 changed files with 1285 additions and 217 deletions

View file

@ -0,0 +1,21 @@
/* 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/. */
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#client
// [Exposed=ServiceWorker]
[Pref="dom.serviceworker.enabled"]
interface Client {
readonly attribute USVString url;
readonly attribute FrameType frameType;
readonly attribute DOMString id;
//void postMessage(any message, optional sequence<Transferable> transfer);
};
enum FrameType {
"auxiliary",
"top-level",
"nested",
"none"
};

View file

@ -31,6 +31,11 @@ interface NavigatorBluetooth {
readonly attribute Bluetooth bluetooth;
};
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#navigator-service-worker
partial interface Navigator {
[SameObject, Pref="dom.serviceworker.enabled"] readonly attribute ServiceWorkerContainer serviceWorker;
};
// https://html.spec.whatwg.org/multipage/#navigatorlanguage
[NoInterfaceObject/*, Exposed=Window,Worker*/]
interface NavigatorLanguage {

View file

@ -0,0 +1,25 @@
/* 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/. */
// http://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-obj
//[Exposed=(Window,Worker)]
[Pref="dom.serviceworker.enabled"]
interface ServiceWorker : EventTarget {
readonly attribute USVString scriptURL;
readonly attribute ServiceWorkerState state;
//[Throws] void postMessage(any message/*, optional sequence<Transferable> transfer*/);
// event
attribute EventHandler onstatechange;
};
ServiceWorker implements AbstractWorker;
enum ServiceWorkerState {
"installing",
"installed",
"activating",
"activated",
"redundant"
};

View file

@ -0,0 +1,27 @@
/* 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/. */
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-container
// [Exposed=(Window,Worker)]
[Pref="dom.serviceworker.enabled"]
interface ServiceWorkerContainer : EventTarget {
[Unforgeable] readonly attribute ServiceWorker? controller;
//[SameObject] readonly attribute Promise<ServiceWorkerRegistration> ready;
[NewObject, Throws] ServiceWorkerRegistration register(USVString scriptURL, optional RegistrationOptions options);
//[NewObject] /*Promise<any>*/ any getRegistration(optional USVString clientURL = "");
//[NewObject] /* Promise */<sequence<ServiceWorkerRegistration>> getRegistrations();
// events
//attribute EventHandler oncontrollerchange;
//attribute EventHandler onerror;
//attribute EventHandler onmessage; // event.source of message events is ServiceWorker object
};
dictionary RegistrationOptions {
USVString scope;
//WorkerType type = "classic";
};

View file

@ -0,0 +1,23 @@
/* 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/. */
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-global-scope
[Global, Pref="dom.serviceworker.enabled"/*=(Worker,ServiceWorker), Exposed=ServiceWorker*/]
interface ServiceWorkerGlobalScope : WorkerGlobalScope {
// A container for a list of Client objects that correspond to
// browsing contexts (or shared workers) that are on the origin of this SW
//[SameObject] readonly attribute Clients clients;
//[SameObject] readonly attribute ServiceWorkerRegistration registration;
//[NewObject] Promise<void> skipWaiting();
//attribute EventHandler oninstall;
//attribute EventHandler onactivate;
//attribute EventHandler onfetch;
//attribute EventHandler onforeignfetch;
// event
attribute EventHandler onmessage; // event.source of the message events is Client object
};

View file

@ -0,0 +1,20 @@
/* 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/. */
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#service-worker-registration-obj
//[Exposed=(Window,Worker)]
[Pref="dom.serviceworker.enabled"]
interface ServiceWorkerRegistration : EventTarget {
[Unforgeable] readonly attribute ServiceWorker? installing;
[Unforgeable] readonly attribute ServiceWorker? waiting;
[Unforgeable] readonly attribute ServiceWorker? active;
readonly attribute USVString scope;
// [NewObject] Promise<void> update();
// [NewObject] Promise<boolean> unregister();
// event
// attribute EventHandler onupdatefound;
};