| 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_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 6 #define CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 15 #include "content/public/common/presentation_connection_message.h" | 15 #include "content/public/common/presentation_connection_message.h" |
| 16 #include "content/public/common/presentation_session.h" | 16 #include "content/public/common/presentation_info.h" |
| 17 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 17 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
| 18 | 18 |
| 19 class GURL; | 19 class GURL; |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 class PresentationScreenAvailabilityListener; | 23 class PresentationScreenAvailabilityListener; |
| 24 | 24 |
| 25 using PresentationSessionStartedCallback = | 25 using PresentationConnectionCallback = |
| 26 base::Callback<void(const PresentationSessionInfo&)>; | 26 base::Callback<void(const PresentationInfo&)>; |
| 27 using PresentationSessionErrorCallback = | 27 using PresentationConnectionErrorCallback = |
| 28 base::Callback<void(const PresentationError&)>; | 28 base::Callback<void(const PresentationError&)>; |
| 29 | 29 |
| 30 // Param: a vector of messages that are received. | 30 // Param: a vector of messages that are received. |
| 31 using PresentationConnectionMessageCallback = | 31 using PresentationConnectionMessageCallback = |
| 32 base::Callback<void(std::vector<content::PresentationConnectionMessage>)>; | 32 base::Callback<void(std::vector<content::PresentationConnectionMessage>)>; |
| 33 | 33 |
| 34 struct PresentationConnectionStateChangeInfo { | 34 struct PresentationConnectionStateChangeInfo { |
| 35 explicit PresentationConnectionStateChangeInfo( | 35 explicit PresentationConnectionStateChangeInfo( |
| 36 PresentationConnectionState state) | 36 PresentationConnectionState state) |
| 37 : state(state), | 37 : state(state), |
| 38 close_reason(PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR) {} | 38 close_reason(PRESENTATION_CONNECTION_CLOSE_REASON_CONNECTION_ERROR) {} |
| 39 ~PresentationConnectionStateChangeInfo() = default; | 39 ~PresentationConnectionStateChangeInfo() = default; |
| 40 | 40 |
| 41 PresentationConnectionState state; | 41 PresentationConnectionState state; |
| 42 | 42 |
| 43 // |close_reason| and |messsage| are only used for state change to CLOSED. | 43 // |close_reason| and |messsage| are only used for state change to CLOSED. |
| 44 PresentationConnectionCloseReason close_reason; | 44 PresentationConnectionCloseReason close_reason; |
| 45 std::string message; | 45 std::string message; |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 using PresentationConnectionStateChangedCallback = | 48 using PresentationConnectionStateChangedCallback = |
| 49 base::Callback<void(const PresentationConnectionStateChangeInfo&)>; | 49 base::Callback<void(const PresentationConnectionStateChangeInfo&)>; |
| 50 | 50 |
| 51 using PresentationConnectionPtr = blink::mojom::PresentationConnectionPtr; | 51 using PresentationConnectionPtr = blink::mojom::PresentationConnectionPtr; |
| 52 using PresentationConnectionRequest = | 52 using PresentationConnectionRequest = |
| 53 blink::mojom::PresentationConnectionRequest; | 53 blink::mojom::PresentationConnectionRequest; |
| 54 | 54 |
| 55 using ReceiverConnectionAvailableCallback = | 55 using ReceiverConnectionAvailableCallback = |
| 56 base::Callback<void(const content::PresentationSessionInfo&, | 56 base::Callback<void(const content::PresentationInfo&, |
| 57 PresentationConnectionPtr, | 57 PresentationConnectionPtr, |
| 58 PresentationConnectionRequest)>; | 58 PresentationConnectionRequest)>; |
| 59 | 59 |
| 60 // Base class for ControllerPresentationServiceDelegate and | 60 // Base class for ControllerPresentationServiceDelegate and |
| 61 // ReceiverPresentationServiceDelegate. | 61 // ReceiverPresentationServiceDelegate. |
| 62 class CONTENT_EXPORT PresentationServiceDelegate { | 62 class CONTENT_EXPORT PresentationServiceDelegate { |
| 63 public: | 63 public: |
| 64 // Observer interface to listen for changes to PresentationServiceDelegate. | 64 // Observer interface to listen for changes to PresentationServiceDelegate. |
| 65 class CONTENT_EXPORT Observer { | 65 class CONTENT_EXPORT Observer { |
| 66 public: | 66 public: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // |render_process_id| and |render_frame_id| from this class. The listener | 117 // |render_process_id| and |render_frame_id| from this class. The listener |
| 118 // will no longer receive availability updates. | 118 // will no longer receive availability updates. |
| 119 virtual void RemoveScreenAvailabilityListener( | 119 virtual void RemoveScreenAvailabilityListener( |
| 120 int render_process_id, | 120 int render_process_id, |
| 121 int render_frame_id, | 121 int render_frame_id, |
| 122 PresentationScreenAvailabilityListener* listener) = 0; | 122 PresentationScreenAvailabilityListener* listener) = 0; |
| 123 | 123 |
| 124 // Sets the default presentation URLs for frame given by |render_process_id| | 124 // Sets the default presentation URLs for frame given by |render_process_id| |
| 125 // and |render_frame_id|. When the default presentation is started on this | 125 // and |render_frame_id|. When the default presentation is started on this |
| 126 // frame, |callback| will be invoked with the corresponding | 126 // frame, |callback| will be invoked with the corresponding |
| 127 // PresentationSessionInfo object. | 127 // PresentationInfo object. |
| 128 // If |default_presentation_urls| is empty, the default presentation URLs will | 128 // If |default_presentation_urls| is empty, the default presentation URLs will |
| 129 // be cleared and the previously registered callback (if any) will be removed. | 129 // be cleared and the previously registered callback (if any) will be removed. |
| 130 virtual void SetDefaultPresentationUrls( | 130 virtual void SetDefaultPresentationUrls( |
| 131 int render_process_id, | 131 int render_process_id, |
| 132 int render_frame_id, | 132 int render_frame_id, |
| 133 const std::vector<GURL>& default_presentation_urls, | 133 const std::vector<GURL>& default_presentation_urls, |
| 134 const PresentationSessionStartedCallback& callback) = 0; | 134 const PresentationConnectionCallback& callback) = 0; |
| 135 | 135 |
| 136 // Starts a new presentation session. The presentation id of the session will | 136 // Starts a new presentation. The presentation id of the presentation will |
| 137 // be the default presentation ID if any or a generated one otherwise. | 137 // be the default presentation ID if any or a generated one otherwise. |
| 138 // Typically, the embedder will allow the user to select a screen to show | 138 // Typically, the embedder will allow the user to select a screen to show |
| 139 // one of the |presentation_urls|. | 139 // one of the |presentation_urls|. |
| 140 // |render_process_id|, |render_frame_id|: ID of originating frame. | 140 // |render_process_id|, |render_frame_id|: ID of originating frame. |
| 141 // |presentation_urls|: Possible URLs for the presentation. | 141 // |presentation_urls|: Possible URLs for the presentation. |
| 142 // |success_cb|: Invoked with session info, if presentation session started | 142 // |success_cb|: Invoked with presentation info, if presentation started |
| 143 // successfully. | 143 // successfully. |
| 144 // |error_cb|: Invoked with error reason, if presentation session did not | 144 // |error_cb|: Invoked with error reason, if presentation did not |
| 145 // start. | 145 // start. |
| 146 virtual void StartSession( | 146 virtual void StartPresentation( |
| 147 int render_process_id, | 147 int render_process_id, |
| 148 int render_frame_id, | 148 int render_frame_id, |
| 149 const std::vector<GURL>& presentation_urls, | 149 const std::vector<GURL>& presentation_urls, |
| 150 const PresentationSessionStartedCallback& success_cb, | 150 const PresentationConnectionCallback& success_cb, |
| 151 const PresentationSessionErrorCallback& error_cb) = 0; | 151 const PresentationConnectionErrorCallback& error_cb) = 0; |
| 152 | 152 |
| 153 // Joins an existing presentation session. Unlike StartSession(), this | 153 // Reconnects to an existing presentation. Unlike StartPresentation(), this |
| 154 // does not bring a screen list UI. | 154 // does not bring a screen list UI. |
| 155 // |render_process_id|, |render_frame_id|: ID for originating frame. | 155 // |render_process_id|, |render_frame_id|: ID for originating frame. |
| 156 // |presentation_urls|: Possible URLs of the presentation. | 156 // |presentation_urls|: Possible URLs of the presentation. |
| 157 // |presentation_id|: The ID of the presentation to join. | 157 // |presentation_id|: The ID of the presentation to reconnect. |
| 158 // |success_cb|: Invoked with session info, if presentation session joined | 158 // |success_cb|: Invoked with presentation info, if presentation reconnected |
| 159 // successfully. | 159 // successfully. |
| 160 // |error_cb|: Invoked with error reason, if joining failed. | 160 // |error_cb|: Invoked with error reason, if reconnection failed. |
| 161 virtual void JoinSession( | 161 virtual void ReconnectPresentation( |
| 162 int render_process_id, | 162 int render_process_id, |
| 163 int render_frame_id, | 163 int render_frame_id, |
| 164 const std::vector<GURL>& presentation_urls, | 164 const std::vector<GURL>& presentation_urls, |
| 165 const std::string& presentation_id, | 165 const std::string& presentation_id, |
| 166 const PresentationSessionStartedCallback& success_cb, | 166 const PresentationConnectionCallback& success_cb, |
| 167 const PresentationSessionErrorCallback& error_cb) = 0; | 167 const PresentationConnectionErrorCallback& error_cb) = 0; |
| 168 | 168 |
| 169 // Closes an existing presentation connection. | 169 // Closes an existing presentation connection. |
| 170 // |render_process_id|, |render_frame_id|: ID for originating frame. | 170 // |render_process_id|, |render_frame_id|: ID for originating frame. |
| 171 // |presentation_id|: The ID of the presentation to close. | 171 // |presentation_id|: The ID of the presentation to close. |
| 172 virtual void CloseConnection(int render_process_id, | 172 virtual void CloseConnection(int render_process_id, |
| 173 int render_frame_id, | 173 int render_frame_id, |
| 174 const std::string& presentation_id) = 0; | 174 const std::string& presentation_id) = 0; |
| 175 | 175 |
| 176 // Terminates an existing presentation. | 176 // Terminates an existing presentation. |
| 177 // |render_process_id|, |render_frame_id|: ID for originating frame. | 177 // |render_process_id|, |render_frame_id|: ID for originating frame. |
| 178 // |presentation_id|: The ID of the presentation to terminate. | 178 // |presentation_id|: The ID of the presentation to terminate. |
| 179 virtual void Terminate(int render_process_id, | 179 virtual void Terminate(int render_process_id, |
| 180 int render_frame_id, | 180 int render_frame_id, |
| 181 const std::string& presentation_id) = 0; | 181 const std::string& presentation_id) = 0; |
| 182 | 182 |
| 183 // Listens for messages for a presentation session. | 183 // Listens for messages from a presentation. |
| 184 // |render_process_id|, |render_frame_id|: ID for originating frame. | 184 // |render_process_id|, |render_frame_id|: ID for originating frame. |
| 185 // |session|: URL and ID of presentation session to listen for messages. | 185 // |presentation_info|: URL and ID of presentation to listen for messages. |
| 186 // |message_cb|: Invoked with a non-empty list of messages whenever there are | 186 // |message_cb|: Invoked with a non-empty list of messages whenever there are |
| 187 // messages. | 187 // messages. |
| 188 virtual void ListenForConnectionMessages( | 188 virtual void ListenForConnectionMessages( |
| 189 int render_process_id, | 189 int render_process_id, |
| 190 int render_frame_id, | 190 int render_frame_id, |
| 191 const content::PresentationSessionInfo& session, | 191 const content::PresentationInfo& presentation_info, |
| 192 const PresentationConnectionMessageCallback& message_cb) = 0; | 192 const PresentationConnectionMessageCallback& message_cb) = 0; |
| 193 | 193 |
| 194 // Sends a message (string or binary data) to a presentation session. | 194 // Sends a message (string or binary data) to a presentation. |
| 195 // |render_process_id|, |render_frame_id|: ID of originating frame. | 195 // |render_process_id|, |render_frame_id|: ID of originating frame. |
| 196 // |session|: The presentation session to send the message to. | 196 // |presentation_info|: The presentation to send the message to. |
| 197 // |message|: The message to send. The embedder takes ownership of |message|. | 197 // |message|: The message to send. The embedder takes ownership of |message|. |
| 198 // Must not be null. | 198 // Must not be null. |
| 199 // |send_message_cb|: Invoked after handling the send message request. | 199 // |send_message_cb|: Invoked after handling the send message request. |
| 200 virtual void SendMessage(int render_process_id, | 200 virtual void SendMessage(int render_process_id, |
| 201 int render_frame_id, | 201 int render_frame_id, |
| 202 const content::PresentationSessionInfo& session, | 202 const content::PresentationInfo& presentation_info, |
| 203 PresentationConnectionMessage message, | 203 PresentationConnectionMessage message, |
| 204 const SendMessageCallback& send_message_cb) = 0; | 204 const SendMessageCallback& send_message_cb) = 0; |
| 205 | 205 |
| 206 // Continuously listen for state changes for a PresentationConnection in a | 206 // Continuously listen for state changes for a PresentationConnection in a |
| 207 // frame. | 207 // frame. |
| 208 // |render_process_id|, |render_frame_id|: ID of frame. | 208 // |render_process_id|, |render_frame_id|: ID of frame. |
| 209 // |connection|: PresentationConnection to listen for state changes. | 209 // |connection|: PresentationConnection to listen for state changes. |
| 210 // |state_changed_cb|: Invoked with the PresentationConnection and its new | 210 // |state_changed_cb|: Invoked with the PresentationConnection and its new |
| 211 // state whenever there is a state change. | 211 // state whenever there is a state change. |
| 212 virtual void ListenForConnectionStateChange( | 212 virtual void ListenForConnectionStateChange( |
| 213 int render_process_id, | 213 int render_process_id, |
| 214 int render_frame_id, | 214 int render_frame_id, |
| 215 const PresentationSessionInfo& connection, | 215 const PresentationInfo& connection, |
| 216 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; | 216 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; |
| 217 | 217 |
| 218 // Connect |controller_connection| owned by the controlling frame to the | 218 // Connect |controller_connection| owned by the controlling frame to the |
| 219 // offscreen presentation represented by |session|. | 219 // offscreen presentation represented by |presentation_info|. |
| 220 // |render_process_id|, |render_frame_id|: ID of originating frame. | 220 // |render_process_id|, |render_frame_id|: ID of originating frame. |
| 221 // |controller_connection|: Pointer to controller's presentation connection, | 221 // |controller_connection|: Pointer to controller's presentation connection, |
| 222 // ownership passed from controlling frame to the offscreen presentation. | 222 // ownership passed from controlling frame to the offscreen presentation. |
| 223 // |receiver_connection_request|: Mojo InterfaceRequest to be bind to receiver | 223 // |receiver_connection_request|: Mojo InterfaceRequest to be bind to receiver |
| 224 // page's presentation connection. | 224 // page's presentation connection. |
| 225 virtual void ConnectToPresentation( | 225 virtual void ConnectToPresentation( |
| 226 int render_process_id, | 226 int render_process_id, |
| 227 int render_frame_id, | 227 int render_frame_id, |
| 228 const PresentationSessionInfo& session, | 228 const PresentationInfo& presentation_info, |
| 229 PresentationConnectionPtr controller_connection_ptr, | 229 PresentationConnectionPtr controller_connection_ptr, |
| 230 PresentationConnectionRequest receiver_connection_request) = 0; | 230 PresentationConnectionRequest receiver_connection_request) = 0; |
| 231 }; | 231 }; |
| 232 | 232 |
| 233 // An interface implemented by embedders to handle | 233 // An interface implemented by embedders to handle |
| 234 // PresentationService calls from a presentation receiver. | 234 // PresentationService calls from a presentation receiver. |
| 235 class CONTENT_EXPORT ReceiverPresentationServiceDelegate | 235 class CONTENT_EXPORT ReceiverPresentationServiceDelegate |
| 236 : public PresentationServiceDelegate { | 236 : public PresentationServiceDelegate { |
| 237 public: | 237 public: |
| 238 // Registers a callback from the embedder when an offscreeen presentation has | 238 // Registers a callback from the embedder when an offscreeen presentation has |
| 239 // been successfully started. | 239 // been successfully started. |
| 240 // |receiver_available_callback|: Invoked when successfully starting a | 240 // |receiver_available_callback|: Invoked when successfully starting a |
| 241 // offscreen presentation session. | 241 // offscreen presentation. |
| 242 virtual void RegisterReceiverConnectionAvailableCallback( | 242 virtual void RegisterReceiverConnectionAvailableCallback( |
| 243 const content::ReceiverConnectionAvailableCallback& | 243 const content::ReceiverConnectionAvailableCallback& |
| 244 receiver_available_callback) = 0; | 244 receiver_available_callback) = 0; |
| 245 }; | 245 }; |
| 246 | 246 |
| 247 } // namespace content | 247 } // namespace content |
| 248 | 248 |
| 249 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 249 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
| OLD | NEW |