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

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

Issue 1140713005: [PresentationAPI] Implements send API for Blob data from WebPresentationClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated unit tests 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
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/presentation_constants.h"
10 #include "content/public/common/service_registry.h" 10 #include "content/public/common/service_registry.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 return blink::WebPresentationSessionState::Disconnected; 47 return blink::WebPresentationSessionState::Disconnected;
48 } 48 }
49 49
50 GURL GetPresentationURLFromFrame(content::RenderFrame* frame) { 50 GURL GetPresentationURLFromFrame(content::RenderFrame* frame) {
51 DCHECK(frame); 51 DCHECK(frame);
52 52
53 GURL url(frame->GetWebFrame()->document().defaultPresentationURL()); 53 GURL url(frame->GetWebFrame()->document().defaultPresentationURL());
54 return url.is_valid() ? url : GURL(); 54 return url.is_valid() ? url : GURL();
55 } 55 }
56 56
57 presentation::SessionMessage* GetMojoSessionMessage(
58 const blink::WebString& presentationUrl,
59 const blink::WebString& presentationId,
60 const uint8* data,
61 size_t length) {
62 presentation::SessionMessage* session_message =
63 new presentation::SessionMessage();
64 session_message->presentation_url = presentationUrl.utf8();
65 session_message->presentation_id = presentationId.utf8();
66 const std::vector<uint8> vector(data, data + length);
67 session_message->data = mojo::Array<uint8>::From(vector);
68 // Fill session_message->type in the caller.
mark a. foltz 2015/06/02 23:51:02 Why not pass the type as an argument and fill it i
USE s.singapati at gmail.com 2015/06/03 15:03:50 Done. Well, Yes.
69 return session_message;
70 }
71
57 } // namespace 72 } // namespace
58 73
59 namespace content { 74 namespace content {
60 75
61 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) 76 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
62 : RenderFrameObserver(render_frame), 77 : RenderFrameObserver(render_frame),
63 controller_(nullptr), 78 controller_(nullptr),
64 binding_(this) { 79 binding_(this) {
65 } 80 }
66 81
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const blink::WebString& presentationId, 173 const blink::WebString& presentationId,
159 const uint8* data, 174 const uint8* data,
160 size_t length) { 175 size_t length) {
161 DCHECK(data); 176 DCHECK(data);
162 if (length > kMaxPresentationSessionMessageSize) { 177 if (length > kMaxPresentationSessionMessageSize) {
163 // TODO(crbug.com/459008): Same as in sendString(). 178 // TODO(crbug.com/459008): Same as in sendString().
164 LOG(WARNING) << "data size exceeded limit!"; 179 LOG(WARNING) << "data size exceeded limit!";
165 return; 180 return;
166 } 181 }
167 182
168 const std::vector<uint8> vector(data, data + length);
169 presentation::SessionMessage* session_message = 183 presentation::SessionMessage* session_message =
170 new presentation::SessionMessage(); 184 GetMojoSessionMessage(presentationUrl, presentationId, data, length);
171 session_message->presentation_url = presentationUrl.utf8();
172 session_message->presentation_id = presentationId.utf8();
173 session_message->type = presentation::PresentationMessageType:: 185 session_message->type = presentation::PresentationMessageType::
174 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; 186 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
175 session_message->data = mojo::Array<uint8>::From(vector);
176
177 message_request_queue_.push(make_linked_ptr(session_message)); 187 message_request_queue_.push(make_linked_ptr(session_message));
178 // Start processing request if only one in the queue. 188 // Start processing request if only one in the queue.
179 if (message_request_queue_.size() == 1) { 189 if (message_request_queue_.size() == 1) {
180 const linked_ptr<presentation::SessionMessage>& request = 190 const linked_ptr<presentation::SessionMessage>& request =
181 message_request_queue_.front(); 191 message_request_queue_.front();
182 DoSendMessage(*request); 192 DoSendMessage(*request);
183 } 193 }
184 } 194 }
185 195
196 void PresentationDispatcher::sendBlobData(
197 const blink::WebString& presentationUrl,
198 const blink::WebString& presentationId,
199 const uint8* data,
200 size_t length) {
201 DCHECK(data);
202 if (length > kMaxPresentationSessionMessageSize) {
203 // TODO(crbug.com/459008): Same as in sendString().
204 LOG(WARNING) << "data size exceeded limit!";
205 return;
206 }
207
208 presentation::SessionMessage* session_message =
209 GetMojoSessionMessage(presentationUrl, presentationId, data, length);
210 session_message->type = presentation::PresentationMessageType::
211 PRESENTATION_MESSAGE_TYPE_BLOB;
212 message_request_queue_.push(make_linked_ptr(session_message));
213 if (message_request_queue_.size() == 1) {
214 const linked_ptr<presentation::SessionMessage>& request =
215 message_request_queue_.front();
216 DoSendMessage(*request);
217 }
218 }
219
186 void PresentationDispatcher::DoSendMessage( 220 void PresentationDispatcher::DoSendMessage(
187 const presentation::SessionMessage& session_message) { 221 const presentation::SessionMessage& session_message) {
188 ConnectToPresentationServiceIfNeeded(); 222 ConnectToPresentationServiceIfNeeded();
189 223
190 presentation::SessionMessagePtr message_request( 224 presentation::SessionMessagePtr message_request(
191 presentation::SessionMessage::New()); 225 presentation::SessionMessage::New());
192 message_request->presentation_url = session_message.presentation_url; 226 message_request->presentation_url = session_message.presentation_url;
193 message_request->presentation_id = session_message.presentation_id; 227 message_request->presentation_id = session_message.presentation_id;
194 message_request->type = session_message.type; 228 message_request->type = session_message.type;
195 if (session_message.type == presentation::PresentationMessageType:: 229 if (session_message.type == presentation::PresentationMessageType::
196 PRESENTATION_MESSAGE_TYPE_TEXT) { 230 PRESENTATION_MESSAGE_TYPE_TEXT) {
197 message_request->message = session_message.message; 231 message_request->message = session_message.message;
198 } else if (session_message.type == presentation::PresentationMessageType:: 232 } else {
199 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) { 233 // ArrayBuffer or Blob types.
mark a. foltz 2015/06/02 23:51:02 Prefer seeing a switch { } statement here with a d
USE s.singapati at gmail.com 2015/06/03 15:03:50 Done.
200 message_request->data = mojo::Array<uint8>::From( 234 message_request->data = mojo::Array<uint8>::From(
201 session_message.data.storage()); 235 session_message.data.storage());
202 } 236 }
203 237
204 presentation_service_->SendSessionMessage( 238 presentation_service_->SendSessionMessage(
205 message_request.Pass(), 239 message_request.Pass(),
206 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, 240 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
207 base::Unretained(this))); 241 base::Unretained(this)));
208 } 242 }
209 243
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 presentation_service_->ListenForSessionStateChange(base::Bind( 391 presentation_service_->ListenForSessionStateChange(base::Bind(
358 &PresentationDispatcher::OnSessionStateChange, 392 &PresentationDispatcher::OnSessionStateChange,
359 base::Unretained(this))); 393 base::Unretained(this)));
360 presentation_service_->ListenForSessionMessages( 394 presentation_service_->ListenForSessionMessages(
361 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, 395 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
362 base::Unretained(this))); 396 base::Unretained(this)));
363 */ 397 */
364 } 398 }
365 399
366 } // namespace content 400 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698