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

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.
dewittj 2016/05/25 21:03:50 I think you have not added this to compiled resour
+// 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
+ */
+ function clearChildren(element) {
+ element.textContent = '';
+ }
+
+ /**
+ * Clear the specified table.
+ */
+ function clearTable(tableId) {
+ var element = $(tableId);
+ if (!element)
+ return;
+
+ clearChildren(element);
+ }
+
+ /**
+ * Fill stored pages table.
+ * @param {HTMLElement} element A HTML element
dewittj 2016/05/25 21:03:50 @param {?HTMLElement} if nullable, does $() return
+ * @param {Object} data An array object representing stored offline pages
dewittj 2016/05/25 21:03:50 If i understand data right, this should be: @para
+ */
+ 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 keyIndex = 0;
+ keyIndex < storedPagesAttributes.length;
+ keyIndex++) {
+ 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
+ */
+ 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
+ * 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());
+ });
+ 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