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

Side by Side Diff: chrome/browser/autofill/autofill_external_delegate.cc

Issue 10546054: TabContentsWrapper -> TabContents, part 5. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 #include "base/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autocomplete_history_manager.h" 6 #include "chrome/browser/autocomplete_history_manager.h"
7 #include "chrome/browser/autofill/autofill_external_delegate.h" 7 #include "chrome/browser/autofill/autofill_external_delegate.h"
8 #include "chrome/browser/autofill/autofill_manager.h" 8 #include "chrome/browser/autofill/autofill_manager.h"
9 #include "chrome/common/autofill_messages.h" 9 #include "chrome/common/autofill_messages.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
11 #include "content/public/browser/render_view_host.h" 11 #include "content/public/browser/render_view_host.h"
12 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "grit/chromium_strings.h" 13 #include "grit/chromium_strings.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 using content::RenderViewHost; 18 using content::RenderViewHost;
19 using WebKit::WebAutofillClient; 19 using WebKit::WebAutofillClient;
20 20
21 AutofillExternalDelegate::~AutofillExternalDelegate() { 21 AutofillExternalDelegate::~AutofillExternalDelegate() {
22 } 22 }
23 23
24 AutofillExternalDelegate::AutofillExternalDelegate( 24 AutofillExternalDelegate::AutofillExternalDelegate(
25 TabContentsWrapper* tab_contents_wrapper, 25 TabContents* tab_contents,
26 AutofillManager* autofill_manager) 26 AutofillManager* autofill_manager)
27 : tab_contents_wrapper_(tab_contents_wrapper), 27 : tab_contents_(tab_contents),
28 autofill_manager_(autofill_manager), 28 autofill_manager_(autofill_manager),
29 password_autofill_manager_( 29 password_autofill_manager_(
30 tab_contents_wrapper ? tab_contents_wrapper->web_contents() : NULL), 30 tab_contents ? tab_contents->web_contents() : NULL),
31 autofill_query_id_(0), 31 autofill_query_id_(0),
32 display_warning_if_disabled_(false), 32 display_warning_if_disabled_(false),
33 has_shown_autofill_popup_for_current_edit_(false) { 33 has_shown_autofill_popup_for_current_edit_(false) {
34 } 34 }
35 35
36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) { 36 void AutofillExternalDelegate::SelectAutofillSuggestionAtIndex(int unique_id) {
37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions || 37 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions ||
38 unique_id == WebAutofillClient::MenuItemIDClearForm || 38 unique_id == WebAutofillClient::MenuItemIDClearForm ||
39 unique_id == WebAutofillClient::MenuItemIDSeparator || 39 unique_id == WebAutofillClient::MenuItemIDSeparator ||
40 unique_id == WebAutofillClient::MenuItemIDWarningMessage) 40 unique_id == WebAutofillClient::MenuItemIDWarningMessage)
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 v.pop_back(); 139 v.pop_back();
140 l.pop_back(); 140 l.pop_back();
141 i.pop_back(); 141 i.pop_back();
142 ids.pop_back(); 142 ids.pop_back();
143 } 143 }
144 144
145 // Send to display. 145 // Send to display.
146 if (!v.empty() && autofill_query_field_.is_focusable) 146 if (!v.empty() && autofill_query_field_.is_focusable)
147 ApplyAutofillSuggestions(v, l, i, ids); 147 ApplyAutofillSuggestions(v, l, i, ids);
148 148
149 tab_contents_wrapper_->autofill_manager()->OnDidShowAutofillSuggestions( 149 tab_contents_->autofill_manager()->OnDidShowAutofillSuggestions(
150 has_autofill_item && !has_shown_autofill_popup_for_current_edit_); 150 has_autofill_item && !has_shown_autofill_popup_for_current_edit_);
151 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item; 151 has_shown_autofill_popup_for_current_edit_ |= has_autofill_item;
152 } 152 }
153 153
154 void AutofillExternalDelegate::OnShowPasswordSuggestions( 154 void AutofillExternalDelegate::OnShowPasswordSuggestions(
155 const std::vector<string16>& suggestions, 155 const std::vector<string16>& suggestions,
156 const webkit::forms::FormField& field, 156 const webkit::forms::FormField& field,
157 const gfx::Rect& bounds) { 157 const gfx::Rect& bounds) {
158 autofill_query_field_ = field; 158 autofill_query_field_ = field;
159 159
160 if (suggestions.empty()) { 160 if (suggestions.empty()) {
161 HideAutofillPopup(); 161 HideAutofillPopup();
162 return; 162 return;
163 } 163 }
164 164
165 SetBounds(bounds); 165 SetBounds(bounds);
166 166
167 std::vector<string16> empty(suggestions.size()); 167 std::vector<string16> empty(suggestions.size());
168 std::vector<int> password_ids(suggestions.size(), 168 std::vector<int> password_ids(suggestions.size(),
169 WebAutofillClient::MenuItemIDPasswordEntry); 169 WebAutofillClient::MenuItemIDPasswordEntry);
170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids); 170 ApplyAutofillSuggestions(suggestions, empty, empty, password_ids);
171 } 171 }
172 172
173 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) { 173 void AutofillExternalDelegate::RemoveAutocompleteEntry(const string16& value) {
174 if (tab_contents_wrapper_) { 174 if (tab_contents_) {
175 tab_contents_wrapper_->autocomplete_history_manager()-> 175 tab_contents_->autocomplete_history_manager()->
176 OnRemoveAutocompleteEntry(autofill_query_field_.name, value); 176 OnRemoveAutocompleteEntry(autofill_query_field_.name, value);
177 } 177 }
178 } 178 }
179 179
180 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard( 180 void AutofillExternalDelegate::RemoveAutofillProfileOrCreditCard(
181 int unique_id) { 181 int unique_id) {
182 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id); 182 autofill_manager_->RemoveAutofillProfileOrCreditCard(unique_id);
183 } 183 }
184 184
185 185
186 void AutofillExternalDelegate::DidEndTextFieldEditing() { 186 void AutofillExternalDelegate::DidEndTextFieldEditing() {
187 HideAutofillPopup(); 187 HideAutofillPopup();
188 188
189 has_shown_autofill_popup_for_current_edit_ = false; 189 has_shown_autofill_popup_for_current_edit_ = false;
190 } 190 }
191 191
192 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions( 192 bool AutofillExternalDelegate::DidAcceptAutofillSuggestions(
193 const string16& value, 193 const string16& value,
194 int unique_id, 194 int unique_id,
195 unsigned index) { 195 unsigned index) {
196 // If the selected element is a warning we don't want to do anything. 196 // If the selected element is a warning we don't want to do anything.
197 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage) 197 if (unique_id == WebAutofillClient::MenuItemIDWarningMessage)
198 return false; 198 return false;
199 199
200 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) { 200 if (unique_id == WebAutofillClient::MenuItemIDAutofillOptions) {
201 // User selected 'Autofill Options'. 201 // User selected 'Autofill Options'.
202 autofill_manager_->OnShowAutofillDialog(); 202 autofill_manager_->OnShowAutofillDialog();
203 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) { 203 } else if (unique_id == WebAutofillClient::MenuItemIDClearForm) {
204 // User selected 'Clear form'. 204 // User selected 'Clear form'.
205 RenderViewHost* host = 205 RenderViewHost* host = tab_contents_->web_contents()->GetRenderViewHost();
206 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
207 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID())); 206 host->Send(new AutofillMsg_ClearForm(host->GetRoutingID()));
208 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry && 207 } else if (unique_id == WebAutofillClient::MenuItemIDPasswordEntry &&
209 password_autofill_manager_.DidAcceptAutofillSuggestion( 208 password_autofill_manager_.DidAcceptAutofillSuggestion(
210 autofill_query_field_, value)) { 209 autofill_query_field_, value)) {
211 // DidAcceptAutofillSuggestion has already handled the work to fill in 210 // DidAcceptAutofillSuggestion has already handled the work to fill in
212 // the page as required. 211 // the page as required.
213 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) { 212 } else if (unique_id == WebAutofillClient::MenuItemIDAutocompleteEntry) {
214 // User selected an Autocomplete, so we fill directly. 213 // User selected an Autocomplete, so we fill directly.
215 RenderViewHost* host = 214 RenderViewHost* host = tab_contents_->web_contents()->GetRenderViewHost();
216 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
217 host->Send(new AutofillMsg_SetNodeText( 215 host->Send(new AutofillMsg_SetNodeText(
218 host->GetRoutingID(), 216 host->GetRoutingID(),
219 value)); 217 value));
220 } else { 218 } else {
221 FillAutofillFormData(unique_id, false); 219 FillAutofillFormData(unique_id, false);
222 } 220 }
223 221
224 HideAutofillPopup(); 222 HideAutofillPopup();
225 223
226 return true; 224 return true;
227 } 225 }
228 226
229 void AutofillExternalDelegate::ClearPreviewedForm() { 227 void AutofillExternalDelegate::ClearPreviewedForm() {
230 RenderViewHost* host = 228 RenderViewHost* host = tab_contents_->web_contents()->GetRenderViewHost();
231 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
232 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID())); 229 host->Send(new AutofillMsg_ClearPreviewedForm(host->GetRoutingID()));
233 } 230 }
234 231
235 void AutofillExternalDelegate::HideAutofillPopup() { 232 void AutofillExternalDelegate::HideAutofillPopup() {
236 HideAutofillPopupInternal(); 233 HideAutofillPopupInternal();
237 } 234 }
238 235
239 void AutofillExternalDelegate::Reset() { 236 void AutofillExternalDelegate::Reset() {
240 HideAutofillPopup(); 237 HideAutofillPopup();
241 238
242 password_autofill_manager_.Reset(); 239 password_autofill_manager_.Reset();
243 } 240 }
244 241
245 void AutofillExternalDelegate::AddPasswordFormMapping( 242 void AutofillExternalDelegate::AddPasswordFormMapping(
246 const webkit::forms::FormField& form, 243 const webkit::forms::FormField& form,
247 const webkit::forms::PasswordFormFillData& fill_data) { 244 const webkit::forms::PasswordFormFillData& fill_data) {
248 password_autofill_manager_.AddPasswordFormMapping(form, fill_data); 245 password_autofill_manager_.AddPasswordFormMapping(form, fill_data);
249 } 246 }
250 247
251 void AutofillExternalDelegate::FillAutofillFormData(int unique_id, 248 void AutofillExternalDelegate::FillAutofillFormData(int unique_id,
252 bool is_preview) { 249 bool is_preview) {
253 RenderViewHost* host = 250 RenderViewHost* host = tab_contents_->web_contents()->GetRenderViewHost();
254 tab_contents_wrapper_->web_contents()->GetRenderViewHost();
255 251
256 if (is_preview) { 252 if (is_preview) {
257 host->Send(new AutofillMsg_SetAutofillActionPreview( 253 host->Send(new AutofillMsg_SetAutofillActionPreview(
258 host->GetRoutingID())); 254 host->GetRoutingID()));
259 } else { 255 } else {
260 host->Send(new AutofillMsg_SetAutofillActionFill( 256 host->Send(new AutofillMsg_SetAutofillActionFill(
261 host->GetRoutingID())); 257 host->GetRoutingID()));
262 } 258 }
263 259
264 // Fill the values for the whole form. 260 // Fill the values for the whole form.
265 autofill_manager_->OnFillAutofillFormData(autofill_query_id_, 261 autofill_manager_->OnFillAutofillFormData(autofill_query_id_,
266 autofill_query_form_, 262 autofill_query_form_,
267 autofill_query_field_, 263 autofill_query_field_,
268 unique_id); 264 unique_id);
269 } 265 }
270 266
271 // Add a "!defined(OS_YOUROS) for each platform that implements this 267 // Add a "!defined(OS_YOUROS) for each platform that implements this
272 // in an autofill_external_delegate_YOUROS.cc. Currently there are 268 // in an autofill_external_delegate_YOUROS.cc. Currently there are
273 // none, so all platforms use the default. 269 // none, so all platforms use the default.
274 270
275 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK) 271 #if !defined(OS_ANDROID) && !defined(TOOLKIT_GTK)
276 272
277 AutofillExternalDelegate* AutofillExternalDelegate::Create( 273 AutofillExternalDelegate* AutofillExternalDelegate::Create(
278 TabContentsWrapper*, AutofillManager*) { 274 TabContents*, AutofillManager*) {
279 return NULL; 275 return NULL;
280 } 276 }
281 277
282 #endif 278 #endif
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_external_delegate.h ('k') | chrome/browser/autofill/autofill_external_delegate_android.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698