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; | |
|
mark a. foltz
2017/01/03 21:47:13
Takumi is also landing a unit test, so please coor
zhaobin
2017/01/06 01:55:21
Sure.
| |
| 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>& availabilityUrls, |
| 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 |
| 163 using AvailabilityCallbacksMap = | 166 enum class ScreenAvailability { |
|
mlamouri (slow - plz ping)
2017/01/04 16:15:00
It's pretty much a nit but why not using Availabil
mark a. foltz
2017/01/05 22:40:49
There's already an AvailabilityStatus struct decla
zhaobin
2017/01/06 01:55:21
ScreenAvailability represents if there is any scre
| |
| 164 IDMap<std::unique_ptr<blink::WebPresentationAvailabilityCallbacks>>; | 167 UNKNOWN, |
| 168 AVAILABLE, | |
| 169 UNAVAILABLE, | |
| 170 UNSUPPORTED | |
| 171 }; | |
| 172 | |
| 173 struct AvailabilityCallback { | |
| 174 AvailabilityCallback( | |
| 175 const blink::WebVector<blink::WebURL>& availability_urls, | |
|
mark a. foltz
2017/01/03 21:47:13
Can this use std::vector<GURL> to be consistent wi
zhaobin
2017/01/06 01:55:21
Done.
| |
| 176 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> | |
| 177 availability_callback); | |
| 178 ~AvailabilityCallback(); | |
| 179 | |
| 180 blink::WebVector<blink::WebURL> urls; | |
| 181 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callback; | |
| 182 }; | |
| 183 | |
| 184 using AvailabilityCallbacksVector = | |
| 185 std::vector<std::unique_ptr<AvailabilityCallback>>; | |
| 186 using AvailabilityCallbacksSet = std::set<AvailabilityCallback*>; | |
| 165 using AvailabilityObserversSet = | 187 using AvailabilityObserversSet = |
| 166 std::set<blink::WebPresentationAvailabilityObserver*>; | 188 std::set<blink::WebPresentationAvailabilityObserver*>; |
| 167 | 189 |
| 168 // Tracks status of presentation displays availability for |availability_url|. | 190 // Tracks status of presentation displays availability for |availability_url|. |
| 169 struct AvailabilityStatus { | 191 struct AvailabilityStatus { |
| 170 explicit AvailabilityStatus(const GURL& availability_url); | 192 explicit AvailabilityStatus(const GURL& availability_urls); |
|
mark a. foltz
2017/01/03 21:47:13
availability_url
zhaobin
2017/01/06 01:55:21
Done.
| |
| 171 ~AvailabilityStatus(); | 193 ~AvailabilityStatus(); |
| 172 | 194 |
| 173 const GURL url; | 195 const GURL url; |
| 174 bool last_known_availability; | 196 ScreenAvailability last_known_availability; |
| 175 ListeningState listening_state; | 197 ListeningState listening_state; |
| 176 AvailabilityCallbacksMap availability_callbacks; | 198 AvailabilityCallbacksSet availability_callbacks; |
|
mark a. foltz
2017/01/03 21:47:13
It's confusing in the code to have both availabili
zhaobin
2017/01/06 01:55:21
Code removed.
| |
| 177 AvailabilityObserversSet availability_observers; | 199 AvailabilityObserversSet availability_observers; |
| 178 }; | 200 }; |
| 179 | 201 |
| 180 // Map of AvailabilityStatus for known URLs. | 202 // Map of AvailabilityStatus for known URLs. |
| 181 std::map<GURL, std::unique_ptr<AvailabilityStatus>> | 203 std::map<GURL, std::unique_ptr<AvailabilityStatus>> |
| 182 availability_status_; | 204 availability_status_; |
| 183 | 205 |
| 206 // Map of AvailabilityCallbacks. | |
| 207 AvailabilityCallbacksVector availability_callbacks_; | |
|
mark a. foltz
2017/01/03 21:47:13
Is this for ownership purposes (i.e. to make sure
zhaobin
2017/01/06 01:55:21
Code removed.
| |
| 208 | |
| 184 // Updates the listening state of availability for |status| and notifies the | 209 // Updates the listening state of availability for |status| and notifies the |
| 185 // client. | 210 // client. |
| 186 void UpdateListeningState(AvailabilityStatus* status); | 211 void UpdateListeningState(AvailabilityStatus* status); |
| 187 | 212 |
| 213 // Called when |status|'s |last_known_availability|, |availability_callbacks|, | |
| 214 // or |availability_observers| changes. | |
| 215 void UpdateAvailabilityObserversAndCallbacks(AvailabilityStatus* status); | |
| 216 | |
| 217 // Returns UNKNOWN if any url in |urls| has screen availability UNKNOWN; | |
| 218 // Returns UNSUPPORTED if any url in |urls| have screen availability | |
| 219 // UNSUPPORTED, and no url has screen availability UNKNOWN; | |
| 220 // Returns AVAILABLE if at least one url in |urls| has screen availability | |
| 221 // AVAILABLE, and no url has screen availability UNKNOWN or UNSUPPORTED; | |
| 222 // Returns UNAVAILABLE if all urls in |urls| have screen availability | |
| 223 // UNAVAILABLE. | |
| 224 PresentationDispatcher::ScreenAvailability GetScreenAvailability( | |
|
mlamouri (slow - plz ping)
2017/01/04 16:15:00
GetAvailabilityStatus()?
zhaobin
2017/01/06 01:55:21
Cannot use GetAvailabilityStatus since Availabilit
| |
| 225 const blink::WebVector<blink::WebURL>& urls); | |
|
mark a. foltz
2017/01/03 21:47:13
std::vector<GURL>
zhaobin
2017/01/06 01:55:21
Done.
| |
| 226 | |
| 188 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 227 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 189 }; | 228 }; |
| 190 | 229 |
| 191 } // namespace content | 230 } // namespace content |
| 192 | 231 |
| 193 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 232 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |