| 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> |
| 8 |
| 7 #include <cstdlib> | 9 #include <cstdlib> |
| 8 #include <sstream> | 10 #include <sstream> |
| 9 #include <tuple> | 11 #include <tuple> |
| 10 #include <vector> | 12 #include <vector> |
| 11 | 13 |
| 12 #include "base/logging.h" | 14 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 17 #include "extensions/common/permissions/api_permission.h" | 19 #include "extensions/common/permissions/api_permission.h" |
| 18 #include "extensions/common/permissions/socket_permission.h" | 20 #include "extensions/common/permissions/socket_permission.h" |
| 19 #include "url/url_canon.h" | 21 #include "url/url_canon.h" |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 using content::SocketPermissionRequest; | 25 using content::SocketPermissionRequest; |
| 24 | 26 |
| 25 const char kColon = ':'; | 27 const char kColon = ':'; |
| 26 const char kDot = '.'; | 28 const char kDot = '.'; |
| 27 const char kWildcard[] = "*"; | 29 const char kWildcard[] = "*"; |
| 28 const uint16 kWildcardPortNumber = 0; | 30 const uint16_t kWildcardPortNumber = 0; |
| 29 const uint16 kInvalidPort = 65535; | 31 const uint16_t kInvalidPort = 65535; |
| 30 | 32 |
| 31 bool StartsOrEndsWithWhitespace(const std::string& str) { | 33 bool StartsOrEndsWithWhitespace(const std::string& str) { |
| 32 return !str.empty() && (base::IsUnicodeWhitespace(str[0]) || | 34 return !str.empty() && (base::IsUnicodeWhitespace(str[0]) || |
| 33 base::IsUnicodeWhitespace(str[str.length() - 1])); | 35 base::IsUnicodeWhitespace(str[str.length() - 1])); |
| 34 } | 36 } |
| 35 | 37 |
| 36 } // namespace | 38 } // namespace |
| 37 | 39 |
| 38 namespace extensions { | 40 namespace extensions { |
| 39 | 41 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 *entry = result; | 177 *entry = result; |
| 176 return true; | 178 return true; |
| 177 } | 179 } |
| 178 | 180 |
| 179 if (StartsOrEndsWithWhitespace(pattern_tokens[1])) | 181 if (StartsOrEndsWithWhitespace(pattern_tokens[1])) |
| 180 return false; | 182 return false; |
| 181 | 183 |
| 182 int port; | 184 int port; |
| 183 if (!base::StringToInt(pattern_tokens[1], &port) || port < 1 || port > 65535) | 185 if (!base::StringToInt(pattern_tokens[1], &port) || port < 1 || port > 65535) |
| 184 return false; | 186 return false; |
| 185 result.pattern_.port = static_cast<uint16>(port); | 187 result.pattern_.port = static_cast<uint16_t>(port); |
| 186 | 188 |
| 187 *entry = result; | 189 *entry = result; |
| 188 return true; | 190 return true; |
| 189 } | 191 } |
| 190 | 192 |
| 191 std::string SocketPermissionEntry::GetHostPatternAsString() const { | 193 std::string SocketPermissionEntry::GetHostPatternAsString() const { |
| 192 std::string result; | 194 std::string result; |
| 193 | 195 |
| 194 if (!IsAddressBoundType()) | 196 if (!IsAddressBoundType()) |
| 195 return result; | 197 return result; |
| 196 | 198 |
| 197 if (match_subdomains()) { | 199 if (match_subdomains()) { |
| 198 result.append(kWildcard); | 200 result.append(kWildcard); |
| 199 if (!pattern_.host.empty()) | 201 if (!pattern_.host.empty()) |
| 200 result.append(1, kDot).append(pattern_.host); | 202 result.append(1, kDot).append(pattern_.host); |
| 201 } else { | 203 } else { |
| 202 result.append(pattern_.host); | 204 result.append(pattern_.host); |
| 203 } | 205 } |
| 204 | 206 |
| 205 if (pattern_.port == kWildcardPortNumber) | 207 if (pattern_.port == kWildcardPortNumber) |
| 206 result.append(1, kColon).append(kWildcard); | 208 result.append(1, kColon).append(kWildcard); |
| 207 else | 209 else |
| 208 result.append(1, kColon).append(base::UintToString(pattern_.port)); | 210 result.append(1, kColon).append(base::UintToString(pattern_.port)); |
| 209 | 211 |
| 210 return result; | 212 return result; |
| 211 } | 213 } |
| 212 | 214 |
| 213 } // namespace extensions | 215 } // namespace extensions |
| OLD | NEW |