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

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: Created 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 (display_warning_if_disabled_) {
Ilya Sherman 2011/07/26 09:01:55 If display_warning_if_disabled_ is true, that does
honten.org 2011/07/27 03:29:37 I needed a couple of cast, so I made a function.
238 // If autofill is disabled and we had suggestions, show a warning instead.
239 v.assign(1,
240 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
241 l.assign(1, string16());
242 i.assign(1, string16());
243 ids.assign(1, -1);
244 } else if (ids[0] < 0 && ids.size() > 1) {
238 // If we received a warning instead of suggestions from autofill but regular 245 // If we received a warning instead of suggestions from autofill but regular
239 // suggestions from autocomplete, don't show the autofill warning. 246 // suggestions from autocomplete, don't show the autofill warning.
240 v.erase(v.begin()); 247 v.erase(v.begin());
241 l.erase(l.begin()); 248 l.erase(l.begin());
242 i.erase(i.begin()); 249 i.erase(i.begin());
243 ids.erase(ids.begin()); 250 ids.erase(ids.begin());
244 } 251 }
245 252
246 // If we were about to show a warning and we shouldn't, don't. 253 // If we were about to show a warning and we shouldn't, don't.
247 if (ids[0] < 0 && !display_warning_if_disabled_) 254 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) { 320 const std::vector<FormDataPredictions>& forms) {
314 for (size_t i = 0; i < forms.size(); ++i) { 321 for (size_t i = 0; i < forms.size(); ++i) {
315 form_manager_.ShowPredictions(forms[i]); 322 form_manager_.ShowPredictions(forms[i]);
316 } 323 }
317 } 324 }
318 325
319 void AutofillAgent::ShowSuggestions(const WebInputElement& element, 326 void AutofillAgent::ShowSuggestions(const WebInputElement& element,
320 bool autofill_on_empty_values, 327 bool autofill_on_empty_values,
321 bool requires_caret_at_end, 328 bool requires_caret_at_end,
322 bool display_warning_if_disabled) { 329 bool display_warning_if_disabled) {
323 if (!element.isEnabled() || element.isReadOnly() || !element.autoComplete() || 330 const WebFormElement form = element.form();
331 if (!element.isEnabled() || element.isReadOnly() ||
332 (!element.autoComplete() && form.autoComplete()) ||
324 !element.isTextField() || element.isPasswordField() || 333 !element.isTextField() || element.isPasswordField() ||
325 !element.suggestedValue().isEmpty()) 334 !element.suggestedValue().isEmpty())
326 return; 335 return;
327 336
328 // If the field has no name, then we won't have values. 337 // If the field has no name, then we won't have values.
329 if (element.nameForAutofill().isEmpty()) 338 if (element.nameForAutofill().isEmpty())
330 return; 339 return;
331 340
332 // Don't attempt to autofill with values that are too large. 341 // Don't attempt to autofill with values that are too large.
333 WebString value = element.value(); 342 WebString value = element.value();
334 if (value.length() > kMaximumTextSizeForAutofill) 343 if (value.length() > kMaximumTextSizeForAutofill)
335 return; 344 return;
336 345
337 if (!autofill_on_empty_values && value.isEmpty()) 346 if (!autofill_on_empty_values && value.isEmpty())
338 return; 347 return;
339 348
340 if (requires_caret_at_end && 349 if (requires_caret_at_end &&
341 (element.selectionStart() != element.selectionEnd() || 350 (element.selectionStart() != element.selectionEnd() ||
342 element.selectionEnd() != static_cast<int>(value.length()))) 351 element.selectionEnd() != static_cast<int>(value.length())))
343 return; 352 return;
344 353
345 QueryAutofillSuggestions(element, display_warning_if_disabled); 354 QueryAutofillSuggestions(element,
355 display_warning_if_disabled && !form.autoComplete());
Ilya Sherman 2011/07/26 09:01:55 Does this not prevent other warnings from ever dis
honten.org 2011/07/27 03:29:37 I don't need this check anymore. On 2011/07/26 09
346 } 356 }
347 357
348 void AutofillAgent::QueryAutofillSuggestions(const WebNode& node, 358 void AutofillAgent::QueryAutofillSuggestions(const WebNode& node,
349 bool display_warning_if_disabled) { 359 bool display_warning_if_disabled) {
350 static int query_counter = 0; 360 static int query_counter = 0;
351 autofill_query_id_ = query_counter++; 361 autofill_query_id_ = query_counter++;
352 autofill_query_node_ = node; 362 autofill_query_node_ = node;
353 display_warning_if_disabled_ = display_warning_if_disabled; 363 display_warning_if_disabled_ = display_warning_if_disabled;
354 364
355 webkit_glue::FormData form; 365 webkit_glue::FormData form;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 // WebFormControlElementToFormField does not scrape the DOM for the field 407 // WebFormControlElementToFormField does not scrape the DOM for the field
398 // label, so find the label here. 408 // label, so find the label here.
399 // TODO(isherman): Add form and field identities so we can use the cached form 409 // TODO(isherman): Add form and field identities so we can use the cached form
400 // data in FormManager. 410 // data in FormManager.
401 field->label = FormManager::LabelForElement(element); 411 field->label = FormManager::LabelForElement(element);
402 412
403 return true; 413 return true;
404 } 414 }
405 415
406 } // namespace autofill 416 } // namespace autofill
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698