| 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/message_channel.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 if (exception && exception->type != PP_VARTYPE_UNDEFINED) | 56 if (exception && exception->type != PP_VARTYPE_UNDEFINED) |
| 57 return false; | 57 return false; |
| 58 if (instance_) | 58 if (instance_) |
| 59 return true; | 59 return true; |
| 60 if (exception) | 60 if (exception) |
| 61 *exception = ppapi::StringVar::StringToPPVar(kInvalidObjectException); | 61 *exception = ppapi::StringVar::StringToPPVar(kInvalidObjectException); |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 // Lazily grab the object so that the handle is created in the current handle | 64 // Lazily grab the object so that the handle is created in the current handle |
| 65 // scope. | 65 // scope. |
| 66 v8::Handle<v8::Object> GetObject() { return object_var_->GetHandle(); } | 66 v8::Local<v8::Object> GetObject() { return object_var_->GetHandle(); } |
| 67 PepperPluginInstanceImpl* instance() { return instance_; } | 67 PepperPluginInstanceImpl* instance() { return instance_; } |
| 68 V8VarConverter* converter() { return converter_.get(); } | 68 V8VarConverter* converter() { return converter_.get(); } |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 V8ObjectVar* object_var_; | 71 V8ObjectVar* object_var_; |
| 72 PepperPluginInstanceImpl* instance_; | 72 PepperPluginInstanceImpl* instance_; |
| 73 scoped_ptr<V8VarConverter> converter_; | 73 scoped_ptr<V8VarConverter> converter_; |
| 74 }; | 74 }; |
| 75 | 75 |
| 76 bool IsValidIdentifer(PP_Var identifier, PP_Var* exception) { | 76 bool IsValidIdentifer(PP_Var identifier, PP_Var* exception) { |
| 77 if (identifier.type == PP_VARTYPE_INT32 || | 77 if (identifier.type == PP_VARTYPE_INT32 || |
| 78 identifier.type == PP_VARTYPE_STRING) { | 78 identifier.type == PP_VARTYPE_STRING) { |
| 79 return true; | 79 return true; |
| 80 } | 80 } |
| 81 if (exception) | 81 if (exception) |
| 82 *exception = ppapi::StringVar::StringToPPVar(kInvalidIdentifierException); | 82 *exception = ppapi::StringVar::StringToPPVar(kInvalidIdentifierException); |
| 83 return false; | 83 return false; |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | 86 bool HasPropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
| 87 ObjectAccessor accessor(var); | 87 ObjectAccessor accessor(var); |
| 88 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 88 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 89 return false; | 89 return false; |
| 90 | 90 |
| 91 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 91 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 92 exception); | 92 exception); |
| 93 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 93 v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 94 if (try_catch.HasException()) | 94 if (try_catch.HasException()) |
| 95 return false; | 95 return false; |
| 96 | 96 |
| 97 bool result = accessor.GetObject()->Has(v8_name); | 97 bool result = accessor.GetObject()->Has(v8_name); |
| 98 if (try_catch.HasException()) | 98 if (try_catch.HasException()) |
| 99 return false; | 99 return false; |
| 100 return result; | 100 return result; |
| 101 } | 101 } |
| 102 | 102 |
| 103 bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | 103 bool HasMethodDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
| 104 ObjectAccessor accessor(var); | 104 ObjectAccessor accessor(var); |
| 105 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 105 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 106 return false; | 106 return false; |
| 107 | 107 |
| 108 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 108 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 109 exception); | 109 exception); |
| 110 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 110 v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 111 if (try_catch.HasException()) | 111 if (try_catch.HasException()) |
| 112 return false; | 112 return false; |
| 113 | 113 |
| 114 bool result = accessor.GetObject()->Has(v8_name) && | 114 bool result = accessor.GetObject()->Has(v8_name) && |
| 115 accessor.GetObject()->Get(v8_name)->IsFunction(); | 115 accessor.GetObject()->Get(v8_name)->IsFunction(); |
| 116 if (try_catch.HasException()) | 116 if (try_catch.HasException()) |
| 117 return false; | 117 return false; |
| 118 return result; | 118 return result; |
| 119 } | 119 } |
| 120 | 120 |
| 121 PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) { | 121 PP_Var GetProperty(PP_Var var, PP_Var name, PP_Var* exception) { |
| 122 ObjectAccessor accessor(var); | 122 ObjectAccessor accessor(var); |
| 123 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 123 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 124 return PP_MakeUndefined(); | 124 return PP_MakeUndefined(); |
| 125 | 125 |
| 126 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 126 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 127 exception); | 127 exception); |
| 128 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 128 v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 129 if (try_catch.HasException()) | 129 if (try_catch.HasException()) |
| 130 return PP_MakeUndefined(); | 130 return PP_MakeUndefined(); |
| 131 | 131 |
| 132 ScopedPPVar result_var = try_catch.FromV8(accessor.GetObject()->Get(v8_name)); | 132 ScopedPPVar result_var = try_catch.FromV8(accessor.GetObject()->Get(v8_name)); |
| 133 if (try_catch.HasException()) | 133 if (try_catch.HasException()) |
| 134 return PP_MakeUndefined(); | 134 return PP_MakeUndefined(); |
| 135 | 135 |
| 136 return result_var.Release(); | 136 return result_var.Release(); |
| 137 } | 137 } |
| 138 | 138 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 void SetPropertyDeprecated(PP_Var var, | 170 void SetPropertyDeprecated(PP_Var var, |
| 171 PP_Var name, | 171 PP_Var name, |
| 172 PP_Var value, | 172 PP_Var value, |
| 173 PP_Var* exception) { | 173 PP_Var* exception) { |
| 174 ObjectAccessor accessor(var); | 174 ObjectAccessor accessor(var); |
| 175 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 175 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 176 return; | 176 return; |
| 177 | 177 |
| 178 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 178 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 179 exception); | 179 exception); |
| 180 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 180 v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 181 v8::Handle<v8::Value> v8_value = try_catch.ToV8(value); | 181 v8::Local<v8::Value> v8_value = try_catch.ToV8(value); |
| 182 | 182 |
| 183 if (try_catch.HasException()) | 183 if (try_catch.HasException()) |
| 184 return; | 184 return; |
| 185 | 185 |
| 186 accessor.GetObject()->Set(v8_name, v8_value); | 186 accessor.GetObject()->Set(v8_name, v8_value); |
| 187 try_catch.HasException(); // Ensure an exception gets set if one occured. | 187 try_catch.HasException(); // Ensure an exception gets set if one occured. |
| 188 } | 188 } |
| 189 | 189 |
| 190 void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { | 190 void DeletePropertyDeprecated(PP_Var var, PP_Var name, PP_Var* exception) { |
| 191 ObjectAccessor accessor(var); | 191 ObjectAccessor accessor(var); |
| 192 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) | 192 if (!accessor.IsValid(exception) || !IsValidIdentifer(name, exception)) |
| 193 return; | 193 return; |
| 194 | 194 |
| 195 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 195 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 196 exception); | 196 exception); |
| 197 v8::Handle<v8::Value> v8_name = try_catch.ToV8(name); | 197 v8::Local<v8::Value> v8_name = try_catch.ToV8(name); |
| 198 | 198 |
| 199 if (try_catch.HasException()) | 199 if (try_catch.HasException()) |
| 200 return; | 200 return; |
| 201 | 201 |
| 202 accessor.GetObject()->Delete(v8_name); | 202 accessor.GetObject()->Delete(v8_name); |
| 203 try_catch.HasException(); // Ensure an exception gets set if one occured. | 203 try_catch.HasException(); // Ensure an exception gets set if one occured. |
| 204 } | 204 } |
| 205 | 205 |
| 206 PP_Var CallDeprecatedInternal(PP_Var var, | 206 PP_Var CallDeprecatedInternal(PP_Var var, |
| 207 PP_Var method_name, | 207 PP_Var method_name, |
| 208 uint32_t argc, | 208 uint32_t argc, |
| 209 PP_Var* argv, | 209 PP_Var* argv, |
| 210 PP_Var* exception) { | 210 PP_Var* exception) { |
| 211 ObjectAccessor accessor(var); | 211 ObjectAccessor accessor(var); |
| 212 if (!accessor.IsValid(exception)) | 212 if (!accessor.IsValid(exception)) |
| 213 return PP_MakeUndefined(); | 213 return PP_MakeUndefined(); |
| 214 | 214 |
| 215 // If the method name is undefined, set it to the empty string to trigger | 215 // If the method name is undefined, set it to the empty string to trigger |
| 216 // calling |var| as a function. | 216 // calling |var| as a function. |
| 217 ScopedPPVar scoped_name(method_name); | 217 ScopedPPVar scoped_name(method_name); |
| 218 if (method_name.type == PP_VARTYPE_UNDEFINED) { | 218 if (method_name.type == PP_VARTYPE_UNDEFINED) { |
| 219 scoped_name = ScopedPPVar(ScopedPPVar::PassRef(), | 219 scoped_name = ScopedPPVar(ScopedPPVar::PassRef(), |
| 220 StringVar::StringToPPVar("")); | 220 StringVar::StringToPPVar("")); |
| 221 } | 221 } |
| 222 | 222 |
| 223 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), | 223 PepperTryCatchVar try_catch(accessor.instance(), accessor.converter(), |
| 224 exception); | 224 exception); |
| 225 v8::Handle<v8::Value> v8_method_name = try_catch.ToV8(scoped_name.get()); | 225 v8::Local<v8::Value> v8_method_name = try_catch.ToV8(scoped_name.get()); |
| 226 if (try_catch.HasException()) | 226 if (try_catch.HasException()) |
| 227 return PP_MakeUndefined(); | 227 return PP_MakeUndefined(); |
| 228 | 228 |
| 229 if (!v8_method_name->IsString()) { | 229 if (!v8_method_name->IsString()) { |
| 230 try_catch.SetException(kUnableToCallMethodException); | 230 try_catch.SetException(kUnableToCallMethodException); |
| 231 return PP_MakeUndefined(); | 231 return PP_MakeUndefined(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 v8::Handle<v8::Object> function = accessor.GetObject(); | 234 v8::Local<v8::Object> function = accessor.GetObject(); |
| 235 v8::Handle<v8::Object> recv = | 235 v8::Local<v8::Object> recv = |
| 236 accessor.instance()->GetMainWorldContext()->Global(); | 236 accessor.instance()->GetMainWorldContext()->Global(); |
| 237 if (v8_method_name.As<v8::String>()->Length() != 0) { | 237 if (v8_method_name.As<v8::String>()->Length() != 0) { |
| 238 function = function->Get(v8_method_name) | 238 function = function->Get(v8_method_name) |
| 239 ->ToObject(accessor.instance()->GetIsolate()); | 239 ->ToObject(accessor.instance()->GetIsolate()); |
| 240 recv = accessor.GetObject(); | 240 recv = accessor.GetObject(); |
| 241 } | 241 } |
| 242 | 242 |
| 243 if (try_catch.HasException()) | 243 if (try_catch.HasException()) |
| 244 return PP_MakeUndefined(); | 244 return PP_MakeUndefined(); |
| 245 | 245 |
| 246 if (!function->IsFunction()) { | 246 if (!function->IsFunction()) { |
| 247 try_catch.SetException(kUnableToCallMethodException); | 247 try_catch.SetException(kUnableToCallMethodException); |
| 248 return PP_MakeUndefined(); | 248 return PP_MakeUndefined(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 scoped_ptr<v8::Handle<v8::Value>[] > converted_args( | 251 scoped_ptr<v8::Local<v8::Value>[] > converted_args( |
| 252 new v8::Handle<v8::Value>[argc]); | 252 new v8::Local<v8::Value>[argc]); |
| 253 for (uint32_t i = 0; i < argc; ++i) { | 253 for (uint32_t i = 0; i < argc; ++i) { |
| 254 converted_args[i] = try_catch.ToV8(argv[i]); | 254 converted_args[i] = try_catch.ToV8(argv[i]); |
| 255 if (try_catch.HasException()) | 255 if (try_catch.HasException()) |
| 256 return PP_MakeUndefined(); | 256 return PP_MakeUndefined(); |
| 257 } | 257 } |
| 258 | 258 |
| 259 blink::WebPluginContainer* container = accessor.instance()->container(); | 259 blink::WebPluginContainer* container = accessor.instance()->container(); |
| 260 blink::WebLocalFrame* frame = NULL; | 260 blink::WebLocalFrame* frame = NULL; |
| 261 if (container) | 261 if (container) |
| 262 frame = container->element().document().frame(); | 262 frame = container->element().document().frame(); |
| 263 | 263 |
| 264 if (!frame) { | 264 if (!frame) { |
| 265 try_catch.SetException("No frame to execute script in."); | 265 try_catch.SetException("No frame to execute script in."); |
| 266 return PP_MakeUndefined(); | 266 return PP_MakeUndefined(); |
| 267 } | 267 } |
| 268 | 268 |
| 269 v8::Handle<v8::Value> result = frame->callFunctionEvenIfScriptDisabled( | 269 v8::Local<v8::Value> result = frame->callFunctionEvenIfScriptDisabled( |
| 270 function.As<v8::Function>(), recv, argc, converted_args.get()); | 270 function.As<v8::Function>(), recv, argc, converted_args.get()); |
| 271 ScopedPPVar result_var = try_catch.FromV8(result); | 271 ScopedPPVar result_var = try_catch.FromV8(result); |
| 272 | 272 |
| 273 if (try_catch.HasException()) | 273 if (try_catch.HasException()) |
| 274 return PP_MakeUndefined(); | 274 return PP_MakeUndefined(); |
| 275 | 275 |
| 276 return result_var.Release(); | 276 return result_var.Release(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 PP_Var CallDeprecated(PP_Var var, | 279 PP_Var CallDeprecated(PP_Var var, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 297 } | 297 } |
| 298 | 298 |
| 299 bool IsInstanceOfDeprecated(PP_Var var, | 299 bool IsInstanceOfDeprecated(PP_Var var, |
| 300 const PPP_Class_Deprecated* ppp_class, | 300 const PPP_Class_Deprecated* ppp_class, |
| 301 void** ppp_class_data) { | 301 void** ppp_class_data) { |
| 302 scoped_refptr<V8ObjectVar> object(V8ObjectVar::FromPPVar(var)); | 302 scoped_refptr<V8ObjectVar> object(V8ObjectVar::FromPPVar(var)); |
| 303 if (!object.get()) | 303 if (!object.get()) |
| 304 return false; // Not an object at all. | 304 return false; // Not an object at all. |
| 305 | 305 |
| 306 v8::HandleScope handle_scope(object->instance()->GetIsolate()); | 306 v8::HandleScope handle_scope(object->instance()->GetIsolate()); |
| 307 v8::Handle<v8::Context> context = object->instance()->GetMainWorldContext(); | 307 v8::Local<v8::Context> context = object->instance()->GetMainWorldContext(); |
| 308 if (context.IsEmpty()) | 308 if (context.IsEmpty()) |
| 309 return false; | 309 return false; |
| 310 v8::Context::Scope context_scope(context); | 310 v8::Context::Scope context_scope(context); |
| 311 PluginObject* plugin_object = PluginObject::FromV8Object( | 311 PluginObject* plugin_object = PluginObject::FromV8Object( |
| 312 object->instance()->GetIsolate(), object->GetHandle()); | 312 object->instance()->GetIsolate(), object->GetHandle()); |
| 313 if (plugin_object && plugin_object->ppp_class() == ppp_class) { | 313 if (plugin_object && plugin_object->ppp_class() == ppp_class) { |
| 314 if (ppp_class_data) | 314 if (ppp_class_data) |
| 315 *ppp_class_data = plugin_object->ppp_class_data(); | 315 *ppp_class_data = plugin_object->ppp_class_data(); |
| 316 return true; | 316 return true; |
| 317 } | 317 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 &CallDeprecated, | 359 &CallDeprecated, |
| 360 &Construct, | 360 &Construct, |
| 361 &IsInstanceOfDeprecated, | 361 &IsInstanceOfDeprecated, |
| 362 &CreateObjectDeprecated, | 362 &CreateObjectDeprecated, |
| 363 &CreateObjectWithModuleDeprecated, }; | 363 &CreateObjectWithModuleDeprecated, }; |
| 364 | 364 |
| 365 return &var_deprecated_interface; | 365 return &var_deprecated_interface; |
| 366 } | 366 } |
| 367 | 367 |
| 368 } // namespace content | 368 } // namespace content |
| OLD | NEW |