| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/extensions/api/i18n/default_locale_handler.h" | 5 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/common/extensions/extension_l10n_util.h" | 13 #include "chrome/common/extensions/extension_l10n_util.h" |
| 14 #include "chrome/common/extensions/extension_manifest_constants.h" | 14 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 15 #include "chrome/common/extensions/manifest.h" | 15 #include "chrome/common/extensions/manifest.h" |
| 16 #include "extensions/common/constants.h" |
| 16 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 18 | 19 |
| 19 namespace keys = extension_manifest_keys; | 20 namespace keys = extension_manifest_keys; |
| 20 namespace errors = extension_manifest_errors; | 21 namespace errors = extension_manifest_errors; |
| 21 | 22 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 | 24 |
| 24 // static | 25 // static |
| 25 const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) { | 26 const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 44 } | 45 } |
| 45 extension->SetManifestData(keys::kDefaultLocale, info.release()); | 46 extension->SetManifestData(keys::kDefaultLocale, info.release()); |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool DefaultLocaleHandler::Validate( | 50 bool DefaultLocaleHandler::Validate( |
| 50 const Extension* extension, | 51 const Extension* extension, |
| 51 std::string* error, | 52 std::string* error, |
| 52 std::vector<InstallWarning>* warnings) const { | 53 std::vector<InstallWarning>* warnings) const { |
| 53 // default_locale and _locales have to be both present or both missing. | 54 // default_locale and _locales have to be both present or both missing. |
| 54 const base::FilePath path = extension->path().Append( | 55 const base::FilePath path = extension->path().Append(kLocaleFolder); |
| 55 Extension::kLocaleFolder); | |
| 56 bool path_exists = file_util::PathExists(path); | 56 bool path_exists = file_util::PathExists(path); |
| 57 std::string default_locale = | 57 std::string default_locale = |
| 58 extensions::LocaleInfo::GetDefaultLocale(extension); | 58 extensions::LocaleInfo::GetDefaultLocale(extension); |
| 59 | 59 |
| 60 // If both default locale and _locales folder are empty, skip verification. | 60 // If both default locale and _locales folder are empty, skip verification. |
| 61 if (default_locale.empty() && !path_exists) | 61 if (default_locale.empty() && !path_exists) |
| 62 return true; | 62 return true; |
| 63 | 63 |
| 64 if (default_locale.empty() && path_exists) { | 64 if (default_locale.empty() && path_exists) { |
| 65 *error = l10n_util::GetStringUTF8( | 65 *error = l10n_util::GetStringUTF8( |
| (...skipping 13 matching lines...) Expand all Loading... |
| 79 extension_l10n_util::GetAllLocales(&all_locales); | 79 extension_l10n_util::GetAllLocales(&all_locales); |
| 80 const base::FilePath default_locale_path = path.AppendASCII(default_locale); | 80 const base::FilePath default_locale_path = path.AppendASCII(default_locale); |
| 81 bool has_default_locale_message_file = false; | 81 bool has_default_locale_message_file = false; |
| 82 | 82 |
| 83 base::FilePath locale_path; | 83 base::FilePath locale_path; |
| 84 while (!(locale_path = locales.Next()).empty()) { | 84 while (!(locale_path = locales.Next()).empty()) { |
| 85 if (extension_l10n_util::ShouldSkipValidation(path, locale_path, | 85 if (extension_l10n_util::ShouldSkipValidation(path, locale_path, |
| 86 all_locales)) | 86 all_locales)) |
| 87 continue; | 87 continue; |
| 88 | 88 |
| 89 base::FilePath messages_path = | 89 base::FilePath messages_path = locale_path.Append(kMessagesFilename); |
| 90 locale_path.Append(Extension::kMessagesFilename); | |
| 91 | 90 |
| 92 if (!file_util::PathExists(messages_path)) { | 91 if (!file_util::PathExists(messages_path)) { |
| 93 *error = base::StringPrintf( | 92 *error = base::StringPrintf( |
| 94 "%s %s", errors::kLocalesMessagesFileMissing, | 93 "%s %s", errors::kLocalesMessagesFileMissing, |
| 95 UTF16ToUTF8(messages_path.LossyDisplayName()).c_str()); | 94 UTF16ToUTF8(messages_path.LossyDisplayName()).c_str()); |
| 96 return false; | 95 return false; |
| 97 } | 96 } |
| 98 | 97 |
| 99 if (locale_path == default_locale_path) | 98 if (locale_path == default_locale_path) |
| 100 has_default_locale_message_file = true; | 99 has_default_locale_message_file = true; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 112 bool DefaultLocaleHandler::AlwaysValidateForType(Manifest::Type type) const { | 111 bool DefaultLocaleHandler::AlwaysValidateForType(Manifest::Type type) const { |
| 113 // Required to validate _locales directory; see Validate. | 112 // Required to validate _locales directory; see Validate. |
| 114 return true; | 113 return true; |
| 115 } | 114 } |
| 116 | 115 |
| 117 const std::vector<std::string> DefaultLocaleHandler::Keys() const { | 116 const std::vector<std::string> DefaultLocaleHandler::Keys() const { |
| 118 return SingleKey(keys::kDefaultLocale); | 117 return SingleKey(keys::kDefaultLocale); |
| 119 } | 118 } |
| 120 | 119 |
| 121 } // namespace extensions | 120 } // namespace extensions |
| OLD | NEW |