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 29 matching lines...) Expand all Loading... | |
| 40 // Blink. It forwards the calls to the Mojo PresentationService. | 40 // Blink. It forwards the calls to the Mojo PresentationService. |
| 41 class CONTENT_EXPORT PresentationDispatcher | 41 class CONTENT_EXPORT PresentationDispatcher |
| 42 : public RenderFrameObserver, | 42 : public RenderFrameObserver, |
| 43 public NON_EXPORTED_BASE(blink::WebPresentationClient), | 43 public NON_EXPORTED_BASE(blink::WebPresentationClient), |
| 44 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { | 44 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { |
| 45 public: | 45 public: |
| 46 explicit PresentationDispatcher(RenderFrame* render_frame); | 46 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 47 ~PresentationDispatcher() override; | 47 ~PresentationDispatcher() override; |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 friend class PresentationDispatcherTest; | |
| 50 struct SendMessageRequest { | 51 struct SendMessageRequest { |
| 51 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info, | 52 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info, |
| 52 blink::mojom::ConnectionMessagePtr message); | 53 blink::mojom::ConnectionMessagePtr message); |
| 53 ~SendMessageRequest(); | 54 ~SendMessageRequest(); |
| 54 | 55 |
| 55 blink::mojom::PresentationSessionInfoPtr session_info; | 56 blink::mojom::PresentationSessionInfoPtr session_info; |
| 56 blink::mojom::ConnectionMessagePtr message; | 57 blink::mojom::ConnectionMessagePtr message; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 static SendMessageRequest* CreateSendTextMessageRequest( | 60 static SendMessageRequest* CreateSendTextMessageRequest( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 89 size_t length) override; | 90 size_t length) override; |
| 90 void sendBlobData(const blink::WebURL& presentationUrl, | 91 void sendBlobData(const blink::WebURL& presentationUrl, |
| 91 const blink::WebString& presentationId, | 92 const blink::WebString& presentationId, |
| 92 const uint8_t* data, | 93 const uint8_t* data, |
| 93 size_t length) override; | 94 size_t length) override; |
| 94 void closeSession(const blink::WebURL& presentationUrl, | 95 void closeSession(const blink::WebURL& presentationUrl, |
| 95 const blink::WebString& presentationId) override; | 96 const blink::WebString& presentationId) override; |
| 96 void terminateSession(const blink::WebURL& presentationUrl, | 97 void terminateSession(const blink::WebURL& presentationUrl, |
| 97 const blink::WebString& presentationId) override; | 98 const blink::WebString& presentationId) override; |
| 98 void getAvailability( | 99 void getAvailability( |
| 99 const blink::WebVector<blink::WebURL>& availabilityUrl, | 100 const blink::WebVector<blink::WebURL>& availabilityUrl, |
|
mark a. foltz
2016/12/23 01:04:22
Nit: availabilityUrls
zhaobin
2016/12/29 18:48:38
Done.
| |
| 100 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) | 101 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) |
| 101 override; | 102 override; |
| 102 void startListening(blink::WebPresentationAvailabilityObserver*) override; | 103 void startListening(blink::WebPresentationAvailabilityObserver*) override; |
| 103 void stopListening(blink::WebPresentationAvailabilityObserver*) override; | 104 void stopListening(blink::WebPresentationAvailabilityObserver*) override; |
| 104 void setDefaultPresentationUrls( | 105 void setDefaultPresentationUrls( |
| 105 const blink::WebVector<blink::WebURL>& presentationUrls) override; | 106 const blink::WebVector<blink::WebURL>& presentationUrls) override; |
| 106 | 107 |
| 107 // RenderFrameObserver implementation. | 108 // RenderFrameObserver implementation. |
| 108 void DidCommitProvisionalLoad( | 109 void DidCommitProvisionalLoad( |
| 109 bool is_new_navigation, | 110 bool is_new_navigation, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 133 void OnReceiverConnectionAvailable( | 134 void OnReceiverConnectionAvailable( |
| 134 blink::mojom::PresentationSessionInfoPtr) override; | 135 blink::mojom::PresentationSessionInfoPtr) override; |
| 135 | 136 |
| 136 // Call to PresentationService to send the message in |request|. | 137 // Call to PresentationService to send the message in |request|. |
| 137 // |session_info| and |message| of |reuqest| will be consumed. | 138 // |session_info| and |message| of |reuqest| will be consumed. |
| 138 // |HandleSendMessageRequests| will be invoked after the send is attempted. | 139 // |HandleSendMessageRequests| will be invoked after the send is attempted. |
| 139 void DoSendMessage(SendMessageRequest* request); | 140 void DoSendMessage(SendMessageRequest* request); |
| 140 void HandleSendMessageRequests(bool success); | 141 void HandleSendMessageRequests(bool success); |
| 141 | 142 |
| 142 void ConnectToPresentationServiceIfNeeded(); | 143 void ConnectToPresentationServiceIfNeeded(); |
| 144 void SetPresentationServiceForTest( | |
| 145 blink::mojom::PresentationServicePtr presentation_service); | |
| 143 | 146 |
| 144 void UpdateListeningState(); | 147 void UpdateListeningState(); |
| 145 | 148 |
| 146 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 149 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 147 blink::WebPresentationController* controller_; | 150 blink::WebPresentationController* controller_; |
| 148 blink::WebPresentationReceiver* receiver_; | 151 blink::WebPresentationReceiver* receiver_; |
| 149 blink::mojom::PresentationServicePtr presentation_service_; | 152 blink::mojom::PresentationServicePtr presentation_service_; |
| 150 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; | 153 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; |
| 151 | 154 |
| 152 // Message requests are queued here and only one message at a time is sent | 155 // Message requests are queued here and only one message at a time is sent |
| 153 // over mojo channel. | 156 // over mojo channel. |
| 154 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; | 157 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; |
| 155 MessageRequestQueue message_request_queue_; | 158 MessageRequestQueue message_request_queue_; |
| 156 | 159 |
| 157 enum class ListeningState { | 160 enum class ListeningState { |
| 158 INACTIVE, | 161 INACTIVE, |
| 159 WAITING, | 162 WAITING, |
| 160 ACTIVE, | 163 ACTIVE, |
| 161 }; | 164 }; |
| 162 | 165 |
| 166 enum class ScreenAvailability { | |
| 167 UNKNOWN, | |
| 168 AVAILABLE, | |
| 169 UNAVAILABLE, | |
| 170 UNSUPPORTED | |
|
mark a. foltz
2016/12/23 01:04:22
I don't recall exactly why we have an API in the d
zhaobin
2016/12/29 18:48:38
Done.
| |
| 171 }; | |
| 172 | |
| 163 using AvailabilityCallbacksMap = | 173 using AvailabilityCallbacksMap = |
| 164 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; | 174 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; |
| 165 using AvailabilityObserversSet = | 175 using AvailabilityObserversSet = |
| 166 std::set<blink::WebPresentationAvailabilityObserver*>; | 176 std::set<blink::WebPresentationAvailabilityObserver*>; |
| 167 | 177 |
| 168 // Tracks status of presentation displays availability for |availability_url|. | 178 // Tracks status of presentation displays availability for |availability_url|. |
| 169 struct AvailabilityStatus { | 179 struct AvailabilityStatus { |
| 170 explicit AvailabilityStatus(const GURL& availability_url); | 180 explicit AvailabilityStatus(const std::vector<GURL>& availability_urls); |
| 171 ~AvailabilityStatus(); | 181 ~AvailabilityStatus(); |
| 172 | 182 |
| 173 const GURL url; | 183 const std::vector<GURL> urls; |
| 174 bool last_known_availability; | |
| 175 ListeningState listening_state; | |
| 176 AvailabilityCallbacksMap availability_callbacks; | 184 AvailabilityCallbacksMap availability_callbacks; |
| 177 AvailabilityObserversSet availability_observers; | 185 AvailabilityObserversSet availability_observers; |
| 178 }; | 186 }; |
| 179 | 187 |
| 180 // Map of AvailabilityStatus for known URLs. | 188 // Map of AvailabilityStatus for known URLs. |
| 181 std::map<GURL, std::unique_ptr<AvailabilityStatus>> | 189 std::map<std::vector<GURL>, std::unique_ptr<AvailabilityStatus>> |
|
mark a. foltz
2016/12/23 01:04:22
Is it okay to use a container as a map key?
I us
zhaobin
2016/12/29 18:48:38
Code removed.
| |
| 182 availability_status_; | 190 availability_status_; |
| 183 | 191 |
| 192 // Map of ScreenAvailability for known URL. | |
| 193 std::map<GURL, ScreenAvailability> screen_availability_; | |
| 194 | |
| 195 // Map of ListeningState for known URL. | |
| 196 std::map<GURL, ListeningState> url_listening_state_; | |
|
mark a. foltz
2016/12/23 01:04:22
Can we combine these with AvailabilityStatus?
zhaobin
2016/12/29 18:48:38
Code removed.
| |
| 197 | |
| 184 // Updates the listening state of availability for |status| and notifies the | 198 // Updates the listening state of availability for |status| and notifies the |
| 185 // client. | 199 // client. |
| 186 void UpdateListeningState(AvailabilityStatus* status); | 200 void UpdateListeningState(AvailabilityStatus* status); |
| 187 | 201 |
| 202 // Called when all urls in |status| reports ScreenAvailability::UNSUPPORTED. | |
| 203 void OnScreenAvailabilityNotSupported(AvailabilityStatus* status); | |
| 204 | |
| 205 // Called when all urls in |status| reports their screen availability. | |
| 206 void OnScreenAvailabilityUpdated(AvailabilityStatus* status, bool available); | |
| 207 | |
| 208 void OnScreenAvailabilityUpdated(const GURL& url, ScreenAvailability); | |
| 209 | |
| 210 // Returns UNKNOWN if any url in |urls| has screen availability UNKNOWN. | |
| 211 // Returns AVAILABLE if at least one url in |urls| has screen availability | |
| 212 // AVAILABLE, and no url has screen availability UNKNOWN; | |
| 213 // Returns UNAVAILABLE is at least one url in |urls| has screen availability | |
| 214 // UNAVAILABLE, and no url has screen availability UNKNOWN or AVAILABLE; | |
| 215 // Returns UNSUPPORTED if all urls in |urls| have screen availability | |
| 216 // UNSUPPORTED. | |
| 217 PresentationDispatcher::ScreenAvailability GetRequestAvailability( | |
| 218 const std::vector<GURL>& urls); | |
| 219 | |
| 188 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 220 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 189 }; | 221 }; |
| 190 | 222 |
| 191 } // namespace content | 223 } // namespace content |
| 192 | 224 |
| 193 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 225 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |