Commit 469d6f7b authored by timvolodine's avatar timvolodine Committed by Commit bot

[Android] Add spellchecking support in android_webview.

Add spellcheck functionality to webview. Spellchecking
feature will be enabled if the kEnableAndroidSpellChecker
flag is present.

Historical note:
Blink used to have unified_textchecker_enabled setting
which was false by default in android webview and
needed to be enabled in order for spellchecking to work.
It was recently removed in
https://codereview.chromium.org/2235643002/ though.

BUG=583616, 629609

Review-Url: https://codereview.chromium.org/2264633002
Cr-Commit-Position: refs/heads/master@{#414331}
parent 9b61930c
......@@ -630,6 +630,13 @@ source_set("common") {
]
}
if (enable_spellcheck) {
deps += [
"//components/spellcheck/browser",
"//components/spellcheck/renderer",
]
}
configs += [ "//v8:external_startup_data" ]
}
......@@ -719,6 +726,10 @@ android_library("android_webview_java") {
deps += [ "//components/policy/android:policy_java" ]
}
if (enable_spellcheck) {
deps += [ "//components/spellcheck/browser/android:java" ]
}
srcjar_deps = [ "//android_webview/native:aw_permission_request_resource" ]
}
......
......@@ -20,6 +20,8 @@ include_rules = [
"+components/pref_registry",
"+components/printing/browser",
"+components/printing/common",
"+components/spellcheck/browser",
"+components/spellcheck/common",
"+components/url_formatter",
"+components/user_prefs",
"+components/visitedlink/browser",
......
......@@ -55,6 +55,11 @@
#include "ui/base/resource/resource_bundle_android.h"
#include "ui/resources/grit/ui_resources.h"
#if defined(ENABLE_SPELLCHECK)
#include "components/spellcheck/browser/spellcheck_message_filter_platform.h"
#include "components/spellcheck/common/spellcheck_switches.h"
#endif
using content::BrowserThread;
using content::ResourceType;
......@@ -218,6 +223,13 @@ void AwContentBrowserClient::RenderProcessWillLaunch(
host->AddFilter(new AwContentsMessageFilter(host->GetID()));
host->AddFilter(new cdm::CdmMessageFilterAndroid());
host->AddFilter(new AwPrintingMessageFilter(host->GetID()));
#if defined(ENABLE_SPELLCHECK)
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
spellcheck::switches::kEnableAndroidSpellChecker)) {
host->AddFilter(new SpellCheckMessageFilterPlatform(host->GetID()));
}
#endif
}
bool AwContentBrowserClient::IsHandledURL(const GURL& url) {
......
......@@ -118,6 +118,10 @@ source_set("native") {
deps += [ "//components/external_video_surface:external_video_surface" ]
}
if (enable_spellcheck) {
deps += [ "//components/spellcheck/browser:browser" ]
}
libs = [ "jnigraphics" ]
}
......
......@@ -14,6 +14,7 @@ include_rules = [
"+components/devtools_http_handler",
"+components/external_video_surface",
"+components/navigation_interception",
"+components/spellcheck/browser/android",
"+components/user_prefs",
"+components/web_contents_delegate_android",
......
......@@ -27,6 +27,10 @@
#include "base/android/jni_registrar.h"
#include "base/trace_event/trace_event.h"
#if defined(ENABLE_SPELLCHECK)
#include "components/spellcheck/browser/android/component_jni_registrar.h"
#endif
namespace android_webview {
static base::android::RegistrationMethod kWebViewRegisteredMethods[] = {
......@@ -50,6 +54,9 @@ static base::android::RegistrationMethod kWebViewRegisteredMethods[] = {
{ "CookieManager", RegisterCookieManager },
{ "AwMessagePortService", RegisterAwMessagePortService },
{ "AwGLFunctor", RegisterAwGLFunctor },
#if defined(ENABLE_SPELLCHECK)
{"SpellCheckerSessionBridge", spellcheck::android::RegisterSpellcheckJni},
#endif
};
bool RegisterJni(JNIEnv* env) {
......
......@@ -8,6 +8,7 @@ include_rules = [
"+components/cdm/renderer",
"+components/printing/common",
"+components/printing/renderer",
"+components/spellcheck/renderer",
"+components/visitedlink/renderer",
"+content/public/child",
......
......@@ -52,6 +52,11 @@
#include "url/gurl.h"
#include "url/url_constants.h"
#if defined(ENABLE_SPELLCHECK)
#include "components/spellcheck/renderer/spellcheck.h"
#include "components/spellcheck/renderer/spellcheck_provider.h"
#endif
using content::RenderThread;
namespace android_webview {
......@@ -74,6 +79,13 @@ void AwContentRendererClient::RenderThreadStarted() {
blink::WebString aw_scheme(
base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme));
blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme);
#if defined(ENABLE_SPELLCHECK)
if (!spellcheck_) {
spellcheck_ = base::MakeUnique<SpellCheck>();
thread->AddObserver(spellcheck_.get());
}
#endif
}
bool AwContentRendererClient::HandleNavigation(
......@@ -163,6 +175,10 @@ void AwContentRendererClient::RenderViewCreated(
new printing::PrintWebViewHelper(
render_view, std::unique_ptr<printing::PrintWebViewHelper::Delegate>(
new AwPrintWebViewHelperDelegate()));
#if defined(ENABLE_SPELLCHECK)
new SpellCheckProvider(render_view, spellcheck_.get());
#endif
}
bool AwContentRendererClient::HasErrorPage(int http_status_code,
......
......@@ -14,6 +14,11 @@
#include "components/web_restrictions/interfaces/web_restrictions.mojom.h"
#include "content/public/renderer/content_renderer_client.h"
#if defined(ENABLE_SPELLCHECK)
class SpellCheck;
class SpellCheckProvider;
#endif
namespace visitedlink {
class VisitedLinkSlave;
}
......@@ -57,6 +62,10 @@ class AwContentRendererClient : public content::ContentRendererClient {
std::unique_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
web_restrictions::mojom::WebRestrictionsPtr web_restrictions_service_;
#if defined(ENABLE_SPELLCHECK)
std::unique_ptr<SpellCheck> spellcheck_;
#endif
DISALLOW_COPY_AND_ASSIGN(AwContentRendererClient);
};
......
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