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

Side by Side Diff: chrome/renderer/autofill/autofill_agent.cc

Issue 7514003: Show display warning if the form is autocomplete off. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add comment and change autofill_query_node_ type. Created 9 years, 4 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) 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 #include "chrome/renderer/autofill/autofill_agent.h" 5 #include "chrome/renderer/autofill/autofill_agent.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.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"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 web_view->hidePopups(); 227 web_view->hidePopups();
228 return; 228 return;
229 } 229 }
230 230
231 std::vector<string16> v(values); 231 std::vector<string16> v(values);
232 std::vector<string16> l(labels); 232 std::vector<string16> l(labels);
233 std::vector<string16> i(icons); 233 std::vector<string16> i(icons);
234 std::vector<int> ids(unique_ids); 234 std::vector<int> ids(unique_ids);
235 int separator_index = -1; 235 int separator_index = -1;
236 236
237 if (ids[0] < 0 && ids.size() > 1) { 237 if (!autofill_query_node_.isNull() && !autofill_query_node_.autoComplete()) {
238 // If autofill is disabled and we had suggestions, show a warning instead.
239 v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
240 l.assign(1, string16());
241 i.assign(1, string16());
242 ids.assign(1, -1);
243 } else if (ids[0] < 0 && ids.size() > 1) {
238 // If we received a warning instead of suggestions from autofill but regular 244 // If we received a warning instead of suggestions from autofill but regular
239 // suggestions from autocomplete, don't show the autofill warning. 245 // suggestions from autocomplete, don't show the autofill warning.
240 v.erase(v.begin()); 246 v.erase(v.begin());
241 l.erase(l.begin()); 247 l.erase(l.begin());
242 i.erase(i.begin()); 248 i.erase(i.begin());
243 ids.erase(ids.begin()); 249 ids.erase(ids.begin());
244 } 250 }
245 251
246 // If we were about to show a warning and we shouldn't, don't. 252 // If we were about to show a warning and we shouldn't, don't.
247 if (ids[0] < 0 && !display_warning_if_disabled_) 253 if (ids[0] < 0 && !display_warning_if_disabled_)
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 const std::vector<FormDataPredictions>& forms) { 319 const std::vector<FormDataPredictions>& forms) {
314 for (size_t i = 0; i < forms.size(); ++i) { 320 for (size_t i = 0; i < forms.size(); ++i) {
315 form_manager_.ShowPredictions(forms[i]); 321 form_manager_.ShowPredictions(forms[i]);
316 } 322 }
317 } 323 }
318 324
319 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 325 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
320 bool autofill_on_empty_values, 326 bool autofill_on_empty_values,
321 bool requires_caret_at_end, 327 bool requires_caret_at_end,
322 bool display_warning_if_disabled) { 328 bool display_warning_if_disabled) {
323 if (!element.isEnabled() || element.isReadOnly() || !element.autoComplete() || 329 // If autocomplete is disabled at the form level, then we might want to show
330 // a warning in place of suggestions. However, if autocomplete is disabled
331 // specifically for this field, we never want to show a warning. Otherwise,
332 // we might interfere with custom popups (e.g. search suggestions) used by
333 // the website.
334 const WebFormElement form = element.form();
335 if (!element.isEnabled() || element.isReadOnly() ||
336 (!element.autoComplete() && form.autoComplete()) ||
324 !element.isTextField() || element.isPasswordField() || 337 !element.isTextField() || element.isPasswordField() ||
325 !element.suggestedValue().isEmpty()) 338 !element.suggestedValue().isEmpty())
326 return; 339 return;
327 340
328 // If the field has no name, then we won't have values. 341 // If the field has no name, then we won't have values.
329 if (element.nameForAutofill().isEmpty()) 342 if (element.nameForAutofill().isEmpty())
330 return; 343 return;
331 344
332 // Don't attempt to autofill with values that are too large. 345 // Don't attempt to autofill with values that are too large.
333 WebString value = element.value(); 346 WebString value = element.value();
334 if (value.length() > kMaximumTextSizeForAutofill) 347 if (value.length() > kMaximumTextSizeForAutofill)
335 return; 348 return;
336 349
337 if (!autofill_on_empty_values && value.isEmpty()) 350 if (!autofill_on_empty_values && value.isEmpty())
338 return; 351 return;
339 352
340 if (requires_caret_at_end && 353 if (requires_caret_at_end &&
341 (element.selectionStart() != element.selectionEnd() || 354 (element.selectionStart() != element.selectionEnd() ||
342 element.selectionEnd() != static_cast<int>(value.length()))) 355 element.selectionEnd() != static_cast<int>(value.length())))
343 return; 356 return;
344 357
345 QueryAutofillSuggestions(element, display_warning_if_disabled); 358 QueryAutofillSuggestions(element, display_warning_if_disabled);
346 } 359 }
347 360
348 void AutofillAgent::QueryAutofillSuggestions(const WebNode& node, 361 void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element,
349 bool display_warning_if_disabled) { 362 bool display_warning_if_disabled) {
350 static int query_counter = 0; 363 static int query_counter = 0;
351 autofill_query_id_ = query_counter++; 364 autofill_query_id_ = query_counter++;
352 autofill_query_node_ = node; 365 autofill_query_node_ = element;
353 display_warning_if_disabled_ = display_warning_if_disabled; 366 display_warning_if_disabled_ = display_warning_if_disabled;
354 367
355 webkit_glue::FormData form; 368 webkit_glue::FormData form;
356 webkit_glue::FormField field; 369 webkit_glue::FormField field;
357 if (!FindFormAndFieldForNode(node, &form, &field)) { 370 if (!FindFormAndFieldForNode(element, &form, &field)) {
358 // If we didn't find the cached form, at least let autocomplete have a shot 371 // If we didn't find the cached form, at least let autocomplete have a shot
359 // at providing suggestions. 372 // at providing suggestions.
360 FormManager::WebFormControlElementToFormField( 373 FormManager::WebFormControlElementToFormField(element,
361 node.toConst<WebFormControlElement>(), FormManager::EXTRACT_VALUE, 374 FormManager::EXTRACT_VALUE,
362 &field); 375 &field);
363 } 376 }
364 377
365 Send(new AutofillHostMsg_QueryFormFieldAutofill( 378 Send(new AutofillHostMsg_QueryFormFieldAutofill(
366 routing_id(), autofill_query_id_, form, field)); 379 routing_id(), autofill_query_id_, form, field));
367 } 380 }
368 381
369 void AutofillAgent::FillAutofillFormData(const WebNode& node, 382 void AutofillAgent::FillAutofillFormData(const WebNode& node,
370 int unique_id, 383 int unique_id,
371 AutofillAction action) { 384 AutofillAction action) {
372 static int query_counter = 0; 385 static int query_counter = 0;
(...skipping 24 matching lines...) Expand all
397 // WebFormControlElementToFormField does not scrape the DOM for the field 410 // WebFormControlElementToFormField does not scrape the DOM for the field
398 // label, so find the label here. 411 // label, so find the label here.
399 // TODO(isherman): Add form and field identities so we can use the cached form 412 // TODO(isherman): Add form and field identities so we can use the cached form
400 // data in FormManager. 413 // data in FormManager.
401 field->label = FormManager::LabelForElement(element); 414 field->label = FormManager::LabelForElement(element);
402 415
403 return true; 416 return true;
404 } 417 }
405 418
406 } // namespace autofill 419 } // namespace autofill
OLDNEW
« chrome/renderer/autofill/autofill_agent.h ('K') | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698