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 #include "ppapi/shared_impl/var.h" | 5 #include "ppapi/shared_impl/var.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 return "[Undefined]"; | 30 return "[Undefined]"; |
31 case PP_VARTYPE_NULL: | 31 case PP_VARTYPE_NULL: |
32 return "[Null]"; | 32 return "[Null]"; |
33 case PP_VARTYPE_BOOL: | 33 case PP_VARTYPE_BOOL: |
34 return var.value.as_bool ? "[True]" : "[False]"; | 34 return var.value.as_bool ? "[True]" : "[False]"; |
35 case PP_VARTYPE_INT32: | 35 case PP_VARTYPE_INT32: |
36 return base::IntToString(var.value.as_int); | 36 return base::IntToString(var.value.as_int); |
37 case PP_VARTYPE_DOUBLE: | 37 case PP_VARTYPE_DOUBLE: |
38 return base::DoubleToString(var.value.as_double); | 38 return base::DoubleToString(var.value.as_double); |
39 case PP_VARTYPE_STRING: { | 39 case PP_VARTYPE_STRING: { |
40 scoped_refptr<StringVar> string(StringVar::FromPPVar(var)); | 40 StringVar* string(StringVar::FromPPVar(var)); |
41 if (!string) | 41 if (!string) |
42 return "[Invalid string]"; | 42 return "[Invalid string]"; |
43 | 43 |
44 // Since this is for logging, escape NULLs, truncate length. | 44 // Since this is for logging, escape NULLs, truncate length. |
45 std::string result; | 45 std::string result; |
46 const size_t kTruncateAboveLength = 128; | 46 const size_t kTruncateAboveLength = 128; |
47 if (string->value().size() > kTruncateAboveLength) | 47 if (string->value().size() > kTruncateAboveLength) |
48 result = string->value().substr(0, kTruncateAboveLength) + "..."; | 48 result = string->value().substr(0, kTruncateAboveLength) + "..."; |
49 else | 49 else |
50 result = string->value(); | 50 result = string->value(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 // static | 132 // static |
133 PP_Var StringVar::StringToPPVar(PP_Module module, | 133 PP_Var StringVar::StringToPPVar(PP_Module module, |
134 const char* data, uint32 len) { | 134 const char* data, uint32 len) { |
135 scoped_refptr<StringVar> str(new StringVar(module, data, len)); | 135 scoped_refptr<StringVar> str(new StringVar(module, data, len)); |
136 if (!str || !IsStringUTF8(str->value())) | 136 if (!str || !IsStringUTF8(str->value())) |
137 return PP_MakeNull(); | 137 return PP_MakeNull(); |
138 return str->GetPPVar(); | 138 return str->GetPPVar(); |
139 } | 139 } |
140 | 140 |
141 // static | 141 // static |
142 scoped_refptr<StringVar> StringVar::FromPPVar(PP_Var var) { | 142 StringVar* StringVar::FromPPVar(PP_Var var) { |
143 if (var.type != PP_VARTYPE_STRING) | 143 if (var.type != PP_VARTYPE_STRING) |
144 return scoped_refptr<StringVar>(); | 144 return NULL; |
145 scoped_refptr<Var> var_object( | 145 scoped_refptr<Var> var_object( |
146 TrackerBase::Get()->GetVarTracker()->GetVar(var)); | 146 TrackerBase::Get()->GetVarTracker()->GetVar(var)); |
147 if (!var_object) | 147 if (!var_object) |
148 return scoped_refptr<StringVar>(); | 148 return NULL; |
149 return scoped_refptr<StringVar>(var_object->AsStringVar()); | 149 return var_object->AsStringVar(); |
150 } | 150 } |
151 | 151 |
152 } // namespace ppapi | 152 } // namespace ppapi |
153 | 153 |
OLD | NEW |