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

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

Issue 5828003: Move the Pepper implementation from webkit/glue/plugins/pepper_* to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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
« no previous file with comments | « webkit/plugins/ppapi/mock_resource.h ('k') | webkit/plugins/ppapi/npapi_glue.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_
6 #define WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_
7
8 #include "base/basictypes.h"
9 #include "base/scoped_ptr.h"
10 #include "ppapi/c/pp_var.h"
11
12 struct NPObject;
13 typedef struct _NPVariant NPVariant;
14 typedef void* NPIdentifier;
15
16 namespace webkit {
17 namespace ppapi {
18
19 class PluginModule;
20 class PluginObject;
21
22 // Utilities -------------------------------------------------------------------
23
24 // Converts the given PP_Var to an NPVariant, returning true on success.
25 // False means that the given variant is invalid. In this case, the result
26 // NPVariant will be set to a void one.
27 //
28 // The contents of the PP_Var will be copied unless the PP_Var corresponds to
29 // an object.
30 bool PPVarToNPVariant(PP_Var var, NPVariant* result);
31
32 // PPResultAndExceptionToNPResult ----------------------------------------------
33
34 // Convenience object for converting a PPAPI call that can throw an exception
35 // and optionally return a value, back to the NPAPI layer which expects a
36 // NPVariant as a result.
37 //
38 // Normal usage is that you will pass the result of exception() to the
39 // PPAPI function as the exception output parameter. Then you will either
40 // call SetResult with the result of the PPAPI call, or
41 // CheckExceptionForNoResult if the PPAPI call doesn't return a PP_Var.
42 //
43 // Both SetResult and CheckExceptionForNoResult will throw an exception to
44 // the JavaScript library if the plugin reported an exception. SetResult
45 // will additionally convert the result to an NPVariant and write it to the
46 // output parameter given in the constructor.
47 class PPResultAndExceptionToNPResult {
48 public:
49 // The object_var parameter is the object to associate any exception with.
50 // It may not be NULL.
51 //
52 // The np_result parameter is the NPAPI result output parameter. This may be
53 // NULL if there is no NPVariant result (like for HasProperty). If this is
54 // specified, you must call SetResult() to set it. If it is not, you must
55 // call CheckExceptionForNoResult to do the exception checking with no result
56 // conversion.
57 PPResultAndExceptionToNPResult(NPObject* object_var, NPVariant* np_result);
58
59 ~PPResultAndExceptionToNPResult();
60
61 // Returns true if an exception has been set.
62 bool has_exception() const { return exception_.type != PP_VARTYPE_UNDEFINED; }
63
64 // Returns a pointer to the exception. You would pass this to the PPAPI
65 // function as the exception parameter. If it is set to non-void, this object
66 // will take ownership of destroying it.
67 PP_Var* exception() { return &exception_; }
68
69 // Returns true if everything succeeded with no exception. This is valid only
70 // after calling SetResult/CheckExceptionForNoResult.
71 bool success() const {
72 return success_;
73 }
74
75 // Call this with the return value of the PPAPI function. It will convert
76 // the result to the NPVariant output parameter and pass any exception on to
77 // the JS engine. It will update the success flag and return it.
78 bool SetResult(PP_Var result);
79
80 // Call this after calling a PPAPI function that could have set the
81 // exception. It will pass the exception on to the JS engine and update
82 // the success flag.
83 //
84 // The success flag will be returned.
85 bool CheckExceptionForNoResult();
86
87 // Call this to ignore any exception. This prevents the DCHECK from failing
88 // in the destructor.
89 void IgnoreException();
90
91 private:
92 // Throws the current exception to JS. The exception must be set.
93 void ThrowException();
94
95 NPObject* object_var_; // Non-owning ref (see constructor).
96 NPVariant* np_result_; // Output value, possibly NULL (see constructor).
97 PP_Var exception_; // Exception set by the PPAPI call. We own a ref to it.
98 bool success_; // See the success() function above.
99 bool checked_exception_; // SetResult/CheckExceptionForNoResult was called.
100
101 DISALLOW_COPY_AND_ASSIGN(PPResultAndExceptionToNPResult);
102 };
103
104 // PPVarArrayFromNPVariantArray ------------------------------------------------
105
106 // Converts an array of NPVariants to an array of PP_Var, and scopes the
107 // ownership of the PP_Var. This is used when converting argument lists from
108 // WebKit to the plugin.
109 class PPVarArrayFromNPVariantArray {
110 public:
111 PPVarArrayFromNPVariantArray(PluginModule* module,
112 size_t size,
113 const NPVariant* variants);
114 ~PPVarArrayFromNPVariantArray();
115
116 PP_Var* array() { return array_.get(); }
117
118 private:
119 size_t size_;
120 scoped_array<PP_Var> array_;
121
122 DISALLOW_COPY_AND_ASSIGN(PPVarArrayFromNPVariantArray);
123 };
124
125 // PPVarFromNPObject -----------------------------------------------------------
126
127 // Converts an NPObject tp PP_Var, and scopes the ownership of the PP_Var. This
128 // is used when converting 'this' pointer from WebKit to the plugin.
129 class PPVarFromNPObject {
130 public:
131 PPVarFromNPObject(PluginModule* module, NPObject* object);
132 ~PPVarFromNPObject();
133
134 PP_Var var() const { return var_; }
135
136 private:
137 const PP_Var var_;
138
139 DISALLOW_COPY_AND_ASSIGN(PPVarFromNPObject);
140 };
141
142 // NPObjectAccessorWithIdentifier ----------------------------------------------
143
144 // Helper class for our NPObject wrapper. This converts a call from WebKit
145 // where it gives us an NPObject and an NPIdentifier to an easily-accessible
146 // ObjectVar (corresponding to the NPObject) and PP_Var (corresponding to the
147 // NPIdentifier).
148 //
149 // If the NPObject or identifier is invalid, we'll set is_valid() to false.
150 // The caller should check is_valid() before doing anything with the class.
151 //
152 // JS can't have integer functions, so when dealing with these, we don't want
153 // to allow integer identifiers. The calling code can decode if it wants to
154 // allow integer identifiers (like for property access) or prohibit them
155 // (like for method calling) by setting |allow_integer_identifier|. If this
156 // is false and the identifier is an integer, we'll set is_valid() to false.
157 //
158 // Getting an integer identifier in this case should be impossible. V8
159 // shouldn't be allowing this, and the Pepper Var calls from the plugin are
160 // supposed to error out before calling into V8 (which will then call us back).
161 // Aside from an egregious error, the only time this could happen is an NPAPI
162 // plugin calling us.
163 class NPObjectAccessorWithIdentifier {
164 public:
165 NPObjectAccessorWithIdentifier(NPObject* object,
166 NPIdentifier identifier,
167 bool allow_integer_identifier);
168 ~NPObjectAccessorWithIdentifier();
169
170 // Returns true if both the object and identifier are valid.
171 bool is_valid() const {
172 return object_ && identifier_.type != PP_VARTYPE_UNDEFINED;
173 }
174
175 PluginObject* object() { return object_; }
176 PP_Var identifier() const { return identifier_; }
177
178 private:
179 PluginObject* object_;
180 PP_Var identifier_;
181
182 DISALLOW_COPY_AND_ASSIGN(NPObjectAccessorWithIdentifier);
183 };
184
185 } // namespace ppapi
186 } // namespace webkit
187
188 #endif // WEBKIT_PLUGINS_PPAPI_NPAPI_GLUE_H_
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/mock_resource.h ('k') | webkit/plugins/ppapi/npapi_glue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698