| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 return NULL; | 367 return NULL; |
| 368 TemplateURL* template_url = keyword.empty() ? | 368 TemplateURL* template_url = keyword.empty() ? |
| 369 NULL : template_url_service->GetTemplateURLForKeyword(keyword); | 369 NULL : template_url_service->GetTemplateURLForKeyword(keyword); |
| 370 return (template_url || host.empty()) ? | 370 return (template_url || host.empty()) ? |
| 371 template_url : template_url_service->GetTemplateURLForHost(host); | 371 template_url : template_url_service->GetTemplateURLForHost(host); |
| 372 } | 372 } |
| 373 | 373 |
| 374 // static | 374 // static |
| 375 GURL AutocompleteMatch::GURLToStrippedGURL( | 375 GURL AutocompleteMatch::GURLToStrippedGURL( |
| 376 const GURL& url, | 376 const GURL& url, |
| 377 const bool scheme_explicitly_entered, |
| 377 TemplateURLService* template_url_service, | 378 TemplateURLService* template_url_service, |
| 378 const base::string16& keyword) { | 379 const base::string16& keyword) { |
| 379 if (!url.is_valid()) | 380 if (!url.is_valid()) |
| 380 return url; | 381 return url; |
| 381 | 382 |
| 382 GURL stripped_destination_url = url; | 383 GURL stripped_destination_url = url; |
| 383 | 384 |
| 384 // If the destination URL looks like it was generated from a TemplateURL, | 385 // If the destination URL looks like it was generated from a TemplateURL, |
| 385 // remove all substitutions other than the search terms. This allows us | 386 // remove all substitutions other than the search terms. This allows us |
| 386 // to eliminate cases like past search URLs from history that differ only | 387 // to eliminate cases like past search URLs from history that differ only |
| (...skipping 25 matching lines...) Expand all Loading... |
| 412 | 413 |
| 413 // Remove the www. prefix from the host. | 414 // Remove the www. prefix from the host. |
| 414 static const char prefix[] = "www."; | 415 static const char prefix[] = "www."; |
| 415 static const size_t prefix_len = arraysize(prefix) - 1; | 416 static const size_t prefix_len = arraysize(prefix) - 1; |
| 416 std::string host = stripped_destination_url.host(); | 417 std::string host = stripped_destination_url.host(); |
| 417 if (host.compare(0, prefix_len, prefix) == 0) { | 418 if (host.compare(0, prefix_len, prefix) == 0) { |
| 418 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); | 419 replacements.SetHostStr(base::StringPiece(host).substr(prefix_len)); |
| 419 needs_replacement = true; | 420 needs_replacement = true; |
| 420 } | 421 } |
| 421 | 422 |
| 422 // Replace https protocol with http protocol. | 423 // Possibly replace https protocol with http protocol. |
| 423 if (stripped_destination_url.SchemeIs(url::kHttpsScheme)) { | 424 if (!scheme_explicitly_entered && |
| 425 stripped_destination_url.SchemeIs(url::kHttpsScheme)) { |
| 424 replacements.SetScheme(url::kHttpScheme, | 426 replacements.SetScheme(url::kHttpScheme, |
| 425 url::Component(0, strlen(url::kHttpScheme))); | 427 url::Component(0, strlen(url::kHttpScheme))); |
| 426 needs_replacement = true; | 428 needs_replacement = true; |
| 427 } | 429 } |
| 428 | 430 |
| 429 if (needs_replacement) | 431 if (needs_replacement) |
| 430 stripped_destination_url = stripped_destination_url.ReplaceComponents( | 432 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
| 431 replacements); | 433 replacements); |
| 432 return stripped_destination_url; | 434 return stripped_destination_url; |
| 433 } | 435 } |
| 434 | 436 |
| 435 void AutocompleteMatch::ComputeStrippedDestinationURL( | 437 void AutocompleteMatch::ComputeStrippedDestinationURL( |
| 438 const bool scheme_explicitly_entered, |
| 436 TemplateURLService* template_url_service) { | 439 TemplateURLService* template_url_service) { |
| 437 stripped_destination_url = | 440 stripped_destination_url = GURLToStrippedGURL( |
| 438 GURLToStrippedGURL(destination_url, template_url_service, keyword); | 441 destination_url, scheme_explicitly_entered,template_url_service, keyword); |
| 439 } | 442 } |
| 440 | 443 |
| 441 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( | 444 void AutocompleteMatch::EnsureUWYTIsAllowedToBeDefault( |
| 442 const GURL& canonical_input_url, | 445 const GURL& canonical_input_url, |
| 446 const bool scheme_explicitly_entered, |
| 443 TemplateURLService* template_url_service) { | 447 TemplateURLService* template_url_service) { |
| 444 if (!allowed_to_be_default_match) { | 448 if (!allowed_to_be_default_match) { |
| 445 const GURL& stripped_canonical_input_url = | 449 const GURL& stripped_canonical_input_url = |
| 446 AutocompleteMatch::GURLToStrippedGURL( | 450 AutocompleteMatch::GURLToStrippedGURL( |
| 447 canonical_input_url, template_url_service, base::string16()); | 451 canonical_input_url, scheme_explicitly_entered, |
| 448 ComputeStrippedDestinationURL(template_url_service); | 452 template_url_service, base::string16()); |
| 453 ComputeStrippedDestinationURL(scheme_explicitly_entered, |
| 454 template_url_service); |
| 449 allowed_to_be_default_match = | 455 allowed_to_be_default_match = |
| 450 stripped_canonical_input_url == stripped_destination_url; | 456 stripped_canonical_input_url == stripped_destination_url; |
| 451 } | 457 } |
| 452 } | 458 } |
| 453 | 459 |
| 454 void AutocompleteMatch::GetKeywordUIState( | 460 void AutocompleteMatch::GetKeywordUIState( |
| 455 TemplateURLService* template_url_service, | 461 TemplateURLService* template_url_service, |
| 456 base::string16* keyword, | 462 base::string16* keyword, |
| 457 bool* is_keyword_hint) const { | 463 bool* is_keyword_hint) const { |
| 458 *is_keyword_hint = associated_keyword.get() != NULL; | 464 *is_keyword_hint = associated_keyword.get() != NULL; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 << " is unsorted in relation to last offset of " << last_offset | 567 << " is unsorted in relation to last offset of " << last_offset |
| 562 << ". Provider: " << provider_name << "."; | 568 << ". Provider: " << provider_name << "."; |
| 563 DCHECK_LT(i->offset, text.length()) | 569 DCHECK_LT(i->offset, text.length()) |
| 564 << " Classification of [" << i->offset << "," << text.length() | 570 << " Classification of [" << i->offset << "," << text.length() |
| 565 << "] is out of bounds for \"" << text << "\". Provider: " | 571 << "] is out of bounds for \"" << text << "\". Provider: " |
| 566 << provider_name << "."; | 572 << provider_name << "."; |
| 567 last_offset = i->offset; | 573 last_offset = i->offset; |
| 568 } | 574 } |
| 569 } | 575 } |
| 570 #endif | 576 #endif |
| OLD | NEW |