| 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..cca32be42ff225e0fa20249e481a5a52abe9d168 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/content/browser/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) {
|
| - // 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 =
|
| + Java_AwContents_getAutofillProvider(env, obj);
|
| +
|
| + // Just return, if the app neither targets for O nor enables autocomplete.
|
| + 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;
|
|
|