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

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

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