| 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/cpp/var.h" | 5 #include "ppapi/cpp/var.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "ppapi/c/pp_var.h" | 12 #include "ppapi/c/pp_var.h" |
| 13 #include "ppapi/c/ppb_var.h" | 13 #include "ppapi/c/ppb_var.h" |
| 14 #include "ppapi/cpp/instance.h" | 14 #include "ppapi/cpp/instance.h" |
| 15 #include "ppapi/cpp/logging.h" | 15 #include "ppapi/cpp/logging.h" |
| 16 #include "ppapi/cpp/module.h" | 16 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/module_impl.h" | 17 #include "ppapi/cpp/module_impl.h" |
| 18 | 18 |
| 19 // Define equivalent to snprintf on Windows. | 19 // Define equivalent to snprintf on Windows. |
| 20 #if defined(_MSC_VER) | 20 #if defined(_MSC_VER) |
| 21 # define snprintf sprintf_s | 21 # define snprintf sprintf_s |
| 22 #endif | 22 #endif |
| 23 | 23 |
| 24 namespace pp { | 24 namespace pp { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 template <> const char* interface_name<PPB_Var>() { | 28 template <> const char* interface_name<PPB_Var_1_1>() { |
| 29 return PPB_VAR_INTERFACE; | 29 return PPB_VAR_INTERFACE_1_1; |
| 30 } | 30 } |
| 31 template <> const char* interface_name<PPB_Var_1_0>() { | 31 template <> const char* interface_name<PPB_Var_1_0>() { |
| 32 return PPB_VAR_INTERFACE_1_0; | 32 return PPB_VAR_INTERFACE_1_0; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Technically you can call AddRef and Release on any Var, but it may involve | 35 // Technically you can call AddRef and Release on any Var, but it may involve |
| 36 // cross-process calls depending on the plugin. This is an optimization so we | 36 // cross-process calls depending on the plugin. This is an optimization so we |
| 37 // only do refcounting on the necessary objects. | 37 // only do refcounting on the necessary objects. |
| 38 inline bool NeedsRefcounting(const PP_Var& var) { | 38 inline bool NeedsRefcounting(const PP_Var& var) { |
| 39 return var.type > PP_VARTYPE_DOUBLE; | 39 return var.type > PP_VARTYPE_DOUBLE; |
| 40 } | 40 } |
| 41 | 41 |
| 42 // This helper function detects whether PPB_Var version 1.1 is available. If so, | 42 // This helper function detects whether PPB_Var version 1.1 is available. If so, |
| 43 // it uses it to create a PP_Var for the given string. Otherwise it falls back | 43 // it uses it to create a PP_Var for the given string. Otherwise it falls back |
| 44 // to PPB_Var version 1.0. | 44 // to PPB_Var version 1.0. |
| 45 PP_Var VarFromUtf8Helper(const char* utf8_str, uint32_t len) { | 45 PP_Var VarFromUtf8Helper(const char* utf8_str, uint32_t len) { |
| 46 if (has_interface<PPB_Var>()) { | 46 if (has_interface<PPB_Var_1_1>()) { |
| 47 return get_interface<PPB_Var>()->VarFromUtf8(utf8_str, len); | 47 return get_interface<PPB_Var_1_1>()->VarFromUtf8(utf8_str, len); |
| 48 } else if (has_interface<PPB_Var_1_0>()) { | 48 } else if (has_interface<PPB_Var_1_0>()) { |
| 49 return get_interface<PPB_Var_1_0>()->VarFromUtf8(Module::Get()->pp_module(), | 49 return get_interface<PPB_Var_1_0>()->VarFromUtf8(Module::Get()->pp_module(), |
| 50 utf8_str, | 50 utf8_str, |
| 51 len); | 51 len); |
| 52 } else { | 52 } else { |
| 53 return PP_MakeNull(); | 53 return PP_MakeNull(); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // TODO(dmichael): We could make this dump hex. Maybe DebugString should be | 239 // TODO(dmichael): We could make this dump hex. Maybe DebugString should be |
| 240 // virtual? | 240 // virtual? |
| 241 snprintf(buf, sizeof(buf), "Var(ARRAY_BUFFER)"); | 241 snprintf(buf, sizeof(buf), "Var(ARRAY_BUFFER)"); |
| 242 } else if (is_object()) { | 242 } else if (is_object()) { |
| 243 snprintf(buf, sizeof(buf), "Var(OBJECT)"); | 243 snprintf(buf, sizeof(buf), "Var(OBJECT)"); |
| 244 } | 244 } |
| 245 return buf; | 245 return buf; |
| 246 } | 246 } |
| 247 | 247 |
| 248 } // namespace pp | 248 } // namespace pp |
| OLD | NEW |