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

Side by Side Diff: chrome/browser/media/router/receiver_presentation_service_delegate_impl.h

Issue 1314413005: [Presentation API] 1-UA presentation support + presenter APIs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 2015 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 #ifndef CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IMPL_ H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IMPL_ H_
7
8 #include <map>
9
10 #include "base/observer_list.h"
11 #include "chrome/browser/media/router/offscreen_presentation_manager.h"
12 #include "chrome/browser/media/router/render_frame_host_id.h"
13 #include "content/public/browser/presentation_service_delegate.h"
14 #include "content/public/browser/web_contents_user_data.h"
15
16 namespace content {
17 class RenderFrameHost;
18 class WebContents;
19 struct PresentationSessionInfo;
20 struct PresentationSessionMessage;
21 } // namespace content
22
23 namespace media_router {
24
25 // Implements the receiver side of presentation API for offscreen presentations.
26 // Created under the offscreen tab WebContents when the tab is created for an
27 // offscreen presentation. Each instance is tied to a single offscreen
28 // presentation whose ID is given during construction. As such, the receiver
29 // APIs are contextual with the offscreen presentation.
30 // Only the main frame of the offscreen tab is allowed to make receiver
31 // Presentation API requests; requests made from any other frame will be
32 // rejected.
33 class ReceiverPresentationServiceDelegateImpl
34 : public content::WebContentsUserData<
35 ReceiverPresentationServiceDelegateImpl>,
36 public content::PresentationServiceDelegate {
37 public:
38 // Creates an instance of ReceiverPresentationServiceDelegateImpl under
39 // |web_contents| and registers it as the receiver of the offscreen
40 // presentation |presentation_id| with OffscreenPresentationManager.
41 // No-op if a ReceiverPresentationServiceDelegateImpl instance already
42 // exists under |web_contents|.
43 static void CreateForWebContents(content::WebContents* web_contents,
44 const std::string& presentation_id);
45
46 ~ReceiverPresentationServiceDelegateImpl() override;
47
48 // content::PresentationServiceDelegate implementation.
49 void AddObserver(
50 int render_process_id,
51 int render_frame_id,
52 content::PresentationServiceDelegate::Observer* observer) override;
53 void RemoveObserver(int render_process_id, int render_frame_id) override;
54 bool AddScreenAvailabilityListener(
55 int render_process_id,
56 int render_frame_id,
57 content::PresentationScreenAvailabilityListener* listener) override;
58 void RemoveScreenAvailabilityListener(
59 int render_process_id,
60 int render_frame_id,
61 content::PresentationScreenAvailabilityListener* listener) override;
62 void Reset(int render_process_id, int render_frame_id) override;
63 void SetDefaultPresentationUrl(
64 int render_process_id,
65 int render_frame_id,
66 const std::string& default_presentation_url,
67 const content::PresentationSessionStartedCallback& callback) override;
68 void StartSession(
69 int render_process_id,
70 int render_frame_id,
71 const std::string& presentation_url,
72 const content::PresentationSessionStartedCallback& success_cb,
73 const content::PresentationSessionErrorCallback& error_cb) override;
74 void JoinSession(
75 int render_process_id,
76 int render_frame_id,
77 const std::string& presentation_url,
78 const std::string& presentation_id,
79 const content::PresentationSessionStartedCallback& success_cb,
80 const content::PresentationSessionErrorCallback& error_cb) override;
81 void CloseConnection(int render_process_id,
82 int render_frame_id,
83 const std::string& presentation_id) override;
84 void Terminate(int render_process_id,
85 int render_frame_id,
86 const std::string& presentation_id) override;
87 void ListenForSessionMessages(
88 int render_process_id,
89 int render_frame_id,
90 const content::PresentationSessionInfo& session_info,
91 const content::PresentationSessionMessageCallback& message_cb) override;
92 void SendMessage(
93 int render_process_id,
94 int render_frame_id,
95 const content::PresentationSessionInfo& session_info,
96 std::unique_ptr<content::PresentationSessionMessage> message,
97 const content::SendMessageCallback& send_message_cb) override;
98 void ListenForConnectionStateChange(
99 int render_process_id,
100 int render_frame_id,
101 const content::PresentationSessionInfo& connection,
102 const content::PresentationConnectionStateChangedCallback&
103 state_changed_cb) override;
104 std::vector<content::PresentationSessionInfo> GetReceiverConnections(
105 int render_process_id,
106 int render_frame_id,
107 const content::PresentationSessionStartedCallback& callback) override;
108
109 private:
110 friend class content::WebContentsUserData<
111 ReceiverPresentationServiceDelegateImpl>;
112
113 explicit ReceiverPresentationServiceDelegateImpl(
114 content::WebContents* web_contents,
115 const std::string& presentation_id);
116 void OnReceiverConnectionAvailable(
117 std::unique_ptr<
118 OffscreenPresentationManager::OffscreenPresentationConnection>
119 connection);
120 bool IsMainFrame(const RenderFrameHostId& rfh_id) const;
121
122 // Attempts to set |current_frame_id_|. Returns |true| if |current_frame_id_|
123 // is currently not set, and provided frame ID is the main frame of the
124 // WebContents.
125 bool BindToFrame(const RenderFrameHostId& rfh_id);
126
127 OffscreenPresentationManager::OffscreenPresentationConnection* FindConnection(
128 const content::PresentationSessionInfo& session_info);
129
130 // Reference to the WebContents that owns this instance.
131 content::WebContents* const web_contents_;
132
133 const std::string presentation_id_;
134 OffscreenPresentationManager* const offscreen_presentation_manager_;
135 std::vector<std::unique_ptr<
136 OffscreenPresentationManager::OffscreenPresentationConnection>>
137 receiver_connections_;
138 content::PresentationSessionStartedCallback receiver_available_callback_;
139 std::map<RenderFrameHostId, content::PresentationServiceDelegate::Observer*>
140 observers_;
141
142 // Set to the current main frame of the owning WebContents on first request,
143 // and unset when Reset() is called with current main frame. When this is
144 // set, incoming requests except Reset() will be rejected if it does not match
145 // the incoming frame.
146 RenderFrameHostId current_frame_id_;
147
148 DISALLOW_COPY_AND_ASSIGN(ReceiverPresentationServiceDelegateImpl);
149 };
150
151 } // namespace media_router
152
153 #endif // CHROME_BROWSER_MEDIA_ROUTER_RECEIVER_PRESENTATION_SERVICE_DELEGATE_IM PL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698