| 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 "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" |    5 #include "native_client/src/shared/ppapi_proxy/plugin_ppb_var.h" | 
|    6  |    6  | 
|    7 #include <stdio.h> |    7 #include <stdio.h> | 
|    8  |    8  | 
|    9 #include <string> |    9 #include <string> | 
|   10 #include <utility> |   10 #include <utility> | 
|   11  |   11  | 
|   12 #include "native_client/src/include/checked_cast.h" |   12 #include "native_client/src/include/checked_cast.h" | 
|   13 #include "native_client/src/include/nacl_macros.h" |   13 #include "native_client/src/include/nacl_macros.h" | 
|   14 #include "native_client/src/include/portability.h" |   14 #include "native_client/src/include/portability.h" | 
|   15 #include "native_client/src/include/portability_io.h" |   15 #include "native_client/src/include/portability_io.h" | 
 |   16 #include "native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h" | 
|   16 #include "native_client/src/shared/ppapi_proxy/proxy_var_cache.h" |   17 #include "native_client/src/shared/ppapi_proxy/proxy_var_cache.h" | 
|   17 #include "native_client/src/shared/ppapi_proxy/string_proxy_var.h" |   18 #include "native_client/src/shared/ppapi_proxy/string_proxy_var.h" | 
|   18 #include "native_client/src/shared/ppapi_proxy/utility.h" |   19 #include "native_client/src/shared/ppapi_proxy/utility.h" | 
|   19 #include "ppapi/c/pp_var.h" |   20 #include "ppapi/c/pp_var.h" | 
|   20 #include "ppapi/c/ppb_var.h" |   21 #include "ppapi/c/ppb_var.h" | 
|   21  |   22  | 
|   22 namespace ppapi_proxy { |   23 namespace ppapi_proxy { | 
|   23  |   24  | 
|   24 namespace { |   25 namespace { | 
|   25  |   26  | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   76 int64_t GetVarId(PP_Var var) { |   77 int64_t GetVarId(PP_Var var) { | 
|   77   SharedProxyVar proxy_var = |   78   SharedProxyVar proxy_var = | 
|   78       ProxyVarCache::GetInstance().SharedProxyVarForVar(var); |   79       ProxyVarCache::GetInstance().SharedProxyVarForVar(var); | 
|   79   if (proxy_var == NULL) { |   80   if (proxy_var == NULL) { | 
|   80     return -1; |   81     return -1; | 
|   81   } else { |   82   } else { | 
|   82     return proxy_var->id(); |   83     return proxy_var->id(); | 
|   83   } |   84   } | 
|   84 } |   85 } | 
|   85  |   86  | 
 |   87 PP_Var CreateArrayBuffer(uint32_t size_in_bytes) { | 
 |   88   DebugPrintf("PPB_VarArrayBuffer::Create: size_in_bytes=%"NACL_PRIu32"\n", | 
 |   89               size_in_bytes); | 
 |   90   SharedProxyVar proxy_var(new ArrayBufferProxyVar(size_in_bytes)); | 
 |   91   ProxyVarCache::GetInstance().RetainSharedProxyVar(proxy_var); | 
 |   92   PP_Var var; | 
 |   93   var.type = PP_VARTYPE_ARRAY_BUFFER; | 
 |   94   var.value.as_id = proxy_var->id(); | 
 |   95   // Increment the reference count for the return to the caller. | 
 |   96   AddRef(var); | 
 |   97   DebugPrintf("PPB_VarArrayBuffer::Create: as_id=%"NACL_PRId64"\n", | 
 |   98               var.value.as_id); | 
 |   99   return var; | 
 |  100 } | 
 |  101  | 
 |  102 uint32_t ByteLength(PP_Var var) { | 
 |  103   DebugPrintf("PPB_VarArrayBuffer::ByteLength: var=PPB_Var(%s)\n", | 
 |  104               PluginVar::DebugString(var).c_str()); | 
 |  105   SharedArrayBufferProxyVar buffer_var = ArrayBufferProxyVar::CastFromProxyVar( | 
 |  106       ProxyVarCache::GetInstance().SharedProxyVarForVar(var)); | 
 |  107   uint32_t len = buffer_var->buffer_length(); | 
 |  108   DebugPrintf("PPB_VarArrayBuffer::ByteLength: length=%"NACL_PRIu32"\n", len); | 
 |  109   return len; | 
 |  110 } | 
 |  111  | 
 |  112 void* Map(PP_Var var) { | 
 |  113   DebugPrintf("PPB_VarArrayBuffer::Map: var=PPB_Var(%s)\n", | 
 |  114               PluginVar::DebugString(var).c_str()); | 
 |  115   SharedArrayBufferProxyVar buffer_var = ArrayBufferProxyVar::CastFromProxyVar( | 
 |  116       ProxyVarCache::GetInstance().SharedProxyVarForVar(var)); | 
 |  117   void* data = buffer_var->buffer(); | 
 |  118   DebugPrintf("PPB_VarArrayBuffer::Map: buffer=%p\n", data); | 
 |  119   return data; | 
 |  120 } | 
 |  121  | 
|   86 }  // namespace |  122 }  // namespace | 
|   87  |  123  | 
|   88 const PPB_Var* PluginVar::GetInterface() { |  124 const PPB_Var* PluginVar::GetInterface() { | 
|   89   static const PPB_Var var_interface = { |  125   static const PPB_Var var_interface = { | 
|   90     AddRef, |  126     AddRef, | 
|   91     Release, |  127     Release, | 
|   92     VarFromUtf8, |  128     VarFromUtf8, | 
|   93     VarToUtf8 |  129     VarToUtf8 | 
|   94   }; |  130   }; | 
|   95   return &var_interface; |  131   return &var_interface; | 
|   96 } |  132 } | 
|   97  |  133  | 
|   98 const PPB_Var_1_0* PluginVar::GetInterface1_0() { |  134 const PPB_Var_1_0* PluginVar::GetInterface1_0() { | 
|   99   static const PPB_Var_1_0 var_interface = { |  135   static const PPB_Var_1_0 var_interface = { | 
|  100     AddRef, |  136     AddRef, | 
|  101     Release, |  137     Release, | 
|  102     VarFromUtf8_1_0, |  138     VarFromUtf8_1_0, | 
|  103     VarToUtf8 |  139     VarToUtf8 | 
|  104   }; |  140   }; | 
|  105   return &var_interface; |  141   return &var_interface; | 
|  106 } |  142 } | 
|  107  |  143  | 
 |  144 const PPB_VarArrayBuffer_Dev* PluginVar::GetArrayBufferInterface() { | 
 |  145   static const PPB_VarArrayBuffer_Dev interface = { | 
 |  146     CreateArrayBuffer, | 
 |  147     ByteLength, | 
 |  148     Map | 
 |  149   }; | 
 |  150   return &interface; | 
 |  151 } | 
 |  152  | 
|  108 std::string PluginVar::DebugString(const PP_Var& var) { |  153 std::string PluginVar::DebugString(const PP_Var& var) { | 
|  109   switch (var.type) { |  154   switch (var.type) { | 
|  110     case PP_VARTYPE_UNDEFINED: |  155     case PP_VARTYPE_UNDEFINED: | 
|  111       return "##UNDEFINED##"; |  156       return "##UNDEFINED##"; | 
|  112     case PP_VARTYPE_NULL: |  157     case PP_VARTYPE_NULL: | 
|  113       return "##NULL##"; |  158       return "##NULL##"; | 
|  114     case PP_VARTYPE_BOOL: |  159     case PP_VARTYPE_BOOL: | 
|  115       return (var.value.as_bool ? "true" : "false"); |  160       return (var.value.as_bool ? "true" : "false"); | 
|  116     case PP_VARTYPE_INT32: |  161     case PP_VARTYPE_INT32: | 
|  117       { |  162       { | 
| (...skipping 12 matching lines...) Expand all  Loading... | 
|  130     case PP_VARTYPE_STRING: |  175     case PP_VARTYPE_STRING: | 
|  131       { |  176       { | 
|  132         uint32_t len; |  177         uint32_t len; | 
|  133         const char* data = VarToUtf8(var, &len); |  178         const char* data = VarToUtf8(var, &len); | 
|  134         return std::string(data, len); |  179         return std::string(data, len); | 
|  135       } |  180       } | 
|  136     case PP_VARTYPE_OBJECT: |  181     case PP_VARTYPE_OBJECT: | 
|  137       { |  182       { | 
|  138         char buf[32]; |  183         char buf[32]; | 
|  139         const size_t kBufSize = sizeof(buf); |  184         const size_t kBufSize = sizeof(buf); | 
|  140         SNPRINTF(buf, kBufSize, "%"NACL_PRIu64"", GetVarId(var)); |  185         SNPRINTF(buf, kBufSize, "%"NACL_PRId64"", GetVarId(var)); | 
|  141         return std::string("##OBJECT##") + buf + "##"; |  186         return std::string("##OBJECT##") + buf + "##"; | 
|  142       } |  187       } | 
 |  188     case PP_VARTYPE_ARRAY_BUFFER: | 
 |  189       { | 
 |  190         char buf[32]; | 
 |  191         const size_t kBufSize = sizeof(buf); | 
 |  192         SNPRINTF(buf, kBufSize, "%"NACL_PRId64"", GetVarId(var)); | 
 |  193         return std::string("##ARRAYBUFFER##") + buf + "##"; | 
 |  194       } | 
|  143     case PP_VARTYPE_ARRAY: |  195     case PP_VARTYPE_ARRAY: | 
|  144     case PP_VARTYPE_DICTIONARY: |  196     case PP_VARTYPE_DICTIONARY: | 
|  145     case PP_VARTYPE_ARRAY_BUFFER: |  | 
|  146       NACL_NOTREACHED(); |  197       NACL_NOTREACHED(); | 
|  147       break; |  198       break; | 
|  148   } |  199   } | 
|  149   ASSERT_MSG(0, "Unexpected type seen"); |  200   ASSERT_MSG(0, "Unexpected type seen"); | 
|  150   return "##ERROR##"; |  201   return "##ERROR##"; | 
|  151 } |  202 } | 
|  152  |  203  | 
|  153 PP_Var PluginVar::StringToPPVar(const std::string& str) { |  204 PP_Var PluginVar::StringToPPVar(const std::string& str) { | 
|  154   static const PPB_Var* ppb_var = NULL; |  205   static const PPB_Var* ppb_var = NULL; | 
|  155   if (ppb_var == NULL) { |  206   if (ppb_var == NULL) { | 
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  205       break; |  256       break; | 
|  206     case PP_VARTYPE_ARRAY: |  257     case PP_VARTYPE_ARRAY: | 
|  207     case PP_VARTYPE_DICTIONARY: |  258     case PP_VARTYPE_DICTIONARY: | 
|  208     case PP_VARTYPE_ARRAY_BUFFER: |  259     case PP_VARTYPE_ARRAY_BUFFER: | 
|  209       NACL_NOTREACHED(); |  260       NACL_NOTREACHED(); | 
|  210       break; |  261       break; | 
|  211   } |  262   } | 
|  212 } |  263 } | 
|  213  |  264  | 
|  214 }  // namespace ppapi_proxy |  265 }  // namespace ppapi_proxy | 
| OLD | NEW |