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<MediaInProductHelpManager>(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 20 matching lines...) Expand all Loading... |
413 content::Source<content::NavigationController>( | 422 content::Source<content::NavigationController>( |
414 &web_contents()->GetController())); | 423 &web_contents()->GetController())); |
415 | 424 |
416 favicon::FaviconDriver* favicon_driver = | 425 favicon::FaviconDriver* favicon_driver = |
417 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); | 426 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); |
418 | 427 |
419 if (favicon_driver) | 428 if (favicon_driver) |
420 favicon_driver->RemoveObserver(this); | 429 favicon_driver->RemoveObserver(this); |
421 | 430 |
422 web_contents()->SetDelegate(NULL); | 431 web_contents()->SetDelegate(NULL); |
| 432 media_iph_manager_.reset(); |
423 | 433 |
424 if (delete_native) { | 434 if (delete_native) { |
425 // Terminate the renderer process if this is the last tab. | 435 // Terminate the renderer process if this is the last tab. |
426 // If there's no unload listener, FastShutdownForPageCount kills the | 436 // If there's no unload listener, FastShutdownForPageCount kills the |
427 // renderer process. Otherwise, we go with the slow path where renderer | 437 // renderer process. Otherwise, we go with the slow path where renderer |
428 // process shuts down itself when ref count becomes 0. | 438 // process shuts down itself when ref count becomes 0. |
429 // This helps the render process exit quickly which avoids some issues | 439 // This helps the render process exit quickly which avoids some issues |
430 // during shutdown. See https://codereview.chromium.org/146693011/ | 440 // during shutdown. See https://codereview.chromium.org/146693011/ |
431 // and http://crbug.com/338709 for details. | 441 // and http://crbug.com/338709 for details. |
432 content::RenderProcessHost* process = | 442 content::RenderProcessHost* process = |
(...skipping 361 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 void TabAndroid::ShowMediaDownloadInProductHelp( |
| 815 const gfx::Rect& rect_in_frame) { |
| 816 DCHECK(web_contents_); |
| 817 |
| 818 // We need to account for the browser controls offset to get the location for |
| 819 // the widget in the view. |
| 820 float content_offset = web_contents_->GetNativeView()->content_offset(); |
| 821 gfx::Rect rect_in_view(rect_in_frame.x(), rect_in_frame.y() + content_offset, |
| 822 rect_in_frame.width(), rect_in_frame.height()); |
| 823 gfx::Rect rect_in_view_scaled = gfx::ScaleToEnclosingRectSafe( |
| 824 rect_in_view, |
| 825 ui::GetScaleFactorForNativeView(web_contents_->GetNativeView())); |
| 826 |
| 827 JNIEnv* env = base::android::AttachCurrentThread(); |
| 828 Java_Tab_showMediaDownloadInProductHelp( |
| 829 env, weak_java_tab_.get(env), rect_in_view_scaled.x(), |
| 830 rect_in_view_scaled.y(), rect_in_view_scaled.width(), |
| 831 rect_in_view_scaled.height()); |
| 832 } |
| 833 |
| 834 void TabAndroid::DismissMediaDownloadInProductHelp() { |
| 835 JNIEnv* env = base::android::AttachCurrentThread(); |
| 836 Java_Tab_hideMediaDownloadInProductHelp(env, weak_java_tab_.get(env)); |
| 837 } |
| 838 |
| 839 void TabAndroid::DownloadMediaInProductHelpDismissed( |
| 840 JNIEnv* env, |
| 841 const base::android::JavaParamRef<jobject>& obj) { |
| 842 DCHECK(media_iph_manager_); |
| 843 |
| 844 media_iph_manager_->WidgetDismissed(); |
| 845 } |
| 846 |
804 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { | 847 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { |
805 return devtools_host_; | 848 return devtools_host_; |
806 } | 849 } |
807 | 850 |
808 void TabAndroid::SetDevToolsAgentHost( | 851 void TabAndroid::SetDevToolsAgentHost( |
809 scoped_refptr<content::DevToolsAgentHost> host) { | 852 scoped_refptr<content::DevToolsAgentHost> host) { |
810 devtools_host_ = std::move(host); | 853 devtools_host_ = std::move(host); |
811 } | 854 } |
812 | 855 |
813 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { | 856 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
814 TRACE_EVENT0("native", "TabAndroid::Init"); | 857 TRACE_EVENT0("native", "TabAndroid::Init"); |
815 // This will automatically bind to the Java object and pass ownership there. | 858 // This will automatically bind to the Java object and pass ownership there. |
816 new TabAndroid(env, obj); | 859 new TabAndroid(env, obj); |
817 } | 860 } |
818 | 861 |
819 // static | 862 // static |
820 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { | 863 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { |
821 return RegisterNativesImpl(env); | 864 return RegisterNativesImpl(env); |
822 } | 865 } |
OLD | NEW |