Chromium Code Reviews| Index: chrome/browser/resources/offline_pages/offline_internals.js |
| diff --git a/chrome/browser/resources/offline_pages/offline_internals.js b/chrome/browser/resources/offline_pages/offline_internals.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5b914782f0acfc283ac35f3056024ab499afcef4 |
| --- /dev/null |
| +++ b/chrome/browser/resources/offline_pages/offline_internals.js |
| @@ -0,0 +1,168 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +cr.define('offlineInternals', function() { |
| + 'use strict'; |
| + |
| + /** |
| + * @typedef {{ |
| + * onlineUrl: string, |
| + * creationTime: number, |
| + * status: number, |
| + * id: string, |
| + * namespace: string, |
| + * size: string, |
| + * filePath: string, |
| + * lastAccessTime: number, |
| + * accessCount: number |
| + * }} |
| + */ |
| + var OfflinePageItem; |
|
Dan Beam
2016/06/03 23:27:24
i highly recommend you add a compiled_resources2.g
chili
2016/06/06 18:11:58
If possible, I'd like to push that until the next
|
| + |
| + /** |
| + * @typedef {{ |
| + * status: string, |
| + * onlineUrl: string, |
| + * creationTime: number, |
| + * id: string, |
| + * namespace: string, |
| + * attemptCount: number |
| + * }} |
| + */ |
| + var SavePageRequest; |
| + |
| + /** |
| + * Clear the specified table. |
| + * @param {string} tableId id of the table to clear. |
| + */ |
| + function clearTable(tableId) { |
| + $(tableId).textContent = ''; |
| + } |
| + |
| + /** |
| + * Fill stored pages table. |
| + * @param {HTMLElement} element A HTML element. |
| + * @param {!Array<OfflinePageItem>} data An array object representing |
| + * stored offline pages. |
| + */ |
| + function fillStoredPages(element, data) { |
|
Dan Beam
2016/06/03 23:27:24
nit: data -> pages
chili
2016/06/06 18:11:58
Done.
|
| + for (var i = 0; i < data.length; i++) { |
| + var row = document.createElement('tr'); |
| + |
| + var checkboxCell = document.createElement('td'); |
| + var checkbox = document.createElement('input'); |
| + checkbox.setAttribute('type', 'checkbox'); |
| + checkbox.setAttribute('name', 'stored'); |
| + checkbox.setAttribute('value', data[i].id); |
| + |
| + checkboxCell.appendChild(checkbox); |
| + row.appendChild(checkboxCell); |
| + |
| + var cell = document.createElement('td'); |
| + cell.textContent = data[i].onlineUrl; |
| + row.appendChild(cell); |
| + |
| + cell = document.createElement('td'); |
| + cell.textContent = data[i].namespace; |
| + row.appendChild(cell); |
| + |
| + cell = document.createElement('td'); |
| + cell.textContent = data[i].size; |
| + row.appendChild(cell); |
| + |
| + element.appendChild(row); |
| + } |
| + } |
| + |
| + /** |
| + * Fill requests table. |
| + * @param {HTMLElement} element A HTML element. |
| + * @param {!Array<SavePageRequest>} data An array object representing |
| + * the request queue. |
| + */ |
| + function fillRequestQueue(element, data) { |
|
Dan Beam
2016/06/03 23:27:24
nit: data -> requests
chili
2016/06/06 18:11:58
Done.
|
| + for (var i = 0; i < data.length; i++) { |
| + var row = document.createElement('tr'); |
| + |
| + var cell = document.createElement('td'); |
| + cell.textContent = data[i].onlineUrl; |
| + row.appendChild(cell); |
| + |
| + cell = document.createElement('td'); |
| + cell.textContent = new Date(data[i].creationTime); |
| + row.appendChild(cell); |
| + |
| + cell = document.createElement('td'); |
| + cell.textContent = data[i].status; |
| + row.appendChild(cell); |
| + |
| + element.appendChild(row); |
| + } |
| + } |
| + |
| + /** |
| + * Refresh all displayed information. |
| + */ |
| + function refreshAll() { |
| + cr.sendWithPromise('getOfflineInternalsInfo').then(setOfflineInternalsInfo); |
| + } |
| + |
| + /** |
| + * Delete all pages in the offline store. |
| + */ |
| + function deleteAllPages() { |
| + cr.sendWithPromise('deleteAllPages').then(pagesDeleted); |
| + } |
| + |
| + /** |
| + * Callback when pages are deleted. |
| + * @param {string} deletePageStatus The status of delete page call. |
| + */ |
| + function pagesDeleted(deletePageStatus) { |
| + // TODO(chili): decide what to do here. Perhaps a refresh of just |
| + // the stored pages table? |
| + } |
| + |
| + /** |
| + * Callback when information is loaded. |
| + * @param {{AllPages: !Array<OfflinePageItem>, |
| + * Queue: !Array<SavePageRequest>}} info An object containing both |
| + * stored pages and request queue status. |
| + */ |
| + function setOfflineInternalsInfo(info) { |
| + clearTable('stored-pages'); |
| + clearTable('request-queue'); |
| + |
| + fillStoredPages($('stored-pages'), info.AllPages); |
| + fillRequestQueue($('request-queue'), info.Queue); |
| + } |
| + |
| + /** |
| + * Delete selected pages from the offline store. |
| + */ |
| + function deleteSelectedPages() { |
| + var checkboxes = document.getElementsByName('stored'); |
| + var selectedIds = []; |
| + for (var checkbox of checkboxes) { |
| + if (checkbox.checked) |
| + selectedIds.push(checkbox.value); |
| + } |
| + |
| + cr.sendWithPromise('deleteSelectedPages', selectedIds).then(pagesDeleted); |
| + } |
| + |
| + function initialize() { |
| + $('clear-all').onclick = deleteAllPages; |
| + $('clear-selected').onclick = deleteSelectedPages; |
| + $('refresh').onclick = refreshAll; |
| + refreshAll(); |
| + } |
| + |
| + // Return an object with all of the exports. |
| + return { |
| + initialize: initialize, |
| + }; |
| +}); |
| + |
| +document.addEventListener('DOMContentLoaded', offlineInternals.initialize); |