OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 13 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
14 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 14 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
15 #include "chrome/browser/extensions/extension_service.h" | 15 #include "chrome/browser/extensions/extension_service.h" |
| 16 #include "chrome/browser/extensions/extension_system.h" |
16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
18 #include "chrome/browser/search_engines/template_url_service.h" | 19 #include "chrome/browser/search_engines/template_url_service.h" |
19 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
20 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
21 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
22 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
23 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
25 #include "net/base/net_util.h" | 26 #include "net/base/net_util.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 return string16(); | 169 return string16(); |
169 | 170 |
170 // Don't provide a keyword if it doesn't support replacement. | 171 // Don't provide a keyword if it doesn't support replacement. |
171 const TemplateURL* const template_url = | 172 const TemplateURL* const template_url = |
172 url_service->GetTemplateURLForKeyword(keyword); | 173 url_service->GetTemplateURLForKeyword(keyword); |
173 if (!template_url || !template_url->SupportsReplacement()) | 174 if (!template_url || !template_url->SupportsReplacement()) |
174 return string16(); | 175 return string16(); |
175 | 176 |
176 // Don't provide a keyword for inactive/disabled extension keywords. | 177 // Don't provide a keyword for inactive/disabled extension keywords. |
177 if (template_url->IsExtensionKeyword()) { | 178 if (template_url->IsExtensionKeyword()) { |
178 const extensions::Extension* extension = profile_->GetExtensionService()-> | 179 ExtensionService* extension_service = |
| 180 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 181 const extensions::Extension* extension = extension_service-> |
179 GetExtensionById(template_url->GetExtensionId(), false); | 182 GetExtensionById(template_url->GetExtensionId(), false); |
180 if (!extension || | 183 if (!extension || |
181 (profile_->IsOffTheRecord() && | 184 (profile_->IsOffTheRecord() && |
182 !profile_->GetExtensionService()->IsIncognitoEnabled(extension->id()))) | 185 !extension_service->IsIncognitoEnabled(extension->id()))) |
183 return string16(); | 186 return string16(); |
184 } | 187 } |
185 | 188 |
186 return keyword; | 189 return keyword; |
187 } | 190 } |
188 | 191 |
189 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( | 192 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
190 const string16& text, | 193 const string16& text, |
191 const string16& keyword, | 194 const string16& keyword, |
192 const AutocompleteInput& input) { | 195 const AutocompleteInput& input) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 !remaining_input.empty(), | 247 !remaining_input.empty(), |
245 &keyword_matches); | 248 &keyword_matches); |
246 | 249 |
247 for (std::vector<string16>::iterator i(keyword_matches.begin()); | 250 for (std::vector<string16>::iterator i(keyword_matches.begin()); |
248 i != keyword_matches.end(); ) { | 251 i != keyword_matches.end(); ) { |
249 const TemplateURL* template_url = model->GetTemplateURLForKeyword(*i); | 252 const TemplateURL* template_url = model->GetTemplateURLForKeyword(*i); |
250 | 253 |
251 // Prune any extension keywords that are disallowed in incognito mode (if | 254 // Prune any extension keywords that are disallowed in incognito mode (if |
252 // we're incognito), or disabled. | 255 // we're incognito), or disabled. |
253 if (profile_ && template_url->IsExtensionKeyword()) { | 256 if (profile_ && template_url->IsExtensionKeyword()) { |
254 ExtensionService* service = profile_->GetExtensionService(); | 257 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)-> |
| 258 extension_service(); |
255 const extensions::Extension* extension = service->GetExtensionById( | 259 const extensions::Extension* extension = service->GetExtensionById( |
256 template_url->GetExtensionId(), false); | 260 template_url->GetExtensionId(), false); |
257 bool enabled = | 261 bool enabled = |
258 extension && (!profile_->IsOffTheRecord() || | 262 extension && (!profile_->IsOffTheRecord() || |
259 service->IsIncognitoEnabled(extension->id())); | 263 service->IsIncognitoEnabled(extension->id())); |
260 if (!enabled) { | 264 if (!enabled) { |
261 i = keyword_matches.erase(i); | 265 i = keyword_matches.erase(i); |
262 continue; | 266 continue; |
263 } | 267 } |
264 } | 268 } |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 586 } |
583 | 587 |
584 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 588 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
585 if (!current_keyword_extension_id_.empty()) { | 589 if (!current_keyword_extension_id_.empty()) { |
586 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 590 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
587 profile_, current_keyword_extension_id_); | 591 profile_, current_keyword_extension_id_); |
588 | 592 |
589 current_keyword_extension_id_.clear(); | 593 current_keyword_extension_id_.clear(); |
590 } | 594 } |
591 } | 595 } |
OLD | NEW |