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

Side by Side Diff: chrome/browser/android/tab_android.cc

Issue 2943983003: chrome/blink: Add functionality for in-product help for media elements. (Closed)
Patch Set: .. Created 3 years, 4 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 | « chrome/browser/android/tab_android.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('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 "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
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/public/feature_constants.h"
58 #include "components/feature_engagement/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"
77 #include "mojo/public/cpp/bindings/strong_binding.h"
75 #include "net/base/escape.h" 78 #include "net/base/escape.h"
79 #include "services/service_manager/public/cpp/bind_source_info.h"
76 #include "services/service_manager/public/cpp/interface_provider.h" 80 #include "services/service_manager/public/cpp/interface_provider.h"
77 #include "skia/ext/image_operations.h" 81 #include "skia/ext/image_operations.h"
78 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h" 82 #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
79 #include "ui/android/view_android.h" 83 #include "ui/android/view_android.h"
80 #include "ui/android/window_android.h" 84 #include "ui/android/window_android.h"
85 #include "ui/base/layout.h"
81 #include "ui/base/resource/resource_bundle.h" 86 #include "ui/base/resource/resource_bundle.h"
82 #include "ui/base/window_open_disposition.h" 87 #include "ui/base/window_open_disposition.h"
83 #include "ui/display/display.h" 88 #include "ui/display/display.h"
84 #include "ui/display/screen.h" 89 #include "ui/display/screen.h"
85 #include "ui/gfx/android/java_bitmap.h" 90 #include "ui/gfx/android/java_bitmap.h"
86 #include "ui/gfx/favicon_size.h" 91 #include "ui/gfx/favicon_size.h"
87 #include "ui/gfx/image/image_skia.h" 92 #include "ui/gfx/image/image_skia.h"
88 93
89 using base::android::AttachCurrentThread; 94 using base::android::AttachCurrentThread;
90 using base::android::ConvertUTF8ToJavaString; 95 using base::android::ConvertUTF8ToJavaString;
91 using base::android::JavaParamRef; 96 using base::android::JavaParamRef;
92 using base::android::JavaRef; 97 using base::android::JavaRef;
93 using chrome::android::BackgroundTabManager; 98 using chrome::android::BackgroundTabManager;
94 using content::BrowserThread; 99 using content::BrowserThread;
95 using content::GlobalRequestID; 100 using content::GlobalRequestID;
96 using content::NavigationController; 101 using content::NavigationController;
97 using content::WebContents; 102 using content::WebContents;
98 using navigation_interception::InterceptNavigationDelegate; 103 using navigation_interception::InterceptNavigationDelegate;
99 using navigation_interception::NavigationParams; 104 using navigation_interception::NavigationParams;
100 105
106 // This class is created and owned by the MediaDownloadInProductHelpManager.
107 class TabAndroid::MediaDownloadInProductHelp
108 : public blink::mojom::MediaDownloadInProductHelp {
109 public:
110 MediaDownloadInProductHelp(
111 content::RenderFrameHost* render_frame_host,
112 TabAndroid* tab,
113 blink::mojom::MediaDownloadInProductHelpRequest request)
114 : render_frame_host_(render_frame_host),
115 tab_(tab),
116 binding_(this, std::move(request)) {
117 DCHECK(render_frame_host_);
118 DCHECK(tab_);
119
120 binding_.set_connection_error_handler(
121 base::BindOnce(&TabAndroid::OnMediaDownloadInProductHelpConnectionError,
122 base::Unretained(tab_)));
123 }
124 ~MediaDownloadInProductHelp() override = default;
125
126 // blink::mojom::MediaPromoUI implementation.
127 void ShowInProductHelpWidget(const gfx::Rect& rect) override {
128 tab_->ShowMediaDownloadInProductHelp(rect);
129 }
130
131 content::RenderFrameHost* render_frame_host() const {
132 return render_frame_host_;
133 }
134
135 private:
136 // The |manager_| and |render_frame_host_| outlive this class.
137 content::RenderFrameHost* const render_frame_host_;
138 TabAndroid* tab_;
139 mojo::Binding<blink::mojom::MediaDownloadInProductHelp> binding_;
140 };
141
101 TabAndroid* TabAndroid::FromWebContents( 142 TabAndroid* TabAndroid::FromWebContents(
102 const content::WebContents* web_contents) { 143 const content::WebContents* web_contents) {
103 const CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents( 144 const CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(
104 web_contents); 145 web_contents);
105 if (!core_tab_helper) 146 if (!core_tab_helper)
106 return NULL; 147 return NULL;
107 148
108 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate(); 149 CoreTabHelperDelegate* core_delegate = core_tab_helper->delegate();
109 if (!core_delegate) 150 if (!core_delegate)
110 return NULL; 151 return NULL;
111 152
112 return static_cast<TabAndroid*>(core_delegate); 153 return static_cast<TabAndroid*>(core_delegate);
113 } 154 }
114 155
115 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, const JavaRef<jobject>& obj) { 156 TabAndroid* TabAndroid::GetNativeTab(JNIEnv* env, const JavaRef<jobject>& obj) {
116 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj)); 157 return reinterpret_cast<TabAndroid*>(Java_Tab_getNativePtr(env, obj));
117 } 158 }
118 159
119 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) { 160 void TabAndroid::AttachTabHelpers(content::WebContents* web_contents) {
120 DCHECK(web_contents); 161 DCHECK(web_contents);
121 162
122 TabHelpers::AttachTabHelpers(web_contents); 163 TabHelpers::AttachTabHelpers(web_contents);
123 } 164 }
124 165
125 TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj) 166 TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj)
126 : weak_java_tab_(env, obj), 167 : weak_java_tab_(env, obj),
127 content_layer_(cc::Layer::Create()), 168 content_layer_(cc::Layer::Create()),
128 tab_content_manager_(NULL), 169 tab_content_manager_(NULL),
129 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)), 170 synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)),
130 embedded_media_experience_enabled_(false) { 171 embedded_media_experience_enabled_(false),
172 weak_factory_(this) {
131 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this)); 173 Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
174
175 frame_interfaces_.AddInterface(base::Bind(
176 &TabAndroid::CreateInProductHelpService, weak_factory_.GetWeakPtr()));
132 } 177 }
133 178
134 TabAndroid::~TabAndroid() { 179 TabAndroid::~TabAndroid() {
135 GetContentLayer()->RemoveAllChildren(); 180 GetContentLayer()->RemoveAllChildren();
136 JNIEnv* env = base::android::AttachCurrentThread(); 181 JNIEnv* env = base::android::AttachCurrentThread();
137 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env)); 182 Java_Tab_clearNativePtr(env, weak_java_tab_.get(env));
138 } 183 }
139 184
140 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() { 185 base::android::ScopedJavaLocalRef<jobject> TabAndroid::GetJavaObject() {
141 JNIEnv* env = base::android::AttachCurrentThread(); 186 JNIEnv* env = base::android::AttachCurrentThread();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 const JavaParamRef<jobject>& obj, 380 const JavaParamRef<jobject>& obj,
336 jboolean incognito, 381 jboolean incognito,
337 jboolean is_background_tab, 382 jboolean is_background_tab,
338 const JavaParamRef<jobject>& jweb_contents, 383 const JavaParamRef<jobject>& jweb_contents,
339 const JavaParamRef<jobject>& jweb_contents_delegate, 384 const JavaParamRef<jobject>& jweb_contents_delegate,
340 const JavaParamRef<jobject>& jcontext_menu_populator) { 385 const JavaParamRef<jobject>& jcontext_menu_populator) {
341 web_contents_.reset(content::WebContents::FromJavaWebContents(jweb_contents)); 386 web_contents_.reset(content::WebContents::FromJavaWebContents(jweb_contents));
342 DCHECK(web_contents_.get()); 387 DCHECK(web_contents_.get());
343 388
344 AttachTabHelpers(web_contents_.get()); 389 AttachTabHelpers(web_contents_.get());
390 WebContentsObserver::Observe(web_contents_.get());
345 391
346 SetWindowSessionID(session_window_id_.id()); 392 SetWindowSessionID(session_window_id_.id());
347 393
348 session_tab_id_.set_id( 394 session_tab_id_.set_id(
349 SessionTabHelper::FromWebContents(web_contents())->session_id().id()); 395 SessionTabHelper::FromWebContents(web_contents())->session_id().id());
350 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator( 396 ContextMenuHelper::FromWebContents(web_contents())->SetPopulator(
351 jcontext_menu_populator); 397 jcontext_menu_populator);
352 ViewAndroidHelper::FromWebContents(web_contents())-> 398 ViewAndroidHelper::FromWebContents(web_contents())->
353 SetViewAndroid(web_contents()->GetNativeView()); 399 SetViewAndroid(web_contents()->GetNativeView());
354 CoreTabHelper::FromWebContents(web_contents())->set_delegate(this); 400 CoreTabHelper::FromWebContents(web_contents())->set_delegate(this);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 456
411 notification_registrar_.Remove( 457 notification_registrar_.Remove(
412 this, 458 this,
413 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 459 chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
414 content::Source<content::WebContents>(web_contents())); 460 content::Source<content::WebContents>(web_contents()));
415 notification_registrar_.Remove( 461 notification_registrar_.Remove(
416 this, 462 this,
417 content::NOTIFICATION_NAV_ENTRY_CHANGED, 463 content::NOTIFICATION_NAV_ENTRY_CHANGED,
418 content::Source<content::NavigationController>( 464 content::Source<content::NavigationController>(
419 &web_contents()->GetController())); 465 &web_contents()->GetController()));
466 WebContentsObserver::Observe(nullptr);
420 467
421 favicon::FaviconDriver* favicon_driver = 468 favicon::FaviconDriver* favicon_driver =
422 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get()); 469 favicon::ContentFaviconDriver::FromWebContents(web_contents_.get());
423 470
424 if (favicon_driver) 471 if (favicon_driver)
425 favicon_driver->RemoveObserver(this); 472 favicon_driver->RemoveObserver(this);
426 473
427 web_contents()->SetDelegate(NULL); 474 web_contents()->SetDelegate(NULL);
428 475
429 if (delete_native) { 476 if (delete_native) {
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 if (tab_content_manager_) 874 if (tab_content_manager_)
828 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer()); 875 tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer());
829 } 876 }
830 877
831 void TabAndroid::ClearThumbnailPlaceholder(JNIEnv* env, 878 void TabAndroid::ClearThumbnailPlaceholder(JNIEnv* env,
832 const JavaParamRef<jobject>& obj) { 879 const JavaParamRef<jobject>& obj) {
833 if (tab_content_manager_) 880 if (tab_content_manager_)
834 tab_content_manager_->NativeRemoveTabThumbnail(GetAndroidId()); 881 tab_content_manager_->NativeRemoveTabThumbnail(GetAndroidId());
835 } 882 }
836 883
884 void TabAndroid::OnInterfaceRequestFromFrame(
885 content::RenderFrameHost* render_frame_host,
886 const std::string& interface_name,
887 mojo::ScopedMessagePipeHandle* interface_pipe) {
888 frame_interfaces_.TryBindInterface(interface_name, interface_pipe,
889 render_frame_host);
890 }
891
892 void TabAndroid::RenderFrameDeleted(
893 content::RenderFrameHost* render_frame_host) {
894 if (media_in_product_help_ &&
895 media_in_product_help_->render_frame_host() == render_frame_host) {
896 DismissMediaDownloadInProductHelp();
897 }
898 }
899
900 void TabAndroid::ShowMediaDownloadInProductHelp(
901 const gfx::Rect& rect_in_frame) {
902 DCHECK(web_contents_);
903
904 // We need to account for the browser controls offset to get the location for
905 // the widget in the view.
906 float content_offset = web_contents_->GetNativeView()->content_offset();
907 gfx::Rect rect_in_view(rect_in_frame.x(), rect_in_frame.y() + content_offset,
908 rect_in_frame.width(), rect_in_frame.height());
909 gfx::Rect rect_in_view_scaled = gfx::ScaleToEnclosingRectSafe(
910 rect_in_view,
911 ui::GetScaleFactorForNativeView(web_contents_->GetNativeView()));
912
913 JNIEnv* env = base::android::AttachCurrentThread();
914 Java_Tab_showMediaDownloadInProductHelp(
915 env, weak_java_tab_.get(env), rect_in_view_scaled.x(),
916 rect_in_view_scaled.y(), rect_in_view_scaled.width(),
917 rect_in_view_scaled.height());
918 }
919
920 void TabAndroid::DismissMediaDownloadInProductHelp() {
921 JNIEnv* env = base::android::AttachCurrentThread();
922 Java_Tab_hideMediaDownloadInProductHelp(env, weak_java_tab_.get(env));
923 }
924
925 void TabAndroid::MediaDownloadInProductHelpDismissed(
926 JNIEnv* env,
927 const base::android::JavaParamRef<jobject>& obj) {
928 DCHECK(media_in_product_help_);
929 media_in_product_help_.reset();
930 }
931
932 void TabAndroid::CreateInProductHelpService(
933 blink::mojom::MediaDownloadInProductHelpRequest request,
934 content::RenderFrameHost* render_frame_host) {
935 // If we are showing the UI already, ignore the request.
936 if (media_in_product_help_)
937 return;
938
939 media_in_product_help_ = base::MakeUnique<MediaDownloadInProductHelp>(
940 render_frame_host, this, std::move(request));
941 }
942
943 void TabAndroid::OnMediaDownloadInProductHelpConnectionError() {
944 DCHECK(media_in_product_help_);
945 DismissMediaDownloadInProductHelp();
946 }
947
837 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { 948 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() {
838 return devtools_host_; 949 return devtools_host_;
839 } 950 }
840 951
841 void TabAndroid::SetDevToolsAgentHost( 952 void TabAndroid::SetDevToolsAgentHost(
842 scoped_refptr<content::DevToolsAgentHost> host) { 953 scoped_refptr<content::DevToolsAgentHost> host) {
843 devtools_host_ = std::move(host); 954 devtools_host_ = std::move(host);
844 } 955 }
845 956
846 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 957 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
847 TRACE_EVENT0("native", "TabAndroid::Init"); 958 TRACE_EVENT0("native", "TabAndroid::Init");
848 // This will automatically bind to the Java object and pass ownership there. 959 // This will automatically bind to the Java object and pass ownership there.
849 new TabAndroid(env, obj); 960 new TabAndroid(env, obj);
850 } 961 }
OLDNEW
« no previous file with comments | « chrome/browser/android/tab_android.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698