OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 6 #define CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 88 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
89 ReceiveConnectionMessagesAfterReset); | 89 ReceiveConnectionMessagesAfterReset); |
90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 90 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
91 MaxPendingStartSessionRequests); | 91 MaxPendingStartSessionRequests); |
92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 92 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
93 MaxPendingJoinSessionRequests); | 93 MaxPendingJoinSessionRequests); |
94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 94 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
95 ListenForConnectionStateChangeAndChangeState); | 95 ListenForConnectionStateChangeAndChangeState); |
96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, | 96 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
97 ListenForConnectionClose); | 97 ListenForConnectionClose); |
| 98 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 99 SetPresentationConnection); |
| 100 FRIEND_TEST_ALL_PREFIXES(PresentationServiceImplTest, |
| 101 ReceiverPresentationServiceDelegate); |
98 | 102 |
99 // Maximum number of pending JoinSession requests at any given time. | 103 // Maximum number of pending JoinSession requests at any given time. |
100 static const int kMaxNumQueuedSessionRequests = 10; | 104 static const int kMaxNumQueuedSessionRequests = 10; |
101 | 105 |
102 using ConnectionMessagesCallback = | 106 using ConnectionMessagesCallback = |
103 base::Callback<void(std::vector<blink::mojom::ConnectionMessagePtr>)>; | 107 base::Callback<void(std::vector<blink::mojom::ConnectionMessagePtr>)>; |
104 using SendConnectionMessageCallback = base::Callback<void(bool)>; | 108 using SendConnectionMessageCallback = base::Callback<void(bool)>; |
105 | 109 |
106 // Listener implementation owned by PresentationServiceImpl. An instance of | 110 // Listener implementation owned by PresentationServiceImpl. An instance of |
107 // this is created when PresentationRequest.getAvailability() is resolved. | 111 // this is created when PresentationRequest.getAvailability() is resolved. |
(...skipping 28 matching lines...) Expand all Loading... |
136 blink::mojom::PresentationErrorPtr error); | 140 blink::mojom::PresentationErrorPtr error); |
137 | 141 |
138 private: | 142 private: |
139 NewSessionCallback callback_; | 143 NewSessionCallback callback_; |
140 | 144 |
141 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); | 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); |
142 }; | 146 }; |
143 | 147 |
144 // |render_frame_host|: The RFH this instance is associated with. | 148 // |render_frame_host|: The RFH this instance is associated with. |
145 // |web_contents|: The WebContents to observe. | 149 // |web_contents|: The WebContents to observe. |
146 // |delegate|: Where Presentation API requests are delegated to. Not owned | 150 // |controller_delegate|: Where Presentation API requests are delegated to in |
147 // by this class. | 151 // controller frame. Set to nullptr if current frame is receiver frame. Not |
| 152 // owned by this class. |
| 153 // |receiver_delegate|: Where Presentation API requests are delegated to in |
| 154 // receiver frame. Set to nullptr if current frame is controller frame. Not |
| 155 // owned by this class. |
148 PresentationServiceImpl( | 156 PresentationServiceImpl( |
149 RenderFrameHost* render_frame_host, | 157 RenderFrameHost* render_frame_host, |
150 WebContents* web_contents, | 158 WebContents* web_contents, |
151 PresentationServiceDelegate* delegate); | 159 ControllerPresentationServiceDelegate* controller_delegate, |
| 160 ReceiverPresentationServiceDelegate* receiver_delegate); |
152 | 161 |
153 // PresentationService implementation. | 162 // PresentationService implementation. |
154 void SetDefaultPresentationUrls( | 163 void SetDefaultPresentationUrls( |
155 const std::vector<GURL>& presentation_urls) override; | 164 const std::vector<GURL>& presentation_urls) override; |
156 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; | 165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; |
157 void ListenForScreenAvailability(const GURL& url) override; | 166 void ListenForScreenAvailability(const GURL& url) override; |
158 void StopListeningForScreenAvailability(const GURL& url) override; | 167 void StopListeningForScreenAvailability(const GURL& url) override; |
159 void StartSession(const std::vector<GURL>& presentation_urls, | 168 void StartSession(const std::vector<GURL>& presentation_urls, |
160 const NewSessionCallback& callback) override; | 169 const NewSessionCallback& callback) override; |
161 void JoinSession(const std::vector<GURL>& presentation_urls, | 170 void JoinSession(const std::vector<GURL>& presentation_urls, |
162 const base::Optional<std::string>& presentation_id, | 171 const base::Optional<std::string>& presentation_id, |
163 const NewSessionCallback& callback) override; | 172 const NewSessionCallback& callback) override; |
164 void SendConnectionMessage( | 173 void SendConnectionMessage( |
165 blink::mojom::PresentationSessionInfoPtr session_info, | 174 blink::mojom::PresentationSessionInfoPtr session_info, |
166 blink::mojom::ConnectionMessagePtr connection_message, | 175 blink::mojom::ConnectionMessagePtr connection_message, |
167 const SendConnectionMessageCallback& callback) override; | 176 const SendConnectionMessageCallback& callback) override; |
168 void CloseConnection(const GURL& presentation_url, | 177 void CloseConnection(const GURL& presentation_url, |
169 const std::string& presentation_id) override; | 178 const std::string& presentation_id) override; |
170 void Terminate(const GURL& presentation_url, | 179 void Terminate(const GURL& presentation_url, |
171 const std::string& presentation_id) override; | 180 const std::string& presentation_id) override; |
172 void ListenForConnectionMessages( | 181 void ListenForConnectionMessages( |
173 blink::mojom::PresentationSessionInfoPtr session) override; | 182 blink::mojom::PresentationSessionInfoPtr session) override; |
| 183 void SetPresentationConnection( |
| 184 blink::mojom::PresentationSessionInfoPtr session, |
| 185 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
| 186 blink::mojom::PresentationConnectionRequest receiver_connection_request) |
| 187 override; |
174 | 188 |
175 // Creates a binding between this object and |request|. | 189 // Creates a binding between this object and |request|. |
176 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 190 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
177 | 191 |
178 // WebContentsObserver override. | 192 // WebContentsObserver override. |
179 void DidNavigateAnyFrame( | 193 void DidNavigateAnyFrame( |
180 content::RenderFrameHost* render_frame_host, | 194 content::RenderFrameHost* render_frame_host, |
181 const content::LoadCommittedDetails& details, | 195 const content::LoadCommittedDetails& details, |
182 const content::FrameNavigateParams& params) override; | 196 const content::FrameNavigateParams& params) override; |
183 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 197 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 const PresentationSessionInfo& connection); | 243 const PresentationSessionInfo& connection); |
230 | 244 |
231 // Passed to embedder's implementation of PresentationServiceDelegate for | 245 // Passed to embedder's implementation of PresentationServiceDelegate for |
232 // later invocation when session messages arrive. | 246 // later invocation when session messages arrive. |
233 void OnConnectionMessages( | 247 void OnConnectionMessages( |
234 const content::PresentationSessionInfo& session, | 248 const content::PresentationSessionInfo& session, |
235 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& | 249 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& |
236 messages, | 250 messages, |
237 bool pass_ownership); | 251 bool pass_ownership); |
238 | 252 |
| 253 // A callback registered to OffscreenPresentationManager when |
| 254 // the PresentationServiceImpl for the presentation receiver is initialized. |
| 255 // Calls |client_| to create a new PresentationConnection on receiver page. |
| 256 void OnReceiverConnectionAvailable( |
| 257 const content::PresentationSessionInfo& session_info, |
| 258 PresentationConnectionPtr controller_connection_ptr, |
| 259 PresentationConnectionRequest receiver_connection_request); |
| 260 |
239 // Associates a JoinSession |callback| with a unique request ID and | 261 // Associates a JoinSession |callback| with a unique request ID and |
240 // stores it in a map. | 262 // stores it in a map. |
241 // Returns a positive value on success. | 263 // Returns a positive value on success. |
242 int RegisterJoinSessionCallback(const NewSessionCallback& callback); | 264 int RegisterJoinSessionCallback(const NewSessionCallback& callback); |
243 | 265 |
244 // Invoked by the embedder's PresentationServiceDelegate when a | 266 // Invoked by the embedder's PresentationServiceDelegate when a |
245 // PresentationConnection's state has changed. | 267 // PresentationConnection's state has changed. |
246 void OnConnectionStateChanged( | 268 void OnConnectionStateChanged( |
247 const PresentationSessionInfo& connection, | 269 const PresentationSessionInfo& connection, |
248 const PresentationConnectionStateChangeInfo& info); | 270 const PresentationConnectionStateChangeInfo& info); |
249 | 271 |
250 // Returns true if this object is associated with |render_frame_host|. | 272 // Returns true if this object is associated with |render_frame_host|. |
251 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; | 273 bool FrameMatches(content::RenderFrameHost* render_frame_host) const; |
252 | 274 |
253 // Embedder-specific delegate to forward Presentation requests to. | 275 // Returns |controller_delegate| if current frame is controller frame; Returns |
254 // May be null if embedder does not support Presentation API. | 276 // |receiver_delegate| if current frame is receiver frame. |
255 PresentationServiceDelegate* delegate_; | 277 PresentationServiceDelegate* GetPresentationServiceDelegate(); |
| 278 |
| 279 // Embedder-specific delegate for controller to forward Presentation requests |
| 280 // to. Must be nullptr if current page is receiver page or |
| 281 // embedder does not support Presentation API . |
| 282 ControllerPresentationServiceDelegate* controller_delegate_; |
| 283 |
| 284 // Embedder-specific delegate for receiver to forward Presentation requests |
| 285 // to. Must be nullptr if current page is receiver page or |
| 286 // embedder does not support Presentation API. |
| 287 ReceiverPresentationServiceDelegate* receiver_delegate_; |
256 | 288 |
257 // Proxy to the PresentationServiceClient to send results (e.g., screen | 289 // Proxy to the PresentationServiceClient to send results (e.g., screen |
258 // availability) to. | 290 // availability) to. |
259 blink::mojom::PresentationServiceClientPtr client_; | 291 blink::mojom::PresentationServiceClientPtr client_; |
260 | 292 |
261 std::vector<GURL> default_presentation_urls_; | 293 std::vector<GURL> default_presentation_urls_; |
262 | 294 |
263 using ScreenAvailabilityListenerMap = | 295 using ScreenAvailabilityListenerMap = |
264 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; | 296 std::map<GURL, std::unique_ptr<ScreenAvailabilityListenerImpl>>; |
265 ScreenAvailabilityListenerMap screen_availability_listeners_; | 297 ScreenAvailabilityListenerMap screen_availability_listeners_; |
(...skipping 22 matching lines...) Expand all Loading... |
288 | 320 |
289 // NOTE: Weak pointers must be invalidated before all other member variables. | 321 // NOTE: Weak pointers must be invalidated before all other member variables. |
290 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 322 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
291 | 323 |
292 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 324 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
293 }; | 325 }; |
294 | 326 |
295 } // namespace content | 327 } // namespace content |
296 | 328 |
297 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 329 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
OLD | NEW |