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

Side by Side Diff: chrome/browser/resources/settings/languages_page/languages.js

Issue 1372053002: Flesh out the location-page class to make it more general. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from Dan and Michael Created 5 years, 1 month 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 * @fileoverview 'settings-languages' provides convenient access to 6 * @fileoverview 'settings-languages' provides convenient access to
7 * Chrome's language and input method settings. 7 * Chrome's language and input method settings.
8 * 8 *
9 * Instances of this element have a 'languages' property, which reflects the 9 * Instances of this element have a 'languages' property, which reflects the
10 * current language settings. The 'languages' property is read-only, meaning 10 * current language settings. The 'languages' property is read-only, meaning
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 /** 185 /**
186 * Singleton element created when settings-languages is registered. 186 * Singleton element created when settings-languages is registered.
187 * Generates the languages model on start-up, and updates it whenever Chrome's 187 * Generates the languages model on start-up, and updates it whenever Chrome's
188 * pref store and other settings change. These updates propagate to each 188 * pref store and other settings change. These updates propagate to each
189 * <settings-language> instance so that their 'languages' property updates 189 * <settings-language> instance so that their 'languages' property updates
190 * like any other Polymer property. 190 * like any other Polymer property.
191 */ 191 */
192 Polymer({ 192 Polymer({
193 is: 'settings-languages-singleton', 193 is: 'settings-languages-singleton',
194 194
195 behaviors: [PrefsBehavior],
196
195 properties: { 197 properties: {
196 /** 198 /**
197 * @type {LanguagesModel|undefined} 199 * @type {LanguagesModel|undefined}
198 */ 200 */
199 languages: { 201 languages: {
200 type: Object, 202 type: Object,
201 notify: true, 203 notify: true,
202 }, 204 },
203 205
204 /** 206 /**
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 for (var i = 0; i < this.languages.enabledLanguages.length; i++) { 400 for (var i = 0; i < this.languages.enabledLanguages.length; i++) {
399 var translateCode = this.convertLanguageCodeForTranslate( 401 var translateCode = this.convertLanguageCodeForTranslate(
400 this.languages.enabledLanguages[i].language.code); 402 this.languages.enabledLanguages[i].language.code);
401 this.set( 403 this.set(
402 'languages.enabledLanguages.' + i + '.state.translateEnabled', 404 'languages.enabledLanguages.' + i + '.state.translateEnabled',
403 !translateBlockedMap[translateCode]); 405 !translateBlockedMap[translateCode]);
404 } 406 }
405 }, 407 },
406 408
407 /** 409 /**
408 * Gets the pref at the given key. Asserts if the pref is not found.
409 * @param {string} key
410 * @return {!chrome.settingsPrivate.PrefObject}
411 */
412 getPref_: function(key) {
413 var pref = /** @type {!chrome.settingsPrivate.PrefObject} */(
414 this.get(key, this.prefs));
415 assert(typeof pref != 'undefined', 'Pref is missing: ' + key);
416 return pref;
417 },
418
419 /**
420 * Sets the value of the pref at the given key. Asserts if the pref is not
421 * found.
422 * @param {string} key
423 * @param {*} value
424 */
425 setPrefValue_: function(key, value) {
426 this.getPref_(key);
427 this.set('prefs.' + key + '.value', value);
428 },
429
430 /**
431 * Deletes the given item from the pref at the given key if the item is found. 410 * Deletes the given item from the pref at the given key if the item is found.
432 * Asserts if the pref itself is not found or is not an Array type. 411 * Asserts if the pref itself is not found or is not an Array type.
433 * @param {string} key 412 * @param {string} key
434 * @param {*} item 413 * @param {*} item
435 */ 414 */
436 deletePrefItem_: function(key, item) { 415 deletePrefItem_: function(key, item) {
437 assert(this.getPref_(key).type == chrome.settingsPrivate.PrefType.LIST); 416 assert(this.getPref_(key).type == chrome.settingsPrivate.PrefType.LIST);
438 this.arrayDelete('prefs.' + key + '.value', item); 417 this.arrayDelete('prefs.' + key + '.value', item);
439 }, 418 },
440 419
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 // necessary as a language code for the Translate server. 557 // necessary as a language code for the Translate server.
579 return languageCode; 558 return languageCode;
580 } 559 }
581 if (main in kTranslateLanguageSynonyms) 560 if (main in kTranslateLanguageSynonyms)
582 return kTranslateLanguageSynonyms[main]; 561 return kTranslateLanguageSynonyms[main];
583 562
584 return main; 563 return main;
585 }, 564 },
586 }); 565 });
587 })(); 566 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698