OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function setupMessageHandler() { |
| 6 window.onmessage = function(e) { |
| 7 if (e.data.command === 'start-download') { |
| 8 console.log("Start Download received for URL " + e.data.url); |
| 9 var anchor = document.createElement('a'); |
| 10 anchor.href = e.data.url; |
| 11 anchor.download = 'foo'; |
| 12 document.getElementById('container').appendChild(anchor); |
| 13 anchor.click(); |
| 14 } |
| 15 }; |
| 16 } |
| 17 |
| 18 function setCookiesBasedOnURLFragment() { |
| 19 var cookieValue = window.location.hash.substr(1); |
| 20 var expiresOn = new Date(); |
| 21 expiresOn.setMonth(expiresOn.getMonth() + 1); |
| 22 cookieValue += ";path=/"; |
| 23 cookieValue += ";expires=" + expiresOn.toUTCString(); |
| 24 document.cookie = cookieValue; |
| 25 console.log("Setting cookie: " + cookieValue); |
| 26 } |
| 27 |
| 28 window.onload = function() { |
| 29 setCookiesBasedOnURLFragment(); |
| 30 setupMessageHandler(); |
| 31 } |
OLD | NEW |