| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** @type {string} | 5 /** @type {string} |
| 6 * @const | 6 * @const |
| 7 */ | 7 */ |
| 8 var FEEDBACK_LANDING_PAGE = | 8 var FEEDBACK_LANDING_PAGE = |
| 9 'https://www.google.com/support/chrome/go/feedback_confirmation'; | 9 'https://www.google.com/support/chrome/go/feedback_confirmation'; |
| 10 /** @type {number} | 10 /** @type {number} |
| 11 * @const | 11 * @const |
| 12 */ | 12 */ |
| 13 var MAX_ATTACH_FILE_SIZE = 3 * 1024 * 1024; | 13 var MAX_ATTACH_FILE_SIZE = 3 * 1024 * 1024; |
| 14 | 14 |
| 15 /** @type {number} | 15 /** @type {number} |
| 16 * @const | 16 * @const |
| 17 */ | 17 */ |
| 18 var CONTENT_MARGIN_HEIGHT = 40; | 18 var CONTENT_MARGIN_HEIGHT = 40; |
| 19 | 19 |
| 20 var attachedFileBlob = null; | 20 var attachedFileBlob = null; |
| 21 var lastReader = null; | 21 var lastReader = null; |
| 22 | 22 |
| 23 var feedbackInfo = null; | 23 var feedbackInfo = null; |
| 24 var systemInfo = null; | 24 var systemInfo = null; |
| 25 | 25 |
| 26 var systemInfoWindowId = 0; | 26 var systemInfoWindow = {id: 0}; |
| 27 var histogramsWindow = {id: 0}; |
| 27 | 28 |
| 28 /** | 29 /** |
| 29 * Reads the selected file when the user selects a file. | 30 * Reads the selected file when the user selects a file. |
| 30 * @param {Event} fileSelectedEvent The onChanged event for the file input box. | 31 * @param {Event} fileSelectedEvent The onChanged event for the file input box. |
| 31 */ | 32 */ |
| 32 function onFileSelected(fileSelectedEvent) { | 33 function onFileSelected(fileSelectedEvent) { |
| 33 $('attach-error').hidden = true; | 34 $('attach-error').hidden = true; |
| 34 var file = fileSelectedEvent.target.files[0]; | 35 var file = fileSelectedEvent.target.files[0]; |
| 35 if (!file) { | 36 if (!file) { |
| 36 // User canceled file selection. | 37 // User canceled file selection. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 * attach another file. | 57 * attach another file. |
| 57 */ | 58 */ |
| 58 function clearAttachedFile() { | 59 function clearAttachedFile() { |
| 59 $('custom-file-container').hidden = true; | 60 $('custom-file-container').hidden = true; |
| 60 attachedFileBlob = null; | 61 attachedFileBlob = null; |
| 61 feedbackInfo.attachedFile = null; | 62 feedbackInfo.attachedFile = null; |
| 62 $('attach-file').hidden = false; | 63 $('attach-file').hidden = false; |
| 63 } | 64 } |
| 64 | 65 |
| 65 /** | 66 /** |
| 66 * Opens a new window with chrome://system, showing the current system info. | 67 * Creates and shows a window with the given url, if the window is not already |
| 68 * open. |
| 69 * @param {Object} window An object with the id of the window to update, or 0. |
| 70 * @param {string} url The destination URL of the new window. |
| 71 * @return {function()} A function to be called to open the window. |
| 67 */ | 72 */ |
| 68 function openSystemInfoWindow() { | 73 function windowOpener(window, url) { |
| 69 if (systemInfoWindowId == 0) { | 74 return function() { |
| 70 chrome.windows.create({url: 'chrome://system'}, function(win) { | 75 if (window.id == 0) { |
| 71 systemInfoWindowId = win.id; | 76 chrome.windows.create({url: url}, function(win) { |
| 72 chrome.app.window.current().show(); | 77 window.id = win.id; |
| 73 }); | 78 chrome.app.window.current().show(); |
| 74 } else { | 79 }); |
| 75 chrome.windows.update(systemInfoWindowId, {drawAttention: true}); | 80 } else { |
| 76 } | 81 chrome.windows.update(window.id, {drawAttention: true}); |
| 82 } |
| 83 }; |
| 77 } | 84 } |
| 78 | 85 |
| 79 /** | 86 /** |
| 80 * Opens a new window with chrome://slow_trace, downloading performance data. | 87 * Opens a new window with chrome://slow_trace, downloading performance data. |
| 81 */ | 88 */ |
| 82 function openSlowTraceWindow() { | 89 function openSlowTraceWindow() { |
| 83 chrome.windows.create( | 90 chrome.windows.create( |
| 84 {url: 'chrome://slow_trace/tracing.zip#' + feedbackInfo.traceId}, | 91 {url: 'chrome://slow_trace/tracing.zip#' + feedbackInfo.traceId}, |
| 85 function(win) {}); | 92 function(win) {}); |
| 86 } | 93 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 if (!feedbackInfo.attachedFile && attachedFileBlob) { | 112 if (!feedbackInfo.attachedFile && attachedFileBlob) { |
| 106 feedbackInfo.attachedFile = { name: $('attach-file').value, | 113 feedbackInfo.attachedFile = { name: $('attach-file').value, |
| 107 data: attachedFileBlob }; | 114 data: attachedFileBlob }; |
| 108 } | 115 } |
| 109 | 116 |
| 110 feedbackInfo.description = $('description-text').value; | 117 feedbackInfo.description = $('description-text').value; |
| 111 feedbackInfo.pageUrl = $('page-url-text').value; | 118 feedbackInfo.pageUrl = $('page-url-text').value; |
| 112 feedbackInfo.email = $('user-email-text').value; | 119 feedbackInfo.email = $('user-email-text').value; |
| 113 | 120 |
| 114 var useSystemInfo = false; | 121 var useSystemInfo = false; |
| 122 var useHistograms = false; |
| 115 // On ChromeOS, since we gather System info, check if the user has given his | 123 // On ChromeOS, since we gather System info, check if the user has given his |
| 116 // permission for us to send system info. | 124 // permission for us to send system info. |
| 117 <if expr="pp_ifdef('chromeos')"> | 125 <if expr="pp_ifdef('chromeos')"> |
| 118 if ($('sys-info-checkbox') != null && | 126 if ($('sys-info-checkbox') != null && |
| 119 $('sys-info-checkbox').checked && | 127 $('sys-info-checkbox').checked && |
| 120 systemInfo != null) { | 128 systemInfo != null) { |
| 121 useSystemInfo = true; | 129 // Send histograms along with system info. |
| 130 useSystemInfo = useHistograms = true; |
| 122 } | 131 } |
| 123 if ($('performance-info-checkbox') == null || | 132 if ($('performance-info-checkbox') == null || |
| 124 !($('performance-info-checkbox').checked)) { | 133 !($('performance-info-checkbox').checked)) { |
| 125 feedbackInfo.traceId = null; | 134 feedbackInfo.traceId = null; |
| 126 } | 135 } |
| 127 </if> | 136 </if> |
| 128 | 137 |
| 129 // On NonChromeOS, we don't have any system information gathered except the | 138 // On NonChromeOS, we don't have any system information gathered except the |
| 130 // Chrome version and the OS version. Hence for Chrome, pass the system info | 139 // Chrome version and the OS version. Hence for Chrome, pass the system info |
| 131 // through. | 140 // through. |
| 132 <if expr="not pp_ifdef('chromeos')"> | 141 <if expr="not pp_ifdef('chromeos')"> |
| 133 if (systemInfo != null) | 142 if (systemInfo != null) |
| 134 useSystemInfo = true; | 143 useSystemInfo = true; |
| 135 </if> | 144 </if> |
| 136 | 145 |
| 137 if (useSystemInfo) { | 146 if (useSystemInfo) { |
| 138 if (feedbackInfo.systemInformation != null) { | 147 if (feedbackInfo.systemInformation != null) { |
| 139 // Concatenate sysinfo if we had any initial system information | 148 // Concatenate sysinfo if we had any initial system information |
| 140 // sent with the feedback request event. | 149 // sent with the feedback request event. |
| 141 feedbackInfo.systemInformation = | 150 feedbackInfo.systemInformation = |
| 142 feedbackInfo.systemInformation.concat(systemInfo); | 151 feedbackInfo.systemInformation.concat(systemInfo); |
| 143 } else { | 152 } else { |
| 144 feedbackInfo.systemInformation = systemInfo; | 153 feedbackInfo.systemInformation = systemInfo; |
| 145 } | 154 } |
| 146 } | 155 } |
| 147 | 156 |
| 157 feedbackInfo.sendHistograms = useHistograms; |
| 158 |
| 148 // If the user doesn't want to send the screenshot. | 159 // If the user doesn't want to send the screenshot. |
| 149 if (!$('screenshot-checkbox').checked) | 160 if (!$('screenshot-checkbox').checked) |
| 150 feedbackInfo.screenshot = null; | 161 feedbackInfo.screenshot = null; |
| 151 | 162 |
| 152 chrome.feedbackPrivate.sendFeedback(feedbackInfo, function(result) { | 163 chrome.feedbackPrivate.sendFeedback(feedbackInfo, function(result) { |
| 153 window.open(FEEDBACK_LANDING_PAGE, '_blank'); | 164 window.open(FEEDBACK_LANDING_PAGE, '_blank'); |
| 154 window.close(); | 165 window.close(); |
| 155 }); | 166 }); |
| 156 | 167 |
| 157 return true; | 168 return true; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 $('performance-info-area').hidden = false; | 282 $('performance-info-area').hidden = false; |
| 272 $('performance-info-checkbox').checked = true; | 283 $('performance-info-checkbox').checked = true; |
| 273 performanceFeedbackChanged(); | 284 performanceFeedbackChanged(); |
| 274 $('performance-info-link').onclick = openSlowTraceWindow; | 285 $('performance-info-link').onclick = openSlowTraceWindow; |
| 275 } | 286 } |
| 276 </if> | 287 </if> |
| 277 | 288 |
| 278 chrome.feedbackPrivate.getStrings(function(strings) { | 289 chrome.feedbackPrivate.getStrings(function(strings) { |
| 279 loadTimeData.data = strings; | 290 loadTimeData.data = strings; |
| 280 i18nTemplate.process(document, loadTimeData); | 291 i18nTemplate.process(document, loadTimeData); |
| 292 |
| 293 if ($('sys-info-url')) { |
| 294 // Opens a new window showing the current system info. |
| 295 $('sys-info-url').onclick = |
| 296 windowOpener(systemInfoWindow, 'chrome://system'); |
| 297 } |
| 298 if ($('histograms-url')) { |
| 299 // Opens a new window showing the histogram metrics. |
| 300 $('histograms-url').onclick = |
| 301 windowOpener(histogramsWindow, 'chrome://histograms'); |
| 302 } |
| 281 }); | 303 }); |
| 282 } | 304 } |
| 283 }); | 305 }); |
| 284 | 306 |
| 285 window.addEventListener('DOMContentLoaded', function() { | 307 window.addEventListener('DOMContentLoaded', function() { |
| 286 // TODO(rkc): Remove logging once crbug.com/284662 is closed. | 308 // TODO(rkc): Remove logging once crbug.com/284662 is closed. |
| 287 console.log('FEEDBACK_DEBUG: feedback.js: DOMContentLoaded'); | 309 console.log('FEEDBACK_DEBUG: feedback.js: DOMContentLoaded'); |
| 288 // Ready to receive the feedback object. | 310 // Ready to receive the feedback object. |
| 289 chrome.runtime.sendMessage({ready: true}); | 311 chrome.runtime.sendMessage({ready: true}); |
| 290 | 312 |
| 291 // Setup our event handlers. | 313 // Setup our event handlers. |
| 292 $('attach-file').addEventListener('change', onFileSelected); | 314 $('attach-file').addEventListener('change', onFileSelected); |
| 293 $('send-report-button').onclick = sendReport; | 315 $('send-report-button').onclick = sendReport; |
| 294 $('cancel-button').onclick = cancel; | 316 $('cancel-button').onclick = cancel; |
| 295 $('remove-attached-file').onclick = clearAttachedFile; | 317 $('remove-attached-file').onclick = clearAttachedFile; |
| 296 <if expr="pp_ifdef('chromeos')"> | 318 <if expr="pp_ifdef('chromeos')"> |
| 297 $('performance-info-checkbox').addEventListener( | 319 $('performance-info-checkbox').addEventListener( |
| 298 'change', performanceFeedbackChanged); | 320 'change', performanceFeedbackChanged); |
| 299 </if> | 321 </if> |
| 300 | 322 |
| 301 chrome.windows.onRemoved.addListener(function(windowId, removeInfo) { | 323 chrome.windows.onRemoved.addListener(function(windowId, removeInfo) { |
| 302 if (windowId == systemInfoWindowId) | 324 if (windowId == systemInfoWindow.id) |
| 303 systemInfoWindowId = 0; | 325 systemInfoWindow.id = 0; |
| 326 else if (windowId == histogramsWindow.id) |
| 327 histogramsWindow.id = 0; |
| 304 }); | 328 }); |
| 305 if ($('sysinfo-url')) { | |
| 306 $('sysinfo-url').onclick = openSystemInfoWindow; | |
| 307 } | |
| 308 }); | 329 }); |
| 309 } | 330 } |
| 310 | 331 |
| 311 initialize(); | 332 initialize(); |
| OLD | NEW |