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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 instance_ = NULL; | 162 instance_ = NULL; |
163 } | 163 } |
164 | 164 |
165 PluginObject::PluginObject(PepperPluginInstanceImpl* instance, | 165 PluginObject::PluginObject(PepperPluginInstanceImpl* instance, |
166 const PPP_Class_Deprecated* ppp_class, | 166 const PPP_Class_Deprecated* ppp_class, |
167 void* ppp_class_data) | 167 void* ppp_class_data) |
168 : gin::NamedPropertyInterceptor(instance->GetIsolate(), this), | 168 : gin::NamedPropertyInterceptor(instance->GetIsolate(), this), |
169 instance_(instance), | 169 instance_(instance), |
170 ppp_class_(ppp_class), | 170 ppp_class_(ppp_class), |
171 ppp_class_data_(ppp_class_data), | 171 ppp_class_data_(ppp_class_data), |
172 weak_factory_(this) { | 172 weak_factory_(this), |
| 173 template_cache_(instance->GetIsolate()) { |
173 instance_->AddPluginObject(this); | 174 instance_->AddPluginObject(this); |
174 } | 175 } |
175 | 176 |
176 gin::ObjectTemplateBuilder PluginObject::GetObjectTemplateBuilder( | 177 gin::ObjectTemplateBuilder PluginObject::GetObjectTemplateBuilder( |
177 v8::Isolate* isolate) { | 178 v8::Isolate* isolate) { |
178 return Wrappable<PluginObject>::GetObjectTemplateBuilder(isolate) | 179 return Wrappable<PluginObject>::GetObjectTemplateBuilder(isolate) |
179 .AddNamedPropertyInterceptor(); | 180 .AddNamedPropertyInterceptor(); |
180 } | 181 } |
181 | 182 |
182 v8::Local<v8::Value> PluginObject::GetPropertyOrMethod(v8::Isolate* isolate, | 183 v8::Local<v8::Value> PluginObject::GetPropertyOrMethod(v8::Isolate* isolate, |
(...skipping 26 matching lines...) Expand all Loading... |
209 | 210 |
210 bool has_method = identifier_var.type == PP_VARTYPE_STRING && | 211 bool has_method = identifier_var.type == PP_VARTYPE_STRING && |
211 ppp_class_->HasMethod(ppp_class_data_, identifier_var, | 212 ppp_class_->HasMethod(ppp_class_data_, identifier_var, |
212 try_catch.exception()); | 213 try_catch.exception()); |
213 if (try_catch.ThrowException()) | 214 if (try_catch.ThrowException()) |
214 return v8::Local<v8::Value>(); | 215 return v8::Local<v8::Value>(); |
215 | 216 |
216 if (has_method) { | 217 if (has_method) { |
217 const std::string& identifier = | 218 const std::string& identifier = |
218 StringVar::FromPPVar(identifier_var)->value(); | 219 StringVar::FromPPVar(identifier_var)->value(); |
219 return gin::CreateFunctionTemplate(isolate, | 220 return GetFunctionTemplate(isolate, identifier)->GetFunction(); |
220 base::Bind(&PluginObject::Call, | |
221 weak_factory_.GetWeakPtr(), | |
222 identifier))->GetFunction(); | |
223 } | 221 } |
224 | 222 |
225 return v8::Local<v8::Value>(); | 223 return v8::Local<v8::Value>(); |
226 } | 224 } |
227 | 225 |
228 void PluginObject::Call(const std::string& identifier, | 226 void PluginObject::Call(const std::string& identifier, |
229 gin::Arguments* args) { | 227 gin::Arguments* args) { |
230 if (!instance_) | 228 if (!instance_) |
231 return; | 229 return; |
232 | 230 |
(...skipping 28 matching lines...) Expand all Loading... |
261 if (try_catch.ThrowException()) | 259 if (try_catch.ThrowException()) |
262 return; | 260 return; |
263 | 261 |
264 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); | 262 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); |
265 if (try_catch.ThrowException()) | 263 if (try_catch.ThrowException()) |
266 return; | 264 return; |
267 | 265 |
268 args->Return(result); | 266 args->Return(result); |
269 } | 267 } |
270 | 268 |
| 269 v8::Local<v8::FunctionTemplate> PluginObject::GetFunctionTemplate( |
| 270 v8::Isolate* isolate, |
| 271 const std::string& name) { |
| 272 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); |
| 273 if (!function_template.IsEmpty()) |
| 274 return function_template; |
| 275 function_template = |
| 276 gin::CreateFunctionTemplate( |
| 277 isolate, base::Bind(&PluginObject::Call, weak_factory_.GetWeakPtr(), |
| 278 name)); |
| 279 template_cache_.Set(name, function_template); |
| 280 return function_template; |
| 281 } |
| 282 |
271 } // namespace content | 283 } // namespace content |
OLD | NEW |