| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/extensions/extension_omnibox_api.h" | 13 #include "chrome/browser/extensions/extension_omnibox_api.h" |
| 14 #include "chrome/browser/extensions/extensions_service.h" | 14 #include "chrome/browser/extensions/extensions_service.h" |
| 15 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
| 16 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 17 #include "chrome/browser/search_engines/template_url_model.h" | 17 #include "chrome/browser/search_engines/template_url_model.h" |
| 18 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "net/base/escape.h" | 20 #include "net/base/escape.h" |
| 21 #include "net/base/net_util.h" | 21 #include "net/base/net_util.h" |
| 22 | 22 |
| 23 // Helper functor for Start(), for ending keyword mode unless explicitly told | 23 // Helper functor for Start(), for ending keyword mode unless explicitly told |
| 24 // otherwise. | 24 // otherwise. |
| 25 class KeywordProvider::ScopedEndExtensionKeywordMode { | 25 class KeywordProvider::ScopedEndExtensionKeywordMode { |
| 26 public: | 26 public: |
| 27 ScopedEndExtensionKeywordMode(KeywordProvider* provider) | 27 explicit ScopedEndExtensionKeywordMode(KeywordProvider* provider) |
| 28 : provider_(provider) { } | 28 : provider_(provider) { } |
| 29 ~ScopedEndExtensionKeywordMode() { | 29 ~ScopedEndExtensionKeywordMode() { |
| 30 if (provider_) | 30 if (provider_) |
| 31 provider_->MaybeEndExtensionKeywordMode(); | 31 provider_->MaybeEndExtensionKeywordMode(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void StayInKeywordMode() { | 34 void StayInKeywordMode() { |
| 35 provider_ = NULL; | 35 provider_ = NULL; |
| 36 } | 36 } |
| 37 private: | 37 private: |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 if (keyword_matches.empty()) | 170 if (keyword_matches.empty()) |
| 171 return; | 171 return; |
| 172 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); | 172 std::sort(keyword_matches.begin(), keyword_matches.end(), CompareQuality()); |
| 173 | 173 |
| 174 // Limit to one exact or three inexact matches, and mark them up for display | 174 // Limit to one exact or three inexact matches, and mark them up for display |
| 175 // in the autocomplete popup. | 175 // in the autocomplete popup. |
| 176 // Any exact match is going to be the highest quality match, and thus at the | 176 // Any exact match is going to be the highest quality match, and thus at the |
| 177 // front of our vector. | 177 // front of our vector. |
| 178 if (keyword_matches.front() == keyword) { | 178 if (keyword_matches.front() == keyword) { |
| 179 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); | 179 const TemplateURL* template_url(model->GetTemplateURLForKeyword(keyword)); |
| 180 // TODO(pkasting): We should probably check that if the user explicitly |
| 181 // typed a scheme, that scheme matches the one in |template_url|. |
| 182 |
| 180 if (profile_ && | 183 if (profile_ && |
| 181 !input.synchronous_only() && template_url->IsExtensionKeyword()) { | 184 !input.synchronous_only() && template_url->IsExtensionKeyword()) { |
| 182 // If this extension keyword is disabled, make sure we don't add any | 185 // If this extension keyword is disabled, make sure we don't add any |
| 183 // matches (including the synchronous one below). | 186 // matches (including the synchronous one below). |
| 184 ExtensionsService* service = profile_->GetExtensionsService(); | 187 ExtensionsService* service = profile_->GetExtensionsService(); |
| 185 Extension* extension = service->GetExtensionById( | 188 Extension* extension = service->GetExtensionById( |
| 186 template_url->GetExtensionId(), false); | 189 template_url->GetExtensionId(), false); |
| 187 bool enabled = extension && (!profile_->IsOffTheRecord() || | 190 bool enabled = extension && (!profile_->IsOffTheRecord() || |
| 188 service->IsIncognitoEnabled(extension)); | 191 service->IsIncognitoEnabled(extension)); |
| 189 if (!enabled) | 192 if (!enabled) |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 468 } |
| 466 | 469 |
| 467 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 470 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
| 468 if (!current_keyword_extension_id_.empty()) { | 471 if (!current_keyword_extension_id_.empty()) { |
| 469 ExtensionOmniboxEventRouter::OnInputCancelled( | 472 ExtensionOmniboxEventRouter::OnInputCancelled( |
| 470 profile_, current_keyword_extension_id_); | 473 profile_, current_keyword_extension_id_); |
| 471 | 474 |
| 472 current_keyword_extension_id_.clear(); | 475 current_keyword_extension_id_.clear(); |
| 473 } | 476 } |
| 474 } | 477 } |
| OLD | NEW |