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

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: Use a vector instead of variable-length array. (Fix Windows compile). 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
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 // Should only be called when the Pepper plugin is out of process.
31 Connection GetConnectionForInstance(PP_Instance instance) {
32 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
33 // GetForInstance returns NULL in the in-process case.
34 DCHECK(dispatcher);
35 return Connection(PluginGlobals::Get()->GetBrowserSender(), dispatcher);
36 }
37
38 } // namespace
39
25 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i) 40 PluginVarTracker::HostVar::HostVar(PluginDispatcher* d, int32 i)
26 : dispatcher(d), 41 : dispatcher(d),
27 host_object_id(i) { 42 host_object_id(i) {
28 } 43 }
29 44
30 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const { 45 bool PluginVarTracker::HostVar::operator<(const HostVar& other) const {
31 if (dispatcher < other.dispatcher) 46 if (dispatcher < other.dispatcher)
32 return true; 47 return true;
33 if (other.dispatcher < dispatcher) 48 if (other.dispatcher < dispatcher)
34 return false; 49 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))); 162 HostVar(dispatcher, static_cast<int32>(host_object.value.as_id)));
148 if (found == host_var_to_plugin_var_.end()) { 163 if (found == host_var_to_plugin_var_.end()) {
149 NOTREACHED(); 164 NOTREACHED();
150 return; 165 return;
151 } 166 }
152 167
153 // Now just release the object given the plugin var ID. 168 // Now just release the object given the plugin var ID.
154 ReleaseVar(found->second); 169 ReleaseVar(found->second);
155 } 170 }
156 171
172 PP_Var PluginVarTracker::MakeResourcePPVar(const IPC::Message& creation_message,
173 int pending_renderer_id,
174 int pending_browser_id,
175 PP_Instance instance) {
176 DCHECK(pending_renderer_id);
177 DCHECK(pending_browser_id);
178 switch (creation_message.type()) {
179 case PpapiPluginMsg_FileSystem_CreateFromPendingHost::ID: {
180 PP_FileSystemType file_system_type;
181 if (!UnpackMessage<PpapiPluginMsg_FileSystem_CreateFromPendingHost>(
182 creation_message, &file_system_type)) {
raymes 2013/10/30 06:31:51 nit: indentation
Matt Giuca 2013/10/30 07:00:39 dmichael already picked this up. My reply: ClangF
183 NOTREACHED() << "Invalid message of type "
184 "PpapiPluginMsg_FileSystem_CreateFromPendingHost";
185 return PP_MakeNull();
186 }
187 // Create a plugin-side resource and attach it to the host resource.
188 // Note: This only makes sense when the plugin is out of process (which
189 // should always be true when passing resource vars).
190 PP_Resource pp_resource =
191 (new FileSystemResource(GetConnectionForInstance(instance),
192 instance,
193 pending_renderer_id,
194 pending_browser_id,
195 file_system_type))->GetReference();
196 return VarTracker::MakeResourcePPVar(pp_resource);
197 }
198 default: {
199 NOTREACHED() << "Creation message has unexpected type "
200 << creation_message.type();
201 return PP_MakeNull();
202 }
203 }
204 }
205
157 ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) { 206 ResourceVar* PluginVarTracker::MakeResourceVar(PP_Resource pp_resource) {
158 // The resource 0 returns a null resource var. 207 // The resource 0 returns a null resource var.
159 if (!pp_resource) 208 if (!pp_resource)
160 return new PluginResourceVar(); 209 return new PluginResourceVar();
161 210
162 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker(); 211 ResourceTracker* resource_tracker = PpapiGlobals::Get()->GetResourceTracker();
163 ppapi::Resource* resource = resource_tracker->GetResource(pp_resource); 212 ppapi::Resource* resource = resource_tracker->GetResource(pp_resource);
164 // A non-existant resource other than 0 returns NULL. 213 // A non-existant resource other than 0 returns NULL.
165 if (!resource) 214 if (!resource)
166 return NULL; 215 return NULL;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 int id, 471 int id,
423 PP_Instance instance, 472 PP_Instance instance,
424 base::SharedMemoryHandle* handle, 473 base::SharedMemoryHandle* handle,
425 uint32* size_in_bytes) { 474 uint32* size_in_bytes) {
426 NOTREACHED(); 475 NOTREACHED();
427 return false; 476 return false;
428 } 477 }
429 478
430 } // namesace proxy 479 } // namesace proxy
431 } // namespace ppapi 480 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698