| 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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
| 10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 // Blink. It forwards the calls to the Mojo PresentationService. | 24 // Blink. It forwards the calls to the Mojo PresentationService. |
| 25 class CONTENT_EXPORT PresentationDispatcher | 25 class CONTENT_EXPORT PresentationDispatcher |
| 26 : public RenderFrameObserver, | 26 : public RenderFrameObserver, |
| 27 public NON_EXPORTED_BASE(blink::WebPresentationClient), | 27 public NON_EXPORTED_BASE(blink::WebPresentationClient), |
| 28 public NON_EXPORTED_BASE(presentation::PresentationServiceClient) { | 28 public NON_EXPORTED_BASE(presentation::PresentationServiceClient) { |
| 29 public: | 29 public: |
| 30 explicit PresentationDispatcher(RenderFrame* render_frame); | 30 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 31 ~PresentationDispatcher() override; | 31 ~PresentationDispatcher() override; |
| 32 | 32 |
| 33 private: | 33 private: |
| 34 struct SendMessageRequest { |
| 35 SendMessageRequest(presentation::PresentationSessionInfoPtr session_info, |
| 36 presentation::SessionMessagePtr message); |
| 37 ~SendMessageRequest(); |
| 38 |
| 39 presentation::PresentationSessionInfoPtr session_info; |
| 40 presentation::SessionMessagePtr message; |
| 41 }; |
| 42 |
| 43 static SendMessageRequest* CreateSendTextMessageRequest( |
| 44 const blink::WebString& presentationUrl, |
| 45 const blink::WebString& presentationId, |
| 46 const blink::WebString& message); |
| 47 static SendMessageRequest* CreateSendBinaryMessageRequest( |
| 48 const blink::WebString& presentationUrl, |
| 49 const blink::WebString& presentationId, |
| 50 presentation::PresentationMessageType type, |
| 51 const uint8* data, |
| 52 size_t length); |
| 53 |
| 34 // WebPresentationClient implementation. | 54 // WebPresentationClient implementation. |
| 35 virtual void setController( | 55 virtual void setController( |
| 36 blink::WebPresentationController* controller); | 56 blink::WebPresentationController* controller); |
| 37 virtual void updateAvailableChangeWatched(bool watched); | 57 virtual void updateAvailableChangeWatched(bool watched); |
| 38 virtual void startSession( | 58 virtual void startSession( |
| 39 const blink::WebString& presentationUrl, | 59 const blink::WebString& presentationUrl, |
| 40 blink::WebPresentationSessionClientCallbacks* callback); | 60 blink::WebPresentationSessionClientCallbacks* callback); |
| 41 virtual void joinSession( | 61 virtual void joinSession( |
| 42 const blink::WebString& presentationUrl, | 62 const blink::WebString& presentationUrl, |
| 43 const blink::WebString& presentationId, | 63 const blink::WebString& presentationId, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 70 void DidCommitProvisionalLoad( | 90 void DidCommitProvisionalLoad( |
| 71 bool is_new_navigation, | 91 bool is_new_navigation, |
| 72 bool is_same_page_navigation) override; | 92 bool is_same_page_navigation) override; |
| 73 | 93 |
| 74 // presentation::PresentationServiceClient | 94 // presentation::PresentationServiceClient |
| 75 void OnScreenAvailabilityUpdated(bool available) override; | 95 void OnScreenAvailabilityUpdated(bool available) override; |
| 76 void OnSessionStateChanged( | 96 void OnSessionStateChanged( |
| 77 presentation::PresentationSessionInfoPtr session_info, | 97 presentation::PresentationSessionInfoPtr session_info, |
| 78 presentation::PresentationSessionState new_state) override; | 98 presentation::PresentationSessionState new_state) override; |
| 79 void OnScreenAvailabilityNotSupported() override; | 99 void OnScreenAvailabilityNotSupported() override; |
| 100 void OnSessionMessagesReceived( |
| 101 presentation::PresentationSessionInfoPtr session_info, |
| 102 mojo::Array<presentation::SessionMessagePtr> messages) override; |
| 80 | 103 |
| 81 void OnSessionCreated( | 104 void OnSessionCreated( |
| 82 blink::WebPresentationSessionClientCallbacks* callback, | 105 blink::WebPresentationSessionClientCallbacks* callback, |
| 83 presentation::PresentationSessionInfoPtr session_info, | 106 presentation::PresentationSessionInfoPtr session_info, |
| 84 presentation::PresentationErrorPtr error); | 107 presentation::PresentationErrorPtr error); |
| 85 void OnDefaultSessionStarted( | 108 void OnDefaultSessionStarted( |
| 86 presentation::PresentationSessionInfoPtr session_info); | 109 presentation::PresentationSessionInfoPtr session_info); |
| 87 void OnSessionMessagesReceived( | 110 |
| 88 mojo::Array<presentation::SessionMessagePtr> messages); | 111 // Call to PresentationService to send the message in |request|. |
| 89 void DoSendMessage(const presentation::SessionMessage& session_message); | 112 // |session_info| and |message| of |reuqest| will be consumed. |
| 113 // |HandleSendMessageRequests| will be invoked after the send is attempted. |
| 114 void DoSendMessage(SendMessageRequest* request); |
| 90 void HandleSendMessageRequests(bool success); | 115 void HandleSendMessageRequests(bool success); |
| 91 | 116 |
| 92 void ConnectToPresentationServiceIfNeeded(); | 117 void ConnectToPresentationServiceIfNeeded(); |
| 93 | 118 |
| 94 void UpdateListeningState(); | 119 void UpdateListeningState(); |
| 95 | 120 |
| 96 void StartListenForMessages(); | |
| 97 | |
| 98 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 121 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 99 blink::WebPresentationController* controller_; | 122 blink::WebPresentationController* controller_; |
| 100 presentation::PresentationServicePtr presentation_service_; | 123 presentation::PresentationServicePtr presentation_service_; |
| 101 mojo::Binding<presentation::PresentationServiceClient> binding_; | 124 mojo::Binding<presentation::PresentationServiceClient> binding_; |
| 102 | 125 |
| 103 // Message requests are queued here and only one message at a time is sent | 126 // Message requests are queued here and only one message at a time is sent |
| 104 // over mojo channel. | 127 // over mojo channel. |
| 105 using MessageRequestQueue = | 128 using MessageRequestQueue = std::queue<linked_ptr<SendMessageRequest>>; |
| 106 std::queue<linked_ptr<presentation::SessionMessage>>; | |
| 107 MessageRequestQueue message_request_queue_; | 129 MessageRequestQueue message_request_queue_; |
| 108 | 130 |
| 109 enum class ListeningState { | 131 enum class ListeningState { |
| 110 Inactive, | 132 Inactive, |
| 111 Waiting, | 133 Waiting, |
| 112 Active, | 134 Active, |
| 113 }; | 135 }; |
| 114 | 136 |
| 115 ListeningState listening_state_; | 137 ListeningState listening_state_; |
| 116 bool last_known_availability_; | 138 bool last_known_availability_; |
| 117 | 139 |
| 118 using AvailabilityCallbacksMap = | 140 using AvailabilityCallbacksMap = |
| 119 IDMap<blink::WebPresentationAvailabilityCallbacks, IDMapOwnPointer>; | 141 IDMap<blink::WebPresentationAvailabilityCallbacks, IDMapOwnPointer>; |
| 120 AvailabilityCallbacksMap availability_callbacks_; | 142 AvailabilityCallbacksMap availability_callbacks_; |
| 121 | 143 |
| 122 using AvailabilityObserversSet = | 144 using AvailabilityObserversSet = |
| 123 std::set<blink::WebPresentationAvailabilityObserver*>; | 145 std::set<blink::WebPresentationAvailabilityObserver*>; |
| 124 AvailabilityObserversSet availability_observers_; | 146 AvailabilityObserversSet availability_observers_; |
| 125 | 147 |
| 126 bool listening_for_messages_; | |
| 127 | |
| 128 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); | 148 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); |
| 129 }; | 149 }; |
| 130 | 150 |
| 131 } // namespace content | 151 } // namespace content |
| 132 | 152 |
| 133 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 153 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |