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 CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ |
6 #define WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ | 6 #define CONTENT_RENDERER_PEPPER_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 "content/common/content_export.h" |
10 #include "ppapi/c/pp_module.h" | 11 #include "ppapi/c/pp_module.h" |
11 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
12 #include "webkit/plugins/webkit_plugins_export.h" | |
13 | 13 |
14 struct NPObject; | 14 struct NPObject; |
15 typedef struct _NPVariant NPVariant; | 15 typedef struct _NPVariant NPVariant; |
16 typedef void* NPIdentifier; | 16 typedef void* NPIdentifier; |
17 | 17 |
18 namespace webkit { | 18 namespace webkit { |
19 namespace ppapi { | 19 namespace ppapi { |
20 | 20 |
21 class PluginInstanceImpl; | 21 class PluginInstanceImpl; |
22 class PluginObject; | 22 class PluginObject; |
23 | 23 |
24 // Utilities ------------------------------------------------------------------- | 24 // Utilities ------------------------------------------------------------------- |
25 | 25 |
26 // 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. |
27 // 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 |
28 // NPVariant will be set to a void one. | 28 // NPVariant will be set to a void one. |
29 // | 29 // |
30 // 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 |
31 // an object. | 31 // an object. |
32 bool PPVarToNPVariant(PP_Var var, NPVariant* result); | 32 bool PPVarToNPVariant(PP_Var var, NPVariant* result); |
33 | 33 |
34 // 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 |
35 // the NPVariant will be copied unless the NPVariant corresponds to an | 35 // the NPVariant will be copied unless the NPVariant corresponds to an |
36 // object. This will handle all Variant types including POD, strings, and | 36 // object. This will handle all Variant types including POD, strings, and |
37 // objects. | 37 // objects. |
38 // | 38 // |
39 // 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 |
40 // 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. |
41 WEBKIT_PLUGINS_EXPORT PP_Var NPVariantToPPVar(PluginInstanceImpl* instance, | 41 PP_Var NPVariantToPPVar(PluginInstanceImpl* instance, const NPVariant* variant); |
42 const NPVariant* variant); | |
43 | 42 |
44 // Returns a NPIdentifier that corresponds to the given PP_Var. The contents | 43 // Returns a NPIdentifier that corresponds to the given PP_Var. The contents |
45 // of the PP_Var will be copied. Returns 0 if the given PP_Var is not a a | 44 // of the PP_Var will be copied. Returns 0 if the given PP_Var is not a a |
46 // string or integer type. | 45 // string or integer type. |
47 NPIdentifier PPVarToNPIdentifier(PP_Var var); | 46 NPIdentifier PPVarToNPIdentifier(PP_Var var); |
48 | 47 |
49 // Returns a PP_Var corresponding to the given identifier. In the case of | 48 // Returns a PP_Var corresponding to the given identifier. In the case of |
50 // a string identifier, the returned string will have a reference count of 1. | 49 // a string identifier, the returned string will have a reference count of 1. |
51 PP_Var NPIdentifierToPPVar(NPIdentifier id); | 50 PP_Var NPIdentifierToPPVar(NPIdentifier id); |
52 | 51 |
53 // Helper function to create a PP_Var of type object that contains the given | 52 // Helper function to create a PP_Var of type object that contains the given |
54 // NPObject for use byt he given module. Calling this function multiple times | 53 // NPObject for use byt he given module. Calling this function multiple times |
55 // given the same module + NPObject results in the same PP_Var, assuming that | 54 // given the same module + NPObject results in the same PP_Var, assuming that |
56 // there is still a PP_Var with a reference open to it from the previous | 55 // there is still a PP_Var with a reference open to it from the previous |
57 // call. | 56 // call. |
58 // | 57 // |
59 // The instance is necessary because we can have different instances pointing to | 58 // The instance is necessary because we can have different instances pointing to |
60 // the same NPObject, and we want to keep their refs separate. | 59 // the same NPObject, and we want to keep their refs separate. |
61 // | 60 // |
62 // If no ObjectVar currently exists corresponding to the NPObject, one is | 61 // If no ObjectVar currently exists corresponding to the NPObject, one is |
63 // created associated with the given module. | 62 // created associated with the given module. |
64 // | 63 // |
65 // Note: this could easily be changed to take a PP_Instance instead if that | 64 // Note: this could easily be changed to take a PP_Instance instead if that |
66 // makes certain calls in the future easier. Currently all callers have a | 65 // makes certain calls in the future easier. Currently all callers have a |
67 // PluginInstance so that's what we use here. | 66 // PluginInstance so that's what we use here. |
68 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVar(PluginInstanceImpl* instance, | 67 CONTENT_EXPORT PP_Var NPObjectToPPVar(PluginInstanceImpl* instance, |
69 NPObject* object); | 68 NPObject* object); |
70 | 69 |
71 // This version creates a default v8::Context rather than using the one from | 70 // This version creates a default v8::Context rather than using the one from |
72 // the container of |instance|. It is only for use in unit tests, where we don't | 71 // the container of |instance|. It is only for use in unit tests, where we don't |
73 // have a real container for |instance|. | 72 // have a real container for |instance|. |
74 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVarForTest( | 73 CONTENT_EXPORT PP_Var NPObjectToPPVarForTest(PluginInstanceImpl* instance, |
75 PluginInstanceImpl* instance, | 74 NPObject* object); |
76 NPObject* object); | |
77 | 75 |
78 // PPResultAndExceptionToNPResult ---------------------------------------------- | 76 // PPResultAndExceptionToNPResult ---------------------------------------------- |
79 | 77 |
80 // Convenience object for converting a PPAPI call that can throw an exception | 78 // Convenience object for converting a PPAPI call that can throw an exception |
81 // and optionally return a value, back to the NPAPI layer which expects a | 79 // and optionally return a value, back to the NPAPI layer which expects a |
82 // NPVariant as a result. | 80 // NPVariant as a result. |
83 // | 81 // |
84 // Normal usage is that you will pass the result of exception() to the | 82 // Normal usage is that you will pass the result of exception() to the |
85 // PPAPI function as the exception output parameter. Then you will either | 83 // PPAPI function as the exception output parameter. Then you will either |
86 // call SetResult with the result of the PPAPI call, or | 84 // call SetResult with the result of the PPAPI call, or |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 // the exception itself has been stored. | 255 // the exception itself has been stored. |
258 bool has_exception_; | 256 bool has_exception_; |
259 | 257 |
260 // May be null if the consumer isn't interesting in catching exceptions. | 258 // May be null if the consumer isn't interesting in catching exceptions. |
261 PP_Var* exception_; | 259 PP_Var* exception_; |
262 }; | 260 }; |
263 | 261 |
264 } // namespace ppapi | 262 } // namespace ppapi |
265 } // namespace webkit | 263 } // namespace webkit |
266 | 264 |
267 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ | 265 #endif // CONTENT_RENDERER_PEPPER_NPAPI_GLUE_H_ |
OLD | NEW |