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

Side by Side Diff: android_webview/browser/aw_contents.cc

Issue 2839023003: WebView autofill implementation (Closed)
Patch Set: sync Created 3 years, 6 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "android_webview/browser/aw_contents.h" 5 #include "android_webview/browser/aw_contents.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "android_webview/browser/aw_autofill_client.h" 10 #include "android_webview/browser/aw_autofill_client.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 #include "base/callback.h" 44 #include "base/callback.h"
45 #include "base/command_line.h" 45 #include "base/command_line.h"
46 #include "base/location.h" 46 #include "base/location.h"
47 #include "base/memory/memory_pressure_listener.h" 47 #include "base/memory/memory_pressure_listener.h"
48 #include "base/memory/ptr_util.h" 48 #include "base/memory/ptr_util.h"
49 #include "base/pickle.h" 49 #include "base/pickle.h"
50 #include "base/single_thread_task_runner.h" 50 #include "base/single_thread_task_runner.h"
51 #include "base/strings/string16.h" 51 #include "base/strings/string16.h"
52 #include "base/supports_user_data.h" 52 #include "base/supports_user_data.h"
53 #include "base/threading/thread_task_runner_handle.h" 53 #include "base/threading/thread_task_runner_handle.h"
54 #include "components/autofill/android/autofill_provider_android.h"
54 #include "components/autofill/content/browser/content_autofill_driver_factory.h" 55 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
55 #include "components/autofill/core/browser/autofill_manager.h" 56 #include "components/autofill/core/browser/autofill_manager.h"
56 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 57 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
57 #include "components/navigation_interception/intercept_navigation_delegate.h" 58 #include "components/navigation_interception/intercept_navigation_delegate.h"
58 #include "content/public/browser/android/content_view_core.h" 59 #include "content/public/browser/android/content_view_core.h"
59 #include "content/public/browser/android/synchronous_compositor.h" 60 #include "content/public/browser/android/synchronous_compositor.h"
60 #include "content/public/browser/browser_thread.h" 61 #include "content/public/browser/browser_thread.h"
61 #include "content/public/browser/browsing_data_remover.h" 62 #include "content/public/browser/browsing_data_remover.h"
62 #include "content/public/browser/child_process_security_policy.h" 63 #include "content/public/browser/child_process_security_policy.h"
63 #include "content/public/browser/favicon_status.h" 64 #include "content/public/browser/favicon_status.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 AwContentsLifecycleNotifier::OnWebViewCreated(); 242 AwContentsLifecycleNotifier::OnWebViewCreated();
242 } 243 }
243 244
244 void AwContents::SetJavaPeers( 245 void AwContents::SetJavaPeers(
245 JNIEnv* env, 246 JNIEnv* env,
246 const JavaParamRef<jobject>& obj, 247 const JavaParamRef<jobject>& obj,
247 const JavaParamRef<jobject>& aw_contents, 248 const JavaParamRef<jobject>& aw_contents,
248 const JavaParamRef<jobject>& web_contents_delegate, 249 const JavaParamRef<jobject>& web_contents_delegate,
249 const JavaParamRef<jobject>& contents_client_bridge, 250 const JavaParamRef<jobject>& contents_client_bridge,
250 const JavaParamRef<jobject>& io_thread_client, 251 const JavaParamRef<jobject>& io_thread_client,
251 const JavaParamRef<jobject>& intercept_navigation_delegate) { 252 const JavaParamRef<jobject>& intercept_navigation_delegate,
253 const JavaParamRef<jobject>& autofill_provider) {
252 DCHECK_CURRENTLY_ON(BrowserThread::UI); 254 DCHECK_CURRENTLY_ON(BrowserThread::UI);
253 // The |aw_content| param is technically spurious as it duplicates |obj| but 255 // The |aw_content| param is technically spurious as it duplicates |obj| but
254 // is passed over anyway to make the binding more explicit. 256 // is passed over anyway to make the binding more explicit.
255 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents); 257 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents);
256 258
257 web_contents_delegate_.reset( 259 web_contents_delegate_.reset(
258 new AwWebContentsDelegate(env, web_contents_delegate)); 260 new AwWebContentsDelegate(env, web_contents_delegate));
259 web_contents_->SetDelegate(web_contents_delegate_.get()); 261 web_contents_->SetDelegate(web_contents_delegate_.get());
260 262
261 contents_client_bridge_.reset( 263 contents_client_bridge_.reset(
262 new AwContentsClientBridge(env, contents_client_bridge)); 264 new AwContentsClientBridge(env, contents_client_bridge));
263 AwContentsClientBridge::Associate(web_contents_.get(), 265 AwContentsClientBridge::Associate(web_contents_.get(),
264 contents_client_bridge_.get()); 266 contents_client_bridge_.get());
265 267
266 AwContentsIoThreadClient::Associate(web_contents_.get(), io_thread_client); 268 AwContentsIoThreadClient::Associate(web_contents_.get(), io_thread_client);
267 269
268 InterceptNavigationDelegate::Associate( 270 InterceptNavigationDelegate::Associate(
269 web_contents_.get(), base::MakeUnique<InterceptNavigationDelegate>( 271 web_contents_.get(), base::MakeUnique<InterceptNavigationDelegate>(
270 env, intercept_navigation_delegate)); 272 env, intercept_navigation_delegate));
271 273
274 if (!autofill_provider.is_null()) {
275 autofill_provider_ = base::MakeUnique<autofill::AutofillProviderAndroid>(
276 autofill_provider, web_contents_.get());
277 }
278
272 // Finally, having setup the associations, release any deferred requests 279 // Finally, having setup the associations, release any deferred requests
273 for (content::RenderFrameHost* rfh : web_contents_->GetAllFrames()) { 280 for (content::RenderFrameHost* rfh : web_contents_->GetAllFrames()) {
274 int render_process_id = rfh->GetProcess()->GetID(); 281 int render_process_id = rfh->GetProcess()->GetID();
275 int render_frame_id = rfh->GetRoutingID(); 282 int render_frame_id = rfh->GetRoutingID();
276 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(render_process_id, 283 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(render_process_id,
277 render_frame_id); 284 render_frame_id);
278 } 285 }
279 } 286 }
280 287
281 void AwContents::SetSaveFormData(bool enabled) { 288 void AwContents::SetSaveFormData(bool enabled) {
282 DCHECK_CURRENTLY_ON(BrowserThread::UI); 289 DCHECK_CURRENTLY_ON(BrowserThread::UI);
283 InitAutofillIfNecessary(enabled); 290 InitAutofillIfNecessary(enabled);
284 // We need to check for the existence, since autofill_manager_delegate 291 // We need to check for the existence, since autofill_manager_delegate
285 // may not be created when the setting is false. 292 // may not be created when the setting is false.
286 if (AwAutofillClient::FromWebContents(web_contents_.get())) { 293 if (AwAutofillClient::FromWebContents(web_contents_.get())) {
287 AwAutofillClient::FromWebContents(web_contents_.get()) 294 AwAutofillClient::FromWebContents(web_contents_.get())
288 ->SetSaveFormData(enabled); 295 ->SetSaveFormData(enabled);
289 } 296 }
290 } 297 }
291 298
292 void AwContents::InitAutofillIfNecessary(bool enabled) { 299 void AwContents::InitAutofillIfNecessary(bool autocomplete_enabled) {
293 // Do not initialize if the feature is not enabled.
294 if (!enabled)
295 return;
296 // Check if the autofill driver factory already exists. 300 // Check if the autofill driver factory already exists.
297 content::WebContents* web_contents = web_contents_.get(); 301 content::WebContents* web_contents = web_contents_.get();
298 if (ContentAutofillDriverFactory::FromWebContents(web_contents)) 302 if (ContentAutofillDriverFactory::FromWebContents(web_contents))
299 return; 303 return;
300 304
305 // Check if AutofillProvider is available.
306 DCHECK_CURRENTLY_ON(BrowserThread::UI);
307 JNIEnv* env = AttachCurrentThread();
308 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
309 if (obj.is_null())
310 return;
311
312 // Just return, if the app neither runs on O sdk nor enables autocomplete.
313 if (!autofill_provider_ && !autocomplete_enabled)
314 return;
315
301 AwAutofillClient::CreateForWebContents(web_contents); 316 AwAutofillClient::CreateForWebContents(web_contents);
302 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate( 317 ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(
303 web_contents, AwAutofillClient::FromWebContents(web_contents), 318 web_contents, AwAutofillClient::FromWebContents(web_contents),
304 base::android::GetDefaultLocaleString(), 319 base::android::GetDefaultLocaleString(),
305 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER); 320 AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER,
321 autofill_provider_.get());
306 } 322 }
307 323
308 void AwContents::SetAwAutofillClient(const JavaRef<jobject>& client) { 324 void AwContents::SetAwAutofillClient(const JavaRef<jobject>& client) {
309 DCHECK_CURRENTLY_ON(BrowserThread::UI); 325 DCHECK_CURRENTLY_ON(BrowserThread::UI);
310 JNIEnv* env = AttachCurrentThread(); 326 JNIEnv* env = AttachCurrentThread();
311 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 327 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
312 if (obj.is_null()) 328 if (obj.is_null())
313 return; 329 return;
314 Java_AwContents_setAwAutofillClient(env, obj, client); 330 Java_AwContents_setAwAutofillClient(env, obj, client);
315 } 331 }
(...skipping 1031 matching lines...) Expand 10 before | Expand all | Expand 10 after
1347 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( 1363 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme(
1348 web_contents_->GetRenderProcessHost()->GetID(), url::kFileScheme); 1364 web_contents_->GetRenderProcessHost()->GetID(), url::kFileScheme);
1349 } 1365 }
1350 1366
1351 void AwContents::ResumeLoadingCreatedPopupWebContents( 1367 void AwContents::ResumeLoadingCreatedPopupWebContents(
1352 JNIEnv* env, 1368 JNIEnv* env,
1353 const JavaParamRef<jobject>& obj) { 1369 const JavaParamRef<jobject>& obj) {
1354 web_contents_->ResumeLoadingCreatedWebContents(); 1370 web_contents_->ResumeLoadingCreatedWebContents();
1355 } 1371 }
1356 1372
1373 jlong AwContents::GetAutofillProvider(
1374 JNIEnv* env,
1375 const base::android::JavaParamRef<jobject>& obj) {
1376 return reinterpret_cast<jlong>(autofill_provider_.get());
1377 }
1378
1357 void SetShouldDownloadFavicons(JNIEnv* env, 1379 void SetShouldDownloadFavicons(JNIEnv* env,
1358 const JavaParamRef<jclass>& jclazz) { 1380 const JavaParamRef<jclass>& jclazz) {
1359 g_should_download_favicons = true; 1381 g_should_download_favicons = true;
1360 } 1382 }
1361 1383
1362 void AwContents::RenderViewHostChanged(content::RenderViewHost* old_host, 1384 void AwContents::RenderViewHostChanged(content::RenderViewHost* old_host,
1363 content::RenderViewHost* new_host) { 1385 content::RenderViewHost* new_host) {
1364 DCHECK(new_host); 1386 DCHECK(new_host);
1365 1387
1366 int process_id = new_host->GetProcess()->GetID(); 1388 int process_id = new_host->GetProcess()->GetID();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1446 1468
1447 return Java_AwContents_onRenderProcessGoneDetail(env, obj, child_process_id, 1469 return Java_AwContents_onRenderProcessGoneDetail(env, obj, child_process_id,
1448 crashed); 1470 crashed);
1449 } 1471 }
1450 1472
1451 void AwContents::RenderProcessReady(content::RenderProcessHost* host) { 1473 void AwContents::RenderProcessReady(content::RenderProcessHost* host) {
1452 UpdateRendererPriority(); 1474 UpdateRendererPriority();
1453 } 1475 }
1454 1476
1455 } // namespace android_webview 1477 } // namespace android_webview
OLDNEW
« 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