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

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: reverted "using presentation::PresentationMessageType" Created 5 years, 6 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/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 presentation::PresentationMessageType type,
61 const uint8* data,
62 size_t length) {
63 presentation::SessionMessage* session_message =
64 new presentation::SessionMessage();
65 session_message->presentation_url = presentationUrl.utf8();
66 session_message->presentation_id = presentationId.utf8();
67 session_message->type = type;
68 const std::vector<uint8> vector(data, data + length);
69 session_message->data = mojo::Array<uint8>::From(vector);
70 return session_message;
71 }
72
57 } // namespace 73 } // namespace
58 74
59 namespace content { 75 namespace content {
60 76
61 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame) 77 PresentationDispatcher::PresentationDispatcher(RenderFrame* render_frame)
62 : RenderFrameObserver(render_frame), 78 : RenderFrameObserver(render_frame),
63 controller_(nullptr), 79 controller_(nullptr),
64 binding_(this) { 80 binding_(this) {
65 } 81 }
66 82
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 const blink::WebString& presentationId, 174 const blink::WebString& presentationId,
159 const uint8* data, 175 const uint8* data,
160 size_t length) { 176 size_t length) {
161 DCHECK(data); 177 DCHECK(data);
162 if (length > kMaxPresentationSessionMessageSize) { 178 if (length > kMaxPresentationSessionMessageSize) {
163 // TODO(crbug.com/459008): Same as in sendString(). 179 // TODO(crbug.com/459008): Same as in sendString().
164 LOG(WARNING) << "data size exceeded limit!"; 180 LOG(WARNING) << "data size exceeded limit!";
165 return; 181 return;
166 } 182 }
167 183
168 const std::vector<uint8> vector(data, data + length);
169 presentation::SessionMessage* session_message = 184 presentation::SessionMessage* session_message =
170 new presentation::SessionMessage(); 185 GetMojoSessionMessage(presentationUrl, presentationId,
171 session_message->presentation_url = presentationUrl.utf8(); 186 presentation::PresentationMessageType::
172 session_message->presentation_id = presentationId.utf8(); 187 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER,
173 session_message->type = presentation::PresentationMessageType:: 188 data, length);
174 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)); 189 message_request_queue_.push(make_linked_ptr(session_message));
178 // Start processing request if only one in the queue. 190 // Start processing request if only one in the queue.
179 if (message_request_queue_.size() == 1) { 191 if (message_request_queue_.size() == 1) {
180 const linked_ptr<presentation::SessionMessage>& request = 192 const linked_ptr<presentation::SessionMessage>& request =
181 message_request_queue_.front(); 193 message_request_queue_.front();
182 DoSendMessage(*request); 194 DoSendMessage(*request);
183 } 195 }
184 } 196 }
185 197
198 void PresentationDispatcher::sendBlobData(
199 const blink::WebString& presentationUrl,
200 const blink::WebString& presentationId,
201 const uint8* data,
202 size_t length) {
203 DCHECK(data);
204 if (length > kMaxPresentationSessionMessageSize) {
205 // TODO(crbug.com/459008): Same as in sendString().
206 LOG(WARNING) << "data size exceeded limit!";
207 return;
208 }
209
210 presentation::SessionMessage* session_message = GetMojoSessionMessage(
211 presentationUrl, presentationId,
212 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB,
213 data, length);
214 message_request_queue_.push(make_linked_ptr(session_message));
215 if (message_request_queue_.size() == 1) {
216 const linked_ptr<presentation::SessionMessage>& request =
217 message_request_queue_.front();
218 DoSendMessage(*request);
219 }
220 }
221
186 void PresentationDispatcher::DoSendMessage( 222 void PresentationDispatcher::DoSendMessage(
187 const presentation::SessionMessage& session_message) { 223 const presentation::SessionMessage& session_message) {
188 ConnectToPresentationServiceIfNeeded(); 224 ConnectToPresentationServiceIfNeeded();
189
190 presentation::SessionMessagePtr message_request( 225 presentation::SessionMessagePtr message_request(
191 presentation::SessionMessage::New()); 226 presentation::SessionMessage::New());
192 message_request->presentation_url = session_message.presentation_url; 227 message_request->presentation_url = session_message.presentation_url;
193 message_request->presentation_id = session_message.presentation_id; 228 message_request->presentation_id = session_message.presentation_id;
194 message_request->type = session_message.type; 229 message_request->type = session_message.type;
195 if (session_message.type == presentation::PresentationMessageType:: 230 switch (session_message.type) {
196 PRESENTATION_MESSAGE_TYPE_TEXT) { 231 case presentation::PresentationMessageType::
197 message_request->message = session_message.message; 232 PRESENTATION_MESSAGE_TYPE_TEXT: {
198 } else if (session_message.type == presentation::PresentationMessageType:: 233 message_request->message = session_message.message;
199 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) { 234 break;
200 message_request->data = mojo::Array<uint8>::From( 235 }
201 session_message.data.storage()); 236 case presentation::PresentationMessageType::
237 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER:
238 case presentation::PresentationMessageType::
239 PRESENTATION_MESSAGE_TYPE_BLOB: {
240 message_request->data =
241 mojo::Array<uint8>::From(session_message.data.storage());
242 break;
243 }
244 default: {
245 NOTREACHED() << "Invalid presentation message type "
246 << session_message.type;
247 break;
248 }
202 } 249 }
203 250
204 presentation_service_->SendSessionMessage( 251 presentation_service_->SendSessionMessage(
205 message_request.Pass(), 252 message_request.Pass(),
206 base::Bind(&PresentationDispatcher::HandleSendMessageRequests, 253 base::Bind(&PresentationDispatcher::HandleSendMessageRequests,
207 base::Unretained(this))); 254 base::Unretained(this)));
208 } 255 }
209 256
210 void PresentationDispatcher::HandleSendMessageRequests(bool success) { 257 void PresentationDispatcher::HandleSendMessageRequests(bool success) {
211 // In normal cases, message_request_queue_ should not be empty at this point 258 // In normal cases, message_request_queue_ should not be empty at this point
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 presentation_service_->ListenForSessionStateChange(base::Bind( 404 presentation_service_->ListenForSessionStateChange(base::Bind(
358 &PresentationDispatcher::OnSessionStateChange, 405 &PresentationDispatcher::OnSessionStateChange,
359 base::Unretained(this))); 406 base::Unretained(this)));
360 presentation_service_->ListenForSessionMessages( 407 presentation_service_->ListenForSessionMessages(
361 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived, 408 base::Bind(&PresentationDispatcher::OnSessionMessagesReceived,
362 base::Unretained(this))); 409 base::Unretained(this)));
363 */ 410 */
364 } 411 }
365 412
366 } // namespace content 413 } // 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