| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstdlib> | 9 #include <cstdlib> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <sstream> | 11 #include <sstream> |
| 12 #include <tuple> | 12 #include <tuple> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_piece.h" |
| 17 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
| 19 #include "extensions/common/permissions/api_permission.h" | 20 #include "extensions/common/permissions/api_permission.h" |
| 20 #include "extensions/common/permissions/socket_permission.h" | 21 #include "extensions/common/permissions/socket_permission.h" |
| 21 #include "url/url_canon.h" | 22 #include "url/url_canon.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 using content::SocketPermissionRequest; | 26 using content::SocketPermissionRequest; |
| 26 | 27 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (!result.IsAddressBoundType()) | 152 if (!result.IsAddressBoundType()) |
| 152 return false; | 153 return false; |
| 153 | 154 |
| 154 result.pattern_.host = pattern_tokens[0]; | 155 result.pattern_.host = pattern_tokens[0]; |
| 155 if (!result.pattern_.host.empty()) { | 156 if (!result.pattern_.host.empty()) { |
| 156 if (StartsOrEndsWithWhitespace(result.pattern_.host)) | 157 if (StartsOrEndsWithWhitespace(result.pattern_.host)) |
| 157 return false; | 158 return false; |
| 158 result.pattern_.host = base::ToLowerASCII(result.pattern_.host); | 159 result.pattern_.host = base::ToLowerASCII(result.pattern_.host); |
| 159 | 160 |
| 160 // The first component can optionally be '*' to match all subdomains. | 161 // The first component can optionally be '*' to match all subdomains. |
| 161 std::vector<std::string> host_components = | 162 std::vector<base::StringPiece> host_components = |
| 162 base::SplitString(result.pattern_.host, std::string(1, kDot), | 163 base::SplitStringPiece(result.pattern_.host, std::string{kDot}, |
| 163 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 164 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 164 DCHECK(!host_components.empty()); | 165 DCHECK(!host_components.empty()); |
| 165 | 166 |
| 166 if (host_components[0] == kWildcard || host_components[0].empty()) { | 167 if (host_components[0] == kWildcard || host_components[0].empty()) { |
| 167 host_components.erase(host_components.begin(), | 168 host_components.erase(host_components.begin(), |
| 168 host_components.begin() + 1); | 169 host_components.begin() + 1); |
| 169 } else { | 170 } else { |
| 170 result.match_subdomains_ = false; | 171 result.match_subdomains_ = false; |
| 171 } | 172 } |
| 172 result.pattern_.host = base::JoinString(host_components, "."); | 173 result.pattern_.host = base::JoinString(host_components, "."); |
| 173 } | 174 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 | 207 |
| 207 if (pattern_.port == kWildcardPortNumber) | 208 if (pattern_.port == kWildcardPortNumber) |
| 208 result.append(1, kColon).append(kWildcard); | 209 result.append(1, kColon).append(kWildcard); |
| 209 else | 210 else |
| 210 result.append(1, kColon).append(base::UintToString(pattern_.port)); | 211 result.append(1, kColon).append(base::UintToString(pattern_.port)); |
| 211 | 212 |
| 212 return result; | 213 return result; |
| 213 } | 214 } |
| 214 | 215 |
| 215 } // namespace extensions | 216 } // namespace extensions |
| OLD | NEW |