diff --git a/docs/api/session.md b/docs/api/session.md index de2fcd8f866b..7179fb378368 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -495,6 +495,14 @@ Returns `Boolean` - Whether the word was successfully written to the custom dict **Note:** On macOS and Windows 10 this word will be written to the OS custom dictionary as well +#### `ses.removeWordFromSpellCheckerDictionary(word)` + +* `word` String - The word you want to remove from the dictionary + +Returns `Boolean` - Whether the word was successfully removed from the custom dictionary. + +**Note:** On macOS and Windows 10 this word will be removed from the OS custom dictionary as well + #### `ses.loadExtension(path)` * `path` String - Path to a directory containing an unpacked Chrome extension diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc index 860d00101990..d1c90bcc0f3c 100644 --- a/shell/browser/api/electron_api_session.cc +++ b/shell/browser/api/electron_api_session.cc @@ -785,6 +785,21 @@ bool Session::AddWordToSpellCheckerDictionary(const std::string& word) { #endif return service->GetCustomDictionary()->AddWord(word); } + +bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) { + SpellcheckService* service = + SpellcheckServiceFactory::GetForContext(browser_context_.get()); + if (!service) + return false; + +#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) + if (spellcheck::UseBrowserSpellChecker()) { + spellcheck_platform::RemoveWord(service->platform_spell_checker(), + base::UTF8ToUTF16(word)); + } +#endif + return service->GetCustomDictionary()->RemoveWord(word); +} #endif // static @@ -873,6 +888,8 @@ void Session::BuildPrototype(v8::Isolate* isolate, &SetSpellCheckerDictionaryDownloadURL) .SetMethod("addWordToSpellCheckerDictionary", &Session::AddWordToSpellCheckerDictionary) + .SetMethod("removeWordFromSpellCheckerDictionary", + &Session::RemoveWordFromSpellCheckerDictionary) #endif .SetMethod("preconnect", &Session::Preconnect) .SetProperty("cookies", &Session::Cookies) diff --git a/shell/browser/api/electron_api_session.h b/shell/browser/api/electron_api_session.h index c162e474fd51..640d3104e26e 100644 --- a/shell/browser/api/electron_api_session.h +++ b/shell/browser/api/electron_api_session.h @@ -96,6 +96,7 @@ class Session : public gin_helper::TrackableObject, void SetSpellCheckerLanguages(gin_helper::ErrorThrower thrower, const std::vector& languages); bool AddWordToSpellCheckerDictionary(const std::string& word); + bool RemoveWordFromSpellCheckerDictionary(const std::string& word); #endif #if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)