Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: webkit/plugins/ppapi/npapi_glue.h

Issue 19744007: Create a public API around webkit::ppapi::PluginInstance and use it in chrome. After this, webkit/p… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #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 PluginInstance; 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(PluginInstance* instance, 41 WEBKIT_PLUGINS_EXPORT PP_Var NPVariantToPPVar(PluginInstanceImpl* instance,
42 const NPVariant* variant); 42 const NPVariant* variant);
43 43
44 // 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
45 // 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
46 // string or integer type. 46 // string or integer type.
47 NPIdentifier PPVarToNPIdentifier(PP_Var var); 47 NPIdentifier PPVarToNPIdentifier(PP_Var var);
48 48
49 // 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
50 // a string identifier, the returned string will have a reference count of 1. 50 // a string identifier, the returned string will have a reference count of 1.
51 PP_Var NPIdentifierToPPVar(NPIdentifier id); 51 PP_Var NPIdentifierToPPVar(NPIdentifier id);
52 52
53 // Helper function to create a PP_Var of type object that contains the given 53 // 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 54 // 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 55 // 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 56 // there is still a PP_Var with a reference open to it from the previous
57 // call. 57 // call.
58 // 58 //
59 // The instance is necessary because we can have different instances pointing to 59 // The instance is necessary because we can have different instances pointing to
60 // the same NPObject, and we want to keep their refs separate. 60 // the same NPObject, and we want to keep their refs separate.
61 // 61 //
62 // If no ObjectVar currently exists corresponding to the NPObject, one is 62 // If no ObjectVar currently exists corresponding to the NPObject, one is
63 // created associated with the given module. 63 // created associated with the given module.
64 // 64 //
65 // Note: this could easily be changed to take a PP_Instance instead if that 65 // 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 66 // makes certain calls in the future easier. Currently all callers have a
67 // PluginInstance so that's what we use here. 67 // PluginInstance so that's what we use here.
68 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVar(PluginInstance* instance, 68 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVar(PluginInstanceImpl* instance,
69 NPObject* object); 69 NPObject* object);
70 70
71 // This version creates a default v8::Context rather than using the one from 71 // 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 72 // the container of |instance|. It is only for use in unit tests, where we don't
73 // have a real container for |instance|. 73 // have a real container for |instance|.
74 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVarForTest(PluginInstance* instance, 74 WEBKIT_PLUGINS_EXPORT PP_Var NPObjectToPPVarForTest(
75 NPObject* object); 75 PluginInstanceImpl* instance,
76 NPObject* object);
76 77
77 // PPResultAndExceptionToNPResult ---------------------------------------------- 78 // PPResultAndExceptionToNPResult ----------------------------------------------
78 79
79 // Convenience object for converting a PPAPI call that can throw an exception 80 // Convenience object for converting a PPAPI call that can throw an exception
80 // and optionally return a value, back to the NPAPI layer which expects a 81 // and optionally return a value, back to the NPAPI layer which expects a
81 // NPVariant as a result. 82 // NPVariant as a result.
82 // 83 //
83 // Normal usage is that you will pass the result of exception() to the 84 // Normal usage is that you will pass the result of exception() to the
84 // PPAPI function as the exception output parameter. Then you will either 85 // PPAPI function as the exception output parameter. Then you will either
85 // call SetResult with the result of the PPAPI call, or 86 // call SetResult with the result of the PPAPI call, or
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult); 147 DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult);
147 }; 148 };
148 149
149 // PPVarArrayFromNPVariantArray ------------------------------------------------ 150 // PPVarArrayFromNPVariantArray ------------------------------------------------
150 151
151 // Converts an array of NPVariants to an array of PP_Var, and scopes the 152 // Converts an array of NPVariants to an array of PP_Var, and scopes the
152 // ownership of the PP_Var. This is used when converting argument lists from 153 // ownership of the PP_Var. This is used when converting argument lists from
153 // WebKit to the plugin. 154 // WebKit to the plugin.
154 class PPVarArrayFromNPVariantArray { 155 class PPVarArrayFromNPVariantArray {
155 public: 156 public:
156 PPVarArrayFromNPVariantArray(PluginInstance* instance, 157 PPVarArrayFromNPVariantArray(PluginInstanceImpl* instance,
157 size_t size, 158 size_t size,
158 const NPVariant* variants); 159 const NPVariant* variants);
159 ~PPVarArrayFromNPVariantArray(); 160 ~PPVarArrayFromNPVariantArray();
160 161
161 PP_Var* array() { return array_.get(); } 162 PP_Var* array() { return array_.get(); }
162 163
163 private: 164 private:
164 size_t size_; 165 size_t size_;
165 scoped_ptr<PP_Var[]> array_; 166 scoped_ptr<PP_Var[]> array_;
166 167
167 DISALLOW_COPY_AND_ASSIGN(PPVarArrayFromNPVariantArray); 168 DISALLOW_COPY_AND_ASSIGN(PPVarArrayFromNPVariantArray);
168 }; 169 };
169 170
170 // PPVarFromNPObject ----------------------------------------------------------- 171 // PPVarFromNPObject -----------------------------------------------------------
171 172
172 // Converts an NPObject tp PP_Var, and scopes the ownership of the PP_Var. This 173 // Converts an NPObject tp PP_Var, and scopes the ownership of the PP_Var. This
173 // is used when converting 'this' pointer from WebKit to the plugin. 174 // is used when converting 'this' pointer from WebKit to the plugin.
174 class PPVarFromNPObject { 175 class PPVarFromNPObject {
175 public: 176 public:
176 PPVarFromNPObject(PluginInstance* instance, NPObject* object); 177 PPVarFromNPObject(PluginInstanceImpl* instance, NPObject* object);
177 ~PPVarFromNPObject(); 178 ~PPVarFromNPObject();
178 179
179 PP_Var var() const { return var_; } 180 PP_Var var() const { return var_; }
180 181
181 private: 182 private:
182 const PP_Var var_; 183 const PP_Var var_;
183 184
184 DISALLOW_COPY_AND_ASSIGN(PPVarFromNPObject); 185 DISALLOW_COPY_AND_ASSIGN(PPVarFromNPObject);
185 }; 186 };
186 187
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 bool has_exception_; 258 bool has_exception_;
258 259
259 // May be null if the consumer isn't interesting in catching exceptions. 260 // May be null if the consumer isn't interesting in catching exceptions.
260 PP_Var* exception_; 261 PP_Var* exception_;
261 }; 262 };
262 263
263 } // namespace ppapi 264 } // namespace ppapi
264 } // namespace webkit 265 } // namespace webkit
265 266
266 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_ 267 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698