| 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 #include "chrome/browser/ui/tab_helpers.h" | 47 #include "chrome/browser/ui/tab_helpers.h" |
| 48 #include "chrome/common/image_context_menu_renderer.mojom.h" | 48 #include "chrome/common/image_context_menu_renderer.mojom.h" |
| 49 #include "chrome/common/render_messages.h" | 49 #include "chrome/common/render_messages.h" |
| 50 #include "chrome/common/url_constants.h" | 50 #include "chrome/common/url_constants.h" |
| 51 #include "components/bookmarks/browser/bookmark_model.h" | 51 #include "components/bookmarks/browser/bookmark_model.h" |
| 52 #include "components/bookmarks/browser/bookmark_node.h" | 52 #include "components/bookmarks/browser/bookmark_node.h" |
| 53 #include "components/bookmarks/browser/bookmark_utils.h" | 53 #include "components/bookmarks/browser/bookmark_utils.h" |
| 54 #include "components/bookmarks/managed/managed_bookmark_service.h" | 54 #include "components/bookmarks/managed/managed_bookmark_service.h" |
| 55 #include "components/dom_distiller/core/url_utils.h" | 55 #include "components/dom_distiller/core/url_utils.h" |
| 56 #include "components/favicon/content/content_favicon_driver.h" | 56 #include "components/favicon/content/content_favicon_driver.h" |
| 57 #include "components/feature_engagement_tracker/public/feature_constants.h" |
| 58 #include "components/feature_engagement_tracker/public/feature_list.h" |
| 57 #include "components/navigation_interception/intercept_navigation_delegate.h" | 59 #include "components/navigation_interception/intercept_navigation_delegate.h" |
| 58 #include "components/navigation_interception/navigation_params.h" | 60 #include "components/navigation_interception/navigation_params.h" |
| 59 #include "components/sessions/content/content_live_tab.h" | 61 #include "components/sessions/content/content_live_tab.h" |
| 60 #include "components/sessions/core/tab_restore_service.h" | 62 #include "components/sessions/core/tab_restore_service.h" |
| 61 #include "components/url_formatter/url_fixer.h" | 63 #include "components/url_formatter/url_fixer.h" |
| 62 #include "content/public/browser/android/compositor.h" | 64 #include "content/public/browser/android/compositor.h" |
| 63 #include "content/public/browser/browser_thread.h" | 65 #include "content/public/browser/browser_thread.h" |
| 64 #include "content/public/browser/devtools_agent_host.h" | 66 #include "content/public/browser/devtools_agent_host.h" |
| 65 #include "content/public/browser/interstitial_page.h" | 67 #include "content/public/browser/interstitial_page.h" |
| 66 #include "content/public/browser/navigation_entry.h" | 68 #include "content/public/browser/navigation_entry.h" |
| 67 #include "content/public/browser/notification_service.h" | 69 #include "content/public/browser/notification_service.h" |
| 68 #include "content/public/browser/render_frame_host.h" | 70 #include "content/public/browser/render_frame_host.h" |
| 69 #include "content/public/browser/render_process_host.h" | 71 #include "content/public/browser/render_process_host.h" |
| 70 #include "content/public/browser/render_view_host.h" | 72 #include "content/public/browser/render_view_host.h" |
| 71 #include "content/public/browser/web_contents.h" | 73 #include "content/public/browser/web_contents.h" |
| 72 #include "content/public/common/browser_controls_state.h" | 74 #include "content/public/common/browser_controls_state.h" |
| 73 #include "content/public/common/resource_request_body.h" | 75 #include "content/public/common/resource_request_body.h" |
| 74 #include "jni/Tab_jni.h" | 76 #include "jni/Tab_jni.h" |
| 75 #include "net/base/escape.h" | 77 #include "net/base/escape.h" |
| 76 #include "services/service_manager/public/cpp/interface_provider.h" | 78 #include "services/service_manager/public/cpp/interface_provider.h" |
| 77 #include "skia/ext/image_operations.h" | 79 #include "skia/ext/image_operations.h" |
| 78 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" | 80 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" |
| 79 #include "ui/android/view_android.h" | 81 #include "ui/android/view_android.h" |
| 80 #include "ui/android/window_android.h" | 82 #include "ui/android/window_android.h" |
| 83 #include "ui/base/layout.h" |
| 81 #include "ui/base/resource/resource_bundle.h" | 84 #include "ui/base/resource/resource_bundle.h" |
| 82 #include "ui/base/window_open_disposition.h" | 85 #include "ui/base/window_open_disposition.h" |
| 83 #include "ui/display/display.h" | 86 #include "ui/display/display.h" |
| 84 #include "ui/display/screen.h" | 87 #include "ui/display/screen.h" |
| 85 #include "ui/gfx/android/java_bitmap.h" | 88 #include "ui/gfx/android/java_bitmap.h" |
| 86 #include "ui/gfx/favicon_size.h" | 89 #include "ui/gfx/favicon_size.h" |
| 87 #include "ui/gfx/image/image_skia.h" | 90 #include "ui/gfx/image/image_skia.h" |
| 88 | 91 |
| 89 using base::android::AttachCurrentThread; | 92 using base::android::AttachCurrentThread; |
| 90 using base::android::ConvertUTF8ToJavaString; | 93 using base::android::ConvertUTF8ToJavaString; |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 376 |
| 374 // Verify that the WebContents this tab represents matches the expected | 377 // Verify that the WebContents this tab represents matches the expected |
| 375 // off the record state. | 378 // off the record state. |
| 376 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); | 379 CHECK_EQ(GetProfile()->IsOffTheRecord(), incognito); |
| 377 | 380 |
| 378 if (is_background_tab) { | 381 if (is_background_tab) { |
| 379 BackgroundTabManager::GetInstance()->RegisterBackgroundTab(web_contents(), | 382 BackgroundTabManager::GetInstance()->RegisterBackgroundTab(web_contents(), |
| 380 GetProfile()); | 383 GetProfile()); |
| 381 } | 384 } |
| 382 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); | 385 content_layer_->InsertChild(web_contents_->GetNativeView()->GetLayer(), 0); |
| 386 |
| 387 if (base::FeatureList::IsEnabled( |
| 388 feature_engagement_tracker::kIPHMediaDownloadFeature)) { |
| 389 media_iph_manager_ = |
| 390 base::MakeUnique<MediaIPHManager>(web_contents_.get(), this); |
| 391 } |
| 383 } | 392 } |
| 384 | 393 |
| 385 void TabAndroid::UpdateDelegates( | 394 void TabAndroid::UpdateDelegates( |
| 386 JNIEnv* env, | 395 JNIEnv* env, |
| 387 const JavaParamRef<jobject>& obj, | 396 const JavaParamRef<jobject>& obj, |
| 388 const JavaParamRef<jobject>& jweb_contents_delegate, | 397 const JavaParamRef<jobject>& jweb_contents_delegate, |
| 389 const JavaParamRef<jobject>& jcontext_menu_populator) { | 398 const JavaParamRef<jobject>& jcontext_menu_populator) { |
| 390 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( | 399 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( |
| 391 jcontext_menu_populator); | 400 jcontext_menu_populator); |
| 392 web_contents_delegate_ = | 401 web_contents_delegate_ = |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // renderer process. Otherwise, we go with the slow path where renderer | 436 // renderer process. Otherwise, we go with the slow path where renderer |
| 428 // process shuts down itself when ref count becomes 0. | 437 // process shuts down itself when ref count becomes 0. |
| 429 // This helps the render process exit quickly which avoids some issues | 438 // This helps the render process exit quickly which avoids some issues |
| 430 // during shutdown. See https://codereview.chromium.org/146693011/ | 439 // during shutdown. See https://codereview.chromium.org/146693011/ |
| 431 // and http://crbug.com/338709 for details. | 440 // and http://crbug.com/338709 for details. |
| 432 content::RenderProcessHost* process = | 441 content::RenderProcessHost* process = |
| 433 web_contents()->GetRenderProcessHost(); | 442 web_contents()->GetRenderProcessHost(); |
| 434 if (process) | 443 if (process) |
| 435 process->FastShutdownForPageCount(1); | 444 process->FastShutdownForPageCount(1); |
| 436 | 445 |
| 446 media_iph_manager_.reset(); |
| 437 web_contents_.reset(); | 447 web_contents_.reset(); |
| 438 synced_tab_delegate_->ResetWebContents(); | 448 synced_tab_delegate_->ResetWebContents(); |
| 439 } else { | 449 } else { |
| 440 // Release the WebContents so it does not get deleted by the scoped_ptr. | 450 // Release the WebContents so it does not get deleted by the scoped_ptr. |
| 441 ignore_result(web_contents_.release()); | 451 ignore_result(web_contents_.release()); |
| 442 } | 452 } |
| 443 } | 453 } |
| 444 | 454 |
| 445 void TabAndroid::OnPhysicalBackingSizeChanged( | 455 void TabAndroid::OnPhysicalBackingSizeChanged( |
| 446 JNIEnv* env, | 456 JNIEnv* env, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 if (tab_content_manager == tab_content_manager_) | 804 if (tab_content_manager == tab_content_manager_) |
| 795 return; | 805 return; |
| 796 | 806 |
| 797 if (tab_content_manager_) | 807 if (tab_content_manager_) |
| 798 tab_content_manager_->DetachLiveLayer(GetAndroidId(), GetContentLayer()); | 808 tab_content_manager_->DetachLiveLayer(GetAndroidId(), GetContentLayer()); |
| 799 tab_content_manager_ = tab_content_manager; | 809 tab_content_manager_ = tab_content_manager; |
| 800 if (tab_content_manager_) | 810 if (tab_content_manager_) |
| 801 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); | 811 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); |
| 802 } | 812 } |
| 803 | 813 |
| 814 bool TabAndroid::ShowMediaDownloadIPH() { |
| 815 JNIEnv* env = base::android::AttachCurrentThread(); |
| 816 return Java_Tab_showMediaDownloadIPH(env, weak_java_tab_.get(env)); |
| 817 } |
| 818 |
| 819 void TabAndroid::UpdateMediaDownloadIPHPosition( |
| 820 const gfx::Rect& rect_in_frame) { |
| 821 DCHECK(web_contents_); |
| 822 |
| 823 // We need to account for the browser controls offset to get the location for |
| 824 // the widget in the view. |
| 825 gfx::Vector2dF content_offset = |
| 826 web_contents_->GetNativeView()->content_offset(); |
| 827 gfx::Rect rect_in_view(rect_in_frame.x() + content_offset.x(), |
| 828 rect_in_frame.y() + content_offset.y(), |
| 829 rect_in_frame.width(), rect_in_frame.height()); |
| 830 gfx::Rect rect_in_view_scaled = gfx::ScaleToEnclosingRectSafe( |
| 831 rect_in_view, |
| 832 ui::GetScaleFactorForNativeView(web_contents_->GetNativeView())); |
| 833 |
| 834 JNIEnv* env = base::android::AttachCurrentThread(); |
| 835 Java_Tab_updateMediaDownloadIPH( |
| 836 env, weak_java_tab_.get(env), rect_in_view_scaled.x(), |
| 837 rect_in_view_scaled.y(), rect_in_view_scaled.width(), |
| 838 rect_in_view_scaled.height()); |
| 839 } |
| 840 |
| 841 void TabAndroid::DismissMediaDownloadIPH() { |
| 842 JNIEnv* env = base::android::AttachCurrentThread(); |
| 843 Java_Tab_hideMediaDownloadIPH(env, weak_java_tab_.get(env)); |
| 844 } |
| 845 |
| 846 void TabAndroid::DownloadMediaIPHDismissed( |
| 847 JNIEnv* env, |
| 848 const base::android::JavaParamRef<jobject>& obj) { |
| 849 DCHECK(media_iph_manager_); |
| 850 media_iph_manager_->WidgetDismissed(); |
| 851 } |
| 852 |
| 804 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { | 853 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { |
| 805 return devtools_host_; | 854 return devtools_host_; |
| 806 } | 855 } |
| 807 | 856 |
| 808 void TabAndroid::SetDevToolsAgentHost( | 857 void TabAndroid::SetDevToolsAgentHost( |
| 809 scoped_refptr<content::DevToolsAgentHost> host) { | 858 scoped_refptr<content::DevToolsAgentHost> host) { |
| 810 devtools_host_ = std::move(host); | 859 devtools_host_ = std::move(host); |
| 811 } | 860 } |
| 812 | 861 |
| 813 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 862 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 814 TRACE_EVENT0("native", "TabAndroid::Init"); | 863 TRACE_EVENT0("native", "TabAndroid::Init"); |
| 815 // This will automatically bind to the Java object and pass ownership there. | 864 // This will automatically bind to the Java object and pass ownership there. |
| 816 new TabAndroid(env, obj); | 865 new TabAndroid(env, obj); |
| 817 } | 866 } |
| 818 | 867 |
| 819 // static | 868 // static |
| 820 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 869 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
| 821 return RegisterNativesImpl(env); | 870 return RegisterNativesImpl(env); |
| 822 } | 871 } |
| OLD | NEW |