Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Deprecate electron spellchecker by chromium's
Browse files Browse the repository at this point in the history
  • Loading branch information
darkdh committed Jul 11, 2017
1 parent 5390512 commit ed81eb2
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 368 deletions.
2 changes: 0 additions & 2 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,6 @@ source_set("renderer") {
]

sources = [
"atom/renderer/api/atom_api_spell_check_client.cc",
"atom/renderer/api/atom_api_spell_check_client.h",
"atom/renderer/content_settings_manager.cc",
"atom/renderer/content_settings_manager.h",
"brave/renderer/brave_content_renderer_client.cc",
Expand Down
68 changes: 67 additions & 1 deletion atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
#include "chrome/browser/printing/print_preview_message_handler.h"
#include "chrome/browser/printing/print_view_manager_basic.h"
#include "chrome/browser/printing/print_view_manager_common.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "chrome/browser/spellchecker/spellcheck_service.h"
#include "chrome/browser/ssl/security_state_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
Expand Down Expand Up @@ -951,7 +953,23 @@ bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) {
Emit("pepper-context-menu", std::make_pair(params, web_contents()));
web_contents()->NotifyContextMenuClosed(params.custom_context);
} else {
Emit("context-menu", std::make_pair(params, web_contents()));
// For forgetting custom dictionary option
content::ContextMenuParams new_params(params);
if (new_params.misspelled_word.empty()) {
auto browser_context = web_contents()->GetBrowserContext();
if (browser_context) {
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck) {
if (spellcheck->GetCustomDictionary()
->HasWord(base::UTF16ToUTF8(new_params.selection_text))) {
new_params.misspelled_word =
base::ASCIIToUTF16("match-brave-custom-dictionary");
}
}
}
}
Emit("context-menu", std::make_pair(new_params, web_contents()));
}

return true;
Expand All @@ -973,6 +991,50 @@ void WebContents::AuthorizePlugin(mate::Arguments* args) {
web_contents(), true, resource_id);
}

void WebContents::AddWord(mate::Arguments* args) {
if (args->Length() != 1) {
args->ThrowError("Wrong number of arguments");
return;
}

std::string word;
if (!args->GetNext(&word)) {
args->ThrowError("word is a required field");
return;
}

auto browser_context = web_contents()->GetBrowserContext();
if (browser_context) {
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck) {
spellcheck->GetCustomDictionary()->AddWord(word);
}
}
}

void WebContents::RemoveWord(mate::Arguments* args) {
if (args->Length() != 1) {
args->ThrowError("Wrong number of arguments");
return;
}

std::string word;
if (!args->GetNext(&word)) {
args->ThrowError("word is a required field");
return;
}

auto browser_context = web_contents()->GetBrowserContext();
if (browser_context) {
SpellcheckService* spellcheck =
SpellcheckServiceFactory::GetForContext(browser_context);
if (spellcheck) {
spellcheck->GetCustomDictionary()->RemoveWord(word);
}
}
}

void WebContents::TabPinnedStateChanged(TabStripModel* tab_strip_model,
content::WebContents* contents,
int index) {
Expand Down Expand Up @@ -2430,6 +2492,10 @@ void WebContents::BuildPrototype(v8::Isolate* isolate,
&WebContents::EnablePreferredSizeMode)
.SetMethod("authorizePlugin",
&WebContents::AuthorizePlugin)
.SetMethod("addWord",
&WebContents::AddWord)
.SetMethod("removeWord",
&WebContents::RemoveWord)
#if BUILDFLAG(ENABLE_EXTENSIONS)
.SetMethod("executeScriptInTab", &WebContents::ExecuteScriptInTab)
.SetMethod("isBackgroundPage", &WebContents::IsBackgroundPage)
Expand Down
4 changes: 4 additions & 0 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ class WebContents : public mate::TrackableObject<WebContents>,

void AuthorizePlugin(mate::Arguments* args);

void AddWord(mate::Arguments* args);

void RemoveWord(mate::Arguments* args);

// TabStripModelObserver
void TabPinnedStateChanged(TabStripModel* tab_strip_model,
content::WebContents* contents,
Expand Down
12 changes: 12 additions & 0 deletions atom/browser/browser_context_keyed_service_factories.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/password_manager/password_store_factory.h"
#include "chrome/browser/spellchecker/spellcheck_factory.h"
#include "components/spellcheck/spellcheck_build_features.h"
#include "extensions/features/features.h"
#include "ppapi/features/features.h"
#if BUILDFLAG(ENABLE_PLUGINS)
Expand Down Expand Up @@ -38,6 +40,10 @@
#include "extensions/browser/renderer_startup_helper.h"
#endif

#if BUILDFLAG(ENABLE_SPELLCHECK)
#include "chrome/browser/extensions/api/spellcheck/spellcheck_api.h"
#endif

namespace atom {

void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
Expand Down Expand Up @@ -67,6 +73,9 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
extensions::StorageFrontend::GetFactoryInstance();
extensions::WebRequestAPI::GetFactoryInstance();
extensions::AtomExtensionSystemFactory::GetInstance();
#if BUILDFLAG(ENABLE_SPELLCHECK)
extensions::SpellcheckAPI::GetFactoryInstance();
#endif
#endif
CookieSettingsFactory::GetInstance();
HostContentSettingsMapFactory::GetInstance();
Expand All @@ -76,6 +85,9 @@ void EnsureBrowserContextKeyedServiceFactoriesBuilt() {
ProtocolHandlerRegistryFactory::GetInstance();
HistoryServiceFactory::GetInstance();
PasswordStoreFactory::GetInstance();
#if BUILDFLAG(ENABLE_SPELLCHECK)
SpellcheckServiceFactory::GetInstance();
#endif
}

} // namespace atom
1 change: 1 addition & 0 deletions atom/browser/ui/atom_menu_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "atom/browser/ui/atom_menu_model.h"

#include "base/stl_util.h"
#include "chrome/browser/renderer_context_menu/spelling_menu_observer.h"

namespace atom {

Expand Down
4 changes: 0 additions & 4 deletions atom/common/api/resources/web_frame_bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ binding.registerCustomHook(function(bindingsAPI, extensionId) {
return webFrameNatives.executeJavaScript(code)
})

apiFunctions.setHandleRequest('setSpellCheckProvider', function(lang, autoCorrectEnabled, spellCheckProvider) {
return webFrameNatives.setSpellCheckProvider(lang, autoCorrectEnabled, spellCheckProvider)
})

apiFunctions.setHandleRequest('setZoomLevel', function(level) {
return webFrameNatives.setZoomLevel(level)
})
Expand Down
1 change: 1 addition & 0 deletions atom/common/native_mate_converters/content_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ v8::Local<v8::Value> Converter<ContextMenuParamsWithWebContents>::ToV8(
dict.Set("selectionText", params.selection_text);
dict.Set("titleText", params.title_text);
dict.Set("misspelledWord", params.misspelled_word);
dict.Set("dictionarySuggestions", params.dictionary_suggestions);
dict.Set("frameCharset", params.frame_charset);
dict.Set("inputFieldType", params.input_field_type);
dict.Set("menuSourceType", params.source_type);
Expand Down
201 changes: 0 additions & 201 deletions atom/renderer/api/atom_api_spell_check_client.cc

This file was deleted.

Loading

0 comments on commit ed81eb2

Please sign in to comment.