Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(836)

Unified Diff: ppapi/shared_impl/private/net_address_private_impl.cc

Issue 8537026: Pepper: Implement PPB_NetAddress_Private Describe() for IPv4 on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/shared_impl/private/net_address_private_impl.cc
diff --git a/ppapi/shared_impl/private/net_address_private_impl.cc b/ppapi/shared_impl/private/net_address_private_impl.cc
index fe55b2cbd0c8647ce9872212e685e7fca908aab3..61033a74fec5bdc9abca957e6257e68e0f93b673 100644
--- a/ppapi/shared_impl/private/net_address_private_impl.cc
+++ b/ppapi/shared_impl/private/net_address_private_impl.cc
@@ -9,6 +9,8 @@
#include <string>
#include "base/basictypes.h"
+#include "base/logging.h"
+#include "base/stringprintf.h"
#include "build/build_config.h"
#include "net/base/net_util.h"
#include "net/base/sys_addrinfo.h"
@@ -92,12 +94,39 @@ PP_Var Describe(PP_Module module,
if (!NetAddressPrivateImpl::ValidateNetAddress(*addr))
return PP_MakeUndefined();
+#if defined(OS_WIN)
+ // On Windows, |NetAddressToString()| doesn't work in the sandbox.
+ // TODO(viettrungluu): Consider switching to this everywhere once it's fully
+ // implemented.
+ switch (GetFamily(*addr)) {
+ case AF_INET: {
+ const sockaddr_in* a = reinterpret_cast<const sockaddr_in*>(addr->data);
+ unsigned ip = ntohl(a->sin_addr.s_addr);
+ unsigned port = ntohs(a->sin_port);
+ std::string description = base::StringPrintf(
+ "%u.%u.%u.%u",
+ (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff);
+ if (include_port)
+ description.append(base::StringPrintf(":%u", port));
+ return StringVar::StringToPPVar(module, description);
+ }
+ case AF_INET6:
+ // TODO(viettrungluu): crbug.com/103969
+ NOTIMPLEMENTED();
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+ return PP_MakeUndefined();
+#else
const sockaddr* a = reinterpret_cast<const sockaddr*>(addr->data);
socklen_t l = addr->size;
std::string description =
include_port ? net::NetAddressToStringWithPort(a, l) :
net::NetAddressToString(a, l);
return StringVar::StringToPPVar(module, description);
+#endif
}
PP_Bool ReplacePort(const struct PP_NetAddress_Private* src_addr,
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698