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" | |
mark a. foltz
2015/04/10 19:03:18
This #include doesn't seem necessary.
USE s.singapati at gmail.com
2015/04/14 17:51:51
Done.
| |
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(s.singapati): Handle ArrayBuffer/View and Blob data. | |
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); |
61 | 87 |
62 void ConnectToPresentationServiceIfNeeded(); | 88 void ConnectToPresentationServiceIfNeeded(); |
63 | 89 |
64 void DoUpdateAvailableChangeWatched( | 90 void DoUpdateAvailableChangeWatched( |
65 const std::string& presentation_url, | 91 const std::string& presentation_url, |
66 bool watched); | 92 bool watched); |
67 | 93 |
94 void DoSendStringMessage( | |
95 const std::string& presentation_url, | |
96 const std::string& presentation_id, | |
97 const std::string& message); | |
98 void HandleSendMessageRequests(); | |
99 void RemoveAllMessageRequests(); | |
100 | |
68 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 101 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
69 blink::WebPresentationController* controller_; | 102 blink::WebPresentationController* controller_; |
70 presentation::PresentationServicePtr presentation_service_; | 103 presentation::PresentationServicePtr presentation_service_; |
104 | |
105 // Message requests are queued here and only one message is sent | |
106 // at a time over mojo channel. | |
107 using MessageRequestQueue = std::queue<linked_ptr<MessageRequest>>; | |
108 MessageRequestQueue message_request_queue_; | |
71 }; | 109 }; |
72 | 110 |
73 } // namespace content | 111 } // namespace content |
74 | 112 |
75 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 113 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
OLD | NEW |