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

Unified Diff: android_webview/native/aw_contents.cc

Issue 2839023003: WebView autofill implementation (Closed)
Patch Set: address comments 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
Index: android_webview/native/aw_contents.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 5d348686112afc1623dec547e209268a2db50412..04cd621766da7eeb88e3ba658c84876a594dcb9f 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/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"
@@ -289,19 +290,33 @@ void AwContents::SetSaveFormData(bool enabled) {
}
void AwContents::InitAutofillIfNecessary(bool enabled) {
sgurun-gerrit only 2017/05/11 00:13:29 rename enabled to autocomplete_enabled
- // Do not initialize if the feature is not enabled.
- if (!enabled)
- return;
// 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;
+
+ base::android::ScopedJavaLocalRef<_jobject*> jAutofillProvider =
sgurun-gerrit only 2017/05/11 00:13:29 you can drop this once you use nativeSetJavaPeers.
michaelbai 2017/05/12 00:37:23 Done.
+ Java_AwContents_getAutofillProvider(env, obj);
+
+ // Just return, if the app neither targets for O nor enables autocomplete.
sgurun-gerrit only 2017/05/11 00:13:29 s/app targets for O/app runs on O SDK/
michaelbai 2017/05/12 00:37:23 Done.
+ if (jAutofillProvider.is_null() && !enabled)
+ return;
+
+ autofill_provider_ = base::MakeUnique<autofill::AutofillProviderAndroid>(
+ jAutofillProvider, web_contents);
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) {
@@ -1364,6 +1379,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;

Powered by Google App Engine
This is Rietveld 408576698