| 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 #include "ppapi/proxy/host_var_serialization_rules.h" | 5 #include "ppapi/proxy/host_var_serialization_rules.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "ppapi/c/dev/ppb_var_deprecated.h" | 8 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 9 | 9 |
| 10 namespace pp { | 10 namespace pp { |
| 11 namespace proxy { | 11 namespace proxy { |
| 12 | 12 |
| 13 HostVarSerializationRules::HostVarSerializationRules( | 13 HostVarSerializationRules::HostVarSerializationRules( |
| 14 const PPB_Var_Deprecated* var_interface, | 14 const PPB_Var_Deprecated* var_interface, |
| 15 PP_Module pp_module) | 15 PP_Module pp_module) |
| 16 : var_interface_(var_interface), | 16 : var_interface_(var_interface), |
| 17 pp_module_(pp_module) { | 17 pp_module_(pp_module) { |
| 18 } | 18 } |
| 19 | 19 |
| 20 HostVarSerializationRules::~HostVarSerializationRules() { | 20 HostVarSerializationRules::~HostVarSerializationRules() { |
| 21 } | 21 } |
| 22 | 22 |
| 23 void HostVarSerializationRules::SendCallerOwned(const PP_Var& var, | 23 PP_Var HostVarSerializationRules::SendCallerOwned(const PP_Var& var, |
| 24 std::string* str_val) { | 24 std::string* str_val) { |
| 25 if (var.type == PP_VARTYPE_STRING) | 25 if (var.type == PP_VARTYPE_STRING) |
| 26 VarToString(var, str_val); | 26 VarToString(var, str_val); |
| 27 return var; |
| 27 } | 28 } |
| 28 | 29 |
| 29 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( | 30 PP_Var HostVarSerializationRules::BeginReceiveCallerOwned( |
| 30 const PP_Var& var, | 31 const PP_Var& var, |
| 31 const std::string* str_val) { | 32 const std::string* str_val, |
| 33 Dispatcher* /* dispatcher */) { |
| 32 if (var.type == PP_VARTYPE_STRING) { | 34 if (var.type == PP_VARTYPE_STRING) { |
| 33 // Convert the string to the context of the current process. | 35 // Convert the string to the context of the current process. |
| 34 return var_interface_->VarFromUtf8(pp_module_, str_val->c_str(), | 36 return var_interface_->VarFromUtf8(pp_module_, str_val->c_str(), |
| 35 static_cast<uint32_t>(str_val->size())); | 37 static_cast<uint32_t>(str_val->size())); |
| 36 } | 38 } |
| 37 return var; | 39 return var; |
| 38 } | 40 } |
| 39 | 41 |
| 40 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { | 42 void HostVarSerializationRules::EndReceiveCallerOwned(const PP_Var& var) { |
| 41 if (var.type == PP_VARTYPE_STRING) { | 43 if (var.type == PP_VARTYPE_STRING) { |
| 42 // Destroy the string BeginReceiveCallerOwned created above. | 44 // Destroy the string BeginReceiveCallerOwned created above. |
| 43 var_interface_->Release(var); | 45 var_interface_->Release(var); |
| 44 } | 46 } |
| 45 } | 47 } |
| 46 | 48 |
| 47 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var, | 49 PP_Var HostVarSerializationRules::ReceivePassRef(const PP_Var& var, |
| 48 const std::string& str_val) { | 50 const std::string& str_val, |
| 51 Dispatcher* /* dispatcher */) { |
| 49 if (var.type == PP_VARTYPE_STRING) { | 52 if (var.type == PP_VARTYPE_STRING) { |
| 50 // Convert the string to the context of the current process. | 53 // Convert the string to the context of the current process. |
| 51 return var_interface_->VarFromUtf8(pp_module_, str_val.c_str(), | 54 return var_interface_->VarFromUtf8(pp_module_, str_val.c_str(), |
| 52 static_cast<uint32_t>(str_val.size())); | 55 static_cast<uint32_t>(str_val.size())); |
| 53 } | 56 } |
| 54 | 57 |
| 55 // See PluginVarSerialization::BeginSendPassRef for an example. | 58 // See PluginVarSerialization::BeginSendPassRef for an example. |
| 56 if (var.type == PP_VARTYPE_OBJECT) | 59 if (var.type == PP_VARTYPE_OBJECT) |
| 57 var_interface_->AddRef(var); | 60 var_interface_->AddRef(var); |
| 58 return var; | 61 return var; |
| 59 } | 62 } |
| 60 | 63 |
| 61 void HostVarSerializationRules::BeginSendPassRef(const PP_Var& var, | 64 PP_Var HostVarSerializationRules::BeginSendPassRef(const PP_Var& var, |
| 62 std::string* str_val) { | 65 std::string* str_val) { |
| 63 // See PluginVarSerialization::ReceivePassRef for an example. We don't need | 66 // See PluginVarSerialization::ReceivePassRef for an example. We don't need |
| 64 // to do anything here other than convert the string. | 67 // to do anything here other than convert the string. |
| 65 if (var.type == PP_VARTYPE_STRING) | 68 if (var.type == PP_VARTYPE_STRING) |
| 66 VarToString(var, str_val); | 69 VarToString(var, str_val); |
| 70 return var; |
| 67 } | 71 } |
| 68 | 72 |
| 69 void HostVarSerializationRules::EndSendPassRef(const PP_Var& var) { | 73 void HostVarSerializationRules::EndSendPassRef(const PP_Var& var) { |
| 70 // See PluginVarSerialization::ReceivePassRef for an example. We don't need | 74 // See PluginVarSerialization::ReceivePassRef for an example. We don't need |
| 71 // to do anything here. | 75 // to do anything here. |
| 72 } | 76 } |
| 73 | 77 |
| 74 void HostVarSerializationRules::VarToString(const PP_Var& var, | 78 void HostVarSerializationRules::VarToString(const PP_Var& var, |
| 75 std::string* str) { | 79 std::string* str) { |
| 76 DCHECK(var.type == PP_VARTYPE_STRING); | 80 DCHECK(var.type == PP_VARTYPE_STRING); |
| 77 | 81 |
| 78 // This could be optimized to avoid an extra string copy by going to a lower | 82 // This could be optimized to avoid an extra string copy by going to a lower |
| 79 // level of the browser's implementation of strings where we already have | 83 // level of the browser's implementation of strings where we already have |
| 80 // a std::string. | 84 // a std::string. |
| 81 uint32_t len = 0; | 85 uint32_t len = 0; |
| 82 const char* data = var_interface_->VarToUtf8(var, &len); | 86 const char* data = var_interface_->VarToUtf8(var, &len); |
| 83 str->assign(data, len); | 87 str->assign(data, len); |
| 84 } | 88 } |
| 85 | 89 |
| 86 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { | 90 void HostVarSerializationRules::ReleaseObjectRef(const PP_Var& var) { |
| 87 var_interface_->Release(var); | 91 var_interface_->Release(var); |
| 88 } | 92 } |
| 89 | 93 |
| 90 } // namespace proxy | 94 } // namespace proxy |
| 91 } // namespace pp | 95 } // namespace pp |
| OLD | NEW |