| 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_PLUGINS_PPAPI_VAR_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_VAR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "webkit/glue/plugins/pepper_resource.h" | 10 #include "webkit/plugins/ppapi/resource.h" |
| 11 | 11 |
| 12 struct PP_Var; | 12 struct PP_Var; |
| 13 struct PPB_Var; | 13 struct PPB_Var; |
| 14 struct PPB_Var_Deprecated; | 14 struct PPB_Var_Deprecated; |
| 15 typedef struct NPObject NPObject; | 15 typedef struct NPObject NPObject; |
| 16 typedef struct _NPVariant NPVariant; | 16 typedef struct _NPVariant NPVariant; |
| 17 typedef void* NPIdentifier; | 17 typedef void* NPIdentifier; |
| 18 | 18 |
| 19 namespace pepper { | 19 namespace webkit { |
| 20 namespace plugins { |
| 21 namespace ppapi { |
| 20 | 22 |
| 21 // Var ------------------------------------------------------------------------- | 23 // Var ------------------------------------------------------------------------- |
| 22 | 24 |
| 23 // Represents a non-POD var. This is derived from a resource even though it | 25 // Represents a non-POD var. This is derived from a resource even though it |
| 24 // isn't a resource from the plugin's perspective. This allows us to re-use | 26 // isn't a resource from the plugin's perspective. This allows us to re-use |
| 25 // the refcounting and the association with the module from the resource code. | 27 // the refcounting and the association with the module from the resource code. |
| 26 class Var : public Resource { | 28 class Var : public Resource { |
| 27 public: | 29 public: |
| 28 virtual ~Var(); | 30 virtual ~Var(); |
| 29 | 31 |
| 30 // Resource overrides. | 32 // Resource overrides. |
| 31 virtual Var* AsVar() { return this; } | 33 virtual Var* AsVar(); |
| 32 | 34 |
| 33 // Returns a PP_Var that corresponds to the given NPVariant. The contents of | 35 // 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 | 36 // the NPVariant will be copied unless the NPVariant corresponds to an |
| 35 // object. This will handle all Variant types including POD, strings, and | 37 // object. This will handle all Variant types including POD, strings, and |
| 36 // objects. | 38 // objects. |
| 37 // | 39 // |
| 38 // The returned PP_Var will have a refcount of 1, this passing ownership of | 40 // 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. | 41 // the reference to the caller. This is suitable for returning to a plugin. |
| 40 static PP_Var NPVariantToPPVar(PluginModule* module, | 42 static PP_Var NPVariantToPPVar(PluginModule* module, |
| 41 const NPVariant* variant); | 43 const NPVariant* variant); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // return false; // Not a string or an invalid var. | 109 // return false; // Not a string or an invalid var. |
| 108 // DoSomethingWithTheString(string->value()); | 110 // DoSomethingWithTheString(string->value()); |
| 109 class StringVar : public Var { | 111 class StringVar : public Var { |
| 110 public: | 112 public: |
| 111 StringVar(PluginModule* module, const char* str, uint32 len); | 113 StringVar(PluginModule* module, const char* str, uint32 len); |
| 112 virtual ~StringVar(); | 114 virtual ~StringVar(); |
| 113 | 115 |
| 114 const std::string& value() const { return value_; } | 116 const std::string& value() const { return value_; } |
| 115 | 117 |
| 116 // Resource overrides. | 118 // Resource overrides. |
| 117 virtual StringVar* AsStringVar() { return this; } | 119 virtual StringVar* AsStringVar(); |
| 118 | 120 |
| 119 // Helper function to create a PP_Var of type string that contains a copy of | 121 // Helper function to create a PP_Var of type string that contains a copy of |
| 120 // the given string. The input data must be valid UTF-8 encoded text, if it | 122 // the given string. The input data must be valid UTF-8 encoded text, if it |
| 121 // is not valid UTF-8, a NULL var will be returned. | 123 // is not valid UTF-8, a NULL var will be returned. |
| 122 // | 124 // |
| 123 // The return value will have a reference count of 1. Internally, this will | 125 // The return value will have a reference count of 1. Internally, this will |
| 124 // create a StringVar, associate it with a module, and return the reference | 126 // create a StringVar, associate it with a module, and return the reference |
| 125 // to it in the var. | 127 // to it in the var. |
| 126 static PP_Var StringToPPVar(PluginModule* module, const std::string& str); | 128 static PP_Var StringToPPVar(PluginModule* module, const std::string& str); |
| 127 static PP_Var StringToPPVar(PluginModule* module, | 129 static PP_Var StringToPPVar(PluginModule* module, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 147 // given module and free them when the plugin exits independently of other | 149 // given module and free them when the plugin exits independently of other |
| 148 // plugins that may be running at the same time. | 150 // plugins that may be running at the same time. |
| 149 // | 151 // |
| 150 // See StringVar for examples, except obviously using NPObjects instead of | 152 // See StringVar for examples, except obviously using NPObjects instead of |
| 151 // strings. | 153 // strings. |
| 152 class ObjectVar : public Var { | 154 class ObjectVar : public Var { |
| 153 public: | 155 public: |
| 154 virtual ~ObjectVar(); | 156 virtual ~ObjectVar(); |
| 155 | 157 |
| 156 // Resource overrides. | 158 // Resource overrides. |
| 157 virtual ObjectVar* AsObjectVar() { return this; } | 159 virtual ObjectVar* AsObjectVar(); |
| 158 | 160 |
| 159 // Returns the underlying NPObject corresponding to this ObjectVar. | 161 // Returns the underlying NPObject corresponding to this ObjectVar. |
| 160 // Guaranteed non-NULL. | 162 // Guaranteed non-NULL. |
| 161 NPObject* np_object() const { return np_object_; } | 163 NPObject* np_object() const { return np_object_; } |
| 162 | 164 |
| 163 // Helper function to create a PP_Var of type object that contains the given | 165 // Helper function to create a PP_Var of type object that contains the given |
| 164 // NPObject for use byt he given module. Calling this function multiple times | 166 // NPObject for use byt he given module. Calling this function multiple times |
| 165 // given the same module + NPObject results in the same PP_Var, assuming that | 167 // given the same module + NPObject results in the same PP_Var, assuming that |
| 166 // there is still a PP_Var with a reference open to it from the previous | 168 // there is still a PP_Var with a reference open to it from the previous |
| 167 // call. | 169 // call. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // True if an exception has been thrown. Since the exception itself may be | 241 // True if an exception has been thrown. Since the exception itself may be |
| 240 // NULL if the plugin isn't interested in getting the exception, this will | 242 // NULL if the plugin isn't interested in getting the exception, this will |
| 241 // always indicate if SetException has been called, regardless of whether | 243 // always indicate if SetException has been called, regardless of whether |
| 242 // the exception itself has been stored. | 244 // the exception itself has been stored. |
| 243 bool has_exception_; | 245 bool has_exception_; |
| 244 | 246 |
| 245 // May be null if the consumer isn't interesting in catching exceptions. | 247 // May be null if the consumer isn't interesting in catching exceptions. |
| 246 PP_Var* exception_; | 248 PP_Var* exception_; |
| 247 }; | 249 }; |
| 248 | 250 |
| 249 } // namespace pepper | 251 } // namespace ppapi |
| 252 } // namespace plugins |
| 253 } // namespace webkit |
| 250 | 254 |
| 251 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_VAR_H_ | 255 #endif // WEBKIT_PLUGINS_PPAPI_VAR_H_ |
| OLD | NEW |