Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Side by Side Diff: content/renderer/presentation/presentation_dispatcher.h

Issue 2622993002: [Presentation API] Move presentation.mojom to content/common/presentation (Closed)
Patch Set: Fix #include and OWNERS Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <map> 11 #include <map>
12 #include <memory> 12 #include <memory>
13 #include <queue> 13 #include <queue>
14 #include <set> 14 #include <set>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/id_map.h" 19 #include "base/id_map.h"
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "content/common/content_export.h" 21 #include "content/common/content_export.h"
22 #include "content/common/presentation/presentation.mojom.h"
22 #include "content/public/renderer/render_frame_observer.h" 23 #include "content/public/renderer/render_frame_observer.h"
23 #include "mojo/public/cpp/bindings/binding.h" 24 #include "mojo/public/cpp/bindings/binding.h"
24 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nClient.h" 25 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nClient.h"
25 #include "third_party/WebKit/public/platform/modules/presentation/presentation.m ojom.h"
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace blink { 28 namespace blink {
29 class WebPresentationAvailabilityObserver; 29 class WebPresentationAvailabilityObserver;
30 class WebPresentationReceiver; 30 class WebPresentationReceiver;
31 class WebString; 31 class WebString;
32 class WebURL; 32 class WebURL;
33 template <typename T> 33 template <typename T>
34 class WebVector; 34 class WebVector;
35 } // namespace blink 35 } // namespace blink
36 36
37 namespace content { 37 namespace content {
38 38
39 class TestPresentationDispatcher; 39 class TestPresentationDispatcher;
40 40
41 // PresentationDispatcher is a delegate for Presentation API messages used by 41 // PresentationDispatcher is a delegate for Presentation API messages used by
42 // Blink. It forwards the calls to the Mojo PresentationService. 42 // Blink. It forwards the calls to the Mojo PresentationService.
43 class CONTENT_EXPORT PresentationDispatcher 43 class CONTENT_EXPORT PresentationDispatcher
44 : public RenderFrameObserver, 44 : public RenderFrameObserver,
45 public NON_EXPORTED_BASE(blink::WebPresentationClient), 45 public NON_EXPORTED_BASE(blink::WebPresentationClient),
46 public NON_EXPORTED_BASE(blink::mojom::PresentationServiceClient) { 46 public NON_EXPORTED_BASE(content::mojom::PresentationServiceClient) {
47 public: 47 public:
48 explicit PresentationDispatcher(RenderFrame* render_frame); 48 explicit PresentationDispatcher(RenderFrame* render_frame);
49 ~PresentationDispatcher() override; 49 ~PresentationDispatcher() override;
50 50
51 private: 51 private:
52 friend class TestPresentationDispatcher; 52 friend class TestPresentationDispatcher;
53 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession); 53 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSession);
54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError); 54 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestStartSessionError);
55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession); 55 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSession);
56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError); 56 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestJoinSessionError);
57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString); 57 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendString);
58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer); 58 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendArrayBuffer);
59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData); 59 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestSendBlobData);
60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession); 60 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestCloseSession);
61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession); 61 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, TestTerminateSession);
62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, 62 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest,
63 TestListenForScreenAvailability); 63 TestListenForScreenAvailability);
64 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest, 64 FRIEND_TEST_ALL_PREFIXES(PresentationDispatcherTest,
65 TestSetDefaultPresentationUrls); 65 TestSetDefaultPresentationUrls);
66 66
67 struct SendMessageRequest { 67 struct SendMessageRequest {
68 SendMessageRequest(blink::mojom::PresentationSessionInfoPtr session_info, 68 SendMessageRequest(content::mojom::PresentationSessionInfoPtr session_info,
69 blink::mojom::ConnectionMessagePtr message); 69 content::mojom::ConnectionMessagePtr message);
70 ~SendMessageRequest(); 70 ~SendMessageRequest();
71 71
72 blink::mojom::PresentationSessionInfoPtr session_info; 72 content::mojom::PresentationSessionInfoPtr session_info;
73 blink::mojom::ConnectionMessagePtr message; 73 content::mojom::ConnectionMessagePtr message;
74 }; 74 };
75 75
76 static SendMessageRequest* CreateSendTextMessageRequest( 76 static SendMessageRequest* CreateSendTextMessageRequest(
77 const blink::WebURL& presentationUrl, 77 const blink::WebURL& presentationUrl,
78 const blink::WebString& presentationId, 78 const blink::WebString& presentationId,
79 const blink::WebString& message); 79 const blink::WebString& message);
80 static SendMessageRequest* CreateSendBinaryMessageRequest( 80 static SendMessageRequest* CreateSendBinaryMessageRequest(
81 const blink::WebURL& presentationUrl, 81 const blink::WebURL& presentationUrl,
82 const blink::WebString& presentationId, 82 const blink::WebString& presentationId,
83 blink::mojom::PresentationMessageType type, 83 content::mojom::PresentationMessageType type,
84 const uint8_t* data, 84 const uint8_t* data,
85 size_t length); 85 size_t length);
86 86
87 // WebPresentationClient implementation. 87 // WebPresentationClient implementation.
88 void setController(blink::WebPresentationController* controller) override; 88 void setController(blink::WebPresentationController* controller) override;
89 void setReceiver(blink::WebPresentationReceiver*) override; 89 void setReceiver(blink::WebPresentationReceiver*) override;
90 90
91 void startSession(const blink::WebVector<blink::WebURL>& presentationUrls, 91 void startSession(const blink::WebVector<blink::WebURL>& presentationUrls,
92 std::unique_ptr<blink::WebPresentationConnectionCallback> 92 std::unique_ptr<blink::WebPresentationConnectionCallback>
93 callback) override; 93 callback) override;
(...skipping 24 matching lines...) Expand all
118 void stopListening(blink::WebPresentationAvailabilityObserver*) override; 118 void stopListening(blink::WebPresentationAvailabilityObserver*) override;
119 void setDefaultPresentationUrls( 119 void setDefaultPresentationUrls(
120 const blink::WebVector<blink::WebURL>& presentationUrls) override; 120 const blink::WebVector<blink::WebURL>& presentationUrls) override;
121 121
122 // RenderFrameObserver implementation. 122 // RenderFrameObserver implementation.
123 void DidCommitProvisionalLoad( 123 void DidCommitProvisionalLoad(
124 bool is_new_navigation, 124 bool is_new_navigation,
125 bool is_same_page_navigation) override; 125 bool is_same_page_navigation) override;
126 void OnDestruct() override; 126 void OnDestruct() override;
127 127
128 // blink::mojom::PresentationServiceClient 128 // content::mojom::PresentationServiceClient
129 void OnScreenAvailabilityNotSupported(const GURL& url) override; 129 void OnScreenAvailabilityNotSupported(const GURL& url) override;
130 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override; 130 void OnScreenAvailabilityUpdated(const GURL& url, bool available) override;
131 void OnConnectionStateChanged( 131 void OnConnectionStateChanged(
132 blink::mojom::PresentationSessionInfoPtr session_info, 132 content::mojom::PresentationSessionInfoPtr session_info,
133 blink::mojom::PresentationConnectionState state) override; 133 content::mojom::PresentationConnectionState state) override;
134 void OnConnectionClosed( 134 void OnConnectionClosed(
135 blink::mojom::PresentationSessionInfoPtr session_info, 135 content::mojom::PresentationSessionInfoPtr session_info,
136 blink::mojom::PresentationConnectionCloseReason reason, 136 content::mojom::PresentationConnectionCloseReason reason,
137 const std::string& message) override; 137 const std::string& message) override;
138 void OnConnectionMessagesReceived( 138 void OnConnectionMessagesReceived(
139 blink::mojom::PresentationSessionInfoPtr session_info, 139 content::mojom::PresentationSessionInfoPtr session_info,
140 std::vector<blink::mojom::ConnectionMessagePtr> messages) override; 140 std::vector<content::mojom::ConnectionMessagePtr> messages) override;
141 void OnDefaultSessionStarted( 141 void OnDefaultSessionStarted(
142 blink::mojom::PresentationSessionInfoPtr session_info) override; 142 content::mojom::PresentationSessionInfoPtr session_info) override;
143 143
144 void OnSessionCreated( 144 void OnSessionCreated(
145 std::unique_ptr<blink::WebPresentationConnectionCallback> callback, 145 std::unique_ptr<blink::WebPresentationConnectionCallback> callback,
146 blink::mojom::PresentationSessionInfoPtr session_info, 146 content::mojom::PresentationSessionInfoPtr session_info,
147 blink::mojom::PresentationErrorPtr error); 147 content::mojom::PresentationErrorPtr error);
148 void OnReceiverConnectionAvailable( 148 void OnReceiverConnectionAvailable(
149 blink::mojom::PresentationSessionInfoPtr) override; 149 content::mojom::PresentationSessionInfoPtr) override;
150 150
151 // Call to PresentationService to send the message in |request|. 151 // Call to PresentationService to send the message in |request|.
152 // |session_info| and |message| of |reuqest| will be consumed. 152 // |session_info| and |message| of |reuqest| will be consumed.
153 // |HandleSendMessageRequests| will be invoked after the send is attempted. 153 // |HandleSendMessageRequests| will be invoked after the send is attempted.
154 void DoSendMessage(SendMessageRequest* request); 154 void DoSendMessage(SendMessageRequest* request);
155 void HandleSendMessageRequests(bool success); 155 void HandleSendMessageRequests(bool success);
156 156
157 virtual void ConnectToPresentationServiceIfNeeded(); 157 virtual void ConnectToPresentationServiceIfNeeded();
158 158
159 void UpdateListeningState(); 159 void UpdateListeningState();
160 160
161 // Used as a weak reference. Can be null since lifetime is bound to the frame. 161 // Used as a weak reference. Can be null since lifetime is bound to the frame.
162 blink::WebPresentationController* controller_; 162 blink::WebPresentationController* controller_;
163 blink::WebPresentationReceiver* receiver_; 163 blink::WebPresentationReceiver* receiver_;
164 blink::mojom::PresentationServicePtr presentation_service_; 164 content::mojom::PresentationServicePtr presentation_service_;
165 mojo::Binding<blink::mojom::PresentationServiceClient> binding_; 165 mojo::Binding<content::mojom::PresentationServiceClient> binding_;
166 166
167 // Message requests are queued here and only one message at a time is sent 167 // Message requests are queued here and only one message at a time is sent
168 // over mojo channel. 168 // over mojo channel.
169 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>; 169 using MessageRequestQueue = std::queue<std::unique_ptr<SendMessageRequest>>;
170 MessageRequestQueue message_request_queue_; 170 MessageRequestQueue message_request_queue_;
171 171
172 enum class ListeningState { 172 enum class ListeningState {
173 INACTIVE, 173 INACTIVE,
174 WAITING, 174 WAITING,
175 ACTIVE, 175 ACTIVE,
(...skipping 23 matching lines...) Expand all
199 // Updates the listening state of availability for |status| and notifies the 199 // Updates the listening state of availability for |status| and notifies the
200 // client. 200 // client.
201 void UpdateListeningState(AvailabilityStatus* status); 201 void UpdateListeningState(AvailabilityStatus* status);
202 202
203 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher); 203 DISALLOW_COPY_AND_ASSIGN(PresentationDispatcher);
204 }; 204 };
205 205
206 } // namespace content 206 } // namespace content
207 207
208 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_ 208 #endif // CONTENT_RENDERER_PRESENTATION_PRESENTATION_DISPATCHER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698