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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "content/common/content_export.h" | 14 #include "content/common/content_export.h" |
15 #include "content/public/browser/presentation_session.h" | 15 #include "content/public/browser/presentation_session.h" |
16 #include "content/public/browser/presentation_session_message.h" | 16 #include "content/public/browser/presentation_session_message.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 class PresentationScreenAvailabilityListener; | 20 class PresentationScreenAvailabilityListener; |
21 class PresentationSessionStateListener; | 21 class PresentationSessionStateListener; |
22 | 22 |
23 // Param #0: a vector of messages that are received. | 23 // Param #0: a vector of messages that are received. |
24 // Param #1: tells the callback handler that it may reuse strings or buffers | 24 // Param #1: tells the callback handler that it may reuse strings or buffers |
25 // in the messages contained within param #0. | 25 // in the messages contained within param #0. |
26 using PresentationSessionMessageCallback = base::Callback< | 26 using PresentationSessionMessageCallback = base::Callback< |
27 void(const ScopedVector<content::PresentationSessionMessage>&, bool)>; | 27 void(const ScopedVector<content::PresentationSessionMessage>&, bool)>; |
28 | 28 |
| 29 using PresentationReceiverSessionAvailableCallback = |
| 30 base::Callback<void(const content::PresentationSessionInfo*)>; |
| 31 |
| 32 using SendMessageCallback = base::Callback<void(bool)>; |
| 33 |
29 // An interface implemented by embedders to handle presentation API calls | 34 // An interface implemented by embedders to handle presentation API calls |
30 // forwarded from PresentationServiceImpl. | 35 // forwarded from PresentationServiceImpl. |
31 class CONTENT_EXPORT PresentationServiceDelegate { | 36 class CONTENT_EXPORT PresentationServiceDelegate { |
32 public: | 37 public: |
33 // Observer interface to listen for changes to PresentationServiceDelegate. | 38 // Observer interface to listen for changes to PresentationServiceDelegate. |
34 class CONTENT_EXPORT Observer { | 39 class CONTENT_EXPORT Observer { |
35 public: | 40 public: |
36 // Called when the PresentationServiceDelegate is being destroyed. | 41 // Called when the PresentationServiceDelegate is being destroyed. |
37 virtual void OnDelegateDestroyed() = 0; | 42 virtual void OnDelegateDestroyed() = 0; |
38 | 43 |
39 // Called when the default presentation has been started outside of a | 44 // Called when the default presentation has been started outside of a |
40 // Presentation API context (e.g., browser action). This will not be called | 45 // Presentation API context (e.g., browser action). This will not be called |
41 // if the session was created as a result of Presentation API's | 46 // if the session was created as a result of Presentation API's |
42 // StartSession()/JoinSession(). | 47 // StartSession()/JoinSession(). |
43 virtual void OnDefaultPresentationStarted( | 48 virtual void OnDefaultPresentationStarted( |
44 const PresentationSessionInfo& session) = 0; | 49 const PresentationSessionInfo& session) = 0; |
45 | 50 |
46 protected: | 51 protected: |
47 virtual ~Observer() {} | 52 virtual ~Observer() {} |
48 }; | 53 }; |
49 | 54 |
50 using PresentationSessionSuccessCallback = | 55 using PresentationSessionStartedCallback = |
51 base::Callback<void(const PresentationSessionInfo&)>; | 56 base::Callback<void(const PresentationSessionInfo&)>; |
52 using PresentationSessionErrorCallback = | 57 using PresentationSessionErrorCallback = |
53 base::Callback<void(const PresentationError&)>; | 58 base::Callback<void(const PresentationError&)>; |
54 using SendMessageCallback = base::Callback<void(bool)>; | |
55 | 59 |
56 virtual ~PresentationServiceDelegate() {} | 60 virtual ~PresentationServiceDelegate() {} |
57 | 61 |
58 // Registers an observer associated with frame with |render_process_id| | 62 // Registers an observer associated with frame with |render_process_id| |
59 // and |render_frame_id| with this class to listen for updates. | 63 // and |render_frame_id| with this class to listen for updates. |
60 // This class does not own the observer. | 64 // This class does not own the observer. |
61 // It is an error to add an observer if there is already an observer for that | 65 // It is an error to add an observer if there is already an observer for that |
62 // frame. | 66 // frame. |
63 virtual void AddObserver(int render_process_id, | 67 virtual void AddObserver(int render_process_id, |
64 int render_frame_id, | 68 int render_frame_id, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 int render_process_id, | 101 int render_process_id, |
98 int render_frame_id) = 0; | 102 int render_frame_id) = 0; |
99 | 103 |
100 // Sets the default presentation URL for frame given by |render_process_id| | 104 // Sets the default presentation URL for frame given by |render_process_id| |
101 // and |render_frame_id|. | 105 // and |render_frame_id|. |
102 // If |default_presentation_url| is empty, the default presentation URL will | 106 // If |default_presentation_url| is empty, the default presentation URL will |
103 // be cleared. | 107 // be cleared. |
104 virtual void SetDefaultPresentationUrl( | 108 virtual void SetDefaultPresentationUrl( |
105 int render_process_id, | 109 int render_process_id, |
106 int render_frame_id, | 110 int render_frame_id, |
107 const std::string& default_presentation_url) = 0; | 111 const std::string& default_presentation_url, |
| 112 const PresentationSessionStartedCallback& callback) = 0; |
108 | 113 |
109 // Starts a new presentation session. The presentation id of the session will | 114 // Starts a new presentation session. The presentation id of the session will |
110 // be the default presentation ID if any or a generated one otherwise. | 115 // be the default presentation ID if any or a generated one otherwise. |
111 // Typically, the embedder will allow the user to select a screen to show | 116 // Typically, the embedder will allow the user to select a screen to show |
112 // |presentation_url|. | 117 // |presentation_url|. |
113 // |render_process_id|, |render_frame_id|: ID of originating frame. | 118 // |render_process_id|, |render_frame_id|: ID of originating frame. |
114 // |presentation_url|: URL of the presentation. | 119 // |presentation_url|: URL of the presentation. |
115 // |success_cb|: Invoked with session info, if presentation session started | 120 // |success_cb|: Invoked with session info, if presentation session started |
116 // successfully. | 121 // successfully. |
117 // |error_cb|: Invoked with error reason, if presentation session did not | 122 // |error_cb|: Invoked with error reason, if presentation session did not |
118 // start. | 123 // start. |
119 virtual void StartSession( | 124 virtual void StartSession( |
120 int render_process_id, | 125 int render_process_id, |
121 int render_frame_id, | 126 int render_frame_id, |
122 const std::string& presentation_url, | 127 const std::string& presentation_url, |
123 const PresentationSessionSuccessCallback& success_cb, | 128 const PresentationSessionStartedCallback& success_cb, |
124 const PresentationSessionErrorCallback& error_cb) = 0; | 129 const PresentationSessionErrorCallback& error_cb) = 0; |
125 | 130 |
126 // Joins an existing presentation session. Unlike StartSession(), this | 131 // Joins an existing presentation session. Unlike StartSession(), this |
127 // does not bring a screen list UI. | 132 // does not bring a screen list UI. |
128 // |render_process_id|, |render_frame_id|: ID for originating frame. | 133 // |render_process_id|, |render_frame_id|: ID for originating frame. |
129 // |presentation_url|: URL of the presentation. | 134 // |presentation_url|: URL of the presentation. |
130 // |presentation_id|: The ID of the presentation to join. | 135 // |presentation_id|: The ID of the presentation to join. |
131 // |success_cb|: Invoked with session info, if presentation session joined | 136 // |success_cb|: Invoked with session info, if presentation session joined |
132 // successfully. | 137 // successfully. |
133 // |error_cb|: Invoked with error reason, if joining failed. | 138 // |error_cb|: Invoked with error reason, if joining failed. |
134 virtual void JoinSession( | 139 virtual void JoinSession( |
135 int render_process_id, | 140 int render_process_id, |
136 int render_frame_id, | 141 int render_frame_id, |
137 const std::string& presentation_url, | 142 const std::string& presentation_url, |
138 const std::string& presentation_id, | 143 const std::string& presentation_id, |
139 const PresentationSessionSuccessCallback& success_cb, | 144 const PresentationSessionStartedCallback& success_cb, |
140 const PresentationSessionErrorCallback& error_cb) = 0; | 145 const PresentationSessionErrorCallback& error_cb) = 0; |
141 | 146 |
142 // Close an existing presentation session. | 147 // Close an existing presentation session. |
143 // |render_process_id|, |render_frame_id|: ID for originating frame. | 148 // |render_process_id|, |render_frame_id|: ID for originating frame. |
144 // |presentation_id|: The ID of the presentation to close. | 149 // |presentation_id|: The ID of the presentation to close. |
145 virtual void CloseSession(int render_process_id, | 150 virtual void CloseSession(int render_process_id, |
146 int render_frame_id, | 151 int render_frame_id, |
147 const std::string& presentation_id) = 0; | 152 const std::string& presentation_id) = 0; |
148 | 153 |
149 // Listen for messages for a presentation session. | 154 // Listen for messages for a presentation session. |
(...skipping 22 matching lines...) Expand all Loading... |
172 // Continuously listen for presentation session state changes for a session. | 177 // Continuously listen for presentation session state changes for a session. |
173 // Returns true if |listener| is sucessfully registered. | 178 // Returns true if |listener| is sucessfully registered. |
174 // |render_process_id|, |render_frame_id|: ID of frame. | 179 // |render_process_id|, |render_frame_id|: ID of frame. |
175 // |session|: Presentation session to listen for state changes. | 180 // |session|: Presentation session to listen for state changes. |
176 // |listener|: The listener to be invoked whenever there is a state change. | 181 // |listener|: The listener to be invoked whenever there is a state change. |
177 // Not owned by this class. | 182 // Not owned by this class. |
178 virtual bool ListenForSessionStateChange( | 183 virtual bool ListenForSessionStateChange( |
179 int render_process_id, | 184 int render_process_id, |
180 int render_frame_id, | 185 int render_frame_id, |
181 content::PresentationSessionStateListener* listener) = 0; | 186 content::PresentationSessionStateListener* listener) = 0; |
| 187 |
| 188 // Gets a presentation session for the offscreen presentation hosted on the |
| 189 // offscreen tab containing this frame, or waits until one is available. |
| 190 // Runs |callback| once the receiver becomes available. |callback| will be |
| 191 // run during this method call if the receiver is already available, or at |
| 192 // some later time when a receiver presentation session becomes available. |
| 193 // It is possible that |callback| will never be run if a receiver never |
| 194 // becomes available. |
| 195 // If |render_process_id| and |render_frame_id| do not refer to the main |
| 196 // render frame of this WebContents, |callback| will be immediately invoked |
| 197 // with null. |
| 198 virtual void NotifyWhenReceiverSessionIsAvailable( |
| 199 int render_process_id, |
| 200 int render_frame_id, |
| 201 const PresentationReceiverSessionAvailableCallback& callback) = 0; |
182 }; | 202 }; |
183 | 203 |
184 } // namespace content | 204 } // namespace content |
185 | 205 |
186 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ | 206 #endif // CONTENT_PUBLIC_BROWSER_PRESENTATION_SERVICE_DELEGATE_H_ |
OLD | NEW |