Chromium Code Reviews| 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 (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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 var text = formatLanguageCode(language); | 246 var text = formatLanguageCode(language); |
| 247 if (details['alpha_languages'].indexOf(language) != -1) | 247 if (details['alpha_languages'].indexOf(language) != -1) |
| 248 text += ' - alpha'; | 248 text += ' - alpha'; |
| 249 li.innerText = text; | 249 li.innerText = text; |
| 250 | 250 |
| 251 ul.appendChild(li); | 251 ul.appendChild(li); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 /** | 255 /** |
| 256 * Addes '0's to |number| as a string. |width| is length of the string | 256 * Handles the message of 'countryUpdated' from the browser. |
| 257 * | |
| 258 * @param {Object} details the object containing the country | |
| 259 * information. | |
| 260 */ | |
| 261 function onCountryUpdated(details) { | |
| 262 var p; | |
| 263 p = $('country-override'); | |
| 264 | |
| 265 p.innerHTML = ''; | |
| 266 | |
| 267 if ('country' in details) { | |
| 268 var country = details['country']; | |
| 269 | |
| 270 var input = document.createElement('input'); | |
| 271 input.type = 'text'; | |
|
Takashi Toyoshima
2016/04/22 07:10:08
Question: Is it safe to allow arbitrary string for
Alexei Svitkine (slow)
2016/04/22 14:50:13
Yep, it's safe. It's just stored in prefs and used
| |
| 272 input.value = country; | |
| 273 | |
| 274 var button = document.createElement('button'); | |
| 275 button.textContent = 'update'; | |
| 276 button.addEventListener('click', function() { | |
| 277 chrome.send('overrideCountry', [input.value]); | |
| 278 }, false); | |
| 279 p.appendChild(input); | |
| 280 p.appendChild(document.createElement('br')); | |
| 281 p.appendChild(button); | |
| 282 | |
| 283 if ('update' in details && details['update']) { | |
|
Takashi Toyoshima
2016/04/22 07:10:08
IIUC, this configuration isn't directly used by Tr
Alexei Svitkine (slow)
2016/04/22 14:50:13
Maybe we can title it something like "Override Var
hamelphi
2016/04/22 17:20:05
Added a text explanation about the variable. Alexe
| |
| 284 var div1 = document.createElement('div'); | |
| 285 div1.textContent = 'Permanent stored country updated.'; | |
| 286 var div2 = document.createElement('div'); | |
| 287 div2.textContent = ('You will need to restart your browser ' + | |
| 288 'for the changes to take effect.'); | |
| 289 p.appendChild(div1); | |
| 290 p.appendChild(div2); | |
| 291 } | |
| 292 } else { | |
| 293 p.textContent = 'Could not load country info from Variations.'; | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 /** | |
| 298 * Adds '0's to |number| as a string. |width| is length of the string | |
| 257 * including '0's. | 299 * including '0's. |
| 258 * | 300 * |
| 259 * @param {string} number The number to be converted into a string. | 301 * @param {string} number The number to be converted into a string. |
| 260 * @param {number} width The width of the returned string. | 302 * @param {number} width The width of the returned string. |
| 261 * @return {string} The formatted string. | 303 * @return {string} The formatted string. |
| 262 */ | 304 */ |
| 263 function padWithZeros(number, width) { | 305 function padWithZeros(number, width) { |
| 264 var numberStr = number.toString(); | 306 var numberStr = number.toString(); |
| 265 var restWidth = width - numberStr.length; | 307 var restWidth = width - numberStr.length; |
| 266 if (restWidth <= 0) | 308 if (restWidth <= 0) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 switch (message) { | 440 switch (message) { |
| 399 case 'languageDetectionInfoAdded': | 441 case 'languageDetectionInfoAdded': |
| 400 onLanguageDetectionInfoAdded(details); | 442 onLanguageDetectionInfoAdded(details); |
| 401 break; | 443 break; |
| 402 case 'prefsUpdated': | 444 case 'prefsUpdated': |
| 403 onPrefsUpdated(details); | 445 onPrefsUpdated(details); |
| 404 break; | 446 break; |
| 405 case 'supportedLanguagesUpdated': | 447 case 'supportedLanguagesUpdated': |
| 406 onSupportedLanguagesUpdated(details); | 448 onSupportedLanguagesUpdated(details); |
| 407 break; | 449 break; |
| 450 case 'countryUpdated': | |
| 451 onCountryUpdated(details); | |
| 452 break; | |
| 408 case 'translateErrorDetailsAdded': | 453 case 'translateErrorDetailsAdded': |
| 409 onTranslateErrorDetailsAdded(details); | 454 onTranslateErrorDetailsAdded(details); |
| 410 break; | 455 break; |
| 411 case 'translateEventDetailsAdded': | 456 case 'translateEventDetailsAdded': |
| 412 onTranslateEventDetailsAdded(details); | 457 onTranslateEventDetailsAdded(details); |
| 413 break; | 458 break; |
| 414 default: | 459 default: |
| 415 console.error('Unknown message:', message); | 460 console.error('Unknown message:', message); |
| 416 break; | 461 break; |
| 417 } | 462 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 446 /** | 491 /** |
| 447 * The entry point of the UI. | 492 * The entry point of the UI. |
| 448 */ | 493 */ |
| 449 function main() { | 494 function main() { |
| 450 cr.doc.addEventListener('DOMContentLoaded', | 495 cr.doc.addEventListener('DOMContentLoaded', |
| 451 cr.translateInternals.initialize); | 496 cr.translateInternals.initialize); |
| 452 } | 497 } |
| 453 | 498 |
| 454 main(); | 499 main(); |
| 455 })(); | 500 })(); |
| OLD | NEW |