| 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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "webkit/plugins/ppapi/host_array_buffer_var.h" |
| 10 #include "webkit/plugins/ppapi/host_globals.h" | 11 #include "webkit/plugins/ppapi/host_globals.h" |
| 11 #include "webkit/plugins/ppapi/host_var_tracker.h" | 12 #include "webkit/plugins/ppapi/host_var_tracker.h" |
| 12 #include "webkit/plugins/ppapi/npobject_var.h" | 13 #include "webkit/plugins/ppapi/npobject_var.h" |
| 13 #include "webkit/plugins/ppapi/plugin_module.h" | 14 #include "webkit/plugins/ppapi/plugin_module.h" |
| 14 #include "webkit/plugins/ppapi/plugin_object.h" | 15 #include "webkit/plugins/ppapi/plugin_object.h" |
| 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 16 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 16 #include "third_party/npapi/bindings/npapi.h" | 17 #include "third_party/npapi/bindings/npapi.h" |
| 17 #include "third_party/npapi/bindings/npruntime.h" | 18 #include "third_party/npapi/bindings/npruntime.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 19 | 20 |
| 20 using ppapi::NPObjectVar; | 21 using ppapi::NPObjectVar; |
| 21 using ppapi::PpapiGlobals; | 22 using ppapi::PpapiGlobals; |
| 22 using ppapi::StringVar; | 23 using ppapi::StringVar; |
| 23 using ppapi::Var; | 24 using ppapi::Var; |
| 25 using WebKit::WebArrayBuffer; |
| 24 using WebKit::WebBindings; | 26 using WebKit::WebBindings; |
| 25 | 27 |
| 26 namespace webkit { | 28 namespace webkit { |
| 27 namespace ppapi { | 29 namespace ppapi { |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; | 33 const char kInvalidPluginValue[] = "Error: Plugin returned invalid value."; |
| 32 | 34 |
| 33 } // namespace | 35 } // namespace |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 case PP_VARTYPE_OBJECT: { | 68 case PP_VARTYPE_OBJECT: { |
| 67 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var)); | 69 scoped_refptr<NPObjectVar> object(NPObjectVar::FromPPVar(var)); |
| 68 if (!object) { | 70 if (!object) { |
| 69 VOID_TO_NPVARIANT(*result); | 71 VOID_TO_NPVARIANT(*result); |
| 70 return false; | 72 return false; |
| 71 } | 73 } |
| 72 OBJECT_TO_NPVARIANT(WebBindings::retainObject(object->np_object()), | 74 OBJECT_TO_NPVARIANT(WebBindings::retainObject(object->np_object()), |
| 73 *result); | 75 *result); |
| 74 break; | 76 break; |
| 75 } | 77 } |
| 78 // The following types are not supported for use with PPB_Var_Deprecated, |
| 79 // because PPB_Var_Deprecated is only for trusted plugins, and the trusted |
| 80 // plugins we have don't need these types. We can add support in the future |
| 81 // if it becomes necessary. |
| 76 case PP_VARTYPE_ARRAY: | 82 case PP_VARTYPE_ARRAY: |
| 77 case PP_VARTYPE_DICTIONARY: | 83 case PP_VARTYPE_DICTIONARY: |
| 78 case PP_VARTYPE_ARRAY_BUFFER: | 84 case PP_VARTYPE_ARRAY_BUFFER: |
| 79 VOID_TO_NPVARIANT(*result); | 85 VOID_TO_NPVARIANT(*result); |
| 80 break; | 86 break; |
| 81 } | 87 } |
| 82 return true; | 88 return true; |
| 83 } | 89 } |
| 84 | 90 |
| 85 PP_Var NPVariantToPPVar(PluginInstance* instance, const NPVariant* variant) { | 91 PP_Var NPVariantToPPVar(PluginInstance* instance, const NPVariant* variant) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 bool is_string = false; | 132 bool is_string = false; |
| 127 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); | 133 WebBindings::extractIdentifierData(id, string_value, int_value, is_string); |
| 128 if (is_string) | 134 if (is_string) |
| 129 return StringVar::StringToPPVar(string_value); | 135 return StringVar::StringToPPVar(string_value); |
| 130 | 136 |
| 131 return PP_MakeInt32(int_value); | 137 return PP_MakeInt32(int_value); |
| 132 } | 138 } |
| 133 | 139 |
| 134 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { | 140 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object) { |
| 135 DCHECK(object); | 141 DCHECK(object); |
| 142 WebArrayBuffer buffer; |
| 143 // TODO(dmichael): Should I protect against duplicate Vars representing the |
| 144 // same array buffer? It's probably not worth the trouble, since it will only |
| 145 // affect in-process plugins. |
| 146 if (WebBindings::getArrayBuffer(object, &buffer)) { |
| 147 scoped_refptr<HostArrayBufferVar> buffer_var( |
| 148 new HostArrayBufferVar(buffer)); |
| 149 return buffer_var->GetPPVar(); |
| 150 } |
| 136 scoped_refptr<NPObjectVar> object_var( | 151 scoped_refptr<NPObjectVar> object_var( |
| 137 HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject( | 152 HostGlobals::Get()->host_var_tracker()->NPObjectVarForNPObject( |
| 138 instance->pp_instance(), object)); | 153 instance->pp_instance(), object)); |
| 139 if (!object_var) { // No object for this module yet, make a new one. | 154 if (!object_var) { // No object for this module yet, make a new one. |
| 140 object_var = new NPObjectVar(instance->pp_instance(), object); | 155 object_var = new NPObjectVar(instance->pp_instance(), object); |
| 141 } | 156 } |
| 142 return object_var->GetPPVar(); | 157 return object_var->GetPPVar(); |
| 143 } | 158 } |
| 144 | 159 |
| 145 // PPResultAndExceptionToNPResult ---------------------------------------------- | 160 // PPResultAndExceptionToNPResult ---------------------------------------------- |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 } | 307 } |
| 293 } | 308 } |
| 294 | 309 |
| 295 // static | 310 // static |
| 296 void TryCatch::Catch(void* self, const char* message) { | 311 void TryCatch::Catch(void* self, const char* message) { |
| 297 static_cast<TryCatch*>(self)->SetException(message); | 312 static_cast<TryCatch*>(self)->SetException(message); |
| 298 } | 313 } |
| 299 | 314 |
| 300 } // namespace ppapi | 315 } // namespace ppapi |
| 301 } // namespace webkit | 316 } // namespace webkit |
| OLD | NEW |