| 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 "ui/base/l10n/l10n_util.h" |
| 13 |
| 14 namespace keys = extension_manifest_keys; |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 // static |
| 19 const std::string& LocaleInfo::GetDefaultLocale(const Extension* extension) { |
| 20 LocaleInfo* info = static_cast<LocaleInfo*>( |
| 21 extension->GetManifestData(keys::kDefaultLocale)); |
| 22 return info ? info->default_locale_ : EmptyString(); |
| 23 } |
| 24 |
| 25 DefaultLocaleHandler::DefaultLocaleHandler() { |
| 26 } |
| 27 |
| 28 DefaultLocaleHandler::~DefaultLocaleHandler() { |
| 29 } |
| 30 |
| 31 bool DefaultLocaleHandler::Parse(const base::Value* value, |
| 32 Extension* extension, |
| 33 string16* error) { |
| 34 scoped_ptr<LocaleInfo> info(new LocaleInfo); |
| 35 if (!value->GetAsString(&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 |