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_util.h" | 18 #include "chrome/browser/extensions/extension_util.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/search_engines/template_url.h" | 20 #include "chrome/browser/search_engines/template_url.h" |
21 #include "chrome/browser/search_engines/template_url_service.h" | 21 #include "chrome/browser/search_engines/template_url_service.h" |
22 #include "chrome/browser/search_engines/template_url_service_factory.h" | 22 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 23 #include "components/metrics/proto/omnibox_input_type.pb.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 "extensions/browser/extension_system.h" | 26 #include "extensions/browser/extension_system.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
28 #include "net/base/net_util.h" | 29 #include "net/base/net_util.h" |
29 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
30 | 31 |
31 namespace omnibox_api = extensions::api::omnibox; | 32 namespace omnibox_api = extensions::api::omnibox; |
32 | 33 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 done_ = true; | 380 done_ = true; |
380 MaybeEndExtensionKeywordMode(); | 381 MaybeEndExtensionKeywordMode(); |
381 } | 382 } |
382 | 383 |
383 KeywordProvider::~KeywordProvider() {} | 384 KeywordProvider::~KeywordProvider() {} |
384 | 385 |
385 // static | 386 // static |
386 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, | 387 bool KeywordProvider::ExtractKeywordFromInput(const AutocompleteInput& input, |
387 base::string16* keyword, | 388 base::string16* keyword, |
388 base::string16* remaining_input) { | 389 base::string16* remaining_input) { |
389 if ((input.type() == AutocompleteInput::INVALID) || | 390 if ((input.type() == metrics::OmniboxInputType::INVALID) || |
390 (input.type() == AutocompleteInput::FORCED_QUERY)) | 391 (input.type() == metrics::OmniboxInputType::FORCED_QUERY)) |
391 return false; | 392 return false; |
392 | 393 |
393 *keyword = TemplateURLService::CleanUserInputKeyword( | 394 *keyword = TemplateURLService::CleanUserInputKeyword( |
394 SplitKeywordFromInput(input.text(), true, remaining_input)); | 395 SplitKeywordFromInput(input.text(), true, remaining_input)); |
395 return !keyword->empty(); | 396 return !keyword->empty(); |
396 } | 397 } |
397 | 398 |
398 // static | 399 // static |
399 int KeywordProvider::CalculateRelevance(AutocompleteInput::Type type, | 400 int KeywordProvider::CalculateRelevance(metrics::OmniboxInputType::Type type, |
400 bool complete, | 401 bool complete, |
401 bool supports_replacement, | 402 bool supports_replacement, |
402 bool prefer_keyword, | 403 bool prefer_keyword, |
403 bool allow_exact_keyword_match) { | 404 bool allow_exact_keyword_match) { |
404 // This function is responsible for scoring suggestions of keywords | 405 // This function is responsible for scoring suggestions of keywords |
405 // themselves and the suggestion of the verbatim query on an | 406 // themselves and the suggestion of the verbatim query on an |
406 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim() | 407 // extension keyword. SearchProvider::CalculateRelevanceForKeywordVerbatim() |
407 // scores verbatim query suggestions for non-extension keywords. | 408 // scores verbatim query suggestions for non-extension keywords. |
408 // These two functions are currently in sync, but there's no reason | 409 // These two functions are currently in sync, but there's no reason |
409 // we couldn't decide in the future to score verbatim matches | 410 // we couldn't decide in the future to score verbatim matches |
410 // differently for extension and non-extension keywords. If you | 411 // differently for extension and non-extension keywords. If you |
411 // make such a change, however, you should update this comment to | 412 // make such a change, however, you should update this comment to |
412 // describe it, so it's clear why the functions diverge. | 413 // describe it, so it's clear why the functions diverge. |
413 if (!complete) | 414 if (!complete) |
414 return (type == AutocompleteInput::URL) ? 700 : 450; | 415 return (type == metrics::OmniboxInputType::URL) ? 700 : 450; |
415 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) | 416 if (!supports_replacement || (allow_exact_keyword_match && prefer_keyword)) |
416 return 1500; | 417 return 1500; |
417 return (allow_exact_keyword_match && (type == AutocompleteInput::QUERY)) ? | 418 return (allow_exact_keyword_match && |
| 419 (type == metrics::OmniboxInputType::QUERY)) ? |
418 1450 : 1100; | 420 1450 : 1100; |
419 } | 421 } |
420 | 422 |
421 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( | 423 AutocompleteMatch KeywordProvider::CreateAutocompleteMatch( |
422 const TemplateURL* template_url, | 424 const TemplateURL* template_url, |
423 const AutocompleteInput& input, | 425 const AutocompleteInput& input, |
424 size_t prefix_length, | 426 size_t prefix_length, |
425 const base::string16& remaining_input, | 427 const base::string16& remaining_input, |
426 bool allowed_to_be_default_match, | 428 bool allowed_to_be_default_match, |
427 int relevance) { | 429 int relevance) { |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 } | 628 } |
627 | 629 |
628 void KeywordProvider::MaybeEndExtensionKeywordMode() { | 630 void KeywordProvider::MaybeEndExtensionKeywordMode() { |
629 if (!current_keyword_extension_id_.empty()) { | 631 if (!current_keyword_extension_id_.empty()) { |
630 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( | 632 extensions::ExtensionOmniboxEventRouter::OnInputCancelled( |
631 profile_, current_keyword_extension_id_); | 633 profile_, current_keyword_extension_id_); |
632 | 634 |
633 current_keyword_extension_id_.clear(); | 635 current_keyword_extension_id_.clear(); |
634 } | 636 } |
635 } | 637 } |
OLD | NEW |