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