| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/common/extensions/api/i18n/default_locale_handler.h" |
| 6 |
| 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/values.h" |
| 11 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 12 #include "chrome/common/extensions/manifest.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 |
| 15 namespace keys = extension_manifest_keys; |
| 16 |
| 17 namespace extensions { |
| 18 |
| 19 // static |
| 20 const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) { |
| 21 LocaleInfo* info = static_cast<LocaleInfo*>( |
| 22 extension->GetManifestData(keys::kDefaultLocale)); |
| 23 return info ? info->default_locale : EmptyString(); |
| 24 } |
| 25 |
| 26 DefaultLocaleHandler::DefaultLocaleHandler() { |
| 27 } |
| 28 |
| 29 DefaultLocaleHandler::~DefaultLocaleHandler() { |
| 30 } |
| 31 |
| 32 bool DefaultLocaleHandler::Parse(Extension* extension, string16* error) { |
| 33 scoped_ptr<LocaleInfo> info(new LocaleInfo); |
| 34 if (!extension->manifest()->GetString(keys::kDefaultLocale, |
| 35 &info->default_locale) || |
| 36 !l10n_util::IsValidLocaleSyntax(info->default_locale)) { |
| 37 *error = ASCIIToUTF16(extension_manifest_errors::kInvalidDefaultLocale); |
| 38 return false; |
| 39 } |
| 40 extension->SetManifestData(keys::kDefaultLocale, info.release()); |
| 41 return true; |
| 42 } |
| 43 |
| 44 } // namespace extensions |
| OLD | NEW |