| 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 PPAPI_SHARED_IMPL_VAR_H_ | 5 #ifndef PPAPI_SHARED_IMPL_VAR_H_ |
| 6 #define PPAPI_SHARED_IMPL_VAR_H_ | 6 #define PPAPI_SHARED_IMPL_VAR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
| 13 #include "ppapi/shared_impl/ppapi_shared_export.h" | 13 #include "ppapi/shared_impl/ppapi_shared_export.h" |
| 14 | 14 |
| 15 namespace ppapi { | 15 namespace ppapi { |
| 16 | 16 |
| 17 class ArrayBufferVar; |
| 17 class NPObjectVar; | 18 class NPObjectVar; |
| 18 class ProxyObjectVar; | 19 class ProxyObjectVar; |
| 19 class StringVar; | 20 class StringVar; |
| 20 class VarTracker; | 21 class VarTracker; |
| 21 | 22 |
| 22 // Var ------------------------------------------------------------------------- | 23 // Var ------------------------------------------------------------------------- |
| 23 | 24 |
| 24 // Represents a non-POD var. | 25 // Represents a non-POD var. |
| 25 class PPAPI_SHARED_EXPORT Var : public base::RefCounted<Var> { | 26 class PPAPI_SHARED_EXPORT Var : public base::RefCounted<Var> { |
| 26 public: | 27 public: |
| 27 virtual ~Var(); | 28 virtual ~Var(); |
| 28 | 29 |
| 29 // Returns a string representing the given var for logging purposes. | 30 // Returns a string representing the given var for logging purposes. |
| 30 static std::string PPVarToLogString(PP_Var var); | 31 static std::string PPVarToLogString(PP_Var var); |
| 31 | 32 |
| 32 virtual StringVar* AsStringVar(); | 33 virtual StringVar* AsStringVar(); |
| 34 virtual ArrayBufferVar* AsArrayBufferVar(); |
| 33 virtual NPObjectVar* AsNPObjectVar(); | 35 virtual NPObjectVar* AsNPObjectVar(); |
| 34 virtual ProxyObjectVar* AsProxyObjectVar(); | 36 virtual ProxyObjectVar* AsProxyObjectVar(); |
| 35 | 37 |
| 36 // Creates a PP_Var corresponding to this object. The return value will have | 38 // Creates a PP_Var corresponding to this object. The return value will have |
| 37 // one reference addrefed on behalf of the caller. | 39 // one reference addrefed on behalf of the caller. |
| 38 virtual PP_Var GetPPVar() = 0; | 40 PP_Var GetPPVar(); |
| 39 | 41 |
| 40 // Returns the type of this var. | 42 // Returns the type of this var. |
| 41 virtual PP_VarType GetType() const = 0; | 43 virtual PP_VarType GetType() const = 0; |
| 42 | 44 |
| 43 // Returns the ID corresponing to the string or object if it exists already, | 45 // Returns the ID corresponing to the string or object if it exists already, |
| 44 // or 0 if an ID hasn't been generated for this object (the plugin is holding | 46 // or 0 if an ID hasn't been generated for this object (the plugin is holding |
| 45 // no refs). | 47 // no refs). |
| 46 // | 48 // |
| 47 // Contrast to GetOrCreateVarID which creates the ID and a ref on behalf of | 49 // Contrast to GetOrCreateVarID which creates the ID and a ref on behalf of |
| 48 // the plugin. | 50 // the plugin. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 class PPAPI_SHARED_EXPORT StringVar : public Var { | 92 class PPAPI_SHARED_EXPORT StringVar : public Var { |
| 91 public: | 93 public: |
| 92 StringVar(const std::string& str); | 94 StringVar(const std::string& str); |
| 93 StringVar(const char* str, uint32 len); | 95 StringVar(const char* str, uint32 len); |
| 94 virtual ~StringVar(); | 96 virtual ~StringVar(); |
| 95 | 97 |
| 96 const std::string& value() const { return value_; } | 98 const std::string& value() const { return value_; } |
| 97 | 99 |
| 98 // Var override. | 100 // Var override. |
| 99 virtual StringVar* AsStringVar() OVERRIDE; | 101 virtual StringVar* AsStringVar() OVERRIDE; |
| 100 virtual PP_Var GetPPVar() OVERRIDE; | |
| 101 virtual PP_VarType GetType() const OVERRIDE; | 102 virtual PP_VarType GetType() const OVERRIDE; |
| 102 | 103 |
| 103 // Helper function to create a PP_Var of type string that contains a copy of | 104 // Helper function to create a PP_Var of type string that contains a copy of |
| 104 // the given string. The input data must be valid UTF-8 encoded text, if it | 105 // the given string. The input data must be valid UTF-8 encoded text, if it |
| 105 // is not valid UTF-8, a NULL var will be returned. | 106 // is not valid UTF-8, a NULL var will be returned. |
| 106 // | 107 // |
| 107 // The return value will have a reference count of 1. Internally, this will | 108 // The return value will have a reference count of 1. Internally, this will |
| 108 // create a StringVar and return the reference to it in the var. | 109 // create a StringVar and return the reference to it in the var. |
| 109 static PP_Var StringToPPVar(const std::string& str); | 110 static PP_Var StringToPPVar(const std::string& str); |
| 110 static PP_Var StringToPPVar(const char* str, uint32 len); | 111 static PP_Var StringToPPVar(const char* str, uint32 len); |
| 111 | 112 |
| 112 // Helper function that converts a PP_Var to a string. This will return NULL | 113 // Helper function that converts a PP_Var to a string. This will return NULL |
| 113 // if the PP_Var is not of string type or the string is invalid. | 114 // if the PP_Var is not of string type or the string is invalid. |
| 114 static StringVar* FromPPVar(PP_Var var); | 115 static StringVar* FromPPVar(PP_Var var); |
| 115 | 116 |
| 116 private: | 117 private: |
| 117 std::string value_; | 118 std::string value_; |
| 118 | 119 |
| 119 DISALLOW_COPY_AND_ASSIGN(StringVar); | 120 DISALLOW_COPY_AND_ASSIGN(StringVar); |
| 120 }; | 121 }; |
| 121 | 122 |
| 123 // ArrayBufferVar -------------------------------------------------------------- |
| 124 |
| 125 // Represents an array buffer Var. |
| 126 // |
| 127 // Note this is an abstract class. To create an appropriate concrete one, you |
| 128 // need to use the VarTracker: |
| 129 // VarArrayBuffer* buf = |
| 130 // PpapiGlobals::Get()->GetVarTracker()->CreateArrayBuffer(size); |
| 131 // |
| 132 // Converting a PP_Var to an ArrayBufferVar: |
| 133 // ArrayBufferVar* array = ArrayBufferVar::FromPPVar(var); |
| 134 // if (!array) |
| 135 // return false; // Not an ArrayBuffer or an invalid var. |
| 136 // DoSomethingWithTheBuffer(array); |
| 137 class PPAPI_SHARED_EXPORT ArrayBufferVar : public Var { |
| 138 public: |
| 139 ArrayBufferVar(); |
| 140 virtual ~ArrayBufferVar(); |
| 141 |
| 142 virtual void* Map() = 0; |
| 143 virtual uint32 ByteLength() = 0; |
| 144 |
| 145 // Var override. |
| 146 virtual ArrayBufferVar* AsArrayBufferVar() OVERRIDE; |
| 147 virtual PP_VarType GetType() const OVERRIDE; |
| 148 |
| 149 // Helper function that converts a PP_Var to an ArrayBufferVar. This will |
| 150 // return NULL if the PP_Var is not of ArrayBuffer type. |
| 151 static ArrayBufferVar* FromPPVar(PP_Var var); |
| 152 |
| 153 private: |
| 154 DISALLOW_COPY_AND_ASSIGN(ArrayBufferVar); |
| 155 }; |
| 156 |
| 122 } // namespace ppapi | 157 } // namespace ppapi |
| 123 | 158 |
| 124 #endif // PPAPI_SHARED_IMPL_VAR_H_ | 159 #endif // PPAPI_SHARED_IMPL_VAR_H_ |
| OLD | NEW |