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.
5 #include "chrome/common/extensions/api/spellcheck/spellcheck_handler.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "extensions/common/manifest_constants.h"
10 namespace extensions {
12 namespace keys = manifest_keys;
13 namespace errors = manifest_errors;
15 SpellcheckDictionaryInfo::SpellcheckDictionaryInfo() {
18 SpellcheckDictionaryInfo::~SpellcheckDictionaryInfo() {
21 SpellcheckHandler::SpellcheckHandler() {
24 SpellcheckHandler::~SpellcheckHandler() {
27 bool SpellcheckHandler::Parse(Extension* extension, string16* error) {
28 const base::DictionaryValue* spellcheck_value = NULL;
29 if (!extension->manifest()->GetDictionary(keys::kSpellcheck,
31 *error = ASCIIToUTF16(errors::kInvalidSpellcheck);
34 scoped_ptr<SpellcheckDictionaryInfo> spellcheck_info(
35 new SpellcheckDictionaryInfo);
36 if (!spellcheck_value->HasKey(keys::kSpellcheckDictionaryLanguage) ||
37 !spellcheck_value->GetString(keys::kSpellcheckDictionaryLanguage,
38 &spellcheck_info->language)) {
39 *error = ASCIIToUTF16(errors::kInvalidSpellcheckDictionaryLanguage);
42 if (!spellcheck_value->HasKey(keys::kSpellcheckDictionaryLocale) ||
43 !spellcheck_value->GetString(keys::kSpellcheckDictionaryLocale,
44 &spellcheck_info->locale)) {
45 *error = ASCIIToUTF16(errors::kInvalidSpellcheckDictionaryLocale);
48 if (!spellcheck_value->HasKey(keys::kSpellcheckDictionaryFormat) ||
49 !spellcheck_value->GetString(keys::kSpellcheckDictionaryFormat,
50 &spellcheck_info->format)) {
51 *error = ASCIIToUTF16(errors::kInvalidSpellcheckDictionaryFormat);
54 if (!spellcheck_value->HasKey(keys::kSpellcheckDictionaryPath) ||
55 !spellcheck_value->GetString(keys::kSpellcheckDictionaryPath,
56 &spellcheck_info->path)) {
57 *error = ASCIIToUTF16(errors::kInvalidSpellcheckDictionaryPath);
60 extension->SetManifestData(keys::kSpellcheck, spellcheck_info.release());
64 const std::vector<std::string> SpellcheckHandler::Keys() const {
65 return SingleKey(keys::kSpellcheck);
68 } // namespace extensions