| 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 <memory> | 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/callback.h" | 13 #include "base/callback.h" |
| 13 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
| 14 #include "content/public/common/presentation_connection_message.h" | 15 #include "content/public/common/presentation_connection_message.h" |
| 15 #include "content/public/common/presentation_session.h" | 16 #include "content/public/common/presentation_session.h" |
| 17 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
| 16 | 18 |
| 17 class GURL; | 19 class GURL; |
| 18 | 20 |
| 19 namespace content { | 21 namespace content { |
| 20 | 22 |
| 21 class PresentationScreenAvailabilityListener; | 23 class PresentationScreenAvailabilityListener; |
| 22 | 24 |
| 23 using PresentationSessionStartedCallback = | 25 using PresentationSessionStartedCallback = |
| 24 base::Callback<void(const PresentationSessionInfo&)>; | 26 base::Callback<void(const PresentationSessionInfo&)>; |
| 25 using PresentationSessionErrorCallback = | 27 using PresentationSessionErrorCallback = |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 PresentationConnectionState state; | 44 PresentationConnectionState state; |
| 43 | 45 |
| 44 // |close_reason| and |messsage| are only used for state change to CLOSED. | 46 // |close_reason| and |messsage| are only used for state change to CLOSED. |
| 45 PresentationConnectionCloseReason close_reason; | 47 PresentationConnectionCloseReason close_reason; |
| 46 std::string message; | 48 std::string message; |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 using PresentationConnectionStateChangedCallback = | 51 using PresentationConnectionStateChangedCallback = |
| 50 base::Callback<void(const PresentationConnectionStateChangeInfo&)>; | 52 base::Callback<void(const PresentationConnectionStateChangeInfo&)>; |
| 51 | 53 |
| 52 // An interface implemented by embedders to handle presentation API calls | 54 using PresentationConnectionPtr = blink::mojom::PresentationConnectionPtr; |
| 53 // forwarded from PresentationServiceImpl. | 55 using PresentationConnectionRequest = |
| 56 blink::mojom::PresentationConnectionRequest; |
| 57 |
| 58 using ReceiverConnectionAvailableCallback = |
| 59 base::Callback<void(const content::PresentationSessionInfo&, |
| 60 PresentationConnectionPtr, |
| 61 PresentationConnectionRequest)>; |
| 62 |
| 63 // Base class for ControllerPresentationServiceDelegate and |
| 64 // ReceiverPresentationServiceDelegate. |
| 54 class CONTENT_EXPORT PresentationServiceDelegate { | 65 class CONTENT_EXPORT PresentationServiceDelegate { |
| 55 public: | 66 public: |
| 56 // Observer interface to listen for changes to PresentationServiceDelegate. | 67 // Observer interface to listen for changes to PresentationServiceDelegate. |
| 57 class CONTENT_EXPORT Observer { | 68 class CONTENT_EXPORT Observer { |
| 58 public: | 69 public: |
| 59 // Called when the PresentationServiceDelegate is being destroyed. | 70 // Called when the PresentationServiceDelegate is being destroyed. |
| 60 virtual void OnDelegateDestroyed() = 0; | 71 virtual void OnDelegateDestroyed() = 0; |
| 61 | 72 |
| 62 protected: | 73 protected: |
| 63 virtual ~Observer() {} | 74 virtual ~Observer() {} |
| 64 }; | 75 }; |
| 65 | 76 |
| 66 using SendMessageCallback = base::Callback<void(bool)>; | |
| 67 | |
| 68 virtual ~PresentationServiceDelegate() {} | 77 virtual ~PresentationServiceDelegate() {} |
| 69 | 78 |
| 70 // Registers an observer associated with frame with |render_process_id| | 79 // Registers an observer associated with frame with |render_process_id| |
| 71 // and |render_frame_id| with this class to listen for updates. | 80 // and |render_frame_id| with this class to listen for updates. |
| 72 // This class does not own the observer. | 81 // This class does not own the observer. |
| 73 // It is an error to add an observer if there is already an observer for that | 82 // It is an error to add an observer if there is already an observer for that |
| 74 // frame. | 83 // frame. |
| 75 virtual void AddObserver(int render_process_id, | 84 virtual void AddObserver(int render_process_id, |
| 76 int render_frame_id, | 85 int render_frame_id, |
| 77 Observer* observer) = 0; | 86 Observer* observer) = 0; |
| 78 | 87 |
| 79 // Unregisters the observer associated with the frame with |render_process_id| | 88 // Unregisters the observer associated with the frame with |render_process_id| |
| 80 // and |render_frame_id|. | 89 // and |render_frame_id|. |
| 81 // The observer will no longer receive updates. | 90 // The observer will no longer receive updates. |
| 82 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0; | 91 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0; |
| 83 | 92 |
| 93 // Resets the presentation state for the frame given by |render_process_id| |
| 94 // and |render_frame_id|. |
| 95 // This unregisters all screen availability associated with the given frame, |
| 96 // and clears the default presentation URL for the frame. |
| 97 virtual void Reset(int render_process_id, int render_frame_id) = 0; |
| 98 }; |
| 99 |
| 100 // An interface implemented by embedders to handle Presentation API calls |
| 101 // forwarded from PresentationServiceImpl. |
| 102 class CONTENT_EXPORT ControllerPresentationServiceDelegate |
| 103 : public PresentationServiceDelegate { |
| 104 public: |
| 105 using SendMessageCallback = base::Callback<void(bool)>; |
| 106 |
| 84 // Registers |listener| to continuously listen for | 107 // Registers |listener| to continuously listen for |
| 85 // availability updates for a presentation URL, originated from the frame | 108 // availability updates for a presentation URL, originated from the frame |
| 86 // given by |render_process_id| and |render_frame_id|. | 109 // given by |render_process_id| and |render_frame_id|. |
| 87 // This class does not own |listener|. | 110 // This class does not own |listener|. |
| 88 // Returns true on success. | 111 // Returns true on success. |
| 89 // This call will return false if a listener with the same presentation URL | 112 // This call will return false if a listener with the same presentation URL |
| 90 // from the same frame is already registered. | 113 // from the same frame is already registered. |
| 91 virtual bool AddScreenAvailabilityListener( | 114 virtual bool AddScreenAvailabilityListener( |
| 92 int render_process_id, | 115 int render_process_id, |
| 93 int render_frame_id, | 116 int render_frame_id, |
| 94 PresentationScreenAvailabilityListener* listener) = 0; | 117 PresentationScreenAvailabilityListener* listener) = 0; |
| 95 | 118 |
| 96 // Unregisters |listener| originated from the frame given by | 119 // Unregisters |listener| originated from the frame given by |
| 97 // |render_process_id| and |render_frame_id| from this class. The listener | 120 // |render_process_id| and |render_frame_id| from this class. The listener |
| 98 // will no longer receive availability updates. | 121 // will no longer receive availability updates. |
| 99 virtual void RemoveScreenAvailabilityListener( | 122 virtual void RemoveScreenAvailabilityListener( |
| 100 int render_process_id, | 123 int render_process_id, |
| 101 int render_frame_id, | 124 int render_frame_id, |
| 102 PresentationScreenAvailabilityListener* listener) = 0; | 125 PresentationScreenAvailabilityListener* listener) = 0; |
| 103 | 126 |
| 104 // Resets the presentation state for the frame given by |render_process_id| | |
| 105 // and |render_frame_id|. | |
| 106 // This unregisters all listeners associated with the given frame, and clears | |
| 107 // the default presentation URL and ID set for the frame. | |
| 108 virtual void Reset( | |
| 109 int render_process_id, | |
| 110 int render_frame_id) = 0; | |
| 111 | |
| 112 // Sets the default presentation URLs for frame given by |render_process_id| | 127 // Sets the default presentation URLs for frame given by |render_process_id| |
| 113 // and |render_frame_id|. When the default presentation is started on this | 128 // and |render_frame_id|. When the default presentation is started on this |
| 114 // frame, |callback| will be invoked with the corresponding | 129 // frame, |callback| will be invoked with the corresponding |
| 115 // PresentationSessionInfo object. | 130 // PresentationSessionInfo object. |
| 116 // If |default_presentation_urls| is empty, the default presentation URLs will | 131 // If |default_presentation_urls| is empty, the default presentation URLs will |
| 117 // be cleared and the previously registered callback (if any) will be removed. | 132 // be cleared and the previously registered callback (if any) will be removed. |
| 118 virtual void SetDefaultPresentationUrls( | 133 virtual void SetDefaultPresentationUrls( |
| 119 int render_process_id, | 134 int render_process_id, |
| 120 int render_frame_id, | 135 int render_frame_id, |
| 121 const std::vector<GURL>& default_presentation_urls, | 136 const std::vector<GURL>& default_presentation_urls, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 // frame. | 211 // frame. |
| 197 // |render_process_id|, |render_frame_id|: ID of frame. | 212 // |render_process_id|, |render_frame_id|: ID of frame. |
| 198 // |connection|: PresentationConnection to listen for state changes. | 213 // |connection|: PresentationConnection to listen for state changes. |
| 199 // |state_changed_cb|: Invoked with the PresentationConnection and its new | 214 // |state_changed_cb|: Invoked with the PresentationConnection and its new |
| 200 // state whenever there is a state change. | 215 // state whenever there is a state change. |
| 201 virtual void ListenForConnectionStateChange( | 216 virtual void ListenForConnectionStateChange( |
| 202 int render_process_id, | 217 int render_process_id, |
| 203 int render_frame_id, | 218 int render_frame_id, |
| 204 const PresentationSessionInfo& connection, | 219 const PresentationSessionInfo& connection, |
| 205 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; | 220 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; |
| 221 |
| 222 // Connect |controller_connection| owned by the controlling frame to the |
| 223 // offscreen presentation represented by |session|. |
| 224 // |render_process_id|, |render_frame_id|: ID of originating frame. |
| 225 // |controller_connection|: Pointer to controller's presentation connection, |
| 226 // ownership passed from controlling frame to the offscreen presentation. |
| 227 // |receiver_connection_request|: Mojo InterfaceRequest to be bind to receiver |
| 228 // page's presentation connection. |
| 229 virtual void ConnectToOffscreenPresentation( |
| 230 int render_process_id, |
| 231 int render_frame_id, |
| 232 const PresentationSessionInfo& session, |
| 233 PresentationConnectionPtr controller_connection_ptr, |
| 234 PresentationConnectionRequest receiver_connection_request) = 0; |
| 235 }; |
| 236 |
| 237 // An interface implemented by embedders to handle |
| 238 // PresentationService calls from a presentation receiver. |
| 239 class CONTENT_EXPORT ReceiverPresentationServiceDelegate |
| 240 : public PresentationServiceDelegate { |
| 241 public: |
| 242 // Registers a callback from the embedder when an offscreeen presentation has |
| 243 // been successfully started. |
| 244 // |receiver_available_callback|: Invoked when successfully starting a |
| 245 // offscreen presentation session. |
| 246 virtual void RegisterReceiverConnectionAvailableCallback( |
| 247 const content::ReceiverConnectionAvailableCallback& |
| 248 receiver_available_callback) = 0; |
| 206 }; | 249 }; |
| 207 | 250 |
| 208 } // namespace content | 251 } // namespace content |
| 209 | 252 |
| 210 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 253 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
| OLD | NEW |