From bf75e5a91f87a8716c6a1f615e1963612e4ade89 Mon Sep 17 00:00:00 2001 From: Alexey Kuzmin Date: Tue, 10 Mar 2020 10:39:40 +0100 Subject: [PATCH] build: fix build without built-in spellchecker (#22594) --- shell/browser/api/electron_api_session.cc | 12 ++++++++++-- shell/browser/api/electron_api_session.h | 13 ++++++++++--- shell/common/api/features.cc | 5 +++++ spec-main/spellchecker-spec.ts | 6 ++++-- typings/internal-ambient.d.ts | 1 + 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/shell/browser/api/electron_api_session.cc b/shell/browser/api/electron_api_session.cc index c297258fdd83..b45a8bc53ad8 100644 --- a/shell/browser/api/electron_api_session.cc +++ b/shell/browser/api/electron_api_session.cc @@ -76,7 +76,6 @@ #if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) #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 "components/spellcheck/browser/pref_names.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 { private: std::unique_ptr>> promise_; @@ -263,6 +263,7 @@ class DictionaryObserver final : public SpellcheckCustomDictionary::Observer { // noop } }; +#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) } // namespace @@ -280,22 +281,27 @@ Session::Session(v8::Isolate* isolate, ElectronBrowserContext* browser_context) Init(isolate); AttachAsUserData(browser_context); +#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) SpellcheckService* service = SpellcheckServiceFactory::GetForContext(browser_context_.get()); if (service) { service->SetHunspellObserver(this); } +#endif } Session::~Session() { content::BrowserContext::GetDownloadManager(browser_context()) ->RemoveObserver(this); +#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) SpellcheckService* service = SpellcheckServiceFactory::GetForContext(browser_context_.get()); if (service) { service->SetHunspellObserver(nullptr); } +#endif + // TODO(zcbenz): Now since URLRequestContextGetter is gone, is this still // needed? // 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) { Emit("spellcheck-dictionary-initialized", language); } @@ -336,6 +343,7 @@ void Session::OnHunspellDictionaryDownloadSuccess(const std::string& language) { void Session::OnHunspellDictionaryDownloadFailure(const std::string& language) { Emit("spellcheck-dictionary-download-failure", language); } +#endif v8::Local Session::ResolveProxy(gin_helper::Arguments* args) { v8::Isolate* isolate = args->isolate(); @@ -908,7 +916,7 @@ bool Session::RemoveWordFromSpellCheckerDictionary(const std::string& word) { #endif return service->GetCustomDictionary()->RemoveWord(word); } -#endif +#endif // BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) // static gin::Handle Session::CreateFrom( diff --git a/shell/browser/api/electron_api_session.h b/shell/browser/api/electron_api_session.h index 6beced55f5a5..eedc2c67797f 100644 --- a/shell/browser/api/electron_api_session.h +++ b/shell/browser/api/electron_api_session.h @@ -9,7 +9,6 @@ #include #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" @@ -17,6 +16,10 @@ #include "shell/common/gin_helper/promise.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; namespace base { @@ -38,8 +41,10 @@ class ElectronBrowserContext; namespace api { class Session : public gin_helper::TrackableObject, - public content::DownloadManager::Observer, - public SpellcheckHunspellDictionary::Observer { +#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) + public SpellcheckHunspellDictionary::Observer, +#endif + public content::DownloadManager::Observer { public: // Gets or creates Session from the |browser_context|. static gin::Handle CreateFrom( @@ -118,6 +123,7 @@ class Session : public gin_helper::TrackableObject, void OnDownloadCreated(content::DownloadManager* manager, download::DownloadItem* item) override; +#if BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER) // SpellcheckHunspellDictionary::Observer void OnHunspellDictionaryInitialized(const std::string& language) override; void OnHunspellDictionaryDownloadBegin(const std::string& language) override; @@ -125,6 +131,7 @@ class Session : public gin_helper::TrackableObject, const std::string& language) override; void OnHunspellDictionaryDownloadFailure( const std::string& language) override; +#endif private: // Cached gin_helper::Wrappable objects. diff --git a/shell/common/api/features.cc b/shell/common/api/features.cc index 610f0d1424a0..3f875fcd448e 100644 --- a/shell/common/api/features.cc +++ b/shell/common/api/features.cc @@ -9,6 +9,10 @@ namespace { +bool IsBuiltinSpellCheckerEnabled() { + return BUILDFLAG(ENABLE_BUILTIN_SPELLCHECKER); +} + bool IsDesktopCapturerEnabled() { return BUILDFLAG(ENABLE_DESKTOP_CAPTURER); } @@ -66,6 +70,7 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { gin_helper::Dictionary dict(context->GetIsolate(), exports); + dict.SetMethod("isBuiltinSpellCheckerEnabled", &IsBuiltinSpellCheckerEnabled); dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled); dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled); dict.SetMethod("isRemoteModuleEnabled", &IsRemoteModuleEnabled); diff --git a/spec-main/spellchecker-spec.ts b/spec-main/spellchecker-spec.ts index 4c26afbda94b..cc28cebb801f 100644 --- a/spec-main/spellchecker-spec.ts +++ b/spec-main/spellchecker-spec.ts @@ -4,9 +4,11 @@ import { expect } from 'chai' import * as path from 'path' import { closeWindow } from './window-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 beforeEach(async () => { diff --git a/typings/internal-ambient.d.ts b/typings/internal-ambient.d.ts index 25d98a21671a..424637ca3f0a 100644 --- a/typings/internal-ambient.d.ts +++ b/typings/internal-ambient.d.ts @@ -2,6 +2,7 @@ declare var internalBinding: any; declare namespace NodeJS { interface FeaturesBinding { + isBuiltinSpellCheckerEnabled(): boolean; isDesktopCapturerEnabled(): boolean; isOffscreenRenderingEnabled(): boolean; isRemoteModuleEnabled(): boolean;