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 "components/omnibox/autocomplete_match.h" | 5 #include "components/omnibox/autocomplete_match.h" |
6 | 6 |
7 #include "base/i18n/time_formatting.h" | 7 #include "base/i18n/time_formatting.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 408 |
409 // Remove the www. prefix from the host. | 409 // Remove the www. prefix from the host. |
410 static const char prefix[] = "www."; | 410 static const char prefix[] = "www."; |
411 static const size_t prefix_len = arraysize(prefix) - 1; | 411 static const size_t prefix_len = arraysize(prefix) - 1; |
412 std::string host = stripped_destination_url.host(); | 412 std::string host = stripped_destination_url.host(); |
413 if (host.compare(0, prefix_len, prefix) == 0) { | 413 if (host.compare(0, prefix_len, prefix) == 0) { |
414 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); | 414 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); |
415 needs_replacement = true; | 415 needs_replacement = true; |
416 } | 416 } |
417 | 417 |
| 418 // Remove any trailing slash (if it's not a lone slash), or add a slash (to |
| 419 // make a lone slash) if the path is empty. (We can't unconditionally |
| 420 // remove even lone slashes because for some schemes the path must consist |
| 421 // of at least a slash.) |
| 422 const std::string& path = stripped_destination_url.path(); |
| 423 if ((path.length() > 1) && (path[path.length() - 1] == '/')) { |
| 424 replacements.SetPathStr( |
| 425 base::StringPiece(path).substr(0, path.length() - 1)); |
| 426 needs_replacement = true; |
| 427 } else if (path.empty()) { |
| 428 static const char slash[] = "/"; |
| 429 replacements.SetPathStr(base::StringPiece(slash)); |
| 430 needs_replacement = true; |
| 431 } |
| 432 |
418 // Replace https protocol with http protocol. | 433 // Replace https protocol with http protocol. |
419 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { | 434 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { |
420 replacements.SetScheme(url::kHttpScheme, | 435 replacements.SetScheme(url::kHttpScheme, |
421 url::Component(0, strlen(url::kHttpScheme))); | 436 url::Component(0, strlen(url::kHttpScheme))); |
422 needs_replacement = true; | 437 needs_replacement = true; |
423 } | 438 } |
424 | 439 |
425 if (needs_replacement) | 440 if (needs_replacement) |
426 stripped_destination_url = stripped_destination_url.ReplaceComponents( | 441 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
427 replacements); | 442 replacements); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 << " is unsorted in relation to last offset of " << last_offset | 572 << " is unsorted in relation to last offset of " << last_offset |
558 << ". Provider: " << provider_name << "."; | 573 << ". Provider: " << provider_name << "."; |
559 DCHECK_LT(i->offset, text.length()) | 574 DCHECK_LT(i->offset, text.length()) |
560 << " Classification of [" << i->offset << "," << text.length() | 575 << " Classification of [" << i->offset << "," << text.length() |
561 << "] is out of bounds for \"" << text << "\". Provider: " | 576 << "] is out of bounds for \"" << text << "\". Provider: " |
562 << provider_name << "."; | 577 << provider_name << "."; |
563 last_offset = i->offset; | 578 last_offset = i->offset; |
564 } | 579 } |
565 } | 580 } |
566 #endif | 581 #endif |
OLD | NEW |