This repository has been archived by the owner on Jan 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #244 from brave/spellchecker
Deprecate electron spellchecker by chromium's
- Loading branch information
Showing
21 changed files
with
275 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2016 The Brave Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "atom/browser/api/atom_api_spellchecker.h" | ||
|
||
#include <string> | ||
|
||
#include "atom/common/node_includes.h" | ||
#include "chrome/browser/spellchecker/spellcheck_factory.h" | ||
#include "chrome/browser/spellchecker/spellcheck_service.h" | ||
#include "native_mate/dictionary.h" | ||
|
||
namespace atom { | ||
|
||
namespace api { | ||
|
||
SpellChecker::SpellChecker(v8::Isolate* isolate, | ||
content::BrowserContext* browser_context) | ||
: browser_context_(browser_context), | ||
weak_ptr_factory_(this) { | ||
Init(isolate); | ||
} | ||
|
||
SpellChecker::~SpellChecker() {} | ||
|
||
void SpellChecker::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; | ||
} | ||
|
||
if (browser_context_) { | ||
SpellcheckService* spellcheck = | ||
SpellcheckServiceFactory::GetForContext(browser_context_); | ||
if (spellcheck) { | ||
spellcheck->GetCustomDictionary()->AddWord(word); | ||
} | ||
} | ||
} | ||
|
||
void SpellChecker::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; | ||
} | ||
|
||
if (browser_context_) { | ||
SpellcheckService* spellcheck = | ||
SpellcheckServiceFactory::GetForContext(browser_context_); | ||
if (spellcheck) { | ||
spellcheck->GetCustomDictionary()->RemoveWord(word); | ||
} | ||
} | ||
} | ||
|
||
// static | ||
mate::Handle<SpellChecker> SpellChecker::Create( | ||
v8::Isolate* isolate, | ||
content::BrowserContext* browser_context) { | ||
return mate::CreateHandle(isolate, | ||
new SpellChecker(isolate, browser_context)); | ||
} | ||
|
||
// static | ||
void SpellChecker::BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype) { | ||
prototype->SetClassName(mate::StringToV8(isolate, "SpellChecker")); | ||
mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) | ||
.SetMethod("addWord", &SpellChecker::AddWord) | ||
.SetMethod("removeWord", &SpellChecker::RemoveWord); | ||
} | ||
|
||
} // namespace api | ||
|
||
} // namespace atom |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2016 The Brave Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ATOM_BROWSER_API_ATOM_API_SPELLCHECKER_H_ | ||
#define ATOM_BROWSER_API_ATOM_API_SPELLCHECKER_H_ | ||
|
||
#include "atom/browser/api/trackable_object.h" | ||
#include "brave/browser/brave_browser_context.h" | ||
#include "native_mate/handle.h" | ||
|
||
namespace atom { | ||
|
||
namespace api { | ||
|
||
class SpellChecker : public mate::TrackableObject<SpellChecker> { | ||
public: | ||
static mate::Handle<SpellChecker> Create(v8::Isolate* isolate, | ||
content::BrowserContext* browser_context); | ||
|
||
// mate::TrackableObject: | ||
static void BuildPrototype(v8::Isolate* isolate, | ||
v8::Local<v8::FunctionTemplate> prototype); | ||
|
||
protected: | ||
SpellChecker(v8::Isolate* isolate, content::BrowserContext* browser_context); | ||
~SpellChecker() override; | ||
|
||
void AddWord(mate::Arguments* args); | ||
|
||
void RemoveWord(mate::Arguments* args); | ||
|
||
private: | ||
content::BrowserContext* browser_context_; // not owned | ||
|
||
base::WeakPtrFactory<SpellChecker> weak_ptr_factory_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(SpellChecker); | ||
}; | ||
|
||
} // namespace api | ||
|
||
} // namespace atom | ||
|
||
#endif // ATOM_BROWSER_API_ATOM_API_SPELLCHECKER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.