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

Side by Side Diff: chrome/browser/translate/translate_prefs.cc

Issue 18114010: Bug fix: Merging language sets to create 'translate_blocked_languages' may be evaded (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/translate/translate_prefs.h" 5 #include "chrome/browser/translate/translate_prefs.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 // - original language -> one target language to auto-translate 317 // - original language -> one target language to auto-translate
318 // - each time that the user enables the "Always translate..." option, that 318 // - each time that the user enables the "Always translate..." option, that
319 // target lang overwrites the previous one. 319 // target lang overwrites the previous one.
320 // - this results in a one-to-one relationship between source lang and target 320 // - this results in a one-to-one relationship between source lang and target
321 // lang 321 // lang
322 // - we replace old list of target langs with the last target lang in list, 322 // - we replace old list of target langs with the last target lang in list,
323 // assuming the last (i.e. most recent) target lang is what user wants to 323 // assuming the last (i.e. most recent) target lang is what user wants to
324 // keep auto-translated. 324 // keep auto-translated.
325 DictionaryPrefUpdate update(user_prefs, kPrefTranslateWhitelists); 325 DictionaryPrefUpdate update(user_prefs, kPrefTranslateWhitelists);
326 DictionaryValue* dict = update.Get(); 326 DictionaryValue* dict = update.Get();
327 if (!dict || dict->empty()) 327 if (dict && !dict->empty()) {
328 return; 328 DictionaryValue::Iterator iter(*dict);
329 DictionaryValue::Iterator iter(*dict); 329 while (!iter.IsAtEnd()) {
330 while (!iter.IsAtEnd()) { 330 const ListValue* list = NULL;
331 const ListValue* list = NULL; 331 if (!iter.value().GetAsList(&list) || !list)
332 if (!iter.value().GetAsList(&list) || !list) 332 break; // Dictionary has either been migrated or new format.
333 break; // Dictionary has either been migrated or new format. 333 std::string key = iter.key();
334 std::string key = iter.key(); 334 // Advance the iterator before removing the current element.
335 // Advance the iterator before removing the current element. 335 iter.Advance();
336 iter.Advance(); 336 std::string target_lang;
337 std::string target_lang; 337 if (list->empty() ||
338 if (list->empty() || !list->GetString(list->GetSize() - 1, &target_lang) || 338 !list->GetString(list->GetSize() - 1, &target_lang) ||
339 target_lang.empty()) { 339 target_lang.empty()) {
340 dict->Remove(key, NULL); 340 dict->Remove(key, NULL);
341 } else { 341 } else {
342 dict->SetString(key, target_lang); 342 dict->SetString(key, target_lang);
343 }
343 } 344 }
344 } 345 }
345 346
346 // Get the union of the blacklist and the Accept languages, and set this to 347 // Get the union of the blacklist and the Accept languages, and set this to
347 // the new language set 'translate_blocked_languages'. This is used for the 348 // the new language set 'translate_blocked_languages'. This is used for the
348 // settings UI for Translate and configration to determine which langauage 349 // settings UI for Translate and configration to determine which langauage
349 // should be translated instead of the blacklist. The blacklist is no longer 350 // should be translated instead of the blacklist. The blacklist is no longer
350 // used after launching the settings UI. 351 // used after launching the settings UI.
351 // After that, Set 'translate_languages_not_translate' to Accept languages to 352 // After that, Set 'translate_languages_not_translate' to Accept languages to
352 // enable settings for users. 353 // enable settings for users.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 484
484 bool TranslatePrefs::IsListEmpty(const char* pref_id) const { 485 bool TranslatePrefs::IsListEmpty(const char* pref_id) const {
485 const ListValue* blacklist = prefs_->GetList(pref_id); 486 const ListValue* blacklist = prefs_->GetList(pref_id);
486 return (blacklist == NULL || blacklist->empty()); 487 return (blacklist == NULL || blacklist->empty());
487 } 488 }
488 489
489 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const { 490 bool TranslatePrefs::IsDictionaryEmpty(const char* pref_id) const {
490 const DictionaryValue* dict = prefs_->GetDictionary(pref_id); 491 const DictionaryValue* dict = prefs_->GetDictionary(pref_id);
491 return (dict == NULL || dict->empty()); 492 return (dict == NULL || dict->empty());
492 } 493 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698