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 "base/memory/scoped_vector.h" | 14 #include "base/memory/scoped_vector.h" |
14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
15 #include "content/public/browser/presentation_session.h" | 16 #include "content/public/browser/presentation_session.h" |
16 #include "content/public/browser/presentation_session_message.h" | 17 #include "content/public/browser/presentation_session_message.h" |
18 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h" | |
17 | 19 |
18 class GURL; | 20 class GURL; |
19 | 21 |
20 namespace content { | 22 namespace content { |
21 | 23 |
22 class PresentationScreenAvailabilityListener; | 24 class PresentationScreenAvailabilityListener; |
23 | 25 |
24 using PresentationSessionStartedCallback = | 26 using PresentationSessionStartedCallback = |
25 base::Callback<void(const PresentationSessionInfo&)>; | 27 base::Callback<void(const PresentationSessionInfo&)>; |
26 using PresentationSessionErrorCallback = | 28 using PresentationSessionErrorCallback = |
(...skipping 15 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 |
56 using ReceiverConnectionAvailableCallback = | |
57 base::Callback<void(const content::PresentationSessionInfo&, | |
58 PresentationConnectionPtr)>; | |
59 | |
60 // Base class for ControllerPresentationServiceDelegate and | |
61 // ReceiverPresentationServiceDelegate. | |
54 class CONTENT_EXPORT PresentationServiceDelegate { | 62 class CONTENT_EXPORT PresentationServiceDelegate { |
55 public: | 63 public: |
56 // Observer interface to listen for changes to PresentationServiceDelegate. | 64 // Observer interface to listen for changes to PresentationServiceDelegate. |
57 class CONTENT_EXPORT Observer { | 65 class Observer { |
58 public: | 66 public: |
59 // Called when the PresentationServiceDelegate is being destroyed. | 67 // Called when the PresentationServiceDelegate is being destroyed. |
60 virtual void OnDelegateDestroyed() = 0; | 68 virtual void OnDelegateDestroyed() = 0; |
61 | 69 |
62 protected: | 70 protected: |
63 virtual ~Observer() {} | 71 virtual ~Observer() {} |
64 }; | 72 }; |
65 | 73 |
66 using SendMessageCallback = base::Callback<void(bool)>; | 74 PresentationServiceDelegate(); |
67 | 75 virtual ~PresentationServiceDelegate(); |
68 virtual ~PresentationServiceDelegate() {} | |
69 | 76 |
70 // Registers an observer associated with frame with |render_process_id| | 77 // Registers an observer associated with frame with |render_process_id| |
71 // and |render_frame_id| with this class to listen for updates. | 78 // and |render_frame_id| with this class to listen for updates. |
72 // This class does not own the observer. | 79 // This class does not own the observer. |
73 // It is an error to add an observer if there is already an observer for that | 80 // It is an error to add an observer if there is already an observer for that |
74 // frame. | 81 // frame. |
75 virtual void AddObserver(int render_process_id, | 82 virtual void AddObserver(int render_process_id, |
76 int render_frame_id, | 83 int render_frame_id, |
77 Observer* observer) = 0; | 84 Observer* observer); |
78 | 85 |
79 // Unregisters the observer associated with the frame with |render_process_id| | 86 // Unregisters the observer associated with the frame with |render_process_id| |
80 // and |render_frame_id|. | 87 // and |render_frame_id|. |
81 // The observer will no longer receive updates. | 88 // The observer will no longer receive updates. |
82 virtual void RemoveObserver(int render_process_id, int render_frame_id) = 0; | 89 virtual void RemoveObserver(int render_process_id, int render_frame_id); |
90 | |
91 // Resets the presentation state for the frame given by |render_process_id| | |
92 // and |render_frame_id|. | |
93 // This unregisters all screen availability associated with the given frame, | |
94 // and clears the default presentation URL for the frame. | |
95 virtual void Reset(int render_process_id, int render_frame_id) = 0; | |
96 | |
97 private: | |
98 // Use as a key in the render frame map. Corresponds to a unique | |
99 // RenderFrameHost. | |
100 using RenderFrameHostID = std::pair<int, int>; | |
101 std::map<RenderFrameHostID, Observer*> observers_; | |
jam
2016/12/14 17:48:23
this is against the content api guidelines per htt
zhaobin
2016/12/15 02:55:59
Done.
| |
102 }; | |
103 | |
104 // An interface implemented by embedders to handle Presentation API calls | |
105 // forwarded from PresentationServiceImpl. | |
106 class CONTENT_EXPORT ControllerPresentationServiceDelegate | |
107 : public PresentationServiceDelegate { | |
108 public: | |
109 using SendMessageCallback = base::Callback<void(bool)>; | |
83 | 110 |
84 // Registers |listener| to continuously listen for | 111 // Registers |listener| to continuously listen for |
85 // availability updates for a presentation URL, originated from the frame | 112 // availability updates for a presentation URL, originated from the frame |
86 // given by |render_process_id| and |render_frame_id|. | 113 // given by |render_process_id| and |render_frame_id|. |
87 // This class does not own |listener|. | 114 // This class does not own |listener|. |
88 // Returns true on success. | 115 // Returns true on success. |
89 // This call will return false if a listener with the same presentation URL | 116 // This call will return false if a listener with the same presentation URL |
90 // from the same frame is already registered. | 117 // from the same frame is already registered. |
91 virtual bool AddScreenAvailabilityListener( | 118 virtual bool AddScreenAvailabilityListener( |
92 int render_process_id, | 119 int render_process_id, |
93 int render_frame_id, | 120 int render_frame_id, |
94 PresentationScreenAvailabilityListener* listener) = 0; | 121 PresentationScreenAvailabilityListener* listener) = 0; |
95 | 122 |
96 // Unregisters |listener| originated from the frame given by | 123 // Unregisters |listener| originated from the frame given by |
97 // |render_process_id| and |render_frame_id| from this class. The listener | 124 // |render_process_id| and |render_frame_id| from this class. The listener |
98 // will no longer receive availability updates. | 125 // will no longer receive availability updates. |
99 virtual void RemoveScreenAvailabilityListener( | 126 virtual void RemoveScreenAvailabilityListener( |
100 int render_process_id, | 127 int render_process_id, |
101 int render_frame_id, | 128 int render_frame_id, |
102 PresentationScreenAvailabilityListener* listener) = 0; | 129 PresentationScreenAvailabilityListener* listener) = 0; |
103 | 130 |
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| | 131 // 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 | 132 // and |render_frame_id|. When the default presentation is started on this |
114 // frame, |callback| will be invoked with the corresponding | 133 // frame, |callback| will be invoked with the corresponding |
115 // PresentationSessionInfo object. | 134 // PresentationSessionInfo object. |
116 // If |default_presentation_urls| is empty, the default presentation URLs will | 135 // If |default_presentation_urls| is empty, the default presentation URLs will |
117 // be cleared and the previously registered callback (if any) will be removed. | 136 // be cleared and the previously registered callback (if any) will be removed. |
118 virtual void SetDefaultPresentationUrls( | 137 virtual void SetDefaultPresentationUrls( |
119 int render_process_id, | 138 int render_process_id, |
120 int render_frame_id, | 139 int render_frame_id, |
121 const std::vector<GURL>& default_presentation_urls, | 140 const std::vector<GURL>& default_presentation_urls, |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
195 // frame. | 214 // frame. |
196 // |render_process_id|, |render_frame_id|: ID of frame. | 215 // |render_process_id|, |render_frame_id|: ID of frame. |
197 // |connection|: PresentationConnection to listen for state changes. | 216 // |connection|: PresentationConnection to listen for state changes. |
198 // |state_changed_cb|: Invoked with the PresentationConnection and its new | 217 // |state_changed_cb|: Invoked with the PresentationConnection and its new |
199 // state whenever there is a state change. | 218 // state whenever there is a state change. |
200 virtual void ListenForConnectionStateChange( | 219 virtual void ListenForConnectionStateChange( |
201 int render_process_id, | 220 int render_process_id, |
202 int render_frame_id, | 221 int render_frame_id, |
203 const PresentationSessionInfo& connection, | 222 const PresentationSessionInfo& connection, |
204 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; | 223 const PresentationConnectionStateChangedCallback& state_changed_cb) = 0; |
224 | |
225 // Connect |connection| owned by the controlling frame to the offscreen | |
226 // presentation represented by |session|. | |
227 // |render_process_id|, |render_frame_id|: ID of originating frame. | |
228 // |connection|: Pointer to controller's presentation connection, | |
229 // ownership passed from controlling frame to the offscreen presentation. | |
230 virtual void ConnectToOffscreenPresentation( | |
231 int render_process_id, | |
232 int render_frame_id, | |
233 const PresentationSessionInfo& session, | |
234 PresentationConnectionPtr connection) = 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; | |
205 }; | 249 }; |
206 | 250 |
207 } // namespace content | 251 } // namespace content |
208 | 252 |
209 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 253 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
OLD | NEW |