Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <script src="test-helpers.js?pipe=sub"></script> | 2 <script src="test-helpers.js?pipe=sub"></script> |
| 3 <script> | 3 <script> |
| 4 var SCOPE = 'fetch-mixed-content-iframe-inscope.html'; | 4 var SCOPE = 'fetch-mixed-content-iframe-inscope.html'; |
| 5 var URL = 'fetch-rewrite-worker.js'; | 5 var URL = 'fetch-rewrite-worker.js'; |
| 6 var host_info = get_host_info(); | 6 var host_info = get_host_info(); |
| 7 | 7 |
| 8 window.addEventListener('message', on_message, false); | 8 window.addEventListener('message', on_message, false); |
| 9 | 9 |
| 10 navigator.serviceWorker.getRegistration(SCOPE) | 10 navigator.serviceWorker.getRegistration(SCOPE) |
| 11 .then(function(registration) { | 11 .then(function(registration) { |
| 12 if (registration) | 12 if (registration) |
| 13 return registration.unregister(); | 13 return registration.unregister(); |
| 14 }) | 14 }) |
| 15 .then(function() { | 15 .then(function() { |
| 16 return navigator.serviceWorker.register(URL, {scope: SCOPE}); | 16 return navigator.serviceWorker.register(URL, {scope: SCOPE}); |
| 17 }) | 17 }) |
| 18 .then(function(registration) { | 18 .then(function(registration) { |
| 19 return new Promise(function(resolve) { | 19 return new Promise(function(resolve) { |
| 20 registration.addEventListener('updatefound', function() { | 20 registration.addEventListener('updatefound', function() { |
| 21 resolve(registration.installing); | 21 resolve(registration.installing); |
| 22 }); | 22 }); |
| 23 }); | 23 }); |
| 24 }) | 24 }) |
| 25 .then(function(worker) { | 25 .then(function(worker) { |
| 26 worker.addEventListener('statechange', on_state_change); | 26 worker.addEventListener('statechange', on_state_change); |
| 27 }); | 27 }) |
| 28 .catch(function(reason) { | |
| 29 window.parent.postMessage({results: 'FAILURE: ' + reason.message}, | |
| 30 host_info['HTTP_ORIGIN']); | |
| 31 }); | |
| 28 | 32 |
| 29 function on_state_change(event) { | 33 function on_state_change(event) { |
| 30 if (event.target.state != 'activated') | 34 if (event.target.state != 'activated') |
| 31 return; | 35 return; |
| 32 var frame = document.createElement('iframe'); | 36 var frame = document.createElement('iframe'); |
| 33 frame.src = SCOPE; | 37 frame.src = SCOPE; |
| 34 document.body.appendChild(frame); | 38 document.body.appendChild(frame); |
| 35 } | 39 } |
| 36 | 40 |
| 37 function on_message(e) { | 41 function on_message(e) { |
| 38 navigator.serviceWorker.getRegistration(SCOPE) | 42 navigator.serviceWorker.getRegistration(SCOPE) |
| 39 .then(function(registration) { | 43 .then(function(registration) { |
| 40 if (registration) | 44 if (registration) |
| 41 return registration.unregister(); | 45 return registration.unregister(); |
| 42 }) | 46 }) |
| 43 .then(function() { | 47 .then(function() { |
| 44 window.parent.postMessage(e.data, host_info['HTTP_ORIGIN']); | 48 window.parent.postMessage(e.data, host_info['HTTP_ORIGIN']); |
| 45 }); | 49 }) |
| 50 .catch(function(reason) { | |
| 51 window.parent.postMessage({results: 'FAILURE: ' + reason.message}, | |
| 52 host_info['HTTP_ORIGIN']); | |
|
falken
2014/10/24 06:54:54
Note that Promises can reject with anything, so .m
| |
| 53 }); | |
| 46 } | 54 } |
| 47 </script> | 55 </script> |
| OLD | NEW |