| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/i18n/i18n_api.h" | 5 #include "chrome/browser/extensions/api/i18n/i18n_api.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // code, and accept-languages are seperatd by "," without surrrounding | 38 // code, and accept-languages are seperatd by "," without surrrounding |
| 39 // spaces. But we do not do any validation (either the format or the validity | 39 // spaces. But we do not do any validation (either the format or the validity |
| 40 // of the language code) on accept-languages set through editing preference | 40 // of the language code) on accept-languages set through editing preference |
| 41 // file directly. So, here, we're adding extra checks to be resistant to | 41 // file directly. So, here, we're adding extra checks to be resistant to |
| 42 // crashes caused by data corruption. | 42 // crashes caused by data corruption. |
| 43 if (accept_languages.empty()) { | 43 if (accept_languages.empty()) { |
| 44 error_ = kEmptyAcceptLanguagesError; | 44 error_ = kEmptyAcceptLanguagesError; |
| 45 return false; | 45 return false; |
| 46 } | 46 } |
| 47 | 47 |
| 48 std::vector<std::string> languages; | 48 std::vector<std::string> languages = base::SplitString( |
| 49 base::SplitString(accept_languages, ',', &languages); | 49 accept_languages, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 50 languages.erase(std::remove(languages.begin(), languages.end(), ""), | 50 languages.erase(std::remove(languages.begin(), languages.end(), ""), |
| 51 languages.end()); | 51 languages.end()); |
| 52 | 52 |
| 53 if (languages.empty()) { | 53 if (languages.empty()) { |
| 54 error_ = kEmptyAcceptLanguagesError; | 54 error_ = kEmptyAcceptLanguagesError; |
| 55 return false; | 55 return false; |
| 56 } | 56 } |
| 57 | 57 |
| 58 results_ = GetAcceptLanguages::Results::Create(languages); | 58 results_ = GetAcceptLanguages::Results::Create(languages); |
| 59 return true; | 59 return true; |
| 60 } | 60 } |
| 61 | 61 |
| 62 } // namespace extensions | 62 } // namespace extensions |
| OLD | NEW |