| 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 // This file contains the keyword autocomplete provider. The keyword provider | 5 // This file contains the keyword autocomplete provider. The keyword provider |
| 6 // is responsible for remembering/suggesting user "search keyword queries" | 6 // is responsible for remembering/suggesting user "search keyword queries" |
| 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An | 7 // (e.g. "imdb Godzilla") and then fixing them up into valid URLs. An |
| 8 // instance of it gets created and managed by the autocomplete controller. | 8 // instance of it gets created and managed by the autocomplete controller. |
| 9 // KeywordProvider uses a TemplateURLService to find the set of keywords. | 9 // KeywordProvider uses a TemplateURLService to find the set of keywords. |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 // after the keyword are placed in |remaining_input|. Returns true if |input| | 103 // after the keyword are placed in |remaining_input|. Returns true if |input| |
| 104 // is valid and has a keyword. This makes use of SplitKeywordFromInput to | 104 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
| 105 // extract the keyword and remaining string, and uses | 105 // extract the keyword and remaining string, and uses |
| 106 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. | 106 // TemplateURLService::CleanUserInputKeyword to remove unnecessary characters. |
| 107 // In general use this instead of SplitKeywordFromInput. | 107 // In general use this instead of SplitKeywordFromInput. |
| 108 // Leading whitespace in |*remaining_input| will be trimmed. | 108 // Leading whitespace in |*remaining_input| will be trimmed. |
| 109 static bool ExtractKeywordFromInput(const AutocompleteInput& input, | 109 static bool ExtractKeywordFromInput(const AutocompleteInput& input, |
| 110 string16* keyword, | 110 string16* keyword, |
| 111 string16* remaining_input); | 111 string16* remaining_input); |
| 112 | 112 |
| 113 // Fills in the "destination_url" and "contents" fields of |match| with the | |
| 114 // provided user input and keyword data. | |
| 115 static void FillInURLAndContents(const string16& remaining_input, | |
| 116 const TemplateURL* element, | |
| 117 AutocompleteMatch* match); | |
| 118 | |
| 119 // Determines the relevance for some input, given its type, whether the user | 113 // Determines the relevance for some input, given its type, whether the user |
| 120 // typed the complete keyword, and whether the user is in "prefer keyword | 114 // typed the complete keyword, and whether the user is in "prefer keyword |
| 121 // matches" mode, and whether the keyword supports replacement. | 115 // matches" mode, and whether the keyword supports replacement. |
| 122 // If |allow_exact_keyword_match| is false, the relevance for complete | 116 // If |allow_exact_keyword_match| is false, the relevance for complete |
| 123 // keywords that support replacements is degraded. | 117 // keywords that support replacements is degraded. |
| 124 static int CalculateRelevance(AutocompleteInput::Type type, | 118 static int CalculateRelevance(AutocompleteInput::Type type, |
| 125 bool complete, | 119 bool complete, |
| 126 bool support_replacement, | 120 bool support_replacement, |
| 127 bool prefer_keyword, | 121 bool prefer_keyword, |
| 128 bool allow_exact_keyword_match); | 122 bool allow_exact_keyword_match); |
| 129 | 123 |
| 124 // Fills in the "destination_url" and "contents" fields of |match| with the |
| 125 // provided user input and keyword data. |
| 126 static void FillInURLAndContents(const string16& remaining_input, |
| 127 const TemplateURL* element, |
| 128 AutocompleteMatch* match); |
| 129 |
| 130 // Creates a fully marked-up AutocompleteMatch from the user's input. | 130 // Creates a fully marked-up AutocompleteMatch from the user's input. |
| 131 // If |relevance| is negative, calculate a relevance based on heuristics. | 131 // If |relevance| is negative, calculate a relevance based on heuristics. |
| 132 AutocompleteMatch CreateAutocompleteMatch(TemplateURLService* model, | 132 AutocompleteMatch CreateAutocompleteMatch(const TemplateURL* template_url, |
| 133 const string16& keyword, | |
| 134 const AutocompleteInput& input, | 133 const AutocompleteInput& input, |
| 135 size_t prefix_length, | 134 size_t prefix_length, |
| 136 const string16& remaining_input, | 135 const string16& remaining_input, |
| 137 int relevance); | 136 int relevance); |
| 138 | 137 |
| 139 void EnterExtensionKeywordMode(const std::string& extension_id); | 138 void EnterExtensionKeywordMode(const std::string& extension_id); |
| 140 void MaybeEndExtensionKeywordMode(); | 139 void MaybeEndExtensionKeywordMode(); |
| 141 | 140 |
| 142 // content::NotificationObserver interface. | 141 // content::NotificationObserver interface. |
| 143 virtual void Observe(int type, | 142 virtual void Observe(int type, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 166 // If non-empty, holds the ID of the extension whose keyword is currently in | 165 // If non-empty, holds the ID of the extension whose keyword is currently in |
| 167 // the URL bar while the autocomplete popup is open. | 166 // the URL bar while the autocomplete popup is open. |
| 168 std::string current_keyword_extension_id_; | 167 std::string current_keyword_extension_id_; |
| 169 | 168 |
| 170 content::NotificationRegistrar registrar_; | 169 content::NotificationRegistrar registrar_; |
| 171 | 170 |
| 172 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 171 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
| 173 }; | 172 }; |
| 174 | 173 |
| 175 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 174 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
| OLD | NEW |