summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormichaelpg <michaelpg@chromium.org>2015-10-23 15:39:11 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-23 22:39:56 +0000
commit3c03efbea3549d485ace8ef14859833163ec3972 (patch)
treeada9e5a7d64d990d3013cea9058bd32af57d48c3
parente8ed88e2b03c9e67b13da3a92ede079b0a345f15 (diff)
downloadchromium_src-3c03efbea3549d485ace8ef14859833163ec3972.zip
chromium_src-3c03efbea3549d485ace8ef14859833163ec3972.tar.gz
chromium_src-3c03efbea3549d485ace8ef14859833163ec3972.tar.bz2
Implement chrome.languageSettingsPrivate custom spell check functions
Implement functions relating to the custom spell check dictionary. These functions will be used by the Material Design Settings page. BUG=479043 Review URL: https://codereview.chromium.org/1373073003 Cr-Commit-Position: refs/heads/master@{#355910}
-rw-r--r--chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc93
-rw-r--r--chrome/browser/extensions/api/language_settings_private/language_settings_private_api.h47
-rw-r--r--chrome/common/extensions/api/language_settings_private.idl8
-rw-r--r--extensions/browser/extension_function_histogram_value.h2
-rw-r--r--third_party/closure_compiler/externs/language_settings_private.js16
-rw-r--r--tools/metrics/histograms/histograms.xml2
6 files changed, 153 insertions, 15 deletions
diff --git a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc
index 1a76caf..e310f15 100644
--- a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc
+++ b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.cc
@@ -26,7 +26,6 @@
#include "chrome/common/extensions/api/language_settings_private.h"
#include "chrome/common/spellcheck_common.h"
#include "components/translate/core/browser/translate_download_manager.h"
-#include "components/translate/core/common/translate_util.h"
#include "third_party/icu/source/i18n/unicode/coll.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_collator.h"
@@ -114,11 +113,9 @@ LanguageSettingsPrivateGetLanguageListFunction::Run() {
language.display_name_rtl.reset(new bool(true));
if (locale_set.count(pair.first) > 0)
language.supports_ui.reset(new bool(true));
- if (spellcheck_language_set.count(language.code) > 0)
+ if (spellcheck_language_set.count(pair.first) > 0)
language.supports_spellcheck.reset(new bool(true));
- std::string translate_code = language.code;
- translate::ToTranslateLanguageSynonym(&translate_code);
- if (translate_language_set.count(translate_code) > 0)
+ if (translate_language_set.count(pair.first) > 0)
language.supports_translate.reset(new bool(true));
language_list->Append(language.ToValue());
@@ -183,14 +180,86 @@ LanguageSettingsPrivateGetSpellcheckWordsFunction::Run() {
SpellcheckServiceFactory::GetForContext(browser_context());
SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary();
+ if (dictionary->IsLoaded())
+ return RespondNow(OneArgument(GetSpellcheckWords().release()));
+
+ dictionary->AddObserver(this);
+ AddRef(); // Balanced in OnCustomDictionaryLoaded().
+ return RespondLater();
+}
+
+void
+LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryLoaded() {
+ SpellcheckService* service =
+ SpellcheckServiceFactory::GetForContext(browser_context());
+ service->GetCustomDictionary()->RemoveObserver(this);
+ Respond(OneArgument(GetSpellcheckWords().release()));
+ Release();
+}
+
+void
+LanguageSettingsPrivateGetSpellcheckWordsFunction::OnCustomDictionaryChanged(
+ const SpellcheckCustomDictionary::Change& dictionary_change) {
+ NOTREACHED() << "SpellcheckCustomDictionary::Observer: "
+ "OnCustomDictionaryChanged() called before "
+ "OnCustomDictionaryLoaded()";
+}
+
+scoped_ptr<base::ListValue>
+LanguageSettingsPrivateGetSpellcheckWordsFunction::GetSpellcheckWords() const {
+ SpellcheckService* service =
+ SpellcheckServiceFactory::GetForContext(browser_context());
+ SpellcheckCustomDictionary* dictionary = service->GetCustomDictionary();
+ DCHECK(dictionary->IsLoaded());
+
+ // TODO(michaelpg): Sort using app locale.
scoped_ptr<base::ListValue> word_list(new base::ListValue());
- // TODO(michaelpg): observe the dictionary and respond later if not loaded.
- if (dictionary->IsLoaded()) {
- const std::set<std::string>& words = dictionary->GetWords();
- for (const std::string& word : words)
- word_list->AppendString(word);
- }
- return RespondNow(OneArgument(word_list.release()));
+ const std::set<std::string>& words = dictionary->GetWords();
+ for (const std::string& word : words)
+ word_list->AppendString(word);
+ return word_list.Pass();
+}
+
+LanguageSettingsPrivateAddSpellcheckWordFunction::
+ LanguageSettingsPrivateAddSpellcheckWordFunction() {
+}
+
+LanguageSettingsPrivateAddSpellcheckWordFunction::
+ ~LanguageSettingsPrivateAddSpellcheckWordFunction() {
+}
+
+ExtensionFunction::ResponseAction
+LanguageSettingsPrivateAddSpellcheckWordFunction::Run() {
+ scoped_ptr<language_settings_private::AddSpellcheckWord::Params> params =
+ language_settings_private::AddSpellcheckWord::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ SpellcheckService* service =
+ SpellcheckServiceFactory::GetForContext(browser_context());
+ bool success = service->GetCustomDictionary()->AddWord(params->word);
+
+ return RespondNow(OneArgument(new base::FundamentalValue(success)));
+}
+
+LanguageSettingsPrivateRemoveSpellcheckWordFunction::
+ LanguageSettingsPrivateRemoveSpellcheckWordFunction() {
+}
+
+LanguageSettingsPrivateRemoveSpellcheckWordFunction::
+ ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() {
+}
+
+ExtensionFunction::ResponseAction
+LanguageSettingsPrivateRemoveSpellcheckWordFunction::Run() {
+ scoped_ptr<language_settings_private::RemoveSpellcheckWord::Params> params =
+ language_settings_private::RemoveSpellcheckWord::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params.get());
+
+ SpellcheckService* service =
+ SpellcheckServiceFactory::GetForContext(browser_context());
+ bool success = service->GetCustomDictionary()->RemoveWord(params->word);
+
+ return RespondNow(OneArgument(new base::FundamentalValue(success)));
}
LanguageSettingsPrivateGetTranslateTargetLanguageFunction::
diff --git a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.h b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.h
index 7d22108..1702754 100644
--- a/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.h
+++ b/chrome/browser/extensions/api/language_settings_private/language_settings_private_api.h
@@ -73,7 +73,8 @@ class LanguageSettingsPrivateGetSpellcheckDictionaryStatusesFunction
// Implements the languageSettingsPrivate.getSpellcheckWords method.
class LanguageSettingsPrivateGetSpellcheckWordsFunction
- : public UIThreadExtensionFunction {
+ : public UIThreadExtensionFunction,
+ public SpellcheckCustomDictionary::Observer {
public:
LanguageSettingsPrivateGetSpellcheckWordsFunction();
DECLARE_EXTENSION_FUNCTION("languageSettingsPrivate.getSpellcheckWords",
@@ -85,10 +86,54 @@ class LanguageSettingsPrivateGetSpellcheckWordsFunction
// ExtensionFunction overrides.
ResponseAction Run() override;
+ // SpellcheckCustomDictionary::Observer overrides.
+ void OnCustomDictionaryLoaded() override;
+ void OnCustomDictionaryChanged(
+ const SpellcheckCustomDictionary::Change& dictionary_change) override;
+
+ // Returns the list of words from the loaded custom dictionary.
+ scoped_ptr<base::ListValue> GetSpellcheckWords() const;
+
private:
DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateGetSpellcheckWordsFunction);
};
+// Implements the languageSettingsPrivate.addSpellcheckWord method.
+class LanguageSettingsPrivateAddSpellcheckWordFunction
+ : public UIThreadExtensionFunction {
+ public:
+ LanguageSettingsPrivateAddSpellcheckWordFunction();
+ DECLARE_EXTENSION_FUNCTION("languageSettingsPrivate.addSpellcheckWord",
+ LANGUAGESETTINGSPRIVATE_ADDSPELLCHECKWORD)
+
+ protected:
+ ~LanguageSettingsPrivateAddSpellcheckWordFunction() override;
+
+ // ExtensionFunction overrides.
+ ResponseAction Run() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateAddSpellcheckWordFunction);
+};
+
+// Implements the languageSettingsPrivate.removeSpellcheckWord method.
+class LanguageSettingsPrivateRemoveSpellcheckWordFunction
+ : public UIThreadExtensionFunction {
+ public:
+ LanguageSettingsPrivateRemoveSpellcheckWordFunction();
+ DECLARE_EXTENSION_FUNCTION("languageSettingsPrivate.removeSpellcheckWord",
+ LANGUAGESETTINGSPRIVATE_REMOVESPELLCHECKWORD)
+
+ protected:
+ ~LanguageSettingsPrivateRemoveSpellcheckWordFunction() override;
+
+ // ExtensionFunction overrides.
+ ResponseAction Run() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(LanguageSettingsPrivateRemoveSpellcheckWordFunction);
+};
+
// Implements the languageSettingsPrivate.getTranslateTargetLanguage method.
class LanguageSettingsPrivateGetTranslateTargetLanguageFunction
: public UIThreadExtensionFunction {
diff --git a/chrome/common/extensions/api/language_settings_private.idl b/chrome/common/extensions/api/language_settings_private.idl
index 8b1a795..30958c5 100644
--- a/chrome/common/extensions/api/language_settings_private.idl
+++ b/chrome/common/extensions/api/language_settings_private.idl
@@ -88,9 +88,15 @@ namespace languageSettingsPrivate {
static void getSpellcheckDictionaryStatuses(
GetSpellcheckDictionaryStatusesCallback callback);
- // Gets the custom spell check words.
+ // Gets the custom spell check words, in sorted order.
static void getSpellcheckWords(GetSpellcheckWordsCallback callback);
+ // Adds a word to the custom dictionary.
+ static void addSpellcheckWord(DOMString word);
+
+ // Removes a word from the custom dictionary.
+ static void removeSpellcheckWord(DOMString word);
+
// Gets the translate target language (in most cases, the display locale).
static void getTranslateTargetLanguage(
GetTranslateTargetLanguageCallback callback);
diff --git a/extensions/browser/extension_function_histogram_value.h b/extensions/browser/extension_function_histogram_value.h
index 4b4ebd3..648f9c5 100644
--- a/extensions/browser/extension_function_histogram_value.h
+++ b/extensions/browser/extension_function_histogram_value.h
@@ -1150,6 +1150,8 @@ enum HistogramValue {
DATAREDUCTIONPROXY_GETDATAUSAGE,
EASYUNLOCKPRIVATE_SETUPCONNECTIONGETDEVICEADDRESS,
TABCAPTURE_CAPTUREOFFSCREENTAB,
+ LANGUAGESETTINGSPRIVATE_ADDSPELLCHECKWORD,
+ LANGUAGESETTINGSPRIVATE_REMOVESPELLCHECKWORD,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
diff --git a/third_party/closure_compiler/externs/language_settings_private.js b/third_party/closure_compiler/externs/language_settings_private.js
index 1dad659..4d1cc7d 100644
--- a/third_party/closure_compiler/externs/language_settings_private.js
+++ b/third_party/closure_compiler/externs/language_settings_private.js
@@ -85,13 +85,27 @@ chrome.languageSettingsPrivate.setLanguageList = function(languageCodes) {};
chrome.languageSettingsPrivate.getSpellcheckDictionaryStatuses = function(callback) {};
/**
- * Gets the custom spell check words.
+ * Gets the custom spell check words, in sorted order.
* @param {function(!Array<string>):void} callback
* @see https://developer.chrome.com/extensions/languageSettingsPrivate#method-getSpellcheckWords
*/
chrome.languageSettingsPrivate.getSpellcheckWords = function(callback) {};
/**
+ * Adds a word to the custom dictionary.
+ * @param {string} word
+ * @see https://developer.chrome.com/extensions/languageSettingsPrivate#method-addSpellcheckWord
+ */
+chrome.languageSettingsPrivate.addSpellcheckWord = function(word) {};
+
+/**
+ * Removes a word from the custom dictionary.
+ * @param {string} word
+ * @see https://developer.chrome.com/extensions/languageSettingsPrivate#method-removeSpellcheckWord
+ */
+chrome.languageSettingsPrivate.removeSpellcheckWord = function(word) {};
+
+/**
* Gets the translate target language (in most cases, the display locale).
* @param {function(string):void} callback
* @see https://developer.chrome.com/extensions/languageSettingsPrivate#method-getTranslateTargetLanguage
diff --git a/tools/metrics/histograms/histograms.xml b/tools/metrics/histograms/histograms.xml
index 6b0b587..977e6a1 100644
--- a/tools/metrics/histograms/histograms.xml
+++ b/tools/metrics/histograms/histograms.xml
@@ -59176,6 +59176,8 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
<int value="1089" label="DATAREDUCTIONPROXY_GETDATAUSAGE"/>
<int value="1090" label="EASYUNLOCKPRIVATE_SETUPCONNECTIONGETDEVICEADDRESS"/>
<int value="1091" label="TABCAPTURE_CAPTUREOFFSCREENTAB"/>
+ <int value="1092" label="LANGUAGESETTINGSPRIVATE_ADDSPELLCHECKWORD"/>
+ <int value="1093" label="LANGUAGESETTINGSPRIVATE_REMOVESPELLCHECKWORD"/>
</enum>
<enum name="ExtensionInstallCause" type="int">