build: fix build without built-in spellchecker (#22594)
This commit is contained in:
parent
3ff98e15d0
commit
bf75e5a91f
5 changed files with 30 additions and 7 deletions
|
@ -76,7 +76,6 @@
|
||||||
|
|
||||||
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
#include "chrome/browser/spellchecker/spellcheck_factory.h" // nogncheck
|
#include "chrome/browser/spellchecker/spellcheck_factory.h" // nogncheck
|
||||||
#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" // nogncheck
|
|
||||||
#include "chrome/browser/spellchecker/spellcheck_service.h" // nogncheck
|
#include "chrome/browser/spellchecker/spellcheck_service.h" // nogncheck
|
||||||
#include "components/spellcheck/browser/pref_names.h"
|
#include "components/spellcheck/browser/pref_names.h"
|
||||||
#include "components/spellcheck/common/spellcheck_common.h"
|
#include "components/spellcheck/common/spellcheck_common.h"
|
||||||
|
@ -228,6 +227,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
|
class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<gin_helper::Promise<std::set<std::string>>> promise_;
|
std::unique_ptr<gin_helper::Promise<std::set<std::string>>> promise_;
|
||||||
|
@ -263,6 +263,7 @@ class DictionaryObserver final : public SpellcheckCustomDictionary::Observer {
|
||||||
// noop
|
// noop
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
@ -280,22 +281,27 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context)
|
||||||
Init(isolate);
|
Init(isolate);
|
||||||
AttachAsUserData(browser_context);
|
AttachAsUserData(browser_context);
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
SpellcheckService* service =
|
SpellcheckService* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||||
if (service) {
|
if (service) {
|
||||||
service->SetHunspellObserver(this);
|
service->SetHunspellObserver(this);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Session::~Session() {
|
Session::~Session() {
|
||||||
content::BrowserContext::GetDownloadManager(browser_context())
|
content::BrowserContext::GetDownloadManager(browser_context())
|
||||||
->RemoveObserver(this);
|
->RemoveObserver(this);
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
SpellcheckService* service =
|
SpellcheckService* service =
|
||||||
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
SpellcheckServiceFactory::GetForContext(browser_context_.get());
|
||||||
if (service) {
|
if (service) {
|
||||||
service->SetHunspellObserver(nullptr);
|
service->SetHunspellObserver(nullptr);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still
|
// TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still
|
||||||
// needed?
|
// needed?
|
||||||
// Refs https://github.com/electron/electron/pull/12305.
|
// Refs https://github.com/electron/electron/pull/12305.
|
||||||
|
@ -324,6 +330,7 @@ void Session::OnDownloadCreated(content::DownloadManager* manager,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
void Session::OnHunspellDictionaryInitialized(const std::string& language) {
|
void Session::OnHunspellDictionaryInitialized(const std::string& language) {
|
||||||
Emit("spellcheck-dictionary-initialized", language);
|
Emit("spellcheck-dictionary-initialized", language);
|
||||||
}
|
}
|
||||||
|
@ -336,6 +343,7 @@ void Session::OnHunspellDictionaryDownloadSuccess(const std::string& language) {
|
||||||
void Session::OnHunspellDictionaryDownloadFailure(const std::string& language) {
|
void Session::OnHunspellDictionaryDownloadFailure(const std::string& language) {
|
||||||
Emit("spellcheck-dictionary-download-failure", language);
|
Emit("spellcheck-dictionary-download-failure", language);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
v8::Local<v8::Promise> Session::ResolveProxy(gin_helper::Arguments* args) {
|
v8::Local<v8::Promise> Session::ResolveProxy(gin_helper::Arguments* args) {
|
||||||
v8::Isolate* isolate = args->isolate();
|
v8::Isolate* isolate = args->isolate();
|
||||||
|
@ -908,7 +916,7 @@ bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) {
|
||||||
#endif
|
#endif
|
||||||
return service->GetCustomDictionary()->RemoveWord(word);
|
return service->GetCustomDictionary()->RemoveWord(word);
|
||||||
}
|
}
|
||||||
#endif
|
#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
|
||||||
// static
|
// static
|
||||||
gin::Handle<Session> Session::CreateFrom(
|
gin::Handle<Session> Session::CreateFrom(
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "base/values.h"
|
#include "base/values.h"
|
||||||
#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h"
|
|
||||||
#include "content/public/browser/download_manager.h"
|
#include "content/public/browser/download_manager.h"
|
||||||
#include "electron/buildflags/buildflags.h"
|
#include "electron/buildflags/buildflags.h"
|
||||||
#include "gin/handle.h"
|
#include "gin/handle.h"
|
||||||
|
@ -17,6 +16,10 @@
|
||||||
#include "shell/common/gin_helper/promise.h"
|
#include "shell/common/gin_helper/promise.h"
|
||||||
#include "shell/common/gin_helper/trackable_object.h"
|
#include "shell/common/gin_helper/trackable_object.h"
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
|
#include "chrome/browser/spellchecker/spellcheck_hunspell_dictionary.h" // nogncheck
|
||||||
|
#endif
|
||||||
|
|
||||||
class GURL;
|
class GURL;
|
||||||
|
|
||||||
namespace base {
|
namespace base {
|
||||||
|
@ -38,8 +41,10 @@ class ElectronBrowserContext;
|
||||||
namespace api {
|
namespace api {
|
||||||
|
|
||||||
class Session : public gin_helper::TrackableObject<Session>,
|
class Session : public gin_helper::TrackableObject<Session>,
|
||||||
public content::DownloadManager::Observer,
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
public SpellcheckHunspellDictionary::Observer {
|
public SpellcheckHunspellDictionary::Observer,
|
||||||
|
#endif
|
||||||
|
public content::DownloadManager::Observer {
|
||||||
public:
|
public:
|
||||||
// Gets or creates Session from the |browser_context|.
|
// Gets or creates Session from the |browser_context|.
|
||||||
static gin::Handle<Session> CreateFrom(
|
static gin::Handle<Session> CreateFrom(
|
||||||
|
@ -118,6 +123,7 @@ class Session : public gin_helper::TrackableObject<Session>,
|
||||||
void OnDownloadCreated(content::DownloadManager* manager,
|
void OnDownloadCreated(content::DownloadManager* manager,
|
||||||
download::DownloadItem* item) override;
|
download::DownloadItem* item) override;
|
||||||
|
|
||||||
|
#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER)
|
||||||
// SpellcheckHunspellDictionary::Observer
|
// SpellcheckHunspellDictionary::Observer
|
||||||
void OnHunspellDictionaryInitialized(const std::string& language) override;
|
void OnHunspellDictionaryInitialized(const std::string& language) override;
|
||||||
void OnHunspellDictionaryDownloadBegin(const std::string& language) override;
|
void OnHunspellDictionaryDownloadBegin(const std::string& language) override;
|
||||||
|
@ -125,6 +131,7 @@ class Session : public gin_helper::TrackableObject<Session>,
|
||||||
const std::string& language) override;
|
const std::string& language) override;
|
||||||
void OnHunspellDictionaryDownloadFailure(
|
void OnHunspellDictionaryDownloadFailure(
|
||||||
const std::string& language) override;
|
const std::string& language) override;
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Cached gin_helper::Wrappable objects.
|
// Cached gin_helper::Wrappable objects.
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
bool IsBuiltinSpellCheckerEnabled() {
|
||||||
|
return BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsDesktopCapturerEnabled() {
|
bool IsDesktopCapturerEnabled() {
|
||||||
return BUILDFLAG(ENABLE_DESKTOP_CAPTURER);
|
return BUILDFLAG(ENABLE_DESKTOP_CAPTURER);
|
||||||
}
|
}
|
||||||
|
@ -66,6 +70,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
||||||
v8::Local<v8::Context> context,
|
v8::Local<v8::Context> context,
|
||||||
void* priv) {
|
void* priv) {
|
||||||
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
gin_helper::Dictionary dict(context->GetIsolate(), exports);
|
||||||
|
dict.SetMethod("isBuiltinSpellCheckerEnabled", &IsBuiltinSpellCheckerEnabled);
|
||||||
dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled);
|
dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled);
|
||||||
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
|
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
|
||||||
dict.SetMethod("isRemoteModuleEnabled", &IsRemoteModuleEnabled);
|
dict.SetMethod("isRemoteModuleEnabled", &IsRemoteModuleEnabled);
|
||||||
|
|
|
@ -4,9 +4,11 @@ import { expect } from 'chai'
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import { closeWindow } from './window-helpers'
|
import { closeWindow } from './window-helpers'
|
||||||
import { emittedOnce } from './events-helpers'
|
import { emittedOnce } from './events-helpers'
|
||||||
import { ifit } from './spec-helpers'
|
import { ifit, ifdescribe } from './spec-helpers'
|
||||||
|
|
||||||
describe('spellchecker', () => {
|
const features = process.electronBinding('features')
|
||||||
|
|
||||||
|
ifdescribe(features.isBuiltinSpellCheckerEnabled())('spellchecker', () => {
|
||||||
let w: BrowserWindow
|
let w: BrowserWindow
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
|
|
1
typings/internal-ambient.d.ts
vendored
1
typings/internal-ambient.d.ts
vendored
|
@ -2,6 +2,7 @@ declare var internalBinding: any;
|
||||||
|
|
||||||
declare namespace NodeJS {
|
declare namespace NodeJS {
|
||||||
interface FeaturesBinding {
|
interface FeaturesBinding {
|
||||||
|
isBuiltinSpellCheckerEnabled(): boolean;
|
||||||
isDesktopCapturerEnabled(): boolean;
|
isDesktopCapturerEnabled(): boolean;
|
||||||
isOffscreenRenderingEnabled(): boolean;
|
isOffscreenRenderingEnabled(): boolean;
|
||||||
isRemoteModuleEnabled(): boolean;
|
isRemoteModuleEnabled(): boolean;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue