OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/plugin_object.h" | 5 #include "content/renderer/pepper/plugin_object.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 ppp_class_->Deallocate(ppp_class_data_); | 51 ppp_class_->Deallocate(ppp_class_data_); |
52 instance_->RemovePluginObject(this); | 52 instance_->RemovePluginObject(this); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 // static | 56 // static |
57 gin::WrapperInfo PluginObject::kWrapperInfo = {gin::kEmbedderNativeGin}; | 57 gin::WrapperInfo PluginObject::kWrapperInfo = {gin::kEmbedderNativeGin}; |
58 | 58 |
59 // static | 59 // static |
60 PluginObject* PluginObject::FromV8Object(v8::Isolate* isolate, | 60 PluginObject* PluginObject::FromV8Object(v8::Isolate* isolate, |
61 v8::Handle<v8::Object> v8_object) { | 61 v8::Local<v8::Object> v8_object) { |
62 PluginObject* plugin_object; | 62 PluginObject* plugin_object; |
63 if (!v8_object.IsEmpty() && | 63 if (!v8_object.IsEmpty() && |
64 gin::ConvertFromV8(isolate, v8_object, &plugin_object)) { | 64 gin::ConvertFromV8(isolate, v8_object, &plugin_object)) { |
65 return plugin_object; | 65 return plugin_object; |
66 } | 66 } |
67 return NULL; | 67 return NULL; |
68 } | 68 } |
69 | 69 |
70 // static | 70 // static |
71 PP_Var PluginObject::Create(PepperPluginInstanceImpl* instance, | 71 PP_Var PluginObject::Create(PepperPluginInstanceImpl* instance, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (try_catch.ThrowException()) | 194 if (try_catch.ThrowException()) |
195 return v8::Local<v8::Value>(); | 195 return v8::Local<v8::Value>(); |
196 | 196 |
197 if (has_property) { | 197 if (has_property) { |
198 ScopedPPVar result_var(ScopedPPVar::PassRef(), | 198 ScopedPPVar result_var(ScopedPPVar::PassRef(), |
199 ppp_class_->GetProperty(ppp_class_data_, identifier_var, | 199 ppp_class_->GetProperty(ppp_class_data_, identifier_var, |
200 try_catch.exception())); | 200 try_catch.exception())); |
201 if (try_catch.ThrowException()) | 201 if (try_catch.ThrowException()) |
202 return v8::Local<v8::Value>(); | 202 return v8::Local<v8::Value>(); |
203 | 203 |
204 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); | 204 v8::Local<v8::Value> result = try_catch.ToV8(result_var.get()); |
205 if (try_catch.ThrowException()) | 205 if (try_catch.ThrowException()) |
206 return v8::Local<v8::Value>(); | 206 return v8::Local<v8::Value>(); |
207 | 207 |
208 return result; | 208 return result; |
209 } | 209 } |
210 | 210 |
211 bool has_method = identifier_var.type == PP_VARTYPE_STRING && | 211 bool has_method = identifier_var.type == PP_VARTYPE_STRING && |
212 ppp_class_->HasMethod(ppp_class_data_, identifier_var, | 212 ppp_class_->HasMethod(ppp_class_data_, identifier_var, |
213 try_catch.exception()); | 213 try_catch.exception()); |
214 if (try_catch.ThrowException()) | 214 if (try_catch.ThrowException()) |
(...skipping 14 matching lines...) Expand all Loading... |
229 return; | 229 return; |
230 | 230 |
231 V8VarConverter var_converter(instance_->pp_instance(), | 231 V8VarConverter var_converter(instance_->pp_instance(), |
232 V8VarConverter::kAllowObjectVars); | 232 V8VarConverter::kAllowObjectVars); |
233 PepperTryCatchV8 try_catch(instance_, &var_converter, args->isolate()); | 233 PepperTryCatchV8 try_catch(instance_, &var_converter, args->isolate()); |
234 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), | 234 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), |
235 StringVar::StringToPPVar(identifier)); | 235 StringVar::StringToPPVar(identifier)); |
236 ScopedPPVarArray argument_vars(args->Length()); | 236 ScopedPPVarArray argument_vars(args->Length()); |
237 | 237 |
238 for (uint32_t i = 0; i < argument_vars.size(); ++i) { | 238 for (uint32_t i = 0; i < argument_vars.size(); ++i) { |
239 v8::Handle<v8::Value> arg; | 239 v8::Local<v8::Value> arg; |
240 if (!args->GetNext(&arg)) { | 240 if (!args->GetNext(&arg)) { |
241 NOTREACHED(); | 241 NOTREACHED(); |
242 } | 242 } |
243 | 243 |
244 argument_vars.Set(i, try_catch.FromV8(arg)); | 244 argument_vars.Set(i, try_catch.FromV8(arg)); |
245 if (try_catch.ThrowException()) | 245 if (try_catch.ThrowException()) |
246 return; | 246 return; |
247 } | 247 } |
248 | 248 |
249 // For the OOP plugin case we need to grab a reference on the plugin module | 249 // For the OOP plugin case we need to grab a reference on the plugin module |
250 // object to ensure that it is not destroyed courtesy an incoming | 250 // object to ensure that it is not destroyed courtesy an incoming |
251 // ExecuteScript call which destroys the plugin module and in turn the | 251 // ExecuteScript call which destroys the plugin module and in turn the |
252 // dispatcher. | 252 // dispatcher. |
253 scoped_refptr<PluginModule> ref(instance_->module()); | 253 scoped_refptr<PluginModule> ref(instance_->module()); |
254 | 254 |
255 ScopedPPVar result_var(ScopedPPVar::PassRef(), | 255 ScopedPPVar result_var(ScopedPPVar::PassRef(), |
256 ppp_class_->Call(ppp_class_data_, identifier_var.get(), | 256 ppp_class_->Call(ppp_class_data_, identifier_var.get(), |
257 argument_vars.size(), argument_vars.get(), | 257 argument_vars.size(), argument_vars.get(), |
258 try_catch.exception())); | 258 try_catch.exception())); |
259 if (try_catch.ThrowException()) | 259 if (try_catch.ThrowException()) |
260 return; | 260 return; |
261 | 261 |
262 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); | 262 v8::Local<v8::Value> result = try_catch.ToV8(result_var.get()); |
263 if (try_catch.ThrowException()) | 263 if (try_catch.ThrowException()) |
264 return; | 264 return; |
265 | 265 |
266 args->Return(result); | 266 args->Return(result); |
267 } | 267 } |
268 | 268 |
269 v8::Local<v8::FunctionTemplate> PluginObject::GetFunctionTemplate( | 269 v8::Local<v8::FunctionTemplate> PluginObject::GetFunctionTemplate( |
270 v8::Isolate* isolate, | 270 v8::Isolate* isolate, |
271 const std::string& name) { | 271 const std::string& name) { |
272 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); | 272 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); |
273 if (!function_template.IsEmpty()) | 273 if (!function_template.IsEmpty()) |
274 return function_template; | 274 return function_template; |
275 function_template = | 275 function_template = |
276 gin::CreateFunctionTemplate( | 276 gin::CreateFunctionTemplate( |
277 isolate, base::Bind(&PluginObject::Call, weak_factory_.GetWeakPtr(), | 277 isolate, base::Bind(&PluginObject::Call, weak_factory_.GetWeakPtr(), |
278 name)); | 278 name)); |
279 template_cache_.Set(name, function_template); | 279 template_cache_.Set(name, function_template); |
280 return function_template; | 280 return function_template; |
281 } | 281 } |
282 | 282 |
283 } // namespace content | 283 } // namespace content |
OLD | NEW |