| Index: chrome/browser/android/media_in_product_help_manager.cc
|
| diff --git a/chrome/browser/android/media_in_product_help_manager.cc b/chrome/browser/android/media_in_product_help_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8445c4fdc7cbff10522af3adb3363a44c4a22f20
|
| --- /dev/null
|
| +++ b/chrome/browser/android/media_in_product_help_manager.cc
|
| @@ -0,0 +1,105 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/android/media_in_product_help_manager.h"
|
| +
|
| +#include "base/memory/ptr_util.h"
|
| +#include "base/optional.h"
|
| +#include "content/public/browser/navigation_handle.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/render_widget_host_view.h"
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| +#include "services/service_manager/public/cpp/bind_source_info.h"
|
| +#include "services/service_manager/public/cpp/interface_provider.h"
|
| +
|
| +// This class is created and owned by the MediaInProductHelpManager.
|
| +class MediaInProductHelpManager::MediaInProductHelp
|
| + : public blink::mojom::MediaInProductHelp {
|
| + public:
|
| + MediaInProductHelp(content::RenderFrameHost* render_frame_host,
|
| + MediaInProductHelpManager* manager,
|
| + blink::mojom::MediaInProductHelpRequest request)
|
| + : render_frame_host_(render_frame_host),
|
| + manager_(manager),
|
| + binding_(this, std::move(request)) {
|
| + DCHECK(render_frame_host_);
|
| + DCHECK(manager_);
|
| +
|
| + binding_.set_connection_error_handler(
|
| + base::BindOnce(&MediaInProductHelpManager::OnConnectionError,
|
| + base::Unretained(manager_)));
|
| + }
|
| + ~MediaInProductHelp() override = default;
|
| +
|
| + // blink::mojom::MediaPromoUI implementation.
|
| + void ShowInProductHelpWidget(const gfx::Rect& rect) override {
|
| + manager_->ShowInProductHelpWidget(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_;
|
| + MediaInProductHelpManager* manager_;
|
| + mojo::Binding<blink::mojom::MediaInProductHelp> binding_;
|
| +};
|
| +
|
| +MediaInProductHelpManager::MediaInProductHelpManager(
|
| + content::WebContents* web_contents,
|
| + MediaInProductHelpManagerClient* client)
|
| + : WebContentsObserver(web_contents), client_(client), weak_factory_(this) {
|
| + DCHECK(client_);
|
| +}
|
| +
|
| +MediaInProductHelpManager::~MediaInProductHelpManager() {
|
| + if (media_in_product_help_) {
|
| + client_->DismissMediaDownloadInProductHelp();
|
| + }
|
| +}
|
| +
|
| +void MediaInProductHelpManager::WidgetDismissed() {
|
| + DCHECK(media_in_product_help_);
|
| + media_in_product_help_.reset();
|
| +}
|
| +
|
| +void MediaInProductHelpManager::RenderFrameCreated(
|
| + content::RenderFrameHost* render_frame_host) {
|
| + // Register the service for the renderer to request showing the UI.
|
| + render_frame_host->GetInterfaceRegistry()->AddInterface(
|
| + base::Bind(&MediaInProductHelpManager::CreateInProductHelpService,
|
| + weak_factory_.GetWeakPtr(), render_frame_host));
|
| +}
|
| +
|
| +void MediaInProductHelpManager::RenderFrameDeleted(
|
| + content::RenderFrameHost* render_frame_host) {
|
| + if (media_in_product_help_ &&
|
| + media_in_product_help_->render_frame_host() == render_frame_host) {
|
| + client_->DismissMediaDownloadInProductHelp();
|
| + }
|
| +}
|
| +
|
| +void MediaInProductHelpManager::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 MediaInProductHelpManager::ShowInProductHelpWidget(
|
| + const gfx::Rect& rect_in_main_frame) {
|
| + client_->ShowMediaDownloadInProductHelp(rect_in_main_frame);
|
| +}
|
| +
|
| +void MediaInProductHelpManager::OnConnectionError() {
|
| + DCHECK(media_in_product_help_);
|
| + client_->DismissMediaDownloadInProductHelp();
|
| +}
|
|
|