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

Side by Side Diff: ppapi/proxy/plugin_var_tracker.cc

Issue 26564009: [PPAPI] It is now possible to pass filesystems from JavaScript to NaCl modules. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 1 month 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 | « ppapi/proxy/plugin_var_tracker.h ('k') | ppapi/proxy/ppapi_messages.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ppapi/proxy/plugin_var_tracker.h" 5 #include "ppapi/proxy/plugin_var_tracker.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "ipc/ipc_message.h"
9 #include "ppapi/c/dev/ppp_class_deprecated.h" 10 #include "ppapi/c/dev/ppp_class_deprecated.h"
10 #include "ppapi/c/ppb_var.h" 11 #include "ppapi/c/ppb_var.h"
12 #include "ppapi/proxy/file_system_resource.h"
11 #include "ppapi/proxy/plugin_array_buffer_var.h" 13 #include "ppapi/proxy/plugin_array_buffer_var.h"
12 #include "ppapi/proxy/plugin_dispatcher.h" 14 #include "ppapi/proxy/plugin_dispatcher.h"
15 #include "ppapi/proxy/plugin_globals.h"
13 #include "ppapi/proxy/plugin_resource_var.h" 16 #include "ppapi/proxy/plugin_resource_var.h"
14 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
15 #include "ppapi/proxy/proxy_object_var.h" 18 #include "ppapi/proxy/proxy_object_var.h"
16 #include "ppapi/shared_impl/api_id.h" 19 #include "ppapi/shared_impl/api_id.h"
17 #include "ppapi/shared_impl/ppapi_globals.h" 20 #include "ppapi/shared_impl/ppapi_globals.h"
18 #include "ppapi/shared_impl/proxy_lock.h" 21 #include "ppapi/shared_impl/proxy_lock.h"
19 #include "ppapi/shared_impl/resource_tracker.h" 22 #include "ppapi/shared_impl/resource_tracker.h"
20 #include "ppapi/shared_impl/var.h" 23 #include "ppapi/shared_impl/var.h"
21 24
22 namespace ppapi { 25 namespace ppapi {
23 namespace proxy { 26 namespace proxy {
24 27
28 namespace {
29
30 Connection GetConnectionForInstance(PP_Instance instance) {
31 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
32 DCHECK(dispatcher);
33 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher);
34 }
35
36 } // namespace
37
25 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i) 38 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i)
26 : dispatcher(d), 39 : dispatcher(d),
27 host_object_id(i) { 40 host_object_id(i) {
28 } 41 }
29 42
30 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { 43 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const {
31 if (dispatcher < other.dispatcher) 44 if (dispatcher < other.dispatcher)
32 return true; 45 return true;
33 if (other.dispatcher < dispatcher) 46 if (other.dispatcher < dispatcher)
34 return false; 47 return false;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id))); 160 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id)));
148 if (found == host_var_to_plugin_var_.end()) { 161 if (found == host_var_to_plugin_var_.end()) {
149 NOTREACHED(); 162 NOTREACHED();
150 return; 163 return;
151 } 164 }
152 165
153 // Now just release the object given the plugin var ID. 166 // Now just release the object given the plugin var ID.
154 ReleaseVar(found->second); 167 ReleaseVar(found->second);
155 } 168 }
156 169
170 PP_Var PluginVarTracker::MakeResourcePPVarFromMessage(
171 PP_Instance instance,
172 const IPC::Message& creation_message,
173 int pending_renderer_id,
174 int pending_browser_id) {
175 DCHECK(pending_renderer_id);
176 DCHECK(pending_browser_id);
177 switch (creation_message.type()) {
178 case PpapiPluginMsg_FileSystem_CreateFromPendingHost::ID: {
179 PP_FileSystemType file_system_type;
180 if (!UnpackMessage<PpapiPluginMsg_FileSystem_CreateFromPendingHost>(
181 creation_message, &file_system_type)) {
182 NOTREACHED() << "Invalid message of type "
183 "PpapiPluginMsg_FileSystem_CreateFromPendingHost";
184 return PP_MakeNull();
185 }
186 // Create a plugin-side resource and attach it to the host resource.
187 // Note: This only makes sense when the plugin is out of process (which
188 // should always be true when passing resource vars).
189 PP_Resource pp_resource =
190 (new FileSystemResource(GetConnectionForInstance(instance),
191 instance,
192 pending_renderer_id,
193 pending_browser_id,
194 file_system_type))->GetReference();
195 return MakeResourcePPVar(pp_resource);
196 }
197 default: {
198 NOTREACHED() << "Creation message has unexpected type "
199 << creation_message.type();
200 return PP_MakeNull();
201 }
202 }
203 }
204
157 ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) { 205 ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) {
158 // The resource 0 returns a null resource var. 206 // The resource 0 returns a null resource var.
159 if (!pp_resource) 207 if (!pp_resource)
160 return new PluginResourceVar(); 208 return new PluginResourceVar();
161 209
162 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker(); 210 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
163 ppapi::Resource* resource = resource_tracker->GetResource(pp_resource); 211 ppapi::Resource* resource = resource_tracker->GetResource(pp_resource);
164 // A non-existant resource other than 0 returns NULL. 212 // A non-existant resource other than 0 returns NULL.
165 if (!resource) 213 if (!resource)
166 return NULL; 214 return NULL;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 int id, 470 int id,
423 PP_Instance instance, 471 PP_Instance instance,
424 base::SharedMemoryHandle* handle, 472 base::SharedMemoryHandle* handle,
425 uint32* size_in_bytes) { 473 uint32* size_in_bytes) {
426 NOTREACHED(); 474 NOTREACHED();
427 return false; 475 return false;
428 } 476 }
429 477
430 } // namesace proxy 478 } // namesace proxy
431 } // namespace ppapi 479 } // namespace ppapi
OLDNEW
« no previous file with comments | « ppapi/proxy/plugin_var_tracker.h ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698