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://support.google.com/chrome/go/feedback_confirmation'; | 9 'https://support.google.com/chrome/go/feedback_confirmation'; |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 * @enum {string} | 56 * @enum {string} |
57 */ | 57 */ |
58 var FeedbackFlow = { | 58 var FeedbackFlow = { |
59 REGULAR: 'regular', // Flow in a regular user session. | 59 REGULAR: 'regular', // Flow in a regular user session. |
60 LOGIN: 'login' // Flow on the login screen. | 60 LOGIN: 'login' // Flow on the login screen. |
61 }; | 61 }; |
62 | 62 |
63 var attachedFileBlob = null; | 63 var attachedFileBlob = null; |
64 var lastReader = null; | 64 var lastReader = null; |
65 | 65 |
66 var feedbackInfo = null; | 66 /** |
| 67 * Determines whether the system information associated with this instance of |
| 68 * the feedback window has been received. |
| 69 * @type {boolean} |
| 70 */ |
| 71 var isSystemInfoReady = false; |
67 | 72 |
68 /** | 73 /** |
69 * The callback used by the sys_info_page to receive the event that the system | 74 * The callback used by the sys_info_page to receive the event that the system |
70 * information is ready. | 75 * information is ready. |
71 * @type {function(sysInfo)} | 76 * @type {function(sysInfo)} |
72 */ | 77 */ |
73 var sysInfoPageOnSysInfoReadyCallback = null; | 78 var sysInfoPageOnSysInfoReadyCallback = null; |
74 | 79 |
75 /** | 80 /** |
76 * Reads the selected file when the user selects a file. | 81 * Reads the selected file when the user selects a file. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 feedbackInfo.traceId = null; | 174 feedbackInfo.traceId = null; |
170 } | 175 } |
171 </if> | 176 </if> |
172 | 177 |
173 feedbackInfo.sendHistograms = useHistograms; | 178 feedbackInfo.sendHistograms = useHistograms; |
174 | 179 |
175 // If the user doesn't want to send the screenshot. | 180 // If the user doesn't want to send the screenshot. |
176 if (!$('screenshot-checkbox').checked) | 181 if (!$('screenshot-checkbox').checked) |
177 feedbackInfo.screenshot = null; | 182 feedbackInfo.screenshot = null; |
178 | 183 |
179 if (useSystemInfo) { | 184 // Request sending the report, show the landing page (if allowed), and close |
180 // The user chose to include the system information as part of the report. | 185 // this window right away. The FeedbackRequest object that represents this |
181 // If they are not ready yet, we have to send the report later. | 186 // report will take care of sending the report in the background. |
182 if (!isSystemInfoReady()) { | 187 sendFeedbackReport(useSystemInfo); |
183 // The report will be sent later by the feedback extension's background | 188 if (feedbackInfo.flow != FeedbackFlow.LOGIN) |
184 // page (see event_handler.js). | 189 window.open(FEEDBACK_LANDING_PAGE, '_blank'); |
185 sendReportLater(feedbackInfo); | 190 window.close(); |
186 | |
187 // No landing page for login screen feedback. | |
188 if (feedbackInfo.flow != FeedbackFlow.LOGIN) | |
189 window.open(FEEDBACK_LANDING_PAGE, '_blank'); | |
190 window.close(); | |
191 return true; | |
192 } | |
193 } | |
194 | |
195 chrome.feedbackPrivate.sendFeedback(feedbackInfo, function(result) { | |
196 // No landing page for login screen feedback. | |
197 if (feedbackInfo.flow != FeedbackFlow.LOGIN) | |
198 window.open(FEEDBACK_LANDING_PAGE, '_blank'); | |
199 window.close(); | |
200 }); | |
201 | |
202 return true; | 191 return true; |
203 } | 192 } |
204 | 193 |
205 /** | 194 /** |
206 * Click listener for the cancel button. | 195 * Click listener for the cancel button. |
207 * @param {Event} e The click event being handled. | 196 * @param {Event} e The click event being handled. |
208 */ | 197 */ |
209 function cancel(e) { | 198 function cancel(e) { |
210 e.preventDefault(); | 199 e.preventDefault(); |
211 window.close(); | 200 window.close(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 if (feedbackInfo.flow == FeedbackFlow.LOGIN) | 249 if (feedbackInfo.flow == FeedbackFlow.LOGIN) |
261 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN; | 250 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN; |
262 height = Math.max(height, minHeight); | 251 height = Math.max(height, minHeight); |
263 | 252 |
264 chrome.app.window.current().resizeTo(width, height); | 253 chrome.app.window.current().resizeTo(width, height); |
265 } | 254 } |
266 | 255 |
267 /** | 256 /** |
268 * A callback to be invoked when the background page of this extension receives | 257 * A callback to be invoked when the background page of this extension receives |
269 * the system information. | 258 * the system information. |
270 * @param {Object} sysInfo The received system information. | |
271 */ | 259 */ |
272 function onSystemInformation(sysInfo) { | 260 function onSystemInformation() { |
273 // Concatenate the feedbackInfo's systemInformation with the newly received | 261 isSystemInfoReady = true; |
274 // sysInfo once (if any). | |
275 if (feedbackInfo.systemInformation) { | |
276 feedbackInfo.systemInformation = | |
277 feedbackInfo.systemInformation.concat(sysInfo); | |
278 } else { | |
279 feedbackInfo.systemInformation = sysInfo; | |
280 } | |
281 | |
282 // In case the sys_info_page needs to be notified by this event, do so. | 262 // In case the sys_info_page needs to be notified by this event, do so. |
283 if (sysInfoPageOnSysInfoReadyCallback != null) { | 263 if (sysInfoPageOnSysInfoReadyCallback != null) { |
284 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation); | 264 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation); |
285 sysInfoPageOnSysInfoReadyCallback = null; | 265 sysInfoPageOnSysInfoReadyCallback = null; |
286 } | 266 } |
287 } | 267 } |
288 | 268 |
289 /** | 269 /** |
290 * Initializes our page. | 270 * Initializes our page. |
291 * Flow: | 271 * Flow: |
292 * .) DOMContent Loaded -> . Request feedbackInfo object | 272 * .) DOMContent Loaded -> . Request feedbackInfo object |
293 * . Setup page event handlers | 273 * . Setup page event handlers |
294 * .) Feedback Object Received -> . take screenshot | 274 * .) Feedback Object Received -> . take screenshot |
295 * . request email | 275 * . request email |
296 * . request System info | 276 * . request System info |
297 * . request i18n strings | 277 * . request i18n strings |
298 * .) Screenshot taken -> . Show Feedback window. | 278 * .) Screenshot taken -> . Show Feedback window. |
299 */ | 279 */ |
300 function initialize() { | 280 function initialize() { |
301 // Add listener to receive the feedback info object. | 281 // Add listener to receive the feedback info object. |
302 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { | 282 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { |
303 if (request.sentFromEventPage) { | 283 if (request.sentFromEventPage) { |
304 feedbackInfo = request.data; | |
305 | |
306 if (!feedbackInfo.flow) | 284 if (!feedbackInfo.flow) |
307 feedbackInfo.flow = FeedbackFlow.REGULAR; | 285 feedbackInfo.flow = FeedbackFlow.REGULAR; |
308 | 286 |
309 $('description-text').textContent = feedbackInfo.description; | 287 $('description-text').textContent = feedbackInfo.description; |
310 if (feedbackInfo.pageUrl) | 288 if (feedbackInfo.pageUrl) |
311 $('page-url-text').value = feedbackInfo.pageUrl; | 289 $('page-url-text').value = feedbackInfo.pageUrl; |
312 | 290 |
313 takeScreenshot(function(screenshotCanvas) { | 291 takeScreenshot(function(screenshotCanvas) { |
314 // We've taken our screenshot, show the feedback page without any | 292 // We've taken our screenshot, show the feedback page without any |
315 // further delay. | 293 // further delay. |
316 window.webkitRequestAnimationFrame(function() { | 294 window.webkitRequestAnimationFrame(function() { |
317 resizeAppWindow(); | 295 resizeAppWindow(); |
318 }); | 296 }); |
319 chrome.app.window.current().show(); | 297 chrome.app.window.current().show(); |
320 | 298 |
321 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png'); | 299 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png'); |
322 $('screenshot-image').src = screenshotDataUrl; | 300 $('screenshot-image').src = screenshotDataUrl; |
323 $('screenshot-image').classList.toggle('wide-screen', | 301 $('screenshot-image').classList.toggle('wide-screen', |
324 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH); | 302 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH); |
325 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl); | 303 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl); |
326 }); | 304 }); |
327 | 305 |
328 chrome.feedbackPrivate.getUserEmail(function(email) { | 306 chrome.feedbackPrivate.getUserEmail(function(email) { |
329 $('user-email-text').value = email; | 307 $('user-email-text').value = email; |
330 }); | 308 }); |
331 | 309 |
332 // Initiate getting the system info and use it to prepare the full | 310 // Initiate getting the system info. |
333 // feedback info. | 311 isSystemInfoReady = false; |
334 getSystemInformation(onSystemInformation); | 312 getSystemInformation(onSystemInformation); |
335 | 313 |
336 // An extension called us with an attached file. | 314 // An extension called us with an attached file. |
337 if (feedbackInfo.attachedFile) { | 315 if (feedbackInfo.attachedFile) { |
338 $('attached-filename-text').textContent = | 316 $('attached-filename-text').textContent = |
339 feedbackInfo.attachedFile.name; | 317 feedbackInfo.attachedFile.name; |
340 attachedFileBlob = feedbackInfo.attachedFile.data; | 318 attachedFileBlob = feedbackInfo.attachedFile.data; |
341 $('custom-file-container').hidden = false; | 319 $('custom-file-container').hidden = false; |
342 $('attach-file').hidden = true; | 320 $('attach-file').hidden = true; |
343 } | 321 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 width: 600, | 356 width: 600, |
379 height: 400, | 357 height: 400, |
380 hidden: false, | 358 hidden: false, |
381 resizable: true | 359 resizable: true |
382 }, function(appWindow) { | 360 }, function(appWindow) { |
383 // Define functions for the newly created window. | 361 // Define functions for the newly created window. |
384 | 362 |
385 // Gets the full system information for the new window. | 363 // Gets the full system information for the new window. |
386 appWindow.contentWindow.getFullSystemInfo = | 364 appWindow.contentWindow.getFullSystemInfo = |
387 function(callback) { | 365 function(callback) { |
388 if (isSystemInfoReady()) { | 366 if (isSystemInfoReady) { |
389 callback(feedbackInfo.systemInformation); | 367 callback(feedbackInfo.systemInformation); |
390 return; | 368 return; |
391 } | 369 } |
392 | 370 |
393 sysInfoPageOnSysInfoReadyCallback = callback; | 371 sysInfoPageOnSysInfoReadyCallback = callback; |
394 }; | 372 }; |
395 | 373 |
396 // Returns the loadTimeData for the new window. | 374 // Returns the loadTimeData for the new window. |
397 appWindow.contentWindow.getLoadTimeData = function() { | 375 appWindow.contentWindow.getLoadTimeData = function() { |
398 return loadTimeData; | 376 return loadTimeData; |
(...skipping 22 matching lines...) Expand all Loading... |
421 $('cancel-button').onclick = cancel; | 399 $('cancel-button').onclick = cancel; |
422 $('remove-attached-file').onclick = clearAttachedFile; | 400 $('remove-attached-file').onclick = clearAttachedFile; |
423 <if expr="chromeos"> | 401 <if expr="chromeos"> |
424 $('performance-info-checkbox').addEventListener( | 402 $('performance-info-checkbox').addEventListener( |
425 'change', performanceFeedbackChanged); | 403 'change', performanceFeedbackChanged); |
426 </if> | 404 </if> |
427 }); | 405 }); |
428 } | 406 } |
429 | 407 |
430 initialize(); | 408 initialize(); |
OLD | NEW |