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

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

Issue 2600683002: Run tools/clang-format-js on some of chrome/browser/resources/ (Closed)
Patch Set: event_handler.js Created 4 years 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-text').value; 171 feedbackInfo.email = $('user-email-text').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 28 matching lines...) Expand all
222 function dataUrlToBlob(url) { 223 function dataUrlToBlob(url) {
223 var mimeString = url.split(',')[0].split(':')[1].split(';')[0]; 224 var mimeString = url.split(',')[0].split(':')[1].split(';')[0];
224 var data = atob(url.split(',')[1]); 225 var data = atob(url.split(',')[1]);
225 var dataArray = []; 226 var dataArray = [];
226 for (var i = 0; i < data.length; ++i) 227 for (var i = 0; i < data.length; ++i)
227 dataArray.push(data.charCodeAt(i)); 228 dataArray.push(data.charCodeAt(i));
228 229
229 return new Blob([new Uint8Array(dataArray)], {type: mimeString}); 230 return new Blob([new Uint8Array(dataArray)], {type: mimeString});
230 } 231 }
231 232
232 <if expr="chromeos"> 233 // <if expr="chromeos">
233 /** 234 /**
234 * Update the page when performance feedback state is changed. 235 * Update the page when performance feedback state is changed.
235 */ 236 */
236 function performanceFeedbackChanged() { 237 function performanceFeedbackChanged() {
237 if ($('performance-info-checkbox').checked) { 238 if ($('performance-info-checkbox').checked) {
238 $('attach-file').disabled = true; 239 $('attach-file').disabled = true;
239 $('attach-file').checked = false; 240 $('attach-file').checked = false;
240 241
241 $('screenshot-checkbox').disabled = true; 242 $('screenshot-checkbox').disabled = true;
242 $('screenshot-checkbox').checked = false; 243 $('screenshot-checkbox').checked = false;
243 } else { 244 } else {
244 $('attach-file').disabled = false; 245 $('attach-file').disabled = false;
245 $('screenshot-checkbox').disabled = false; 246 $('screenshot-checkbox').disabled = false;
246 } 247 }
247 } 248 }
248 </if> 249 // </if>
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 == FeedbackFlow.LOGIN) 264 if (feedbackInfo.flow == 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 /**
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 takeScreenshot(function(screenshotCanvas) { 332 takeScreenshot(function(screenshotCanvas) {
332 // We've taken our screenshot, show the feedback page without any 333 // We've taken our screenshot, show the feedback page without any
333 // further delay. 334 // further delay.
334 window.webkitRequestAnimationFrame(function() { 335 window.webkitRequestAnimationFrame(function() {
335 resizeAppWindow(); 336 resizeAppWindow();
336 }); 337 });
337 chrome.app.window.current().show(); 338 chrome.app.window.current().show();
338 339
339 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png'); 340 var screenshotDataUrl = screenshotCanvas.toDataURL('image/png');
340 $('screenshot-image').src = screenshotDataUrl; 341 $('screenshot-image').src = screenshotDataUrl;
341 $('screenshot-image').classList.toggle('wide-screen', 342 $('screenshot-image')
342 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH); 343 .classList.toggle(
344 'wide-screen',
345 $('screenshot-image').width > MAX_SCREENSHOT_WIDTH);
343 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl); 346 feedbackInfo.screenshot = dataUrlToBlob(screenshotDataUrl);
344 }); 347 });
345 348
346 chrome.feedbackPrivate.getUserEmail(function(email) { 349 chrome.feedbackPrivate.getUserEmail(function(email) {
347 $('user-email-text').value = email; 350 $('user-email-text').value = email;
348 }); 351 });
349 352
350 // Initiate getting the system info. 353 // Initiate getting the system info.
351 isSystemInfoReady = false; 354 isSystemInfoReady = false;
352 getSystemInformation(onSystemInformation); 355 getSystemInformation(onSystemInformation);
353 356
354 // An extension called us with an attached file. 357 // An extension called us with an attached file.
355 if (feedbackInfo.attachedFile) { 358 if (feedbackInfo.attachedFile) {
356 $('attached-filename-text').textContent = 359 $('attached-filename-text').textContent =
357 feedbackInfo.attachedFile.name; 360 feedbackInfo.attachedFile.name;
358 attachedFileBlob = feedbackInfo.attachedFile.data; 361 attachedFileBlob = feedbackInfo.attachedFile.data;
359 $('custom-file-container').hidden = false; 362 $('custom-file-container').hidden = false;
360 $('attach-file').hidden = true; 363 $('attach-file').hidden = true;
361 } 364 }
362 365
363 // No URL and file attachment for login screen feedback. 366 // No URL and file attachment for login screen feedback.
364 if (feedbackInfo.flow == FeedbackFlow.LOGIN) { 367 if (feedbackInfo.flow == FeedbackFlow.LOGIN) {
365 $('page-url').hidden = true; 368 $('page-url').hidden = true;
366 $('attach-file-container').hidden = true; 369 $('attach-file-container').hidden = true;
367 $('attach-file-note').hidden = true; 370 $('attach-file-note').hidden = true;
368 } 371 }
369 372
370 <if expr="chromeos"> 373 // <if expr="chromeos">
371 if (feedbackInfo.traceId && ($('performance-info-area'))) { 374 if (feedbackInfo.traceId && ($('performance-info-area'))) {
372 $('performance-info-area').hidden = false; 375 $('performance-info-area').hidden = false;
373 $('performance-info-checkbox').checked = true; 376 $('performance-info-checkbox').checked = true;
374 performanceFeedbackChanged(); 377 performanceFeedbackChanged();
375 $('performance-info-link').onclick = openSlowTraceWindow; 378 $('performance-info-link').onclick = openSlowTraceWindow;
376 } 379 }
377 </if> 380 // </if>
378 chrome.feedbackPrivate.getStrings(function(strings) { 381 chrome.feedbackPrivate.getStrings(function(strings) {
379 loadTimeData.data = strings; 382 loadTimeData.data = strings;
380 i18nTemplate.process(document, loadTimeData); 383 i18nTemplate.process(document, loadTimeData);
381 384
382 if ($('sys-info-url')) { 385 if ($('sys-info-url')) {
383 // Opens a new window showing the full anonymized system+app 386 // Opens a new window showing the full anonymized system+app
384 // information. 387 // information.
385 $('sys-info-url').onclick = function() { 388 $('sys-info-url').onclick = function() {
386 var win = chrome.app.window.get(SYSINFO_WINDOW_ID); 389 var win = chrome.app.window.get(SYSINFO_WINDOW_ID);
387 if (win) { 390 if (win) {
388 win.show(); 391 win.show();
389 return; 392 return;
390 } 393 }
391 chrome.app.window.create( 394 chrome.app.window.create(
392 '/html/sys_info.html', { 395 '/html/sys_info.html', {
393 frame: 'chrome', 396 frame: 'chrome',
394 id: SYSINFO_WINDOW_ID, 397 id: SYSINFO_WINDOW_ID,
395 width: 640, 398 width: 640,
396 height: 400, 399 height: 400,
397 hidden: false, 400 hidden: false,
398 resizable: true 401 resizable: true
399 }, function(appWindow) { 402 },
400 // Define functions for the newly created window. 403 function(appWindow) {
404 // Define functions for the newly created window.
401 405
402 // Gets the full system information for the new window. 406 // Gets the full system information for the new window.
403 appWindow.contentWindow.getFullSystemInfo = 407 appWindow.contentWindow.getFullSystemInfo = function(
404 function(callback) { 408 callback) {
405 if (isSystemInfoReady) { 409 if (isSystemInfoReady) {
406 callback(feedbackInfo.systemInformation); 410 callback(feedbackInfo.systemInformation);
407 return; 411 return;
408 } 412 }
409 413
410 sysInfoPageOnSysInfoReadyCallback = callback; 414 sysInfoPageOnSysInfoReadyCallback = callback;
411 }; 415 };
412 416
413 // Returns the loadTimeData for the new window. 417 // Returns the loadTimeData for the new window.
414 appWindow.contentWindow.getLoadTimeData = function() { 418 appWindow.contentWindow.getLoadTimeData = function() {
415 return loadTimeData; 419 return loadTimeData;
416 }; 420 };
417 }); 421 });
418 }; 422 };
419 } 423 }
420 if ($('histograms-url')) { 424 if ($('histograms-url')) {
421 // Opens a new window showing the histogram metrics. 425 // Opens a new window showing the histogram metrics.
422 $('histograms-url').onclick = 426 $('histograms-url').onclick =
423 windowOpener(STATS_WINDOW_ID, 'chrome://histograms'); 427 windowOpener(STATS_WINDOW_ID, 'chrome://histograms');
424 } 428 }
425 // Make sure our focus starts on the description field. 429 // Make sure our focus starts on the description field.
426 $('description-text').focus(); 430 $('description-text').focus();
427 }); 431 });
428 } 432 }
429 }); 433 });
430 434
431 window.addEventListener('DOMContentLoaded', function() { 435 window.addEventListener('DOMContentLoaded', function() {
432 // Ready to receive the feedback object. 436 // Ready to receive the feedback object.
433 chrome.runtime.sendMessage({ready: true}); 437 chrome.runtime.sendMessage({ready: true});
434 438
435 // Setup our event handlers. 439 // Setup our event handlers.
436 $('attach-file').addEventListener('change', onFileSelected); 440 $('attach-file').addEventListener('change', onFileSelected);
437 $('send-report-button').onclick = sendReport; 441 $('send-report-button').onclick = sendReport;
438 $('cancel-button').onclick = cancel; 442 $('cancel-button').onclick = cancel;
439 $('remove-attached-file').onclick = clearAttachedFile; 443 $('remove-attached-file').onclick = clearAttachedFile;
440 <if expr="chromeos"> 444 // <if expr="chromeos">
dschuyler 2016/12/28 23:59:12 Just pointing this out in case it hadn't been noti
Dan Beam 2016/12/29 00:02:05 we're probably gonna have to change these to cr.is
441 $('performance-info-checkbox').addEventListener( 445 $('performance-info-checkbox')
442 'change', performanceFeedbackChanged); 446 .addEventListener('change', performanceFeedbackChanged);
443 </if> 447 // </if>
444 }); 448 });
445 } 449 }
446 450
447 initialize(); 451 initialize();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698