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/autocomplete/autocomplete_match.h" | 5 #include "chrome/browser/autocomplete/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/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 } | 349 } |
350 | 350 |
351 // static | 351 // static |
352 bool AutocompleteMatch::IsSearchType(Type type) { | 352 bool AutocompleteMatch::IsSearchType(Type type) { |
353 return type == SEARCH_WHAT_YOU_TYPED || | 353 return type == SEARCH_WHAT_YOU_TYPED || |
354 type == SEARCH_HISTORY || | 354 type == SEARCH_HISTORY || |
355 type == SEARCH_SUGGEST || | 355 type == SEARCH_SUGGEST || |
356 type == SEARCH_OTHER_ENGINE; | 356 type == SEARCH_OTHER_ENGINE; |
357 } | 357 } |
358 | 358 |
359 void AutocompleteMatch::ComputeStrippedDestinationURL() { | 359 void AutocompleteMatch::ComputeStrippedDestinationURL( |
360 TemplateURL* search_provider_url) { | |
360 stripped_destination_url = destination_url; | 361 stripped_destination_url = destination_url; |
361 if (!stripped_destination_url.is_valid()) | 362 if (!stripped_destination_url.is_valid()) |
362 return; | 363 return; |
363 | 364 |
365 // Attempt to normalize search URLs by removing non-essential substitutions | |
366 // like aqs/oq/aq. | |
beaudoin
2012/10/19 14:25:34
I would not be opposed to adding a NormalizeURL to
| |
367 if (search_provider_url != NULL) { | |
368 string16 search_terms; | |
369 if (search_provider_url->ExtractSearchTermsFromURL(stripped_destination_url, | |
370 &search_terms)) { | |
371 // Rewrite the URL by using the extracted search terms and ignoring other | |
372 // arguments (it's OK, because it doesn't affect the destination URL and | |
373 // is sufficient from de-dupping perspective). | |
beaudoin
2012/10/19 14:25:34
This may confuse an "image search" with a regular
Peter Kasting
2012/10/19 22:49:33
Uuuuugggghhh. This is the sort of reason why I ge
Bart N.
2012/10/22 18:20:24
I agree this is a problem here. Even with your pro
beaudoin
2012/10/22 18:43:23
The problem is that ExtractSearchTermsFromURL is "
Bart N.
2012/10/22 19:19:42
Yes, totally makes sense. I didn't mean to make Ex
beaudoin
2012/10/22 21:36:48
Totally. It would probably also have to wait after
| |
374 stripped_destination_url = | |
375 GURL(search_provider_url->url_ref().ReplaceSearchTerms( | |
376 TemplateURLRef::SearchTermsArgs(search_terms))); | |
Peter Kasting
2012/10/19 22:49:33
In the original bug we proposed replacing the actu
Bart N.
2012/10/22 18:20:24
Yup, I'm totally aware of that, in fact it could h
beaudoin
2012/10/22 18:43:23
With the approach above we could maybe even recons
Bart N.
2012/10/22 19:19:42
Agreed. It would be clean and Google-agnostic.
| |
377 } | |
378 } | |
379 | |
364 // |replacements| keeps all the substitions we're going to make to | 380 // |replacements| keeps all the substitions we're going to make to |
365 // from {destination_url} to {stripped_destination_url}. |need_replacement| | 381 // from {destination_url} to {stripped_destination_url}. |need_replacement| |
366 // is a helper variable that helps us keep track of whether we need | 382 // is a helper variable that helps us keep track of whether we need |
367 // to apply the replacement. | 383 // to apply the replacement. |
368 bool needs_replacement = false; | 384 bool needs_replacement = false; |
369 GURL::Replacements replacements; | 385 GURL::Replacements replacements; |
370 | 386 |
371 // Remove the www. prefix from the host. | 387 // Remove the www. prefix from the host. |
372 static const char prefix[] = "www."; | 388 static const char prefix[] = "www."; |
373 static const size_t prefix_len = arraysize(prefix) - 1; | 389 static const size_t prefix_len = arraysize(prefix) - 1; |
374 std::string host = destination_url.host(); | 390 std::string host = stripped_destination_url.host(); |
375 if (host.compare(0, prefix_len, prefix) == 0) { | 391 if (host.compare(0, prefix_len, prefix) == 0) { |
376 host = host.substr(prefix_len); | 392 host = host.substr(prefix_len); |
377 replacements.SetHostStr(host); | 393 replacements.SetHostStr(host); |
378 needs_replacement = true; | 394 needs_replacement = true; |
379 } | 395 } |
380 | 396 |
381 // Replace https protocol with http protocol. | 397 // Replace https protocol with http protocol. |
382 if (stripped_destination_url.SchemeIs(chrome::kHttpsScheme)) { | 398 if (stripped_destination_url.SchemeIs(chrome::kHttpsScheme)) { |
383 replacements.SetScheme( | 399 replacements.SetScheme( |
384 chrome::kHttpScheme, | 400 chrome::kHttpScheme, |
385 url_parse::Component(0, strlen(chrome::kHttpScheme))); | 401 url_parse::Component(0, strlen(chrome::kHttpScheme))); |
386 needs_replacement = true; | 402 needs_replacement = true; |
387 } | 403 } |
388 | 404 |
389 if (needs_replacement) | 405 if (needs_replacement) |
390 stripped_destination_url = destination_url.ReplaceComponents(replacements); | 406 stripped_destination_url = stripped_destination_url.ReplaceComponents( |
407 replacements); | |
391 } | 408 } |
392 | 409 |
393 void AutocompleteMatch::GetKeywordUIState(Profile* profile, | 410 void AutocompleteMatch::GetKeywordUIState(Profile* profile, |
394 string16* keyword, | 411 string16* keyword, |
395 bool* is_keyword_hint) const { | 412 bool* is_keyword_hint) const { |
396 *is_keyword_hint = associated_keyword.get() != NULL; | 413 *is_keyword_hint = associated_keyword.get() != NULL; |
397 keyword->assign(*is_keyword_hint ? associated_keyword->keyword : | 414 keyword->assign(*is_keyword_hint ? associated_keyword->keyword : |
398 GetSubstitutingExplicitlyInvokedKeyword(profile)); | 415 GetSubstitutingExplicitlyInvokedKeyword(profile)); |
399 } | 416 } |
400 | 417 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 << " is unsorted in relation to last offset of " << last_offset | 479 << " is unsorted in relation to last offset of " << last_offset |
463 << ". Provider: " << provider_name << "."; | 480 << ". Provider: " << provider_name << "."; |
464 DCHECK_LT(i->offset, text.length()) | 481 DCHECK_LT(i->offset, text.length()) |
465 << " Classification of [" << i->offset << "," << text.length() | 482 << " Classification of [" << i->offset << "," << text.length() |
466 << "] is out of bounds for \"" << text << "\". Provider: " | 483 << "] is out of bounds for \"" << text << "\". Provider: " |
467 << provider_name << "."; | 484 << provider_name << "."; |
468 last_offset = i->offset; | 485 last_offset = i->offset; |
469 } | 486 } |
470 } | 487 } |
471 #endif | 488 #endif |
OLD | NEW |