Commit 73091994 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Use EnableIf in spellcheck mojom

The SpellCheckHost mojom has some platform-dependent APIs.

This patch uses the EnableIf mojo attribute so that we don't need
to leave dummy API implementations on unsupported platforms.

Bug: 813217
Change-Id: I407ebc6687c404b1583ceeac346a29cb775847ee
Reviewed-on: https://chromium-review.googlesource.com/905579
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarAlex Moshchuk <alexmos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537879}
parent 68ee851d
...@@ -799,32 +799,33 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { ...@@ -799,32 +799,33 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
// spellcheck::mojom::SpellCheckHost: // spellcheck::mojom::SpellCheckHost:
void RequestDictionary() override {} void RequestDictionary() override {}
void NotifyChecked(const base::string16& word, bool misspelled) override {} void NotifyChecked(const base::string16& word, bool misspelled) override {}
void ToggleSpellCheck(bool, bool) override {}
void CheckSpelling(const base::string16& word,
int,
CheckSpellingCallback) override {}
void FillSuggestionList(const base::string16& word,
FillSuggestionListCallback) override {}
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void CallSpellingService(const base::string16& text, void CallSpellingService(const base::string16& text,
CallSpellingServiceCallback callback) override { CallSpellingServiceCallback callback) override {
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::move(callback).Run(true, std::vector<SpellCheckResult>()); std::move(callback).Run(true, std::vector<SpellCheckResult>());
TextReceived(text); TextReceived(text);
#endif
} }
#endif
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void RequestTextCheck(const base::string16& text, void RequestTextCheck(const base::string16& text,
int route_id, int route_id,
RequestTextCheckCallback callback) override { RequestTextCheckCallback callback) override {
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
std::move(callback).Run(std::vector<SpellCheckResult>()); std::move(callback).Run(std::vector<SpellCheckResult>());
TextReceived(text); TextReceived(text);
#endif
} }
void ToggleSpellCheck(bool, bool) override {}
void CheckSpelling(const base::string16& word,
int,
CheckSpellingCallback) override {}
void FillSuggestionList(const base::string16& word,
FillSuggestionListCallback) override {}
#endif
content::RenderProcessHost* process_host_; content::RenderProcessHost* process_host_;
bool text_received_ = false; bool text_received_ = false;
base::string16 text_; base::string16 text_;
......
...@@ -21,8 +21,7 @@ void SpellCheckHostImpl::Create( ...@@ -21,8 +21,7 @@ void SpellCheckHostImpl::Create(
void SpellCheckHostImpl::RequestDictionary() { void SpellCheckHostImpl::RequestDictionary() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features.
// current platform.
return; return;
} }
...@@ -30,11 +29,11 @@ void SpellCheckHostImpl::NotifyChecked(const base::string16& word, ...@@ -30,11 +29,11 @@ void SpellCheckHostImpl::NotifyChecked(const base::string16& word,
bool misspelled) { bool misspelled) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features.
// current platform.
return; return;
} }
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void SpellCheckHostImpl::CallSpellingService( void SpellCheckHostImpl::CallSpellingService(
const base::string16& text, const base::string16& text,
CallSpellingServiceCallback callback) { CallSpellingServiceCallback callback) {
...@@ -43,11 +42,12 @@ void SpellCheckHostImpl::CallSpellingService( ...@@ -43,11 +42,12 @@ void SpellCheckHostImpl::CallSpellingService(
if (text.empty()) if (text.empty())
mojo::ReportBadMessage(__FUNCTION__); mojo::ReportBadMessage(__FUNCTION__);
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features.
// current platform.
std::move(callback).Run(false, std::vector<SpellCheckResult>()); std::move(callback).Run(false, std::vector<SpellCheckResult>());
} }
#endif // !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void SpellCheckHostImpl::RequestTextCheck(const base::string16& text, void SpellCheckHostImpl::RequestTextCheck(const base::string16& text,
int route_id, int route_id,
RequestTextCheckCallback callback) { RequestTextCheckCallback callback) {
...@@ -59,8 +59,7 @@ void SpellCheckHostImpl::RequestTextCheck(const base::string16& text, ...@@ -59,8 +59,7 @@ void SpellCheckHostImpl::RequestTextCheck(const base::string16& text,
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
session_bridge_.RequestTextCheck(text, std::move(callback)); session_bridge_.RequestTextCheck(text, std::move(callback));
#else #else
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features on the platform.
// current non-Android platform.
std::move(callback).Run(std::vector<SpellCheckResult>()); std::move(callback).Run(std::vector<SpellCheckResult>());
#endif #endif
} }
...@@ -78,8 +77,7 @@ void SpellCheckHostImpl::CheckSpelling(const base::string16& word, ...@@ -78,8 +77,7 @@ void SpellCheckHostImpl::CheckSpelling(const base::string16& word,
CheckSpellingCallback callback) { CheckSpellingCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features.
// current platform.
std::move(callback).Run(false); std::move(callback).Run(false);
} }
...@@ -88,7 +86,7 @@ void SpellCheckHostImpl::FillSuggestionList( ...@@ -88,7 +86,7 @@ void SpellCheckHostImpl::FillSuggestionList(
FillSuggestionListCallback callback) { FillSuggestionListCallback callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// This API either requires Chrome-only features, or is not supported on the // This API requires Chrome-only features.
// current platform.
std::move(callback).Run(std::vector<base::string16>()); std::move(callback).Run(std::vector<base::string16>());
} }
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
...@@ -35,8 +35,13 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost { ...@@ -35,8 +35,13 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost {
// spellcheck::mojom::SpellCheckHost: // spellcheck::mojom::SpellCheckHost:
void RequestDictionary() override; void RequestDictionary() override;
void NotifyChecked(const base::string16& word, bool misspelled) override; void NotifyChecked(const base::string16& word, bool misspelled) override;
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void CallSpellingService(const base::string16& text, void CallSpellingService(const base::string16& text,
CallSpellingServiceCallback callback) override; CallSpellingServiceCallback callback) override;
#endif // !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void RequestTextCheck(const base::string16& text, void RequestTextCheck(const base::string16& text,
int route_id, int route_id,
RequestTextCheckCallback callback) override; RequestTextCheckCallback callback) override;
...@@ -46,6 +51,7 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost { ...@@ -46,6 +51,7 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost {
CheckSpellingCallback callback) override; CheckSpellingCallback callback) override;
void FillSuggestionList(const base::string16& word, void FillSuggestionList(const base::string16& word,
FillSuggestionListCallback callback) override; FillSuggestionListCallback callback) override;
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
private: private:
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
......
...@@ -43,4 +43,11 @@ mojom("interfaces") { ...@@ -43,4 +43,11 @@ mojom("interfaces") {
public_deps = [ public_deps = [
"//mojo/common:common_custom_types", "//mojo/common:common_custom_types",
] ]
enabled_features = []
if (use_browser_spellchecker) {
enabled_features += [ "USE_BROWSER_SPELLCHECKER" ]
} else {
enabled_features += [ "USE_RENDERER_SPELLCHECKER" ]
}
} }
...@@ -44,34 +44,35 @@ interface SpellCheckHost { ...@@ -44,34 +44,35 @@ interface SpellCheckHost {
// Asks the host to spellcheck the |text| using a remote Spelling server // Asks the host to spellcheck the |text| using a remote Spelling server
// to do the spellchecking. If the remote Spelling server is available, // to do the spellchecking. If the remote Spelling server is available,
// returns |success| true, and the spellchecked |results|. Note this API // returns |success| true, and the spellchecked |results|.
// requires a !BUILDFLAG(USE_BROWSER_SPELLCHECKER) build. [EnableIf=USE_RENDERER_SPELLCHECKER]
CallSpellingService(mojo_base.mojom.String16 text) => CallSpellingService(mojo_base.mojom.String16 text) =>
(bool success, array<SpellCheckResult> results); (bool success, array<SpellCheckResult> results);
// Asks the host to spellcheck the |text| using a platform-specific spell // Asks the host to spellcheck the |text| using a platform-specific spell
// checker, and returns the spellchecked |results|. Note this API requires a // checker, and returns the spellchecked |results|.
// BUILDFLAG(USE_BROWSER_SPELLCHECKER) build.
// TODO(crbug.com/812959): Try not to pass |route_id|. What SpellCheckHost // TODO(crbug.com/812959): Try not to pass |route_id|. What SpellCheckHost
// needs is the render frame id, which should be passed in a cleaner way. // needs is the render frame id, which should be passed in a cleaner way.
[EnableIf=USE_BROWSER_SPELLCHECKER]
RequestTextCheck(mojo_base.mojom.String16 text, int32 route_id) => RequestTextCheck(mojo_base.mojom.String16 text, int32 route_id) =>
(array<SpellCheckResult> results); (array<SpellCheckResult> results);
// Toggles the enabled state of the platform-specific spell checker. Note this // Toggles the enabled state of the platform-specific spell checker.
// API is Android-only. [EnableIf=USE_BROWSER_SPELLCHECKER]
ToggleSpellCheck(bool enabled, bool checked); ToggleSpellCheck(bool enabled, bool checked);
// Checks the correctness of a word with a platform-specific spell checker. // Checks the correctness of a word with a platform-specific spell checker.
// Note this API is Mac-only.
// TODO(groby): This needs to originate from SpellcheckProvider. // TODO(groby): This needs to originate from SpellcheckProvider.
// TODO(crbug.com/812959): Try not to pass |route_id|. What SpellCheckHost // TODO(crbug.com/812959): Try not to pass |route_id|. What SpellCheckHost
// needs is the render frame id, which should be passed in a cleaner way. // needs is the render frame id, which should be passed in a cleaner way.
[Sync] CheckSpelling(mojo_base.mojom.String16 word, int32 route_id) [EnableIf=USE_BROWSER_SPELLCHECKER, Sync]
CheckSpelling(mojo_base.mojom.String16 word, int32 route_id)
=> (bool correct); => (bool correct);
// Returns a list of suggestions for a given word with a platform-specific // Returns a list of suggestions for a given word with a platform-specific
// spell checker. Note this API is Mac-only. // spell checker.
[Sync] FillSuggestionList(mojo_base.mojom.String16 word) => [EnableIf=USE_BROWSER_SPELLCHECKER, Sync]
FillSuggestionList(mojo_base.mojom.String16 word) =>
(array<mojo_base.mojom.String16> suggestions); (array<mojo_base.mojom.String16> suggestions);
}; };
......
...@@ -34,14 +34,12 @@ TestingSpellCheckProvider::TestingSpellCheckProvider( ...@@ -34,14 +34,12 @@ TestingSpellCheckProvider::TestingSpellCheckProvider(
: SpellCheckProvider(nullptr, : SpellCheckProvider(nullptr,
new SpellCheck(nullptr, embedder_provider), new SpellCheck(nullptr, embedder_provider),
embedder_provider), embedder_provider),
spelling_service_call_count_(0),
binding_(this) {} binding_(this) {}
TestingSpellCheckProvider::TestingSpellCheckProvider( TestingSpellCheckProvider::TestingSpellCheckProvider(
SpellCheck* spellcheck, SpellCheck* spellcheck,
service_manager::LocalInterfaceProvider* embedder_provider) service_manager::LocalInterfaceProvider* embedder_provider)
: SpellCheckProvider(nullptr, spellcheck, embedder_provider), : SpellCheckProvider(nullptr, spellcheck, embedder_provider),
spelling_service_call_count_(0),
binding_(this) {} binding_(this) {}
TestingSpellCheckProvider::~TestingSpellCheckProvider() { TestingSpellCheckProvider::~TestingSpellCheckProvider() {
...@@ -68,20 +66,16 @@ void TestingSpellCheckProvider::RequestDictionary() {} ...@@ -68,20 +66,16 @@ void TestingSpellCheckProvider::RequestDictionary() {}
void TestingSpellCheckProvider::NotifyChecked(const base::string16& word, void TestingSpellCheckProvider::NotifyChecked(const base::string16& word,
bool misspelled) {} bool misspelled) {}
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void TestingSpellCheckProvider::CallSpellingService( void TestingSpellCheckProvider::CallSpellingService(
const base::string16& text, const base::string16& text,
CallSpellingServiceCallback callback) { CallSpellingServiceCallback callback) {
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
OnCallSpellingService(text); OnCallSpellingService(text);
std::move(callback).Run(true, std::vector<SpellCheckResult>()); std::move(callback).Run(true, std::vector<SpellCheckResult>());
#else
NOTREACHED();
#endif
} }
void TestingSpellCheckProvider::OnCallSpellingService( void TestingSpellCheckProvider::OnCallSpellingService(
const base::string16& text) { const base::string16& text) {
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
++spelling_service_call_count_; ++spelling_service_call_count_;
blink::WebTextCheckingCompletion* completion = blink::WebTextCheckingCompletion* completion =
text_check_completions_.Lookup(last_identifier_); text_check_completions_.Lookup(last_identifier_);
...@@ -98,20 +92,19 @@ void TestingSpellCheckProvider::OnCallSpellingService( ...@@ -98,20 +92,19 @@ void TestingSpellCheckProvider::OnCallSpellingService(
completion->DidFinishCheckingText(results); completion->DidFinishCheckingText(results);
last_request_ = text; last_request_ = text;
last_results_ = results; last_results_ = results;
#else
NOTREACHED();
#endif
} }
void TestingSpellCheckProvider::ResetResult() {
text_.clear();
}
#endif // !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void TestingSpellCheckProvider::RequestTextCheck( void TestingSpellCheckProvider::RequestTextCheck(
const base::string16& text, const base::string16& text,
int, int,
RequestTextCheckCallback callback) { RequestTextCheckCallback callback) {
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
text_check_requests_.push_back(std::make_pair(text, std::move(callback))); text_check_requests_.push_back(std::make_pair(text, std::move(callback)));
#else
NOTREACHED();
#endif
} }
void TestingSpellCheckProvider::ToggleSpellCheck(bool, bool) { void TestingSpellCheckProvider::ToggleSpellCheck(bool, bool) {
...@@ -128,10 +121,7 @@ void TestingSpellCheckProvider::FillSuggestionList(const base::string16&, ...@@ -128,10 +121,7 @@ void TestingSpellCheckProvider::FillSuggestionList(const base::string16&,
FillSuggestionListCallback) { FillSuggestionListCallback) {
NOTREACHED(); NOTREACHED();
} }
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void TestingSpellCheckProvider::ResetResult() {
text_.clear();
}
void TestingSpellCheckProvider::SetLastResults( void TestingSpellCheckProvider::SetLastResults(
const base::string16 last_request, const base::string16 last_request,
......
...@@ -49,30 +49,39 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -49,30 +49,39 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
void RequestTextChecking(const base::string16& text, void RequestTextChecking(const base::string16& text,
blink::WebTextCheckingCompletion* completion); blink::WebTextCheckingCompletion* completion);
void OnCallSpellingService(const base::string16& text);
void ResetResult();
void SetLastResults( void SetLastResults(
const base::string16 last_request, const base::string16 last_request,
blink::WebVector<blink::WebTextCheckingResult>& last_results); blink::WebVector<blink::WebTextCheckingResult>& last_results);
bool SatisfyRequestFromCache(const base::string16& text, bool SatisfyRequestFromCache(const base::string16& text,
blink::WebTextCheckingCompletion* completion); blink::WebTextCheckingCompletion* completion);
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void ResetResult();
// Variables logging CallSpellingService() mojo calls. // Variables logging CallSpellingService() mojo calls.
base::string16 text_; base::string16 text_;
size_t spelling_service_call_count_; size_t spelling_service_call_count_ = 0;
#endif
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
// Variables logging RequestTextCheck() mojo calls. // Variables logging RequestTextCheck() mojo calls.
using RequestTextCheckParams = using RequestTextCheckParams =
std::pair<base::string16, RequestTextCheckCallback>; std::pair<base::string16, RequestTextCheckCallback>;
std::vector<RequestTextCheckParams> text_check_requests_; std::vector<RequestTextCheckParams> text_check_requests_;
#endif
private: private:
// spellcheck::mojom::SpellCheckHost: // spellcheck::mojom::SpellCheckHost:
void RequestDictionary() override; void RequestDictionary() override;
void NotifyChecked(const base::string16& word, bool misspelled) override; void NotifyChecked(const base::string16& word, bool misspelled) override;
#if !BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void CallSpellingService(const base::string16& text, void CallSpellingService(const base::string16& text,
CallSpellingServiceCallback callback) override; CallSpellingServiceCallback callback) override;
void OnCallSpellingService(const base::string16& text);
#endif
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER)
void RequestTextCheck(const base::string16&, void RequestTextCheck(const base::string16&,
int, int,
RequestTextCheckCallback) override; RequestTextCheckCallback) override;
...@@ -83,6 +92,7 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -83,6 +92,7 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
CheckSpellingCallback) override; CheckSpellingCallback) override;
void FillSuggestionList(const base::string16&, void FillSuggestionList(const base::string16&,
FillSuggestionListCallback) override; FillSuggestionListCallback) override;
#endif
// Message loop (if needed) to deliver the SpellCheckHost request flow. // Message loop (if needed) to deliver the SpellCheckHost request flow.
std::unique_ptr<base::MessageLoop> loop_; std::unique_ptr<base::MessageLoop> loop_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment