| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 cell = document.createElement('td'); | 75 cell = document.createElement('td'); |
| 76 cell.textContent = requests[i].status; | 76 cell.textContent = requests[i].status; |
| 77 row.appendChild(cell); | 77 row.appendChild(cell); |
| 78 | 78 |
| 79 requestQueueTable.appendChild(row); | 79 requestQueueTable.appendChild(row); |
| 80 } | 80 } |
| 81 savePageRequests = requests; | 81 savePageRequests = requests; |
| 82 } | 82 } |
| 83 | 83 |
| 84 /** | 84 /** |
| 85 * Fills the event logs section. |
| 86 * @param {!Array<string>} logs A list of log strings. |
| 87 */ |
| 88 function fillEventLog(logs) { |
| 89 var element = $('logs'); |
| 90 element.textContent = ''; |
| 91 for (let log of logs) { |
| 92 var logItem = document.createElement('li'); |
| 93 logItem.textContent = log; |
| 94 element.appendChild(logItem); |
| 95 } |
| 96 } |
| 97 |
| 98 /** |
| 85 * Refresh all displayed information. | 99 * Refresh all displayed information. |
| 86 */ | 100 */ |
| 87 function refreshAll() { | 101 function refreshAll() { |
| 88 browserProxy_.getStoredPages().then(fillStoredPages); | 102 browserProxy_.getStoredPages().then(fillStoredPages); |
| 89 browserProxy_.getRequestQueue().then(fillRequestQueue); | 103 browserProxy_.getRequestQueue().then(fillRequestQueue); |
| 104 refreshLog(); |
| 90 } | 105 } |
| 91 | 106 |
| 92 /** | 107 /** |
| 93 * Delete all pages in the offline store. | 108 * Delete all pages in the offline store. |
| 94 */ | 109 */ |
| 95 function deleteAllPages() { | 110 function deleteAllPages() { |
| 96 browserProxy_.deleteAllPages().then(pagesDeleted); | 111 browserProxy_.deleteAllPages().then(pagesDeleted); |
| 97 } | 112 } |
| 98 | 113 |
| 99 /** | 114 /** |
| (...skipping 14 matching lines...) Expand all Loading... |
| 114 offlinePages: offlinePages, | 129 offlinePages: offlinePages, |
| 115 savePageRequests: savePageRequests | 130 savePageRequests: savePageRequests |
| 116 }, null, 2); | 131 }, null, 2); |
| 117 | 132 |
| 118 window.open( | 133 window.open( |
| 119 'data:application/json,' + encodeURIComponent(json), | 134 'data:application/json,' + encodeURIComponent(json), |
| 120 'dump.json'); | 135 'dump.json'); |
| 121 } | 136 } |
| 122 | 137 |
| 123 /** | 138 /** |
| 139 * Updates the status strings. |
| 140 * @param {!IsLogging} logStatus Status of logging. |
| 141 */ |
| 142 function updateLogStatus(logStatus) { |
| 143 $('model-status').textContent = logStatus.modelIsLogging ? 'On' : 'Off'; |
| 144 $('request-status').textContent = logStatus.queueIsLogging ? 'On' : 'Off'; |
| 145 } |
| 146 |
| 147 /** |
| 124 * Delete selected pages from the offline store. | 148 * Delete selected pages from the offline store. |
| 125 */ | 149 */ |
| 126 function deleteSelectedPages() { | 150 function deleteSelectedPages() { |
| 127 var checkboxes = document.getElementsByName('stored'); | 151 var checkboxes = document.getElementsByName('stored'); |
| 128 var selectedIds = []; | 152 var selectedIds = []; |
| 129 | 153 |
| 130 for (var i = 0; i < checkboxes.length; i++) { | 154 for (var i = 0; i < checkboxes.length; i++) { |
| 131 if (checkboxes[i].checked) | 155 if (checkboxes[i].checked) |
| 132 selectedIds.push(checkboxes[i].value); | 156 selectedIds.push(checkboxes[i].value); |
| 133 } | 157 } |
| 134 | 158 |
| 135 browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted); | 159 browserProxy_.deleteSelectedPages(selectedIds).then(pagesDeleted); |
| 136 } | 160 } |
| 137 | 161 |
| 162 /** |
| 163 * Refreshes the logs. |
| 164 */ |
| 165 function refreshLog() { |
| 166 browserProxy_.getEventLogs().then(fillEventLog); |
| 167 browserProxy_.getLoggingState().then(updateLogStatus); |
| 168 } |
| 169 |
| 138 function initialize() { | 170 function initialize() { |
| 139 $('clear-all').onclick = deleteAllPages; | 171 $('clear-all').onclick = deleteAllPages; |
| 140 $('clear-selected').onclick = deleteSelectedPages; | 172 $('clear-selected').onclick = deleteSelectedPages; |
| 141 $('refresh').onclick = refreshAll; | 173 $('refresh').onclick = refreshAll; |
| 142 $('download').onclick = download; | 174 $('download').onclick = download; |
| 175 $('log-model-on').onclick = |
| 176 browserProxy_.setRecordPageModel.bind(browserProxy_, true); |
| 177 $('log-model-off').onclick = |
| 178 browserProxy_.setRecordPageModel.bind(browserProxy_, false); |
| 179 $('log-request-on').onclick = |
| 180 browserProxy_.setRecordRequestQueue.bind(browserProxy_, true); |
| 181 $('log-request-off').onclick = |
| 182 browserProxy_.setRecordRequestQueue.bind(browserProxy_, false); |
| 183 $('refresh-logs').onclick = refreshLog; |
| 143 browserProxy_ = | 184 browserProxy_ = |
| 144 offlineInternals.OfflineInternalsBrowserProxyImpl.getInstance(); | 185 offlineInternals.OfflineInternalsBrowserProxyImpl.getInstance(); |
| 145 refreshAll(); | 186 refreshAll(); |
| 146 } | 187 } |
| 147 | 188 |
| 148 // Return an object with all of the exports. | 189 // Return an object with all of the exports. |
| 149 return { | 190 return { |
| 150 initialize: initialize, | 191 initialize: initialize, |
| 151 }; | 192 }; |
| 152 }); | 193 }); |
| 153 | 194 |
| 154 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); | 195 document.addEventListener('DOMContentLoaded', offlineInternals.initialize); |
| OLD | NEW |