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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, |
72 const PPP_Class_Deprecated* ppp_class, | 72 const PPP_Class_Deprecated* ppp_class, |
73 void* ppp_class_data) { | 73 void* ppp_class_data) { |
74 PepperTryCatchVar try_catch(instance, NULL); | 74 V8VarConverter var_converter(instance->pp_instance(), |
| 75 V8VarConverter::kAllowObjectVars); |
| 76 PepperTryCatchVar try_catch(instance, &var_converter, NULL); |
75 gin::Handle<PluginObject> object = | 77 gin::Handle<PluginObject> object = |
76 gin::CreateHandle(instance->GetIsolate(), | 78 gin::CreateHandle(instance->GetIsolate(), |
77 new PluginObject(instance, ppp_class, ppp_class_data)); | 79 new PluginObject(instance, ppp_class, ppp_class_data)); |
78 ScopedPPVar result = try_catch.FromV8(object.ToV8()); | 80 ScopedPPVar result = try_catch.FromV8(object.ToV8()); |
79 DCHECK(!try_catch.HasException()); | 81 DCHECK(!try_catch.HasException()); |
80 return result.Release(); | 82 return result.Release(); |
81 } | 83 } |
82 | 84 |
83 v8::Local<v8::Value> PluginObject::GetNamedProperty( | 85 v8::Local<v8::Value> PluginObject::GetNamedProperty( |
84 v8::Isolate* isolate, | 86 v8::Isolate* isolate, |
85 const std::string& identifier) { | 87 const std::string& identifier) { |
86 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), | 88 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), |
87 StringVar::StringToPPVar(identifier)); | 89 StringVar::StringToPPVar(identifier)); |
88 return GetPropertyOrMethod(instance_->GetIsolate(), identifier_var.get()); | 90 return GetPropertyOrMethod(instance_->GetIsolate(), identifier_var.get()); |
89 } | 91 } |
90 | 92 |
91 bool PluginObject::SetNamedProperty(v8::Isolate* isolate, | 93 bool PluginObject::SetNamedProperty(v8::Isolate* isolate, |
92 const std::string& identifier, | 94 const std::string& identifier, |
93 v8::Local<v8::Value> value) { | 95 v8::Local<v8::Value> value) { |
94 if (!instance_) | 96 if (!instance_) |
95 return false; | 97 return false; |
96 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), | 98 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), |
97 StringVar::StringToPPVar(identifier)); | 99 StringVar::StringToPPVar(identifier)); |
98 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kAllowObjectVars, | 100 V8VarConverter var_converter(instance_->pp_instance(), |
99 isolate); | 101 V8VarConverter::kAllowObjectVars); |
| 102 PepperTryCatchV8 try_catch(instance_, &var_converter, isolate); |
100 | 103 |
101 bool has_property = | 104 bool has_property = |
102 ppp_class_->HasProperty(ppp_class_data_, identifier_var.get(), | 105 ppp_class_->HasProperty(ppp_class_data_, identifier_var.get(), |
103 try_catch.exception()); | 106 try_catch.exception()); |
104 if (try_catch.ThrowException()) | 107 if (try_catch.ThrowException()) |
105 return false; | 108 return false; |
106 | 109 |
107 if (!has_property) | 110 if (!has_property) |
108 return false; | 111 return false; |
109 | 112 |
(...skipping 10 matching lines...) Expand all Loading... |
120 try_catch.ThrowException(); | 123 try_catch.ThrowException(); |
121 return true; | 124 return true; |
122 } | 125 } |
123 | 126 |
124 std::vector<std::string> PluginObject::EnumerateNamedProperties( | 127 std::vector<std::string> PluginObject::EnumerateNamedProperties( |
125 v8::Isolate* isolate) { | 128 v8::Isolate* isolate) { |
126 std::vector<std::string> result; | 129 std::vector<std::string> result; |
127 if (!instance_) | 130 if (!instance_) |
128 return result; | 131 return result; |
129 | 132 |
130 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kAllowObjectVars, | 133 V8VarConverter var_converter(instance_->pp_instance(), |
131 isolate); | 134 V8VarConverter::kAllowObjectVars); |
| 135 PepperTryCatchV8 try_catch(instance_, &var_converter, isolate); |
132 | 136 |
133 PP_Var* name_vars; | 137 PP_Var* name_vars; |
134 uint32_t count = 0; | 138 uint32_t count = 0; |
135 ppp_class_->GetAllPropertyNames(ppp_class_data_, &count, &name_vars, | 139 ppp_class_->GetAllPropertyNames(ppp_class_data_, &count, &name_vars, |
136 try_catch.exception()); | 140 try_catch.exception()); |
137 ScopedPPVarArray scoped_name_vars( | 141 ScopedPPVarArray scoped_name_vars( |
138 ScopedPPVarArray::PassPPBMemoryAllocatedArray(), name_vars, count); | 142 ScopedPPVarArray::PassPPBMemoryAllocatedArray(), name_vars, count); |
139 | 143 |
140 if (try_catch.ThrowException()) | 144 if (try_catch.ThrowException()) |
141 return result; | 145 return result; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 v8::Isolate* isolate) { | 177 v8::Isolate* isolate) { |
174 return Wrappable<PluginObject>::GetObjectTemplateBuilder(isolate) | 178 return Wrappable<PluginObject>::GetObjectTemplateBuilder(isolate) |
175 .AddNamedPropertyInterceptor(); | 179 .AddNamedPropertyInterceptor(); |
176 } | 180 } |
177 | 181 |
178 v8::Local<v8::Value> PluginObject::GetPropertyOrMethod(v8::Isolate* isolate, | 182 v8::Local<v8::Value> PluginObject::GetPropertyOrMethod(v8::Isolate* isolate, |
179 PP_Var identifier_var) { | 183 PP_Var identifier_var) { |
180 if (!instance_) | 184 if (!instance_) |
181 return v8::Local<v8::Value>(); | 185 return v8::Local<v8::Value>(); |
182 | 186 |
183 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kAllowObjectVars, | 187 V8VarConverter var_converter(instance_->pp_instance(), |
184 isolate); | 188 V8VarConverter::kAllowObjectVars); |
| 189 PepperTryCatchV8 try_catch(instance_, &var_converter, isolate); |
185 bool has_property = | 190 bool has_property = |
186 ppp_class_->HasProperty(ppp_class_data_, identifier_var, | 191 ppp_class_->HasProperty(ppp_class_data_, identifier_var, |
187 try_catch.exception()); | 192 try_catch.exception()); |
188 if (try_catch.ThrowException()) | 193 if (try_catch.ThrowException()) |
189 return v8::Local<v8::Value>(); | 194 return v8::Local<v8::Value>(); |
190 | 195 |
191 if (has_property) { | 196 if (has_property) { |
192 ScopedPPVar result_var(ScopedPPVar::PassRef(), | 197 ScopedPPVar result_var(ScopedPPVar::PassRef(), |
193 ppp_class_->GetProperty(ppp_class_data_, identifier_var, | 198 ppp_class_->GetProperty(ppp_class_data_, identifier_var, |
194 try_catch.exception())); | 199 try_catch.exception())); |
(...skipping 23 matching lines...) Expand all Loading... |
218 } | 223 } |
219 | 224 |
220 return v8::Local<v8::Value>(); | 225 return v8::Local<v8::Value>(); |
221 } | 226 } |
222 | 227 |
223 void PluginObject::Call(const std::string& identifier, | 228 void PluginObject::Call(const std::string& identifier, |
224 gin::Arguments* args) { | 229 gin::Arguments* args) { |
225 if (!instance_) | 230 if (!instance_) |
226 return; | 231 return; |
227 | 232 |
228 PepperTryCatchV8 try_catch(instance_, V8VarConverter::kAllowObjectVars, | 233 V8VarConverter var_converter(instance_->pp_instance(), |
229 args->isolate()); | 234 V8VarConverter::kAllowObjectVars); |
| 235 PepperTryCatchV8 try_catch(instance_, &var_converter, args->isolate()); |
230 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), | 236 ScopedPPVar identifier_var(ScopedPPVar::PassRef(), |
231 StringVar::StringToPPVar(identifier)); | 237 StringVar::StringToPPVar(identifier)); |
232 ScopedPPVarArray argument_vars(args->Length()); | 238 ScopedPPVarArray argument_vars(args->Length()); |
233 | 239 |
234 for (uint32_t i = 0; i < argument_vars.size(); ++i) { | 240 for (uint32_t i = 0; i < argument_vars.size(); ++i) { |
235 v8::Handle<v8::Value> arg; | 241 v8::Handle<v8::Value> arg; |
236 if (!args->GetNext(&arg)) { | 242 if (!args->GetNext(&arg)) { |
237 NOTREACHED(); | 243 NOTREACHED(); |
238 } | 244 } |
239 | 245 |
(...skipping 16 matching lines...) Expand all Loading... |
256 return; | 262 return; |
257 | 263 |
258 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); | 264 v8::Handle<v8::Value> result = try_catch.ToV8(result_var.get()); |
259 if (try_catch.ThrowException()) | 265 if (try_catch.ThrowException()) |
260 return; | 266 return; |
261 | 267 |
262 args->Return(result); | 268 args->Return(result); |
263 } | 269 } |
264 | 270 |
265 } // namespace content | 271 } // namespace content |
OLD | NEW |