| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 // PresentationServiceDelegate. | 43 // PresentationServiceDelegate. |
| 44 // An instance of this class tied to a RenderFrameHost and listens to events | 44 // An instance of this class tied to a RenderFrameHost and listens to events |
| 45 // related to the RFH via implementing WebContentsObserver. | 45 // related to the RFH via implementing WebContentsObserver. |
| 46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService | 46 // This class is instantiated on-demand via Mojo's ConnectToRemoteService |
| 47 // from the renderer when the first presentation API request is handled. | 47 // from the renderer when the first presentation API request is handled. |
| 48 class CONTENT_EXPORT PresentationServiceImpl | 48 class CONTENT_EXPORT PresentationServiceImpl |
| 49 : public NON_EXPORTED_BASE(blink::mojom::PresentationService), | 49 : public NON_EXPORTED_BASE(blink::mojom::PresentationService), |
| 50 public WebContentsObserver, | 50 public WebContentsObserver, |
| 51 public PresentationServiceDelegate::Observer { | 51 public PresentationServiceDelegate::Observer { |
| 52 public: | 52 public: |
| 53 ~PresentationServiceImpl() override; |
| 54 |
| 53 using NewSessionCallback = | 55 using NewSessionCallback = |
| 54 base::Callback<void(blink::mojom::PresentationSessionInfoPtr, | 56 base::Callback<void(const base::Optional<PresentationSessionInfo>&, |
| 55 blink::mojom::PresentationErrorPtr)>; | 57 const base::Optional<PresentationError>&)>; |
| 56 | |
| 57 ~PresentationServiceImpl() override; | |
| 58 | 58 |
| 59 // Static factory method to create an instance of PresentationServiceImpl. | 59 // Static factory method to create an instance of PresentationServiceImpl. |
| 60 // |render_frame_host|: The RFH the instance is associated with. | 60 // |render_frame_host|: The RFH the instance is associated with. |
| 61 // |request|: The instance will be bound to this request. Used for Mojo setup. | 61 // |request|: The instance will be bound to this request. Used for Mojo setup. |
| 62 static void CreateMojoService( | 62 static void CreateMojoService( |
| 63 RenderFrameHost* render_frame_host, | 63 RenderFrameHost* render_frame_host, |
| 64 mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 64 mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 friend class PresentationServiceImplTest; | 67 friend class PresentationServiceImplTest; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 // Ensures the provided NewSessionCallback is invoked exactly once | 131 // Ensures the provided NewSessionCallback is invoked exactly once |
| 132 // before it goes out of scope. | 132 // before it goes out of scope. |
| 133 class NewSessionCallbackWrapper { | 133 class NewSessionCallbackWrapper { |
| 134 public: | 134 public: |
| 135 explicit NewSessionCallbackWrapper( | 135 explicit NewSessionCallbackWrapper( |
| 136 const NewSessionCallback& callback); | 136 const NewSessionCallback& callback); |
| 137 ~NewSessionCallbackWrapper(); | 137 ~NewSessionCallbackWrapper(); |
| 138 | 138 |
| 139 void Run(blink::mojom::PresentationSessionInfoPtr session, | 139 void Run(const base::Optional<PresentationSessionInfo>& session_info, |
| 140 blink::mojom::PresentationErrorPtr error); | 140 const base::Optional<PresentationError>& error); |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 NewSessionCallback callback_; | 143 NewSessionCallback callback_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); | 145 DISALLOW_COPY_AND_ASSIGN(NewSessionCallbackWrapper); |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 // |render_frame_host|: The RFH this instance is associated with. | 148 // |render_frame_host|: The RFH this instance is associated with. |
| 149 // |web_contents|: The WebContents to observe. | 149 // |web_contents|: The WebContents to observe. |
| 150 // |controller_delegate|: Where Presentation API requests are delegated to in | 150 // |controller_delegate|: Where Presentation API requests are delegated to in |
| (...skipping 13 matching lines...) Expand all Loading... |
| 164 const std::vector<GURL>& presentation_urls) override; | 164 const std::vector<GURL>& presentation_urls) override; |
| 165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; | 165 void SetClient(blink::mojom::PresentationServiceClientPtr client) override; |
| 166 void ListenForScreenAvailability(const GURL& url) override; | 166 void ListenForScreenAvailability(const GURL& url) override; |
| 167 void StopListeningForScreenAvailability(const GURL& url) override; | 167 void StopListeningForScreenAvailability(const GURL& url) override; |
| 168 void StartSession(const std::vector<GURL>& presentation_urls, | 168 void StartSession(const std::vector<GURL>& presentation_urls, |
| 169 const NewSessionCallback& callback) override; | 169 const NewSessionCallback& callback) override; |
| 170 void JoinSession(const std::vector<GURL>& presentation_urls, | 170 void JoinSession(const std::vector<GURL>& presentation_urls, |
| 171 const base::Optional<std::string>& presentation_id, | 171 const base::Optional<std::string>& presentation_id, |
| 172 const NewSessionCallback& callback) override; | 172 const NewSessionCallback& callback) override; |
| 173 void SendConnectionMessage( | 173 void SendConnectionMessage( |
| 174 blink::mojom::PresentationSessionInfoPtr session_info, | 174 const PresentationSessionInfo& session_info, |
| 175 blink::mojom::ConnectionMessagePtr connection_message, | 175 blink::mojom::ConnectionMessagePtr connection_message, |
| 176 const SendConnectionMessageCallback& callback) override; | 176 const SendConnectionMessageCallback& callback) override; |
| 177 void CloseConnection(const GURL& presentation_url, | 177 void CloseConnection(const GURL& presentation_url, |
| 178 const std::string& presentation_id) override; | 178 const std::string& presentation_id) override; |
| 179 void Terminate(const GURL& presentation_url, | 179 void Terminate(const GURL& presentation_url, |
| 180 const std::string& presentation_id) override; | 180 const std::string& presentation_id) override; |
| 181 void ListenForConnectionMessages( | 181 void ListenForConnectionMessages( |
| 182 blink::mojom::PresentationSessionInfoPtr session) override; | 182 const PresentationSessionInfo& session_info) override; |
| 183 void SetPresentationConnection( | 183 void SetPresentationConnection( |
| 184 blink::mojom::PresentationSessionInfoPtr session, | 184 const PresentationSessionInfo& session_info, |
| 185 blink::mojom::PresentationConnectionPtr controller_connection_ptr, | 185 blink::mojom::PresentationConnectionPtr controller_connection_ptr, |
| 186 blink::mojom::PresentationConnectionRequest receiver_connection_request) | 186 blink::mojom::PresentationConnectionRequest receiver_connection_request) |
| 187 override; | 187 override; |
| 188 | 188 |
| 189 // Creates a binding between this object and |request|. | 189 // Creates a binding between this object and |request|. |
| 190 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); | 190 void Bind(mojo::InterfaceRequest<blink::mojom::PresentationService> request); |
| 191 | 191 |
| 192 // WebContentsObserver override. | 192 // WebContentsObserver override. |
| 193 void DidNavigateAnyFrame( | 193 void DidNavigateAnyFrame( |
| 194 content::RenderFrameHost* render_frame_host, | 194 content::RenderFrameHost* render_frame_host, |
| 195 const content::LoadCommittedDetails& details, | 195 const content::LoadCommittedDetails& details, |
| 196 const content::FrameNavigateParams& params) override; | 196 const content::FrameNavigateParams& params) override; |
| 197 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; | 197 void RenderFrameDeleted(content::RenderFrameHost* render_frame_host) override; |
| 198 void WebContentsDestroyed() override; | 198 void WebContentsDestroyed() override; |
| 199 | 199 |
| 200 // PresentationServiceDelegate::Observer | 200 // PresentationServiceDelegate::Observer |
| 201 void OnDelegateDestroyed() override; | 201 void OnDelegateDestroyed() override; |
| 202 | 202 |
| 203 // Passed to embedder's implementation of PresentationServiceDelegate for | 203 // Passed to embedder's implementation of PresentationServiceDelegate for |
| 204 // later invocation when default presentation has started. | 204 // later invocation when default presentation has started. |
| 205 void OnDefaultPresentationStarted( | 205 void OnDefaultPresentationStarted( |
| 206 const PresentationSessionInfo& session_info); | 206 const PresentationSessionInfo& session_info); |
| 207 | 207 |
| 208 // Finds the callback from |pending_join_session_cbs_| using | 208 // Finds the callback from |pending_join_session_cbs_| using |
| 209 // |request_session_id|. | 209 // |request_session_id|. |
| 210 // If it exists, invoke it with |session| and |error|, then erase it from | 210 // If it exists, invoke it with |session_info| and |error|, then erase it from |
| 211 // |pending_join_session_cbs_|. | 211 // |pending_join_session_cbs_|. |
| 212 // Returns true if the callback was found. | 212 // Returns true if the callback was found. |
| 213 bool RunAndEraseJoinSessionMojoCallback( | 213 bool RunAndEraseJoinSessionMojoCallback( |
| 214 int request_session_id, | 214 int request_session_id, |
| 215 blink::mojom::PresentationSessionInfoPtr session, | 215 const base::Optional<PresentationSessionInfo>& session_info, |
| 216 blink::mojom::PresentationErrorPtr error); | 216 const base::Optional<PresentationError>& error); |
| 217 | 217 |
| 218 // Removes all listeners and resets default presentation URL on this instance | 218 // Removes all listeners and resets default presentation URL on this instance |
| 219 // and informs the PresentationServiceDelegate of such. | 219 // and informs the PresentationServiceDelegate of such. |
| 220 void Reset(); | 220 void Reset(); |
| 221 | 221 |
| 222 // These functions are bound as base::Callbacks and passed to | 222 // These functions are bound as base::Callbacks and passed to |
| 223 // embedder's implementation of PresentationServiceDelegate for later | 223 // embedder's implementation of PresentationServiceDelegate for later |
| 224 // invocation. | 224 // invocation. |
| 225 void OnStartSessionSucceeded( | 225 void OnStartSessionSucceeded( |
| 226 int request_session_id, | 226 int request_session_id, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 void OnSendMessageCallback(bool sent); | 237 void OnSendMessageCallback(bool sent); |
| 238 | 238 |
| 239 // Calls to |delegate_| to start listening for state changes for |connection|. | 239 // Calls to |delegate_| to start listening for state changes for |connection|. |
| 240 // State changes will be returned via |OnConnectionStateChanged|. | 240 // State changes will be returned via |OnConnectionStateChanged|. |
| 241 void ListenForConnectionStateChange( | 241 void ListenForConnectionStateChange( |
| 242 const PresentationSessionInfo& connection); | 242 const PresentationSessionInfo& connection); |
| 243 | 243 |
| 244 // Passed to embedder's implementation of PresentationServiceDelegate for | 244 // Passed to embedder's implementation of PresentationServiceDelegate for |
| 245 // later invocation when session messages arrive. | 245 // later invocation when session messages arrive. |
| 246 void OnConnectionMessages( | 246 void OnConnectionMessages( |
| 247 const content::PresentationSessionInfo& session, | 247 const content::PresentationSessionInfo& session_info, |
| 248 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& | 248 const std::vector<std::unique_ptr<PresentationConnectionMessage>>& |
| 249 messages, | 249 messages, |
| 250 bool pass_ownership); | 250 bool pass_ownership); |
| 251 | 251 |
| 252 // A callback registered to OffscreenPresentationManager when | 252 // A callback registered to OffscreenPresentationManager when |
| 253 // the PresentationServiceImpl for the presentation receiver is initialized. | 253 // the PresentationServiceImpl for the presentation receiver is initialized. |
| 254 // Calls |client_| to create a new PresentationConnection on receiver page. | 254 // Calls |client_| to create a new PresentationConnection on receiver page. |
| 255 void OnReceiverConnectionAvailable( | 255 void OnReceiverConnectionAvailable( |
| 256 const content::PresentationSessionInfo& session_info, | 256 const content::PresentationSessionInfo& session_info, |
| 257 PresentationConnectionPtr controller_connection_ptr, | 257 PresentationConnectionPtr controller_connection_ptr, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 319 |
| 320 // NOTE: Weak pointers must be invalidated before all other member variables. | 320 // NOTE: Weak pointers must be invalidated before all other member variables. |
| 321 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; | 321 base::WeakPtrFactory<PresentationServiceImpl> weak_factory_; |
| 322 | 322 |
| 323 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); | 323 DISALLOW_COPY_AND_ASSIGN(PresentationServiceImpl); |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 } // namespace content | 326 } // namespace content |
| 327 | 327 |
| 328 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ | 328 #endif // CONTENT_BROWSER_PRESENTATION_PRESENTATION_SERVICE_IMPL_H_ |
| OLD | NEW |