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/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "chrome/browser/autocomplete/history_url_provider.h" | 12 #include "chrome/browser/autocomplete/history_url_provider.h" |
13 #include "chrome/browser/autocomplete/history_contents_provider.h" | 13 #include "chrome/browser/autocomplete/history_contents_provider.h" |
14 #include "chrome/browser/autocomplete/keyword_provider.h" | 14 #include "chrome/browser/autocomplete/keyword_provider.h" |
15 #include "chrome/browser/autocomplete/search_provider.h" | 15 #include "chrome/browser/autocomplete/search_provider.h" |
16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
17 #include "chrome/browser/dom_ui/history_ui.h" | 17 #include "chrome/browser/dom_ui/history_ui.h" |
18 #include "chrome/browser/external_protocol_handler.h" | 18 #include "chrome/browser/external_protocol_handler.h" |
19 #include "chrome/browser/net/url_fixer_upper.h" | 19 #include "chrome/browser/net/url_fixer_upper.h" |
20 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
21 #include "chrome/common/notification_service.h" | 21 #include "chrome/common/notification_service.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
24 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
26 #include "googleurl/src/url_canon_ip.h" | 26 #include "googleurl/src/url_canon_ip.h" |
| 27 #include "googleurl/src/url_util.h" |
27 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
29 #include "net/base/registry_controlled_domain.h" | 30 #include "net/base/registry_controlled_domain.h" |
30 #include "net/url_request/url_request.h" | 31 #include "net/url_request/url_request.h" |
31 | 32 |
32 using base::TimeDelta; | 33 using base::TimeDelta; |
33 | 34 |
34 // AutocompleteInput ---------------------------------------------------------- | 35 // AutocompleteInput ---------------------------------------------------------- |
35 | 36 |
36 AutocompleteInput::AutocompleteInput(const std::wstring& text, | 37 AutocompleteInput::AutocompleteInput(const std::wstring& text, |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 AutocompleteProvider::~AutocompleteProvider() { | 468 AutocompleteProvider::~AutocompleteProvider() { |
468 Stop(); | 469 Stop(); |
469 } | 470 } |
470 | 471 |
471 void AutocompleteProvider::SetProfile(Profile* profile) { | 472 void AutocompleteProvider::SetProfile(Profile* profile) { |
472 DCHECK(profile); | 473 DCHECK(profile); |
473 Stop(); // It makes no sense to continue running a query from an old profile. | 474 Stop(); // It makes no sense to continue running a query from an old profile. |
474 profile_ = profile; | 475 profile_ = profile; |
475 } | 476 } |
476 | 477 |
| 478 // static |
| 479 size_t AutocompleteProvider::TrimHttpPrefix(std::wstring* url) { |
| 480 url_parse::Component scheme; |
| 481 if (!url_util::FindAndCompareScheme(WideToUTF8(*url), chrome::kHttpScheme, |
| 482 &scheme)) |
| 483 return 0; // Not "http". |
| 484 |
| 485 // Erase scheme plus up to two slashes. |
| 486 size_t prefix_len = scheme.end() + 1; // "http:" |
| 487 const size_t after_slashes = std::min(url->length(), |
| 488 static_cast<size_t>(scheme.end() + 3)); |
| 489 while ((prefix_len < after_slashes) && ((*url)[prefix_len] == L'/')) |
| 490 ++prefix_len; |
| 491 if (prefix_len == url->length()) |
| 492 url->clear(); |
| 493 else |
| 494 url->erase(url->begin(), url->begin() + prefix_len); |
| 495 return prefix_len; |
| 496 } |
| 497 |
477 void AutocompleteProvider::UpdateStarredStateOfMatches() { | 498 void AutocompleteProvider::UpdateStarredStateOfMatches() { |
478 if (matches_.empty()) | 499 if (matches_.empty()) |
479 return; | 500 return; |
480 | 501 |
481 if (!profile_) | 502 if (!profile_) |
482 return; | 503 return; |
483 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); | 504 BookmarkModel* bookmark_model = profile_->GetBookmarkModel(); |
484 if (!bookmark_model || !bookmark_model->IsLoaded()) | 505 if (!bookmark_model || !bookmark_model->IsLoaded()) |
485 return; | 506 return; |
486 | 507 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 match.contents_class.push_back( | 889 match.contents_class.push_back( |
869 ACMatchClassification(keyword_offset + input_.text().size(), | 890 ACMatchClassification(keyword_offset + input_.text().size(), |
870 ACMatchClassification::NONE)); | 891 ACMatchClassification::NONE)); |
871 } | 892 } |
872 match.destination_url = | 893 match.destination_url = |
873 HistoryUI::GetHistoryURLWithSearchText(input_.text()); | 894 HistoryUI::GetHistoryURLWithSearchText(input_.text()); |
874 match.transition = PageTransition::AUTO_BOOKMARK; | 895 match.transition = PageTransition::AUTO_BOOKMARK; |
875 match.provider = history_contents_provider_; | 896 match.provider = history_contents_provider_; |
876 latest_result_.AddMatch(match); | 897 latest_result_.AddMatch(match); |
877 } | 898 } |
OLD | NEW |