| 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 #ifndef WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ | 5 #ifndef WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ |
| 6 #define WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ppapi/c/pp_module.h" | 10 #include "ppapi/c/pp_module.h" |
| 11 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
| 12 #include "webkit/plugins/webkit_plugins_export.h" |
| 12 | 13 |
| 13 struct NPObject; | 14 struct NPObject; |
| 14 typedef struct _NPVariant NPVariant; | 15 typedef struct _NPVariant NPVariant; |
| 15 typedef void* NPIdentifier; | 16 typedef void* NPIdentifier; |
| 16 | 17 |
| 17 namespace webkit { | 18 namespace webkit { |
| 18 namespace ppapi { | 19 namespace ppapi { |
| 19 | 20 |
| 20 class PluginInstance; | 21 class PluginInstance; |
| 21 class PluginObject; | 22 class PluginObject; |
| 22 | 23 |
| 23 // Utilities ------------------------------------------------------------------- | 24 // Utilities ------------------------------------------------------------------- |
| 24 | 25 |
| 25 // Converts the given PP_Var to an NPVariant, returning true on success. | 26 // Converts the given PP_Var to an NPVariant, returning true on success. |
| 26 // False means that the given variant is invalid. In this case, the result | 27 // False means that the given variant is invalid. In this case, the result |
| 27 // NPVariant will be set to a void one. | 28 // NPVariant will be set to a void one. |
| 28 // | 29 // |
| 29 // The contents of the PP_Var will be copied unless the PP_Var corresponds to | 30 // The contents of the PP_Var will be copied unless the PP_Var corresponds to |
| 30 // an object. | 31 // an object. |
| 31 bool PPVarToNPVariant(PP_Var var, NPVariant* result); | 32 bool PPVarToNPVariant(PP_Var var, NPVariant* result); |
| 32 | 33 |
| 33 // Returns a PP_Var that corresponds to the given NPVariant. The contents of | 34 // Returns a PP_Var that corresponds to the given NPVariant. The contents of |
| 34 // the NPVariant will be copied unless the NPVariant corresponds to an | 35 // the NPVariant will be copied unless the NPVariant corresponds to an |
| 35 // object. This will handle all Variant types including POD, strings, and | 36 // object. This will handle all Variant types including POD, strings, and |
| 36 // objects. | 37 // objects. |
| 37 // | 38 // |
| 38 // The returned PP_Var will have a refcount of 1, this passing ownership of | 39 // The returned PP_Var will have a refcount of 1, this passing ownership of |
| 39 // the reference to the caller. This is suitable for returning to a plugin. | 40 // the reference to the caller. This is suitable for returning to a plugin. |
| 40 PP_Var NPVariantToPPVar(PluginInstance* instance, const NPVariant* variant); | 41 WEBKIT_PLUGINS_EXPORT PP_Var NPVariantToPPVar(PluginInstance* instance, |
| 42 const NPVariant* variant); |
| 41 | 43 |
| 42 // Returns a NPIdentifier that corresponds to the given PP_Var. The contents | 44 // Returns a NPIdentifier that corresponds to the given PP_Var. The contents |
| 43 // of the PP_Var will be copied. Returns 0 if the given PP_Var is not a a | 45 // of the PP_Var will be copied. Returns 0 if the given PP_Var is not a a |
| 44 // string or integer type. | 46 // string or integer type. |
| 45 NPIdentifier PPVarToNPIdentifier(PP_Var var); | 47 NPIdentifier PPVarToNPIdentifier(PP_Var var); |
| 46 | 48 |
| 47 // Returns a PP_Var corresponding to the given identifier. In the case of | 49 // Returns a PP_Var corresponding to the given identifier. In the case of |
| 48 // a string identifier, the string will be allocated associated with the | 50 // a string identifier, the string will be allocated associated with the |
| 49 // given module. A returned string will have a reference count of 1. | 51 // given module. A returned string will have a reference count of 1. |
| 50 PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id); | 52 PP_Var NPIdentifierToPPVar(PP_Module module, NPIdentifier id); |
| 51 | 53 |
| 52 // Helper function to create a PP_Var of type object that contains the given | 54 // Helper function to create a PP_Var of type object that contains the given |
| 53 // NPObject for use byt he given module. Calling this function multiple times | 55 // NPObject for use byt he given module. Calling this function multiple times |
| 54 // given the same module + NPObject results in the same PP_Var, assuming that | 56 // given the same module + NPObject results in the same PP_Var, assuming that |
| 55 // there is still a PP_Var with a reference open to it from the previous | 57 // there is still a PP_Var with a reference open to it from the previous |
| 56 // call. | 58 // call. |
| 57 // | 59 // |
| 58 // The module is necessary because we can have different modules pointing to | 60 // The module is necessary because we can have different modules pointing to |
| 59 // the same NPObject, and we want to keep their refs separate. | 61 // the same NPObject, and we want to keep their refs separate. |
| 60 // | 62 // |
| 61 // If no ObjectVar currently exists corresponding to the NPObject, one is | 63 // If no ObjectVar currently exists corresponding to the NPObject, one is |
| 62 // created associated with the given module. | 64 // created associated with the given module. |
| 63 // | 65 // |
| 64 // Note: this could easily be changed to take a PP_Instance instead if that | 66 // Note: this could easily be changed to take a PP_Instance instead if that |
| 65 // makes certain calls in the future easier. Currently all callers have a | 67 // makes certain calls in the future easier. Currently all callers have a |
| 66 // PluginInstance so that's what we use here. | 68 // PluginInstance so that's what we use here. |
| 67 PP_Var NPObjectToPPVar(PluginInstance* instance, NPObject* object); | 69 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVar(PluginInstance* instance, |
| 70 NPObject* object); |
| 68 | 71 |
| 69 // PPResultAndExceptionToNPResult ---------------------------------------------- | 72 // PPResultAndExceptionToNPResult ---------------------------------------------- |
| 70 | 73 |
| 71 // Convenience object for converting a PPAPI call that can throw an exception | 74 // Convenience object for converting a PPAPI call that can throw an exception |
| 72 // and optionally return a value, back to the NPAPI layer which expects a | 75 // and optionally return a value, back to the NPAPI layer which expects a |
| 73 // NPVariant as a result. | 76 // NPVariant as a result. |
| 74 // | 77 // |
| 75 // Normal usage is that you will pass the result of exception() to the | 78 // Normal usage is that you will pass the result of exception() to the |
| 76 // PPAPI function as the exception output parameter. Then you will either | 79 // PPAPI function as the exception output parameter. Then you will either |
| 77 // call SetResult with the result of the PPAPI call, or | 80 // call SetResult with the result of the PPAPI call, or |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 bool has_exception_; | 274 bool has_exception_; |
| 272 | 275 |
| 273 // May be null if the consumer isn't interesting in catching exceptions. | 276 // May be null if the consumer isn't interesting in catching exceptions. |
| 274 PP_Var* exception_; | 277 PP_Var* exception_; |
| 275 }; | 278 }; |
| 276 | 279 |
| 277 } // namespace ppapi | 280 } // namespace ppapi |
| 278 } // namespace webkit | 281 } // namespace webkit |
| 279 | 282 |
| 280 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ | 283 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ |
| OLD | NEW |