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_contents_provider.h" | 5 #include "chrome/browser/autocomplete/history_contents_provider.h" |
6 | 6 |
7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
10 #include "chrome/browser/history/query_parser.h" | 10 #include "chrome/browser/history/query_parser.h" |
11 #include "chrome/browser/profile.h" | 11 #include "chrome/browser/profile.h" |
| 12 #include "chrome/common/url_constants.h" |
| 13 #include "googleurl/src/url_util.h" |
12 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
13 | 15 |
14 using base::TimeTicks; | 16 using base::TimeTicks; |
15 | 17 |
16 namespace { | 18 namespace { |
17 | 19 |
18 // Number of days to search for full text results. The longer this is, the more | 20 // Number of days to search for full text results. The longer this is, the more |
19 // time it will take. | 21 // time it will take. |
20 const int kDaysToSearch = 30; | 22 const int kDaysToSearch = 30; |
21 | 23 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 (((input.type() == AutocompleteInput::REQUESTED_URL) || | 67 (((input.type() == AutocompleteInput::REQUESTED_URL) || |
66 (input.type() == AutocompleteInput::UNKNOWN)) && | 68 (input.type() == AutocompleteInput::UNKNOWN)) && |
67 (input.text().find('.') != std::wstring::npos))) { | 69 (input.text().find('.') != std::wstring::npos))) { |
68 Stop(); | 70 Stop(); |
69 return; | 71 return; |
70 } | 72 } |
71 | 73 |
72 // Change input type and reset relevance counters, so matches will be marked | 74 // Change input type and reset relevance counters, so matches will be marked |
73 // up properly. | 75 // up properly. |
74 input_type_ = input.type(); | 76 input_type_ = input.type(); |
| 77 trim_http_ = !url_util::FindAndCompareScheme(WideToUTF8(input.text()), |
| 78 chrome::kHttpScheme, NULL); |
75 star_title_count_ = star_contents_count_ = title_count_ = contents_count_ = 0; | 79 star_title_count_ = star_contents_count_ = title_count_ = contents_count_ = 0; |
76 | 80 |
77 // Decide what to do about any previous query/results. | 81 // Decide what to do about any previous query/results. |
78 if (!minimal_changes) { | 82 if (!minimal_changes) { |
79 // Any in-progress request is irrelevant, cancel it. | 83 // Any in-progress request is irrelevant, cancel it. |
80 Stop(); | 84 Stop(); |
81 } else if (have_results_) { | 85 } else if (have_results_) { |
82 // We finished the previous query and still have its results. Mark them up | 86 // We finished the previous query and still have its results. Mark them up |
83 // again for the new input. | 87 // again for the new input. |
84 ConvertResults(); | 88 ConvertResults(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 AutocompleteMatch HistoryContentsProvider::ResultToMatch( | 195 AutocompleteMatch HistoryContentsProvider::ResultToMatch( |
192 const history::URLResult& result, | 196 const history::URLResult& result, |
193 int score) { | 197 int score) { |
194 // TODO(sky): if matched title highlight matching words in title. | 198 // TODO(sky): if matched title highlight matching words in title. |
195 // Also show star in popup. | 199 // Also show star in popup. |
196 AutocompleteMatch match(this, score, false, MatchInTitle(result) ? | 200 AutocompleteMatch match(this, score, false, MatchInTitle(result) ? |
197 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); | 201 AutocompleteMatch::HISTORY_TITLE : AutocompleteMatch::HISTORY_BODY); |
198 match.fill_into_edit = StringForURLDisplay(result.url(), true); | 202 match.fill_into_edit = StringForURLDisplay(result.url(), true); |
199 match.destination_url = result.url(); | 203 match.destination_url = result.url(); |
200 match.contents = match.fill_into_edit; | 204 match.contents = match.fill_into_edit; |
| 205 if (trim_http_) |
| 206 TrimHttpPrefix(&match.contents); |
201 match.contents_class.push_back( | 207 match.contents_class.push_back( |
202 ACMatchClassification(0, ACMatchClassification::URL)); | 208 ACMatchClassification(0, ACMatchClassification::URL)); |
203 match.description = result.title(); | 209 match.description = result.title(); |
204 match.starred = | 210 match.starred = |
205 (profile_->GetBookmarkModel() && | 211 (profile_->GetBookmarkModel() && |
206 profile_->GetBookmarkModel()->IsBookmarked(result.url())); | 212 profile_->GetBookmarkModel()->IsBookmarked(result.url())); |
207 | 213 |
208 ClassifyDescription(result, &match); | 214 ClassifyDescription(result, &match); |
209 return match; | 215 return match; |
210 } | 216 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", | 287 UMA_HISTOGRAM_TIMES("Omnibox.QueryBookmarksTime", |
282 TimeTicks::Now() - start_time); | 288 TimeTicks::Now() - start_time); |
283 } | 289 } |
284 | 290 |
285 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( | 291 void HistoryContentsProvider::AddBookmarkTitleMatchToResults( |
286 const bookmark_utils::TitleMatch& match) { | 292 const bookmark_utils::TitleMatch& match) { |
287 history::URLResult url_result(match.node->GetURL(), match.match_positions); | 293 history::URLResult url_result(match.node->GetURL(), match.match_positions); |
288 url_result.set_title(match.node->GetTitle()); | 294 url_result.set_title(match.node->GetTitle()); |
289 results_.AppendURLBySwapping(&url_result); | 295 results_.AppendURLBySwapping(&url_result); |
290 } | 296 } |
OLD | NEW |