| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 const string16& input, | 64 const string16& input, |
| 65 bool trim_leading_whitespace); | 65 bool trim_leading_whitespace); |
| 66 | 66 |
| 67 // Returns the matching substituting keyword for |input|, or NULL if there | 67 // Returns the matching substituting keyword for |input|, or NULL if there |
| 68 // is no keyword for the specified input. | 68 // is no keyword for the specified input. |
| 69 static const TemplateURL* GetSubstitutingTemplateURLForInput( | 69 static const TemplateURL* GetSubstitutingTemplateURLForInput( |
| 70 Profile* profile, | 70 Profile* profile, |
| 71 const AutocompleteInput& input, | 71 const AutocompleteInput& input, |
| 72 string16* remaining_input); | 72 string16* remaining_input); |
| 73 | 73 |
| 74 // If |text| corresponds (in the sense of |
| 75 // TemplateURLModel::CleanUserInputKeyword()) to an enabled, substituting |
| 76 // keyword, returns that keyword; returns the empty string otherwise. |
| 77 string16 GetKeywordForText(const string16& text) const; |
| 78 |
| 79 // Creates a fully marked-up AutocompleteMatch for a specific keyword. |
| 80 AutocompleteMatch CreateAutocompleteMatch( |
| 81 const string16& keyword, |
| 82 const AutocompleteInput& input); |
| 83 |
| 74 // AutocompleteProvider | 84 // AutocompleteProvider |
| 75 virtual void Start(const AutocompleteInput& input, bool minimal_changes); | 85 virtual void Start(const AutocompleteInput& input, bool minimal_changes); |
| 76 virtual void Stop(); | 86 virtual void Stop(); |
| 77 | 87 |
| 78 private: | 88 private: |
| 79 class ScopedEndExtensionKeywordMode; | 89 class ScopedEndExtensionKeywordMode; |
| 80 friend class ScopedEndExtensionKeywordMode; | 90 friend class ScopedEndExtensionKeywordMode; |
| 81 | 91 |
| 82 virtual ~KeywordProvider(); | 92 virtual ~KeywordProvider(); |
| 83 | 93 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 int relevance); | 140 int relevance); |
| 131 | 141 |
| 132 void EnterExtensionKeywordMode(const std::string& extension_id); | 142 void EnterExtensionKeywordMode(const std::string& extension_id); |
| 133 void MaybeEndExtensionKeywordMode(); | 143 void MaybeEndExtensionKeywordMode(); |
| 134 | 144 |
| 135 // NotificationObserver interface. | 145 // NotificationObserver interface. |
| 136 virtual void Observe(int type, | 146 virtual void Observe(int type, |
| 137 const NotificationSource& source, | 147 const NotificationSource& source, |
| 138 const NotificationDetails& details); | 148 const NotificationDetails& details); |
| 139 | 149 |
| 150 TemplateURLService* GetTemplateURLService() const; |
| 151 |
| 140 // Model for the keywords. This is only non-null when testing, otherwise the | 152 // Model for the keywords. This is only non-null when testing, otherwise the |
| 141 // TemplateURLService from the Profile is used. | 153 // TemplateURLService from the Profile is used. |
| 142 TemplateURLService* model_; | 154 TemplateURLService* model_; |
| 143 | 155 |
| 144 // Identifies the current input state. This is incremented each time the | 156 // Identifies the current input state. This is incremented each time the |
| 145 // autocomplete edit's input changes in any way. It is used to tell whether | 157 // autocomplete edit's input changes in any way. It is used to tell whether |
| 146 // suggest results from the extension are current. | 158 // suggest results from the extension are current. |
| 147 int current_input_id_; | 159 int current_input_id_; |
| 148 | 160 |
| 149 // The input state at the time we last asked the extension for suggest | 161 // The input state at the time we last asked the extension for suggest |
| 150 // results. | 162 // results. |
| 151 AutocompleteInput extension_suggest_last_input_; | 163 AutocompleteInput extension_suggest_last_input_; |
| 152 | 164 |
| 153 // We remember the last suggestions we've received from the extension in case | 165 // We remember the last suggestions we've received from the extension in case |
| 154 // we need to reset our matches without asking the extension again. | 166 // we need to reset our matches without asking the extension again. |
| 155 std::vector<AutocompleteMatch> extension_suggest_matches_; | 167 std::vector<AutocompleteMatch> extension_suggest_matches_; |
| 156 | 168 |
| 157 // If non-empty, holds the ID of the extension whose keyword is currently in | 169 // If non-empty, holds the ID of the extension whose keyword is currently in |
| 158 // the URL bar while the autocomplete popup is open. | 170 // the URL bar while the autocomplete popup is open. |
| 159 std::string current_keyword_extension_id_; | 171 std::string current_keyword_extension_id_; |
| 160 | 172 |
| 161 NotificationRegistrar registrar_; | 173 NotificationRegistrar registrar_; |
| 162 | 174 |
| 163 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 175 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
| 164 }; | 176 }; |
| 165 | 177 |
| 166 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 178 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
| OLD | NEW |