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 | |
183 // we're incognito), or disabled. | |
184 for (std::vector<string16>::iterator i(keyword_matches.begin()); | 182 for (std::vector<string16>::iterator i(keyword_matches.begin()); |
185 i != keyword_matches.end(); ) { | 183 i != keyword_matches.end(); ) { |
186 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); | 184 const TemplateURL* template_url(model->GetTemplateURLForKeyword(*i)); |
| 185 |
| 186 // Prune any extension keywords that are disallowed in incognito mode (if |
| 187 // we're incognito), or disabled. |
187 if (profile_ && | 188 if (profile_ && |
188 input.matches_requested() == AutocompleteInput::ALL_MATCHES && | 189 input.matches_requested() == AutocompleteInput::ALL_MATCHES && |
189 template_url->IsExtensionKeyword()) { | 190 template_url->IsExtensionKeyword()) { |
190 ExtensionService* service = profile_->GetExtensionService(); | 191 ExtensionService* service = profile_->GetExtensionService(); |
191 const Extension* extension = service->GetExtensionById( | 192 const Extension* extension = service->GetExtensionById( |
192 template_url->GetExtensionId(), false); | 193 template_url->GetExtensionId(), false); |
193 bool enabled = | 194 bool enabled = |
194 extension && (!profile_->IsOffTheRecord() || | 195 extension && (!profile_->IsOffTheRecord() || |
195 service->IsIncognitoEnabled(extension->id())); | 196 service->IsIncognitoEnabled(extension->id())); |
196 if (!enabled) { | 197 if (!enabled) { |
197 i = keyword_matches.erase(i); | 198 i = keyword_matches.erase(i); |
198 continue; | 199 continue; |
199 } | 200 } |
200 } | 201 } |
| 202 |
| 203 // Prune any substituting keywords if there is no substitution. |
| 204 if (TemplateURL::SupportsReplacement(template_url) && |
| 205 !input.allow_exact_keyword_match()) { |
| 206 i = keyword_matches.erase(i); |
| 207 continue; |
| 208 } |
201 ++i; | 209 ++i; |
202 } | 210 } |
203 if (keyword_matches.empty()) | 211 if (keyword_matches.empty()) |
204 return; | 212 return; |
205 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); | 213 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); |
206 | 214 |
207 // Limit to one exact or three inexact matches, and mark them up for display | 215 // Limit to one exact or three inexact matches, and mark them up for display |
208 // in the autocomplete popup. | 216 // in the autocomplete popup. |
209 // Any exact match is going to be the highest quality match, and thus at the | 217 // Any exact match is going to be the highest quality match, and thus at the |
210 // front of our vector. | 218 // front of our vector. |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 541 } |
534 | 542 |
535 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 543 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
536 if (!current_keyword_extension_id_.empty()) { | 544 if (!current_keyword_extension_id_.empty()) { |
537 ExtensionOmniboxEventRouter::OnInputCancelled( | 545 ExtensionOmniboxEventRouter::OnInputCancelled( |
538 profile_, current_keyword_extension_id_); | 546 profile_, current_keyword_extension_id_); |
539 | 547 |
540 current_keyword_extension_id_.clear(); | 548 current_keyword_extension_id_.clear(); |
541 } | 549 } |
542 } | 550 } |
OLD | NEW |