| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/history_url_provider.h" | 5 #include "chrome/browser/autocomplete/history_url_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/histogram.h" | 10 #include "base/histogram.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "chrome/browser/history/history.h" | 13 #include "chrome/browser/history/history.h" |
| 14 #include "chrome/browser/history/history_backend.h" | 14 #include "chrome/browser/history/history_backend.h" |
| 15 #include "chrome/browser/history/history_database.h" | 15 #include "chrome/browser/history/history_database.h" |
| 16 #include "chrome/browser/net/url_fixer_upper.h" | 16 #include "chrome/browser/net/url_fixer_upper.h" |
| 17 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 18 #include "chrome/common/gfx/text_elider.h" | 18 #include "chrome/common/gfx/text_elider.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/common/pref_service.h" | 20 #include "chrome/common/pref_service.h" |
| 21 #include "chrome/common/sqlite_utils.h" | 21 #include "chrome/common/sqlite_utils.h" |
| 22 #include "chrome/common/url_constants.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 23 #include "googleurl/src/url_parse.h" | 24 #include "googleurl/src/url_parse.h" |
| 24 #include "googleurl/src/url_util.h" | 25 #include "googleurl/src/url_util.h" |
| 25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
| 26 | 27 |
| 27 using base::Time; | 28 using base::Time; |
| 28 using base::TimeDelta; | 29 using base::TimeDelta; |
| 29 using base::TimeTicks; | 30 using base::TimeTicks; |
| 30 | 31 |
| 31 HistoryURLProviderParams::HistoryURLProviderParams( | 32 HistoryURLProviderParams::HistoryURLProviderParams( |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 // Fixup and canonicalize user input. | 338 // Fixup and canonicalize user input. |
| 338 const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input), | 339 const GURL canonical_gurl(URLFixerUpper::FixupURL(WideToUTF8(input), |
| 339 std::string())); | 340 std::string())); |
| 340 std::wstring output(UTF8ToWide(canonical_gurl.possibly_invalid_spec())); | 341 std::wstring output(UTF8ToWide(canonical_gurl.possibly_invalid_spec())); |
| 341 if (output.empty()) | 342 if (output.empty()) |
| 342 return input; // This probably won't happen, but there are no guarantees. | 343 return input; // This probably won't happen, but there are no guarantees. |
| 343 | 344 |
| 344 // Don't prepend a scheme when the user didn't have one. Since the fixer | 345 // Don't prepend a scheme when the user didn't have one. Since the fixer |
| 345 // upper only prepends the "http" scheme, that's all we need to check for. | 346 // upper only prepends the "http" scheme, that's all we need to check for. |
| 346 url_parse::Component scheme; | 347 url_parse::Component scheme; |
| 347 if (canonical_gurl.SchemeIs("http") && | 348 if (canonical_gurl.SchemeIs(chrome::kHttpScheme) && |
| 348 !url_util::FindAndCompareScheme(WideToUTF8(input), "http", &scheme)) | 349 !url_util::FindAndCompareScheme(WideToUTF8(input), chrome::kHttpScheme, |
| 350 &scheme)) |
| 349 TrimHttpPrefix(&output); | 351 TrimHttpPrefix(&output); |
| 350 | 352 |
| 351 // Make the number of trailing slashes on the output exactly match the input. | 353 // Make the number of trailing slashes on the output exactly match the input. |
| 352 // Examples of why not doing this would matter: | 354 // Examples of why not doing this would matter: |
| 353 // * The user types "a" and has this fixed up to "a/". Now no other sites | 355 // * The user types "a" and has this fixed up to "a/". Now no other sites |
| 354 // beginning with "a" will match. | 356 // beginning with "a" will match. |
| 355 // * The user types "file:" and has this fixed up to "file://". Now inline | 357 // * The user types "file:" and has this fixed up to "file://". Now inline |
| 356 // autocomplete will append too few slashes, resulting in e.g. "file:/b..." | 358 // autocomplete will append too few slashes, resulting in e.g. "file:/b..." |
| 357 // instead of "file:///b..." | 359 // instead of "file:///b..." |
| 358 // * The user types "http:/" and has this fixed up to "http:". Now inline | 360 // * The user types "http:/" and has this fixed up to "http:". Now inline |
| (...skipping 14 matching lines...) Expand all Loading... |
| 373 output.append(num_input_slashes - num_output_slashes, '/'); | 375 output.append(num_input_slashes - num_output_slashes, '/'); |
| 374 else if (num_output_slashes > num_input_slashes) | 376 else if (num_output_slashes > num_input_slashes) |
| 375 output.erase(output.length() - num_output_slashes + num_input_slashes); | 377 output.erase(output.length() - num_output_slashes + num_input_slashes); |
| 376 | 378 |
| 377 return output; | 379 return output; |
| 378 } | 380 } |
| 379 | 381 |
| 380 // static | 382 // static |
| 381 size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) { | 383 size_t HistoryURLProvider::TrimHttpPrefix(std::wstring* url) { |
| 382 url_parse::Component scheme; | 384 url_parse::Component scheme; |
| 383 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), "http", &scheme)) | 385 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, |
| 386 &scheme)) |
| 384 return 0; // Not "http". | 387 return 0; // Not "http". |
| 385 | 388 |
| 386 // Erase scheme plus up to two slashes. | 389 // Erase scheme plus up to two slashes. |
| 387 size_t prefix_len = scheme.end() + 1; // "http:" | 390 size_t prefix_len = scheme.end() + 1; // "http:" |
| 388 const size_t after_slashes = std::min(url->length(), | 391 const size_t after_slashes = std::min(url->length(), |
| 389 static_cast<size_t>(scheme.end() + 3)); | 392 static_cast<size_t>(scheme.end() + 3)); |
| 390 while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/')) | 393 while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/')) |
| 391 ++prefix_len; | 394 ++prefix_len; |
| 392 if (prefix_len == url->length()) | 395 if (prefix_len == url->length()) |
| 393 url->clear(); | 396 url->clear(); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 matches_.clear(); | 589 matches_.clear(); |
| 587 | 590 |
| 588 if ((input.type() != AutocompleteInput::UNKNOWN) && | 591 if ((input.type() != AutocompleteInput::UNKNOWN) && |
| 589 (input.type() != AutocompleteInput::REQUESTED_URL) && | 592 (input.type() != AutocompleteInput::REQUESTED_URL) && |
| 590 (input.type() != AutocompleteInput::URL)) | 593 (input.type() != AutocompleteInput::URL)) |
| 591 return; | 594 return; |
| 592 | 595 |
| 593 // Create a match for exactly what the user typed. This will always be one | 596 // Create a match for exactly what the user typed. This will always be one |
| 594 // of the top two results we return. | 597 // of the top two results we return. |
| 595 const bool trim_http = !url_util::FindAndCompareScheme( | 598 const bool trim_http = !url_util::FindAndCompareScheme( |
| 596 WideToUTF8(input.text()), "http", NULL); | 599 WideToUTF8(input.text()), chrome::kHttpScheme, NULL); |
| 597 SuggestExactInput(input, trim_http); | 600 SuggestExactInput(input, trim_http); |
| 598 | 601 |
| 599 // We'll need the history service to run both passes, so try to obtain it. | 602 // We'll need the history service to run both passes, so try to obtain it. |
| 600 HistoryService* const history_service = profile_ ? | 603 HistoryService* const history_service = profile_ ? |
| 601 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : history_service_; | 604 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : history_service_; |
| 602 if (!history_service) | 605 if (!history_service) |
| 603 return; | 606 return; |
| 604 | 607 |
| 605 // Create the data structure for the autocomplete passes. We'll save this off | 608 // Create the data structure for the autocomplete passes. We'll save this off |
| 606 // onto the |params_| member for later deletion below if we need to run pass | 609 // onto the |params_| member for later deletion below if we need to run pass |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 history_match.input_location - offset, params->input.text().length(), | 831 history_match.input_location - offset, params->input.text().length(), |
| 829 match.contents.length(), ACMatchClassification::URL, | 832 match.contents.length(), ACMatchClassification::URL, |
| 830 &match.contents_class); | 833 &match.contents_class); |
| 831 match.description = info.title(); | 834 match.description = info.title(); |
| 832 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), | 835 AutocompleteMatch::ClassifyMatchInString(params->input.text(), info.title(), |
| 833 ACMatchClassification::NONE, | 836 ACMatchClassification::NONE, |
| 834 &match.description_class); | 837 &match.description_class); |
| 835 | 838 |
| 836 return match; | 839 return match; |
| 837 } | 840 } |
| OLD | NEW |