Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/clients-get-worker.js

Issue 1439333002: Service Worker: Add Clients.get(id) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unnecessary condition Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 self.onfetch = function(e) {
2 if (e.request.url.indexOf('clients-get-frame.html') >= 0) {
3 // On navigation, the client id should be null.
4 if (e.clientId === null) {
5 e.respondWith(fetch(e.request));
6 } else {
7 e.respondWith(Response.error());
8 }
9 return;
10 }
11 e.respondWith(new Response(e.clientId));
12 };
13
14 self.onmessage = function(e) {
15 var port = e.data.port;
16 var client_ids = e.data.clientIds;
17 var message = [];
18
19 e.waitUntil(Promise.all(
20 client_ids.map(function(client_id) {
21 return self.clients.get(client_id);
22 }))
23 .then(function(clients) {
24 // No matching client for a given id or a matched client is off-origin
25 // from the service worker.
26 if (clients.length == 1 && clients[0] == undefined) {
27 port.postMessage(clients[0]);
28 } else {
29 clients.forEach(function(client) {
30 if (client instanceof Client) {
31 message.push([client.visibilityState,
32 client.focused,
33 client.url,
34 client.frameType]);
35 } else {
36 message.push(client);
37 }
38 });
39 port.postMessage(message);
40 }
41 }));
42 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698