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

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: addressed comments Created 3 years, 5 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
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_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
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 gfx::Vector2dF content_offset =
821 web_contents_->GetNativeView()->content_offset();
822 gfx::Rect rect_in_view(rect_in_frame.x() + content_offset.x(),
823 rect_in_frame.y() + content_offset.y(),
824 rect_in_frame.width(), rect_in_frame.height());
825 gfx::Rect rect_in_view_scaled = gfx::ScaleToEnclosingRectSafe(
826 rect_in_view,
827 ui::GetScaleFactorForNativeView(web_contents_->GetNativeView()));
828
829 JNIEnv* env = base::android::AttachCurrentThread();
830 Java_Tab_showMediaDownloadInProductHelp(
831 env, weak_java_tab_.get(env), rect_in_view_scaled.x(),
832 rect_in_view_scaled.y(), rect_in_view_scaled.width(),
833 rect_in_view_scaled.height());
834 }
835
836 void TabAndroid::DismissMediaDownloadInProductHelp() {
837 JNIEnv* env = base::android::AttachCurrentThread();
838 Java_Tab_hideMediaDownloadInProductHelp(env, weak_java_tab_.get(env));
839 }
840
841 void TabAndroid::DownloadMediaInProductHelpDismissed(
842 JNIEnv* env,
843 const base::android::JavaParamRef<jobject>& obj) {
844 DCHECK(media_iph_manager_);
845 media_iph_manager_->WidgetDismissed();
846 }
847
804 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() { 848 scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() {
805 return devtools_host_; 849 return devtools_host_;
806 } 850 }
807 851
808 void TabAndroid::SetDevToolsAgentHost( 852 void TabAndroid::SetDevToolsAgentHost(
809 scoped_refptr<content::DevToolsAgentHost> host) { 853 scoped_refptr<content::DevToolsAgentHost> host) {
810 devtools_host_ = std::move(host); 854 devtools_host_ = std::move(host);
811 } 855 }
812 856
813 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) { 857 static void Init(JNIEnv* env, const JavaParamRef<jobject>& obj) {
814 TRACE_EVENT0("native", "TabAndroid::Init"); 858 TRACE_EVENT0("native", "TabAndroid::Init");
815 // This will automatically bind to the Java object and pass ownership there. 859 // This will automatically bind to the Java object and pass ownership there.
816 new TabAndroid(env, obj); 860 new TabAndroid(env, obj);
817 } 861 }
818 862
819 // static 863 // static
820 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) { 864 bool TabAndroid::RegisterTabAndroid(JNIEnv* env) {
821 return RegisterNativesImpl(env); 865 return RegisterNativesImpl(env);
822 } 866 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698