OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/keyword_provider.h" | 5 #include "chrome/browser/autocomplete/keyword_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string16.h" | 10 #include "base/string16.h" |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 // don't bother. | 172 // don't bother. |
173 // | 173 // |
174 // TODO(pkasting): http://b/893701 We should remember the user's use of a | 174 // TODO(pkasting): http://b/893701 We should remember the user's use of a |
175 // search query both from the autocomplete popup and from web pages | 175 // search query both from the autocomplete popup and from web pages |
176 // themselves. | 176 // themselves. |
177 std::vector<string16> keyword_matches; | 177 std::vector<string16> keyword_matches; |
178 model->FindMatchingKeywords(keyword, | 178 model->FindMatchingKeywords(keyword, |
179 !remaining_input.empty(), | 179 !remaining_input.empty(), |
180 &keyword_matches); | 180 &keyword_matches); |
181 | 181 |
182 // Prune any extension keywords that are disallowed in incognito mode (if | 182 // Prune any extension keywords that are disallowed in incognito mode (if |
Peter Kasting
2011/04/01 00:09:09
Nit: Move this comment inside the loop.
| |
183 // we're incognito), or disabled. | 183 // we're incognito), or disabled. |
184 for (std::vector<string16>::iterator i(keyword_matches.begin()); | 184 for (std::vector<string16>::iterator i(keyword_matches.begin()); |
185 i != keyword_matches.end(); ) { | 185 i != keyword_matches.end(); ) { |
186 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); | 186 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); |
187 if (profile_ && | 187 if (profile_ && |
188 !input.synchronous_only() && template_url->IsExtensionKeyword()) { | 188 !input.synchronous_only() && template_url->IsExtensionKeyword()) { |
189 ExtensionService* service = profile_->GetExtensionService(); | 189 ExtensionService* service = profile_->GetExtensionService(); |
190 const Extension* extension = service->GetExtensionById( | 190 const Extension* extension = service->GetExtensionById( |
191 template_url->GetExtensionId(), false); | 191 template_url->GetExtensionId(), false); |
192 bool enabled = extension && (!profile_->IsOffTheRecord() || | 192 bool enabled = extension && (!profile_->IsOffTheRecord() || |
193 service->IsIncognitoEnabled(extension)); | 193 service->IsIncognitoEnabled(extension)); |
194 if (!enabled) { | 194 if (!enabled) { |
195 i = keyword_matches.erase(i); | 195 i = keyword_matches.erase(i); |
196 continue; | 196 continue; |
197 } | 197 } |
198 } | 198 } |
199 | |
200 // Prune any substituting keywords if there is no substitution. | |
201 if (TemplateURL::SupportsReplacement(template_url) && | |
202 !input.allow_exact_keyword_match()) { | |
203 i = keyword_matches.erase(i); | |
204 continue; | |
205 } | |
199 ++i; | 206 ++i; |
200 } | 207 } |
201 if (keyword_matches.empty()) | 208 if (keyword_matches.empty()) |
202 return; | 209 return; |
203 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); | 210 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); |
204 | 211 |
205 // Limit to one exact or three inexact matches, and mark them up for display | 212 // Limit to one exact or three inexact matches, and mark them up for display |
206 // in the autocomplete popup. | 213 // in the autocomplete popup. |
207 // Any exact match is going to be the highest quality match, and thus at the | 214 // Any exact match is going to be the highest quality match, and thus at the |
208 // front of our vector. | 215 // front of our vector. |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 } | 537 } |
531 | 538 |
532 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 539 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
533 if (!current_keyword_extension_id_.empty()) { | 540 if (!current_keyword_extension_id_.empty()) { |
534 ExtensionOmniboxEventRouter::OnInputCancelled( | 541 ExtensionOmniboxEventRouter::OnInputCancelled( |
535 profile_, current_keyword_extension_id_); | 542 profile_, current_keyword_extension_id_); |
536 | 543 |
537 current_keyword_extension_id_.clear(); | 544 current_keyword_extension_id_.clear(); |
538 } | 545 } |
539 } | 546 } |
OLD | NEW |