| 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/memory/linked_ptr.h" |
| 9 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
| 10 #include "content/common/presentation/presentation_service.mojom.h" | 11 #include "content/common/presentation/presentation_service.mojom.h" |
| 11 #include "content/public/renderer/render_frame_observer.h" | 12 #include "content/public/renderer/render_frame_observer.h" |
| 12 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" | 13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio
nClient.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 class WebString; | 16 class WebString; |
| 16 } // namespace blink | 17 } // namespace blink |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 // PresentationDispatcher is a delegate for Presentation API messages used by | 21 // PresentationDispatcher is a delegate for Presentation API messages used by |
| 21 // Blink. It forwards the calls to the Mojo PresentationService. | 22 // Blink. It forwards the calls to the Mojo PresentationService. |
| 22 class CONTENT_EXPORT PresentationDispatcher | 23 class CONTENT_EXPORT PresentationDispatcher |
| 23 : public RenderFrameObserver, | 24 : public RenderFrameObserver, |
| 24 public NON_EXPORTED_BASE(blink::WebPresentationClient) { | 25 public NON_EXPORTED_BASE(blink::WebPresentationClient) { |
| 25 public: | 26 public: |
| 26 explicit PresentationDispatcher(RenderFrame* render_frame); | 27 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 27 ~PresentationDispatcher() override; | 28 ~PresentationDispatcher() override; |
| 28 | 29 |
| 29 private: | 30 private: |
| 31 |
| 32 // send request from a presentation session. |
| 33 struct CONTENT_EXPORT MessageRequest { |
| 34 MessageRequest(const std::string& presentation_url, |
| 35 const std::string& presentation_id, |
| 36 const std::string& message); |
| 37 ~MessageRequest(); |
| 38 |
| 39 const std::string presentation_url; |
| 40 const std::string presentation_id; |
| 41 const std::string message; |
| 42 // TODO(s.singapati): Handle ArrayBuffer/View and Blob data. |
| 43 }; |
| 44 |
| 30 // WebPresentationClient implementation. | 45 // WebPresentationClient implementation. |
| 31 virtual void setController( | 46 virtual void setController( |
| 32 blink::WebPresentationController* controller); | 47 blink::WebPresentationController* controller); |
| 33 virtual void updateAvailableChangeWatched(bool watched); | 48 virtual void updateAvailableChangeWatched(bool watched); |
| 34 virtual void startSession( | 49 virtual void startSession( |
| 35 const blink::WebString& presentationUrl, | 50 const blink::WebString& presentationUrl, |
| 36 const blink::WebString& presentationId, | 51 const blink::WebString& presentationId, |
| 37 blink::WebPresentationSessionClientCallbacks* callback); | 52 blink::WebPresentationSessionClientCallbacks* callback); |
| 38 virtual void joinSession( | 53 virtual void joinSession( |
| 39 const blink::WebString& presentationUrl, | 54 const blink::WebString& presentationUrl, |
| 40 const blink::WebString& presentationId, | 55 const blink::WebString& presentationId, |
| 41 blink::WebPresentationSessionClientCallbacks* callback); | 56 blink::WebPresentationSessionClientCallbacks* callback); |
| 57 virtual void sendString( |
| 58 const blink::WebString& presentationUrl, |
| 59 const blink::WebString& presentationId, |
| 60 const blink::WebString& message); |
| 61 virtual void sendArrayBuffer( |
| 62 const blink::WebString& presentationUrl, |
| 63 const blink::WebString& presentationId, |
| 64 const char* data, |
| 65 size_t length); |
| 42 virtual void closeSession( | 66 virtual void closeSession( |
| 43 const blink::WebString& presentationUrl, | 67 const blink::WebString& presentationUrl, |
| 44 const blink::WebString& presentationId); | 68 const blink::WebString& presentationId); |
| 45 | 69 |
| 46 // RenderFrameObserver | 70 // RenderFrameObserver |
| 47 void DidChangeDefaultPresentation() override; | 71 void DidChangeDefaultPresentation() override; |
| 72 void FrameWillClose() override; |
| 48 | 73 |
| 49 void OnScreenAvailabilityChanged( | 74 void OnScreenAvailabilityChanged( |
| 50 const std::string& presentation_url, | 75 const std::string& presentation_url, |
| 51 bool available); | 76 bool available); |
| 52 void OnSessionCreated( | 77 void OnSessionCreated( |
| 53 blink::WebPresentationSessionClientCallbacks* callback, | 78 blink::WebPresentationSessionClientCallbacks* callback, |
| 54 presentation::PresentationSessionInfoPtr session_info, | 79 presentation::PresentationSessionInfoPtr session_info, |
| 55 presentation::PresentationErrorPtr error); | 80 presentation::PresentationErrorPtr error); |
| 56 void OnDefaultSessionStarted( | 81 void OnDefaultSessionStarted( |
| 57 presentation::PresentationSessionInfoPtr session_info); | 82 presentation::PresentationSessionInfoPtr session_info); |
| 58 void OnSessionStateChange( | 83 void OnSessionStateChange( |
| 59 presentation::PresentationSessionInfoPtr session_info, | 84 presentation::PresentationSessionInfoPtr session_info, |
| 60 presentation::PresentationSessionState session_state); | 85 presentation::PresentationSessionState session_state); |
| 61 | 86 |
| 62 void ConnectToPresentationServiceIfNeeded(); | 87 void ConnectToPresentationServiceIfNeeded(); |
| 63 | 88 |
| 64 void DoUpdateAvailableChangeWatched( | 89 void DoUpdateAvailableChangeWatched( |
| 65 const std::string& presentation_url, | 90 const std::string& presentation_url, |
| 66 bool watched); | 91 bool watched); |
| 67 | 92 |
| 93 void DoSendStringMessage( |
| 94 const std::string& presentation_url, |
| 95 const std::string& presentation_id, |
| 96 const std::string& message); |
| 97 void HandleSendMessageRequests(); |
| 98 |
| 68 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 99 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 69 blink::WebPresentationController* controller_; | 100 blink::WebPresentationController* controller_; |
| 70 presentation::PresentationServicePtr presentation_service_; | 101 presentation::PresentationServicePtr presentation_service_; |
| 102 |
| 103 // Message requests are queued here and only one message is sent |
| 104 // at a time over mojo channel. |
| 105 using MessageRequestQueue = std::queue<linked_ptr<MessageRequest>>; |
| 106 MessageRequestQueue message_request_queue_; |
| 71 }; | 107 }; |
| 72 | 108 |
| 73 } // namespace content | 109 } // namespace content |
| 74 | 110 |
| 75 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 111 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |