OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "remoting/host/host_plugin_utils.h" |
| 6 |
| 7 namespace remoting { |
| 8 |
| 9 NPNetscapeFuncs* g_npnetscape_funcs = NULL; |
| 10 |
| 11 std::string StringFromNPIdentifier(NPIdentifier identifier) { |
| 12 if (!g_npnetscape_funcs->identifierisstring(identifier)) |
| 13 return std::string(); |
| 14 NPUTF8* np_string = g_npnetscape_funcs->utf8fromidentifier(identifier); |
| 15 std::string string(np_string); |
| 16 g_npnetscape_funcs->memfree(np_string); |
| 17 return string; |
| 18 } |
| 19 |
| 20 std::string StringFromNPVariant(const NPVariant& variant) { |
| 21 if (!NPVARIANT_IS_STRING(variant)) |
| 22 return std::string(); |
| 23 const NPString& np_string = NPVARIANT_TO_STRING(variant); |
| 24 return std::string(np_string.UTF8Characters, np_string.UTF8Length); |
| 25 } |
| 26 |
| 27 NPVariant NPVariantFromString(const std::string& val) { |
| 28 size_t len = val.length(); |
| 29 NPUTF8* chars = |
| 30 reinterpret_cast<NPUTF8*>(g_npnetscape_funcs->memalloc(len + 1)); |
| 31 strcpy(chars, val.c_str()); |
| 32 NPVariant variant; |
| 33 STRINGN_TO_NPVARIANT(chars, len, variant); |
| 34 return variant; |
| 35 } |
| 36 |
| 37 NPObject* ObjectFromNPVariant(const NPVariant& variant) { |
| 38 if (!NPVARIANT_IS_OBJECT(variant)) |
| 39 return NULL; |
| 40 return NPVARIANT_TO_OBJECT(variant); |
| 41 } |
| 42 |
| 43 } // namespace remoting |
OLD | NEW |