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

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..704c0f7d190d33f715e8b866610c2c4d5d6ae9d7
--- /dev/null
+++ b/chrome/browser/resources/offline_pages/offline_internals.js
@@ -0,0 +1,149 @@
+// 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'];
Dan Beam 2016/05/26 00:54:39 nit: FINAL_CONST_LIKE_THIS (i.e. STORED_PAGE_ATTRI
chili 2016/05/27 01:36:59 Done.
+ var queueAttributes = ['onlineUrl', 'creation time', 'status'];
+
+ /**
+ * Remove all the child nodes of the element.
+ * @param {HTMLElement} element A HTML element
+ */
+ function clearChildren(element) {
+ element.textContent = '';
+ }
+
+ /**
+ * Clear the specified table.
+ */
+ function clearTable(tableId) {
+ var element = $(tableId);
+ if (!element)
+ return;
Dan Beam 2016/05/26 00:54:39 shouldn't this blow up because of programmer error
chili 2016/05/27 01:36:59 I've removed the checks. Not sure what you mean b
+
+ clearChildren(element);
+ }
+
+ /**
+ * Fill stored pages table.
+ * @param {HTMLElement} element A HTML element
+ * @param {Object} data An array object representing stored offline pages
+ */
+ function fillStoredPages(element, data) {
+ if (!element) {
Dan Beam 2016/05/26 00:54:39 nit: no curlies around 1-line conditionals
Dan Beam 2016/05/26 00:54:39 when should this validly just return?
chili 2016/05/27 01:36:59 Acknowledged.
chili 2016/05/27 01:36:59 Done.
+ 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 keyIndex = 0;
+ keyIndex < storedPagesAttributes.length;
+ keyIndex++) {
Dan Beam 2016/05/26 00:54:39 i don't know if this runs on iOS (or if the linter
chili 2016/05/27 01:36:59 offline stuff is only available on android. trying
+ var cell = document.createElement('td');
+ cell.textContent = data[i][storedPagesAttributes[keyIndex]];
+ row.appendChild(cell);
+ }
+ element.appendChild(row);
+ }
+ }
+
+ /**
+ * Fill requests table.
+ * @param {HTMLElement} element A HTML element
+ * @param {Object} data An array object representing the request queue
Dan Beam 2016/05/26 00:54:39 Object -> !Array
chili 2016/05/27 01:36:59 Done.
+ */
+ function fillRequestQueue(element, data) {
+ if (!element) {
+ return;
+ }
+ for (var i = 0; i < data.length; i++) {
+ var row = document.createElement('tr');
+
+ for (var keyIndex = 0;
+ keyIndex < queueAttributes.length;
+ keyIndex++) {
+ var cell = document.createElement('td');
+ cell.textContent = data[i][queueAttributes[keyIndex]];
+ 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.
+ * @param {Object} info An object containing both stored pages and
Dan Beam 2016/05/26 00:54:39 it'd be useful to type this more strongly, i.e.
chili 2016/05/27 01:36:59 Done.
+ * 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 selectedIds = new Array();
+ $('input:checkbox[name=stored]:checked').each(function() {
+ selectedIds.push($(this).val());
Dan Beam 2016/05/26 00:54:39 $ is not jQuery
chili 2016/05/27 01:36:59 Darn :(
+ });
+ chrome.send('deleteSelectedPages', [selectedIds]);
+ }
+
+ /**
+ * Initializing everything.
Dan Beam 2016/05/26 00:54:39 is this comment useful?
chili 2016/05/27 01:36:59 Done.
+ */
+ 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