Implement the detailed progress values for Background Fetch

This updates our implementation with the recent spec changes. Notably:
  * BackgroundFetchRegistration gets an `onprogress` event.
  * `totalDownloadSize` has been renamed to `downloadTotal`.
  * `uploadTotal`, `uploaded` and `downloaded` were added to BGReg.

The old `totalDownloadSize` property has been kept as-is because there
are a few demos out there that depend on it. They'll be removed soon.

This CL only adjusts the Web exposed properties. In the next CL I'll add
the observer mechanism that will power the progress events, after which
we can make BackgroundFetchRegistration a live object and ensure that
there's only one instance of it for a given execution context.

BUG=768273

Change-Id: I9a31f69441909e6cf41a63a3a50b6e31a8a1c574
Reviewed-on: https://chromium-review.googlesource.com/690160
Commit-Queue: Peter Beverloo <peter@chromium.org>
Reviewed-by: John Mellor <johnme@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505604}
diff --git a/background-fetch/interfaces.idl b/background-fetch/interfaces.idl
index d8b2fed..77cdfff 100644
--- a/background-fetch/interfaces.idl
+++ b/background-fetch/interfaces.idl
@@ -1,10 +1,19 @@
-// 3.1. Extensions to ServiceWorkerRegistration
+// 4.1. Extensions to ServiceWorkerGlobalScope
+
+partial interface ServiceWorkerGlobalScope {
+  attribute EventHandler onbackgroundfetched;
+  attribute EventHandler onbackgroundfetchfail;
+  attribute EventHandler onbackgroundfetchabort;
+  attribute EventHandler onbackgroundfetchclick;
+};
+
+// 4.2. Extensions to ServiceWorkerRegistration
 
 partial interface ServiceWorkerRegistration {
   readonly attribute BackgroundFetchManager backgroundFetch;
 };
 
-// 3.2. BackgroundFetchManager
+// 4.3. BackgroundFetchManager
 
 [Exposed=(Window,Worker)]
 interface BackgroundFetchManager {
@@ -17,7 +26,7 @@
 dictionary BackgroundFetchOptions {
   sequence<IconDefinition> icons;
   DOMString title;
-  long totalDownloadSize;
+  unsigned long long downloadTotal;
 };
 
 // This is taken from https://w3c.github.io/manifest/#icons-member.
@@ -28,40 +37,40 @@
   DOMString type;
 };
 
-// 3.3. BackgroundFetchRegistration
+// 4.4. BackgroundFetchRegistration
 
 [Exposed=(Window,Worker)]
-interface BackgroundFetchRegistration {
+interface BackgroundFetchRegistration : EventTarget {
   readonly attribute DOMString id;
-  readonly attribute FrozenArray<IconDefinition> icons;
-  readonly attribute long totalDownloadSize;
-  readonly attribute DOMString title;
-  readonly attribute FrozenArray<BackgroundFetchActiveFetches> fetches;
+  readonly attribute unsigned long long uploadTotal;
+  readonly attribute unsigned long long uploaded;
+  readonly attribute unsigned long long downloadTotal;
+  readonly attribute unsigned long long downloaded;
+  readonly attribute BackgroundFetchActiveFetches activeFetches;
 
-  void abort();
+  attribute EventHandler onprogress;
+
+  Promise<boolean> abort();
 };
 
 [Exposed=(Window,Worker)]
-interface BackgroundFetchFetches {
+interface BackgroundFetchFetch {
   readonly attribute Request request;
 };
 
 [Exposed=(Window,Worker)]
-interface BackgroundFetchActiveFetches : BackgroundFetchFetches {
+interface BackgroundFetchActiveFetches {
+  Promise<BackgroundFetchActiveFetch> match(RequestInfo request);
+  Promise<FrozenArray<BackgroundFetchActiveFetch>> values();
+};
+
+[Exposed=(Window,Worker)]
+interface BackgroundFetchActiveFetch : BackgroundFetchFetch {
   readonly attribute Promise<Response> responseReady;
-  // TODO: this will include fetch controller/observer objects
+  // In future this will include a fetch observer
 };
 
-// 3.4. Events
-
-partial interface ServiceWorkerGlobalScope {
-  attribute EventHandler onbackgroundfetched;
-  attribute EventHandler onbackgroundfetchfail;
-  attribute EventHandler onbackgroundfetchabort;
-  attribute EventHandler onbackgroundfetchclick;
-};
-
-// 3.4.1. BackgroundFetchEvent
+// 4.4.3. BackgroundFetchEvent
 
 [Constructor(DOMString type, BackgroundFetchEventInit init), Exposed=ServiceWorker]
 interface BackgroundFetchEvent : ExtendableEvent {
@@ -72,38 +81,38 @@
   required DOMString id;
 };
 
-// 3.4.2. BackgroundFetchEndEvent
+// 4.4.4. BackgroundFetchSettledEvent
 
-[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
-interface BackgroundFetchEndEvent : BackgroundFetchEvent {
-  readonly attribute FrozenArray<BackgroundFetchSettledFetches> completeFetches;
-
-  Promise<void> updateUI(DOMString title);
+[Constructor(DOMString type, BackgroundFetchSettledEventInit init), Exposed=ServiceWorker]
+interface BackgroundFetchSettledEvent : BackgroundFetchEvent {
+  readonly attribute BackgroundFetchSettledFetches fetches;
 };
 
-dictionary BackgroundFetchEndEventInit : BackgroundFetchEventInit {
-  required BackgroundFetchSettledFetches completeFetches;
+dictionary BackgroundFetchSettledEventInit : BackgroundFetchEventInit {
+  required BackgroundFetchSettledFetches fetches;
 };
 
 [Exposed=ServiceWorker]
-interface BackgroundFetchSettledFetches : BackgroundFetchFetches {
+interface BackgroundFetchSettledFetches {
+  Promise<BackgroundFetchSettledFetch> match(RequestInfo request);
+  Promise<FrozenArray<BackgroundFetchSettledFetch>> values();
+};
+
+[Exposed=ServiceWorker]
+interface BackgroundFetchSettledFetch : BackgroundFetchFetch {
   readonly attribute Response? response;
 };
 
-// 3.4.3. BackgroundFetchFailEvent
+// 4.4.5. BackgroundFetchUpdateEvent
 
-[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
-interface BackgroundFetchFailEvent : BackgroundFetchEndEvent {
-  readonly attribute FrozenArray<BackgroundFetchSettledFetches> failedFetches;
+[Constructor(DOMString type, BackgroundFetchSettledEventInit init), Exposed=ServiceWorker]
+interface BackgroundFetchUpdateEvent : BackgroundFetchSettledEvent {
+  Promise<void> updateUI(DOMString title);
 };
 
-dictionary BackgroundFetchFailEventInit : BackgroundFetchEndEventInit {
-  required BackgroundFetchSettledFetches failedFetches;
-};
+// 4.4.6. BackgroundFetchClickEvent
 
-// 3.4.4. BackgroundFetchClickEvent
-
-[Constructor(DOMString type, BackgroundFetchEndEventInit init), Exposed=ServiceWorker]
+[Constructor(DOMString type, BackgroundFetchClickEventInit init), Exposed=ServiceWorker]
 interface BackgroundFetchClickEvent : BackgroundFetchEvent {
   readonly attribute BackgroundFetchState state;
 };
diff --git a/background-fetch/interfaces.worker.js b/background-fetch/interfaces.worker.js
index d3145b9..a5fc4ed 100644
--- a/background-fetch/interfaces.worker.js
+++ b/background-fetch/interfaces.worker.js
@@ -14,3 +14,5 @@
       idlArray.test();
     });
 }, 'Exposed interfaces in a Service Worker.');
+
+done();