| OLD | NEW |
| 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 "chrome/browser/safe_browsing/safe_browsing_util.h" | 5 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
| 10 #include "chrome/browser/google/google_util.h" | 10 #include "chrome/browser/google/google_util.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 f_replacements.ClearPassword(); | 291 f_replacements.ClearPassword(); |
| 292 url_without_fragment = url.ReplaceComponents(f_replacements); | 292 url_without_fragment = url.ReplaceComponents(f_replacements); |
| 293 | 293 |
| 294 // 2. Do URL unescaping until no more hex encoded characters exist. | 294 // 2. Do URL unescaping until no more hex encoded characters exist. |
| 295 std::string url_unescaped_str(Unescape(url_without_fragment.spec())); | 295 std::string url_unescaped_str(Unescape(url_without_fragment.spec())); |
| 296 url_parse::Parsed parsed; | 296 url_parse::Parsed parsed; |
| 297 url_parse::ParseStandardURL(url_unescaped_str.data(), | 297 url_parse::ParseStandardURL(url_unescaped_str.data(), |
| 298 url_unescaped_str.length(), &parsed); | 298 url_unescaped_str.length(), &parsed); |
| 299 | 299 |
| 300 // 3. In hostname, remove all leading and trailing dots. | 300 // 3. In hostname, remove all leading and trailing dots. |
| 301 const std::string host = (parsed.host.len > 0) ? url_unescaped_str.substr( | 301 const std::string host = |
| 302 parsed.host.begin, parsed.host.len) : ""; | 302 (parsed.host.len > 0) |
| 303 ? url_unescaped_str.substr(parsed.host.begin, parsed.host.len) |
| 304 : std::string(); |
| 303 const char kCharsToTrim[] = "."; | 305 const char kCharsToTrim[] = "."; |
| 304 std::string host_without_end_dots; | 306 std::string host_without_end_dots; |
| 305 TrimString(host, kCharsToTrim, &host_without_end_dots); | 307 TrimString(host, kCharsToTrim, &host_without_end_dots); |
| 306 | 308 |
| 307 // 4. In hostname, replace consecutive dots with a single dot. | 309 // 4. In hostname, replace consecutive dots with a single dot. |
| 308 std::string host_without_consecutive_dots(RemoveConsecutiveChars( | 310 std::string host_without_consecutive_dots(RemoveConsecutiveChars( |
| 309 host_without_end_dots, '.')); | 311 host_without_end_dots, '.')); |
| 310 | 312 |
| 311 // 5. In path, replace runs of consecutive slashes with a single slash. | 313 // 5. In path, replace runs of consecutive slashes with a single slash. |
| 312 std::string path = (parsed.path.len > 0) ? url_unescaped_str.substr( | 314 std::string path = |
| 313 parsed.path.begin, parsed.path.len): ""; | 315 (parsed.path.len > 0) |
| 314 std::string path_without_consecutive_slash(RemoveConsecutiveChars( | 316 ? url_unescaped_str.substr(parsed.path.begin, parsed.path.len) |
| 315 path, '/')); | 317 : std::string(); |
| 318 std::string path_without_consecutive_slash(RemoveConsecutiveChars(path, '/')); |
| 316 | 319 |
| 317 url_canon::Replacements<char> hp_replacements; | 320 url_canon::Replacements<char> hp_replacements; |
| 318 hp_replacements.SetHost(host_without_consecutive_dots.data(), | 321 hp_replacements.SetHost(host_without_consecutive_dots.data(), |
| 319 url_parse::Component(0, host_without_consecutive_dots.length())); | 322 url_parse::Component(0, host_without_consecutive_dots.length())); |
| 320 hp_replacements.SetPath(path_without_consecutive_slash.data(), | 323 hp_replacements.SetPath(path_without_consecutive_slash.data(), |
| 321 url_parse::Component(0, path_without_consecutive_slash.length())); | 324 url_parse::Component(0, path_without_consecutive_slash.length())); |
| 322 | 325 |
| 323 std::string url_unescaped_with_can_hostpath; | 326 std::string url_unescaped_with_can_hostpath; |
| 324 url_canon::StdStringCanonOutput output(&url_unescaped_with_can_hostpath); | 327 url_canon::StdStringCanonOutput output(&url_unescaped_with_can_hostpath); |
| 325 url_parse::Parsed temp_parsed; | 328 url_parse::Parsed temp_parsed; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); | 509 memcpy(hash_out.full_hash, hash_in.data(), crypto::kSHA256Length); |
| 507 return hash_out; | 510 return hash_out; |
| 508 } | 511 } |
| 509 | 512 |
| 510 std::string SBFullHashToString(const SBFullHash& hash) { | 513 std::string SBFullHashToString(const SBFullHash& hash) { |
| 511 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); | 514 DCHECK_EQ(crypto::kSHA256Length, sizeof(hash.full_hash)); |
| 512 return std::string(hash.full_hash, sizeof(hash.full_hash)); | 515 return std::string(hash.full_hash, sizeof(hash.full_hash)); |
| 513 } | 516 } |
| 514 | 517 |
| 515 } // namespace safe_browsing_util | 518 } // namespace safe_browsing_util |
| OLD | NEW |