Commit 551a8c17 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Refactor SpellCheckHost::ToggleSpellCheck

The mojo API is a no-op other than on Android with |enabled| being
false. This patch refactors it and renames it into
|DisconnectSessionBridge| to make the behavior more explicit.

Bug: 814225
Change-Id: I786411375edd594806fb2f7bcdc7b884be4352fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1500016
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637847}
parent 22ea6590
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/external_protocol/external_protocol_handler.h" #include "chrome/browser/external_protocol/external_protocol_handler.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -947,7 +948,6 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { ...@@ -947,7 +948,6 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
TextReceived(text); TextReceived(text);
} }
void ToggleSpellCheck(bool, bool) override {}
void CheckSpelling(const base::string16& word, void CheckSpelling(const base::string16& word,
int, int,
CheckSpellingCallback) override {} CheckSpellingCallback) override {}
...@@ -955,6 +955,11 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost { ...@@ -955,6 +955,11 @@ class MockSpellCheckHost : spellcheck::mojom::SpellCheckHost {
FillSuggestionListCallback) override {} FillSuggestionListCallback) override {}
#endif #endif
#if defined(OS_ANDROID)
// spellcheck::mojom::SpellCheckHost:
void DisconnectSessionBridge() override {}
#endif
content::RenderProcessHost* process_host_; content::RenderProcessHost* process_host_;
bool text_received_ = false; bool text_received_ = false;
base::string16 text_; base::string16 text_;
......
...@@ -63,14 +63,6 @@ void SpellCheckHostImpl::RequestTextCheck(const base::string16& text, ...@@ -63,14 +63,6 @@ void SpellCheckHostImpl::RequestTextCheck(const base::string16& text,
#endif #endif
} }
void SpellCheckHostImpl::ToggleSpellCheck(bool enabled, bool checked) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
#if defined(OS_ANDROID)
if (!enabled)
session_bridge_.DisconnectSession();
#endif
}
void SpellCheckHostImpl::CheckSpelling(const base::string16& word, void SpellCheckHostImpl::CheckSpelling(const base::string16& word,
int route_id, int route_id,
CheckSpellingCallback callback) { CheckSpellingCallback callback) {
...@@ -89,3 +81,10 @@ void SpellCheckHostImpl::FillSuggestionList( ...@@ -89,3 +81,10 @@ void SpellCheckHostImpl::FillSuggestionList(
std::move(callback).Run(std::vector<base::string16>()); std::move(callback).Run(std::vector<base::string16>());
} }
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) #endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if defined(OS_ANDROID)
void SpellCheckHostImpl::DisconnectSessionBridge() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
session_bridge_.DisconnectSession();
}
#endif
...@@ -45,7 +45,6 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost { ...@@ -45,7 +45,6 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost {
void RequestTextCheck(const base::string16& text, void RequestTextCheck(const base::string16& text,
int route_id, int route_id,
RequestTextCheckCallback callback) override; RequestTextCheckCallback callback) override;
void ToggleSpellCheck(bool enabled, bool checked) override;
void CheckSpelling(const base::string16& word, void CheckSpelling(const base::string16& word,
int route_id, int route_id,
CheckSpellingCallback callback) override; CheckSpellingCallback callback) override;
...@@ -53,6 +52,11 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost { ...@@ -53,6 +52,11 @@ class SpellCheckHostImpl : public spellcheck::mojom::SpellCheckHost {
FillSuggestionListCallback callback) override; FillSuggestionListCallback callback) override;
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) #endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if defined(OS_ANDROID)
// spellcheck::mojom::SpellCheckHost:
void DisconnectSessionBridge() override;
#endif
private: private:
#if defined(OS_ANDROID) #if defined(OS_ANDROID)
// Android-specific object used to query the Android spellchecker. // Android-specific object used to query the Android spellchecker.
......
...@@ -55,10 +55,10 @@ void SpellCheckerSessionBridge::RequestTextCheck( ...@@ -55,10 +55,10 @@ void SpellCheckerSessionBridge::RequestTextCheck(
} }
// RequestTextCheck API call arrives at the SpellCheckHost before // RequestTextCheck API call arrives at the SpellCheckHost before
// ToggleSpellCheck when the user focuses an input field that already // DisconnectSessionBridge when the user focuses an input field that already
// contains completed text. We need to initialize the spellchecker here // contains completed text. We need to initialize the spellchecker here
// rather than in response to ToggleSpellCheck so that the existing text // rather than in response to DisconnectSessionBridge so that the existing
// will be spellchecked immediately. // text will be spellchecked immediately.
if (java_object_.is_null()) { if (java_object_.is_null()) {
java_object_.Reset(Java_SpellCheckerSessionBridge_create( java_object_.Reset(Java_SpellCheckerSessionBridge_create(
base::android::AttachCurrentThread(), base::android::AttachCurrentThread(),
......
...@@ -57,9 +57,9 @@ interface SpellCheckHost { ...@@ -57,9 +57,9 @@ interface SpellCheckHost {
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. // Disconnects the Android spell checker session bridge.
[EnableIf=USE_BROWSER_SPELLCHECKER] [EnableIf=is_android]
ToggleSpellCheck(bool enabled, bool checked); DisconnectSessionBridge();
// Checks the correctness of a word with a platform-specific spell checker. // Checks the correctness of a word with a platform-specific spell checker.
// TODO(groby): This needs to originate from SpellcheckProvider. // TODO(groby): This needs to originate from SpellcheckProvider.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "build/build_config.h"
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
#include "components/spellcheck/common/spellcheck_result.h" #include "components/spellcheck/common/spellcheck_result.h"
#include "components/spellcheck/renderer/spellcheck.h" #include "components/spellcheck/renderer/spellcheck.h"
...@@ -144,15 +145,18 @@ void SpellCheckProvider::RequestTextChecking( ...@@ -144,15 +145,18 @@ void SpellCheckProvider::RequestTextChecking(
} }
void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) { void SpellCheckProvider::FocusedNodeChanged(const blink::WebNode& unused) {
#if BUILDFLAG(USE_BROWSER_SPELLCHECKER) #if defined(OS_ANDROID)
WebLocalFrame* frame = render_frame()->GetWebFrame(); WebLocalFrame* frame = render_frame()->GetWebFrame();
WebElement element = frame->GetDocument().IsNull() WebElement element = frame->GetDocument().IsNull()
? WebElement() ? WebElement()
: frame->GetDocument().FocusedElement(); : frame->GetDocument().FocusedElement();
bool enabled = !element.IsNull() && element.IsEditable(); bool enabled = !element.IsNull() && element.IsEditable();
bool checked = enabled && IsSpellCheckingEnabled();
GetSpellCheckHost().ToggleSpellCheck(enabled, checked); // TODO(xiaochengh): Don't call GetSpellCheckHost() if SpellCheckHost is not
#endif // USE_BROWSER_SPELLCHECKER // bound yet. crbug.com/814225
if (!enabled)
GetSpellCheckHost().DisconnectSessionBridge();
#endif // defined(OS_ANDROID)
} }
bool SpellCheckProvider::IsSpellCheckingEnabled() const { bool SpellCheckProvider::IsSpellCheckingEnabled() const {
......
...@@ -109,10 +109,6 @@ void TestingSpellCheckProvider::RequestTextCheck( ...@@ -109,10 +109,6 @@ void TestingSpellCheckProvider::RequestTextCheck(
text_check_requests_.push_back(std::make_pair(text, std::move(callback))); text_check_requests_.push_back(std::make_pair(text, std::move(callback)));
} }
void TestingSpellCheckProvider::ToggleSpellCheck(bool, bool) {
NOTREACHED();
}
void TestingSpellCheckProvider::CheckSpelling(const base::string16&, void TestingSpellCheckProvider::CheckSpelling(const base::string16&,
int, int,
CheckSpellingCallback) { CheckSpellingCallback) {
...@@ -125,6 +121,12 @@ void TestingSpellCheckProvider::FillSuggestionList(const base::string16&, ...@@ -125,6 +121,12 @@ void TestingSpellCheckProvider::FillSuggestionList(const base::string16&,
} }
#endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER) #endif // BUILDFLAG(USE_BROWSER_SPELLCHECKER)
#if defined(OS_ANDROID)
void TestingSpellCheckProvider::DisconnectSessionBridge() {
NOTREACHED();
}
#endif
void TestingSpellCheckProvider::SetLastResults( void TestingSpellCheckProvider::SetLastResults(
const base::string16 last_request, const base::string16 last_request,
blink::WebVector<blink::WebTextCheckingResult>& last_results) { blink::WebVector<blink::WebTextCheckingResult>& last_results) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <vector> #include <vector>
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "build/build_config.h"
#include "components/spellcheck/renderer/empty_local_interface_provider.h" #include "components/spellcheck/renderer/empty_local_interface_provider.h"
#include "components/spellcheck/renderer/spellcheck_provider.h" #include "components/spellcheck/renderer/spellcheck_provider.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/binding.h"
...@@ -88,7 +89,6 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -88,7 +89,6 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
void RequestTextCheck(const base::string16&, void RequestTextCheck(const base::string16&,
int, int,
RequestTextCheckCallback) override; RequestTextCheckCallback) override;
void ToggleSpellCheck(bool, bool) override;
using SpellCheckProvider::CheckSpelling; using SpellCheckProvider::CheckSpelling;
void CheckSpelling(const base::string16&, void CheckSpelling(const base::string16&,
int, int,
...@@ -97,6 +97,10 @@ class TestingSpellCheckProvider : public SpellCheckProvider, ...@@ -97,6 +97,10 @@ class TestingSpellCheckProvider : public SpellCheckProvider,
FillSuggestionListCallback) override; FillSuggestionListCallback) override;
#endif #endif
#if defined(OS_ANDROID)
void DisconnectSessionBridge() 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