| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/renderer/autofill_agent.h" | 5 #include "components/autofill/content/renderer/autofill_agent.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 42 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 43 #include "third_party/WebKit/public/web/WebNode.h" | 43 #include "third_party/WebKit/public/web/WebNode.h" |
| 44 #include "third_party/WebKit/public/web/WebOptionElement.h" | 44 #include "third_party/WebKit/public/web/WebOptionElement.h" |
| 45 #include "third_party/WebKit/public/web/WebTextAreaElement.h" | 45 #include "third_party/WebKit/public/web/WebTextAreaElement.h" |
| 46 #include "third_party/WebKit/public/web/WebView.h" | 46 #include "third_party/WebKit/public/web/WebView.h" |
| 47 #include "ui/base/l10n/l10n_util.h" | 47 #include "ui/base/l10n/l10n_util.h" |
| 48 #include "ui/events/keycodes/keyboard_codes.h" | 48 #include "ui/events/keycodes/keyboard_codes.h" |
| 49 | 49 |
| 50 using blink::WebAutofillClient; | 50 using blink::WebAutofillClient; |
| 51 using blink::WebConsoleMessage; | 51 using blink::WebConsoleMessage; |
| 52 using blink::WebDocument; |
| 52 using blink::WebElement; | 53 using blink::WebElement; |
| 53 using blink::WebElementCollection; | 54 using blink::WebElementCollection; |
| 54 using blink::WebFormControlElement; | 55 using blink::WebFormControlElement; |
| 55 using blink::WebFormElement; | 56 using blink::WebFormElement; |
| 56 using blink::WebFrame; | 57 using blink::WebFrame; |
| 57 using blink::WebInputElement; | 58 using blink::WebInputElement; |
| 58 using blink::WebKeyboardEvent; | 59 using blink::WebKeyboardEvent; |
| 59 using blink::WebLocalFrame; | 60 using blink::WebLocalFrame; |
| 60 using blink::WebNode; | 61 using blink::WebNode; |
| 61 using blink::WebOptionElement; | 62 using blink::WebOptionElement; |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 208 |
| 208 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 209 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
| 209 HidePopup(); | 210 HidePopup(); |
| 210 | 211 |
| 211 if (node.isNull() || !node.isElementNode()) | 212 if (node.isNull() || !node.isElementNode()) |
| 212 return; | 213 return; |
| 213 | 214 |
| 214 if (node.document().frame() != render_frame()->GetWebFrame()) | 215 if (node.document().frame() != render_frame()->GetWebFrame()) |
| 215 return; | 216 return; |
| 216 | 217 |
| 217 if (password_generation_agent_ && | |
| 218 password_generation_agent_->FocusedNodeHasChanged(node)) { | |
| 219 is_popup_possibly_visible_ = true; | |
| 220 return; | |
| 221 } | |
| 222 | |
| 223 WebElement web_element = node.toConst<WebElement>(); | 218 WebElement web_element = node.toConst<WebElement>(); |
| 224 | 219 |
| 225 if (!web_element.document().frame()) | 220 if (!web_element.document().frame()) |
| 226 return; | 221 return; |
| 227 | 222 |
| 228 const WebInputElement* element = toWebInputElement(&web_element); | 223 const WebInputElement* element = toWebInputElement(&web_element); |
| 229 | 224 |
| 230 if (!element || !element->isEnabled() || element->isReadOnly() || | 225 if (!element || !element->isEnabled() || element->isReadOnly() || |
| 231 !element->isTextField() || element->isPasswordField()) | 226 !element->isTextField()) |
| 232 return; | 227 return; |
| 233 | 228 |
| 234 element_ = *element; | 229 element_ = *element; |
| 235 } | 230 } |
| 236 | 231 |
| 237 void AutofillAgent::Resized() { | 232 void AutofillAgent::FocusedElementMovedOnResize() { |
| 238 HidePopup(); | 233 HidePopup(); |
| 239 } | 234 } |
| 240 | 235 |
| 236 void AutofillAgent::FocusChangeComplete() { |
| 237 WebDocument doc = render_frame()->GetWebFrame()->document(); |
| 238 WebElement focused_element; |
| 239 if (!doc.isNull()) |
| 240 focused_element = doc.focusedElement(); |
| 241 |
| 242 if (!focused_element.isNull() && password_generation_agent_ && |
| 243 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { |
| 244 is_popup_possibly_visible_ = true; |
| 245 } |
| 246 } |
| 247 |
| 241 void AutofillAgent::didRequestAutocomplete( | 248 void AutofillAgent::didRequestAutocomplete( |
| 242 const WebFormElement& form) { | 249 const WebFormElement& form) { |
| 243 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); | 250 DCHECK_EQ(form.document().frame(), render_frame()->GetWebFrame()); |
| 244 | 251 |
| 245 // Disallow the dialog over non-https or broken https, except when the | 252 // Disallow the dialog over non-https or broken https, except when the |
| 246 // ignore SSL flag is passed. See http://crbug.com/272512. | 253 // ignore SSL flag is passed. See http://crbug.com/272512. |
| 247 // TODO(palmer): this should be moved to the browser process after frames | 254 // TODO(palmer): this should be moved to the browser process after frames |
| 248 // get their own processes. | 255 // get their own processes. |
| 249 GURL url(form.document().url()); | 256 GURL url(form.document().url()); |
| 250 content::SSLStatus ssl_status = | 257 content::SSLStatus ssl_status = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 | 316 |
| 310 ShowSuggestionsOptions options; | 317 ShowSuggestionsOptions options; |
| 311 options.autofill_on_empty_values = true; | 318 options.autofill_on_empty_values = true; |
| 312 options.display_warning_if_disabled = true; | 319 options.display_warning_if_disabled = true; |
| 313 options.show_full_suggestion_list = element.isAutofilled(); | 320 options.show_full_suggestion_list = element.isAutofilled(); |
| 314 | 321 |
| 315 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 322 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 316 switches::kEnableSingleClickAutofill)) { | 323 switches::kEnableSingleClickAutofill)) { |
| 317 // Show full suggestions when clicking on an already-focused form field. On | 324 // Show full suggestions when clicking on an already-focused form field. On |
| 318 // the initial click (not focused yet), only show password suggestions. | 325 // the initial click (not focused yet), only show password suggestions. |
| 319 #if defined(OS_ANDROID) | |
| 320 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. | |
| 321 if (!was_focused) | |
| 322 return; | |
| 323 #endif | |
| 324 | |
| 325 options.show_full_suggestion_list = | 326 options.show_full_suggestion_list = |
| 326 options.show_full_suggestion_list || was_focused; | 327 options.show_full_suggestion_list || was_focused; |
| 327 options.show_password_suggestions_only = !was_focused; | 328 options.show_password_suggestions_only = !was_focused; |
| 328 } | 329 } |
| 329 ShowSuggestions(element, options); | 330 ShowSuggestions(element, options); |
| 330 } | 331 } |
| 331 | 332 |
| 332 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 333 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
| 333 password_autofill_agent_->TextFieldDidEndEditing(element); | 334 password_autofill_agent_->TextFieldDidEndEditing(element); |
| 334 has_shown_autofill_popup_for_current_edit_ = false; | 335 has_shown_autofill_popup_for_current_edit_ = false; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 | 779 |
| 779 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { | 780 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { |
| 780 // No-op. Don't delete |this|. | 781 // No-op. Don't delete |this|. |
| 781 } | 782 } |
| 782 | 783 |
| 783 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( | 784 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( |
| 784 const WebNode& node) { | 785 const WebNode& node) { |
| 785 agent_->FocusedNodeChanged(node); | 786 agent_->FocusedNodeChanged(node); |
| 786 } | 787 } |
| 787 | 788 |
| 788 void AutofillAgent::LegacyAutofillAgent::Resized() { | 789 void AutofillAgent::LegacyAutofillAgent::FocusedElementMovedOnResize() { |
| 789 agent_->Resized(); | 790 agent_->FocusedElementMovedOnResize(); |
| 791 } |
| 792 |
| 793 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { |
| 794 agent_->FocusChangeComplete(); |
| 790 } | 795 } |
| 791 | 796 |
| 792 } // namespace autofill | 797 } // namespace autofill |
| OLD | NEW |