Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1824)

Unified Diff: android_webview/browser/aw_contents.cc

Issue 2745803003: autofill-try
Patch Set: autofill-try Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « android_webview/browser/aw_contents.h ('k') | android_webview/glue/glue.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: android_webview/browser/aw_contents.cc
diff --git a/android_webview/browser/aw_contents.cc b/android_webview/browser/aw_contents.cc
index 45fc4ff0747ec3bd09332abdd8eb28a86b0176aa..1cf6be1f699cca77356ec79ce0b3279ca4a0aa9e 100644
--- a/android_webview/browser/aw_contents.cc
+++ b/android_webview/browser/aw_contents.cc
@@ -52,6 +52,7 @@
#include "base/strings/string16.h"
#include "base/supports_user_data.h"
#include "base/threading/thread_task_runner_handle.h"
+#include "components/autofill/android/autofill_provider_android.h"
#include "components/autofill/content/browser/content_autofill_driver_factory.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
@@ -249,7 +250,8 @@ void AwContents::SetJavaPeers(
const JavaParamRef<jobject>& web_contents_delegate,
const JavaParamRef<jobject>& contents_client_bridge,
const JavaParamRef<jobject>& io_thread_client,
- const JavaParamRef<jobject>& intercept_navigation_delegate) {
+ const JavaParamRef<jobject>& intercept_navigation_delegate,
+ const JavaParamRef<jobject>& autofill_provider) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
// The |aw_content| param is technically spurious as it duplicates |obj| but
// is passed over anyway to make the binding more explicit.
@@ -271,6 +273,11 @@ void AwContents::SetJavaPeers(
web_contents_.get(), base::MakeUnique<InterceptNavigationDelegate>(
env, intercept_navigation_delegate));
+ if (!autofill_provider.is_null()) {
+ autofill_provider_ = base::MakeUnique<autofill::AutofillProviderAndroid>(
+ autofill_provider, web_contents_.get());
+ }
+
// Finally, having setup the associations, release any deferred requests
for (content::RenderFrameHost* rfh : web_contents_->GetAllFrames()) {
int render_process_id = rfh->GetProcess()->GetID();
@@ -291,20 +298,29 @@ void AwContents::SetSaveFormData(bool enabled) {
}
}
-void AwContents::InitAutofillIfNecessary(bool enabled) {
- // Do not initialize if the feature is not enabled.
- if (!enabled)
- return;
+void AwContents::InitAutofillIfNecessary(bool autocomplete_enabled) {
// Check if the autofill driver factory already exists.
content::WebContents* web_contents = web_contents_.get();
if (ContentAutofillDriverFactory::FromWebContents(web_contents))
return;
+ // Check if AutofillProvider is available.
+ DCHECK_CURRENTLY_ON(BrowserThread::UI);
+ JNIEnv* env = AttachCurrentThread();
+ ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
+ if (obj.is_null())
+ return;
+
+ // Just return, if the app neither runs on O sdk nor enables autocomplete.
+ if (!autofill_provider_ && !autocomplete_enabled)
+ return;
+
AwAutofillClient::CreateForWebContents(web_contents);
ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
web_contents, AwAutofillClient::FromWebContents(web_contents),
base::android::GetDefaultLocaleString(),
- AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
+ AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER,
+ autofill_provider_.get());
}
void AwContents::SetAwAutofillClient(const JavaRef<jobject>& client) {
@@ -1361,6 +1377,12 @@ void AwContents::ResumeLoadingCreatedPopupWebContents(
web_contents_->ResumeLoadingCreatedWebContents();
}
+jlong AwContents::GetAutofillProvider(
+ JNIEnv* env,
+ const base::android::JavaParamRef<jobject>& obj) {
+ return reinterpret_cast<jlong>(autofill_provider_.get());
+}
+
void SetShouldDownloadFavicons(JNIEnv* env,
const JavaParamRef<jclass>& jclazz) {
g_should_download_favicons = true;
« no previous file with comments | « android_webview/browser/aw_contents.h ('k') | android_webview/glue/glue.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698