OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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_GLUE_PLUGINS_PEPPER_VAR_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ |
6 #define WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 struct PP_Var; | 10 struct PP_Var; |
11 struct PPB_Var; | 11 struct PPB_Var; |
12 typedef struct NPObject NPObject; | 12 typedef struct NPObject NPObject; |
13 typedef struct _NPVariant NPVariant; | 13 typedef struct _NPVariant NPVariant; |
14 typedef void* NPIdentifier; | 14 typedef void* NPIdentifier; |
15 | 15 |
16 namespace pepper { | 16 namespace pepper { |
17 | 17 |
18 class String; | 18 class String; |
19 | 19 |
20 // There's no class implementing Var since it could represent a number of | 20 // There's no class implementing Var since it could represent a number of |
21 // objects. Instead, we just expose a getter for the interface implemented in | 21 // objects. Instead, we just expose a getter for the interface implemented in |
22 // the .cc file here. | 22 // the .cc file here. |
23 const PPB_Var* GetVarInterface(); | 23 const PPB_Var* GetVarInterface(); |
24 | 24 |
25 // Returns a PP_Var of type object that wraps the given NPObject. Calling this | 25 // Returns a PP_Var of type object that wraps the given NPObject. Calling this |
26 // function multiple times given the same NPObject results in the same PP_Var. | 26 // function multiple times given the same NPObject results in the same PP_Var. |
27 PP_Var NPObjectToPPVar(NPObject* object); | 27 PP_Var NPObjectToPPVar(NPObject* object); |
28 | 28 |
29 // Returns a PP_Var that corresponds to the given NPVariant. The contents of | |
30 // the NPVariant will be copied unless the NPVariant corresponds to an object. | |
31 PP_Var NPVariantToPPVar(const NPVariant* variant); | |
32 | |
33 // Returns the NPObject corresponding to the PP_Var. This pointer has not been | 29 // Returns the NPObject corresponding to the PP_Var. This pointer has not been |
34 // retained, so you should not call WebBindings::releaseObject unless you first | 30 // retained, so you should not call WebBindings::releaseObject unless you first |
35 // call WebBindings::retainObject. Returns NULL if the PP_Var is not an object | 31 // call WebBindings::retainObject. Returns NULL if the PP_Var is not an object |
36 // type. | 32 // type. |
37 NPObject* GetNPObject(PP_Var var); | 33 NPObject* GetNPObject(PP_Var var); |
38 | 34 |
39 // Returns a PP_Var of type string that contains a copy of the given string. | 35 // Returns a PP_Var of type string that contains a copy of the given string. |
40 // The input data must be valid UTF-8 encoded text. The return value will | 36 // The input data must be valid UTF-8 encoded text. The return value will |
41 // have a reference count of 1. | 37 // have a reference count of 1. |
42 PP_Var StringToPPVar(const std::string& str); | 38 PP_Var StringToPPVar(const std::string& str); |
43 | 39 |
44 // Returns the String corresponding to the PP_Var. This pointer has not been | 40 // Returns the String corresponding to the PP_Var. This pointer has not been |
45 // AddRef'd, so you should not call Release! Returns NULL if the PP_Var is not | 41 // AddRef'd, so you should not call Release! Returns NULL if the PP_Var is not |
46 // a string type. | 42 // a string type. |
47 String* GetString(PP_Var var); | 43 String* GetString(PP_Var var); |
48 | 44 |
49 // Instantiate this object on the stack to catch V8 exceptions and pass them | |
50 // to an optional out parameter supplied by the plugin. | |
51 class TryCatch { | |
52 public: | |
53 // The given exception may be NULL if the consumer isn't interested in | |
54 // catching exceptions. If non-NULL, the given var will be updated if any | |
55 // exception is thrown (so it must outlive the TryCatch object). | |
56 TryCatch(PP_Var* exception); | |
57 ~TryCatch(); | |
58 | |
59 // Returns true is an exception has been thrown. This can be true immediately | |
60 // after construction if the var passed to the constructor is non-void. | |
61 bool HasException() const; | |
62 | |
63 // Sets the given exception. | |
64 void SetException(const char* message); | |
65 | |
66 private: | |
67 static void Catch(void* self, const char* message); | |
68 | |
69 // May be null if the consumer isn't interesting in catching exceptions. | |
70 PP_Var* exception_; | |
71 }; | |
72 | |
73 } // namespace pepper | 45 } // namespace pepper |
74 | 46 |
75 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ | 47 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ |
OLD | NEW |