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