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 "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 10 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 11 #include "content/common/presentation/presentation_service.mojom.h" | 13 #include "content/common/presentation/presentation_service.mojom.h" |
| 12 #include "content/public/renderer/render_frame_observer.h" | 14 #include "content/public/renderer/render_frame_observer.h" |
| 13 #include "content/renderer/presentation/presentation_session_dispatcher.h" | 15 #include "content/renderer/presentation/presentation_session_dispatcher.h" |
| 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nClient.h" | 16 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nClient.h" |
| 15 | 17 |
| 16 namespace blink { | 18 namespace blink { |
| 17 class WebString; | 19 class WebString; |
| 18 } // namespace blink | 20 } // namespace blink |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 // PresentationDispatcher is a delegate for Presentation API messages used by | 24 // PresentationDispatcher is a delegate for Presentation API messages used by |
| 23 // Blink. It forwards the calls to the Mojo PresentationService. | 25 // Blink. It forwards the calls to the Mojo PresentationService. |
| 24 class CONTENT_EXPORT PresentationDispatcher | 26 class CONTENT_EXPORT PresentationDispatcher |
| 25 : public RenderFrameObserver, | 27 : public RenderFrameObserver, |
| 26 public NON_EXPORTED_BASE(blink::WebPresentationClient) { | 28 public NON_EXPORTED_BASE(blink::WebPresentationClient) { |
| 27 public: | 29 public: |
| 28 explicit PresentationDispatcher(RenderFrame* render_frame); | 30 explicit PresentationDispatcher(RenderFrame* render_frame); |
| 29 ~PresentationDispatcher() override; | 31 ~PresentationDispatcher() override; |
| 30 | 32 |
| 31 private: | 33 private: |
| 34 | |
| 35 // postMessage request from a presentation session. | |
| 36 struct CONTENT_EXPORT PostMessageRequest { | |
| 37 PostMessageRequest(const std::string& presentation_url, | |
| 38 const std::string& presentation_id, | |
| 39 const std::string& message); | |
| 40 ~PostMessageRequest(); | |
| 41 | |
| 42 const std::string presentation_url; | |
| 43 const std::string presentation_id; | |
| 44 const std::string message; | |
| 45 | |
| 46 // Need to handle ArrayBuffer/View and Blob data also | |
|
imcheng
2015/04/02 23:57:24
Please add a TODO here.
USE s.singapati at gmail.com
2015/04/07 17:45:16
Done.
| |
| 47 //presentation::MessageType message_type; | |
| 48 //presentation::BinaryType binary_type; | |
| 49 }; | |
| 50 | |
| 32 // WebPresentationClient implementation. | 51 // WebPresentationClient implementation. |
| 33 virtual void setController( | 52 virtual void setController( |
| 34 blink::WebPresentationController* controller); | 53 blink::WebPresentationController* controller); |
| 35 virtual void updateAvailableChangeWatched(bool watched); | 54 virtual void updateAvailableChangeWatched(bool watched); |
| 36 virtual void startSession( | 55 virtual void startSession( |
| 37 const blink::WebString& presentationUrl, | 56 const blink::WebString& presentationUrl, |
| 38 const blink::WebString& presentationId, | 57 const blink::WebString& presentationId, |
| 39 blink::WebPresentationSessionClientCallbacks* callback); | 58 blink::WebPresentationSessionClientCallbacks* callback); |
| 40 virtual void joinSession( | 59 virtual void joinSession( |
| 41 const blink::WebString& presentationUrl, | 60 const blink::WebString& presentationUrl, |
| 42 const blink::WebString& presentationId, | 61 const blink::WebString& presentationId, |
| 43 blink::WebPresentationSessionClientCallbacks* callback); | 62 blink::WebPresentationSessionClientCallbacks* callback); |
| 63 virtual void postMessage( | |
| 64 const blink::WebString& presentationUrl, | |
| 65 const blink::WebString& presentationId, | |
| 66 const blink::WebString& message); | |
| 67 virtual void postMessage( | |
| 68 const blink::WebString& presentationUrl, | |
| 69 const blink::WebString& presentationId, | |
| 70 const char* data, | |
| 71 size_t length); | |
| 44 virtual void closeSession( | 72 virtual void closeSession( |
| 45 const blink::WebString& presentationUrl, | 73 const blink::WebString& presentationUrl, |
| 46 const blink::WebString& presentationId); | 74 const blink::WebString& presentationId); |
| 47 | 75 |
| 48 // RenderFrameObserver | 76 // RenderFrameObserver |
| 49 void DidChangeDefaultPresentation() override; | 77 void DidChangeDefaultPresentation() override; |
| 50 | 78 |
| 51 void OnScreenAvailabilityChanged( | 79 void OnScreenAvailabilityChanged( |
| 52 const std::string& presentation_url, | 80 const std::string& presentation_url, |
| 53 bool available); | 81 bool available); |
| 54 void OnSessionCreated( | 82 void OnSessionCreated( |
| 55 blink::WebPresentationSessionClientCallbacks* callback, | 83 blink::WebPresentationSessionClientCallbacks* callback, |
| 56 presentation::PresentationSessionInfoPtr session_info, | 84 presentation::PresentationSessionInfoPtr session_info, |
| 57 presentation::PresentationErrorPtr error); | 85 presentation::PresentationErrorPtr error); |
| 58 void OnDefaultSessionStarted( | 86 void OnDefaultSessionStarted( |
| 59 presentation::PresentationSessionInfoPtr session_info); | 87 presentation::PresentationSessionInfoPtr session_info); |
| 60 | 88 |
| 61 void ConnectToPresentationServiceIfNeeded(); | 89 void ConnectToPresentationServiceIfNeeded(); |
| 62 | 90 |
| 63 void DoUpdateAvailableChangeWatched( | 91 void DoUpdateAvailableChangeWatched( |
| 64 const std::string& presentation_url, | 92 const std::string& presentation_url, |
| 65 bool watched); | 93 bool watched); |
| 66 | 94 |
| 95 void PostMessagesOfFirstSession(); | |
| 96 | |
| 97 void HandlePostMessageRequests(); | |
| 98 | |
| 99 void DoPostMessages( | |
| 100 const std::string& presentation_url, | |
| 101 const std::string& presentation_id, | |
| 102 std::vector<std::string> string_messages); | |
| 103 | |
| 104 void RemovePostMessageRequestsOfFirstSession(); | |
| 105 | |
| 67 // Used as a weak reference. Can be null since lifetime is bound to the frame. | 106 // Used as a weak reference. Can be null since lifetime is bound to the frame. |
| 68 blink::WebPresentationController* controller_; | 107 blink::WebPresentationController* controller_; |
| 69 presentation::PresentationServicePtr presentation_service_; | 108 presentation::PresentationServicePtr presentation_service_; |
| 70 | 109 |
| 71 // Wrappers around the PresentationSessionPtr corresponding to each Javascript | 110 // Wrappers around the PresentationSessionPtr corresponding to each Javascript |
| 72 // PresentationSession object passed back to the frame. | 111 // PresentationSession object passed back to the frame. |
| 73 // TODO(avayvod): Switch to base::IDMap when the lookup by presentation id is | 112 // TODO(avayvod): Switch to base::IDMap when the lookup by presentation id is |
| 74 // needed. | 113 // needed. |
| 75 using PresentationSessionDispatchers = | 114 using PresentationSessionDispatchers = |
| 76 ScopedVector<PresentationSessionDispatcher>; | 115 ScopedVector<PresentationSessionDispatcher>; |
| 77 PresentationSessionDispatchers presentation_session_dispatchers_; | 116 PresentationSessionDispatchers presentation_session_dispatchers_; |
| 117 | |
| 118 // Map of presentation ID to its postMessage requests. | |
| 119 typedef std::vector<linked_ptr<PostMessageRequest>> PostMessageVector; | |
|
imcheng
2015/04/02 23:57:24
using PostMessageVector = std::vector<linked_ptr<P
USE s.singapati at gmail.com
2015/04/07 17:45:16
Done.
| |
| 120 typedef base::hash_map<std::string, linked_ptr<PostMessageVector>> | |
| 121 PostMessageRequestMap; | |
| 122 | |
| 123 PostMessageRequestMap post_message_requests_map_; | |
|
imcheng
2015/04/02 23:57:24
If we are sending 1 message per mojo call (I think
USE s.singapati at gmail.com
2015/04/07 17:45:16
Acknowledged. Simple queuing approach in new patch
| |
| 78 }; | 124 }; |
| 79 | 125 |
| 80 } // namespace content | 126 } // namespace content |
| 81 | 127 |
| 82 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ | 128 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ |
| OLD | NEW |