summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 22:16:31 +0000
committerMHX348@motorola.com <MHX348@motorola.com@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-30 22:16:31 +0000
commit0273969d8ffd29497e074478c07db701058d8167 (patch)
tree688d31d03872679223d2cf360ab9a67ecd46354d
parente95b14cc2d69affc426c4129ee81784c05f01fd2 (diff)
downloadchromium_src-0273969d8ffd29497e074478c07db701058d8167.zip
chromium_src-0273969d8ffd29497e074478c07db701058d8167.tar.gz
chromium_src-0273969d8ffd29497e074478c07db701058d8167.tar.bz2
Move default_locale out of Extension class.
BUG=159265 Review URL: https://chromiumcodereview.appspot.com/12025010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/extensions/api/i18n/i18n_api.cc28
-rw-r--r--chrome/browser/extensions/api/i18n/i18n_api.h27
-rw-r--r--chrome/browser/extensions/api/tabs/tabs_api.cc3
-rw-r--r--chrome/browser/extensions/extension_service_unittest.cc6
-rw-r--r--chrome/browser/extensions/sandboxed_unpacker_unittest.cc7
-rw-r--r--chrome/browser/extensions/user_script_master.cc3
-rw-r--r--chrome/browser/profiles/profile_dependency_manager.cc2
-rw-r--r--chrome/browser/renderer_host/chrome_render_message_filter.cc3
-rw-r--r--chrome/chrome_common.gypi4
-rw-r--r--chrome/chrome_tests_unit.gypi3
-rw-r--r--chrome/common/extensions/api/i18n/default_locale_handler.cc44
-rw-r--r--chrome/common/extensions/api/i18n/default_locale_handler.h36
-rw-r--r--chrome/common/extensions/api/i18n/default_locale_manifest_unittest.cc30
-rw-r--r--chrome/common/extensions/extension.cc12
-rw-r--r--chrome/common/extensions/extension.h5
-rw-r--r--chrome/common/extensions/extension_file_util.cc4
-rw-r--r--chrome/common/extensions/extension_file_util_unittest.cc4
-rw-r--r--chrome/common/extensions/manifest_handler.cc2
-rw-r--r--chrome/common/extensions/manifest_tests/extension_manifests_default_extent_path_unittest.cc (renamed from chrome/common/extensions/manifest_tests/extension_manifests_default_unittest.cc)14
-rw-r--r--chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc9
-rw-r--r--chrome/common/extensions/unpacker.cc5
-rw-r--r--chrome/common/extensions/unpacker_unittest.cc8
-rw-r--r--chrome/utility/chrome_content_utility_client.cc4
23 files changed, 220 insertions, 43 deletions
diff --git a/chrome/browser/extensions/api/i18n/i18n_api.cc b/chrome/browser/extensions/api/i18n/i18n_api.cc
index ad2ef32..4351dad 100644
--- a/chrome/browser/extensions/api/i18n/i18n_api.cc
+++ b/chrome/browser/extensions/api/i18n/i18n_api.cc
@@ -8,18 +8,28 @@
#include <string>
#include <vector>
+#include "base/lazy_instance.h"
#include "base/string_piece.h"
#include "base/string_split.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/extensions/api/i18n.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest_handler.h"
#include "chrome/common/pref_names.h"
namespace GetAcceptLanguages = extensions::api::i18n::GetAcceptLanguages;
+namespace extensions {
+
+namespace {
+
// Errors.
static const char kEmptyAcceptLanguagesError[] = "accept-languages is empty.";
+}
+
bool I18nGetAcceptLanguagesFunction::RunImpl() {
std::string accept_languages =
profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
@@ -51,3 +61,21 @@ bool I18nGetAcceptLanguagesFunction::RunImpl() {
results_ = GetAcceptLanguages::Results::Create(languages);
return true;
}
+
+I18nAPI::I18nAPI(Profile* profile) {
+ ManifestHandler::Register(extension_manifest_keys::kDefaultLocale,
+ new DefaultLocaleHandler);
+}
+
+I18nAPI::~I18nAPI() {
+}
+
+static base::LazyInstance<ProfileKeyedAPIFactory<I18nAPI> >
+ g_factory = LAZY_INSTANCE_INITIALIZER;
+
+// static
+ProfileKeyedAPIFactory<I18nAPI>* I18nAPI::GetFactoryInstance() {
+ return &g_factory.Get();
+}
+
+} // namespace extensions
diff --git a/chrome/browser/extensions/api/i18n/i18n_api.h b/chrome/browser/extensions/api/i18n/i18n_api.h
index 10b4339..9e291dc 100644
--- a/chrome/browser/extensions/api/i18n/i18n_api.h
+++ b/chrome/browser/extensions/api/i18n/i18n_api.h
@@ -5,12 +5,39 @@
#ifndef CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
#define CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
+#include "chrome/browser/extensions/api/profile_keyed_api_factory.h"
#include "chrome/browser/extensions/extension_function.h"
+class Profile;
+
+namespace extensions {
+
class I18nGetAcceptLanguagesFunction : public SyncExtensionFunction {
virtual ~I18nGetAcceptLanguagesFunction() {}
virtual bool RunImpl() OVERRIDE;
DECLARE_EXTENSION_FUNCTION("i18n.getAcceptLanguages", I18N_GETACCEPTLANGUAGES)
};
+class I18nAPI : public ProfileKeyedAPI {
+ public:
+ explicit I18nAPI(Profile* profile);
+ virtual ~I18nAPI();
+
+ // ProfileKeyedAPI implementation.
+ static ProfileKeyedAPIFactory<I18nAPI>* GetFactoryInstance();
+
+ private:
+ friend class ProfileKeyedAPIFactory<I18nAPI>;
+
+ // ProfileKeyedAPI implementation.
+ static const char* service_name() {
+ return "I18nAPI";
+ }
+ static const bool kServiceIsNULLWhileTesting = true;
+
+ DISALLOW_COPY_AND_ASSIGN(I18nAPI);
+};
+
+} // namespace extensions
+
#endif // CHROME_BROWSER_EXTENSIONS_API_I18N_I18N_API_H_
diff --git a/chrome/browser/extensions/api/tabs/tabs_api.cc b/chrome/browser/extensions/api/tabs/tabs_api.cc
index da60264..3f72ba9 100644
--- a/chrome/browser/extensions/api/tabs/tabs_api.cc
+++ b/chrome/browser/extensions/api/tabs/tabs_api.cc
@@ -51,6 +51,7 @@
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/api/tabs.h"
#include "chrome/common/extensions/api/windows.h"
#include "chrome/common/extensions/extension.h"
@@ -2032,7 +2033,7 @@ void ExecuteCodeInTabFunction::DidLoadFile(bool success,
data,
extension->id(),
extension->path(),
- extension->default_locale()));
+ extensions::LocaleInfo::GetDefaultLocale(extension)));
} else {
DidLoadAndLocalizeFile(success, data);
}
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc
index 9ec6427..60a1ca3 100644
--- a/chrome/browser/extensions/extension_service_unittest.cc
+++ b/chrome/browser/extensions/extension_service_unittest.cc
@@ -62,10 +62,12 @@
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/extension_resource.h"
+#include "chrome/common/extensions/manifest_handler.h"
#include "chrome/common/extensions/manifest_url_handler.h"
#include "chrome/common/extensions/permissions/permission_set.h"
#include "chrome/common/pref_names.h"
@@ -534,7 +536,11 @@ void ExtensionServiceTestBase::SetUpTestCase() {
}
void ExtensionServiceTestBase::SetUp() {
+ testing::Test::SetUp();
ExtensionErrorReporter::GetInstance()->ClearErrors();
+ extensions::ManifestHandler::Register(
+ keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
}
class ExtensionServiceTest
diff --git a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
index 1ab1f56..468916e 100644
--- a/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
+++ b/chrome/browser/extensions/sandboxed_unpacker_unittest.cc
@@ -11,6 +11,7 @@
#include "base/values.h"
#include "chrome/browser/extensions/sandboxed_unpacker.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/unpacker.h"
@@ -19,9 +20,6 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
-namespace errors = extension_manifest_errors;
-namespace keys = extension_manifest_keys;
-
using content::BrowserThread;
using testing::_;
using testing::Invoke;
@@ -69,6 +67,9 @@ class SandboxedUnpackerTest : public testing::Test {
// It will delete itself.
client_ = new MockSandboxedUnpackerClient;
client_->DelegateToFake();
+ extensions::ManifestHandler::Register(
+ extension_manifest_keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
}
virtual void TearDown() {
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index 543379b..9c8738f 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -20,6 +20,7 @@
#include "chrome/browser/extensions/extension_system.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_resource.h"
@@ -359,7 +360,7 @@ void UserScriptMaster::Observe(int type,
content::Details<const Extension>(details).ptr();
extensions_info_[extension->id()] =
ExtensionSet::ExtensionPathAndDefaultLocale(
- extension->path(), extension->default_locale());
+ extension->path(), LocaleInfo::GetDefaultLocale(extension));
bool incognito_enabled = extensions::ExtensionSystem::Get(profile_)->
extension_service()->IsIncognitoEnabled(extension->id());
const UserScriptList& scripts = extension->content_scripts();
diff --git a/chrome/browser/profiles/profile_dependency_manager.cc b/chrome/browser/profiles/profile_dependency_manager.cc
index f32fc61..df9f61a 100644
--- a/chrome/browser/profiles/profile_dependency_manager.cc
+++ b/chrome/browser/profiles/profile_dependency_manager.cc
@@ -26,6 +26,7 @@
#include "chrome/browser/extensions/api/file_handlers/file_handlers_api.h"
#include "chrome/browser/extensions/api/font_settings/font_settings_api.h"
#include "chrome/browser/extensions/api/history/history_api.h"
+#include "chrome/browser/extensions/api/i18n/i18n_api.h"
#include "chrome/browser/extensions/api/idle/idle_manager_factory.h"
#include "chrome/browser/extensions/api/input/input.h"
#include "chrome/browser/extensions/api/managed_mode/managed_mode_api.h"
@@ -264,6 +265,7 @@ void ProfileDependencyManager::AssertFactoriesBuilt() {
extensions::FileHandlersAPI::GetFactoryInstance();
extensions::FontSettingsAPI::GetFactoryInstance();
extensions::HistoryAPI::GetFactoryInstance();
+ extensions::I18nAPI::GetFactoryInstance();
extensions::IdleManagerFactory::GetInstance();
#if defined(TOOLKIT_VIEWS)
extensions::InputAPI::GetFactoryInstance();
diff --git a/chrome/browser/renderer_host/chrome_render_message_filter.cc b/chrome/browser/renderer_host/chrome_render_message_filter.cc
index bd55aed..da5419f 100644
--- a/chrome/browser/renderer_host/chrome_render_message_filter.cc
+++ b/chrome/browser/renderer_host/chrome_render_message_filter.cc
@@ -28,6 +28,7 @@
#include "chrome/browser/task_manager/task_manager.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_switches.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_messages.h"
@@ -375,7 +376,7 @@ void ChromeRenderMessageFilter::OnGetExtensionMessageBundle(
std::string default_locale;
if (extension) {
extension_path = extension->path();
- default_locale = extension->default_locale();
+ default_locale = extensions::LocaleInfo::GetDefaultLocale(extension);
}
BrowserThread::PostTask(
diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi
index e991fa4..d41d1a1 100644
--- a/chrome/chrome_common.gypi
+++ b/chrome/chrome_common.gypi
@@ -138,6 +138,8 @@
'common/extensions/api/extension_api.cc',
'common/extensions/api/extension_api.h',
'common/extensions/api/extension_api_stub.cc',
+ 'common/extensions/api/i18n/default_locale_handler.cc',
+ 'common/extensions/api/i18n/default_locale_handler.h',
'common/extensions/api/input_ime/input_components_handler.cc',
'common/extensions/api/input_ime/input_components_handler.h',
'common/extensions/api/file_handlers/file_handlers_parser.cc',
@@ -478,6 +480,8 @@
['include', 'common/extensions/api/extension_action/action_info.h'],
['include', 'common/extensions/api/extension_action/browser_action_handler.cc'],
['include', 'common/extensions/api/extension_action/browser_action_handler.h'],
+ ['include', 'common/extensions/api/i18n/default_locale_handler.cc'],
+ ['include', 'common/extensions/api/i18n/default_locale_handler.h'],
],
}],
['remoting==1', {
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi
index d6b96b6..75cb38a 100644
--- a/chrome/chrome_tests_unit.gypi
+++ b/chrome/chrome_tests_unit.gypi
@@ -1463,6 +1463,7 @@
'common/extensions/api/extension_action/browser_action_manifest_unittest.cc',
'common/extensions/api/extension_action/page_action_manifest_unittest.cc',
'common/extensions/api/extension_action/script_badge_manifest_unittest.cc',
+ 'common/extensions/api/i18n/default_locale_manifest_unittest.cc',
'common/extensions/command_unittest.cc',
'common/extensions/csp_validator_unittest.cc',
'common/extensions/event_filter_unittest.cc',
@@ -1484,7 +1485,7 @@
'common/extensions/manifest_tests/extension_manifests_chromepermission_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_contentscript_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_contentsecuritypolicy_unittest.cc',
- 'common/extensions/manifest_tests/extension_manifests_default_unittest.cc',
+ 'common/extensions/manifest_tests/extension_manifests_default_extent_path_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_devtools_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_excludematches_unittest.cc',
'common/extensions/manifest_tests/extension_manifests_experimental_unittest.cc',
diff --git a/chrome/common/extensions/api/i18n/default_locale_handler.cc b/chrome/common/extensions/api/i18n/default_locale_handler.cc
new file mode 100644
index 0000000..7baa9b59
--- /dev/null
+++ b/chrome/common/extensions/api/i18n/default_locale_handler.cc
@@ -0,0 +1,44 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
+
+#include "base/memory/scoped_ptr.h"
+#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest.h"
+#include "ui/base/l10n/l10n_util.h"
+
+namespace keys = extension_manifest_keys;
+
+namespace extensions {
+
+// static
+const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) {
+ LocaleInfo* info = static_cast<LocaleInfo*>(
+ extension->GetManifestData(keys::kDefaultLocale));
+ return info ? info->default_locale : EmptyString();
+}
+
+DefaultLocaleHandler::DefaultLocaleHandler() {
+}
+
+DefaultLocaleHandler::~DefaultLocaleHandler() {
+}
+
+bool DefaultLocaleHandler::Parse(Extension* extension, string16* error) {
+ scoped_ptr<LocaleInfo> info(new LocaleInfo);
+ if (!extension->manifest()->GetString(keys::kDefaultLocale,
+ &info->default_locale) ||
+ !l10n_util::IsValidLocaleSyntax(info->default_locale)) {
+ *error = ASCIIToUTF16(extension_manifest_errors::kInvalidDefaultLocale);
+ return false;
+ }
+ extension->SetManifestData(keys::kDefaultLocale, info.release());
+ return true;
+}
+
+} // namespace extensions
diff --git a/chrome/common/extensions/api/i18n/default_locale_handler.h b/chrome/common/extensions/api/i18n/default_locale_handler.h
new file mode 100644
index 0000000..112fb96
--- /dev/null
+++ b/chrome/common/extensions/api/i18n/default_locale_handler.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_COMMON_EXTENSIONS_API_I18N_DEFAULT_LOCALE_HANDLER_H_
+#define CHROME_COMMON_EXTENSIONS_API_I18N_DEFAULT_LOCALE_HANDLER_H_
+
+#include <string>
+
+#include "chrome/common/extensions/extension.h"
+#include "chrome/common/extensions/manifest_handler.h"
+
+namespace extensions {
+
+// A structure to hold the locale information for an extension.
+struct LocaleInfo : public Extension::ManifestData {
+ // Default locale for fall back. Can be empty if extension is not localized.
+ std::string default_locale;
+
+ static const std::string& GetDefaultLocale(const Extension* extension);
+};
+
+// Parses the "default_locale" manifest key.
+class DefaultLocaleHandler : public ManifestHandler {
+ public:
+ DefaultLocaleHandler();
+ virtual ~DefaultLocaleHandler();
+
+ virtual bool Parse(Extension* extension, string16* error) OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(DefaultLocaleHandler);
+};
+
+} // namespace extensions
+
+#endif // CHROME_COMMON_EXTENSIONS_API_I18N_DEFAULT_LOCALE_HANDLER_H_
diff --git a/chrome/common/extensions/api/i18n/default_locale_manifest_unittest.cc b/chrome/common/extensions/api/i18n/default_locale_manifest_unittest.cc
new file mode 100644
index 0000000..645a3ff
--- /dev/null
+++ b/chrome/common/extensions/api/i18n/default_locale_manifest_unittest.cc
@@ -0,0 +1,30 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
+#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest_handler.h"
+#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+class DefaultLocaleManifestTest : public ExtensionManifestTest {
+ virtual void SetUp() OVERRIDE {
+ ExtensionManifestTest::SetUp();
+ ManifestHandler::Register(keys::kDefaultLocale,
+ new DefaultLocaleHandler);
+ }
+};
+
+TEST_F(DefaultLocaleManifestTest, DefaultLocale) {
+ LoadAndExpectError("default_locale_invalid.json",
+ errors::kInvalidDefaultLocale);
+
+ scoped_refptr<Extension> extension(
+ LoadAndExpectSuccess("default_locale_valid.json"));
+ EXPECT_EQ("de-AT", LocaleInfo::GetDefaultLocale(extension));
+}
+
+} // namespace extensions
diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc
index 97f67a9..c64e0bb 100644
--- a/chrome/common/extensions/extension.cc
+++ b/chrome/common/extensions/extension.cc
@@ -1927,7 +1927,6 @@ bool Extension::LoadSharedFeatures(
!LoadNaClModules(error) ||
!LoadSandboxedPages(error) ||
!LoadRequirements(error) ||
- !LoadDefaultLocale(error) ||
!LoadOfflineEnabled(error) ||
// LoadBackgroundScripts() must be called before LoadBackgroundPage().
!LoadBackgroundScripts(error) ||
@@ -2212,17 +2211,6 @@ bool Extension::LoadRequirements(string16* error) {
return true;
}
-bool Extension::LoadDefaultLocale(string16* error) {
- if (!manifest_->HasKey(keys::kDefaultLocale))
- return true;
- if (!manifest_->GetString(keys::kDefaultLocale, &default_locale_) ||
- !l10n_util::IsValidLocaleSyntax(default_locale_)) {
- *error = ASCIIToUTF16(errors::kInvalidDefaultLocale);
- return false;
- }
- return true;
-}
-
bool Extension::LoadOfflineEnabled(string16* error) {
// Defaults to false, except for platform apps which are offline by default.
if (!manifest_->HasKey(keys::kOfflineEnabled)) {
diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h
index 4c9986b..a6ead5b 100644
--- a/chrome/common/extensions/extension.h
+++ b/chrome/common/extensions/extension.h
@@ -643,7 +643,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
const extensions::Manifest* manifest() const {
return manifest_.get();
}
- const std::string default_locale() const { return default_locale_; }
bool incognito_split_mode() const { return incognito_split_mode_; }
bool offline_enabled() const { return offline_enabled_; }
const OAuth2Info& oauth2_info() const { return oauth2_info_; }
@@ -785,7 +784,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
bool LoadSandboxedPages(string16* error);
// Must be called after LoadPlugins().
bool LoadRequirements(string16* error);
- bool LoadDefaultLocale(string16* error);
bool LoadOfflineEnabled(string16* error);
bool LoadBackgroundScripts(string16* error);
bool LoadBackgroundScripts(const std::string& key, string16* error);
@@ -906,9 +904,6 @@ class Extension : public base::RefCountedThreadSafe<Extension> {
// The absolute path to the directory the extension is stored in.
FilePath path_;
- // Default locale for fall back. Can be empty if extension is not localized.
- std::string default_locale_;
-
// If true, a separate process will be used for the extension in incognito
// mode.
bool incognito_split_mode_;
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index f6d2e22..99aa826 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.cc
@@ -21,6 +21,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/api/extension_action/action_info.h"
#include "chrome/common/extensions/api/extension_action/browser_action_handler.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
@@ -563,7 +564,8 @@ static bool ValidateLocaleInfo(const Extension& extension,
const FilePath path = extension.path().Append(
Extension::kLocaleFolder);
bool path_exists = file_util::PathExists(path);
- std::string default_locale = extension.default_locale();
+ std::string default_locale =
+ extensions::LocaleInfo::GetDefaultLocale(&extension);
// If both default locale and _locales folder are empty, skip verification.
if (default_locale.empty() && !path_exists)
diff --git a/chrome/common/extensions/extension_file_util_unittest.cc b/chrome/common/extensions/extension_file_util_unittest.cc
index 5418066..87dc1e0 100644
--- a/chrome/common/extensions/extension_file_util_unittest.cc
+++ b/chrome/common/extensions/extension_file_util_unittest.cc
@@ -12,6 +12,7 @@
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/extensions/api/extension_action/browser_action_handler.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/manifest_handler.h"
@@ -31,6 +32,9 @@ class ExtensionFileUtilTest : public testing::Test {
extensions::ManifestHandler::Register(
extension_manifest_keys::kBrowserAction,
new extensions::BrowserActionHandler);
+ extensions::ManifestHandler::Register(
+ keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
}
};
diff --git a/chrome/common/extensions/manifest_handler.cc b/chrome/common/extensions/manifest_handler.cc
index 9d2a9b5..ce214eb 100644
--- a/chrome/common/extensions/manifest_handler.cc
+++ b/chrome/common/extensions/manifest_handler.cc
@@ -41,7 +41,7 @@ bool ManifestHandlerRegistry::ParseExtension(Extension* extension,
ManifestHandler* handler = iter->second.get();
if (extension->manifest()->HasPath(iter->first) ||
handler->AlwaysParseForType(extension->GetType()))
- handler_set.insert(iter->second.get());
+ handler_set.insert(handler);
}
// TODO(yoz): Some handlers may depend on other handlers having already
diff --git a/chrome/common/extensions/manifest_tests/extension_manifests_default_unittest.cc b/chrome/common/extensions/manifest_tests/extension_manifests_default_extent_path_unittest.cc
index 959a161..7f4ea07 100644
--- a/chrome/common/extensions/manifest_tests/extension_manifests_default_unittest.cc
+++ b/chrome/common/extensions/manifest_tests/extension_manifests_default_extent_path_unittest.cc
@@ -2,14 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
-
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace errors = extension_manifest_errors;
-
TEST_F(ExtensionManifestTest, DefaultPathForExtent) {
scoped_refptr<extensions::Extension> extension(
LoadAndExpectSuccess("default_path_for_extent.json"));
@@ -19,12 +16,3 @@ TEST_F(ExtensionManifestTest, DefaultPathForExtent) {
EXPECT_TRUE(extension->web_extent().MatchesURL(
GURL("http://www.google.com/monkey")));
}
-
-TEST_F(ExtensionManifestTest, DefaultLocale) {
- LoadAndExpectError("default_locale_invalid.json",
- errors::kInvalidDefaultLocale);
-
- scoped_refptr<extensions::Extension> extension(
- LoadAndExpectSuccess("default_locale_valid.json"));
- EXPECT_EQ("de-AT", extension->default_locale());
-}
diff --git a/chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc b/chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc
index eb537a1..aa7f5c5f 100644
--- a/chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc
+++ b/chrome/common/extensions/manifest_tests/extension_manifests_initvalue_unittest.cc
@@ -6,6 +6,7 @@
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
#include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
@@ -22,8 +23,12 @@ namespace errors = extension_manifest_errors;
class InitValueManifestTest : public ExtensionManifestTest {
virtual void SetUp() OVERRIDE {
ExtensionManifestTest::SetUp();
- extensions::ManifestHandler::Register(extension_manifest_keys::kOptionsPage,
- new extensions::OptionsPageHandler);
+ extensions::ManifestHandler::Register(
+ extension_manifest_keys::kOptionsPage,
+ new extensions::OptionsPageHandler);
+ extensions::ManifestHandler::Register(
+ extension_manifest_keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
}
};
diff --git a/chrome/common/extensions/unpacker.cc b/chrome/common/extensions/unpacker.cc
index 08eb09b..90ce3fd5a 100644
--- a/chrome/common/extensions/unpacker.cc
+++ b/chrome/common/extensions/unpacker.cc
@@ -15,6 +15,7 @@
#include "base/threading/thread.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_file_util.h"
#include "chrome/common/extensions/extension_l10n_util.h"
@@ -202,8 +203,8 @@ bool Unpacker::Run() {
// Parse all message catalogs (if any).
parsed_catalogs_.reset(new DictionaryValue);
- if (!extension->default_locale().empty()) {
- if (!ReadAllMessageCatalogs(extension->default_locale()))
+ if (!LocaleInfo::GetDefaultLocale(extension).empty()) {
+ if (!ReadAllMessageCatalogs(LocaleInfo::GetDefaultLocale(extension)))
return false; // Error was already reported.
}
diff --git a/chrome/common/extensions/unpacker_unittest.cc b/chrome/common/extensions/unpacker_unittest.cc
index bbb8b55..d2590b3 100644
--- a/chrome/common/extensions/unpacker_unittest.cc
+++ b/chrome/common/extensions/unpacker_unittest.cc
@@ -9,8 +9,10 @@
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
+#include "chrome/common/extensions/manifest_handler.h"
#include "chrome/common/extensions/unpacker.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkBitmap.h"
@@ -29,6 +31,12 @@ public:
LOG(WARNING) << temp_dir_.Delete();
}
+ virtual void SetUp() OVERRIDE {
+ testing::Test::SetUp();
+ extensions::ManifestHandler::Register(keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
+ }
+
void SetupUnpacker(const std::string& crx_name) {
FilePath original_path;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &original_path));
diff --git a/chrome/utility/chrome_content_utility_client.cc b/chrome/utility/chrome_content_utility_client.cc
index 3d710c5..5d1fa23 100644
--- a/chrome/utility/chrome_content_utility_client.cc
+++ b/chrome/utility/chrome_content_utility_client.cc
@@ -18,6 +18,7 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_utility_messages.h"
#include "chrome/common/extensions/api/extension_action/browser_action_handler.h"
+#include "chrome/common/extensions/api/i18n/default_locale_handler.h"
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/extensions/extension_manifest_constants.h"
@@ -52,6 +53,9 @@ void RegisterExtensionManifestHandlers() {
extensions::ManifestHandler::Register(
extension_manifest_keys::kBrowserAction,
new extensions::BrowserActionHandler);
+ extensions::ManifestHandler::Register(
+ extension_manifest_keys::kDefaultLocale,
+ new extensions::DefaultLocaleHandler);
}
} // namespace