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