| OLD | NEW |
| 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_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 177 } |
| 178 static const size_t kLanguageListCallbackNameLength = | 178 static const size_t kLanguageListCallbackNameLength = |
| 179 strlen(kLanguageListCallbackName); | 179 strlen(kLanguageListCallbackName); |
| 180 std::string languages_json = language_list.substr( | 180 std::string languages_json = language_list.substr( |
| 181 kLanguageListCallbackNameLength, | 181 kLanguageListCallbackNameLength, |
| 182 language_list.size() - kLanguageListCallbackNameLength - 1); | 182 language_list.size() - kLanguageListCallbackNameLength - 1); |
| 183 // JSON doesn't support single quotes though this is what is used on the | 183 // JSON doesn't support single quotes though this is what is used on the |
| 184 // translate server so we must replace them with double quotes. | 184 // translate server so we must replace them with double quotes. |
| 185 ReplaceSubstringsAfterOffset(&languages_json, 0, "'", "\""); | 185 ReplaceSubstringsAfterOffset(&languages_json, 0, "'", "\""); |
| 186 scoped_ptr<Value> json_value(base::JSONReader::Read(languages_json, true)); | 186 scoped_ptr<Value> json_value(base::JSONReader::Read(languages_json, true)); |
| 187 if (json_value == NULL || !json_value->IsType(Value::TYPE_DICTIONARY)) { | 187 if (json_value == NULL || !json_value->IsDictionary()) { |
| 188 NOTREACHED(); | 188 NOTREACHED(); |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 // The first level dictionary contains two sub-dict, one for source languages | 191 // The first level dictionary contains two sub-dict, one for source languages |
| 192 // and the other for target languages, we want to use the target languages. | 192 // and the other for target languages, we want to use the target languages. |
| 193 DictionaryValue* language_dict = | 193 DictionaryValue* language_dict = |
| 194 static_cast<DictionaryValue*>(json_value.get()); | 194 static_cast<DictionaryValue*>(json_value.get()); |
| 195 DictionaryValue* target_languages = NULL; | 195 DictionaryValue* target_languages = NULL; |
| 196 if (!language_dict->GetDictionary(kTargetLanguagesKey, &target_languages) || | 196 if (!language_dict->GetDictionary(kTargetLanguagesKey, &target_languages) || |
| 197 target_languages == NULL) { | 197 target_languages == NULL) { |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 return NULL; | 798 return NULL; |
| 799 | 799 |
| 800 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { | 800 for (size_t i = 0; i < wrapper->infobar_count(); ++i) { |
| 801 TranslateInfoBarDelegate* delegate = | 801 TranslateInfoBarDelegate* delegate = |
| 802 wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); | 802 wrapper->GetInfoBarDelegateAt(i)->AsTranslateInfoBarDelegate(); |
| 803 if (delegate) | 803 if (delegate) |
| 804 return delegate; | 804 return delegate; |
| 805 } | 805 } |
| 806 return NULL; | 806 return NULL; |
| 807 } | 807 } |
| OLD | NEW |