| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 // AutocompleteProvider | 74 // AutocompleteProvider |
| 75 virtual void Start(const AutocompleteInput& input, bool minimal_changes); | 75 virtual void Start(const AutocompleteInput& input, |
| 76 virtual void Stop(); | 76 bool minimal_changes) OVERRIDE; |
| 77 virtual void Stop() OVERRIDE; |
| 77 | 78 |
| 78 private: | 79 private: |
| 79 class ScopedEndExtensionKeywordMode; | 80 class ScopedEndExtensionKeywordMode; |
| 80 friend class ScopedEndExtensionKeywordMode; | 81 friend class ScopedEndExtensionKeywordMode; |
| 81 | 82 |
| 82 virtual ~KeywordProvider(); | 83 virtual ~KeywordProvider(); |
| 83 | 84 |
| 84 // Extracts the keyword from |input| into |keyword|. Any remaining characters | 85 // Extracts the keyword from |input| into |keyword|. Any remaining characters |
| 85 // after the keyword are placed in |remaining_input|. Returns true if |input| | 86 // after the keyword are placed in |remaining_input|. Returns true if |input| |
| 86 // is valid and has a keyword. This makes use of SplitKeywordFromInput to | 87 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 size_t prefix_length, | 130 size_t prefix_length, |
| 130 const string16& remaining_input, | 131 const string16& remaining_input, |
| 131 int relevance); | 132 int relevance); |
| 132 | 133 |
| 133 void EnterExtensionKeywordMode(const std::string& extension_id); | 134 void EnterExtensionKeywordMode(const std::string& extension_id); |
| 134 void MaybeEndExtensionKeywordMode(); | 135 void MaybeEndExtensionKeywordMode(); |
| 135 | 136 |
| 136 // content::NotificationObserver interface. | 137 // content::NotificationObserver interface. |
| 137 virtual void Observe(int type, | 138 virtual void Observe(int type, |
| 138 const content::NotificationSource& source, | 139 const content::NotificationSource& source, |
| 139 const content::NotificationDetails& details); | 140 const content::NotificationDetails& details) OVERRIDE; |
| 140 | 141 |
| 141 // Model for the keywords. This is only non-null when testing, otherwise the | 142 // Model for the keywords. This is only non-null when testing, otherwise the |
| 142 // TemplateURLService from the Profile is used. | 143 // TemplateURLService from the Profile is used. |
| 143 TemplateURLService* model_; | 144 TemplateURLService* model_; |
| 144 | 145 |
| 145 // Identifies the current input state. This is incremented each time the | 146 // Identifies the current input state. This is incremented each time the |
| 146 // autocomplete edit's input changes in any way. It is used to tell whether | 147 // autocomplete edit's input changes in any way. It is used to tell whether |
| 147 // suggest results from the extension are current. | 148 // suggest results from the extension are current. |
| 148 int current_input_id_; | 149 int current_input_id_; |
| 149 | 150 |
| 150 // The input state at the time we last asked the extension for suggest | 151 // The input state at the time we last asked the extension for suggest |
| 151 // results. | 152 // results. |
| 152 AutocompleteInput extension_suggest_last_input_; | 153 AutocompleteInput extension_suggest_last_input_; |
| 153 | 154 |
| 154 // We remember the last suggestions we've received from the extension in case | 155 // We remember the last suggestions we've received from the extension in case |
| 155 // we need to reset our matches without asking the extension again. | 156 // we need to reset our matches without asking the extension again. |
| 156 std::vector<AutocompleteMatch> extension_suggest_matches_; | 157 std::vector<AutocompleteMatch> extension_suggest_matches_; |
| 157 | 158 |
| 158 // If non-empty, holds the ID of the extension whose keyword is currently in | 159 // If non-empty, holds the ID of the extension whose keyword is currently in |
| 159 // the URL bar while the autocomplete popup is open. | 160 // the URL bar while the autocomplete popup is open. |
| 160 std::string current_keyword_extension_id_; | 161 std::string current_keyword_extension_id_; |
| 161 | 162 |
| 162 content::NotificationRegistrar registrar_; | 163 content::NotificationRegistrar registrar_; |
| 163 | 164 |
| 164 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 165 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
| 165 }; | 166 }; |
| 166 | 167 |
| 167 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 168 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
| OLD | NEW |