| 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 |
| 11 #include <deque> | 11 #include <deque> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <set> | 14 #include <set> |
| 15 #include <string> | 15 #include <string> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/id_map.h" | 19 #include "base/id_map.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 22 #include "content/public/common/presentation_connection_message.h" | 22 #include "content/public/common/presentation_connection_message.h" |
| 23 #include "content/public/common/presentation_session.h" | 23 #include "content/public/common/presentation_info.h" |
| 24 #include "content/public/renderer/render_frame_observer.h" | 24 #include "content/public/renderer/render_frame_observer.h" |
| 25 #include "mojo/public/cpp/bindings/binding.h" | 25 #include "mojo/public/cpp/bindings/binding.h" |
| 26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" | 26 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" |
| 27 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 27 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
| 28 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 29 | 29 |
| 30 namespace blink { | 30 namespace blink { |
| 31 class WebPresentationAvailabilityObserver; | 31 class WebPresentationAvailabilityObserver; |
| 32 class WebPresentationConnection; | 32 class WebPresentationConnection; |
| 33 class WebPresentationReceiver; | 33 class WebPresentationReceiver; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 50 public: | 50 public: |
| 51 explicit PresentationDispatcher(RenderFrame* render_frame); | 51 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 52 ~PresentationDispatcher() override; | 52 ~PresentationDispatcher() override; |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 // TODO(crbug.com/684116): remove friend class after moving message queue | 55 // TODO(crbug.com/684116): remove friend class after moving message queue |
| 56 // logic from PresentationDispatcher to PresentationConnectionProxy. | 56 // logic from PresentationDispatcher to PresentationConnectionProxy. |
| 57 friend class PresentationConnectionProxy; | 57 friend class PresentationConnectionProxy; |
| 58 friend class TestPresentationDispatcher; | 58 friend class TestPresentationDispatcher; |
| 59 friend class PresentationDispatcherTest; | 59 friend class PresentationDispatcherTest; |
| 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); | 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartPresentation); |
| 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); | 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); | 62 TestStartPresentationError); |
| 63 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); | 63 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 64 TestReconnectPresentation); |
| 65 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 66 TestReconnectPresentationError); |
| 64 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); | 67 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); |
| 65 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); | 68 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); |
| 66 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); | 69 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); |
| 67 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 70 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 68 TestOnReceiverConnectionAvailable); | 71 TestOnReceiverConnectionAvailable); |
| 69 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); | 72 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseConnection); |
| 70 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); | 73 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 74 TestTerminatePresentation); |
| 71 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 75 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 72 TestListenForScreenAvailability); | 76 TestListenForScreenAvailability); |
| 73 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 77 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 74 TestSetDefaultPresentationUrls); | 78 TestSetDefaultPresentationUrls); |
| 75 | 79 |
| 76 struct SendMessageRequest { | 80 struct SendMessageRequest { |
| 77 SendMessageRequest( | 81 SendMessageRequest( |
| 78 const PresentationSessionInfo& session_info, | 82 const PresentationInfo& presentation_info, |
| 79 PresentationConnectionMessage connection_message, | 83 PresentationConnectionMessage connection_message, |
| 80 const blink::WebPresentationConnectionProxy* connection_proxy); | 84 const blink::WebPresentationConnectionProxy* connection_proxy); |
| 81 | 85 |
| 82 ~SendMessageRequest(); | 86 ~SendMessageRequest(); |
| 83 | 87 |
| 84 PresentationSessionInfo session_info; | 88 PresentationInfo presentation_info; |
| 85 PresentationConnectionMessage message; | 89 PresentationConnectionMessage message; |
| 86 // Proxy of Blink connection object |connection| calling connection.send(). | 90 // Proxy of Blink connection object |connection| calling connection.send(). |
| 87 // It does not take ownership of proxy object. Proxy object is owned by | 91 // It does not take ownership of proxy object. Proxy object is owned by |
| 88 // Blink connection. Blink connection is destroyed after | 92 // Blink connection. Blink connection is destroyed after |
| 89 // PresentationDispatcher so |connection_proxy| should always be valid. | 93 // PresentationDispatcher so |connection_proxy| should always be valid. |
| 90 const blink::WebPresentationConnectionProxy* connection_proxy; | 94 const blink::WebPresentationConnectionProxy* connection_proxy; |
| 91 }; | 95 }; |
| 92 | 96 |
| 93 static std::unique_ptr<SendMessageRequest> CreateSendTextMessageRequest( | 97 static std::unique_ptr<SendMessageRequest> CreateSendTextMessageRequest( |
| 94 const blink::WebURL& presentationUrl, | 98 const blink::WebURL& presentationUrl, |
| 95 const blink::WebString& presentationId, | 99 const blink::WebString& presentationId, |
| 96 const blink::WebString& message, | 100 const blink::WebString& message, |
| 97 const blink::WebPresentationConnectionProxy* connection_proxy); | 101 const blink::WebPresentationConnectionProxy* connection_proxy); |
| 98 static std::unique_ptr<SendMessageRequest> CreateSendBinaryMessageRequest( | 102 static std::unique_ptr<SendMessageRequest> CreateSendBinaryMessageRequest( |
| 99 const blink::WebURL& presentationUrl, | 103 const blink::WebURL& presentationUrl, |
| 100 const blink::WebString& presentationId, | 104 const blink::WebString& presentationId, |
| 101 const uint8_t* data, | 105 const uint8_t* data, |
| 102 size_t length, | 106 size_t length, |
| 103 const blink::WebPresentationConnectionProxy* connection_proxy); | 107 const blink::WebPresentationConnectionProxy* connection_proxy); |
| 104 | 108 |
| 105 // WebPresentationClient implementation. | 109 // WebPresentationClient implementation. |
| 106 void setController(blink::WebPresentationController* controller) override; | 110 void setController(blink::WebPresentationController* controller) override; |
| 107 void setReceiver(blink::WebPresentationReceiver*) override; | 111 void setReceiver(blink::WebPresentationReceiver*) override; |
| 108 void startSession(const blink::WebVector<blink::WebURL>& presentationUrls, | 112 void startPresentation( |
| 109 std::unique_ptr<blink::WebPresentationConnectionCallbacks> | 113 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 110 callback) override; | 114 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) |
| 111 void joinSession(const blink::WebVector<blink::WebURL>& presentationUrls, | 115 override; |
| 112 const blink::WebString& presentationId, | 116 void reconnectPresentation( |
| 113 std::unique_ptr<blink::WebPresentationConnectionCallbacks> | 117 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 114 callback) override; | 118 const blink::WebString& presentationId, |
| 119 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback) |
| 120 override; |
| 121 void terminatePresentation(const blink::WebURL& presentationUrl, |
| 122 const blink::WebString& presentationId) override; |
| 115 void sendString( | 123 void sendString( |
| 116 const blink::WebURL& presentationUrl, | 124 const blink::WebURL& presentationUrl, |
| 117 const blink::WebString& presentationId, | 125 const blink::WebString& presentationId, |
| 118 const blink::WebString& message, | 126 const blink::WebString& message, |
| 119 const blink::WebPresentationConnectionProxy* connection_proxy) override; | 127 const blink::WebPresentationConnectionProxy* connection_proxy) override; |
| 120 void sendArrayBuffer( | 128 void sendArrayBuffer( |
| 121 const blink::WebURL& presentationUrl, | 129 const blink::WebURL& presentationUrl, |
| 122 const blink::WebString& presentationId, | 130 const blink::WebString& presentationId, |
| 123 const uint8_t* data, | 131 const uint8_t* data, |
| 124 size_t length, | 132 size_t length, |
| 125 const blink::WebPresentationConnectionProxy* connection_proxy) override; | 133 const blink::WebPresentationConnectionProxy* connection_proxy) override; |
| 126 void sendBlobData( | 134 void sendBlobData( |
| 127 const blink::WebURL& presentationUrl, | 135 const blink::WebURL& presentationUrl, |
| 128 const blink::WebString& presentationId, | 136 const blink::WebString& presentationId, |
| 129 const uint8_t* data, | 137 const uint8_t* data, |
| 130 size_t length, | 138 size_t length, |
| 131 const blink::WebPresentationConnectionProxy* connection_proxy) override; | 139 const blink::WebPresentationConnectionProxy* connection_proxy) override; |
| 132 void closeSession( | 140 void closeConnection( |
| 133 const blink::WebURL& presentationUrl, | 141 const blink::WebURL& presentationUrl, |
| 134 const blink::WebString& presentationId, | 142 const blink::WebString& presentationId, |
| 135 const blink::WebPresentationConnectionProxy* connection_proxy) override; | 143 const blink::WebPresentationConnectionProxy* connection_proxy) override; |
| 136 void terminateConnection(const blink::WebURL& presentationUrl, | |
| 137 const blink::WebString& presentationId) override; | |
| 138 void getAvailability( | 144 void getAvailability( |
| 139 const blink::WebVector<blink::WebURL>& availabilityUrls, | 145 const blink::WebVector<blink::WebURL>& availabilityUrls, |
| 140 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) | 146 std::unique_ptr<blink::WebPresentationAvailabilityCallbacks> callbacks) |
| 141 override; | 147 override; |
| 142 void startListening(blink::WebPresentationAvailabilityObserver*) override; | 148 void startListening(blink::WebPresentationAvailabilityObserver*) override; |
| 143 void stopListening(blink::WebPresentationAvailabilityObserver*) override; | 149 void stopListening(blink::WebPresentationAvailabilityObserver*) override; |
| 144 void setDefaultPresentationUrls( | 150 void setDefaultPresentationUrls( |
| 145 const blink::WebVector<blink::WebURL>& presentationUrls) override; | 151 const blink::WebVector<blink::WebURL>& presentationUrls) override; |
| 146 | 152 |
| 147 // RenderFrameObserver implementation. | 153 // RenderFrameObserver implementation. |
| 148 void DidCommitProvisionalLoad( | 154 void DidCommitProvisionalLoad( |
| 149 bool is_new_navigation, | 155 bool is_new_navigation, |
| 150 bool is_same_page_navigation) override; | 156 bool is_same_page_navigation) override; |
| 151 void OnDestruct() override; | 157 void OnDestruct() override; |
| 152 void WidgetWillClose() override; | 158 void WidgetWillClose() override; |
| 153 | 159 |
| 154 // blink::mojom::PresentationServiceClient | 160 // blink::mojom::PresentationServiceClient |
| 155 void OnScreenAvailabilityNotSupported(const GURL& url) override; | 161 void OnScreenAvailabilityNotSupported(const GURL& url) override; |
| 156 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override; | 162 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override; |
| 157 void OnConnectionStateChanged(const PresentationSessionInfo& session_info, | 163 void OnConnectionStateChanged(const PresentationInfo& presentation_info, |
| 158 PresentationConnectionState state) override; | 164 PresentationConnectionState state) override; |
| 159 void OnConnectionClosed(const PresentationSessionInfo& session_info, | 165 void OnConnectionClosed(const PresentationInfo& presentation_info, |
| 160 PresentationConnectionCloseReason reason, | 166 PresentationConnectionCloseReason reason, |
| 161 const std::string& message) override; | 167 const std::string& message) override; |
| 162 void OnConnectionMessagesReceived( | 168 void OnConnectionMessagesReceived( |
| 163 const PresentationSessionInfo& session_info, | 169 const PresentationInfo& presentation_info, |
| 164 std::vector<PresentationConnectionMessage> messages) override; | 170 std::vector<PresentationConnectionMessage> messages) override; |
| 165 void OnDefaultSessionStarted( | 171 void OnDefaultPresentationStarted( |
| 166 const PresentationSessionInfo& session_info) override; | 172 const PresentationInfo& presentation_info) override; |
| 167 | 173 |
| 168 void OnSessionCreated( | 174 void OnConnectionCreated( |
| 169 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, | 175 std::unique_ptr<blink::WebPresentationConnectionCallbacks> callback, |
| 170 const base::Optional<PresentationSessionInfo>& session_info, | 176 const base::Optional<PresentationInfo>& presentation_info, |
| 171 const base::Optional<PresentationError>& error); | 177 const base::Optional<PresentationError>& error); |
| 172 void OnReceiverConnectionAvailable( | 178 void OnReceiverConnectionAvailable( |
| 173 const PresentationSessionInfo& session_info, | 179 const PresentationInfo& presentation_info, |
| 174 blink::mojom::PresentationConnectionPtr /*connection*/, | 180 blink::mojom::PresentationConnectionPtr /*connection*/, |
| 175 blink::mojom::PresentationConnectionRequest /*connection_request*/) | 181 blink::mojom::PresentationConnectionRequest /*connection_request*/) |
| 176 override; | 182 override; |
| 177 | 183 |
| 178 // Call to PresentationService to send the message in |request|. | 184 // Call to PresentationService to send the message in |request|. |
| 179 // |session_info| and |message| of |reuqest| will be consumed. | 185 // |presentation_info| and |message| of |reuqest| will be consumed. |
| 180 // |HandleSendMessageRequests| will be invoked after the send is attempted. | 186 // |HandleSendMessageRequests| will be invoked after the send is attempted. |
| 181 void DoSendMessage(SendMessageRequest* request); | 187 void DoSendMessage(SendMessageRequest* request); |
| 182 void HandleSendMessageRequests(bool success); | 188 void HandleSendMessageRequests(bool success); |
| 183 | 189 |
| 184 // Creates ControllerConnectionProxy object |controller_connection_proxy| with | 190 // Creates ControllerConnectionProxy object |controller_connection_proxy| with |
| 185 // |connection|. Sends mojo interface ptr of |controller_connection_proxy| | 191 // |connection|. Sends mojo interface ptr of |controller_connection_proxy| |
| 186 // and mojo interface request of |controller_connection_proxy|'s | 192 // and mojo interface request of |controller_connection_proxy|'s |
| 187 // |target_connection_| to PresentationService. | 193 // |target_connection_| to PresentationService. |
| 188 // |session_info|: |connection|'s id and url; | 194 // |presentation_info|: |connection|'s id and url; |
| 189 // |connection|: |controller_connection_proxy|'s |source_connection_|. Raw | 195 // |connection|: |controller_connection_proxy|'s |source_connection_|. Raw |
| 190 // pointer to Blink connection owning proxy object. It does not take object | 196 // pointer to Blink connection owning proxy object. It does not take object |
| 191 // ownership. | 197 // ownership. |
| 192 void SetControllerConnection(const PresentationSessionInfo& session_info, | 198 void SetControllerConnection(const PresentationInfo& presentation_info, |
| 193 blink::WebPresentationConnection* connection); | 199 blink::WebPresentationConnection* connection); |
| 194 | 200 |
| 195 virtual void ConnectToPresentationServiceIfNeeded(); | 201 virtual void ConnectToPresentationServiceIfNeeded(); |
| 196 | 202 |
| 197 void UpdateListeningState(); | 203 void UpdateListeningState(); |
| 198 | 204 |
| 199 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 205 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 200 blink::WebPresentationController* controller_; | 206 blink::WebPresentationController* controller_; |
| 201 blink::WebPresentationReceiver* receiver_; | 207 blink::WebPresentationReceiver* receiver_; |
| 202 blink::mojom::PresentationServicePtr presentation_service_; | 208 blink::mojom::PresentationServicePtr presentation_service_; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Returns UNKNOWN if all urls in |urls| have screen availability | 286 // Returns UNKNOWN if all urls in |urls| have screen availability |
| 281 // UNKNOWN. | 287 // UNKNOWN. |
| 282 ScreenAvailability GetScreenAvailability(const std::vector<GURL>& urls) const; | 288 ScreenAvailability GetScreenAvailability(const std::vector<GURL>& urls) const; |
| 283 | 289 |
| 284 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 290 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 285 }; | 291 }; |
| 286 | 292 |
| 287 } // namespace content | 293 } // namespace content |
| 288 | 294 |
| 289 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 295 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |