Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: chrome/browser/resources/feedback/js/feedback.js

Issue 1794513002: Fix sending multiple feedback reports within short durations of each other (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: simplify a lot Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 // Clear the system information if the user doesn't want it to be sent.
180 // The user chose to include the system information as part of the report. 185 if (!useSystemInfo)
181 // If they are not ready yet, we have to send the report later. 186 feedbackInfo.systemInformation = null;
xiyuan 2016/03/16 16:39:28 It is probably safer to remember useSystemInfo in
afakhry 2016/03/16 17:51:22 Thanks for catching this. Done.
182 if (!isSystemInfoReady()) {
183 // The report will be sent later by the feedback extension's background
184 // page (see event_handler.js).
185 sendReportLater(feedbackInfo);
186 187
187 // No landing page for login screen feedback. 188 // Request sending the report, show the landing page (if allowed), and close
188 if (feedbackInfo.flow != FeedbackFlow.LOGIN) 189 // this window right away. The FeedbackRequest object that represents this
189 window.open(FEEDBACK_LANDING_PAGE, '_blank'); 190 // report will take care of sending the report in the background.
190 window.close(); 191 sendFeedbackReport(useSystemInfo);
191 return true; 192 if (feedbackInfo.flow != FeedbackFlow.LOGIN)
192 } 193 window.open(FEEDBACK_LANDING_PAGE, '_blank');
193 } 194 window.close();
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; 195 return true;
203 } 196 }
204 197
205 /** 198 /**
206 * Click listener for the cancel button. 199 * Click listener for the cancel button.
207 * @param {Event} e The click event being handled. 200 * @param {Event} e The click event being handled.
208 */ 201 */
209 function cancel(e) { 202 function cancel(e) {
210 e.preventDefault(); 203 e.preventDefault();
211 window.close(); 204 window.close();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 if (feedbackInfo.flow == FeedbackFlow.LOGIN) 253 if (feedbackInfo.flow == FeedbackFlow.LOGIN)
261 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN; 254 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN;
262 height = Math.max(height, minHeight); 255 height = Math.max(height, minHeight);
263 256
264 chrome.app.window.current().resizeTo(width, height); 257 chrome.app.window.current().resizeTo(width, height);
265 } 258 }
266 259
267 /** 260 /**
268 * A callback to be invoked when the background page of this extension receives 261 * A callback to be invoked when the background page of this extension receives
269 * the system information. 262 * the system information.
270 * @param {Object} sysInfo The received system information.
271 */ 263 */
272 function onSystemInformation(sysInfo) { 264 function onSystemInformation() {
273 // Concatenate the feedbackInfo's systemInformation with the newly received 265 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. 266 // In case the sys_info_page needs to be notified by this event, do so.
283 if (sysInfoPageOnSysInfoReadyCallback != null) { 267 if (sysInfoPageOnSysInfoReadyCallback != null) {
284 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation); 268 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation);
285 sysInfoPageOnSysInfoReadyCallback = null; 269 sysInfoPageOnSysInfoReadyCallback = null;
286 } 270 }
287 } 271 }
288 272
289 /** 273 /**
290 * Initializes our page. 274 * Initializes our page.
291 * Flow: 275 * Flow:
292 * .) DOMContent Loaded -> . Request feedbackInfo object 276 * .) DOMContent Loaded -> . Request feedbackInfo object
293 * . Setup page event handlers 277 * . Setup page event handlers
294 * .) Feedback Object Received -> . take screenshot 278 * .) Feedback Object Received -> . take screenshot
295 * . request email 279 * . request email
296 * . request System info 280 * . request System info
297 * . request i18n strings 281 * . request i18n strings
298 * .) Screenshot taken -> . Show Feedback window. 282 * .) Screenshot taken -> . Show Feedback window.
299 */ 283 */
300 function initialize() { 284 function initialize() {
301 // Add listener to receive the feedback info object. 285 // Add listener to receive the feedback info object.
302 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { 286 chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
303 if (request.sentFromEventPage) { 287 if (request.sentFromEventPage) {
304 feedbackInfo = request.data;
305
306 if (!feedbackInfo.flow) 288 if (!feedbackInfo.flow)
307 feedbackInfo.flow = FeedbackFlow.REGULAR; 289 feedbackInfo.flow = FeedbackFlow.REGULAR;
308 290
309 $('description-text').textContent = feedbackInfo.description; 291 $('description-text').textContent = feedbackInfo.description;
310 if (feedbackInfo.pageUrl) 292 if (feedbackInfo.pageUrl)
311 $('page-url-text').value = feedbackInfo.pageUrl; 293 $('page-url-text').value = feedbackInfo.pageUrl;
312 294
313 takeScreenshot(function(screenshotCanvas) { 295 takeScreenshot(function(screenshotCanvas) {
314 // We've taken our screenshot, show the feedback page without any 296 // We've taken our screenshot, show the feedback page without any
315 // further delay. 297 // further delay.
316 window.webkitRequestAnimationFrame(function() { 298 window.webkitRequestAnimationFrame(function() {
317 resizeAppWindow(); 299 resizeAppWindow();
318 }); 300 });
319 chrome.app.window.current().show(); 301 chrome.app.window.current().show();
320 302
321 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png'); 303 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png');
322 $('screenshot-image').src = screenshotDataUrl; 304 $('screenshot-image').src = screenshotDataUrl;
323 $('screenshot-image').classList.toggle('wide-screen', 305 $('screenshot-image').classList.toggle('wide-screen',
324 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH); 306 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH);
325 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl); 307 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl);
326 }); 308 });
327 309
328 chrome.feedbackPrivate.getUserEmail(function(email) { 310 chrome.feedbackPrivate.getUserEmail(function(email) {
329 $('user-email-text').value = email; 311 $('user-email-text').value = email;
330 }); 312 });
331 313
332 // Initiate getting the system info and use it to prepare the full 314 // Initiate getting the system info.
333 // feedback info. 315 isSystemInfoReady = false;
334 getSystemInformation(onSystemInformation); 316 getSystemInformation(onSystemInformation);
335 317
336 // An extension called us with an attached file. 318 // An extension called us with an attached file.
337 if (feedbackInfo.attachedFile) { 319 if (feedbackInfo.attachedFile) {
338 $('attached-filename-text').textContent = 320 $('attached-filename-text').textContent =
339 feedbackInfo.attachedFile.name; 321 feedbackInfo.attachedFile.name;
340 attachedFileBlob = feedbackInfo.attachedFile.data; 322 attachedFileBlob = feedbackInfo.attachedFile.data;
341 $('custom-file-container').hidden = false; 323 $('custom-file-container').hidden = false;
342 $('attach-file').hidden = true; 324 $('attach-file').hidden = true;
343 } 325 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 width: 600, 360 width: 600,
379 height: 400, 361 height: 400,
380 hidden: false, 362 hidden: false,
381 resizable: true 363 resizable: true
382 }, function(appWindow) { 364 }, function(appWindow) {
383 // Define functions for the newly created window. 365 // Define functions for the newly created window.
384 366
385 // Gets the full system information for the new window. 367 // Gets the full system information for the new window.
386 appWindow.contentWindow.getFullSystemInfo = 368 appWindow.contentWindow.getFullSystemInfo =
387 function(callback) { 369 function(callback) {
388 if (isSystemInfoReady()) { 370 if (isSystemInfoReady) {
389 callback(feedbackInfo.systemInformation); 371 callback(feedbackInfo.systemInformation);
390 return; 372 return;
391 } 373 }
392 374
393 sysInfoPageOnSysInfoReadyCallback = callback; 375 sysInfoPageOnSysInfoReadyCallback = callback;
394 }; 376 };
395 377
396 // Returns the loadTimeData for the new window. 378 // Returns the loadTimeData for the new window.
397 appWindow.contentWindow.getLoadTimeData = function() { 379 appWindow.contentWindow.getLoadTimeData = function() {
398 return loadTimeData; 380 return loadTimeData;
(...skipping 22 matching lines...) Expand all
421 $('cancel-button').onclick = cancel; 403 $('cancel-button').onclick = cancel;
422 $('remove-attached-file').onclick = clearAttachedFile; 404 $('remove-attached-file').onclick = clearAttachedFile;
423 <if expr="chromeos"> 405 <if expr="chromeos">
424 $('performance-info-checkbox').addEventListener( 406 $('performance-info-checkbox').addEventListener(
425 'change', performanceFeedbackChanged); 407 'change', performanceFeedbackChanged);
426 </if> 408 </if>
427 }); 409 });
428 } 410 }
429 411
430 initialize(); 412 initialize();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698