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

Side by Side Diff: chrome/browser/resources/offline_pages/offline_internals.js

Issue 2328973003: Adds a delete button to chrome:offline-internals (Closed)
Patch Set: CR feedback per BauerB Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('offlineInternals', function() { 5 cr.define('offlineInternals', function() {
6 'use strict'; 6 'use strict';
7 7
8 /** @type {!Array<OfflinePage>} */ 8 /** @type {!Array<OfflinePage>} */
9 var offlinePages = []; 9 var offlinePages = [];
10 10
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 * @param {!Array<SavePageRequest>} requests An array object representing 65 * @param {!Array<SavePageRequest>} requests An array object representing
66 * the request queue. 66 * the request queue.
67 */ 67 */
68 function fillRequestQueue(requests) { 68 function fillRequestQueue(requests) {
69 var requestQueueTable = $('request-queue'); 69 var requestQueueTable = $('request-queue');
70 requestQueueTable.textContent = ''; 70 requestQueueTable.textContent = '';
71 71
72 for (var i = 0; i < requests.length; i++) { 72 for (var i = 0; i < requests.length; i++) {
73 var row = document.createElement('tr'); 73 var row = document.createElement('tr');
74 74
75 var checkboxCell = document.createElement('td');
76 var checkbox = document.createElement('input');
77 checkbox.setAttribute('type', 'checkbox');
78 checkbox.setAttribute('name', 'requests');
79 checkbox.setAttribute('value', requests[i].id);
80
81 checkboxCell.appendChild(checkbox);
82 row.appendChild(checkboxCell);
83
75 var cell = document.createElement('td'); 84 var cell = document.createElement('td');
76 cell.textContent = requests[i].onlineUrl; 85 cell.textContent = requests[i].onlineUrl;
77 row.appendChild(cell); 86 row.appendChild(cell);
78 87
79 cell = document.createElement('td'); 88 cell = document.createElement('td');
80 cell.textContent = new Date(requests[i].creationTime); 89 cell.textContent = new Date(requests[i].creationTime);
81 row.appendChild(cell); 90 row.appendChild(cell);
82 91
83 cell = document.createElement('td'); 92 cell = document.createElement('td');
84 cell.textContent = requests[i].status; 93 cell.textContent = requests[i].status;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 125 }
117 126
118 /** 127 /**
119 * Delete all pages in the offline store. 128 * Delete all pages in the offline store.
120 */ 129 */
121 function deleteAllPages() { 130 function deleteAllPages() {
122 browserProxy_.deleteAllPages().then(pagesDeleted); 131 browserProxy_.deleteAllPages().then(pagesDeleted);
123 } 132 }
124 133
125 /** 134 /**
135 * Delete all pending SavePageRequest items in the request queue.
136 */
137 function deleteAllRequests() {
138 browserProxy_.deleteAllRequests().then(requestsDeleted);
139 }
140
141 /**
126 * Callback when pages are deleted. 142 * Callback when pages are deleted.
127 * @param {string} status The status of the request. 143 * @param {string} status The status of the request.
128 */ 144 */
129 function pagesDeleted(status) { 145 function pagesDeleted(status) {
130 $('page-actions-info').textContent = status; 146 $('page-actions-info').textContent = status;
131 browserProxy_.getStoredPages().then(fillStoredPages); 147 browserProxy_.getStoredPages().then(fillStoredPages);
132 } 148 }
133 149
134 /** 150 /**
151 * Callback when requests are deleted.
152 */
153 function requestsDeleted(status) {
154 $('request-queue-actions-info').textContent = status;
155 browserProxy_.getRequestQueue().then(fillRequestQueue);
156 }
157
158 /**
135 * Downloads all the stored page and request queue information into a file. 159 * Downloads all the stored page and request queue information into a file.
136 * TODO(chili): Create a CSV writer that can abstract out the line joining. 160 * TODO(chili): Create a CSV writer that can abstract out the line joining.
137 */ 161 */
138 function download() { 162 function download() {
139 var json = JSON.stringify({ 163 var json = JSON.stringify({
140 offlinePages: offlinePages, 164 offlinePages: offlinePages,
141 savePageRequests: savePageRequests 165 savePageRequests: savePageRequests
142 }, null, 2); 166 }, null, 2);
143 167
144 window.open( 168 window.open(
(...skipping 19 matching lines...) Expand all
164 188
165 for (var i = 0; i < checkboxes.length; i++) { 189 for (var i = 0; i < checkboxes.length; i++) {
166 if (checkboxes[i].checked) 190 if (checkboxes[i].checked)
167 selectedIds.push(checkboxes[i].value); 191 selectedIds.push(checkboxes[i].value);
168 } 192 }
169 193
170 browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted); 194 browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted);
171 } 195 }
172 196
173 /** 197 /**
198 * Delete selected SavePageRequest items from the request queue.
199 */
200 function deleteSelectedRequests() {
201 var checkboxes = document.getElementsByName('requests');
202 var selectedIds = [];
203
204 for (var i = 0; i < checkboxes.length; i++) {
205 if (checkboxes[i].checked)
206 selectedIds.push(checkboxes[i].value);
207 }
208
209 browserProxy_.deleteSelectedRequests(selectedIds).then(requestsDeleted);
210 }
211
212 /**
174 * Refreshes the logs. 213 * Refreshes the logs.
175 */ 214 */
176 function refreshLog() { 215 function refreshLog() {
177 browserProxy_.getEventLogs().then(fillEventLog); 216 browserProxy_.getEventLogs().then(fillEventLog);
178 browserProxy_.getLoggingState().then(updateLogStatus); 217 browserProxy_.getLoggingState().then(updateLogStatus);
179 } 218 }
180 219
181 function initialize() { 220 function initialize() {
182 /** 221 /**
183 * @param {!boolean} enabled Whether to enable Logging. 222 * @param {!boolean} enabled Whether to enable Logging.
184 */ 223 */
185 function togglePageModelLog(enabled) { 224 function togglePageModelLog(enabled) {
186 browserProxy_.setRecordPageModel(enabled); 225 browserProxy_.setRecordPageModel(enabled);
187 $('model-status').textContent = enabled ? 'On' : 'Off'; 226 $('model-status').textContent = enabled ? 'On' : 'Off';
188 } 227 }
189 228
190 /** 229 /**
191 * @param {!boolean} enabled Whether to enable Logging. 230 * @param {!boolean} enabled Whether to enable Logging.
192 */ 231 */
193 function toggleRequestQueueLog(enabled) { 232 function toggleRequestQueueLog(enabled) {
194 browserProxy_.setRecordRequestQueue(enabled); 233 browserProxy_.setRecordRequestQueue(enabled);
195 $('request-status').textContent = enabled ? 'On' : 'Off'; 234 $('request-status').textContent = enabled ? 'On' : 'Off';
196 } 235 }
197 236
198 var incognito = loadTimeData.getBoolean('isIncognito'); 237 var incognito = loadTimeData.getBoolean('isIncognito');
199 $('clear-all').disabled = incognito; 238 $('clear-all').disabled = incognito;
200 $('clear-selected').disabled = incognito; 239 $('clear-selected').disabled = incognito;
240 $('delete-all-requests').disabled = incognito;
241 $('delete-selected-requests').disabled = incognito;
201 $('log-model-on').disabled = incognito; 242 $('log-model-on').disabled = incognito;
202 $('log-model-off').disabled = incognito; 243 $('log-model-off').disabled = incognito;
203 $('log-request-on').disabled = incognito; 244 $('log-request-on').disabled = incognito;
204 $('log-request-off').disabled = incognito; 245 $('log-request-off').disabled = incognito;
205 $('refresh').disabled = incognito; 246 $('refresh').disabled = incognito;
206 247
207 $('clear-all').onclick = deleteAllPages; 248 $('clear-all').onclick = deleteAllPages;
208 $('clear-selected').onclick = deleteSelectedPages; 249 $('clear-selected').onclick = deleteSelectedPages;
250 $('delete-all-requests').onclick = deleteAllRequests;
251 $('delete-selected-requests').onclick = deleteSelectedRequests;
209 $('refresh').onclick = refreshAll; 252 $('refresh').onclick = refreshAll;
210 $('download').onclick = download; 253 $('download').onclick = download;
211 $('log-model-on').onclick = togglePageModelLog.bind(this, true); 254 $('log-model-on').onclick = togglePageModelLog.bind(this, true);
212 $('log-model-off').onclick = togglePageModelLog.bind(this, false); 255 $('log-model-off').onclick = togglePageModelLog.bind(this, false);
213 $('log-request-on').onclick = toggleRequestQueueLog.bind(this, true); 256 $('log-request-on').onclick = toggleRequestQueueLog.bind(this, true);
214 $('log-request-off').onclick = toggleRequestQueueLog.bind(this, false); 257 $('log-request-off').onclick = toggleRequestQueueLog.bind(this, false);
215 $('refresh-logs').onclick = refreshLog; 258 $('refresh-logs').onclick = refreshLog;
216 $('add-to-queue').onclick = function() { 259 $('add-to-queue').onclick = function() {
217 var saveUrls = $('url').value.split(','); 260 var saveUrls = $('url').value.split(',');
218 var counter = saveUrls.length; 261 var counter = saveUrls.length;
(...skipping 20 matching lines...) Expand all
239 refreshAll(); 282 refreshAll();
240 } 283 }
241 284
242 // Return an object with all of the exports. 285 // Return an object with all of the exports.
243 return { 286 return {
244 initialize: initialize, 287 initialize: initialize,
245 }; 288 };
246 }); 289 });
247 290
248 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); 291 document.addEventListener('DOMContentLoaded', offlineInternals.initialize);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698