Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5801)

Unified Diff: chrome/browser/resources/offline_pages/offline_internals.js

Issue 2003883002: [Offline pages] Create offline internals page for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..2aeb6ac036e5cfbf4e26df595b70f59ea844332a
--- /dev/null
+++ b/chrome/browser/resources/offline_pages/offline_internals.js
@@ -0,0 +1,139 @@
+// 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';
+
+ var storedPagesAttributes = ['onlineUrl', 'namespace', 'size'];
+ var queueAttributes = ['onlineUrl', 'creation time', 'status'];
+
+ /**
+ * Remove all the child nodes of the element.
+ * @param {HTMLElement} element A HTML element
dewittj 2016/05/25 20:08:45 Is this being compiled by closure compiler? I rec
chili 2016/05/25 20:22:55 Done.
+ */
+ function clearChildren(element) {
+ element.textContent = '';
+ }
+
+ /**
+ * Clear the specified table.
+ */
+ function clearTable(tableId) {
+ var element = $(tableId);
+ if (!element)
+ return;
+
+ clearChildren(element);
+ }
+
+ /**
+ * Fill stored pages table.
+ */
+ function fillStoredPages(element, data) {
+ if (!element) {
+ return;
+ }
+ 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);
+
+ for (var key in storedPagesAttributes) {
+ var cell = document.createElement('td');
+ cell.textContent = data[i][key];
+ row.appendChild(cell);
+ }
+ element.appendChild(row);
+ }
+ }
+
+ /**
+ * Fill requests table.
+ */
+ function fillRequestQueue(element, data) {
+ if (!element) {
+ return;
+ }
+ for (var i = 0; i < data.length; i++) {
+ var row = document.createElement('tr');
+
+ for (var key in queueAttributes) {
dewittj 2016/05/25 20:08:44 I don't like using var..in loops for arrays, since
chili 2016/05/25 20:22:55 Data is actually of type List<Map<String, Object>>
dewittj 2016/05/25 20:30:13 What I'm trying to say is that you already should
chili 2016/05/25 20:52:18 Ah. I misunderstood your comment. Yes, I overlook
+ var cell = document.createElement('td');
+ cell.textContent = data[i][key];
+ row.appendChild(cell);
+ }
+ element.appendChild(row);
+ }
+ }
+
+ /**
+ * Refresh all displayed information.
+ */
+ function refreshAll() {
+ chrome.send('getOfflineInternalsInfo');
+ }
+
+ /**
+ * Delete all pages in the offline store.
+ */
+ function deleteAllPages() {
+ chrome.send('deleteAllPages');
+ }
+
+ /**
+ * Callback when pages are deleted.
+ */
+ function pagesDeleted() {
+ // TODO(chili): decide what to do here. Perhaps a refresh of just
+ // the stored pages table?
+ }
+
+ /**
+ * Callback when information is loaded.
+ */
+ 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 selectedIds = new Array();
+ $('input:checkbox[name=stored]:checked').each(function() {
+ selectedIds.push($(this).val());
+ });
+ chrome.send('deleteSelectedPages', [selectedIds]);
+ }
+
+ /**
+ * Initializing everything.
+ */
+ function initialize() {
+ $('clear-all').onclick = deleteAllPages;
+ $('clear-selected').onClick = deleteSelectedPages;
+ $('refresh').onclick = refreshAll;
+ chrome.send('getOfflineInternalsInfo');
+ }
+
+ // Return an object with all of the exports.
+ return {
+ initialize: initialize,
+ setOfflineInternalsInfo: setOfflineInternalsInfo,
+ pagesDeleted: pagesDeleted
+ };
+});
+
+document.addEventListener('DOMContentLoaded', offlineInternals.initialize);

Powered by Google App Engine
This is Rietveld 408576698