OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/pepper/resource_converter.h" | 5 #include "content/renderer/pepper/resource_converter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "content/public/renderer/renderer_ppapi_host.h" | 9 #include "content/public/renderer/renderer_ppapi_host.h" |
10 #include "content/renderer/pepper/pepper_file_system_host.h" | 10 #include "content/renderer/pepper/pepper_file_system_host.h" |
11 #include "content/renderer/pepper/pepper_media_stream_video_track_host.h" | |
11 #include "ipc/ipc_message.h" | 12 #include "ipc/ipc_message.h" |
12 #include "ppapi/host/ppapi_host.h" | 13 #include "ppapi/host/ppapi_host.h" |
13 #include "ppapi/host/resource_host.h" | 14 #include "ppapi/host/resource_host.h" |
14 #include "ppapi/proxy/ppapi_messages.h" | 15 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/shared_impl/resource_var.h" | 16 #include "ppapi/shared_impl/resource_var.h" |
16 #include "ppapi/shared_impl/scoped_pp_var.h" | 17 #include "ppapi/shared_impl/scoped_pp_var.h" |
17 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 18 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
19 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | |
18 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 20 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" |
21 #include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" | |
19 | 22 |
23 namespace content { | |
20 namespace { | 24 namespace { |
21 | 25 |
22 void FlushComplete( | 26 void FlushComplete( |
23 const base::Callback<void(bool)>& callback, | 27 const base::Callback<void(bool)>& callback, |
24 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, | 28 const std::vector<scoped_refptr<content::HostResourceVar> >& browser_vars, |
25 const std::vector<int>& pending_host_ids) { | 29 const std::vector<int>& pending_host_ids) { |
26 CHECK(browser_vars.size() == pending_host_ids.size()); | 30 CHECK(browser_vars.size() == pending_host_ids.size()); |
27 for (size_t i = 0; i < browser_vars.size(); ++i) { | 31 for (size_t i = 0; i < browser_vars.size(); ++i) { |
28 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]); | 32 browser_vars[i]->set_pending_browser_host_id(pending_host_ids[i]); |
29 } | 33 } |
(...skipping 15 matching lines...) Expand all Loading... | |
45 NOTREACHED(); | 49 NOTREACHED(); |
46 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; | 50 return PP_FILESYSTEMTYPE_LOCALTEMPORARY; |
47 } | 51 } |
48 } | 52 } |
49 | 53 |
50 // Given a V8 value containing a DOMFileSystem, creates a resource host and | 54 // Given a V8 value containing a DOMFileSystem, creates a resource host and |
51 // returns the resource information for serialization. | 55 // returns the resource information for serialization. |
52 // On error, false. | 56 // On error, false. |
53 bool DOMFileSystemToResource( | 57 bool DOMFileSystemToResource( |
54 PP_Instance instance, | 58 PP_Instance instance, |
55 content::RendererPpapiHost* host, | 59 RendererPpapiHost* host, |
56 const blink::WebDOMFileSystem& dom_file_system, | 60 const blink::WebDOMFileSystem& dom_file_system, |
57 int* pending_renderer_id, | 61 int* pending_renderer_id, |
58 scoped_ptr<IPC::Message>* create_message, | 62 scoped_ptr<IPC::Message>* create_message, |
59 scoped_ptr<IPC::Message>* browser_host_create_message) { | 63 scoped_ptr<IPC::Message>* browser_host_create_message) { |
60 DCHECK(!dom_file_system.isNull()); | 64 DCHECK(!dom_file_system.isNull()); |
61 | 65 |
62 PP_FileSystemType file_system_type = | 66 PP_FileSystemType file_system_type = |
63 WebFileSystemTypeToPPAPI(dom_file_system.type()); | 67 WebFileSystemTypeToPPAPI(dom_file_system.type()); |
64 GURL root_url = dom_file_system.rootURL(); | 68 GURL root_url = dom_file_system.rootURL(); |
65 | 69 |
66 // External file systems are not currently supported. (Without this check, | 70 // External file systems are not currently supported. (Without this check, |
67 // there would be a CHECK-fail in FileRefResource.) | 71 // there would be a CHECK-fail in FileRefResource.) |
68 // TODO(mgiuca): Support external file systems. | 72 // TODO(mgiuca): Support external file systems. |
69 if (file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) | 73 if (file_system_type == PP_FILESYSTEMTYPE_EXTERNAL) |
70 return false; | 74 return false; |
71 | 75 |
72 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( | 76 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( |
73 scoped_ptr<ppapi::host::ResourceHost>( | 77 scoped_ptr<ppapi::host::ResourceHost>( |
74 new content::PepperFileSystemHost(host, instance, 0, root_url, | 78 new PepperFileSystemHost(host, instance, 0, root_url, |
75 file_system_type))); | 79 file_system_type))); |
76 if (*pending_renderer_id == 0) | 80 if (*pending_renderer_id == 0) |
77 return false; | 81 return false; |
78 | 82 |
79 create_message->reset( | 83 create_message->reset( |
80 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); | 84 new PpapiPluginMsg_FileSystem_CreateFromPendingHost(file_system_type)); |
81 | 85 |
82 browser_host_create_message->reset( | 86 browser_host_create_message->reset( |
83 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), | 87 new PpapiHostMsg_FileSystem_CreateFromRenderer(root_url.spec(), |
84 file_system_type)); | 88 file_system_type)); |
85 return true; | 89 return true; |
86 } | 90 } |
87 | 91 |
92 bool DOMMediaStreamTrackToResource( | |
93 PP_Instance instance, | |
94 RendererPpapiHost* host, | |
95 const blink::WebDOMMediaStreamTrack& dom_media_stream_track, | |
96 int* pending_renderer_id, | |
97 scoped_ptr<IPC::Message>* create_message) { | |
98 DCHECK(!dom_media_stream_track.isNull()); | |
99 *pending_renderer_id = 0; | |
100 | |
101 const blink::WebMediaStreamTrack track = | |
102 dom_media_stream_track.component(); | |
103 const std::string id = track.source().id().utf8(); | |
104 | |
105 if (track.source().type() == blink::WebMediaStreamSource::TypeVideo) { | |
106 *pending_renderer_id = host->GetPpapiHost()->AddPendingResourceHost( | |
107 scoped_ptr<ppapi::host::ResourceHost>( | |
108 new PepperMediaStreamVideoTrackHost(host, instance, 0, track))); | |
109 if (*pending_renderer_id == 0) | |
110 return false; | |
111 create_message->reset( | |
112 new PpapiPluginMsg_MediaStreamVideoTrack_CreateFromPendingHost(id)); | |
dmichael (off chromium)
2014/01/09 21:06:47
nit: should be indented 4 spaces
Peng
2014/01/10 19:14:30
Done.
| |
113 | |
114 return true; | |
115 } | |
dmichael (off chromium)
2014/01/09 21:06:47
Might be worth adding a TODO, if this is also wher
Peng
2014/01/10 19:14:30
Done.
| |
116 | |
117 return false; | |
118 } | |
119 | |
88 } // namespace | 120 } // namespace |
89 | 121 |
90 namespace content { | |
91 | |
92 ResourceConverter::~ResourceConverter() {} | 122 ResourceConverter::~ResourceConverter() {} |
93 | 123 |
94 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, | 124 ResourceConverterImpl::ResourceConverterImpl(PP_Instance instance, |
95 RendererPpapiHost* host) | 125 RendererPpapiHost* host) |
96 : instance_(instance), | 126 : instance_(instance), |
97 host_(host) { | 127 host_(host) { |
98 } | 128 } |
99 | 129 |
100 ResourceConverterImpl::~ResourceConverterImpl() { | 130 ResourceConverterImpl::~ResourceConverterImpl() { |
101 // Verify Flush() was called. | 131 // Verify Flush() was called. |
(...skipping 24 matching lines...) Expand all Loading... | |
126 DCHECK(create_message); | 156 DCHECK(create_message); |
127 DCHECK(browser_host_create_message); | 157 DCHECK(browser_host_create_message); |
128 scoped_refptr<HostResourceVar> result_var = | 158 scoped_refptr<HostResourceVar> result_var = |
129 CreateResourceVarWithBrowserHost( | 159 CreateResourceVarWithBrowserHost( |
130 pending_renderer_id, *create_message, *browser_host_create_message); | 160 pending_renderer_id, *create_message, *browser_host_create_message); |
131 *result = result_var->GetPPVar(); | 161 *result = result_var->GetPPVar(); |
132 *was_resource = true; | 162 *was_resource = true; |
133 return true; | 163 return true; |
134 } | 164 } |
135 | 165 |
166 blink::WebDOMMediaStreamTrack dom_media_stream_track = | |
167 blink::WebDOMMediaStreamTrack::fromV8Value(val); | |
dmichael (off chromium)
2014/01/09 21:06:47
4-space indent
Peng
2014/01/10 19:14:30
Done
I don't know why vim continue giving me 2-sp
dmichael (off chromium)
2014/01/13 21:26:47
No... when I first started, I was using the recom
| |
168 if (!dom_media_stream_track.isNull()) { | |
169 int pending_renderer_id; | |
170 scoped_ptr<IPC::Message> create_message; | |
171 scoped_ptr<IPC::Message> browser_host_create_message; | |
dmichael (off chromium)
2014/01/09 21:06:47
It looks like this message is not necessary here;
Peng
2014/01/10 19:14:30
Done.
| |
172 if (!DOMMediaStreamTrackToResource(instance_, host_, dom_media_stream_track, | |
173 &pending_renderer_id, &create_message)) { | |
174 return false; | |
175 } | |
176 DCHECK(create_message); | |
177 scoped_refptr<HostResourceVar> result_var = | |
178 CreateResourceVar(pending_renderer_id, *create_message); | |
179 *result = result_var->GetPPVar(); | |
180 *was_resource = true; | |
181 return true; | |
182 } | |
183 | |
136 // The value was not convertible to a resource. Return true with | 184 // The value was not convertible to a resource. Return true with |
137 // |was_resource| set to false. As per the interface of FromV8Value, |result| | 185 // |was_resource| set to false. As per the interface of FromV8Value, |result| |
138 // may be left unmodified in this case. | 186 // may be left unmodified in this case. |
139 return true; | 187 return true; |
140 } | 188 } |
141 | 189 |
142 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) { | 190 void ResourceConverterImpl::Flush(const base::Callback<void(bool)>& callback) { |
143 host_->CreateBrowserResourceHosts( | 191 host_->CreateBrowserResourceHosts( |
144 instance_, | 192 instance_, |
145 browser_host_create_messages_, | 193 browser_host_create_messages_, |
(...skipping 14 matching lines...) Expand all Loading... | |
160 const IPC::Message& create_message, | 208 const IPC::Message& create_message, |
161 const IPC::Message& browser_host_create_message) { | 209 const IPC::Message& browser_host_create_message) { |
162 scoped_refptr<HostResourceVar> result = | 210 scoped_refptr<HostResourceVar> result = |
163 CreateResourceVar(pending_renderer_id, create_message); | 211 CreateResourceVar(pending_renderer_id, create_message); |
164 browser_host_create_messages_.push_back(browser_host_create_message); | 212 browser_host_create_messages_.push_back(browser_host_create_message); |
165 browser_vars.push_back(result); | 213 browser_vars.push_back(result); |
166 return result; | 214 return result; |
167 } | 215 } |
168 | 216 |
169 } // namespace content | 217 } // namespace content |
OLD | NEW |