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 // 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 TemplateURLModel to find the set of keywords. | 9 // KeywordProvider uses a TemplateURLModel to find the set of keywords. |
10 // | 10 // |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 const std::wstring& input); | 61 const std::wstring& input); |
62 | 62 |
63 // Returns the matching substituting keyword for |input|, or NULL if there | 63 // Returns the matching substituting keyword for |input|, or NULL if there |
64 // is no keyword for the specified input. | 64 // is no keyword for the specified input. |
65 static const TemplateURL* GetSubstitutingTemplateURLForInput( | 65 static const TemplateURL* GetSubstitutingTemplateURLForInput( |
66 Profile* profile, | 66 Profile* profile, |
67 const AutocompleteInput& input, | 67 const AutocompleteInput& input, |
68 std::wstring* remaining_input); | 68 std::wstring* remaining_input); |
69 | 69 |
70 // AutocompleteProvider | 70 // AutocompleteProvider |
71 virtual void Start(const AutocompleteInput& input, | 71 virtual void Start(const AutocompleteInput& input, bool minimal_changes); |
72 bool minimal_changes); | 72 virtual void Stop(); |
73 | 73 |
74 private: | 74 private: |
| 75 class ScopedEndExtensionKeywordMode; |
| 76 friend class ScopedEndExtensionKeywordMode; |
| 77 |
75 ~KeywordProvider() {} | 78 ~KeywordProvider() {} |
76 | 79 |
77 // Extracts the keyword from |input| into |keyword|. Any remaining characters | 80 // Extracts the keyword from |input| into |keyword|. Any remaining characters |
78 // after the keyword are placed in |remaining_input|. Returns true if |input| | 81 // after the keyword are placed in |remaining_input|. Returns true if |input| |
79 // is valid and has a keyword. This makes use of SplitKeywordFromInput to | 82 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
80 // extract the keyword and remaining string, and uses | 83 // extract the keyword and remaining string, and uses |
81 // TemplateURLModel::CleanUserInputKeyword to remove unnecessary characters. | 84 // TemplateURLModel::CleanUserInputKeyword to remove unnecessary characters. |
82 // In general use this instead of SplitKeywordFromInput. | 85 // In general use this instead of SplitKeywordFromInput. |
83 static bool ExtractKeywordFromInput(const AutocompleteInput& input, | 86 static bool ExtractKeywordFromInput(const AutocompleteInput& input, |
84 std::wstring* keyword, | 87 std::wstring* keyword, |
(...skipping 23 matching lines...) Expand all Loading... |
108 // Creates a fully marked-up AutocompleteMatch from the user's input. | 111 // Creates a fully marked-up AutocompleteMatch from the user's input. |
109 // If |relevance| is negative, calculate a relevance based on heuristics. | 112 // If |relevance| is negative, calculate a relevance based on heuristics. |
110 AutocompleteMatch CreateAutocompleteMatch( | 113 AutocompleteMatch CreateAutocompleteMatch( |
111 TemplateURLModel* model, | 114 TemplateURLModel* model, |
112 const std::wstring keyword, | 115 const std::wstring keyword, |
113 const AutocompleteInput& input, | 116 const AutocompleteInput& input, |
114 size_t prefix_length, | 117 size_t prefix_length, |
115 const std::wstring& remaining_input, | 118 const std::wstring& remaining_input, |
116 int relevance); | 119 int relevance); |
117 | 120 |
| 121 void EnterExtensionKeywordMode(const std::string& extension_id); |
| 122 void MaybeEndExtensionKeywordMode(); |
| 123 |
118 // NotificationObserver interface. | 124 // NotificationObserver interface. |
119 void Observe(NotificationType type, | 125 void Observe(NotificationType type, |
120 const NotificationSource& source, | 126 const NotificationSource& source, |
121 const NotificationDetails& details); | 127 const NotificationDetails& details); |
122 | 128 |
123 // Model for the keywords. This is only non-null when testing, otherwise the | 129 // Model for the keywords. This is only non-null when testing, otherwise the |
124 // TemplateURLModel from the Profile is used. | 130 // TemplateURLModel from the Profile is used. |
125 TemplateURLModel* model_; | 131 TemplateURLModel* model_; |
126 | 132 |
127 // Identifies the current input state. This is incremented each time the | 133 // Identifies the current input state. This is incremented each time the |
128 // autocomplete edit's input changes in any way. It is used to tell whether | 134 // autocomplete edit's input changes in any way. It is used to tell whether |
129 // suggest results from the extension are current. | 135 // suggest results from the extension are current. |
130 int current_input_id_; | 136 int current_input_id_; |
131 | 137 |
132 // The input state at the time we last asked the extension for suggest | 138 // The input state at the time we last asked the extension for suggest |
133 // results. | 139 // results. |
134 AutocompleteInput extension_suggest_last_input_; | 140 AutocompleteInput extension_suggest_last_input_; |
135 | 141 |
136 // We remember the last suggestions we've received from the extension in case | 142 // We remember the last suggestions we've received from the extension in case |
137 // we need to reset our matches without asking the extension again. | 143 // we need to reset our matches without asking the extension again. |
138 std::vector<AutocompleteMatch> extension_suggest_matches_; | 144 std::vector<AutocompleteMatch> extension_suggest_matches_; |
139 | 145 |
| 146 // If non-empty, holds the ID of the extension whose keyword is currently in |
| 147 // the URL bar while the autocomplete popup is open. |
| 148 std::string current_keyword_extension_id_; |
| 149 |
140 NotificationRegistrar registrar_; | 150 NotificationRegistrar registrar_; |
141 | 151 |
142 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); | 152 DISALLOW_COPY_AND_ASSIGN(KeywordProvider); |
143 }; | 153 }; |
144 | 154 |
145 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 155 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
OLD | NEW |