OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('indexeddb', function() { | 5 cr.define('indexeddb', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 function initialize() { | 8 function initialize() { |
9 chrome.send('getAllOrigins'); | 9 chrome.send('getAllOrigins'); |
10 } | 10 } |
11 | 11 |
12 function onOriginsReady(origins, path) { | 12 function progressNodeFor(link) { |
| 13 return link.parentNode.querySelector('.download-status'); |
| 14 } |
| 15 |
| 16 function downloadOriginData(event) { |
| 17 var link = event.target; |
| 18 progressNodeFor(link).style.display = 'inline'; |
| 19 chrome.send('downloadOriginData', [link.idb_partition_path, |
| 20 link.idb_origin_url]); |
| 21 return false; |
| 22 } |
| 23 |
| 24 // Fired from the backend after the data has been zipped up, and the |
| 25 // download manager has begun downloading the file. |
| 26 function onOriginDownloadReady(partition_path, origin_url) { |
| 27 var downloadLinks = document.querySelectorAll('a.download'); |
| 28 for (var i = 0; i < downloadLinks.length; ++i) { |
| 29 var link = downloadLinks[i]; |
| 30 if (partition_path == link.idb_partition_path && |
| 31 origin_url == link.idb_origin_url) { |
| 32 progressNodeFor(link).style.display = 'none'; |
| 33 } |
| 34 } |
| 35 } |
| 36 |
| 37 // Fired from the backend with a single partition's worth of |
| 38 // IndexedDB metadata. |
| 39 function onOriginsReady(origins, partition_path) { |
13 var template = jstGetTemplate('indexeddb-list-template'); | 40 var template = jstGetTemplate('indexeddb-list-template'); |
14 var container = $('indexeddb-list'); | 41 var container = $('indexeddb-list'); |
15 container.appendChild(template); | 42 container.appendChild(template); |
16 jstProcess(new JsEvalContext({ idbs: origins, path: path}), template); | 43 jstProcess(new JsEvalContext({ idbs: origins, |
| 44 partition_path: partition_path}), template); |
| 45 |
| 46 var downloadLinks = container.querySelectorAll('a.download'); |
| 47 for (var i = 0; i < downloadLinks.length; ++i) { |
| 48 downloadLinks[i].addEventListener('click', downloadOriginData, false); |
| 49 } |
17 } | 50 } |
18 | 51 |
19 return { | 52 return { |
20 initialize: initialize, | 53 initialize: initialize, |
21 onOriginsReady: onOriginsReady, | 54 onOriginDownloadReady: onOriginDownloadReady, |
| 55 onOriginsReady: onOriginsReady, |
22 }; | 56 }; |
23 }); | 57 }); |
24 | 58 |
25 document.addEventListener('DOMContentLoaded', indexeddb.initialize); | 59 document.addEventListener('DOMContentLoaded', indexeddb.initialize); |
OLD | NEW |