OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/common/permissions/socket_permission_entry.h" | 5 #include "extensions/common/permissions/socket_permission_entry.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 #include <sstream> | 8 #include <sstream> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 pattern_.type == SocketPermissionRequest::TCP_LISTEN || | 121 pattern_.type == SocketPermissionRequest::TCP_LISTEN || |
122 pattern_.type == SocketPermissionRequest::UDP_BIND || | 122 pattern_.type == SocketPermissionRequest::UDP_BIND || |
123 pattern_.type == SocketPermissionRequest::UDP_SEND_TO; | 123 pattern_.type == SocketPermissionRequest::UDP_SEND_TO; |
124 } | 124 } |
125 | 125 |
126 // static | 126 // static |
127 bool SocketPermissionEntry::ParseHostPattern( | 127 bool SocketPermissionEntry::ParseHostPattern( |
128 SocketPermissionRequest::OperationType type, | 128 SocketPermissionRequest::OperationType type, |
129 const std::string& pattern, | 129 const std::string& pattern, |
130 SocketPermissionEntry* entry) { | 130 SocketPermissionEntry* entry) { |
131 std::vector<std::string> tokens; | 131 std::vector<std::string> tokens = |
132 base::SplitStringDontTrim(pattern, kColon, &tokens); | 132 base::SplitString(pattern, std::string(1, kColon), base::KEEP_WHITESPACE, |
| 133 base::SPLIT_WANT_ALL); |
133 return ParseHostPattern(type, tokens, entry); | 134 return ParseHostPattern(type, tokens, entry); |
134 } | 135 } |
135 | 136 |
136 // static | 137 // static |
137 bool SocketPermissionEntry::ParseHostPattern( | 138 bool SocketPermissionEntry::ParseHostPattern( |
138 SocketPermissionRequest::OperationType type, | 139 SocketPermissionRequest::OperationType type, |
139 const std::vector<std::string>& pattern_tokens, | 140 const std::vector<std::string>& pattern_tokens, |
140 SocketPermissionEntry* entry) { | 141 SocketPermissionEntry* entry) { |
141 | 142 |
142 SocketPermissionEntry result; | 143 SocketPermissionEntry result; |
(...skipping 18 matching lines...) Expand all Loading... |
161 if (!result.IsAddressBoundType()) | 162 if (!result.IsAddressBoundType()) |
162 return false; | 163 return false; |
163 | 164 |
164 result.pattern_.host = pattern_tokens[0]; | 165 result.pattern_.host = pattern_tokens[0]; |
165 if (!result.pattern_.host.empty()) { | 166 if (!result.pattern_.host.empty()) { |
166 if (StartsOrEndsWithWhitespace(result.pattern_.host)) | 167 if (StartsOrEndsWithWhitespace(result.pattern_.host)) |
167 return false; | 168 return false; |
168 result.pattern_.host = base::StringToLowerASCII(result.pattern_.host); | 169 result.pattern_.host = base::StringToLowerASCII(result.pattern_.host); |
169 | 170 |
170 // The first component can optionally be '*' to match all subdomains. | 171 // The first component can optionally be '*' to match all subdomains. |
171 std::vector<std::string> host_components; | 172 std::vector<std::string> host_components = |
172 base::SplitString(result.pattern_.host, kDot, &host_components); | 173 base::SplitString(result.pattern_.host, std::string(1, kDot), |
| 174 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
173 DCHECK(!host_components.empty()); | 175 DCHECK(!host_components.empty()); |
174 | 176 |
175 if (host_components[0] == kWildcard || host_components[0].empty()) { | 177 if (host_components[0] == kWildcard || host_components[0].empty()) { |
176 host_components.erase(host_components.begin(), | 178 host_components.erase(host_components.begin(), |
177 host_components.begin() + 1); | 179 host_components.begin() + 1); |
178 } else { | 180 } else { |
179 result.match_subdomains_ = false; | 181 result.match_subdomains_ = false; |
180 } | 182 } |
181 result.pattern_.host = base::JoinString(host_components, "."); | 183 result.pattern_.host = base::JoinString(host_components, "."); |
182 } | 184 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 217 |
216 if (pattern_.port == kWildcardPortNumber) | 218 if (pattern_.port == kWildcardPortNumber) |
217 result.append(1, kColon).append(kWildcard); | 219 result.append(1, kColon).append(kWildcard); |
218 else | 220 else |
219 result.append(1, kColon).append(base::IntToString(pattern_.port)); | 221 result.append(1, kColon).append(base::IntToString(pattern_.port)); |
220 | 222 |
221 return result; | 223 return result; |
222 } | 224 } |
223 | 225 |
224 } // namespace extensions | 226 } // namespace extensions |
OLD | NEW |