| OLD | NEW |
| 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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 function requestsDeleted(status) { | 167 function requestsDeleted(status) { |
| 168 $('request-queue-actions-info').textContent = status; | 168 $('request-queue-actions-info').textContent = status; |
| 169 browserProxy_.getRequestQueue().then(fillRequestQueue); | 169 browserProxy_.getRequestQueue().then(fillRequestQueue); |
| 170 } | 170 } |
| 171 | 171 |
| 172 /** | 172 /** |
| 173 * Downloads all the stored page and request queue information into a file. | 173 * Downloads all the stored page and request queue information into a file. |
| 174 * TODO(chili): Create a CSV writer that can abstract out the line joining. | 174 * TODO(chili): Create a CSV writer that can abstract out the line joining. |
| 175 */ | 175 */ |
| 176 function download() { | 176 function download() { |
| 177 var json = JSON.stringify({ | 177 var json = JSON.stringify( |
| 178 offlinePages: offlinePages, | 178 {offlinePages: offlinePages, savePageRequests: savePageRequests}, null, |
| 179 savePageRequests: savePageRequests | 179 2); |
| 180 }, null, 2); | |
| 181 | 180 |
| 182 window.open( | 181 window.open( |
| 183 'data:application/json,' + encodeURIComponent(json), | 182 'data:application/json,' + encodeURIComponent(json), 'dump.json'); |
| 184 'dump.json'); | |
| 185 } | 183 } |
| 186 | 184 |
| 187 /** | 185 /** |
| 188 * Updates the status strings. | 186 * Updates the status strings. |
| 189 * @param {!IsLogging} logStatus Status of logging. | 187 * @param {!IsLogging} logStatus Status of logging. |
| 190 */ | 188 */ |
| 191 function updateLogStatus(logStatus) { | 189 function updateLogStatus(logStatus) { |
| 192 $('model-status').textContent = logStatus.modelIsLogging ? 'On' : 'Off'; | 190 $('model-status').textContent = logStatus.modelIsLogging ? 'On' : 'Off'; |
| 193 $('request-status').textContent = logStatus.queueIsLogging ? 'On' : 'Off'; | 191 $('request-status').textContent = logStatus.queueIsLogging ? 'On' : 'Off'; |
| 194 } | 192 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 $('log-model-on').onclick = togglePageModelLog.bind(this, true); | 266 $('log-model-on').onclick = togglePageModelLog.bind(this, true); |
| 269 $('log-model-off').onclick = togglePageModelLog.bind(this, false); | 267 $('log-model-off').onclick = togglePageModelLog.bind(this, false); |
| 270 $('log-request-on').onclick = toggleRequestQueueLog.bind(this, true); | 268 $('log-request-on').onclick = toggleRequestQueueLog.bind(this, true); |
| 271 $('log-request-off').onclick = toggleRequestQueueLog.bind(this, false); | 269 $('log-request-off').onclick = toggleRequestQueueLog.bind(this, false); |
| 272 $('refresh-logs').onclick = refreshLog; | 270 $('refresh-logs').onclick = refreshLog; |
| 273 $('add-to-queue').onclick = function() { | 271 $('add-to-queue').onclick = function() { |
| 274 var saveUrls = $('url').value.split(','); | 272 var saveUrls = $('url').value.split(','); |
| 275 var counter = saveUrls.length; | 273 var counter = saveUrls.length; |
| 276 $('save-url-state').textContent = ''; | 274 $('save-url-state').textContent = ''; |
| 277 for (let i = 0; i < saveUrls.length; i++) { | 275 for (let i = 0; i < saveUrls.length; i++) { |
| 278 browserProxy_.addToRequestQueue(saveUrls[i]) | 276 browserProxy_.addToRequestQueue(saveUrls[i]).then(function(state) { |
| 279 .then(function(state) { | 277 if (state) { |
| 280 if (state) { | 278 $('save-url-state').textContent += |
| 281 $('save-url-state').textContent += | 279 saveUrls[i] + ' has been added to queue.\n'; |
| 282 saveUrls[i] + ' has been added to queue.\n'; | 280 $('url').value = ''; |
| 283 $('url').value = ''; | 281 counter--; |
| 284 counter--; | 282 if (counter == 0) { |
| 285 if (counter == 0) { | 283 browserProxy_.getRequestQueue().then(fillRequestQueue); |
| 286 browserProxy_.getRequestQueue().then(fillRequestQueue); | 284 } |
| 287 } | 285 } else { |
| 288 } else { | 286 $('save-url-state').textContent += |
| 289 $('save-url-state').textContent += | 287 saveUrls[i] + ' failed to be added to queue.\n'; |
| 290 saveUrls[i] + ' failed to be added to queue.\n'; | 288 } |
| 291 } | 289 }); |
| 292 }); | |
| 293 } | 290 } |
| 294 }; | 291 }; |
| 295 if (!incognito) | 292 if (!incognito) |
| 296 refreshAll(); | 293 refreshAll(); |
| 297 } | 294 } |
| 298 | 295 |
| 299 // Return an object with all of the exports. | 296 // Return an object with all of the exports. |
| 300 return { | 297 return { |
| 301 initialize: initialize, | 298 initialize: initialize, |
| 302 }; | 299 }; |
| 303 }); | 300 }); |
| 304 | 301 |
| 305 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); | 302 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); |
| OLD | NEW |