| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
| 6 * This view displays options for exporting the captured data. | 6 * This view displays options for exporting the captured data. |
| 7 */ | 7 */ |
| 8 var ExportView = (function() { | 8 var ExportView = (function() { |
| 9 'use strict'; | 9 'use strict'; |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 var privacyStrippingCheckbox = $(ExportView.PRIVACY_STRIPPING_CHECKBOX_ID); | 23 var privacyStrippingCheckbox = $(ExportView.PRIVACY_STRIPPING_CHECKBOX_ID); |
| 24 privacyStrippingCheckbox.onclick = | 24 privacyStrippingCheckbox.onclick = |
| 25 this.onSetPrivacyStripping_.bind(this, privacyStrippingCheckbox); | 25 this.onSetPrivacyStripping_.bind(this, privacyStrippingCheckbox); |
| 26 | 26 |
| 27 this.saveFileButton_ = $(ExportView.SAVE_FILE_BUTTON_ID); | 27 this.saveFileButton_ = $(ExportView.SAVE_FILE_BUTTON_ID); |
| 28 this.saveFileButton_.onclick = this.onSaveFile_.bind(this); | 28 this.saveFileButton_.onclick = this.onSaveFile_.bind(this); |
| 29 this.saveStatusText_ = $(ExportView.SAVE_STATUS_TEXT_ID); | 29 this.saveStatusText_ = $(ExportView.SAVE_STATUS_TEXT_ID); |
| 30 | 30 |
| 31 this.userCommentsTextArea_ = $(ExportView.USER_COMMENTS_TEXT_AREA_ID); | 31 this.userCommentsTextArea_ = $(ExportView.USER_COMMENTS_TEXT_AREA_ID); |
| 32 this.enableSaveFileButton_(false); |
| 33 this.userCommentsTextArea_.onkeyup = this.onUserCommentsUpdated_.bind(this); |
| 32 | 34 |
| 33 // Track blob for previous log dump so it can be revoked when a new dump is | 35 // Track blob for previous log dump so it can be revoked when a new dump is |
| 34 // saved. | 36 // saved. |
| 35 this.lastBlobURL_ = null; | 37 this.lastBlobURL_ = null; |
| 36 | 38 |
| 37 // Cached copy of the last loaded log dump, for use when exporting. | 39 // Cached copy of the last loaded log dump, for use when exporting. |
| 38 this.loadedLogDump_ = null; | 40 this.loadedLogDump_ = null; |
| 39 } | 41 } |
| 40 | 42 |
| 41 ExportView.TAB_ID = 'tab-handle-export'; | 43 ExportView.TAB_ID = 'tab-handle-export'; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } | 120 } |
| 119 this.createLogDump_(this.onLogDumpCreated_.bind(this)); | 121 this.createLogDump_(this.onLogDumpCreated_.bind(this)); |
| 120 }, | 122 }, |
| 121 | 123 |
| 122 /** | 124 /** |
| 123 * Creates a log dump, and either synchronously or asynchronously calls | 125 * Creates a log dump, and either synchronously or asynchronously calls |
| 124 * |callback| if it succeeds. Separate from onSaveFile_ for unit tests. | 126 * |callback| if it succeeds. Separate from onSaveFile_ for unit tests. |
| 125 */ | 127 */ |
| 126 createLogDump_: function(callback) { | 128 createLogDump_: function(callback) { |
| 127 // Get an explanation for the dump file (this is mandatory!) | 129 // Get an explanation for the dump file (this is mandatory!) |
| 128 var userComments = this.getNonEmptyUserComments_(); | 130 var userComments = this.userCommentsTextArea_.value; |
| 129 if (userComments == undefined) { | |
| 130 return; | |
| 131 } | |
| 132 | 131 |
| 133 this.setSaveFileStatus('Preparing data...', true); | 132 this.setSaveFileStatus('Preparing data...', true); |
| 134 | 133 |
| 135 var privacyStripping = SourceTracker.getInstance().getPrivacyStripping(); | 134 var privacyStripping = SourceTracker.getInstance().getPrivacyStripping(); |
| 136 | 135 |
| 137 // If we have a cached log dump, update it synchronously. | 136 // If we have a cached log dump, update it synchronously. |
| 138 if (this.loadedLogDump_) { | 137 if (this.loadedLogDump_) { |
| 139 var dumpText = log_util.createUpdatedLogDump(userComments, | 138 var dumpText = log_util.createUpdatedLogDump(userComments, |
| 140 this.loadedLogDump_, | 139 this.loadedLogDump_, |
| 141 privacyStripping); | 140 privacyStripping); |
| 142 callback(dumpText); | 141 callback(dumpText); |
| 143 return; | 142 return; |
| 144 } | 143 } |
| 145 | 144 |
| 146 // Otherwise, poll information from the browser before creating one. | 145 // Otherwise, poll information from the browser before creating one. |
| 147 log_util.createLogDumpAsync(userComments, | 146 log_util.createLogDumpAsync(userComments, |
| 148 callback, | 147 callback, |
| 149 privacyStripping); | 148 privacyStripping); |
| 150 }, | 149 }, |
| 151 | 150 |
| 152 /** | 151 /** |
| 153 * Sets the user comments. | 152 * Sets the user comments. |
| 154 */ | 153 */ |
| 155 setUserComments_: function(userComments) { | 154 setUserComments_: function(userComments) { |
| 156 this.userCommentsTextArea_.value = userComments; | 155 this.userCommentsTextArea_.value = userComments; |
| 156 this.onUserCommentsUpdated_(); |
| 157 }, | 157 }, |
| 158 | 158 |
| 159 /** | 159 /** |
| 160 * Fetches the user comments for this dump. If none were entered, warns the | 160 * User comments are updated. |
| 161 * user and returns undefined. Otherwise returns the comments text. | |
| 162 */ | 161 */ |
| 163 getNonEmptyUserComments_: function() { | 162 onUserCommentsUpdated_: function() { |
| 164 var value = this.userCommentsTextArea_.value; | 163 this.enableSaveFileButton_(this.userCommentsTextArea_.value != ''); |
| 165 | |
| 166 // Reset the class name in case we had hilighted it earlier. | |
| 167 this.userCommentsTextArea_.className = ''; | |
| 168 | |
| 169 // We don't accept empty explanations. We don't care what is entered, as | |
| 170 // long as there is something (a single whitespace would work). | |
| 171 if (value == '') { | |
| 172 // Put a big obnoxious red border around the text area. | |
| 173 this.userCommentsTextArea_.className = | |
| 174 'export-view-explanation-warning'; | |
| 175 alert('Please fill in the text field!'); | |
| 176 this.userCommentsTextArea_.focus(); | |
| 177 return undefined; | |
| 178 } | |
| 179 | |
| 180 return value; | |
| 181 }, | 164 }, |
| 182 | 165 |
| 183 /** | 166 /** |
| 184 * Creates a blob url and starts downloading it. | 167 * Creates a blob url and starts downloading it. |
| 185 */ | 168 */ |
| 186 onLogDumpCreated_: function(dumpText) { | 169 onLogDumpCreated_: function(dumpText) { |
| 187 var textBlob = new Blob([dumpText], {type: 'octet/stream'}); | 170 var textBlob = new Blob([dumpText], {type: 'octet/stream'}); |
| 188 this.lastBlobURL_ = window.URL.createObjectURL(textBlob); | 171 this.lastBlobURL_ = window.URL.createObjectURL(textBlob); |
| 189 | 172 |
| 190 // Update the anchor tag and simulate a click on it to start the | 173 // Update the anchor tag and simulate a click on it to start the |
| 191 // download. | 174 // download. |
| 192 var downloadAnchor = $(ExportView.DOWNLOAD_ANCHOR_ID); | 175 var downloadAnchor = $(ExportView.DOWNLOAD_ANCHOR_ID); |
| 193 downloadAnchor.href = this.lastBlobURL_; | 176 downloadAnchor.href = this.lastBlobURL_; |
| 194 downloadAnchor.click(); | 177 downloadAnchor.click(); |
| 195 | 178 |
| 196 this.setSaveFileStatus('Dump successful', false); | 179 this.setSaveFileStatus('Dump successful', false); |
| 197 } | 180 } |
| 198 }; | 181 }; |
| 199 | 182 |
| 200 return ExportView; | 183 return ExportView; |
| 201 })(); | 184 })(); |
| OLD | NEW |