| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // |
| 11 // For more information on the autocomplete system in general, including how | 11 // For more information on the autocomplete system in general, including how |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 KeywordProvider(ACProviderListener* listener, Profile* profile); | 50 KeywordProvider(ACProviderListener* listener, Profile* profile); |
| 51 // For testing. | 51 // For testing. |
| 52 KeywordProvider(ACProviderListener* listener, TemplateURLModel* model); | 52 KeywordProvider(ACProviderListener* listener, TemplateURLModel* model); |
| 53 | 53 |
| 54 // Returns the replacement string from the user input. The replacement | 54 // Returns the replacement string from the user input. The replacement |
| 55 // string is the portion of the input that does not contain the keyword. | 55 // string is the portion of the input that does not contain the keyword. |
| 56 // For example, the replacement string for "b blah" is blah. | 56 // For example, the replacement string for "b blah" is blah. |
| 57 static std::wstring SplitReplacementStringFromInput( | 57 static std::wstring SplitReplacementStringFromInput( |
| 58 const std::wstring& input); | 58 const std::wstring& input); |
| 59 | 59 |
| 60 // Returns the matching substituting keyword for |input|, or NULL if there |
| 61 // is no keyword for the specified input. |
| 62 static const TemplateURL* GetSubstitutingTemplateURLForInput( |
| 63 Profile* profile, |
| 64 const AutocompleteInput& input, |
| 65 std::wstring* remaining_input); |
| 66 |
| 60 // AutocompleteProvider | 67 // AutocompleteProvider |
| 61 virtual void Start(const AutocompleteInput& input, | 68 virtual void Start(const AutocompleteInput& input, |
| 62 bool minimal_changes); | 69 bool minimal_changes); |
| 63 | 70 |
| 64 private: | 71 private: |
| 72 // Extracts the keyword from |input| into |keyword|. Any remaining characters |
| 73 // after the keyword are placed in |remaining_input|. Returns true if |input| |
| 74 // is valid and has a keyword. This makes use of SplitKeywordFromInput to |
| 75 // extract the keyword and remaining string, and uses |
| 76 // TemplateURLModel::CleanUserInputKeyword to remove unnecessary characters. |
| 77 // In general use this instead of SplitKeywordFromInput. |
| 78 static bool ExtractKeywordFromInput(const AutocompleteInput& input, |
| 79 std::wstring* keyword, |
| 80 std::wstring* remaining_input); |
| 81 |
| 65 // Extracts the next whitespace-delimited token from input and returns it. | 82 // Extracts the next whitespace-delimited token from input and returns it. |
| 66 // Sets |remaining_input| to everything after the first token (skipping over | 83 // Sets |remaining_input| to everything after the first token (skipping over |
| 67 // intervening whitespace). | 84 // intervening whitespace). |
| 68 static std::wstring SplitKeywordFromInput(const std::wstring& input, | 85 static std::wstring SplitKeywordFromInput(const std::wstring& input, |
| 69 std::wstring* remaining_input); | 86 std::wstring* remaining_input); |
| 70 | 87 |
| 71 // Fills in the "destination_url" and "contents" fields of |match| with the | 88 // Fills in the "destination_url" and "contents" fields of |match| with the |
| 72 // provided user input and keyword data. | 89 // provided user input and keyword data. |
| 73 static void FillInURLAndContents( | 90 static void FillInURLAndContents( |
| 74 const std::wstring& remaining_input, | 91 const std::wstring& remaining_input, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 92 const std::wstring& remaining_input); | 109 const std::wstring& remaining_input); |
| 93 | 110 |
| 94 // Model for the keywords. This is only non-null when testing, otherwise the | 111 // Model for the keywords. This is only non-null when testing, otherwise the |
| 95 // TemplateURLModel from the Profile is used. | 112 // TemplateURLModel from the Profile is used. |
| 96 TemplateURLModel* model_; | 113 TemplateURLModel* model_; |
| 97 | 114 |
| 98 DISALLOW_EVIL_CONSTRUCTORS(KeywordProvider); | 115 DISALLOW_EVIL_CONSTRUCTORS(KeywordProvider); |
| 99 }; | 116 }; |
| 100 | 117 |
| 101 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ | 118 #endif // CHROME_BROWSER_AUTOCOMPLETE_KEYWORD_PROVIDER_H_ |
| OLD | NEW |