| 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/strings/string16.h" | 10 #include "base/strings/string16.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 14 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | 15 #include "chrome/browser/chrome_notification_types.h" |
| 16 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 16 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/extension_system.h" | 18 #include "chrome/browser/extensions/extension_system.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search_engines/template_url.h" | 21 #include "chrome/browser/search_engines/template_url.h" |
| 21 #include "chrome/browser/search_engines/template_url_service.h" | 22 #include "chrome/browser/search_engines/template_url_service.h" |
| 22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 23 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 24 #include "content/public/browser/notification_source.h" | 25 #include "content/public/browser/notification_source.h" |
| 25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 26 #include "net/base/escape.h" | 27 #include "net/base/escape.h" |
| 27 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 return string16(); | 198 return string16(); |
| 198 | 199 |
| 199 // Don't provide a keyword for inactive/disabled extension keywords. | 200 // Don't provide a keyword for inactive/disabled extension keywords. |
| 200 if (template_url->IsExtensionKeyword()) { | 201 if (template_url->IsExtensionKeyword()) { |
| 201 ExtensionService* extension_service = | 202 ExtensionService* extension_service = |
| 202 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 203 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 203 const extensions::Extension* extension = extension_service-> | 204 const extensions::Extension* extension = extension_service-> |
| 204 GetExtensionById(template_url->GetExtensionId(), false); | 205 GetExtensionById(template_url->GetExtensionId(), false); |
| 205 if (!extension || | 206 if (!extension || |
| 206 (profile_->IsOffTheRecord() && | 207 (profile_->IsOffTheRecord() && |
| 207 !extension_service->IsIncognitoEnabled(extension->id()))) | 208 !extension_util::IsIncognitoEnabled(extension->id(), |
| 209 extension_service))) |
| 208 return string16(); | 210 return string16(); |
| 209 } | 211 } |
| 210 | 212 |
| 211 return keyword; | 213 return keyword; |
| 212 } | 214 } |
| 213 | 215 |
| 214 AutocompleteMatch KeywordProvider::CreateVerbatimMatch( | 216 AutocompleteMatch KeywordProvider::CreateVerbatimMatch( |
| 215 const string16& text, | 217 const string16& text, |
| 216 const string16& keyword, | 218 const string16& keyword, |
| 217 const AutocompleteInput& input) { | 219 const AutocompleteInput& input) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 276 |
| 275 // Prune any extension keywords that are disallowed in incognito mode (if | 277 // Prune any extension keywords that are disallowed in incognito mode (if |
| 276 // we're incognito), or disabled. | 278 // we're incognito), or disabled. |
| 277 if (profile_ && template_url->IsExtensionKeyword()) { | 279 if (profile_ && template_url->IsExtensionKeyword()) { |
| 278 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)-> | 280 ExtensionService* service = extensions::ExtensionSystem::Get(profile_)-> |
| 279 extension_service(); | 281 extension_service(); |
| 280 const extensions::Extension* extension = | 282 const extensions::Extension* extension = |
| 281 service->GetExtensionById(template_url->GetExtensionId(), false); | 283 service->GetExtensionById(template_url->GetExtensionId(), false); |
| 282 bool enabled = | 284 bool enabled = |
| 283 extension && (!profile_->IsOffTheRecord() || | 285 extension && (!profile_->IsOffTheRecord() || |
| 284 service->IsIncognitoEnabled(extension->id())); | 286 extension_util::IsIncognitoEnabled(extension->id(), |
| 287 service)); |
| 285 if (!enabled) { | 288 if (!enabled) { |
| 286 i = matches.erase(i); | 289 i = matches.erase(i); |
| 287 continue; | 290 continue; |
| 288 } | 291 } |
| 289 } | 292 } |
| 290 | 293 |
| 291 // Prune any substituting keywords if there is no substitution. | 294 // Prune any substituting keywords if there is no substitution. |
| 292 if (template_url->SupportsReplacement() && remaining_input.empty() && | 295 if (template_url->SupportsReplacement() && remaining_input.empty() && |
| 293 !input.allow_exact_keyword_match()) { | 296 !input.allow_exact_keyword_match()) { |
| 294 i = matches.erase(i); | 297 i = matches.erase(i); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 } | 630 } |
| 628 | 631 |
| 629 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 632 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
| 630 if (!current_keyword_extension_id_.empty()) { | 633 if (!current_keyword_extension_id_.empty()) { |
| 631 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 634 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
| 632 profile_, current_keyword_extension_id_); | 635 profile_, current_keyword_extension_id_); |
| 633 | 636 |
| 634 current_keyword_extension_id_.clear(); | 637 current_keyword_extension_id_.clear(); |
| 635 } | 638 } |
| 636 } | 639 } |
| OLD | NEW |