| OLD | NEW |
| 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 "chrome/browser/android/tab_android.h" | 5 #include "chrome/browser/android/tab_android.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 #include "components/favicon/content/content_favicon_driver.h" | 58 #include "components/favicon/content/content_favicon_driver.h" |
| 59 #include "components/navigation_interception/intercept_navigation_delegate.h" | 59 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 60 #include "components/navigation_interception/navigation_params.h" | 60 #include "components/navigation_interception/navigation_params.h" |
| 61 #include "components/offline_pages/offline_page_feature.h" | 61 #include "components/offline_pages/offline_page_feature.h" |
| 62 #include "components/offline_pages/offline_page_item.h" | 62 #include "components/offline_pages/offline_page_item.h" |
| 63 #include "components/offline_pages/offline_page_model.h" | 63 #include "components/offline_pages/offline_page_model.h" |
| 64 #include "components/sessions/content/content_live_tab.h" | 64 #include "components/sessions/content/content_live_tab.h" |
| 65 #include "components/sessions/core/tab_restore_service.h" | 65 #include "components/sessions/core/tab_restore_service.h" |
| 66 #include "components/url_formatter/url_fixer.h" | 66 #include "components/url_formatter/url_fixer.h" |
| 67 #include "content/public/browser/android/compositor.h" | 67 #include "content/public/browser/android/compositor.h" |
| 68 #include "content/public/browser/android/content_view_core.h" | |
| 69 #include "content/public/browser/browser_thread.h" | 68 #include "content/public/browser/browser_thread.h" |
| 70 #include "content/public/browser/interstitial_page.h" | 69 #include "content/public/browser/interstitial_page.h" |
| 71 #include "content/public/browser/navigation_entry.h" | 70 #include "content/public/browser/navigation_entry.h" |
| 72 #include "content/public/browser/notification_service.h" | 71 #include "content/public/browser/notification_service.h" |
| 73 #include "content/public/browser/render_frame_host.h" | 72 #include "content/public/browser/render_frame_host.h" |
| 74 #include "content/public/browser/render_process_host.h" | 73 #include "content/public/browser/render_process_host.h" |
| 75 #include "content/public/browser/render_view_host.h" | 74 #include "content/public/browser/render_view_host.h" |
| 76 #include "content/public/browser/user_metrics.h" | 75 #include "content/public/browser/user_metrics.h" |
| 77 #include "content/public/browser/web_contents.h" | 76 #include "content/public/browser/web_contents.h" |
| 78 #include "content/public/common/resource_request_body.h" | 77 #include "content/public/common/resource_request_body.h" |
| 79 #include "content/public/common/top_controls_state.h" | 78 #include "content/public/common/top_controls_state.h" |
| 80 #include "jni/Tab_jni.h" | 79 #include "jni/Tab_jni.h" |
| 81 #include "net/base/escape.h" | 80 #include "net/base/escape.h" |
| 82 #include "skia/ext/image_operations.h" | 81 #include "skia/ext/image_operations.h" |
| 83 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 82 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 83 #include "ui/android/view_android.h" |
| 84 #include "ui/base/resource/resource_bundle.h" | 84 #include "ui/base/resource/resource_bundle.h" |
| 85 #include "ui/base/window_open_disposition.h" | 85 #include "ui/base/window_open_disposition.h" |
| 86 #include "ui/display/display.h" | 86 #include "ui/display/display.h" |
| 87 #include "ui/display/screen.h" | 87 #include "ui/display/screen.h" |
| 88 #include "ui/gfx/android/java_bitmap.h" | 88 #include "ui/gfx/android/java_bitmap.h" |
| 89 #include "ui/gfx/favicon_size.h" | 89 #include "ui/gfx/favicon_size.h" |
| 90 #include "ui/gfx/image/image_skia.h" | 90 #include "ui/gfx/image/image_skia.h" |
| 91 | 91 |
| 92 using base::android::AttachCurrentThread; | 92 using base::android::AttachCurrentThread; |
| 93 using base::android::ConvertUTF8ToJavaString; | 93 using base::android::ConvertUTF8ToJavaString; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 JNIEnv* env = base::android::AttachCurrentThread(); | 165 JNIEnv* env = base::android::AttachCurrentThread(); |
| 166 return GURL(base::android::ConvertJavaStringToUTF8( | 166 return GURL(base::android::ConvertJavaStringToUTF8( |
| 167 Java_Tab_getUrl(env, weak_java_tab_.get(env).obj()))); | 167 Java_Tab_getUrl(env, weak_java_tab_.get(env).obj()))); |
| 168 } | 168 } |
| 169 | 169 |
| 170 bool TabAndroid::LoadIfNeeded() { | 170 bool TabAndroid::LoadIfNeeded() { |
| 171 JNIEnv* env = base::android::AttachCurrentThread(); | 171 JNIEnv* env = base::android::AttachCurrentThread(); |
| 172 return Java_Tab_loadIfNeeded(env, weak_java_tab_.get(env).obj()); | 172 return Java_Tab_loadIfNeeded(env, weak_java_tab_.get(env).obj()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 content::ContentViewCore* TabAndroid::GetContentViewCore() const { | |
| 176 if (!web_contents()) | |
| 177 return NULL; | |
| 178 | |
| 179 return content::ContentViewCore::FromWebContents(web_contents()); | |
| 180 } | |
| 181 | |
| 182 Profile* TabAndroid::GetProfile() const { | 175 Profile* TabAndroid::GetProfile() const { |
| 183 if (!web_contents()) | 176 if (!web_contents()) |
| 184 return NULL; | 177 return NULL; |
| 185 | 178 |
| 186 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 179 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 187 } | 180 } |
| 188 | 181 |
| 189 browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { | 182 browser_sync::SyncedTabDelegate* TabAndroid::GetSyncedTabDelegate() const { |
| 190 return synced_tab_delegate_.get(); | 183 return synced_tab_delegate_.get(); |
| 191 } | 184 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 } | 359 } |
| 367 | 360 |
| 368 void TabAndroid::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 361 void TabAndroid::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 369 delete this; | 362 delete this; |
| 370 } | 363 } |
| 371 | 364 |
| 372 void TabAndroid::InitWebContents( | 365 void TabAndroid::InitWebContents( |
| 373 JNIEnv* env, | 366 JNIEnv* env, |
| 374 const JavaParamRef<jobject>& obj, | 367 const JavaParamRef<jobject>& obj, |
| 375 jboolean incognito, | 368 jboolean incognito, |
| 376 const JavaParamRef<jobject>& jcontent_view_core, | 369 const JavaParamRef<jobject>& jweb_contents, |
| 377 const JavaParamRef<jobject>& jweb_contents_delegate, | 370 const JavaParamRef<jobject>& jweb_contents_delegate, |
| 378 const JavaParamRef<jobject>& jcontext_menu_populator) { | 371 const JavaParamRef<jobject>& jcontext_menu_populator) { |
| 379 content::ContentViewCore* content_view_core = | 372 web_contents_.reset( |
| 380 content::ContentViewCore::GetNativeContentViewCore(env, | 373 content::WebContents::FromJavaWebContents(jweb_contents.obj())); |
| 381 jcontent_view_core); | 374 DCHECK(web_contents_.get()); |
| 382 DCHECK(content_view_core); | |
| 383 DCHECK(content_view_core->GetWebContents()); | |
| 384 | 375 |
| 385 web_contents_.reset(content_view_core->GetWebContents()); | |
| 386 AttachTabHelpers(web_contents_.get()); | 376 AttachTabHelpers(web_contents_.get()); |
| 387 | 377 |
| 388 SetWindowSessionID(session_window_id_.id()); | 378 SetWindowSessionID(session_window_id_.id()); |
| 389 | 379 |
| 390 session_tab_id_.set_id( | 380 session_tab_id_.set_id( |
| 391 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); | 381 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); |
| 392 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( | 382 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( |
| 393 jcontext_menu_populator); | 383 jcontext_menu_populator); |
| 394 ViewAndroidHelper::FromWebContents(web_contents())-> | 384 ViewAndroidHelper::FromWebContents(web_contents())-> |
| 395 SetViewAndroid(web_contents()->GetNativeView()); | 385 SetViewAndroid(web_contents()->GetNativeView()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 421 | 411 |
| 422 // Verify that the WebContents this tab represents matches the expected | 412 // Verify that the WebContents this tab represents matches the expected |
| 423 // off the record state. | 413 // off the record state. |
| 424 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); | 414 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); |
| 425 | 415 |
| 426 InstantService* instant_service = | 416 InstantService* instant_service = |
| 427 InstantServiceFactory::GetForProfile(GetProfile()); | 417 InstantServiceFactory::GetForProfile(GetProfile()); |
| 428 if (instant_service) | 418 if (instant_service) |
| 429 instant_service->AddObserver(this); | 419 instant_service->AddObserver(this); |
| 430 | 420 |
| 431 content_layer_->InsertChild(content_view_core->GetLayer(), 0); | 421 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); |
| 432 } | 422 } |
| 433 | 423 |
| 434 void TabAndroid::UpdateDelegates( | 424 void TabAndroid::UpdateDelegates( |
| 435 JNIEnv* env, | 425 JNIEnv* env, |
| 436 const JavaParamRef<jobject>& obj, | 426 const JavaParamRef<jobject>& obj, |
| 437 const JavaParamRef<jobject>& jweb_contents_delegate, | 427 const JavaParamRef<jobject>& jweb_contents_delegate, |
| 438 const JavaParamRef<jobject>& jcontext_menu_populator) { | 428 const JavaParamRef<jobject>& jcontext_menu_populator) { |
| 439 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( | 429 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( |
| 440 jcontext_menu_populator); | 430 jcontext_menu_populator); |
| 441 web_contents_delegate_.reset( | 431 web_contents_delegate_.reset( |
| 442 new chrome::android::TabWebContentsDelegateAndroid( | 432 new chrome::android::TabWebContentsDelegateAndroid( |
| 443 env, jweb_contents_delegate)); | 433 env, jweb_contents_delegate)); |
| 444 web_contents()->SetDelegate(web_contents_delegate_.get()); | 434 web_contents()->SetDelegate(web_contents_delegate_.get()); |
| 445 } | 435 } |
| 446 | 436 |
| 447 void TabAndroid::DestroyWebContents(JNIEnv* env, | 437 void TabAndroid::DestroyWebContents(JNIEnv* env, |
| 448 const JavaParamRef<jobject>& obj, | 438 const JavaParamRef<jobject>& obj, |
| 449 jboolean delete_native) { | 439 jboolean delete_native) { |
| 450 DCHECK(web_contents()); | 440 DCHECK(web_contents()); |
| 451 | 441 |
| 452 content::ContentViewCore* content_view_core = GetContentViewCore(); | 442 if (web_contents()->GetNativeView()) |
| 453 if (content_view_core) | 443 web_contents()->GetNativeView()->GetLayer()->RemoveFromParent(); |
| 454 content_view_core->GetLayer()->RemoveFromParent(); | |
| 455 | 444 |
| 456 notification_registrar_.Remove( | 445 notification_registrar_.Remove( |
| 457 this, | 446 this, |
| 458 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, | 447 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, |
| 459 content::Source<content::WebContents>(web_contents())); | 448 content::Source<content::WebContents>(web_contents())); |
| 460 notification_registrar_.Remove( | 449 notification_registrar_.Remove( |
| 461 this, | 450 this, |
| 462 content::NOTIFICATION_NAV_ENTRY_CHANGED, | 451 content::NOTIFICATION_NAV_ENTRY_CHANGED, |
| 463 content::Source<content::NavigationController>( | 452 content::Source<content::NavigationController>( |
| 464 &web_contents()->GetController())); | 453 &web_contents()->GetController())); |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 if (tab_content_manager == tab_content_manager_) | 856 if (tab_content_manager == tab_content_manager_) |
| 868 return; | 857 return; |
| 869 | 858 |
| 870 if (tab_content_manager_) | 859 if (tab_content_manager_) |
| 871 tab_content_manager_->DetachLiveLayer(GetAndroidId(), GetContentLayer()); | 860 tab_content_manager_->DetachLiveLayer(GetAndroidId(), GetContentLayer()); |
| 872 tab_content_manager_ = tab_content_manager; | 861 tab_content_manager_ = tab_content_manager; |
| 873 if (tab_content_manager_) | 862 if (tab_content_manager_) |
| 874 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); | 863 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); |
| 875 } | 864 } |
| 876 | 865 |
| 877 void TabAndroid::AttachOverlayContentViewCore( | 866 void TabAndroid::AttachOverlayWebContents( |
| 878 JNIEnv* env, | 867 JNIEnv* env, |
| 879 const JavaParamRef<jobject>& obj, | 868 const JavaParamRef<jobject>& obj, |
| 880 const JavaParamRef<jobject>& jcontent_view_core, | 869 const JavaParamRef<jobject>& jweb_contents, |
| 881 jboolean visible) { | 870 jboolean visible) { |
| 882 content::ContentViewCore* content_view_core = | 871 WebContents* web_contents = |
| 883 content::ContentViewCore::GetNativeContentViewCore(env, | 872 content::WebContents::FromJavaWebContents(jweb_contents.obj()); |
| 884 jcontent_view_core); | 873 DCHECK(web_contents); |
| 885 DCHECK(content_view_core); | 874 DCHECK(web_contents->GetNativeView()); |
| 886 | 875 |
| 887 content_view_core->GetLayer()->SetHideLayerAndSubtree(!visible); | 876 web_contents->GetNativeView()->GetLayer()->SetHideLayerAndSubtree(!visible); |
| 888 content_layer_->AddChild(content_view_core->GetLayer()); | 877 content_layer_->AddChild(web_contents->GetNativeView()->GetLayer()); |
| 889 } | 878 } |
| 890 | 879 |
| 891 void TabAndroid::DetachOverlayContentViewCore( | 880 void TabAndroid::DetachOverlayWebContents( |
| 892 JNIEnv* env, | 881 JNIEnv* env, |
| 893 const JavaParamRef<jobject>& obj, | 882 const JavaParamRef<jobject>& obj, |
| 894 const JavaParamRef<jobject>& jcontent_view_core) { | 883 const JavaParamRef<jobject>& jweb_contents) { |
| 895 content::ContentViewCore* content_view_core = | 884 WebContents* web_contents = |
| 896 content::ContentViewCore::GetNativeContentViewCore(env, | 885 content::WebContents::FromJavaWebContents(jweb_contents.obj()); |
| 897 jcontent_view_core); | 886 DCHECK(web_contents); |
| 898 DCHECK(content_view_core); | 887 DCHECK(web_contents->GetNativeView()); |
| 899 | 888 |
| 900 if (content_view_core->GetLayer()->parent() == content_layer_) | 889 if (web_contents->GetNativeView()->GetLayer()->parent() == content_layer_) |
| 901 content_view_core->GetLayer()->RemoveFromParent(); | 890 web_contents->GetNativeView()->GetLayer()->RemoveFromParent(); |
| 902 } | 891 } |
| 903 | 892 |
| 904 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 893 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 905 TRACE_EVENT0("native", "TabAndroid::Init"); | 894 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 906 // This will automatically bind to the Java object and pass ownership there. | 895 // This will automatically bind to the Java object and pass ownership there. |
| 907 new TabAndroid(env, obj); | 896 new TabAndroid(env, obj); |
| 908 } | 897 } |
| 909 | 898 |
| 910 // static | 899 // static |
| 911 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 900 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 912 return RegisterNativesImpl(env); | 901 return RegisterNativesImpl(env); |
| 913 } | 902 } |
| OLD | NEW |