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

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

Issue 1037483003: [PresentationAPI] Implementing send() from WebPresentationClient to the PresentationService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No (c) in new files Copyright message. Created 5 years, 7 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
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "content/renderer/presentation/presentation_dispatcher.h" 5 #include "content/renderer/presentation/presentation_dispatcher.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/common/presentation/presentation_service.mojom.h" 8 #include "content/common/presentation/presentation_service.mojom.h"
9 #include "content/public/common/presentation_constants.h"
9 #include "content/public/common/service_registry.h" 10 #include "content/public/common/service_registry.h"
10 #include "content/public/renderer/render_frame.h" 11 #include "content/public/renderer/render_frame.h"
11 #include "content/renderer/presentation/presentation_session_client.h" 12 #include "content/renderer/presentation/presentation_session_client.h"
12 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h" 14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nController.h"
14 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h" 15 #include "third_party/WebKit/public/platform/modules/presentation/WebPresentatio nError.h"
15 #include "third_party/WebKit/public/web/WebDocument.h" 16 #include "third_party/WebKit/public/web/WebDocument.h"
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 // OnSessionCreated() is called. |callback| needs to be alive and also needs 126 // OnSessionCreated() is called. |callback| needs to be alive and also needs
126 // to be destroyed so we transfer its ownership to the mojo callback. 127 // to be destroyed so we transfer its ownership to the mojo callback.
127 presentation_service_->JoinSession( 128 presentation_service_->JoinSession(
128 presentationUrl.utf8(), 129 presentationUrl.utf8(),
129 presentationId.utf8(), 130 presentationId.utf8(),
130 base::Bind(&PresentationDispatcher::OnSessionCreated, 131 base::Bind(&PresentationDispatcher::OnSessionCreated,
131 base::Unretained(this), 132 base::Unretained(this),
132 base::Owned(callback))); 133 base::Owned(callback)));
133 } 134 }
134 135
136 void PresentationDispatcher::sendString(
137 const blink::WebString& presentationUrl,
138 const blink::WebString& presentationId,
139 const blink::WebString& message) {
140 if (message.utf8().size() > kMaxPresentationSessionMessageSize) {
141 // TODO(crbug.com/459008): Limit the size of individual messages to 64k
142 // for now. Consider throwing DOMException or splitting bigger messages
143 // into smaller chunks later.
144 LOG(WARNING) << "message size exceeded limit!";
145 return;
146 }
147
148 presentation::SessionMessage* session_message =
149 new presentation::SessionMessage();
150 session_message->presentation_url = presentationUrl.utf8();
151 session_message->presentation_id = presentationId.utf8();
152 session_message->type = presentation::PresentationMessageType::
153 PRESENTATION_MESSAGE_TYPE_TEXT;
154 session_message->message = message.utf8();
155
156 message_request_queue_.push(make_linked_ptr(session_message));
157 // Start processing request if only one in the queue.
158 if (message_request_queue_.size() == 1) {
159 const linked_ptr<presentation::SessionMessage>& request =
160 message_request_queue_.front();
161 DoSendMessage(*request);
162 }
163 }
164
165 void PresentationDispatcher::sendArrayBuffer(
166 const blink::WebString& presentationUrl,
167 const blink::WebString& presentationId,
168 const uint8* data,
169 size_t length) {
170 DCHECK(data);
171 if (length > kMaxPresentationSessionMessageSize) {
172 // TODO(crbug.com/459008): Same as in sendString().
173 LOG(WARNING) << "data size exceeded limit!";
174 return;
175 }
176
177 const std::vector<uint8> vector(data, data + length);
178 presentation::SessionMessage* session_message =
179 new presentation::SessionMessage();
180 session_message->presentation_url = presentationUrl.utf8();
181 session_message->presentation_id = presentationId.utf8();
182 session_message->type = presentation::PresentationMessageType::
183 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
184 session_message->data = mojo::Array<uint8>::From(vector);
185
186 message_request_queue_.push(make_linked_ptr(session_message));
187 // Start processing request if only one in the queue.
188 if (message_request_queue_.size() == 1) {
189 const linked_ptr<presentation::SessionMessage>& request =
190 message_request_queue_.front();
191 DoSendMessage(*request);
192 }
193 }
194
195 void PresentationDispatcher::DoSendMessage(
196 const presentation::SessionMessage& session_message) {
197 ConnectToPresentationServiceIfNeeded();
198
199 presentation::SessionMessagePtr message_request(
200 presentation::SessionMessage::New());
201 message_request->presentation_url = session_message.presentation_url;
202 message_request->presentation_id = session_message.presentation_id;
203 message_request->type = session_message.type;
204 if (session_message.type == presentation::PresentationMessageType::
205 PRESENTATION_MESSAGE_TYPE_TEXT) {
206 message_request->message = session_message.message;
207 } else if (session_message.type == presentation::PresentationMessageType::
208 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) {
209 message_request->data = mojo::Array<uint8>::From(
210 session_message.data.storage());
211 }
212
213 presentation_service_->SendSessionMessage(
214 message_request.Pass(),
215 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
216 base::Unretained(this)));
217 }
218
219 void PresentationDispatcher::HandleSendMessageRequests(bool success) {
220 // In normal cases, message_request_queue_ should not be empty at this point
221 // of time, but when DidCommitProvisionalLoad() is invoked before receiving
222 // the callback for previous send mojo call, queue would have been emptied.
223 if (message_request_queue_.empty())
224 return;
225
226 if (!success) {
227 // PresentationServiceImpl is informing that Frame has been detached or
228 // navigated away. Invalidate all pending requests.
229 MessageRequestQueue empty;
230 std::swap(message_request_queue_, empty);
231 return;
232 }
233
234 message_request_queue_.pop();
235 if (!message_request_queue_.empty()) {
236 const linked_ptr<presentation::SessionMessage>& request =
237 message_request_queue_.front();
238 DoSendMessage(*request);
239 }
240 }
241
135 void PresentationDispatcher::closeSession( 242 void PresentationDispatcher::closeSession(
136 const blink::WebString& presentationUrl, 243 const blink::WebString& presentationUrl,
137 const blink::WebString& presentationId) { 244 const blink::WebString& presentationId) {
138 ConnectToPresentationServiceIfNeeded(); 245 ConnectToPresentationServiceIfNeeded();
139 246
140 presentation_service_->CloseSession( 247 presentation_service_->CloseSession(
141 presentationUrl.utf8(), 248 presentationUrl.utf8(),
142 presentationId.utf8()); 249 presentationId.utf8());
143 } 250 }
144 251
145 void PresentationDispatcher::DidChangeDefaultPresentation() { 252 void PresentationDispatcher::DidChangeDefaultPresentation() {
146 GURL presentation_url(GetPresentationURLFromFrame(render_frame())); 253 GURL presentation_url(GetPresentationURLFromFrame(render_frame()));
147 254
148 ConnectToPresentationServiceIfNeeded(); 255 ConnectToPresentationServiceIfNeeded();
149 presentation_service_->SetDefaultPresentationURL( 256 presentation_service_->SetDefaultPresentationURL(
150 presentation_url.spec(), mojo::String()); 257 presentation_url.spec(), mojo::String());
151 } 258 }
152 259
260 void PresentationDispatcher::DidCommitProvisionalLoad(
261 bool is_new_navigation,
262 bool is_same_page_navigation) {
263 blink::WebFrame* frame = render_frame()->GetWebFrame();
264 // If not top-level navigation.
265 if (frame->parent() || is_same_page_navigation)
266 return;
267
268 // Remove all pending send message requests.
269 MessageRequestQueue empty;
270 std::swap(message_request_queue_, empty);
271 }
272
153 void PresentationDispatcher::OnScreenAvailabilityChanged( 273 void PresentationDispatcher::OnScreenAvailabilityChanged(
154 const std::string& presentation_url, bool available) { 274 const std::string& presentation_url, bool available) {
155 if (!controller_) 275 if (!controller_)
156 return; 276 return;
157 277
158 // Reset the callback to get the next event. 278 // Reset the callback to get the next event.
159 DoUpdateAvailableChangeWatched(presentation_url, 279 DoUpdateAvailableChangeWatched(presentation_url,
160 controller_->isAvailableChangeWatched()); 280 controller_->isAvailableChangeWatched());
161 281
162 controller_->didChangeAvailability(available); 282 controller_->didChangeAvailability(available);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 presentation_service_->ListenForSessionStateChange(base::Bind( 369 presentation_service_->ListenForSessionStateChange(base::Bind(
250 &PresentationDispatcher::OnSessionStateChange, 370 &PresentationDispatcher::OnSessionStateChange,
251 base::Unretained(this))); 371 base::Unretained(this)));
252 presentation_service_->ListenForSessionMessages( 372 presentation_service_->ListenForSessionMessages(
253 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, 373 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
254 base::Unretained(this))); 374 base::Unretained(this)));
255 */ 375 */
256 } 376 }
257 377
258 } // namespace content 378 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/presentation/presentation_dispatcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698