Commit c61efb0c authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

WebLayer: hook up spellcheck on Android.

WebLayer uses the same implementation as WebView. What it lacks compared
to Clank is just metrics. That is, the parts of
//chrome/browser/spellchecker that Clank actually uses are purely
metrics as the spelling service is not enabled for Clank.

Implementing spellcheck for desktop would require refactoring a lot of
//chrome/browser/spellchecker.

Bug: 1025621
Change-Id: I186f78c08d97267cb8d55e55adff952018293840
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1929494
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721708}
parent 4a4f9a56
......@@ -16,6 +16,8 @@ namespace service_manager {
class LocalInterfaceProvider {
public:
virtual ~LocalInterfaceProvider() = default;
// Binds |ptr| to an implementation of Interface in the remote application.
// |ptr| can immediately be used to start sending requests to the remote
// interface.
......
......@@ -8,6 +8,7 @@ import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//build/config/win/console_app.gni")
import("//build/config/win/manifest.gni")
import("//components/spellcheck/spellcheck_build_features.gni")
import("//gpu/vulkan/features.gni")
import("//media/media_options.gni")
import("//mojo/public/tools/bindings/mojom.gni")
......@@ -185,6 +186,7 @@ jumbo_static_library("weblayer_lib") {
"//components/security_interstitials/content:security_interstitial_page",
"//components/security_interstitials/content/renderer:security_interstitial_page_controller",
"//components/security_interstitials/core",
"//components/spellcheck:buildflags",
"//components/startup_metric_utils/browser:lib",
"//components/user_prefs",
"//components/version_info",
......@@ -227,6 +229,13 @@ jumbo_static_library("weblayer_lib") {
"//weblayer/browser/webui:mojo_bindings",
]
if (use_browser_spellchecker) {
deps += [
"//components/spellcheck/browser",
"//components/spellcheck/renderer",
]
}
if (is_android) {
sources += [
"common/crash_reporter/crash_keys.cc",
......
......@@ -11,6 +11,7 @@ include_rules = [
"+components/user_prefs",
"+components/safe_browsing",
"+components/security_interstitials",
"+components/spellcheck/browser",
"+components/startup_metric_utils",
"+components/version_info",
"+components/web_cache/browser",
......
......@@ -49,7 +49,13 @@
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/android/path_utils.h"
#include "base/bind.h"
#include "base/task/post_task.h"
#include "components/crash/content/browser/crash_handler_host_linux.h"
#include "components/spellcheck/browser/spell_check_host_impl.h" // nogncheck
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "ui/base/resource/resource_bundle_android.h"
#include "weblayer/browser/android_descriptors.h"
#include "weblayer/browser/devtools_manager_delegate_android.h"
......@@ -324,12 +330,21 @@ void ContentBrowserClientImpl::ExposeInterfacesToRenderer(
service_manager::BinderRegistry* registry,
blink::AssociatedInterfaceRegistry* associated_registry,
content::RenderProcessHost* render_process_host) {
#if defined(OS_ANDROID)
auto create_spellcheck_host =
[](mojo::PendingReceiver<spellcheck::mojom::SpellCheckHost> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<SpellCheckHostImpl>(),
std::move(receiver));
};
registry->AddInterface(
base::BindRepeating(create_spellcheck_host),
base::CreateSingleThreadTaskRunner({content::BrowserThread::UI}));
if (base::FeatureList::IsEnabled(features::kWebLayerSafeBrowsing) &&
IsSafebrowsingSupported()) {
#if defined(OS_ANDROID)
GetSafeBrowsingService()->AddInterface(registry, render_process_host);
#endif
}
#endif // defined(OS_ANDROID)
}
#if defined(OS_ANDROID)
......
......@@ -67,6 +67,7 @@ android_library("java") {
"//components/embedder_support/android:application_java",
"//components/embedder_support/android:web_contents_delegate_java",
"//components/minidump_uploader:minidump_uploader_java",
"//components/spellcheck/browser/android:java",
"//components/version_info/android:version_constants_java",
"//content/public/android:content_java",
"//third_party/android_deps:com_android_support_support_compat_java",
......
......@@ -8,10 +8,12 @@ include_rules = [
"+components/safe_browsing/renderer",
"+components/security_interstitials/content/renderer",
"+components/security_interstitials/core/common",
"+components/spellcheck/renderer",
"+content/public/renderer",
# needed for safebrowsing
"+mojo/public/cpp/bindings",
"+net/base",
"+services/service_manager/public/cpp",
"+third_party/blink/public/common",
"+third_party/blink/public/platform",
"+ui/base",
......
......@@ -19,6 +19,10 @@
#if defined(OS_ANDROID)
#include "android_webview/grit/aw_resources.h"
#include "android_webview/grit/aw_strings.h"
#include "components/spellcheck/renderer/spellcheck.h" // nogncheck
#include "components/spellcheck/renderer/spellcheck_provider.h" // nogncheck
#include "content/public/renderer/render_thread.h"
#include "services/service_manager/public/cpp/local_interface_provider.h"
#include "weblayer/renderer/url_loader_throttle_provider.h"
#endif
......@@ -80,14 +84,55 @@ void PopulateErrorPageHTML(const blink::WebURLError& error,
}
#endif // OS_ANDROID
#if defined(OS_ANDROID)
class SpellcheckInterfaceProvider
: public service_manager::LocalInterfaceProvider {
public:
SpellcheckInterfaceProvider() = default;
~SpellcheckInterfaceProvider() override = default;
// service_manager::LocalInterfaceProvider:
void GetInterface(const std::string& interface_name,
mojo::ScopedMessagePipeHandle interface_pipe) override {
// A dirty hack to make SpellCheckHost requests work on WebLayer.
// TODO(crbug.com/806394): Use a WebView-specific service for SpellCheckHost
// and SafeBrowsing, instead of |content_browser|.
content::RenderThread::Get()->BindHostReceiver(mojo::GenericPendingReceiver(
interface_name, std::move(interface_pipe)));
}
private:
DISALLOW_COPY_AND_ASSIGN(SpellcheckInterfaceProvider);
};
#endif // defined(OS_ANDROID)
} // namespace
ContentRendererClientImpl::ContentRendererClientImpl() = default;
ContentRendererClientImpl::~ContentRendererClientImpl() = default;
void ContentRendererClientImpl::RenderThreadStarted() {
#if defined(OS_ANDROID)
if (!spellcheck_) {
local_interface_provider_ = std::make_unique<SpellcheckInterfaceProvider>();
spellcheck_ = std::make_unique<SpellCheck>(local_interface_provider_.get());
}
#endif
browser_interface_broker_ =
blink::Platform::Current()->GetBrowserInterfaceBroker();
}
void ContentRendererClientImpl::RenderFrameCreated(
content::RenderFrame* render_frame) {
SSLErrorHelper::Create(render_frame);
#if defined(OS_ANDROID)
// |SpellCheckProvider| manages its own lifetime (and destroys itself when the
// RenderFrame is destroyed).
new SpellCheckProvider(render_frame, spellcheck_.get(),
local_interface_provider_.get());
#endif
}
bool ContentRendererClientImpl::HasErrorPage(int http_status_code) {
......@@ -108,11 +153,6 @@ void ContentRendererClientImpl::PrepareErrorPage(
#endif
}
void ContentRendererClientImpl::RenderThreadStarted() {
browser_interface_broker_ =
blink::Platform::Current()->GetBrowserInterfaceBroker();
}
std::unique_ptr<content::URLLoaderThrottleProvider>
ContentRendererClientImpl::CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) {
......
......@@ -6,9 +6,16 @@
#define WEBLAYER_RENDERER_CONTENT_RENDERER_CLIENT_IMPL_H_
#include "base/macros.h"
#include "build/build_config.h"
#include "content/public/renderer/content_renderer_client.h"
#include "third_party/blink/public/common/thread_safe_browser_interface_broker_proxy.h"
class SpellCheck;
namespace service_manager {
class LocalInterfaceProvider;
} // namespace service_manager
namespace weblayer {
class ContentRendererClientImpl : public content::ContentRendererClient {
......@@ -17,18 +24,24 @@ class ContentRendererClientImpl : public content::ContentRendererClient {
~ContentRendererClientImpl() override;
// content::ContentRendererClient:
void RenderThreadStarted() override;
void RenderFrameCreated(content::RenderFrame* render_frame) override;
bool HasErrorPage(int http_status_code) override;
void PrepareErrorPage(content::RenderFrame* render_frame,
const blink::WebURLError& error,
const std::string& http_method,
std::string* error_html) override;
void RenderThreadStarted() override;
std::unique_ptr<content::URLLoaderThrottleProvider>
CreateURLLoaderThrottleProvider(
content::URLLoaderThrottleProviderType provider_type) override;
private:
#if defined(OS_ANDROID)
std::unique_ptr<service_manager::LocalInterfaceProvider>
local_interface_provider_;
std::unique_ptr<SpellCheck> spellcheck_;
#endif
scoped_refptr<blink::ThreadSafeBrowserInterfaceBrokerProxy>
browser_interface_broker_;
......
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