| 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 <map> | 11 #include <map> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <queue> | 13 #include <queue> |
| 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/common/presentation/presentation.mojom.h" |
| 22 #include "content/public/renderer/render_frame_observer.h" | 23 #include "content/public/renderer/render_frame_observer.h" |
| 23 #include "mojo/public/cpp/bindings/binding.h" | 24 #include "mojo/public/cpp/bindings/binding.h" |
| 24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" | 25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" |
| 25 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | |
| 26 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 27 | 27 |
| 28 namespace blink { | 28 namespace blink { |
| 29 class WebPresentationAvailabilityObserver; | 29 class WebPresentationAvailabilityObserver; |
| 30 class WebPresentationReceiver; | 30 class WebPresentationReceiver; |
| 31 class WebString; | 31 class WebString; |
| 32 class WebURL; | 32 class WebURL; |
| 33 template <typename T> | 33 template <typename T> |
| 34 class WebVector; | 34 class WebVector; |
| 35 } // namespace blink | 35 } // namespace blink |
| 36 | 36 |
| 37 namespace content { | 37 namespace content { |
| 38 | 38 |
| 39 class TestPresentationDispatcher; | 39 class TestPresentationDispatcher; |
| 40 | 40 |
| 41 // PresentationDispatcher is a delegate for Presentation API messages used by | 41 // PresentationDispatcher is a delegate for Presentation API messages used by |
| 42 // Blink. It forwards the calls to the Mojo PresentationService. | 42 // Blink. It forwards the calls to the Mojo PresentationService. |
| 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(content::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_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); | 53 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); |
| 54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); | 54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); |
| 55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); | 55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); |
| 56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); | 56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); |
| 57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); | 57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); |
| 58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); | 58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); |
| 59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); | 59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); |
| 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); | 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); |
| 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); | 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); |
| 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 63 TestListenForScreenAvailability); | 63 TestListenForScreenAvailability); |
| 64 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, | 64 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, |
| 65 TestSetDefaultPresentationUrls); | 65 TestSetDefaultPresentationUrls); |
| 66 | 66 |
| 67 struct SendMessageRequest { | 67 struct SendMessageRequest { |
| 68 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info, | 68 SendMessageRequest(content::mojom::PresentationSessionInfoPtr session_info, |
| 69 blink::mojom::ConnectionMessagePtr message); | 69 content::mojom::ConnectionMessagePtr message); |
| 70 ~SendMessageRequest(); | 70 ~SendMessageRequest(); |
| 71 | 71 |
| 72 blink::mojom::PresentationSessionInfoPtr session_info; | 72 content::mojom::PresentationSessionInfoPtr session_info; |
| 73 blink::mojom::ConnectionMessagePtr message; | 73 content::mojom::ConnectionMessagePtr message; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 static SendMessageRequest* CreateSendTextMessageRequest( | 76 static SendMessageRequest* CreateSendTextMessageRequest( |
| 77 const blink::WebURL& presentationUrl, | 77 const blink::WebURL& presentationUrl, |
| 78 const blink::WebString& presentationId, | 78 const blink::WebString& presentationId, |
| 79 const blink::WebString& message); | 79 const blink::WebString& message); |
| 80 static SendMessageRequest* CreateSendBinaryMessageRequest( | 80 static SendMessageRequest* CreateSendBinaryMessageRequest( |
| 81 const blink::WebURL& presentationUrl, | 81 const blink::WebURL& presentationUrl, |
| 82 const blink::WebString& presentationId, | 82 const blink::WebString& presentationId, |
| 83 blink::mojom::PresentationMessageType type, | 83 content::mojom::PresentationMessageType type, |
| 84 const uint8_t* data, | 84 const uint8_t* data, |
| 85 size_t length); | 85 size_t length); |
| 86 | 86 |
| 87 // WebPresentationClient implementation. | 87 // WebPresentationClient implementation. |
| 88 void setController(blink::WebPresentationController* controller) override; | 88 void setController(blink::WebPresentationController* controller) override; |
| 89 void setReceiver(blink::WebPresentationReceiver*) override; | 89 void setReceiver(blink::WebPresentationReceiver*) override; |
| 90 | 90 |
| 91 void startSession(const blink::WebVector<blink::WebURL>& presentationUrls, | 91 void startSession(const blink::WebVector<blink::WebURL>& presentationUrls, |
| 92 std::unique_ptr<blink::WebPresentationConnectionCallback> | 92 std::unique_ptr<blink::WebPresentationConnectionCallback> |
| 93 callback) override; | 93 callback) override; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 118 void stopListening(blink::WebPresentationAvailabilityObserver*) override; | 118 void stopListening(blink::WebPresentationAvailabilityObserver*) override; |
| 119 void setDefaultPresentationUrls( | 119 void setDefaultPresentationUrls( |
| 120 const blink::WebVector<blink::WebURL>& presentationUrls) override; | 120 const blink::WebVector<blink::WebURL>& presentationUrls) override; |
| 121 | 121 |
| 122 // RenderFrameObserver implementation. | 122 // RenderFrameObserver implementation. |
| 123 void DidCommitProvisionalLoad( | 123 void DidCommitProvisionalLoad( |
| 124 bool is_new_navigation, | 124 bool is_new_navigation, |
| 125 bool is_same_page_navigation) override; | 125 bool is_same_page_navigation) override; |
| 126 void OnDestruct() override; | 126 void OnDestruct() override; |
| 127 | 127 |
| 128 // blink::mojom::PresentationServiceClient | 128 // content::mojom::PresentationServiceClient |
| 129 void OnScreenAvailabilityNotSupported(const GURL& url) override; | 129 void OnScreenAvailabilityNotSupported(const GURL& url) override; |
| 130 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override; | 130 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override; |
| 131 void OnConnectionStateChanged( | 131 void OnConnectionStateChanged( |
| 132 blink::mojom::PresentationSessionInfoPtr session_info, | 132 content::mojom::PresentationSessionInfoPtr session_info, |
| 133 blink::mojom::PresentationConnectionState state) override; | 133 content::mojom::PresentationConnectionState state) override; |
| 134 void OnConnectionClosed( | 134 void OnConnectionClosed( |
| 135 blink::mojom::PresentationSessionInfoPtr session_info, | 135 content::mojom::PresentationSessionInfoPtr session_info, |
| 136 blink::mojom::PresentationConnectionCloseReason reason, | 136 content::mojom::PresentationConnectionCloseReason reason, |
| 137 const std::string& message) override; | 137 const std::string& message) override; |
| 138 void OnConnectionMessagesReceived( | 138 void OnConnectionMessagesReceived( |
| 139 blink::mojom::PresentationSessionInfoPtr session_info, | 139 content::mojom::PresentationSessionInfoPtr session_info, |
| 140 std::vector<blink::mojom::ConnectionMessagePtr> messages) override; | 140 std::vector<content::mojom::ConnectionMessagePtr> messages) override; |
| 141 void OnDefaultSessionStarted( | 141 void OnDefaultSessionStarted( |
| 142 blink::mojom::PresentationSessionInfoPtr session_info) override; | 142 content::mojom::PresentationSessionInfoPtr session_info) override; |
| 143 | 143 |
| 144 void OnSessionCreated( | 144 void OnSessionCreated( |
| 145 std::unique_ptr<blink::WebPresentationConnectionCallback> callback, | 145 std::unique_ptr<blink::WebPresentationConnectionCallback> callback, |
| 146 blink::mojom::PresentationSessionInfoPtr session_info, | 146 content::mojom::PresentationSessionInfoPtr session_info, |
| 147 blink::mojom::PresentationErrorPtr error); | 147 content::mojom::PresentationErrorPtr error); |
| 148 void OnReceiverConnectionAvailable( | 148 void OnReceiverConnectionAvailable( |
| 149 blink::mojom::PresentationSessionInfoPtr, | 149 content::mojom::PresentationSessionInfoPtr, |
| 150 blink::mojom::PresentationConnectionPtr, | 150 content::mojom::PresentationConnectionPtr, |
| 151 blink::mojom::PresentationConnectionRequest) override; | 151 content::mojom::PresentationConnectionRequest) override; |
| 152 | 152 |
| 153 // Call to PresentationService to send the message in |request|. | 153 // Call to PresentationService to send the message in |request|. |
| 154 // |session_info| and |message| of |reuqest| will be consumed. | 154 // |session_info| and |message| of |reuqest| will be consumed. |
| 155 // |HandleSendMessageRequests| will be invoked after the send is attempted. | 155 // |HandleSendMessageRequests| will be invoked after the send is attempted. |
| 156 void DoSendMessage(SendMessageRequest* request); | 156 void DoSendMessage(SendMessageRequest* request); |
| 157 void HandleSendMessageRequests(bool success); | 157 void HandleSendMessageRequests(bool success); |
| 158 | 158 |
| 159 virtual void ConnectToPresentationServiceIfNeeded(); | 159 virtual void ConnectToPresentationServiceIfNeeded(); |
| 160 | 160 |
| 161 void UpdateListeningState(); | 161 void UpdateListeningState(); |
| 162 | 162 |
| 163 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 163 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 164 blink::WebPresentationController* controller_; | 164 blink::WebPresentationController* controller_; |
| 165 blink::WebPresentationReceiver* receiver_; | 165 blink::WebPresentationReceiver* receiver_; |
| 166 blink::mojom::PresentationServicePtr presentation_service_; | 166 content::mojom::PresentationServicePtr presentation_service_; |
| 167 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; | 167 mojo::Binding<content::mojom::PresentationServiceClient> binding_; |
| 168 | 168 |
| 169 // Message requests are queued here and only one message at a time is sent | 169 // Message requests are queued here and only one message at a time is sent |
| 170 // over mojo channel. | 170 // over mojo channel. |
| 171 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; | 171 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; |
| 172 MessageRequestQueue message_request_queue_; | 172 MessageRequestQueue message_request_queue_; |
| 173 | 173 |
| 174 enum class ListeningState { | 174 enum class ListeningState { |
| 175 INACTIVE, | 175 INACTIVE, |
| 176 WAITING, | 176 WAITING, |
| 177 ACTIVE, | 177 ACTIVE, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 201 // Updates the listening state of availability for |status| and notifies the | 201 // Updates the listening state of availability for |status| and notifies the |
| 202 // client. | 202 // client. |
| 203 void UpdateListeningState(AvailabilityStatus* status); | 203 void UpdateListeningState(AvailabilityStatus* status); |
| 204 | 204 |
| 205 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 205 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 206 }; | 206 }; |
| 207 | 207 |
| 208 } // namespace content | 208 } // namespace content |
| 209 | 209 |
| 210 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 210 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |