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

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

Issue 2939273002: DO NOT SUBMIT: what chrome/browser/resources/ could eventually look like with clang-format (Closed)
Patch Set: Created 3 years, 6 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 /** 5 /**
6 * @type {string} 6 * @type {string}
7 * @const 7 * @const
8 */ 8 */
9 var SRT_DOWNLOAD_PAGE = 'https://www.google.com/chrome/cleanup-tool/'; 9 var SRT_DOWNLOAD_PAGE = 'https://www.google.com/chrome/cleanup-tool/';
10 10
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 var description = $('description-text'); 153 var description = $('description-text');
154 description.placeholder = loadTimeData.getString('no-description'); 154 description.placeholder = loadTimeData.getString('no-description');
155 description.focus(); 155 description.focus();
156 return false; 156 return false;
157 } 157 }
158 158
159 // Prevent double clicking from sending additional reports. 159 // Prevent double clicking from sending additional reports.
160 $('send-report-button').disabled = true; 160 $('send-report-button').disabled = true;
161 console.log('Feedback: Sending report'); 161 console.log('Feedback: Sending report');
162 if (!feedbackInfo.attachedFile && attachedFileBlob) { 162 if (!feedbackInfo.attachedFile && attachedFileBlob) {
163 feedbackInfo.attachedFile = { name: $('attach-file').value, 163 feedbackInfo.attachedFile = {
164 data: attachedFileBlob }; 164 name: $('attach-file').value,
165 data: attachedFileBlob
166 };
165 } 167 }
166 168
167 feedbackInfo.description = $('description-text').value; 169 feedbackInfo.description = $('description-text').value;
168 feedbackInfo.pageUrl = $('page-url-text').value; 170 feedbackInfo.pageUrl = $('page-url-text').value;
169 feedbackInfo.email = $('user-email-drop-down').value; 171 feedbackInfo.email = $('user-email-drop-down').value;
170 172
171 var useSystemInfo = false; 173 var useSystemInfo = false;
172 var useHistograms = false; 174 var useHistograms = false;
173 if ($('sys-info-checkbox') != null && 175 if ($('sys-info-checkbox') != null && $('sys-info-checkbox').checked) {
174 $('sys-info-checkbox').checked) {
175 // Send histograms along with system info. 176 // Send histograms along with system info.
176 useSystemInfo = useHistograms = true; 177 useSystemInfo = useHistograms = true;
177 } 178 }
178 // <if expr="chromeos"> 179 // <if expr="chromeos">
179 if ($('performance-info-checkbox') == null || 180 if ($('performance-info-checkbox') == null ||
180 !($('performance-info-checkbox').checked)) { 181 !($('performance-info-checkbox').checked)) {
181 feedbackInfo.traceId = null; 182 feedbackInfo.traceId = null;
182 } 183 }
183 // </if> 184 // </if>
184 185
185 feedbackInfo.sendHistograms = useHistograms; 186 feedbackInfo.sendHistograms = useHistograms;
186 187
187 // If the user doesn't want to send the screenshot. 188 // If the user doesn't want to send the screenshot.
188 if (!$('screenshot-checkbox').checked) 189 if (!$('screenshot-checkbox').checked)
189 feedbackInfo.screenshot = null; 190 feedbackInfo.screenshot = null;
190 191
191 var productId = parseInt('' + feedbackInfo.productId); 192 var productId = parseInt('' + feedbackInfo.productId);
192 if (isNaN(productId)) { 193 if (isNaN(productId)) {
193 // For apps that still use a string value as the |productId|, we must clear 194 // For apps that still use a string value as the |productId|, we must clear
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 250
250 function resizeAppWindow() { 251 function resizeAppWindow() {
251 // We pick the width from the titlebar, which has no margins. 252 // We pick the width from the titlebar, which has no margins.
252 var width = $('title-bar').scrollWidth; 253 var width = $('title-bar').scrollWidth;
253 if (width < FEEDBACK_MIN_WIDTH) 254 if (width < FEEDBACK_MIN_WIDTH)
254 width = FEEDBACK_MIN_WIDTH; 255 width = FEEDBACK_MIN_WIDTH;
255 256
256 // We get the height by adding the titlebar height and the content height + 257 // We get the height by adding the titlebar height and the content height +
257 // margins. We can't get the margins for the content-pane here by using 258 // margins. We can't get the margins for the content-pane here by using
258 // style.margin - the variable seems to not exist. 259 // style.margin - the variable seems to not exist.
259 var height = $('title-bar').scrollHeight + 260 var height = $('title-bar').scrollHeight + $('content-pane').scrollHeight +
260 $('content-pane').scrollHeight + CONTENT_MARGIN_HEIGHT; 261 CONTENT_MARGIN_HEIGHT;
261 262
262 var minHeight = FEEDBACK_MIN_HEIGHT; 263 var minHeight = FEEDBACK_MIN_HEIGHT;
263 if (feedbackInfo.flow == chrome.feedbackPrivate.FeedbackFlow.LOGIN) 264 if (feedbackInfo.flow == chrome.feedbackPrivate.FeedbackFlow.LOGIN)
264 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN; 265 minHeight = FEEDBACK_MIN_HEIGHT_LOGIN;
265 height = Math.max(height, minHeight); 266 height = Math.max(height, minHeight);
266 267
267 chrome.app.window.current().resizeTo(width, height); 268 chrome.app.window.current().resizeTo(width, height);
268 } 269 }
269 270
270 /** 271 /**
271 * A callback to be invoked when the background page of this extension receives 272 * A callback to be invoked when the background page of this extension receives
272 * the system information. 273 * the system information.
273 */ 274 */
274 function onSystemInformation() { 275 function onSystemInformation() {
275 isSystemInfoReady = true; 276 isSystemInfoReady = true;
276 // In case the sys_info_page needs to be notified by this event, do so. 277 // In case the sys_info_page needs to be notified by this event, do so.
277 if (sysInfoPageOnSysInfoReadyCallback != null) { 278 if (sysInfoPageOnSysInfoReadyCallback != null) {
278 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation); 279 sysInfoPageOnSysInfoReadyCallback(feedbackInfo.systemInformation);
279 sysInfoPageOnSysInfoReadyCallback = null; 280 sysInfoPageOnSysInfoReadyCallback = null;
280 } 281 }
281 } 282 }
282 283
283 /** 284 /**
284 * Close the window after 100ms delay. 285 * Close the window after 100ms delay.
285 */ 286 */
286 function scheduleWindowClose() { 287 function scheduleWindowClose() {
287 setTimeout(function() { window.close();}, 100); 288 setTimeout(function() {
289 window.close();
290 }, 100);
288 } 291 }
289 292
290 /** 293 /**
291 * Initializes our page. 294 * Initializes our page.
292 * Flow: 295 * Flow:
293 * .) DOMContent Loaded -> . Request feedbackInfo object 296 * .) DOMContent Loaded -> . Request feedbackInfo object
294 * . Setup page event handlers 297 * . Setup page event handlers
295 * .) Feedback Object Received -> . take screenshot 298 * .) Feedback Object Received -> . take screenshot
296 * . request email 299 * . request email
297 * . request System info 300 * . request System info
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 takeScreenshot(function(screenshotCanvas) { 342 takeScreenshot(function(screenshotCanvas) {
340 // We've taken our screenshot, show the feedback page without any 343 // We've taken our screenshot, show the feedback page without any
341 // further delay. 344 // further delay.
342 window.webkitRequestAnimationFrame(function() { 345 window.webkitRequestAnimationFrame(function() {
343 resizeAppWindow(); 346 resizeAppWindow();
344 }); 347 });
345 chrome.app.window.current().show(); 348 chrome.app.window.current().show();
346 349
347 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png'); 350 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png');
348 $('screenshot-image').src = screenshotDataUrl; 351 $('screenshot-image').src = screenshotDataUrl;
349 $('screenshot-image').classList.toggle('wide-screen', 352 $('screenshot-image')
350 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH); 353 .classList.toggle(
354 'wide-screen',
355 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH);
351 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl); 356 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl);
352 }); 357 });
353 358
354 chrome.feedbackPrivate.getUserEmail(function(email) { 359 chrome.feedbackPrivate.getUserEmail(function(email) {
355 // Never add an empty option. 360 // Never add an empty option.
356 if (!email) 361 if (!email)
357 return; 362 return;
358 var optionElement = document.createElement('option'); 363 var optionElement = document.createElement('option');
359 optionElement.value = email; 364 optionElement.value = email;
360 optionElement.text = email; 365 optionElement.text = email;
361 optionElement.selected = true; 366 optionElement.selected = true;
362 // Make sure the "Report anonymously" option comes last. 367 // Make sure the "Report anonymously" option comes last.
363 $('user-email-drop-down').insertBefore(optionElement, 368 $('user-email-drop-down')
364 $('anonymous-user-option')); 369 .insertBefore(optionElement, $('anonymous-user-option'));
365 370
366 // Now we can unhide the user email section: 371 // Now we can unhide the user email section:
367 $('user-email').hidden = false; 372 $('user-email').hidden = false;
368 }); 373 });
369 374
370 // Initiate getting the system info. 375 // Initiate getting the system info.
371 isSystemInfoReady = false; 376 isSystemInfoReady = false;
372 getSystemInformation(onSystemInformation); 377 getSystemInformation(onSystemInformation);
373 378
374 // An extension called us with an attached file. 379 // An extension called us with an attached file.
375 if (feedbackInfo.attachedFile) { 380 if (feedbackInfo.attachedFile) {
376 $('attached-filename-text').textContent = 381 $('attached-filename-text').textContent =
377 feedbackInfo.attachedFile.name; 382 feedbackInfo.attachedFile.name;
378 attachedFileBlob = feedbackInfo.attachedFile.data; 383 attachedFileBlob = feedbackInfo.attachedFile.data;
379 $('custom-file-container').hidden = false; 384 $('custom-file-container').hidden = false;
380 $('attach-file').hidden = true; 385 $('attach-file').hidden = true;
381 } 386 }
382 387
383 // No URL and file attachment for login screen feedback. 388 // No URL and file attachment for login screen feedback.
384 if (feedbackInfo.flow == chrome.feedbackPrivate.FeedbackFlow.LOGIN) { 389 if (feedbackInfo.flow == chrome.feedbackPrivate.FeedbackFlow.LOGIN) {
385 $('page-url').hidden = true; 390 $('page-url').hidden = true;
386 $('attach-file-container').hidden = true; 391 $('attach-file-container').hidden = true;
387 $('attach-file-note').hidden = true; 392 $('attach-file-note').hidden = true;
388 } 393 }
389 394
390 // <if expr="chromeos"> 395 // <if expr="chromeos">
391 if (feedbackInfo.traceId && ($('performance-info-area'))) { 396 if (feedbackInfo.traceId && ($('performance-info-area'))) {
392 $('performance-info-area').hidden = false; 397 $('performance-info-area').hidden = false;
393 $('performance-info-checkbox').checked = true; 398 $('performance-info-checkbox').checked = true;
394 performanceFeedbackChanged(); 399 performanceFeedbackChanged();
395 $('performance-info-link').onclick = openSlowTraceWindow; 400 $('performance-info-link').onclick = openSlowTraceWindow;
396 } 401 }
397 // </if> 402 // </if>
398 chrome.feedbackPrivate.getStrings(feedbackInfo.flow, function(strings) { 403 chrome.feedbackPrivate.getStrings(feedbackInfo.flow, function(strings) {
399 loadTimeData.data = strings; 404 loadTimeData.data = strings;
400 i18nTemplate.process(document, loadTimeData); 405 i18nTemplate.process(document, loadTimeData);
401 406
402 if ($('sys-info-url')) { 407 if ($('sys-info-url')) {
403 // Opens a new window showing the full anonymized system+app 408 // Opens a new window showing the full anonymized system+app
404 // information. 409 // information.
405 $('sys-info-url').onclick = function() { 410 $('sys-info-url').onclick = function() {
406 var win = chrome.app.window.get(SYSINFO_WINDOW_ID); 411 var win = chrome.app.window.get(SYSINFO_WINDOW_ID);
407 if (win) { 412 if (win) {
408 win.show(); 413 win.show();
409 return; 414 return;
410 } 415 }
411 chrome.app.window.create( 416 chrome.app.window.create(
412 '/html/sys_info.html', { 417 '/html/sys_info.html', {
413 frame: 'chrome', 418 frame: 'chrome',
414 id: SYSINFO_WINDOW_ID, 419 id: SYSINFO_WINDOW_ID,
415 width: 640, 420 width: 640,
416 height: 400, 421 height: 400,
417 hidden: false, 422 hidden: false,
418 resizable: true 423 resizable: true
419 }, function(appWindow) { 424 },
420 // Define functions for the newly created window. 425 function(appWindow) {
426 // Define functions for the newly created window.
421 427
422 // Gets the full system information for the new window. 428 // Gets the full system information for the new window.
423 appWindow.contentWindow.getFullSystemInfo = 429 appWindow.contentWindow.getFullSystemInfo = function(
424 function(callback) { 430 callback) {
425 if (isSystemInfoReady) { 431 if (isSystemInfoReady) {
426 callback(feedbackInfo.systemInformation); 432 callback(feedbackInfo.systemInformation);
427 return; 433 return;
428 } 434 }
429 435
430 sysInfoPageOnSysInfoReadyCallback = callback; 436 sysInfoPageOnSysInfoReadyCallback = callback;
431 }; 437 };
432 438
433 // Returns the loadTimeData for the new window. 439 // Returns the loadTimeData for the new window.
434 appWindow.contentWindow.getLoadTimeData = function() { 440 appWindow.contentWindow.getLoadTimeData = function() {
435 return loadTimeData; 441 return loadTimeData;
436 }; 442 };
437 }); 443 });
438 }; 444 };
439 } 445 }
440 if ($('histograms-url')) { 446 if ($('histograms-url')) {
441 // Opens a new window showing the histogram metrics. 447 // Opens a new window showing the histogram metrics.
442 $('histograms-url').onclick = 448 $('histograms-url').onclick =
443 windowOpener(STATS_WINDOW_ID, 'chrome://histograms'); 449 windowOpener(STATS_WINDOW_ID, 'chrome://histograms');
444 } 450 }
445 // Make sure our focus starts on the description field. 451 // Make sure our focus starts on the description field.
446 $('description-text').focus(); 452 $('description-text').focus();
447 }); 453 });
448 } 454 }
449 }); 455 });
450 456
451 window.addEventListener('DOMContentLoaded', function() { 457 window.addEventListener('DOMContentLoaded', function() {
452 // Ready to receive the feedback object. 458 // Ready to receive the feedback object.
453 chrome.runtime.sendMessage({ready: true}); 459 chrome.runtime.sendMessage({ready: true});
454 460
455 // Setup our event handlers. 461 // Setup our event handlers.
456 $('attach-file').addEventListener('change', onFileSelected); 462 $('attach-file').addEventListener('change', onFileSelected);
457 $('send-report-button').onclick = sendReport; 463 $('send-report-button').onclick = sendReport;
458 $('cancel-button').onclick = cancel; 464 $('cancel-button').onclick = cancel;
459 $('remove-attached-file').onclick = clearAttachedFile; 465 $('remove-attached-file').onclick = clearAttachedFile;
460 // <if expr="chromeos"> 466 // <if expr="chromeos">
461 $('performance-info-checkbox').addEventListener( 467 $('performance-info-checkbox')
462 'change', performanceFeedbackChanged); 468 .addEventListener('change', performanceFeedbackChanged);
463 // </if> 469 // </if>
464 }); 470 });
465 } 471 }
466 472
467 initialize(); 473 initialize();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698