OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extensions/extension_i18n_api.h" | 5 #include "chrome/browser/extensions/extension_i18n_api.h" |
6 | 6 |
7 #include "chrome/browser/profile.h" | 7 #include "chrome/browser/profile.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
9 | 9 |
10 namespace extension_i18n_api_functions { | |
11 const char kGetAcceptLanguagesFunction[] = "i18n.getAcceptLanguages"; | |
12 } // namespace extension_i18n_api_functions | |
13 | |
14 namespace { | 10 namespace { |
15 // Errors. | 11 // Errors. |
16 const char kEmptyAcceptLanguagesError[] = "accept-languages is empty."; | 12 const char kEmptyAcceptLanguagesError[] = "accept-languages is empty."; |
17 } // namespace | 13 } // namespace |
18 | 14 |
19 bool GetAcceptLanguagesFunction::RunImpl() { | 15 bool GetAcceptLanguagesFunction::RunImpl() { |
20 std::wstring acceptLanguages = | 16 std::wstring acceptLanguages = |
21 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages); | 17 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages); |
22 // Currently, there are 2 ways to set browser's accept-languages: through UI | 18 // Currently, there are 2 ways to set browser's accept-languages: through UI |
23 // or directly modify the preference file. The accept-languages set through | 19 // or directly modify the preference file. The accept-languages set through |
(...skipping 26 matching lines...) Expand all Loading... |
50 // ending with ','. | 46 // ending with ','. |
51 if (end == std::wstring::npos || begin >= acceptLanguages.length()) | 47 if (end == std::wstring::npos || begin >= acceptLanguages.length()) |
52 break; | 48 break; |
53 } | 49 } |
54 if (static_cast<ListValue*>(result_.get())->GetSize() == 0) { | 50 if (static_cast<ListValue*>(result_.get())->GetSize() == 0) { |
55 error_ = kEmptyAcceptLanguagesError; | 51 error_ = kEmptyAcceptLanguagesError; |
56 return false; | 52 return false; |
57 } | 53 } |
58 return true; | 54 return true; |
59 } | 55 } |
OLD | NEW |