OLD | NEW |
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 "content/renderer/pepper/ppb_var_deprecated_impl.h" | 5 #include "content/renderer/pepper/ppb_var_deprecated_impl.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "content/renderer/pepper/host_globals.h" | 9 #include "content/renderer/pepper/host_globals.h" |
10 #include "content/renderer/pepper/message_channel.h" | 10 #include "content/renderer/pepper/npapi_glue.h" |
| 11 #include "content/renderer/pepper/npobject_var.h" |
11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
12 #include "content/renderer/pepper/pepper_try_catch.h" | |
13 #include "content/renderer/pepper/plugin_module.h" | 13 #include "content/renderer/pepper/plugin_module.h" |
14 #include "content/renderer/pepper/plugin_object.h" | 14 #include "content/renderer/pepper/plugin_object.h" |
15 #include "content/renderer/pepper/v8object_var.h" | |
16 #include "ppapi/c/dev/ppb_var_deprecated.h" | 15 #include "ppapi/c/dev/ppb_var_deprecated.h" |
17 #include "ppapi/c/ppb_var.h" | 16 #include "ppapi/c/ppb_var.h" |
| 17 #include "ppapi/c/pp_var.h" |
18 #include "ppapi/shared_impl/ppb_var_shared.h" | 18 #include "ppapi/shared_impl/ppb_var_shared.h" |
19 #include "third_party/WebKit/public/web/WebDocument.h" | 19 #include "third_party/WebKit/public/web/WebBindings.h" |
20 #include "third_party/WebKit/public/web/WebElement.h" | |
21 #include "third_party/WebKit/public/web/WebLocalFrame.h" | |
22 #include "third_party/WebKit/public/web/WebPluginContainer.h" | |
23 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" | 20 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" |
24 | 21 |
25 using ppapi::V8ObjectVar; | 22 using ppapi::NPObjectVar; |
26 using ppapi::PpapiGlobals; | 23 using ppapi::PpapiGlobals; |
27 using ppapi::ScopedPPVar; | |
28 using ppapi::ScopedPPVarArray; | |
29 using ppapi::StringVar; | 24 using ppapi::StringVar; |
30 using ppapi::Var; | 25 using ppapi::Var; |
| 26 using blink::WebBindings; |
31 | 27 |
32 namespace content { | 28 namespace content { |
33 | 29 |
34 namespace { | 30 namespace { |
35 | 31 |
36 const char kInvalidIdentifierException[] = "Error: Invalid identifier."; | |
37 const char kInvalidObjectException[] = "Error: Invalid object"; | 32 const char kInvalidObjectException[] = "Error: Invalid object"; |
| 33 const char kInvalidPropertyException[] = "Error: Invalid property"; |
| 34 const char kInvalidValueException[] = "Error: Invalid value"; |
| 35 const char kUnableToGetPropertyException[] = "Error: Unable to get property"; |
| 36 const char kUnableToSetPropertyException[] = "Error: Unable to set property"; |
| 37 const char kUnableToRemovePropertyException[] = |
| 38 "Error: Unable to remove property"; |
| 39 const char kUnableToGetAllPropertiesException[] = |
| 40 "Error: Unable to get all properties"; |
38 const char kUnableToCallMethodException[] = "Error: Unable to call method"; | 41 const char kUnableToCallMethodException[] = "Error: Unable to call method"; |
39 | 42 const char kUnableToConstructException[] = "Error: Unable to construct"; |
40 class ObjectAccessor { | 43 |
| 44 // --------------------------------------------------------------------------- |
| 45 // Utilities |
| 46 |
| 47 // Converts the given PP_Var to an NPVariant, returning true on success. |
| 48 // False means that the given variant is invalid. In this case, the result |
| 49 // NPVariant will be set to a void one. |
| 50 // |
| 51 // The contents of the PP_Var will NOT be copied, so you need to ensure that |
| 52 // the PP_Var remains valid while the resultant NPVariant is in use. |
| 53 bool PPVarToNPVariantNoCopy(PP_Var var, NPVariant* result) { |
| 54 switch (var.type) { |
| 55 case PP_VARTYPE_UNDEFINED: |
| 56 VOID_TO_NPVARIANT(*result); |
| 57 break; |
| 58 case PP_VARTYPE_NULL: |
| 59 NULL_TO_NPVARIANT(*result); |
| 60 break; |
| 61 case PP_VARTYPE_BOOL: |
| 62 BOOLEAN_TO_NPVARIANT(var.value.as_bool, *result); |
| 63 break; |
| 64 case PP_VARTYPE_INT32: |
| 65 INT32_TO_NPVARIANT(var.value.as_int, *result); |
| 66 break; |
| 67 case PP_VARTYPE_DOUBLE: |
| 68 DOUBLE_TO_NPVARIANT(var.value.as_double, *result); |
| 69 break; |
| 70 case PP_VARTYPE_STRING: { |
| 71 StringVar* string = StringVar::FromPPVar(var); |
| 72 if (!string) { |
| 73 VOID_TO_NPVARIANT(*result); |
| 74 return false; |
| 75 } |
| 76 const std::string& value = string->value(); |
| 77 STRINGN_TO_NPVARIANT(value.c_str(), value.size(), *result); |
| 78 break; |
| 79 } |
| 80 case PP_VARTYPE_OBJECT: { |
| 81 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var)); |
| 82 if (!object.get()) { |
| 83 VOID_TO_NPVARIANT(*result); |
| 84 return false; |
| 85 } |
| 86 OBJECT_TO_NPVARIANT(object->np_object(), *result); |
| 87 break; |
| 88 } |
| 89 default: |
| 90 VOID_TO_NPVARIANT(*result); |
| 91 return false; |
| 92 } |
| 93 return true; |
| 94 } |
| 95 |
| 96 // ObjectAccessorTryCatch ------------------------------------------------------ |
| 97 |
| 98 // Automatically sets up a TryCatch for accessing the object identified by the |
| 99 // given PP_Var. The module from the object will be used for the exception |
| 100 // strings generated by the TryCatch. |
| 101 // |
| 102 // This will automatically retrieve the ObjectVar from the object and throw |
| 103 // an exception if it's invalid. At the end of construction, if there is no |
| 104 // exception, you know that there is no previously set exception, that the |
| 105 // object passed in is valid and ready to use (via the object() getter), and |
| 106 // that the TryCatch's pp_module() getter is also set up properly and ready to |
| 107 // use. |
| 108 class ObjectAccessorTryCatch : public TryCatch { |
41 public: | 109 public: |
42 ObjectAccessor(PP_Var var) | 110 ObjectAccessorTryCatch(PP_Var object, PP_Var* exception) |
43 : object_var_(V8ObjectVar::FromPPVar(var)), | 111 : TryCatch(exception), object_(NPObjectVar::FromPPVar(object)) { |
44 instance_(object_var_ ? object_var_->instance() : NULL) { | 112 if (!object_.get()) { |
45 } | 113 SetException(kInvalidObjectException); |
46 | 114 } |
47 // Check if the object is valid. If it isn't, set an exception and return | 115 } |
48 // false. | 116 |
49 bool IsValid(PP_Var* exception) { | 117 NPObjectVar* object() { return object_.get(); } |
50 // If we already have an exception, then the call is invalid according to | 118 |
51 // the unittests. | 119 PepperPluginInstanceImpl* GetPluginInstance() { |
52 if (exception && exception->type != PP_VARTYPE_UNDEFINED) | 120 return HostGlobals::Get()->GetInstance(object()->pp_instance()); |
53 return false; | 121 } |
54 if (instance_) | 122 |
55 return true; | 123 protected: |
56 if (exception) | 124 scoped_refptr<NPObjectVar> object_; |
57 *exception = ppapi::StringVar::StringToPPVar(kInvalidObjectException); | 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorTryCatch); |
| 127 }; |
| 128 |
| 129 // ObjectAccessiorWithIdentifierTryCatch --------------------------------------- |
| 130 |
| 131 // Automatically sets up a TryCatch for accessing the identifier on the given |
| 132 // object. This just extends ObjectAccessorTryCatch to additionally convert |
| 133 // the given identifier to an NPIdentifier and validate it, throwing an |
| 134 // exception if it's invalid. |
| 135 // |
| 136 // At the end of construction, if there is no exception, you know that there is |
| 137 // no previously set exception, that the object passed in is valid and ready to |
| 138 // use (via the object() getter), that the identifier is valid and ready to |
| 139 // use (via the identifier() getter), and that the TryCatch's pp_module() getter |
| 140 // is also set up properly and ready to use. |
| 141 class ObjectAccessorWithIdentifierTryCatch : public ObjectAccessorTryCatch { |
| 142 public: |
| 143 ObjectAccessorWithIdentifierTryCatch(PP_Var object, |
| 144 PP_Var identifier, |
| 145 PP_Var* exception) |
| 146 : ObjectAccessorTryCatch(object, exception), identifier_(0) { |
| 147 if (!has_exception()) { |
| 148 identifier_ = PPVarToNPIdentifier(identifier); |
| 149 if (!identifier_) |
| 150 SetException(kInvalidPropertyException); |
| 151 } |
| 152 } |
| 153 |
| 154 NPIdentifier identifier() const { return identifier_; } |
| 155 |
| 156 private: |
| 157 NPIdentifier identifier_; |
| 158 |
| 159 DISALLOW_COPY_AND_ASSIGN(ObjectAccessorWithIdentifierTryCatch); |
| 160 }; |
| 161 |
| 162 PP_Bool HasProperty(PP_Var var, PP_Var name, PP_Var* exception) { |
| 163 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
| 164 if (accessor.has_exception()) |
| 165 return PP_FALSE; |
| 166 return PP_FromBool(WebBindings::hasProperty( |
| 167 NULL, accessor.object()->np_object(), accessor.identifier())); |
| 168 } |
| 169 |
| 170 bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
| 171 return PP_ToBool(HasProperty(var, name, exception)); |
| 172 } |
| 173 |
| 174 bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
| 175 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
| 176 if (accessor.has_exception()) |
58 return false; | 177 return false; |
59 } | 178 return WebBindings::hasMethod( |
60 // Lazily grab the object so that the handle is created in the current handle | 179 NULL, accessor.object()->np_object(), accessor.identifier()); |
61 // scope. | |
62 v8::Handle<v8::Object> GetObject() { return object_var_->GetHandle(); } | |
63 PepperPluginInstanceImpl* instance() { return instance_; } | |
64 | |
65 private: | |
66 V8ObjectVar* object_var_; | |
67 PepperPluginInstanceImpl* instance_; | |
68 }; | |
69 | |
70 bool IsValidIdentifer(PP_Var identifier, PP_Var* exception) { | |
71 if (identifier.type == PP_VARTYPE_INT32 || | |
72 identifier.type == PP_VARTYPE_STRING) { | |
73 return true; | |
74 } | |
75 if (exception) | |
76 *exception = ppapi::StringVar::StringToPPVar(kInvalidIdentifierException); | |
77 return false; | |
78 } | |
79 | |
80 bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | |
81 ObjectAccessor accessor(var); | |
82 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | |
83 return false; | |
84 | |
85 PepperTryCatchVar try_catch(accessor.instance(), exception); | |
86 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | |
87 if (try_catch.HasException()) | |
88 return false; | |
89 | |
90 bool result = accessor.GetObject()->Has(v8_name); | |
91 if (try_catch.HasException()) | |
92 return false; | |
93 return result; | |
94 } | |
95 | |
96 bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | |
97 ObjectAccessor accessor(var); | |
98 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | |
99 return false; | |
100 | |
101 PepperTryCatchVar try_catch(accessor.instance(), exception); | |
102 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | |
103 if (try_catch.HasException()) | |
104 return false; | |
105 | |
106 bool result = accessor.GetObject()->Has(v8_name) && | |
107 accessor.GetObject()->Get(v8_name)->IsFunction(); | |
108 if (try_catch.HasException()) | |
109 return false; | |
110 return result; | |
111 } | 180 } |
112 | 181 |
113 PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) { | 182 PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) { |
114 ObjectAccessor accessor(var); | 183 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
115 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 184 if (accessor.has_exception()) |
116 return PP_MakeUndefined(); | 185 return PP_MakeUndefined(); |
117 | 186 |
118 PepperTryCatchVar try_catch(accessor.instance(), exception); | 187 NPVariant result; |
119 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 188 if (!WebBindings::getProperty(NULL, |
120 if (try_catch.HasException()) | 189 accessor.object()->np_object(), |
| 190 accessor.identifier(), |
| 191 &result)) { |
| 192 // An exception may have been raised. |
| 193 accessor.SetException(kUnableToGetPropertyException); |
121 return PP_MakeUndefined(); | 194 return PP_MakeUndefined(); |
122 | 195 } |
123 ScopedPPVar result_var = try_catch.FromV8(accessor.GetObject()->Get(v8_name)); | 196 |
124 if (try_catch.HasException()) | 197 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result); |
125 return PP_MakeUndefined(); | 198 WebBindings::releaseVariantValue(&result); |
126 | 199 return ret; |
127 return result_var.Release(); | |
128 } | 200 } |
129 | 201 |
130 void EnumerateProperties(PP_Var var, | 202 void EnumerateProperties(PP_Var var, |
131 uint32_t* property_count, | 203 uint32_t* property_count, |
132 PP_Var** properties, | 204 PP_Var** properties, |
133 PP_Var* exception) { | 205 PP_Var* exception) { |
134 ObjectAccessor accessor(var); | |
135 if (!accessor.IsValid(exception)) | |
136 return; | |
137 | |
138 PepperTryCatchVar try_catch(accessor.instance(), exception); | |
139 | |
140 *properties = NULL; | 206 *properties = NULL; |
141 *property_count = 0; | 207 *property_count = 0; |
142 | 208 |
143 v8::Local<v8::Array> identifiers = accessor.GetObject()->GetPropertyNames(); | 209 ObjectAccessorTryCatch accessor(var, exception); |
144 if (try_catch.HasException()) | 210 if (accessor.has_exception()) |
145 return; | 211 return; |
146 ScopedPPVarArray identifier_vars(identifiers->Length()); | 212 |
147 for (uint32_t i = 0; i < identifiers->Length(); ++i) { | 213 NPIdentifier* identifiers = NULL; |
148 ScopedPPVar var = try_catch.FromV8(identifiers->Get(i)); | 214 uint32_t count = 0; |
149 if (try_catch.HasException()) | 215 if (!WebBindings::enumerate( |
150 return; | 216 NULL, accessor.object()->np_object(), &identifiers, &count)) { |
151 identifier_vars.Set(i, var); | 217 accessor.SetException(kUnableToGetAllPropertiesException); |
152 } | 218 return; |
153 | 219 } |
154 size_t size = identifier_vars.size(); | 220 |
155 *properties = identifier_vars.Release( | 221 if (count == 0) |
156 ScopedPPVarArray::PassPPBMemoryAllocatedArray()); | 222 return; |
157 *property_count = size; | 223 |
| 224 *property_count = count; |
| 225 *properties = static_cast<PP_Var*>(malloc(sizeof(PP_Var) * count)); |
| 226 for (uint32_t i = 0; i < count; ++i) { |
| 227 (*properties)[i] = NPIdentifierToPPVar(identifiers[i]); |
| 228 } |
| 229 free(identifiers); |
158 } | 230 } |
159 | 231 |
160 void SetPropertyDeprecated(PP_Var var, | 232 void SetPropertyDeprecated(PP_Var var, |
161 PP_Var name, | 233 PP_Var name, |
162 PP_Var value, | 234 PP_Var value, |
163 PP_Var* exception) { | 235 PP_Var* exception) { |
164 ObjectAccessor accessor(var); | 236 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
165 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 237 if (accessor.has_exception()) |
166 return; | 238 return; |
167 | 239 |
168 PepperTryCatchVar try_catch(accessor.instance(), exception); | 240 NPVariant variant; |
169 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 241 if (!PPVarToNPVariantNoCopy(value, &variant)) { |
170 v8::Handle<v8::Value> v8_value = try_catch.ToV8(value); | 242 accessor.SetException(kInvalidValueException); |
171 | 243 return; |
172 if (try_catch.HasException()) | 244 } |
173 return; | 245 if (!WebBindings::setProperty(NULL, |
174 | 246 accessor.object()->np_object(), |
175 accessor.GetObject()->Set(v8_name, v8_value); | 247 accessor.identifier(), |
176 try_catch.HasException(); // Ensure an exception gets set if one occured. | 248 &variant)) |
| 249 accessor.SetException(kUnableToSetPropertyException); |
177 } | 250 } |
178 | 251 |
179 void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | 252 void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
180 ObjectAccessor accessor(var); | 253 ObjectAccessorWithIdentifierTryCatch accessor(var, name, exception); |
181 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 254 if (accessor.has_exception()) |
182 return; | 255 return; |
183 | 256 |
184 PepperTryCatchVar try_catch(accessor.instance(), exception); | 257 if (!WebBindings::removeProperty( |
185 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 258 NULL, accessor.object()->np_object(), accessor.identifier())) |
186 | 259 accessor.SetException(kUnableToRemovePropertyException); |
187 if (try_catch.HasException()) | 260 } |
188 return; | 261 |
189 | 262 PP_Var InternalCallDeprecated(ObjectAccessorTryCatch* accessor, |
190 accessor.GetObject()->Delete(v8_name); | |
191 try_catch.HasException(); // Ensure an exception gets set if one occured. | |
192 } | |
193 | |
194 PP_Var CallDeprecatedInternal(PP_Var var, | |
195 PP_Var method_name, | 263 PP_Var method_name, |
196 uint32_t argc, | 264 uint32_t argc, |
197 PP_Var* argv, | 265 PP_Var* argv, |
198 PP_Var* exception) { | 266 PP_Var* exception) { |
199 ObjectAccessor accessor(var); | 267 NPIdentifier identifier; |
200 if (!accessor.IsValid(exception)) | 268 if (method_name.type == PP_VARTYPE_UNDEFINED) { |
| 269 identifier = NULL; |
| 270 } else if (method_name.type == PP_VARTYPE_STRING) { |
| 271 // Specifically allow only string functions to be called. |
| 272 identifier = PPVarToNPIdentifier(method_name); |
| 273 if (!identifier) { |
| 274 accessor->SetException(kInvalidPropertyException); |
| 275 return PP_MakeUndefined(); |
| 276 } |
| 277 } else { |
| 278 accessor->SetException(kInvalidPropertyException); |
201 return PP_MakeUndefined(); | 279 return PP_MakeUndefined(); |
202 | 280 } |
203 // If the method name is undefined, set it to the empty string to trigger | 281 |
204 // calling |var| as a function. | 282 scoped_ptr<NPVariant[]> args; |
205 ScopedPPVar scoped_name(method_name); | 283 if (argc) { |
206 if (method_name.type == PP_VARTYPE_UNDEFINED) { | 284 args.reset(new NPVariant[argc]); |
207 scoped_name = ScopedPPVar(ScopedPPVar::PassRef(), | 285 for (uint32_t i = 0; i < argc; ++i) { |
208 StringVar::StringToPPVar("")); | 286 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) { |
209 } | 287 // This argument was invalid, throw an exception & give up. |
210 | 288 accessor->SetException(kInvalidValueException); |
211 PepperTryCatchVar try_catch(accessor.instance(), exception); | 289 return PP_MakeUndefined(); |
212 v8::Handle<v8::Value> v8_method_name = try_catch.ToV8(scoped_name.get()); | 290 } |
213 if (try_catch.HasException()) | 291 } |
| 292 } |
| 293 |
| 294 bool ok; |
| 295 |
| 296 NPVariant result; |
| 297 if (identifier) { |
| 298 ok = WebBindings::invoke(NULL, |
| 299 accessor->object()->np_object(), |
| 300 identifier, |
| 301 args.get(), |
| 302 argc, |
| 303 &result); |
| 304 } else { |
| 305 ok = WebBindings::invokeDefault( |
| 306 NULL, accessor->object()->np_object(), args.get(), argc, &result); |
| 307 } |
| 308 |
| 309 if (!ok) { |
| 310 // An exception may have been raised. |
| 311 accessor->SetException(kUnableToCallMethodException); |
214 return PP_MakeUndefined(); | 312 return PP_MakeUndefined(); |
215 | 313 } |
216 if (!v8_method_name->IsString()) { | 314 |
217 try_catch.SetException(kUnableToCallMethodException); | 315 PP_Var ret = NPVariantToPPVar(accessor->GetPluginInstance(), &result); |
218 return PP_MakeUndefined(); | 316 WebBindings::releaseVariantValue(&result); |
219 } | 317 return ret; |
220 | |
221 v8::Handle<v8::Object> function = accessor.GetObject(); | |
222 v8::Handle<v8::Object> recv = | |
223 accessor.instance()->GetContext()->Global(); | |
224 if (v8_method_name.As<v8::String>()->Length() != 0) { | |
225 function = function->Get(v8_method_name)->ToObject(); | |
226 recv = accessor.GetObject(); | |
227 } | |
228 | |
229 if (try_catch.HasException()) | |
230 return PP_MakeUndefined(); | |
231 | |
232 if (!function->IsFunction()) { | |
233 try_catch.SetException(kUnableToCallMethodException); | |
234 return PP_MakeUndefined(); | |
235 } | |
236 | |
237 scoped_ptr<v8::Handle<v8::Value>[] > converted_args( | |
238 new v8::Handle<v8::Value>[argc]); | |
239 for (uint32_t i = 0; i < argc; ++i) { | |
240 converted_args[i] = try_catch.ToV8(argv[i]); | |
241 if (try_catch.HasException()) | |
242 return PP_MakeUndefined(); | |
243 } | |
244 | |
245 blink::WebPluginContainer* container = accessor.instance()->container(); | |
246 blink::WebLocalFrame* frame = NULL; | |
247 if (container) | |
248 frame = container->element().document().frame(); | |
249 | |
250 if (!frame) { | |
251 try_catch.SetException("No frame to execute script in."); | |
252 return PP_MakeUndefined(); | |
253 } | |
254 | |
255 v8::Handle<v8::Value> result = frame->callFunctionEvenIfScriptDisabled( | |
256 function.As<v8::Function>(), recv, argc, converted_args.get()); | |
257 ScopedPPVar result_var = try_catch.FromV8(result); | |
258 | |
259 if (try_catch.HasException()) | |
260 return PP_MakeUndefined(); | |
261 | |
262 return result_var.Release(); | |
263 } | 318 } |
264 | 319 |
265 PP_Var CallDeprecated(PP_Var var, | 320 PP_Var CallDeprecated(PP_Var var, |
266 PP_Var method_name, | 321 PP_Var method_name, |
267 uint32_t argc, | 322 uint32_t argc, |
268 PP_Var* argv, | 323 PP_Var* argv, |
269 PP_Var* exception) { | 324 PP_Var* exception) { |
270 ObjectAccessor accessor(var); | 325 ObjectAccessorTryCatch accessor(var, exception); |
271 if (accessor.instance() && accessor.instance()->IsProcessingUserGesture()) { | 326 if (accessor.has_exception()) |
272 blink::WebScopedUserGesture user_gesture( | 327 return PP_MakeUndefined(); |
273 accessor.instance()->CurrentUserGestureToken()); | 328 PepperPluginInstanceImpl* plugin = accessor.GetPluginInstance(); |
274 return CallDeprecatedInternal(var, method_name, argc, argv, exception); | 329 if (plugin && plugin->IsProcessingUserGesture()) { |
| 330 blink::WebScopedUserGesture user_gesture(plugin->CurrentUserGestureToken()); |
| 331 return InternalCallDeprecated( |
| 332 &accessor, method_name, argc, argv, exception); |
275 } | 333 } |
276 return CallDeprecatedInternal(var, method_name, argc, argv, exception); | 334 return InternalCallDeprecated(&accessor, method_name, argc, argv, exception); |
277 } | 335 } |
278 | 336 |
279 PP_Var Construct(PP_Var var, uint32_t argc, PP_Var* argv, PP_Var* exception) { | 337 PP_Var Construct(PP_Var var, uint32_t argc, PP_Var* argv, PP_Var* exception) { |
280 // Deprecated. | 338 ObjectAccessorTryCatch accessor(var, exception); |
281 NOTREACHED(); | 339 if (accessor.has_exception()) |
282 return PP_MakeUndefined(); | 340 return PP_MakeUndefined(); |
| 341 |
| 342 scoped_ptr<NPVariant[]> args; |
| 343 if (argc) { |
| 344 args.reset(new NPVariant[argc]); |
| 345 for (uint32_t i = 0; i < argc; ++i) { |
| 346 if (!PPVarToNPVariantNoCopy(argv[i], &args[i])) { |
| 347 // This argument was invalid, throw an exception & give up. |
| 348 accessor.SetException(kInvalidValueException); |
| 349 return PP_MakeUndefined(); |
| 350 } |
| 351 } |
| 352 } |
| 353 |
| 354 NPVariant result; |
| 355 if (!WebBindings::construct( |
| 356 NULL, accessor.object()->np_object(), args.get(), argc, &result)) { |
| 357 // An exception may have been raised. |
| 358 accessor.SetException(kUnableToConstructException); |
| 359 return PP_MakeUndefined(); |
| 360 } |
| 361 |
| 362 PP_Var ret = NPVariantToPPVar(accessor.GetPluginInstance(), &result); |
| 363 WebBindings::releaseVariantValue(&result); |
| 364 return ret; |
283 } | 365 } |
284 | 366 |
285 bool IsInstanceOfDeprecated(PP_Var var, | 367 bool IsInstanceOfDeprecated(PP_Var var, |
286 const PPP_Class_Deprecated* ppp_class, | 368 const PPP_Class_Deprecated* ppp_class, |
287 void** ppp_class_data) { | 369 void** ppp_class_data) { |
288 scoped_refptr<V8ObjectVar> object(V8ObjectVar::FromPPVar(var)); | 370 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var)); |
289 if (!object.get()) | 371 if (!object.get()) |
290 return false; // Not an object at all. | 372 return false; // Not an object at all. |
291 | 373 |
292 v8::HandleScope handle_scope(object->instance()->GetIsolate()); | 374 return PluginObject::IsInstanceOf( |
293 v8::Context::Scope context_scope(object->instance()->GetContext()); | 375 object->np_object(), ppp_class, ppp_class_data); |
294 PluginObject* plugin_object = PluginObject::FromV8Object( | |
295 object->instance()->GetIsolate(), object->GetHandle()); | |
296 if (plugin_object && plugin_object->ppp_class() == ppp_class) { | |
297 if (ppp_class_data) | |
298 *ppp_class_data = plugin_object->ppp_class_data(); | |
299 return true; | |
300 } | |
301 | |
302 return false; | |
303 } | 376 } |
304 | 377 |
305 PP_Var CreateObjectDeprecated(PP_Instance pp_instance, | 378 PP_Var CreateObjectDeprecated(PP_Instance pp_instance, |
306 const PPP_Class_Deprecated* ppp_class, | 379 const PPP_Class_Deprecated* ppp_class, |
307 void* ppp_class_data) { | 380 void* ppp_class_data) { |
308 PepperPluginInstanceImpl* instance = | 381 PepperPluginInstanceImpl* instance = |
309 HostGlobals::Get()->GetInstance(pp_instance); | 382 HostGlobals::Get()->GetInstance(pp_instance); |
310 if (!instance) { | 383 if (!instance) { |
311 DLOG(ERROR) << "Create object passed an invalid instance."; | 384 DLOG(ERROR) << "Create object passed an invalid instance."; |
312 return PP_MakeNull(); | 385 return PP_MakeNull(); |
(...skipping 29 matching lines...) Expand all Loading... |
342 &CallDeprecated, | 415 &CallDeprecated, |
343 &Construct, | 416 &Construct, |
344 &IsInstanceOfDeprecated, | 417 &IsInstanceOfDeprecated, |
345 &CreateObjectDeprecated, | 418 &CreateObjectDeprecated, |
346 &CreateObjectWithModuleDeprecated, }; | 419 &CreateObjectWithModuleDeprecated, }; |
347 | 420 |
348 return &var_deprecated_interface; | 421 return &var_deprecated_interface; |
349 } | 422 } |
350 | 423 |
351 } // namespace content | 424 } // namespace content |
OLD | NEW |