| 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 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/id_map.h" | 16 #include "base/id_map.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/public/renderer/render_frame_observer.h" | 19 #include "content/public/renderer/render_frame_observer.h" |
| 20 #include "mojo/public/cpp/bindings/binding.h" | 20 #include "mojo/public/cpp/bindings/binding.h" |
| 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" | 21 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" |
| 22 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" | 22 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m
ojom.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace blink { | 25 namespace blink { |
| 26 class WebPresentationAvailabilityObserver; | 26 class WebPresentationAvailabilityObserver; |
| 27 class WebPresentationReceiver; |
| 27 class WebString; | 28 class WebString; |
| 28 class WebURL; | 29 class WebURL; |
| 29 template <typename T> | 30 template <typename T> |
| 30 class WebVector; | 31 class WebVector; |
| 31 } // namespace blink | 32 } // namespace blink |
| 32 | 33 |
| 33 namespace content { | 34 namespace content { |
| 34 | 35 |
| 35 // PresentationDispatcher is a delegate for Presentation API messages used by | 36 // PresentationDispatcher is a delegate for Presentation API messages used by |
| 36 // Blink. It forwards the calls to the Mojo PresentationService. | 37 // Blink. It forwards the calls to the Mojo PresentationService. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 58 const blink::WebString& message); | 59 const blink::WebString& message); |
| 59 static SendMessageRequest* CreateSendBinaryMessageRequest( | 60 static SendMessageRequest* CreateSendBinaryMessageRequest( |
| 60 const blink::WebURL& presentationUrl, | 61 const blink::WebURL& presentationUrl, |
| 61 const blink::WebString& presentationId, | 62 const blink::WebString& presentationId, |
| 62 blink::mojom::PresentationMessageType type, | 63 blink::mojom::PresentationMessageType type, |
| 63 const uint8_t* data, | 64 const uint8_t* data, |
| 64 size_t length); | 65 size_t length); |
| 65 | 66 |
| 66 // WebPresentationClient implementation. | 67 // WebPresentationClient implementation. |
| 67 void setController(blink::WebPresentationController* controller) override; | 68 void setController(blink::WebPresentationController* controller) override; |
| 69 void setReceiver(blink::WebPresentationReceiver*) override; |
| 70 |
| 68 void startSession( | 71 void startSession( |
| 69 const blink::WebVector<blink::WebURL>& presentationUrls, | 72 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 70 blink::WebPresentationConnectionClientCallbacks* callback) override; | 73 blink::WebPresentationConnectionClientCallbacks* callback) override; |
| 71 void joinSession( | 74 void joinSession( |
| 72 const blink::WebVector<blink::WebURL>& presentationUrls, | 75 const blink::WebVector<blink::WebURL>& presentationUrls, |
| 73 const blink::WebString& presentationId, | 76 const blink::WebString& presentationId, |
| 74 blink::WebPresentationConnectionClientCallbacks* callback) override; | 77 blink::WebPresentationConnectionClientCallbacks* callback) override; |
| 75 void sendString(const blink::WebURL& presentationUrl, | 78 void sendString(const blink::WebURL& presentationUrl, |
| 76 const blink::WebString& presentationId, | 79 const blink::WebString& presentationId, |
| 77 const blink::WebString& message) override; | 80 const blink::WebString& message) override; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void OnSessionMessagesReceived( | 117 void OnSessionMessagesReceived( |
| 115 blink::mojom::PresentationSessionInfoPtr session_info, | 118 blink::mojom::PresentationSessionInfoPtr session_info, |
| 116 std::vector<blink::mojom::SessionMessagePtr> messages) override; | 119 std::vector<blink::mojom::SessionMessagePtr> messages) override; |
| 117 void OnDefaultSessionStarted( | 120 void OnDefaultSessionStarted( |
| 118 blink::mojom::PresentationSessionInfoPtr session_info) override; | 121 blink::mojom::PresentationSessionInfoPtr session_info) override; |
| 119 | 122 |
| 120 void OnSessionCreated( | 123 void OnSessionCreated( |
| 121 blink::WebPresentationConnectionClientCallbacks* callback, | 124 blink::WebPresentationConnectionClientCallbacks* callback, |
| 122 blink::mojom::PresentationSessionInfoPtr session_info, | 125 blink::mojom::PresentationSessionInfoPtr session_info, |
| 123 blink::mojom::PresentationErrorPtr error); | 126 blink::mojom::PresentationErrorPtr error); |
| 127 void OnReceiverConnectionAvailable( |
| 128 blink::mojom::PresentationSessionInfoPtr) override; |
| 124 | 129 |
| 125 // Call to PresentationService to send the message in |request|. | 130 // Call to PresentationService to send the message in |request|. |
| 126 // |session_info| and |message| of |reuqest| will be consumed. | 131 // |session_info| and |message| of |reuqest| will be consumed. |
| 127 // |HandleSendMessageRequests| will be invoked after the send is attempted. | 132 // |HandleSendMessageRequests| will be invoked after the send is attempted. |
| 128 void DoSendMessage(SendMessageRequest* request); | 133 void DoSendMessage(SendMessageRequest* request); |
| 129 void HandleSendMessageRequests(bool success); | 134 void HandleSendMessageRequests(bool success); |
| 130 | 135 |
| 131 void ConnectToPresentationServiceIfNeeded(); | 136 void ConnectToPresentationServiceIfNeeded(); |
| 132 | 137 |
| 133 void UpdateListeningState(); | 138 void UpdateListeningState(); |
| 134 | 139 |
| 135 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 140 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 136 blink::WebPresentationController* controller_; | 141 blink::WebPresentationController* controller_; |
| 142 blink::WebPresentationReceiver* receiver_; |
| 137 blink::mojom::PresentationServicePtr presentation_service_; | 143 blink::mojom::PresentationServicePtr presentation_service_; |
| 138 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; | 144 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; |
| 139 | 145 |
| 140 // Message requests are queued here and only one message at a time is sent | 146 // Message requests are queued here and only one message at a time is sent |
| 141 // over mojo channel. | 147 // over mojo channel. |
| 142 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; | 148 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; |
| 143 MessageRequestQueue message_request_queue_; | 149 MessageRequestQueue message_request_queue_; |
| 144 | 150 |
| 145 enum class ListeningState { | 151 enum class ListeningState { |
| 146 INACTIVE, | 152 INACTIVE, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 172 // Updates the listening state of availability for |status| and notifies the | 178 // Updates the listening state of availability for |status| and notifies the |
| 173 // client. | 179 // client. |
| 174 void UpdateListeningState(AvailabilityStatus* status); | 180 void UpdateListeningState(AvailabilityStatus* status); |
| 175 | 181 |
| 176 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 182 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 177 }; | 183 }; |
| 178 | 184 |
| 179 } // namespace content | 185 } // namespace content |
| 180 | 186 |
| 181 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 187 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |