| 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 "webkit/plugins/ppapi/npapi_glue.h" | 5 #include "webkit/plugins/ppapi/npapi_glue.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "ppapi/c/pp_var.h" | 10 #include "ppapi/c/pp_var.h" |
| 11 #include "webkit/plugins/ppapi/host_array_buffer_var.h" | |
| 12 #include "webkit/plugins/ppapi/host_globals.h" | |
| 13 #include "webkit/plugins/ppapi/host_var_tracker.h" | |
| 14 #include "webkit/plugins/ppapi/npobject_var.h" | |
| 15 #include "webkit/plugins/ppapi/plugin_module.h" | |
| 16 #include "webkit/plugins/ppapi/plugin_object.h" | |
| 17 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
| 18 #include "third_party/npapi/bindings/npapi.h" | 11 #include "third_party/npapi/bindings/npapi.h" |
| 19 #include "third_party/npapi/bindings/npruntime.h" | 12 #include "third_party/npapi/bindings/npruntime.h" |
| 20 #include "third_party/WebKit/public/web/WebBindings.h" | 13 #include "third_party/WebKit/public/web/WebBindings.h" |
| 21 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
| 22 #include "third_party/WebKit/public/web/WebElement.h" | 15 #include "third_party/WebKit/public/web/WebElement.h" |
| 23 #include "third_party/WebKit/public/web/WebFrame.h" | 16 #include "third_party/WebKit/public/web/WebFrame.h" |
| 24 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 17 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 25 #include "v8/include/v8.h" | 18 #include "v8/include/v8.h" |
| 19 #include "webkit/plugins/ppapi/host_array_buffer_var.h" |
| 20 #include "webkit/plugins/ppapi/host_globals.h" |
| 21 #include "webkit/plugins/ppapi/host_var_tracker.h" |
| 22 #include "webkit/plugins/ppapi/npobject_var.h" |
| 23 #include "webkit/plugins/ppapi/plugin_module.h" |
| 24 #include "webkit/plugins/ppapi/plugin_object.h" |
| 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 26 | 26 |
| 27 using ppapi::NPObjectVar; | 27 using ppapi::NPObjectVar; |
| 28 using ppapi::PpapiGlobals; | 28 using ppapi::PpapiGlobals; |
| 29 using ppapi::StringVar; | 29 using ppapi::StringVar; |
| 30 using ppapi::Var; | 30 using ppapi::Var; |
| 31 using WebKit::WebArrayBuffer; | 31 using WebKit::WebArrayBuffer; |
| 32 using WebKit::WebBindings; | 32 using WebKit::WebBindings; |
| 33 using WebKit::WebPluginContainer; | 33 using WebKit::WebPluginContainer; |
| 34 | 34 |
| 35 namespace webkit { | 35 namespace webkit { |
| 36 namespace ppapi { | 36 namespace ppapi { |
| 37 | 37 |
| 38 namespace { | 38 namespace { |
| 39 | 39 |
| 40 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; | 40 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; |
| 41 | 41 |
| 42 PP_Var NPObjectToPPVarImpl(PluginInstance* instance, | 42 PP_Var NPObjectToPPVarImpl(PluginInstanceImpl* instance, |
| 43 NPObject* object, | 43 NPObject* object, |
| 44 v8::Local<v8::Context> context) { | 44 v8::Local<v8::Context> context) { |
| 45 DCHECK(object); | 45 DCHECK(object); |
| 46 if (context.IsEmpty()) | 46 if (context.IsEmpty()) |
| 47 return PP_MakeUndefined(); | 47 return PP_MakeUndefined(); |
| 48 v8::Context::Scope context_scope(context); | 48 v8::Context::Scope context_scope(context); |
| 49 | 49 |
| 50 WebArrayBuffer buffer; | 50 WebArrayBuffer buffer; |
| 51 // TODO(dmichael): Should I protect against duplicate Vars representing the | 51 // TODO(dmichael): Should I protect against duplicate Vars representing the |
| 52 // same array buffer? It's probably not worth the trouble, since it will only | 52 // same array buffer? It's probably not worth the trouble, since it will only |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // if it becomes necessary. | 115 // if it becomes necessary. |
| 116 case PP_VARTYPE_ARRAY: | 116 case PP_VARTYPE_ARRAY: |
| 117 case PP_VARTYPE_DICTIONARY: | 117 case PP_VARTYPE_DICTIONARY: |
| 118 case PP_VARTYPE_ARRAY_BUFFER: | 118 case PP_VARTYPE_ARRAY_BUFFER: |
| 119 VOID_TO_NPVARIANT(*result); | 119 VOID_TO_NPVARIANT(*result); |
| 120 break; | 120 break; |
| 121 } | 121 } |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 | 124 |
| 125 PP_Var NPVariantToPPVar(PluginInstance* instance, const NPVariant* variant) { | 125 PP_Var NPVariantToPPVar(PluginInstanceImpl* instance, |
| 126 const NPVariant* variant) { |
| 126 switch (variant->type) { | 127 switch (variant->type) { |
| 127 case NPVariantType_Void: | 128 case NPVariantType_Void: |
| 128 return PP_MakeUndefined(); | 129 return PP_MakeUndefined(); |
| 129 case NPVariantType_Null: | 130 case NPVariantType_Null: |
| 130 return PP_MakeNull(); | 131 return PP_MakeNull(); |
| 131 case NPVariantType_Bool: | 132 case NPVariantType_Bool: |
| 132 return PP_MakeBool(PP_FromBool(NPVARIANT_TO_BOOLEAN(*variant))); | 133 return PP_MakeBool(PP_FromBool(NPVARIANT_TO_BOOLEAN(*variant))); |
| 133 case NPVariantType_Int32: | 134 case NPVariantType_Int32: |
| 134 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant)); | 135 return PP_MakeInt32(NPVARIANT_TO_INT32(*variant)); |
| 135 case NPVariantType_Double: | 136 case NPVariantType_Double: |
| (...skipping 28 matching lines...) Expand all Loading... |
| 164 const NPUTF8* string_value = NULL; | 165 const NPUTF8* string_value = NULL; |
| 165 int32_t int_value = 0; | 166 int32_t int_value = 0; |
| 166 bool is_string = false; | 167 bool is_string = false; |
| 167 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); | 168 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); |
| 168 if (is_string) | 169 if (is_string) |
| 169 return StringVar::StringToPPVar(string_value); | 170 return StringVar::StringToPPVar(string_value); |
| 170 | 171 |
| 171 return PP_MakeInt32(int_value); | 172 return PP_MakeInt32(int_value); |
| 172 } | 173 } |
| 173 | 174 |
| 174 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { | 175 PP_Var NPObjectToPPVar(PluginInstanceImpl* instance, NPObject* object) { |
| 175 WebPluginContainer* container = instance->container(); | 176 WebPluginContainer* container = instance->container(); |
| 176 // It's possible that container() is NULL if the plugin has been removed from | 177 // It's possible that container() is NULL if the plugin has been removed from |
| 177 // the DOM (but the PluginInstance is not destroyed yet). | 178 // the DOM (but the PluginInstance is not destroyed yet). |
| 178 if (!container) | 179 if (!container) |
| 179 return PP_MakeUndefined(); | 180 return PP_MakeUndefined(); |
| 180 v8::HandleScope scope(instance->GetIsolate()); | 181 v8::HandleScope scope(instance->GetIsolate()); |
| 181 v8::Local<v8::Context> context = | 182 v8::Local<v8::Context> context = |
| 182 container->element().document().frame()->mainWorldScriptContext(); | 183 container->element().document().frame()->mainWorldScriptContext(); |
| 183 return NPObjectToPPVarImpl(instance, object, context); | 184 return NPObjectToPPVarImpl(instance, object, context); |
| 184 } | 185 } |
| 185 | 186 |
| 186 PP_Var NPObjectToPPVarForTest(PluginInstance* instance, NPObject* object) { | 187 PP_Var NPObjectToPPVarForTest(PluginInstanceImpl* instance, NPObject* object) { |
| 187 v8::Isolate* test_isolate = v8::Isolate::New(); | 188 v8::Isolate* test_isolate = v8::Isolate::New(); |
| 188 PP_Var result = PP_MakeUndefined(); | 189 PP_Var result = PP_MakeUndefined(); |
| 189 { | 190 { |
| 190 v8::HandleScope scope(test_isolate); | 191 v8::HandleScope scope(test_isolate); |
| 191 v8::Isolate::Scope isolate_scope(test_isolate); | 192 v8::Isolate::Scope isolate_scope(test_isolate); |
| 192 v8::Local<v8::Context> context = v8::Context::New(test_isolate); | 193 v8::Local<v8::Context> context = v8::Context::New(test_isolate); |
| 193 result = NPObjectToPPVarImpl(instance, object, context); | 194 result = NPObjectToPPVarImpl(instance, object, context); |
| 194 } | 195 } |
| 195 test_isolate->Dispose(); | 196 test_isolate->Dispose(); |
| 196 return result; | 197 return result; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // Throws the current exception to JS. The exception must be set. | 273 // Throws the current exception to JS. The exception must be set. |
| 273 void PPResultAndExceptionToNPResult::ThrowException() { | 274 void PPResultAndExceptionToNPResult::ThrowException() { |
| 274 StringVar* string = StringVar::FromPPVar(exception_); | 275 StringVar* string = StringVar::FromPPVar(exception_); |
| 275 if (string) | 276 if (string) |
| 276 WebBindings::setException(object_var_, string->value().c_str()); | 277 WebBindings::setException(object_var_, string->value().c_str()); |
| 277 } | 278 } |
| 278 | 279 |
| 279 // PPVarArrayFromNPVariantArray ------------------------------------------------ | 280 // PPVarArrayFromNPVariantArray ------------------------------------------------ |
| 280 | 281 |
| 281 PPVarArrayFromNPVariantArray::PPVarArrayFromNPVariantArray( | 282 PPVarArrayFromNPVariantArray::PPVarArrayFromNPVariantArray( |
| 282 PluginInstance* instance, | 283 PluginInstanceImpl* instance, |
| 283 size_t size, | 284 size_t size, |
| 284 const NPVariant* variants) | 285 const NPVariant* variants) |
| 285 : size_(size) { | 286 : size_(size) { |
| 286 if (size_ > 0) { | 287 if (size_ > 0) { |
| 287 array_.reset(new PP_Var[size_]); | 288 array_.reset(new PP_Var[size_]); |
| 288 for (size_t i = 0; i < size_; i++) | 289 for (size_t i = 0; i < size_; i++) |
| 289 array_[i] = NPVariantToPPVar(instance, &variants[i]); | 290 array_[i] = NPVariantToPPVar(instance, &variants[i]); |
| 290 } | 291 } |
| 291 } | 292 } |
| 292 | 293 |
| 293 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { | 294 PPVarArrayFromNPVariantArray::~PPVarArrayFromNPVariantArray() { |
| 294 ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); | 295 ::ppapi::VarTracker* var_tracker = PpapiGlobals::Get()->GetVarTracker(); |
| 295 for (size_t i = 0; i < size_; i++) | 296 for (size_t i = 0; i < size_; i++) |
| 296 var_tracker->ReleaseVar(array_[i]); | 297 var_tracker->ReleaseVar(array_[i]); |
| 297 } | 298 } |
| 298 | 299 |
| 299 // PPVarFromNPObject ----------------------------------------------------------- | 300 // PPVarFromNPObject ----------------------------------------------------------- |
| 300 | 301 |
| 301 PPVarFromNPObject::PPVarFromNPObject(PluginInstance* instance, NPObject* object) | 302 PPVarFromNPObject::PPVarFromNPObject(PluginInstanceImpl* instance, |
| 303 NPObject* object) |
| 302 : var_(NPObjectToPPVar(instance, object)) { | 304 : var_(NPObjectToPPVar(instance, object)) { |
| 303 } | 305 } |
| 304 | 306 |
| 305 PPVarFromNPObject::~PPVarFromNPObject() { | 307 PPVarFromNPObject::~PPVarFromNPObject() { |
| 306 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_); | 308 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var_); |
| 307 } | 309 } |
| 308 | 310 |
| 309 // NPObjectAccessorWithIdentifier ---------------------------------------------- | 311 // NPObjectAccessorWithIdentifier ---------------------------------------------- |
| 310 | 312 |
| 311 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( | 313 NPObjectAccessorWithIdentifier::NPObjectAccessorWithIdentifier( |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 // static | 351 // static |
| 350 void TryCatch::Catch(void* self, const char* message) { | 352 void TryCatch::Catch(void* self, const char* message) { |
| 351 static_cast<TryCatch*>(self)->SetException(message); | 353 static_cast<TryCatch*>(self)->SetException(message); |
| 352 } | 354 } |
| 353 | 355 |
| 354 } // namespace ppapi | 356 } // namespace ppapi |
| 355 } // namespace webkit | 357 } // namespace webkit |
| OLD | NEW |