Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(282)

Side by Side Diff: chrome/browser/autocomplete/keyword_provider.h

Issue 17022004: Replace --google-base-suggest-url and --instant-url with --google-base-url. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // updates |input|'s text and cursor position. 76 // updates |input|'s text and cursor position.
77 static const TemplateURL* GetSubstitutingTemplateURLForInput( 77 static const TemplateURL* GetSubstitutingTemplateURLForInput(
78 TemplateURLService* model, 78 TemplateURLService* model,
79 AutocompleteInput* input); 79 AutocompleteInput* input);
80 80
81 // If |text| corresponds (in the sense of 81 // If |text| corresponds (in the sense of
82 // TemplateURLModel::CleanUserInputKeyword()) to an enabled, substituting 82 // TemplateURLModel::CleanUserInputKeyword()) to an enabled, substituting
83 // keyword, returns that keyword; returns the empty string otherwise. 83 // keyword, returns that keyword; returns the empty string otherwise.
84 string16 GetKeywordForText(const string16& text) const; 84 string16 GetKeywordForText(const string16& text) const;
85 85
86 // Creates a fully marked-up AutocompleteMatch for a specific keyword. 86 // Creates a fully marked-up AutocompleteMatch for |keyword|.
87 AutocompleteMatch CreateAutocompleteMatch(const string16& text, 87 AutocompleteMatch CreateAutocompleteMatch(const string16& text,
88 const string16& keyword, 88 const string16& keyword,
89 const AutocompleteInput& input); 89 const AutocompleteInput& input);
90 90
91 // AutocompleteProvider: 91 // AutocompleteProvider:
92 virtual void Start(const AutocompleteInput& input, 92 virtual void Start(const AutocompleteInput& input,
93 bool minimal_changes) OVERRIDE; 93 bool minimal_changes) OVERRIDE;
94 virtual void Stop(bool clear_cached_results) OVERRIDE; 94 virtual void Stop(bool clear_cached_results) OVERRIDE;
95 95
96 private: 96 private:
97 class ScopedEndExtensionKeywordMode; 97 class ScopedEndExtensionKeywordMode;
98 friend class ScopedEndExtensionKeywordMode; 98 friend class ScopedEndExtensionKeywordMode;
99 99
100 virtual ~KeywordProvider(); 100 virtual ~KeywordProvider();
101 101
102 // Extracts the keyword from |input| into |keyword|. Any remaining characters 102 // Extracts the keyword from |input| into |keyword|. Any remaining characters
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
130 // Creates a fully marked-up AutocompleteMatch from the user's input. 124 // Creates a fully marked-up AutocompleteMatch from the user's input.
131 // If |relevance| is negative, calculate a relevance based on heuristics. 125 // If |relevance| is negative, calculate a relevance based on heuristics.
132 AutocompleteMatch CreateAutocompleteMatch(TemplateURLService* model, 126 AutocompleteMatch CreateAutocompleteMatch(const TemplateURL* template_url,
133 const string16& keyword,
134 const AutocompleteInput& input, 127 const AutocompleteInput& input,
135 size_t prefix_length, 128 size_t prefix_length,
136 const string16& remaining_input, 129 const string16& remaining_input,
137 int relevance); 130 int relevance);
138 131
132 // Fills in the "destination_url" and "contents" fields of |match| with the
133 // provided user input and keyword data.
134 void FillInURLAndContents(const string16& remaining_input,
135 const TemplateURL* element,
136 AutocompleteMatch* match) const;
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,
144 const content::NotificationSource& source, 143 const content::NotificationSource& source,
145 const content::NotificationDetails& details) OVERRIDE; 144 const content::NotificationDetails& details) OVERRIDE;
146 145
147 TemplateURLService* GetTemplateURLService() const; 146 TemplateURLService* GetTemplateURLService() const;
148 147
(...skipping 17 matching lines...) Expand all
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_
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_provider_unittest.cc ('k') | chrome/browser/autocomplete/keyword_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698