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

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

Issue 2600683002: Run tools/clang-format-js on some of chrome/browser/resources/ (Closed)
Patch Set: hackhackhack Created 3 years, 11 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 (function() { 5 (function() {
6 'use strict'; 6 'use strict';
7 7
8 cr.define('cr.translateInternals', function() { 8 cr.define('cr.translateInternals', function() {
9 9
10 var detectionLogs_ = null; 10 var detectionLogs_ = null;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 ul = document.querySelector('#prefs-blocked-languages ul'); 150 ul = document.querySelector('#prefs-blocked-languages ul');
151 ul.innerHTML = ''; 151 ul.innerHTML = '';
152 152
153 if ('translate_blocked_languages' in detail) { 153 if ('translate_blocked_languages' in detail) {
154 var langs = detail['translate_blocked_languages']; 154 var langs = detail['translate_blocked_languages'];
155 155
156 langs.forEach(function(langCode) { 156 langs.forEach(function(langCode) {
157 var text = formatLanguageCode(langCode); 157 var text = formatLanguageCode(langCode);
158 158
159 var li = createLIWithDismissingButton(text, function() { 159 var li = createLIWithDismissingButton(text, function() {
160 chrome.send('removePrefItem', 160 chrome.send('removePrefItem', ['blocked_languages', langCode]);
161 ['blocked_languages', langCode]);
162 }); 161 });
163 ul.appendChild(li); 162 ul.appendChild(li);
164 }); 163 });
165 } 164 }
166 165
167 ul = document.querySelector('#prefs-language-blacklist ul'); 166 ul = document.querySelector('#prefs-language-blacklist ul');
168 ul.innerHTML = ''; 167 ul.innerHTML = '';
169 168
170 if ('translate_language_blacklist' in detail) { 169 if ('translate_language_blacklist' in detail) {
171 var langs = detail['translate_language_blacklist']; 170 var langs = detail['translate_language_blacklist'];
172 171
173 langs.forEach(function(langCode) { 172 langs.forEach(function(langCode) {
174 var text = formatLanguageCode(langCode); 173 var text = formatLanguageCode(langCode);
175 174
176 var li = createLIWithDismissingButton(text, function() { 175 var li = createLIWithDismissingButton(text, function() {
177 chrome.send('removePrefItem', 176 chrome.send('removePrefItem', ['language_blacklist', langCode]);
178 ['language_blacklist', langCode]);
179 }); 177 });
180 ul.appendChild(li); 178 ul.appendChild(li);
181 }); 179 });
182 } 180 }
183 181
184 ul = document.querySelector('#prefs-site-blacklist ul'); 182 ul = document.querySelector('#prefs-site-blacklist ul');
185 ul.innerHTML = ''; 183 ul.innerHTML = '';
186 184
187 if ('translate_site_blacklist' in detail) { 185 if ('translate_site_blacklist' in detail) {
188 var sites = detail['translate_site_blacklist']; 186 var sites = detail['translate_site_blacklist'];
(...skipping 11 matching lines...) Expand all
200 198
201 if ('translate_whitelists' in detail) { 199 if ('translate_whitelists' in detail) {
202 var pairs = detail['translate_whitelists']; 200 var pairs = detail['translate_whitelists'];
203 201
204 Object.keys(pairs).forEach(function(fromLangCode) { 202 Object.keys(pairs).forEach(function(fromLangCode) {
205 var toLangCode = pairs[fromLangCode]; 203 var toLangCode = pairs[fromLangCode];
206 var text = formatLanguageCode(fromLangCode) + ' \u2192 ' + 204 var text = formatLanguageCode(fromLangCode) + ' \u2192 ' +
207 formatLanguageCode(toLangCode); 205 formatLanguageCode(toLangCode);
208 206
209 var li = createLIWithDismissingButton(text, function() { 207 var li = createLIWithDismissingButton(text, function() {
210 chrome.send('removePrefItem', 208 chrome.send(
211 ['whitelists', fromLangCode, toLangCode]); 209 'removePrefItem', ['whitelists', fromLangCode, toLangCode]);
212 }); 210 });
213 ul.appendChild(li); 211 ul.appendChild(li);
214 }); 212 });
215 } 213 }
216 214
217 var p = $('prefs-too-often-denied'); 215 var p = $('prefs-too-often-denied');
218 p.classList.toggle('prefs-setting-disabled', 216 p.classList.toggle(
219 !detail['translate_too_often_denied']); 217 'prefs-setting-disabled', !detail['translate_too_often_denied']);
220 p.appendChild(createDismissingButton( 218 p.appendChild(createDismissingButton(
221 chrome.send.bind(null, 'removePrefItem', ['too_often_denied']))); 219 chrome.send.bind(null, 'removePrefItem', ['too_often_denied'])));
222 220
223 p = document.querySelector('#prefs-dump p'); 221 p = document.querySelector('#prefs-dump p');
224 var content = JSON.stringify(detail, null, 2); 222 var content = JSON.stringify(detail, null, 2);
225 p.textContent = content; 223 p.textContent = content;
226 } 224 }
227 225
228 /** 226 /**
229 * Handles the message of 'supportedLanguagesUpdated' from the browser. 227 * Handles the message of 'supportedLanguagesUpdated' from the browser.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 function onCountryUpdated(details) { 259 function onCountryUpdated(details) {
262 var p; 260 var p;
263 p = $('country-override'); 261 p = $('country-override');
264 262
265 p.innerHTML = ''; 263 p.innerHTML = '';
266 264
267 if ('country' in details) { 265 if ('country' in details) {
268 var country = details['country']; 266 var country = details['country'];
269 267
270 var h2 = $('override-variations-country'); 268 var h2 = $('override-variations-country');
271 h2.title = ( 269 h2.title =
272 'Changing this value will override the permanent country stored ' + 270 ('Changing this value will override the permanent country stored ' +
273 'by variations. Normally, this value gets automatically updated ' + 271 'by variations. Normally, this value gets automatically updated ' +
274 'with a new value received from the variations server when ' + 272 'with a new value received from the variations server when ' +
275 'Chrome is updated.'); 273 'Chrome is updated.');
276 274
277 var input = document.createElement('input'); 275 var input = document.createElement('input');
278 input.type = 'text'; 276 input.type = 'text';
279 input.value = country; 277 input.value = country;
280 278
281 var button = document.createElement('button'); 279 var button = document.createElement('button');
282 button.textContent = 'update'; 280 button.textContent = 'update';
283 button.addEventListener('click', function() { 281 button.addEventListener('click', function() {
284 chrome.send('overrideCountry', [input.value]); 282 chrome.send('overrideCountry', [input.value]);
285 }, false); 283 }, false);
286 p.appendChild(input); 284 p.appendChild(input);
287 p.appendChild(document.createElement('br')); 285 p.appendChild(document.createElement('br'));
288 p.appendChild(button); 286 p.appendChild(button);
289 287
290 if ('update' in details && details['update']) { 288 if ('update' in details && details['update']) {
291 var div1 = document.createElement('div'); 289 var div1 = document.createElement('div');
292 div1.textContent = 'Permanent stored country updated.'; 290 div1.textContent = 'Permanent stored country updated.';
293 var div2 = document.createElement('div'); 291 var div2 = document.createElement('div');
294 div2.textContent = ('You will need to restart your browser ' + 292 div2.textContent =
295 'for the changes to take effect.'); 293 ('You will need to restart your browser ' +
294 'for the changes to take effect.');
296 p.appendChild(div1); 295 p.appendChild(div1);
297 p.appendChild(div2); 296 p.appendChild(div2);
298 } 297 }
299 } else { 298 } else {
300 p.textContent = 'Could not load country info from Variations.'; 299 p.textContent = 'Could not load country info from Variations.';
301 } 300 }
302 } 301 }
303 302
304 /** 303 /**
305 * Adds '0's to |number| as a string. |width| is length of the string 304 * Adds '0's to |number| as a string. |width| is length of the string
(...skipping 27 matching lines...) Expand all
333 var minute = date.getMinutes(); 332 var minute = date.getMinutes();
334 var second = date.getSeconds(); 333 var second = date.getSeconds();
335 334
336 var yearStr = padWithZeros(year, 4); 335 var yearStr = padWithZeros(year, 4);
337 var monthStr = padWithZeros(month, 2); 336 var monthStr = padWithZeros(month, 2);
338 var dayStr = padWithZeros(day, 2); 337 var dayStr = padWithZeros(day, 2);
339 var hourStr = padWithZeros(hour, 2); 338 var hourStr = padWithZeros(hour, 2);
340 var minuteStr = padWithZeros(minute, 2); 339 var minuteStr = padWithZeros(minute, 2);
341 var secondStr = padWithZeros(second, 2); 340 var secondStr = padWithZeros(second, 2);
342 341
343 var str = yearStr + '-' + monthStr + '-' + dayStr + ' ' + 342 var str = yearStr + '-' + monthStr + '-' + dayStr + ' ' + hourStr + ':' +
344 hourStr + ':' + minuteStr + ':' + secondStr; 343 minuteStr + ':' + secondStr;
345 344
346 return str; 345 return str;
347 } 346 }
348 347
349 /** 348 /**
350 * Appends a new TD element to the specified element. 349 * Appends a new TD element to the specified element.
351 * 350 *
352 * @param {string} parent The element to which a new TD element is appended. 351 * @param {string} parent The element to which a new TD element is appended.
353 * @param {string} content The text content of the element. 352 * @param {string} content The text content of the element.
354 * @param {string} className The class name of the element. 353 * @param {string} className The class name of the element.
(...skipping 11 matching lines...) Expand all
366 * 365 *
367 * @param {Object} detail The object which represents the logs. 366 * @param {Object} detail The object which represents the logs.
368 */ 367 */
369 function onLanguageDetectionInfoAdded(detail) { 368 function onLanguageDetectionInfoAdded(detail) {
370 cr.translateInternals.detectionLogs().push(detail); 369 cr.translateInternals.detectionLogs().push(detail);
371 370
372 var tr = document.createElement('tr'); 371 var tr = document.createElement('tr');
373 372
374 appendTD(tr, formatDate(new Date(detail['time'])), 'detection-logs-time'); 373 appendTD(tr, formatDate(new Date(detail['time'])), 'detection-logs-time');
375 appendTD(tr, detail['url'], 'detection-logs-url'); 374 appendTD(tr, detail['url'], 'detection-logs-url');
376 appendTD(tr, formatLanguageCode(detail['content_language']), 375 appendTD(
377 'detection-logs-content-language'); 376 tr, formatLanguageCode(detail['content_language']),
378 appendTD(tr, formatLanguageCode(detail['cld_language']), 377 'detection-logs-content-language');
379 'detection-logs-cld-language'); 378 appendTD(
379 tr, formatLanguageCode(detail['cld_language']),
380 'detection-logs-cld-language');
380 appendTD(tr, detail['is_cld_reliable'], 'detection-logs-is-cld-reliable'); 381 appendTD(tr, detail['is_cld_reliable'], 'detection-logs-is-cld-reliable');
381 appendTD(tr, detail['has_notranslate'], 'detection-logs-has-notranslate'); 382 appendTD(tr, detail['has_notranslate'], 'detection-logs-has-notranslate');
382 appendTD(tr, formatLanguageCode(detail['html_root_language']), 383 appendTD(
383 'detection-logs-html-root-language'); 384 tr, formatLanguageCode(detail['html_root_language']),
384 appendTD(tr, formatLanguageCode(detail['adopted_language']), 385 'detection-logs-html-root-language');
385 'detection-logs-adopted-language'); 386 appendTD(
386 appendTD(tr, formatLanguageCode(detail['content']), 387 tr, formatLanguageCode(detail['adopted_language']),
387 'detection-logs-content'); 388 'detection-logs-adopted-language');
389 appendTD(
390 tr, formatLanguageCode(detail['content']), 'detection-logs-content');
388 391
389 // TD (and TR) can't use the CSS property 'max-height', so DIV 392 // TD (and TR) can't use the CSS property 'max-height', so DIV
390 // in the content is needed. 393 // in the content is needed.
391 var contentTD = tr.querySelector('.detection-logs-content'); 394 var contentTD = tr.querySelector('.detection-logs-content');
392 var div = document.createElement('div'); 395 var div = document.createElement('div');
393 div.textContent = contentTD.textContent; 396 div.textContent = contentTD.textContent;
394 contentTD.textContent = ''; 397 contentTD.textContent = '';
395 contentTD.appendChild(div); 398 contentTD.appendChild(div);
396 399
397 var tabpanel = $('tabpanel-detection-logs'); 400 var tabpanel = $('tabpanel-detection-logs');
(...skipping 23 matching lines...) Expand all
421 } 424 }
422 425
423 /** 426 /**
424 * Handles the message of 'translateEventDetailsAdded' from the browser. 427 * Handles the message of 'translateEventDetailsAdded' from the browser.
425 * 428 *
426 * @param {Object} details The object which contains event information. 429 * @param {Object} details The object which contains event information.
427 */ 430 */
428 function onTranslateEventDetailsAdded(details) { 431 function onTranslateEventDetailsAdded(details) {
429 var tr = document.createElement('tr'); 432 var tr = document.createElement('tr');
430 appendTD(tr, formatDate(new Date(details['time'])), 'event-logs-time'); 433 appendTD(tr, formatDate(new Date(details['time'])), 'event-logs-time');
431 appendTD(tr, details['filename'] + ': ' + details['line'], 434 appendTD(
432 'event-logs-place'); 435 tr, details['filename'] + ': ' + details['line'], 'event-logs-place');
433 appendTD(tr, details['message'], 'event-logs-message'); 436 appendTD(tr, details['message'], 'event-logs-message');
434 437
435 var tbody = $('tabpanel-event-logs').getElementsByTagName('tbody')[0]; 438 var tbody = $('tabpanel-event-logs').getElementsByTagName('tbody')[0];
436 tbody.appendChild(tr); 439 tbody.appendChild(tr);
437 } 440 }
438 441
439 /** 442 /**
440 * The callback entry point from the browser. This function will be 443 * The callback entry point from the browser. This function will be
441 * called by the browser. 444 * called by the browser.
442 * 445 *
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 var data = JSON.stringify(cr.translateInternals.detectionLogs()); 479 var data = JSON.stringify(cr.translateInternals.detectionLogs());
477 var blob = new Blob([data], {'type': 'text/json'}); 480 var blob = new Blob([data], {'type': 'text/json'});
478 var url = URL.createObjectURL(blob); 481 var url = URL.createObjectURL(blob);
479 var filename = 'translate_internals_detect_logs_dump.json'; 482 var filename = 'translate_internals_detect_logs_dump.json';
480 483
481 var a = document.createElement('a'); 484 var a = document.createElement('a');
482 a.setAttribute('href', url); 485 a.setAttribute('href', url);
483 a.setAttribute('download', filename); 486 a.setAttribute('download', filename);
484 487
485 var event = document.createEvent('MouseEvent'); 488 var event = document.createEvent('MouseEvent');
486 event.initMouseEvent('click', true, true, window, 0, 489 event.initMouseEvent(
487 0, 0, 0, 0, 0, 0, 0, 0, 0, null); 490 'click', true, true, window, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, null);
488 a.dispatchEvent(event); 491 a.dispatchEvent(event);
489 } 492 }
490 493
491 return { 494 return {
492 detectionLogs: detectionLogs, 495 detectionLogs: detectionLogs,
493 initialize: initialize, 496 initialize: initialize,
494 messageHandler: messageHandler, 497 messageHandler: messageHandler,
495 }; 498 };
496 }); 499 });
497 500
498 /** 501 /**
499 * The entry point of the UI. 502 * The entry point of the UI.
500 */ 503 */
501 function main() { 504 function main() {
502 cr.doc.addEventListener('DOMContentLoaded', 505 cr.doc.addEventListener(
503 cr.translateInternals.initialize); 506 'DOMContentLoaded', cr.translateInternals.initialize);
504 } 507 }
505 508
506 main(); 509 main();
507 })(); 510 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698