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