| OLD | NEW |
| 1 // Deep-copies the attributes of |notification|. Note that the | 1 // Deep-copies the attributes of |notification|. Note that the |
| 2 // robustness of this function (and also |assert_object_equals| in | 2 // robustness of this function (and also |assert_object_equals| in |
| 3 // testharness.js) affects the types of possible testing can be done. | 3 // testharness.js) affects the types of possible testing can be done. |
| 4 // TODO(peter): change this to a structured clone algorithm. | 4 // TODO(peter): change this to a structured clone algorithm. |
| 5 function cloneNotification(notification) { | 5 function cloneNotification(notification) { |
| 6 function deepCopy(src) { | 6 function deepCopy(src) { |
| 7 if (typeof src !== 'object' || src === null) | 7 if (typeof src !== 'object' || src === null) |
| 8 return src; | 8 return src; |
| 9 var dst = Array.isArray(src) ? [] : {}; | 9 var dst = Array.isArray(src) ? [] : {}; |
| 10 for (var property in src) { | 10 for (var property in src) { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if (event.notification.body.indexOf('ACTION:CLOSE') != -1) | 105 if (event.notification.body.indexOf('ACTION:CLOSE') != -1) |
| 106 event.notification.close(); | 106 event.notification.close(); |
| 107 | 107 |
| 108 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t | 108 // Notifications containing "ACTION:OPENWINDOW" in their message will attemp
t |
| 109 // to open a new window for an example URL. | 109 // to open a new window for an example URL. |
| 110 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) | 110 if (event.notification.body.indexOf('ACTION:OPENWINDOW') != -1) |
| 111 event.waitUntil(clients.openWindow('https://example.com/')); | 111 event.waitUntil(clients.openWindow('https://example.com/')); |
| 112 | 112 |
| 113 messagePort.postMessage({ command: 'click', | 113 messagePort.postMessage({ command: 'click', |
| 114 notification: notificationCopy, | 114 notification: notificationCopy, |
| 115 action: event.action }); | 115 action: event.action, |
| 116 reply: event.reply }); |
| 116 }); | 117 }); |
| 117 | 118 |
| 118 addEventListener('notificationclose', event => { | 119 addEventListener('notificationclose', event => { |
| 119 var notificationCopy = cloneNotification(event.notification); | 120 var notificationCopy = cloneNotification(event.notification); |
| 120 messagePort.postMessage({ command: 'close', | 121 messagePort.postMessage({ command: 'close', |
| 121 notification: notificationCopy }); | 122 notification: notificationCopy }); |
| 122 }); | 123 }); |
| 123 | 124 |
| 124 addEventListener('fetch', event => { | 125 addEventListener('fetch', event => { |
| 125 fetchHistory.push(event.request.url); | 126 fetchHistory.push(event.request.url); |
| 126 event.respondWith(fetch(event.request)); | 127 event.respondWith(fetch(event.request)); |
| 127 }); | 128 }); |
| OLD | NEW |