Chromium Code Reviews| 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_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 class CONTENT_EXPORT PresentationDispatcher | 43 class CONTENT_EXPORT PresentationDispatcher |
| 44 : public RenderFrameObserver, | 44 : public RenderFrameObserver, |
| 45 public NON_EXPORTED_BASE(blink::WebPresentationClient), | 45 public NON_EXPORTED_BASE(blink::WebPresentationClient), |
| 46 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { | 46 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { |
| 47 public: | 47 public: |
| 48 explicit PresentationDispatcher(RenderFrame* render_frame); | 48 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 49 ~PresentationDispatcher() override; | 49 ~PresentationDispatcher() override; |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 friend class TestPresentationDispatcher; | 52 friend class TestPresentationDispatcher; |
| 53 friend class PresentationDispatcherTest; | |
| 53 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); | 54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); |
| 54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); | 55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); |
| 55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); | 56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); |
| 56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); | 57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); |
| 57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); | 58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); |
| 58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); | 59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); |
| 59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); | 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); |
| 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); | 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); |
| 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); | 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); |
| 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 63 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 size_t length) override; | 105 size_t length) override; |
| 105 void sendBlobData(const blink::WebURL& presentationUrl, | 106 void sendBlobData(const blink::WebURL& presentationUrl, |
| 106 const blink::WebString& presentationId, | 107 const blink::WebString& presentationId, |
| 107 const uint8_t* data, | 108 const uint8_t* data, |
| 108 size_t length) override; | 109 size_t length) override; |
| 109 void closeSession(const blink::WebURL& presentationUrl, | 110 void closeSession(const blink::WebURL& presentationUrl, |
| 110 const blink::WebString& presentationId) override; | 111 const blink::WebString& presentationId) override; |
| 111 void terminateSession(const blink::WebURL& presentationUrl, | 112 void terminateSession(const blink::WebURL& presentationUrl, |
| 112 const blink::WebString& presentationId) override; | 113 const blink::WebString& presentationId) override; |
| 113 void getAvailability( | 114 void getAvailability( |
| 114 const blink::WebVector<blink::WebURL>& availabilityUrl, | 115 const blink::WebVector<blink::WebURL>& availabilityUrls, |
| 115 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) | 116 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) |
| 116 override; | 117 override; |
| 117 void startListening(blink::WebPresentationAvailabilityObserver*) override; | 118 void startListening(blink::WebPresentationAvailabilityObserver*) override; |
| 118 void stopListening(blink::WebPresentationAvailabilityObserver*) override; | 119 void stopListening(blink::WebPresentationAvailabilityObserver*) override; |
| 119 void setDefaultPresentationUrls( | 120 void setDefaultPresentationUrls( |
| 120 const blink::WebVector<blink::WebURL>& presentationUrls) override; | 121 const blink::WebVector<blink::WebURL>& presentationUrls) override; |
| 121 | 122 |
| 122 // RenderFrameObserver implementation. | 123 // RenderFrameObserver implementation. |
| 123 void DidCommitProvisionalLoad( | 124 void DidCommitProvisionalLoad( |
| 124 bool is_new_navigation, | 125 bool is_new_navigation, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 // over mojo channel. | 169 // over mojo channel. |
| 169 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; | 170 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; |
| 170 MessageRequestQueue message_request_queue_; | 171 MessageRequestQueue message_request_queue_; |
| 171 | 172 |
| 172 enum class ListeningState { | 173 enum class ListeningState { |
| 173 INACTIVE, | 174 INACTIVE, |
| 174 WAITING, | 175 WAITING, |
| 175 ACTIVE, | 176 ACTIVE, |
| 176 }; | 177 }; |
| 177 | 178 |
| 179 enum class ScreenAvailability { | |
| 180 UNKNOWN, | |
| 181 AVAILABLE, | |
| 182 UNAVAILABLE, | |
| 183 UNSUPPORTED | |
| 184 }; | |
| 185 | |
| 178 using AvailabilityCallbacksMap = | 186 using AvailabilityCallbacksMap = |
| 179 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; | 187 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; |
| 180 using AvailabilityObserversSet = | 188 using AvailabilityObserversSet = |
| 181 std::set<blink::WebPresentationAvailabilityObserver*>; | 189 std::set<blink::WebPresentationAvailabilityObserver*>; |
| 182 | 190 |
| 183 // Tracks status of presentation displays availability for |availability_url|. | 191 // Tracks status of presentation displays availability for |
| 192 // |availability_urls|. | |
| 184 struct AvailabilityStatus { | 193 struct AvailabilityStatus { |
|
imcheng
2017/01/17 20:53:17
nit: This doesn't really contain the ScreenAvailab
mark a. foltz
2017/01/17 21:04:24
Maybe AvailabilityCallbacks?
zhaobin
2017/01/18 03:38:57
AvailabilityListeners?
| |
| 185 explicit AvailabilityStatus(const GURL& availability_url); | 194 AvailabilityStatus(const std::vector<GURL>& availability_urls); |
|
imcheng
2017/01/17 20:53:17
Still needs explicit?
zhaobin
2017/01/18 03:38:57
Done.
| |
| 186 ~AvailabilityStatus(); | 195 ~AvailabilityStatus(); |
| 187 | 196 |
| 188 const GURL url; | 197 std::vector<GURL> urls; |
|
imcheng
2017/01/17 20:53:17
Can this be const?
zhaobin
2017/01/18 03:38:57
Done.
| |
| 189 bool last_known_availability; | |
| 190 ListeningState listening_state; | |
| 191 AvailabilityCallbacksMap availability_callbacks; | 198 AvailabilityCallbacksMap availability_callbacks; |
| 192 AvailabilityObserversSet availability_observers; | 199 AvailabilityObserversSet availability_observers; |
| 193 }; | 200 }; |
| 194 | 201 |
| 195 // Map of AvailabilityStatus for known URLs. | 202 // Tracks listening status of |availability_url|. |
| 196 std::map<GURL, std::unique_ptr<AvailabilityStatus>> | 203 struct ListeningStatus { |
| 197 availability_status_; | 204 explicit ListeningStatus(const GURL& availability_url); |
| 205 ~ListeningStatus(); | |
| 198 | 206 |
| 199 // Updates the listening state of availability for |status| and notifies the | 207 const GURL url; |
| 200 // client. | 208 ScreenAvailability last_known_availability; |
| 201 void UpdateListeningState(AvailabilityStatus* status); | 209 ListeningState listening_state; |
| 210 }; | |
| 211 | |
| 212 // Map of ListeningStatus for known URLs. | |
| 213 std::map<GURL, std::unique_ptr<ListeningStatus>> listening_status_; | |
| 214 | |
| 215 // Set of AvailabilityStatus for known PresentationRequest. | |
| 216 std::set<std::unique_ptr<AvailabilityStatus>> availability_set_; | |
| 217 | |
| 218 // Starts listening to |url|. | |
| 219 void StartListeningToURL(const GURL& url); | |
| 220 | |
| 221 // Stops listening to |url| if no PresentationAvailability is observing |url|. | |
| 222 // StartListening() must have been called first. | |
| 223 void StopListeningToURL(const GURL& url); | |
| 224 | |
| 225 // Returns nullptr if there is no status for |url|. | |
| 226 ListeningStatus* GetListeningStatus(const GURL& url); | |
|
imcheng
2017/01/17 20:53:17
Can this method and the 2 below be const?
zhaobin
2017/01/18 03:38:57
Done.
| |
| 227 | |
| 228 // Returns nullptr if there is no availability status for |urls|. | |
| 229 AvailabilityStatus* GetAvailabilityStatus(const std::vector<GURL>& urls); | |
| 230 | |
| 231 // Returns AVAILABLE if any url in |urls| has screen availability AVAILABLE; | |
| 232 // Returns UNSUPPORTED if any url in |urls| have screen availability | |
| 233 // UNSUPPORTED, and no url has screen availability AVAILABLE; | |
| 234 // Returns UNAVAILABLE if at least one url in |urls| has screen availability | |
| 235 // UNAVAILABLE, and no url has screen availability AVAILABLE or UNSUPPORTED; | |
| 236 // Returns UNKNOWN if all urls in |urls| have screen availability | |
| 237 // UNKNOWN. | |
| 238 ScreenAvailability GetScreenAvailability(const std::vector<GURL>& urls); | |
| 202 | 239 |
| 203 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 240 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 204 }; | 241 }; |
| 205 | 242 |
| 206 } // namespace content | 243 } // namespace content |
| 207 | 244 |
| 208 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 245 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |