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
3 // found in the LICENSE file.
5 cr.define('indexeddb', function() {
8 function initialize() {
9 chrome.send('getAllOrigins');
12 function progressNodeFor(link) {
13 return link.parentNode.querySelector('.download-status');
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]);
24 function forceClose(event) {
25 var link = event.target;
26 progressNodeFor(link).style.display = 'inline';
27 chrome.send('forceClose', [link.idb_partition_path,
28 link.idb_origin_url]);
32 function withNode(selector, partition_path, origin_url, callback) {
33 var links = document.querySelectorAll(selector);
34 for (var i = 0; i < links.length; ++i) {
36 if (partition_path == link.idb_partition_path &&
37 origin_url == link.idb_origin_url) {
42 // Fired from the backend after the data has been zipped up, and the
43 // download manager has begun downloading the file.
44 function onOriginDownloadReady(partition_path, origin_url, connection_count) {
45 withNode('a.download', partition_path, origin_url, function(link) {
46 progressNodeFor(link).style.display = 'none';
48 withNode('.connection-count', partition_path, origin_url, function(span) {
49 span.innerText = connection_count;
53 function onForcedClose(partition_path, origin_url, connection_count) {
54 withNode('a.force-close', partition_path, origin_url, function(link) {
55 progressNodeFor(link).style.display = 'none';
57 withNode('.connection-count', partition_path, origin_url, function(span) {
58 span.innerText = connection_count;
62 // Fired from the backend with a single partition's worth of
63 // IndexedDB metadata.
64 function onOriginsReady(origins, partition_path) {
65 var template = jstGetTemplate('indexeddb-list-template');
66 var container = $('indexeddb-list');
67 container.appendChild(template);
68 jstProcess(new JsEvalContext({ idbs: origins,
69 partition_path: partition_path}), template);
71 var downloadLinks = container.querySelectorAll('a.download');
72 for (var i = 0; i < downloadLinks.length; ++i) {
73 downloadLinks[i].addEventListener('click', downloadOriginData, false);
75 var forceCloseLinks = container.querySelectorAll('a.force-close');
76 for (i = 0; i < forceCloseLinks.length; ++i) {
77 forceCloseLinks[i].addEventListener('click', forceClose, false);
82 initialize: initialize,
83 onForcedClose: onForcedClose,
84 onOriginDownloadReady: onOriginDownloadReady,
85 onOriginsReady: onOriginsReady,
89 document.addEventListener('DOMContentLoaded', indexeddb.initialize);