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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 base::TimeTicks::Now())); | 207 base::TimeTicks::Now())); |
208 } | 208 } |
209 } | 209 } |
210 | 210 |
211 void AutofillAgent::DidChangeScrollOffset() { | 211 void AutofillAgent::DidChangeScrollOffset() { |
212 HidePopup(); | 212 HidePopup(); |
213 } | 213 } |
214 | 214 |
215 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { | 215 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { |
216 HidePopup(); | 216 HidePopup(); |
217 element_.reset(); | |
Garrett Casto
2015/01/06 20:01:09
Is this safe? |element_| is mostly used to display
please use gerrit instead
2015/01/13 02:14:55
On a second look, nulling |element_| is not requir
| |
217 | 218 |
218 if (node.isNull() || !node.isElementNode()) | 219 if (node.isNull() || !node.isElementNode()) |
219 return; | 220 return; |
220 | 221 |
221 if (node.document().frame() != render_frame()->GetWebFrame()) | 222 if (node.document().frame() != render_frame()->GetWebFrame()) |
222 return; | 223 return; |
223 | 224 |
224 if (password_generation_agent_ && | |
225 password_generation_agent_->FocusedNodeHasChanged(node)) { | |
226 is_popup_possibly_visible_ = true; | |
227 return; | |
228 } | |
229 | |
230 WebElement web_element = node.toConst<WebElement>(); | 225 WebElement web_element = node.toConst<WebElement>(); |
231 | 226 |
232 if (!web_element.document().frame()) | 227 if (!web_element.document().frame()) |
233 return; | 228 return; |
234 | 229 |
235 const WebInputElement* element = toWebInputElement(&web_element); | 230 const WebInputElement* element = toWebInputElement(&web_element); |
236 | 231 |
237 if (!element || !element->isEnabled() || element->isReadOnly() || | 232 if (!element || !element->isEnabled() || element->isReadOnly() || |
238 !element->isTextField() || element->isPasswordField()) | 233 !element->isTextField()) |
239 return; | 234 return; |
240 | 235 |
241 element_ = *element; | 236 element_ = *element; |
242 } | 237 } |
243 | 238 |
244 void AutofillAgent::Resized() { | 239 void AutofillAgent::FocusedElementMovedOnResize() { |
245 HidePopup(); | 240 HidePopup(); |
246 } | 241 } |
247 | 242 |
243 void AutofillAgent::FocusChangeComplete() { | |
244 if (!element_.isNull() && password_generation_agent_ && | |
245 password_generation_agent_->FocusedNodeHasChanged(element_)) { | |
246 is_popup_possibly_visible_ = true; | |
247 } | |
248 } | |
249 | |
248 void AutofillAgent::LegacyFrameWillClose(blink::WebFrame* frame) { | 250 void AutofillAgent::LegacyFrameWillClose(blink::WebFrame* frame) { |
249 if (in_flight_request_form_.isNull()) | 251 if (in_flight_request_form_.isNull()) |
250 return; | 252 return; |
251 | 253 |
252 for (blink::WebFrame* temp = render_frame()->GetWebFrame(); temp; | 254 for (blink::WebFrame* temp = render_frame()->GetWebFrame(); temp; |
253 temp = temp->parent()) { | 255 temp = temp->parent()) { |
254 if (temp == frame) { | 256 if (temp == frame) { |
255 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id())); | 257 Send(new AutofillHostMsg_CancelRequestAutocomplete(routing_id())); |
256 break; | 258 break; |
257 } | 259 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 | 332 |
331 ShowSuggestionsOptions options; | 333 ShowSuggestionsOptions options; |
332 options.autofill_on_empty_values = true; | 334 options.autofill_on_empty_values = true; |
333 options.display_warning_if_disabled = true; | 335 options.display_warning_if_disabled = true; |
334 options.show_full_suggestion_list = element.isAutofilled(); | 336 options.show_full_suggestion_list = element.isAutofilled(); |
335 | 337 |
336 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 338 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
337 switches::kEnableSingleClickAutofill)) { | 339 switches::kEnableSingleClickAutofill)) { |
338 // Show full suggestions when clicking on an already-focused form field. On | 340 // Show full suggestions when clicking on an already-focused form field. On |
339 // the initial click (not focused yet), only show password suggestions. | 341 // the initial click (not focused yet), only show password suggestions. |
340 #if defined(OS_ANDROID) | |
341 // TODO(gcasto): Remove after crbug.com/430318 has been fixed. | |
342 if (!was_focused) | |
343 return; | |
344 #endif | |
345 | |
346 options.show_full_suggestion_list = | 342 options.show_full_suggestion_list = |
347 options.show_full_suggestion_list || was_focused; | 343 options.show_full_suggestion_list || was_focused; |
348 options.show_password_suggestions_only = !was_focused; | 344 options.show_password_suggestions_only = !was_focused; |
349 } | 345 } |
350 ShowSuggestions(element, options); | 346 ShowSuggestions(element, options); |
351 } | 347 } |
352 | 348 |
353 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { | 349 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { |
354 password_autofill_agent_->TextFieldDidEndEditing(element); | 350 password_autofill_agent_->TextFieldDidEndEditing(element); |
355 has_shown_autofill_popup_for_current_edit_ = false; | 351 has_shown_autofill_popup_for_current_edit_ = false; |
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
803 | 799 |
804 void AutofillAgent::LegacyAutofillAgent::FrameDetached(WebFrame* frame) { | 800 void AutofillAgent::LegacyAutofillAgent::FrameDetached(WebFrame* frame) { |
805 agent_->FrameDetached(frame); | 801 agent_->FrameDetached(frame); |
806 } | 802 } |
807 | 803 |
808 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( | 804 void AutofillAgent::LegacyAutofillAgent::FocusedNodeChanged( |
809 const WebNode& node) { | 805 const WebNode& node) { |
810 agent_->FocusedNodeChanged(node); | 806 agent_->FocusedNodeChanged(node); |
811 } | 807 } |
812 | 808 |
813 void AutofillAgent::LegacyAutofillAgent::Resized() { | 809 void AutofillAgent::LegacyAutofillAgent::FocusedElementMovedOnResize() { |
814 agent_->Resized(); | 810 agent_->FocusedElementMovedOnResize(); |
811 } | |
812 | |
813 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { | |
814 agent_->FocusChangeComplete(); | |
815 } | 815 } |
816 | 816 |
817 void AutofillAgent::LegacyAutofillAgent::FrameWillClose( | 817 void AutofillAgent::LegacyAutofillAgent::FrameWillClose( |
818 blink::WebFrame* frame) { | 818 blink::WebFrame* frame) { |
819 agent_->LegacyFrameWillClose(frame); | 819 agent_->LegacyFrameWillClose(frame); |
820 } | 820 } |
821 | 821 |
822 } // namespace autofill | 822 } // namespace autofill |
OLD | NEW |