| Index: chrome/browser/android/tab_android.cc
|
| diff --git a/chrome/browser/android/tab_android.cc b/chrome/browser/android/tab_android.cc
|
| index 005669d1972a18eecc865d99ba76532548b442e1..172fd7274444f7c948952dd8b8853e0687116392 100644
|
| --- a/chrome/browser/android/tab_android.cc
|
| +++ b/chrome/browser/android/tab_android.cc
|
| @@ -54,6 +54,8 @@
|
| #include "components/bookmarks/managed/managed_bookmark_service.h"
|
| #include "components/dom_distiller/core/url_utils.h"
|
| #include "components/favicon/content/content_favicon_driver.h"
|
| +#include "components/feature_engagement_tracker/public/feature_constants.h"
|
| +#include "components/feature_engagement_tracker/public/feature_list.h"
|
| #include "components/navigation_interception/intercept_navigation_delegate.h"
|
| #include "components/navigation_interception/navigation_params.h"
|
| #include "components/sessions/content/content_live_tab.h"
|
| @@ -72,12 +74,15 @@
|
| #include "content/public/common/browser_controls_state.h"
|
| #include "content/public/common/resource_request_body.h"
|
| #include "jni/Tab_jni.h"
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| #include "net/base/escape.h"
|
| +#include "services/service_manager/public/cpp/bind_source_info.h"
|
| #include "services/service_manager/public/cpp/interface_provider.h"
|
| #include "skia/ext/image_operations.h"
|
| #include "third_party/WebKit/public/platform/WebReferrerPolicy.h"
|
| #include "ui/android/view_android.h"
|
| #include "ui/android/window_android.h"
|
| +#include "ui/base/layout.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/base/window_open_disposition.h"
|
| #include "ui/display/display.h"
|
| @@ -98,6 +103,40 @@ using content::WebContents;
|
| using navigation_interception::InterceptNavigationDelegate;
|
| using navigation_interception::NavigationParams;
|
|
|
| +// This class is created and owned by the MediaInProductHelpManager.
|
| +class TabAndroid::MediaInProductHelp : public blink::mojom::MediaInProductHelp {
|
| + public:
|
| + MediaInProductHelp(content::RenderFrameHost* render_frame_host,
|
| + TabAndroid* tab,
|
| + blink::mojom::MediaInProductHelpRequest request)
|
| + : render_frame_host_(render_frame_host),
|
| + tab_(tab),
|
| + binding_(this, std::move(request)) {
|
| + DCHECK(render_frame_host_);
|
| + DCHECK(tab_);
|
| +
|
| + binding_.set_connection_error_handler(
|
| + base::BindOnce(&TabAndroid::OnMediaInProductHelpConnectionError,
|
| + base::Unretained(tab_)));
|
| + }
|
| + ~MediaInProductHelp() override = default;
|
| +
|
| + // blink::mojom::MediaPromoUI implementation.
|
| + void ShowInProductHelpWidget(const gfx::Rect& rect) override {
|
| + tab_->ShowMediaDownloadInProductHelp(rect);
|
| + }
|
| +
|
| + content::RenderFrameHost* render_frame_host() const {
|
| + return render_frame_host_;
|
| + }
|
| +
|
| + private:
|
| + // The |manager_| and |render_frame_host_| outlive this class.
|
| + content::RenderFrameHost* render_frame_host_;
|
| + TabAndroid* tab_;
|
| + mojo::Binding<blink::mojom::MediaInProductHelp> binding_;
|
| +};
|
| +
|
| TabAndroid* TabAndroid::FromWebContents(
|
| const content::WebContents* web_contents) {
|
| const CoreTabHelper* core_tab_helper = CoreTabHelper::FromWebContents(
|
| @@ -127,7 +166,8 @@ TabAndroid::TabAndroid(JNIEnv* env, const JavaRef<jobject>& obj)
|
| content_layer_(cc::Layer::Create()),
|
| tab_content_manager_(NULL),
|
| synced_tab_delegate_(new browser_sync::SyncedTabDelegateAndroid(this)),
|
| - embedded_media_experience_enabled_(false) {
|
| + embedded_media_experience_enabled_(false),
|
| + weak_factory_(this) {
|
| Java_Tab_setNativePtr(env, obj, reinterpret_cast<intptr_t>(this));
|
| }
|
|
|
| @@ -337,6 +377,7 @@ void TabAndroid::InitWebContents(
|
| DCHECK(web_contents_.get());
|
|
|
| AttachTabHelpers(web_contents_.get());
|
| + WebContentsObserver::Observe(web_contents_.get());
|
|
|
| SetWindowSessionID(session_window_id_.id());
|
|
|
| @@ -412,6 +453,7 @@ void TabAndroid::DestroyWebContents(JNIEnv* env,
|
| content::NOTIFICATION_NAV_ENTRY_CHANGED,
|
| content::Source<content::NavigationController>(
|
| &web_contents()->GetController()));
|
| + WebContentsObserver::Observe(nullptr);
|
|
|
| favicon::FaviconDriver* favicon_driver =
|
| favicon::ContentFaviconDriver::FromWebContents(web_contents_.get());
|
| @@ -801,6 +843,74 @@ void TabAndroid::AttachToTabContentManager(
|
| tab_content_manager_->AttachLiveLayer(GetAndroidId(), GetContentLayer());
|
| }
|
|
|
| +void TabAndroid::RenderFrameCreated(
|
| + content::RenderFrameHost* render_frame_host) {
|
| + if (base::FeatureList::IsEnabled(
|
| + feature_engagement_tracker::kIPHMediaDownloadFeature)) {
|
| + // Register the service for the renderer to request showing the UI.
|
| + render_frame_host->GetInterfaceRegistry()->AddInterface(
|
| + base::Bind(&TabAndroid::CreateInProductHelpService,
|
| + weak_factory_.GetWeakPtr(), render_frame_host));
|
| + }
|
| +}
|
| +
|
| +void TabAndroid::RenderFrameDeleted(
|
| + content::RenderFrameHost* render_frame_host) {
|
| + if (media_in_product_help_ &&
|
| + media_in_product_help_->render_frame_host() == render_frame_host) {
|
| + DismissMediaDownloadInProductHelp();
|
| + }
|
| +}
|
| +
|
| +void TabAndroid::ShowMediaDownloadInProductHelp(
|
| + const gfx::Rect& rect_in_frame) {
|
| + DCHECK(web_contents_);
|
| +
|
| + // We need to account for the browser controls offset to get the location for
|
| + // the widget in the view.
|
| + float content_offset = web_contents_->GetNativeView()->content_offset();
|
| + gfx::Rect rect_in_view(rect_in_frame.x(), rect_in_frame.y() + content_offset,
|
| + rect_in_frame.width(), rect_in_frame.height());
|
| + gfx::Rect rect_in_view_scaled = gfx::ScaleToEnclosingRectSafe(
|
| + rect_in_view,
|
| + ui::GetScaleFactorForNativeView(web_contents_->GetNativeView()));
|
| +
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_Tab_showMediaDownloadInProductHelp(
|
| + env, weak_java_tab_.get(env), rect_in_view_scaled.x(),
|
| + rect_in_view_scaled.y(), rect_in_view_scaled.width(),
|
| + rect_in_view_scaled.height());
|
| +}
|
| +
|
| +void TabAndroid::DismissMediaDownloadInProductHelp() {
|
| + JNIEnv* env = base::android::AttachCurrentThread();
|
| + Java_Tab_hideMediaDownloadInProductHelp(env, weak_java_tab_.get(env));
|
| +}
|
| +
|
| +void TabAndroid::DownloadMediaInProductHelpDismissed(
|
| + JNIEnv* env,
|
| + const base::android::JavaParamRef<jobject>& obj) {
|
| + DCHECK(media_in_product_help_);
|
| + media_in_product_help_.reset();
|
| +}
|
| +
|
| +void TabAndroid::CreateInProductHelpService(
|
| + content::RenderFrameHost* render_frame_host,
|
| + const service_manager::BindSourceInfo& source_info,
|
| + blink::mojom::MediaInProductHelpRequest request) {
|
| + // If we are showing the UI already, ignore the request.
|
| + if (media_in_product_help_)
|
| + return;
|
| +
|
| + media_in_product_help_ = base::MakeUnique<MediaInProductHelp>(
|
| + render_frame_host, this, std::move(request));
|
| +}
|
| +
|
| +void TabAndroid::OnMediaInProductHelpConnectionError() {
|
| + DCHECK(media_in_product_help_);
|
| + DismissMediaDownloadInProductHelp();
|
| +}
|
| +
|
| scoped_refptr<content::DevToolsAgentHost> TabAndroid::GetDevToolsAgentHost() {
|
| return devtools_host_;
|
| }
|
|
|