feat: add events for spellcheck dictionary downloads (#22449)

This commit is contained in:
Samuel Attard 2020-03-05 11:58:19 -08:00 committed by GitHub
parent e9132afa98
commit b3e1134a1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 140 additions and 1 deletions

View file

@ -279,11 +279,23 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
Init(isolate);
AttachAsUserData(browser_context);
SpellcheckService* service =
SpellcheckServiceFactory::GetForContext(browser_context_.get());
if (service) {
service->SetHunspellObserver(this);
}
}
Session::~Session() {
content::BrowserContext::GetDownloadManager(browser_context())
->RemoveObserver(this);
SpellcheckService* service =
SpellcheckServiceFactory::GetForContext(browser_context_.get());
if (service) {
service->SetHunspellObserver(nullptr);
}
// TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still
// needed?
// Refs https://github.com/electron/electron/pull/12305.
@ -312,6 +324,19 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
}
}
void Session::OnHunspellDictionaryInitialized(const std::string& language) {
Emit("spellcheck-dictionary-initialized", language);
}
void Session::OnHunspellDictionaryDownloadBegin(const std::string& language) {
Emit("spellcheck-dictionary-download-begin", language);
}
void Session::OnHunspellDictionaryDownloadSuccess(const std::string& language) {
Emit("spellcheck-dictionary-download-success", language);
}
void Session::OnHunspellDictionaryDownloadFailure(const std::string& language) {
Emit("spellcheck-dictionary-download-failure", language);
}
v8::Local<v8::Promise> Session::ResolveProxy(gin_helper::Arguments* args) {
v8::Isolate* isolate = args->isolate();
gin_helper::Promise<std::string> promise(isolate);

View file

@ -9,6 +9,7 @@
#include <vector>
#include "base/values.h"
#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
#include "content/public/browser/download_manager.h"
#include "electron/buildflags/buildflags.h"
#include "gin/handle.h"
@ -37,7 +38,8 @@ class ElectronBrowserContext;
namespace api {
class Session : public gin_helper::TrackableObject<Session>,
public content::DownloadManager::Observer {
public content::DownloadManager::Observer,
public SpellcheckHunspellDictionary::Observer {
public:
// Gets or creates Session from the |browser_context|.
static gin::Handle<Session> CreateFrom(
@ -116,6 +118,14 @@ class Session : public gin_helper::TrackableObject<Session>,
void OnDownloadCreated(content::DownloadManager* manager,
download::DownloadItem* item) override;
// SpellcheckHunspellDictionary::Observer
void OnHunspellDictionaryInitialized(const std::string& language) override;
void OnHunspellDictionaryDownloadBegin(const std::string& language) override;
void OnHunspellDictionaryDownloadSuccess(
const std::string& language) override;
void OnHunspellDictionaryDownloadFailure(
const std::string& language) override;
private:
// Cached gin_helper::Wrappable objects.
v8::Global<v8::Value> cookies_;