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

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

Issue 2943983003: chrome/blink: Add functionality for in-product help for media elements. (Closed)
Patch Set: nyquist 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/media_in_product_help_manager.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/optional.h"
9 #include "content/public/browser/navigation_handle.h"
10 #include "content/public/browser/render_frame_host.h"
11 #include "content/public/browser/render_widget_host_view.h"
12 #include "mojo/public/cpp/bindings/strong_binding.h"
13 #include "services/service_manager/public/cpp/bind_source_info.h"
14 #include "services/service_manager/public/cpp/interface_provider.h"
15
16 // This class is created and owned by the MediaInProductHelpManager.
17 class MediaInProductHelpManager::MediaInProductHelp
18 : public blink::mojom::MediaInProductHelp {
19 public:
20 MediaInProductHelp(content::RenderFrameHost* render_frame_host,
21 MediaInProductHelpManager* manager,
22 blink::mojom::MediaInProductHelpRequest request)
23 : render_frame_host_(render_frame_host),
24 manager_(manager),
25 binding_(this, std::move(request)) {
26 DCHECK(render_frame_host_);
27 DCHECK(manager_);
28
29 binding_.set_connection_error_handler(
30 base::BindOnce(&MediaInProductHelpManager::OnConnectionError,
31 base::Unretained(manager_)));
32 }
33 ~MediaInProductHelp() override = default;
34
35 // blink::mojom::MediaPromoUI implementation.
36 void ShowInProductHelpWidget(const gfx::Rect& rect) override {
37 manager_->ShowInProductHelpWidget(rect);
38 }
39
40 content::RenderFrameHost* render_frame_host() const {
41 return render_frame_host_;
42 }
43
44 private:
45 // The |manager_| and |render_frame_host_| outlive this class.
46 content::RenderFrameHost* render_frame_host_;
47 MediaInProductHelpManager* manager_;
48 mojo::Binding<blink::mojom::MediaInProductHelp> binding_;
49 };
Sam McNally 2017/07/07 05:22:58 DISALLOW_COPY_AND_ASSIGN
50
51 MediaInProductHelpManager::MediaInProductHelpManager(
52 content::WebContents* web_contents,
53 MediaInProductHelpManagerClient* client)
54 : WebContentsObserver(web_contents), client_(client), weak_factory_(this) {
55 DCHECK(client_);
56 }
57
58 MediaInProductHelpManager::~MediaInProductHelpManager() {
59 if (media_in_product_help_) {
60 client_->DismissMediaDownloadInProductHelp();
61 }
62 }
63
64 void MediaInProductHelpManager::WidgetDismissed() {
65 DCHECK(media_in_product_help_);
66 media_in_product_help_.reset();
67 }
68
69 void MediaInProductHelpManager::RenderFrameCreated(
70 content::RenderFrameHost* render_frame_host) {
71 // Register the service for the renderer to request showing the UI.
72 render_frame_host->GetInterfaceRegistry()->AddInterface(
73 base::Bind(&MediaInProductHelpManager::CreateInProductHelpService,
74 weak_factory_.GetWeakPtr(), render_frame_host));
75 }
76
77 void MediaInProductHelpManager::RenderFrameDeleted(
78 content::RenderFrameHost* render_frame_host) {
79 if (media_in_product_help_ &&
80 media_in_product_help_->render_frame_host() == render_frame_host) {
81 client_->DismissMediaDownloadInProductHelp();
82 }
83 }
84
85 void MediaInProductHelpManager::CreateInProductHelpService(
86 content::RenderFrameHost* render_frame_host,
87 const service_manager::BindSourceInfo& source_info,
88 blink::mojom::MediaInProductHelpRequest request) {
89 // If we are showing the UI already, ignore the request.
90 if (media_in_product_help_)
Khushal 2017/07/07 04:18:14 sammc@, is this the correct way to ignore requests
Sam McNally 2017/07/07 05:22:58 Yes. There will be a race between an existing conn
91 return;
92
93 media_in_product_help_ = base::MakeUnique<MediaInProductHelp>(
94 render_frame_host, this, std::move(request));
95 }
96
97 void MediaInProductHelpManager::ShowInProductHelpWidget(
98 const gfx::Rect& rect_in_main_frame) {
99 client_->ShowMediaDownloadInProductHelp(rect_in_main_frame);
100 }
101
102 void MediaInProductHelpManager::OnConnectionError() {
103 DCHECK(media_in_product_help_);
104 client_->DismissMediaDownloadInProductHelp();
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698