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

Side by Side Diff: content/browser/presentation/presentation_service_impl.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: 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 | « no previous file | content/browser/presentation/presentation_service_impl_unittest.cc » ('j') | 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/browser/presentation/presentation_service_impl.h" 5 #include "content/browser/presentation/presentation_service_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/browser/presentation/presentation_type_converters.h" 10 #include "content/browser/presentation/presentation_type_converters.h"
11 #include "content/public/browser/content_browser_client.h" 11 #include "content/public/browser/content_browser_client.h"
12 #include "content/public/browser/navigation_details.h" 12 #include "content/public/browser/navigation_details.h"
13 #include "content/public/browser/presentation_session_message.h" 13 #include "content/public/browser/presentation_session_message.h"
14 #include "content/public/browser/render_frame_host.h" 14 #include "content/public/browser/render_frame_host.h"
15 #include "content/public/browser/render_process_host.h" 15 #include "content/public/browser/render_process_host.h"
16 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
17 #include "content/public/common/content_client.h" 17 #include "content/public/common/content_client.h"
18 #include "content/public/common/frame_navigate_params.h" 18 #include "content/public/common/frame_navigate_params.h"
19 #include "content/public/common/presentation_constants.h" 19 #include "content/public/common/presentation_constants.h"
20 20
21 namespace content { 21 namespace content {
22 22
23 namespace { 23 namespace {
24 24
25 using presentation::PresentationMessageType;
jochen (gone - plz use gerrit) 2015/06/09 08:29:06 please don't use "using" other for helping for lar
USE s.singapati at gmail.com 2015/06/09 09:07:18 Acknowledged. Yes this is a small change from PS#3
USE s.singapati at gmail.com 2015/06/09 14:12:17 Done.
26
25 const int kInvalidRequestSessionId = -1; 27 const int kInvalidRequestSessionId = -1;
26 28
27 int GetNextRequestSessionId() { 29 int GetNextRequestSessionId() {
28 static int next_request_session_id = 0; 30 static int next_request_session_id = 0;
29 return ++next_request_session_id; 31 return ++next_request_session_id;
30 } 32 }
31 33
32 // The return value takes ownership of the contents of |input|. 34 // The return value takes ownership of the contents of |input|.
33 presentation::SessionMessagePtr ToMojoSessionMessage( 35 presentation::SessionMessagePtr ToMojoSessionMessage(
34 content::PresentationSessionMessage* input) { 36 content::PresentationSessionMessage* input) {
35 presentation::SessionMessagePtr output(presentation::SessionMessage::New()); 37 presentation::SessionMessagePtr output(presentation::SessionMessage::New());
36 output->presentation_url.Swap(&input->presentation_url); 38 output->presentation_url.Swap(&input->presentation_url);
37 output->presentation_id.Swap(&input->presentation_id); 39 output->presentation_id.Swap(&input->presentation_id);
38 if (input->is_binary()) { 40 if (input->is_binary()) {
39 // binary data 41 // binary data
40 output->type = presentation::PresentationMessageType:: 42 output->type =
41 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER; 43 PresentationMessageType::PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER;
42 output->data.Swap(input->data.get()); 44 output->data.Swap(input->data.get());
43 } else { 45 } else {
44 // string message 46 // string message
45 output->type = 47 output->type = PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
46 presentation::PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT;
47 output->message.Swap(input->message.get()); 48 output->message.Swap(input->message.get());
48 } 49 }
49 return output.Pass(); 50 return output.Pass();
50 } 51 }
51 52
52 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage( 53 scoped_ptr<content::PresentationSessionMessage> GetPresentationSessionMessage(
53 presentation::SessionMessagePtr input) { 54 presentation::SessionMessagePtr input) {
54 DCHECK(!input.is_null()); 55 DCHECK(!input.is_null());
55 scoped_ptr<content::PresentationSessionMessage> output; 56 scoped_ptr<content::PresentationSessionMessage> output;
56 if (input->type == presentation::PresentationMessageType:: 57 switch (input->type) {
57 PRESENTATION_MESSAGE_TYPE_TEXT) { 58 case PresentationMessageType::PRESENTATION_MESSAGE_TYPE_TEXT: {
58 DCHECK(!input->message.is_null()); 59 DCHECK(!input->message.is_null());
59 DCHECK(input->data.is_null()); 60 DCHECK(input->data.is_null());
60 // Return null PresentationSessionMessage if size exceeds. 61 // Return null PresentationSessionMessage if size exceeds.
61 if (input->message.size() > content::kMaxPresentationSessionMessageSize) 62 if (input->message.size() > content::kMaxPresentationSessionMessageSize)
63 return output.Pass();
64
65 output = content::PresentationSessionMessage::CreateStringMessage(
66 input->presentation_url, input->presentation_id,
67 make_scoped_ptr(new std::string));
68 input->message.Swap(output->message.get());
62 return output.Pass(); 69 return output.Pass();
70 }
71 case PresentationMessageType::PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER: {
72 DCHECK(!input->data.is_null());
73 DCHECK(input->message.is_null());
74 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
75 return output.Pass();
63 76
64 output = content::PresentationSessionMessage::CreateStringMessage( 77 output = content::PresentationSessionMessage::CreateArrayBufferMessage(
65 input->presentation_url, 78 input->presentation_url, input->presentation_id,
66 input->presentation_id, 79 make_scoped_ptr(new std::vector<uint8_t>));
67 make_scoped_ptr(new std::string)); 80 input->data.Swap(output->data.get());
68 input->message.Swap(output->message.get()); 81 return output.Pass();
82 }
83 case PresentationMessageType::PRESENTATION_MESSAGE_TYPE_BLOB: {
84 DCHECK(!input->data.is_null());
85 DCHECK(input->message.is_null());
86 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
87 return output.Pass();
69 88
70 } else if (input->type == presentation::PresentationMessageType:: 89 output = content::PresentationSessionMessage::CreateBlobMessage(
71 PRESENTATION_MESSAGE_TYPE_ARRAY_BUFFER) { 90 input->presentation_url, input->presentation_id,
72 DCHECK(!input->data.is_null()); 91 make_scoped_ptr(new std::vector<uint8_t>));
73 DCHECK(input->message.is_null()); 92 input->data.Swap(output->data.get());
74 // Return null PresentationSessionMessage if size exceeds.
75 if (input->data.size() > content::kMaxPresentationSessionMessageSize)
76 return output.Pass(); 93 return output.Pass();
77 94 }
78 output = content::PresentationSessionMessage::CreateBinaryMessage(
79 input->presentation_url,
80 input->presentation_id,
81 make_scoped_ptr(new std::vector<uint8_t>));
82 input->data.Swap(output->data.get());
83 } 95 }
84 96
97 NOTREACHED() << "Invalid presentation message type " << input->type;
85 return output.Pass(); 98 return output.Pass();
86 } 99 }
87 100
88 void InvokeNewSessionMojoCallbackWithError( 101 void InvokeNewSessionMojoCallbackWithError(
89 const NewSessionMojoCallback& callback) { 102 const NewSessionMojoCallback& callback) {
90 callback.Run( 103 callback.Run(
91 presentation::PresentationSessionInfoPtr(), 104 presentation::PresentationSessionInfoPtr(),
92 presentation::PresentationError::From( 105 presentation::PresentationError::From(
93 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error"))); 106 PresentationError(PRESENTATION_ERROR_UNKNOWN, "Internal error")));
94 } 107 }
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 void PresentationServiceImpl::DefaultSessionStartContext::Reset() { 678 void PresentationServiceImpl::DefaultSessionStartContext::Reset() {
666 ScopedVector<DefaultSessionMojoCallback> callbacks; 679 ScopedVector<DefaultSessionMojoCallback> callbacks;
667 callbacks.swap(callbacks_); 680 callbacks.swap(callbacks_);
668 for (const auto& callback : callbacks) 681 for (const auto& callback : callbacks)
669 callback->Run(presentation::PresentationSessionInfoPtr()); 682 callback->Run(presentation::PresentationSessionInfoPtr());
670 session_.reset(); 683 session_.reset();
671 } 684 }
672 685
673 } // namespace content 686 } // namespace content
674 687
OLDNEW
« no previous file with comments | « no previous file | content/browser/presentation/presentation_service_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698