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

Side by Side Diff: net/base/net_util_win.cc

Issue 220253002: Add net/base/filename_util.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 months 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/filter/filter.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "net/base/net_util.h" 5 #include "net/base/net_util.h"
6 6
7 #include <iphlpapi.h> 7 #include <iphlpapi.h>
8 #include <wlanapi.h> 8 #include <wlanapi.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 WlanQueryInterfaceFunc query_interface_func; 78 WlanQueryInterfaceFunc query_interface_func;
79 WlanFreeMemoryFunc free_memory_func; 79 WlanFreeMemoryFunc free_memory_func;
80 WlanCloseHandleFunc close_handle_func; 80 WlanCloseHandleFunc close_handle_func;
81 bool initialized; 81 bool initialized;
82 }; 82 };
83 83
84 } // namespace 84 } // namespace
85 85
86 namespace net { 86 namespace net {
87 87
88 bool FileURLToFilePath(const GURL& url, base::FilePath* file_path) {
89 *file_path = base::FilePath();
90 std::wstring& file_path_str = const_cast<std::wstring&>(file_path->value());
91 file_path_str.clear();
92
93 if (!url.is_valid())
94 return false;
95
96 std::string path;
97 std::string host = url.host();
98 if (host.empty()) {
99 // URL contains no host, the path is the filename. In this case, the path
100 // will probably be preceeded with a slash, as in "/C:/foo.txt", so we
101 // trim out that here.
102 path = url.path();
103 size_t first_non_slash = path.find_first_not_of("/\\");
104 if (first_non_slash != std::string::npos && first_non_slash > 0)
105 path.erase(0, first_non_slash);
106 } else {
107 // URL contains a host: this means it's UNC. We keep the preceeding slash
108 // on the path.
109 path = "\\\\";
110 path.append(host);
111 path.append(url.path());
112 }
113
114 if (path.empty())
115 return false;
116 std::replace(path.begin(), path.end(), '/', '\\');
117
118 // GURL stores strings as percent-encoded UTF-8, this will undo if possible.
119 path = UnescapeURLComponent(path,
120 UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS);
121
122 if (!IsStringUTF8(path)) {
123 // Not UTF-8, assume encoding is native codepage and we're done. We know we
124 // are giving the conversion function a nonempty string, and it may fail if
125 // the given string is not in the current encoding and give us an empty
126 // string back. We detect this and report failure.
127 file_path_str = base::SysNativeMBToWide(path);
128 return !file_path_str.empty();
129 }
130 file_path_str.assign(base::UTF8ToWide(path));
131
132 // We used to try too hard and see if |path| made up entirely of
133 // the 1st 256 characters in the Unicode was a zero-extended UTF-16.
134 // If so, we converted it to 'Latin-1' and checked if the result was UTF-8.
135 // If the check passed, we converted the result to UTF-8.
136 // Otherwise, we treated the result as the native OS encoding.
137 // However, that led to http://crbug.com/4619 and http://crbug.com/14153
138 return true;
139 }
140
141 bool GetNetworkList(NetworkInterfaceList* networks, int policy) { 88 bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
142 // GetAdaptersAddresses() may require IO operations. 89 // GetAdaptersAddresses() may require IO operations.
143 base::ThreadRestrictions::AssertIOAllowed(); 90 base::ThreadRestrictions::AssertIOAllowed();
144 bool is_xp = base::win::GetVersion() < base::win::VERSION_VISTA; 91 bool is_xp = base::win::GetVersion() < base::win::VERSION_VISTA;
145 ULONG len = 0; 92 ULONG len = 0;
146 ULONG flags = is_xp ? GAA_FLAG_INCLUDE_PREFIX : 0; 93 ULONG flags = is_xp ? GAA_FLAG_INCLUDE_PREFIX : 0;
147 // First get number of networks. 94 // First get number of networks.
148 ULONG result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, NULL, &len); 95 ULONG result = GetAdaptersAddresses(AF_UNSPEC, flags, NULL, NULL, &len);
149 if (result != ERROR_BUFFER_OVERFLOW) { 96 if (result != ERROR_BUFFER_OVERFLOW) {
150 // There are 0 networks. 97 // There are 0 networks.
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 case dot11_phy_type_erp: 277 case dot11_phy_type_erp:
331 return WIFI_PHY_LAYER_PROTOCOL_G; 278 return WIFI_PHY_LAYER_PROTOCOL_G;
332 case dot11_phy_type_ht: 279 case dot11_phy_type_ht:
333 return WIFI_PHY_LAYER_PROTOCOL_N; 280 return WIFI_PHY_LAYER_PROTOCOL_N;
334 default: 281 default:
335 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN; 282 return WIFI_PHY_LAYER_PROTOCOL_UNKNOWN;
336 } 283 }
337 } 284 }
338 285
339 } // namespace net 286 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util_unittest.cc ('k') | net/filter/filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698