Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 12 matching lines...) Expand all Loading... | |
| 23 #include "webkit/glue/form_data_predictions.h" | 23 #include "webkit/glue/form_data_predictions.h" |
| 24 #include "webkit/glue/form_field.h" | 24 #include "webkit/glue/form_field.h" |
| 25 #include "webkit/glue/password_form.h" | 25 #include "webkit/glue/password_form.h" |
| 26 | 26 |
| 27 using WebKit::WebFormControlElement; | 27 using WebKit::WebFormControlElement; |
| 28 using WebKit::WebFormElement; | 28 using WebKit::WebFormElement; |
| 29 using WebKit::WebFrame; | 29 using WebKit::WebFrame; |
| 30 using WebKit::WebInputElement; | 30 using WebKit::WebInputElement; |
| 31 using WebKit::WebKeyboardEvent; | 31 using WebKit::WebKeyboardEvent; |
| 32 using WebKit::WebNode; | 32 using WebKit::WebNode; |
| 33 using WebKit::WebElement; | |
| 33 using WebKit::WebString; | 34 using WebKit::WebString; |
| 34 using webkit_glue::FormData; | 35 using webkit_glue::FormData; |
| 35 using webkit_glue::FormDataPredictions; | 36 using webkit_glue::FormDataPredictions; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // The size above which we stop triggering autofill for an input text field | 40 // The size above which we stop triggering autofill for an input text field |
| 40 // (so to avoid sending long strings through IPC). | 41 // (so to avoid sending long strings through IPC). |
| 41 const size_t kMaximumTextSizeForAutofill = 1000; | 42 const size_t kMaximumTextSizeForAutofill = 1000; |
| 42 | 43 |
| 44 bool autoCompleteOff(const WebNode& node) { | |
|
Ilya Sherman
2011/07/27 23:41:30
nit: Chromium function names start with capital le
honten.org
2011/07/28 06:03:06
Change the type.
On 2011/07/27 23:41:30, Ilya She
| |
| 45 if (node.isNull()) | |
| 46 return false; | |
| 47 | |
| 48 if (node.nodeType() != WebNode::ElementNode && | |
| 49 node.nodeType() != WebNode::TextNode) | |
|
Ilya Sherman
2011/07/27 23:41:30
I don't think you want TextNode here...
| |
| 50 return false; | |
| 51 | |
| 52 const WebElement element = node.toConst<WebElement>(); | |
| 53 const WebInputElement* input_element = toWebInputElement(&element); | |
| 54 return input_element && !input_element->autoComplete(); | |
| 55 } | |
| 56 | |
| 43 } // namespace | 57 } // namespace |
| 44 | 58 |
| 45 namespace autofill { | 59 namespace autofill { |
| 46 | 60 |
| 47 AutofillAgent::AutofillAgent( | 61 AutofillAgent::AutofillAgent( |
| 48 RenderView* render_view, | 62 RenderView* render_view, |
| 49 PasswordAutofillManager* password_autofill_manager) | 63 PasswordAutofillManager* password_autofill_manager) |
| 50 : RenderViewObserver(render_view), | 64 : RenderViewObserver(render_view), |
| 51 password_autofill_manager_(password_autofill_manager), | 65 password_autofill_manager_(password_autofill_manager), |
| 52 autofill_query_id_(0), | 66 autofill_query_id_(0), |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 web_view->hidePopups(); | 241 web_view->hidePopups(); |
| 228 return; | 242 return; |
| 229 } | 243 } |
| 230 | 244 |
| 231 std::vector<string16> v(values); | 245 std::vector<string16> v(values); |
| 232 std::vector<string16> l(labels); | 246 std::vector<string16> l(labels); |
| 233 std::vector<string16> i(icons); | 247 std::vector<string16> i(icons); |
| 234 std::vector<int> ids(unique_ids); | 248 std::vector<int> ids(unique_ids); |
| 235 int separator_index = -1; | 249 int separator_index = -1; |
| 236 | 250 |
| 237 if (ids[0] < 0 && ids.size() > 1) { | 251 if (autoCompleteOff(autofill_query_node_)) { |
| 252 // If autofill is disabled and we had suggestions, show a warning instead. | |
| 253 v.assign(1, | |
| 254 l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED)); | |
|
Ilya Sherman
2011/07/27 23:41:30
nit: This looks like it could fit on a single line
honten.org
2011/07/28 06:03:06
Done.
| |
| 255 l.assign(1, string16()); | |
| 256 i.assign(1, string16()); | |
| 257 ids.assign(1, -1); | |
| 258 } else if (ids[0] < 0 && ids.size() > 1) { | |
| 238 // If we received a warning instead of suggestions from autofill but regular | 259 // If we received a warning instead of suggestions from autofill but regular |
| 239 // suggestions from autocomplete, don't show the autofill warning. | 260 // suggestions from autocomplete, don't show the autofill warning. |
| 240 v.erase(v.begin()); | 261 v.erase(v.begin()); |
| 241 l.erase(l.begin()); | 262 l.erase(l.begin()); |
| 242 i.erase(i.begin()); | 263 i.erase(i.begin()); |
| 243 ids.erase(ids.begin()); | 264 ids.erase(ids.begin()); |
| 244 } | 265 } |
| 245 | 266 |
| 246 // If we were about to show a warning and we shouldn't, don't. | 267 // If we were about to show a warning and we shouldn't, don't. |
| 247 if (ids[0] < 0 && !display_warning_if_disabled_) | 268 if (ids[0] < 0 && !display_warning_if_disabled_) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 const std::vector<FormDataPredictions>& forms) { | 334 const std::vector<FormDataPredictions>& forms) { |
| 314 for (size_t i = 0; i < forms.size(); ++i) { | 335 for (size_t i = 0; i < forms.size(); ++i) { |
| 315 form_manager_.ShowPredictions(forms[i]); | 336 form_manager_.ShowPredictions(forms[i]); |
| 316 } | 337 } |
| 317 } | 338 } |
| 318 | 339 |
| 319 void AutofillAgent::ShowSuggestions(const WebInputElement& element, | 340 void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| 320 bool autofill_on_empty_values, | 341 bool autofill_on_empty_values, |
| 321 bool requires_caret_at_end, | 342 bool requires_caret_at_end, |
| 322 bool display_warning_if_disabled) { | 343 bool display_warning_if_disabled) { |
| 323 if (!element.isEnabled() || element.isReadOnly() || !element.autoComplete() || | 344 const WebFormElement form = element.form(); |
| 345 if (!element.isEnabled() || element.isReadOnly() || | |
| 346 (!element.autoComplete() && form.autoComplete()) || | |
|
Ilya Sherman
2011/07/27 23:41:30
nit: This line is rather confusing at a glance, an
honten.org
2011/07/28 00:04:50
Should I use extra bool flag like this?
// We sho
Ilya Sherman
2011/07/28 00:29:33
This comment only describes part of the intent. T
honten.org
2011/07/28 06:03:06
Just added comment.
On 2011/07/28 00:29:33, Ilya
| |
| 324 !element.isTextField() || element.isPasswordField() || | 347 !element.isTextField() || element.isPasswordField() || |
| 325 !element.suggestedValue().isEmpty()) | 348 !element.suggestedValue().isEmpty()) |
| 326 return; | 349 return; |
| 327 | 350 |
| 328 // If the field has no name, then we won't have values. | 351 // If the field has no name, then we won't have values. |
| 329 if (element.nameForAutofill().isEmpty()) | 352 if (element.nameForAutofill().isEmpty()) |
| 330 return; | 353 return; |
| 331 | 354 |
| 332 // Don't attempt to autofill with values that are too large. | 355 // Don't attempt to autofill with values that are too large. |
| 333 WebString value = element.value(); | 356 WebString value = element.value(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 // WebFormControlElementToFormField does not scrape the DOM for the field | 420 // WebFormControlElementToFormField does not scrape the DOM for the field |
| 398 // label, so find the label here. | 421 // label, so find the label here. |
| 399 // TODO(isherman): Add form and field identities so we can use the cached form | 422 // TODO(isherman): Add form and field identities so we can use the cached form |
| 400 // data in FormManager. | 423 // data in FormManager. |
| 401 field->label = FormManager::LabelForElement(element); | 424 field->label = FormManager::LabelForElement(element); |
| 402 | 425 |
| 403 return true; | 426 return true; |
| 404 } | 427 } |
| 405 | 428 |
| 406 } // namespace autofill | 429 } // namespace autofill |
| OLD | NEW |