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

Side by Side Diff: components/autofill/content/renderer/autofill_agent.cc

Issue 2007473004: [Autofill] Migrate ContentAutofillDriver<-->AutofillAgent IPCs to mojo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase only Created 4 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
OLDNEW
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 24 matching lines...) Expand all
35 #include "components/autofill/core/common/form_data_predictions.h" 35 #include "components/autofill/core/common/form_data_predictions.h"
36 #include "components/autofill/core/common/form_field_data.h" 36 #include "components/autofill/core/common/form_field_data.h"
37 #include "components/autofill/core/common/password_form.h" 37 #include "components/autofill/core/common/password_form.h"
38 #include "components/autofill/core/common/password_form_fill_data.h" 38 #include "components/autofill/core/common/password_form_fill_data.h"
39 #include "components/autofill/core/common/save_password_progress_logger.h" 39 #include "components/autofill/core/common/save_password_progress_logger.h"
40 #include "content/public/common/content_switches.h" 40 #include "content/public/common/content_switches.h"
41 #include "content/public/common/ssl_status.h" 41 #include "content/public/common/ssl_status.h"
42 #include "content/public/common/url_constants.h" 42 #include "content/public/common/url_constants.h"
43 #include "content/public/renderer/render_frame.h" 43 #include "content/public/renderer/render_frame.h"
44 #include "content/public/renderer/render_view.h" 44 #include "content/public/renderer/render_view.h"
45 #include "mojo/common/common_type_converters.h"
45 #include "net/cert/cert_status_flags.h" 46 #include "net/cert/cert_status_flags.h"
46 #include "services/shell/public/cpp/interface_provider.h" 47 #include "services/shell/public/cpp/interface_provider.h"
47 #include "services/shell/public/cpp/interface_registry.h" 48 #include "services/shell/public/cpp/interface_registry.h"
48 #include "third_party/WebKit/public/platform/WebURLRequest.h" 49 #include "third_party/WebKit/public/platform/WebURLRequest.h"
49 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 50 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
50 #include "third_party/WebKit/public/web/WebDataSource.h" 51 #include "third_party/WebKit/public/web/WebDataSource.h"
51 #include "third_party/WebKit/public/web/WebDocument.h" 52 #include "third_party/WebKit/public/web/WebDocument.h"
52 #include "third_party/WebKit/public/web/WebElementCollection.h" 53 #include "third_party/WebKit/public/web/WebElementCollection.h"
53 #include "third_party/WebKit/public/web/WebFormControlElement.h" 54 #include "third_party/WebKit/public/web/WebFormControlElement.h"
54 #include "third_party/WebKit/public/web/WebFormElement.h" 55 #include "third_party/WebKit/public/web/WebFormElement.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 : content::RenderFrameObserver(render_frame), 171 : content::RenderFrameObserver(render_frame),
171 form_cache_(*render_frame->GetWebFrame()), 172 form_cache_(*render_frame->GetWebFrame()),
172 password_autofill_agent_(password_autofill_agent), 173 password_autofill_agent_(password_autofill_agent),
173 password_generation_agent_(password_generation_agent), 174 password_generation_agent_(password_generation_agent),
174 legacy_(render_frame->GetRenderView(), this), 175 legacy_(render_frame->GetRenderView(), this),
175 autofill_query_id_(0), 176 autofill_query_id_(0),
176 was_query_node_autofilled_(false), 177 was_query_node_autofilled_(false),
177 ignore_text_changes_(false), 178 ignore_text_changes_(false),
178 is_popup_possibly_visible_(false), 179 is_popup_possibly_visible_(false),
179 is_generation_popup_possibly_visible_(false), 180 is_generation_popup_possibly_visible_(false),
181 binding_(this),
180 weak_ptr_factory_(this) { 182 weak_ptr_factory_(this) {
181 render_frame->GetWebFrame()->setAutofillClient(this); 183 render_frame->GetWebFrame()->setAutofillClient(this);
184 password_autofill_agent->SetAutofillAgent(this);
182 185
183 // AutofillAgent is guaranteed to outlive |render_frame|. 186 // AutofillAgent is guaranteed to outlive |render_frame|.
184 render_frame->GetInterfaceRegistry()->AddInterface( 187 render_frame->GetInterfaceRegistry()->AddInterface(
185 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this))); 188 base::Bind(&AutofillAgent::BindRequest, base::Unretained(this)));
186 189
187 // This owns itself, and will delete itself when |render_frame| is destructed 190 // This owns itself, and will delete itself when |render_frame| is destructed
188 // (same as AutofillAgent). This object must be constructed after 191 // (same as AutofillAgent). This object must be constructed after
189 // AutofillAgent so that password generation UI is shown before password 192 // AutofillAgent so that password generation UI is shown before password
190 // manager UI (see https://crbug.com/498545). 193 // manager UI (see https://crbug.com/498545).
191 new PageClickTracker(render_frame, this); 194 new PageClickTracker(render_frame, this);
192 } 195 }
193 196
194 AutofillAgent::~AutofillAgent() {} 197 AutofillAgent::~AutofillAgent() {}
195 198
196 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) { 199 void AutofillAgent::BindRequest(mojom::AutofillAgentRequest request) {
197 bindings_.AddBinding(this, std::move(request)); 200 binding_.Bind(std::move(request));
198 } 201 }
199 202
200 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs, 203 bool AutofillAgent::FormDataCompare::operator()(const FormData& lhs,
201 const FormData& rhs) const { 204 const FormData& rhs) const {
202 return std::tie(lhs.name, lhs.origin, lhs.action, lhs.is_form_tag) < 205 return std::tie(lhs.name, lhs.origin, lhs.action, lhs.is_form_tag) <
203 std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag); 206 std::tie(rhs.name, rhs.origin, rhs.action, rhs.is_form_tag);
204 } 207 }
205 208
206 bool AutofillAgent::OnMessageReceived(const IPC::Message& message) {
207 bool handled = true;
208 IPC_BEGIN_MESSAGE_MAP(AutofillAgent, message)
209 IPC_MESSAGE_HANDLER(AutofillMsg_FillForm, OnFillForm)
210 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewForm, OnPreviewForm)
211 IPC_MESSAGE_HANDLER(AutofillMsg_FieldTypePredictionsAvailable,
212 OnFieldTypePredictionsAvailable)
213 IPC_MESSAGE_HANDLER(AutofillMsg_ClearForm, OnClearForm)
214 IPC_MESSAGE_HANDLER(AutofillMsg_ClearPreviewedForm, OnClearPreviewedForm)
215 IPC_MESSAGE_HANDLER(AutofillMsg_FillFieldWithValue, OnFillFieldWithValue)
216 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewFieldWithValue,
217 OnPreviewFieldWithValue)
218 IPC_MESSAGE_HANDLER(AutofillMsg_AcceptDataListSuggestion,
219 OnAcceptDataListSuggestion)
220 IPC_MESSAGE_HANDLER(AutofillMsg_FillPasswordSuggestion,
221 OnFillPasswordSuggestion)
222 IPC_MESSAGE_HANDLER(AutofillMsg_PreviewPasswordSuggestion,
223 OnPreviewPasswordSuggestion)
224 IPC_MESSAGE_HANDLER(AutofillMsg_ShowInitialPasswordAccountSuggestions,
225 OnShowInitialPasswordAccountSuggestions);
226 IPC_MESSAGE_UNHANDLED(handled = false)
227 IPC_END_MESSAGE_MAP()
228 return handled;
229 }
230
231 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation, 209 void AutofillAgent::DidCommitProvisionalLoad(bool is_new_navigation,
232 bool is_same_page_navigation) { 210 bool is_same_page_navigation) {
233 blink::WebFrame* frame = render_frame()->GetWebFrame(); 211 blink::WebFrame* frame = render_frame()->GetWebFrame();
234 // TODO(dvadym): check if we need to check if it is main frame navigation 212 // TODO(dvadym): check if we need to check if it is main frame navigation
235 // http://crbug.com/443155 213 // http://crbug.com/443155
236 if (frame->parent()) 214 if (frame->parent())
237 return; // Not a top-level navigation. 215 return; // Not a top-level navigation.
238 216
239 if (is_same_page_navigation) { 217 if (is_same_page_navigation) {
240 OnSamePageNavigationCompleted(); 218 OnSamePageNavigationCompleted();
(...skipping 25 matching lines...) Expand all
266 HidePopup(); 244 HidePopup();
267 } 245 }
268 246
269 void AutofillAgent::FocusedNodeChanged(const WebNode& node) { 247 void AutofillAgent::FocusedNodeChanged(const WebNode& node) {
270 HidePopup(); 248 HidePopup();
271 249
272 if (node.isNull() || !node.isElementNode()) { 250 if (node.isNull() || !node.isElementNode()) {
273 if (!last_interacted_form_.isNull()) { 251 if (!last_interacted_form_.isNull()) {
274 // Focus moved away from the last interacted form to somewhere else on 252 // Focus moved away from the last interacted form to somewhere else on
275 // the page. 253 // the page.
276 Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id())); 254 GetAutofillDriver()->FocusNoLongerOnForm();
277 } 255 }
278 return; 256 return;
279 } 257 }
280 258
281 WebElement web_element = node.toConst<WebElement>(); 259 WebElement web_element = node.toConst<WebElement>();
282 const WebInputElement* element = toWebInputElement(&web_element); 260 const WebInputElement* element = toWebInputElement(&web_element);
283 261
284 if (!last_interacted_form_.isNull() && 262 if (!last_interacted_form_.isNull() &&
285 (!element || last_interacted_form_ != element->form())) { 263 (!element || last_interacted_form_ != element->form())) {
286 // The focused element is not part of the last interacted form (could be 264 // The focused element is not part of the last interacted form (could be
287 // in a different form). 265 // in a different form).
288 Send(new AutofillHostMsg_FocusNoLongerOnForm(routing_id())); 266 GetAutofillDriver()->FocusNoLongerOnForm();
289 return; 267 return;
290 } 268 }
291 269
292 if (!element || !element->isEnabled() || element->isReadOnly() || 270 if (!element || !element->isEnabled() || element->isReadOnly() ||
293 !element->isTextField()) 271 !element->isTextField())
294 return; 272 return;
295 273
296 element_ = *element; 274 element_ = *element;
297 } 275 }
298 276
(...skipping 10 matching lines...) Expand all
309 287
310 FireHostSubmitEvents(form_data, form_submitted); 288 FireHostSubmitEvents(form_data, form_submitted);
311 } 289 }
312 290
313 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data, 291 void AutofillAgent::FireHostSubmitEvents(const FormData& form_data,
314 bool form_submitted) { 292 bool form_submitted) {
315 // We remember when we have fired this IPC for this form in this frame load, 293 // We remember when we have fired this IPC for this form in this frame load,
316 // because forms with a submit handler may fire both WillSendSubmitEvent 294 // because forms with a submit handler may fire both WillSendSubmitEvent
317 // and WillSubmitForm, and we don't want duplicate messages. 295 // and WillSubmitForm, and we don't want duplicate messages.
318 if (!submitted_forms_.count(form_data)) { 296 if (!submitted_forms_.count(form_data)) {
319 Send(new AutofillHostMsg_WillSubmitForm(routing_id(), form_data, 297 GetAutofillDriver()->WillSubmitForm(form_data, base::TimeTicks::Now());
320 base::TimeTicks::Now()));
321 submitted_forms_.insert(form_data); 298 submitted_forms_.insert(form_data);
322 } 299 }
323 300
324 if (form_submitted) 301 if (form_submitted) {
325 Send(new AutofillHostMsg_FormSubmitted(routing_id(), form_data)); 302 GetAutofillDriver()->FormSubmitted(form_data);
303 }
326 } 304 }
327 305
328 void AutofillAgent::Shutdown() { 306 void AutofillAgent::Shutdown() {
329 legacy_.Shutdown(); 307 legacy_.Shutdown();
330 weak_ptr_factory_.InvalidateWeakPtrs(); 308 weak_ptr_factory_.InvalidateWeakPtrs();
331 } 309 }
332 310
333 void AutofillAgent::FocusChangeComplete() { 311 void AutofillAgent::FocusChangeComplete() {
334 WebDocument doc = render_frame()->GetWebFrame()->document(); 312 WebDocument doc = render_frame()->GetWebFrame()->document();
335 WebElement focused_element; 313 WebElement focused_element;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // the initial click (not focused yet), only show password suggestions. 345 // the initial click (not focused yet), only show password suggestions.
368 options.show_full_suggestion_list = 346 options.show_full_suggestion_list =
369 options.show_full_suggestion_list || was_focused; 347 options.show_full_suggestion_list || was_focused;
370 options.show_password_suggestions_only = !was_focused; 348 options.show_password_suggestions_only = !was_focused;
371 } 349 }
372 ShowSuggestions(element, options); 350 ShowSuggestions(element, options);
373 } 351 }
374 352
375 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) { 353 void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
376 password_autofill_agent_->TextFieldDidEndEditing(element); 354 password_autofill_agent_->TextFieldDidEndEditing(element);
377 Send(new AutofillHostMsg_DidEndTextFieldEditing(routing_id())); 355 GetAutofillDriver()->DidEndTextFieldEditing();
378 } 356 }
379 357
380 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) { 358 void AutofillAgent::textFieldDidChange(const WebFormControlElement& element) {
381 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element)); 359 DCHECK(toWebInputElement(&element) || form_util::IsTextAreaElement(element));
382 360
383 if (ignore_text_changes_) 361 if (ignore_text_changes_)
384 return; 362 return;
385 363
386 // Disregard text changes that aren't caused by user gestures or pastes. Note 364 // Disregard text changes that aren't caused by user gestures or pastes. Note
387 // that pastes aren't necessarily user gestures because Blink's conception of 365 // that pastes aren't necessarily user gestures because Blink's conception of
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 } 410 }
433 411
434 ShowSuggestionsOptions options; 412 ShowSuggestionsOptions options;
435 options.requires_caret_at_end = true; 413 options.requires_caret_at_end = true;
436 ShowSuggestions(element, options); 414 ShowSuggestions(element, options);
437 415
438 FormData form; 416 FormData form;
439 FormFieldData field; 417 FormFieldData field;
440 if (form_util::FindFormAndFieldForFormControlElement(element, &form, 418 if (form_util::FindFormAndFieldForFormControlElement(element, &form,
441 &field)) { 419 &field)) {
442 Send(new AutofillHostMsg_TextFieldDidChange(routing_id(), form, field, 420 GetAutofillDriver()->TextFieldDidChange(form, field,
443 base::TimeTicks::Now())); 421 base::TimeTicks::Now());
444 } 422 }
445 } 423 }
446 424
447 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element, 425 void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
448 const WebKeyboardEvent& event) { 426 const WebKeyboardEvent& event) {
449 if (event.windowsKeyCode == ui::VKEY_DOWN || 427 if (event.windowsKeyCode == ui::VKEY_DOWN ||
450 event.windowsKeyCode == ui::VKEY_UP) { 428 event.windowsKeyCode == ui::VKEY_UP) {
451 ShowSuggestionsOptions options; 429 ShowSuggestionsOptions options;
452 options.autofill_on_empty_values = true; 430 options.autofill_on_empty_values = true;
453 options.requires_caret_at_end = true; 431 options.requires_caret_at_end = true;
(...skipping 10 matching lines...) Expand all
464 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) { 442 void AutofillAgent::dataListOptionsChanged(const WebInputElement& element) {
465 if (!is_popup_possibly_visible_ || !element.focused()) 443 if (!is_popup_possibly_visible_ || !element.focused())
466 return; 444 return;
467 445
468 TextFieldDidChangeImpl(element); 446 TextFieldDidChangeImpl(element);
469 } 447 }
470 448
471 void AutofillAgent::firstUserGestureObserved() { 449 void AutofillAgent::firstUserGestureObserved() {
472 password_autofill_agent_->FirstUserGestureObserved(); 450 password_autofill_agent_->FirstUserGestureObserved();
473 451
474 ConnectToMojoAutofillDriverIfNeeded(); 452 GetAutofillDriver()->FirstUserGestureObserved();
475 mojo_autofill_driver_->FirstUserGestureObserved();
476 } 453 }
477 454
478 void AutofillAgent::AcceptDataListSuggestion( 455 void AutofillAgent::DoAcceptDataListSuggestion(
479 const base::string16& suggested_value) { 456 const base::string16& suggested_value) {
480 WebInputElement* input_element = toWebInputElement(&element_); 457 WebInputElement* input_element = toWebInputElement(&element_);
481 DCHECK(input_element); 458 DCHECK(input_element);
482 base::string16 new_value = suggested_value; 459 base::string16 new_value = suggested_value;
483 // If this element takes multiple values then replace the last part with 460 // If this element takes multiple values then replace the last part with
484 // the suggestion. 461 // the suggestion.
485 if (input_element->isMultiple() && input_element->isEmailField()) { 462 if (input_element->isMultiple() && input_element->isEmailField()) {
486 std::vector<base::string16> parts = base::SplitString( 463 std::vector<base::string16> parts = base::SplitString(
487 base::StringPiece16(input_element->editingValue()), 464 base::StringPiece16(input_element->editingValue()),
488 base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); 465 base::ASCIIToUTF16(","), base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
489 if (parts.size() == 0) 466 if (parts.size() == 0)
490 parts.push_back(base::string16()); 467 parts.push_back(base::string16());
491 468
492 base::string16 last_part = parts.back(); 469 base::string16 last_part = parts.back();
493 // We want to keep just the leading whitespace. 470 // We want to keep just the leading whitespace.
494 for (size_t i = 0; i < last_part.size(); ++i) { 471 for (size_t i = 0; i < last_part.size(); ++i) {
495 if (!base::IsUnicodeWhitespace(last_part[i])) { 472 if (!base::IsUnicodeWhitespace(last_part[i])) {
496 last_part = last_part.substr(0, i); 473 last_part = last_part.substr(0, i);
497 break; 474 break;
498 } 475 }
499 } 476 }
500 last_part.append(suggested_value); 477 last_part.append(suggested_value);
501 parts.back() = last_part; 478 parts.back() = last_part;
502 479
503 new_value = base::JoinString(parts, base::ASCIIToUTF16(",")); 480 new_value = base::JoinString(parts, base::ASCIIToUTF16(","));
504 } 481 }
505 FillFieldWithValue(new_value, input_element); 482 DoFillFieldWithValue(new_value, input_element);
506 } 483 }
507 484
508 void AutofillAgent::OnFieldTypePredictionsAvailable( 485 // mojom::AutofillAgent:
509 const std::vector<FormDataPredictions>& forms) { 486 void AutofillAgent::FirstUserGestureObservedInTab() {
510 for (size_t i = 0; i < forms.size(); ++i) { 487 password_autofill_agent_->FirstUserGestureObserved();
511 form_cache_.ShowPredictions(forms[i]);
512 }
513 } 488 }
514 489
515 void AutofillAgent::OnFillForm(int query_id, const FormData& form) { 490 void AutofillAgent::FillForm(int32_t id, const FormData& form) {
516 if (query_id != autofill_query_id_) 491 if (id != autofill_query_id_)
517 return; 492 return;
518 493
519 was_query_node_autofilled_ = element_.isAutofilled(); 494 was_query_node_autofilled_ = element_.isAutofilled();
520 form_util::FillForm(form, element_); 495 form_util::FillForm(form, element_);
521 if (!element_.form().isNull()) 496 if (!element_.form().isNull())
522 last_interacted_form_ = element_.form(); 497 last_interacted_form_ = element_.form();
523 498
524 Send(new AutofillHostMsg_DidFillAutofillFormData(routing_id(), form, 499 GetAutofillDriver()->DidFillAutofillFormData(form, base::TimeTicks::Now());
525 base::TimeTicks::Now()));
526 } 500 }
527 501
528 // mojom::AutofillAgent: 502 void AutofillAgent::PreviewForm(int32_t id, const FormData& form) {
529 void AutofillAgent::FirstUserGestureObservedInTab() { 503 if (id != autofill_query_id_)
530 password_autofill_agent_->FirstUserGestureObserved();
531 }
532
533 void AutofillAgent::OnPing() {
534 Send(new AutofillHostMsg_PingAck(routing_id()));
535 }
536
537 void AutofillAgent::OnPreviewForm(int query_id, const FormData& form) {
538 if (query_id != autofill_query_id_)
539 return; 504 return;
540 505
541 was_query_node_autofilled_ = element_.isAutofilled(); 506 was_query_node_autofilled_ = element_.isAutofilled();
542 form_util::PreviewForm(form, element_); 507 form_util::PreviewForm(form, element_);
543 Send(new AutofillHostMsg_DidPreviewAutofillFormData(routing_id())); 508
509 GetAutofillDriver()->DidPreviewAutofillFormData();
544 } 510 }
545 511
546 void AutofillAgent::OnClearForm() { 512 void AutofillAgent::OnPing() {
513 GetAutofillDriver()->PingAck();
514 }
515
516 void AutofillAgent::FieldTypePredictionsAvailable(
517 mojo::Array<FormDataPredictions> forms) {
518 for (size_t i = 0; i < forms.size(); ++i) {
dcheng 2016/07/12 14:22:12 Nit: I think ranged-based for loops work with mojo
leonhsl(Using Gerrit) 2016/07/13 03:48:30 Done.
519 form_cache_.ShowPredictions(forms[i]);
520 }
521 }
522
523 void AutofillAgent::ClearForm() {
547 form_cache_.ClearFormWithElement(element_); 524 form_cache_.ClearFormWithElement(element_);
548 } 525 }
549 526
550 void AutofillAgent::OnClearPreviewedForm() { 527 void AutofillAgent::ClearPreviewedForm() {
551 if (!element_.isNull()) { 528 if (!element_.isNull()) {
552 if (password_autofill_agent_->DidClearAutofillSelection(element_)) 529 if (password_autofill_agent_->DidClearAutofillSelection(element_))
553 return; 530 return;
554 531
555 form_util::ClearPreviewedFormWithElement(element_, 532 form_util::ClearPreviewedFormWithElement(element_,
556 was_query_node_autofilled_); 533 was_query_node_autofilled_);
557 } else { 534 } else {
558 // TODO(isherman): There seem to be rare cases where this code *is* 535 // TODO(isherman): There seem to be rare cases where this code *is*
559 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would 536 // reachable: see [ http://crbug.com/96321#c6 ]. Ideally we would
560 // understand those cases and fix the code to avoid them. However, so far I 537 // understand those cases and fix the code to avoid them. However, so far I
561 // have been unable to reproduce such a case locally. If you hit this 538 // have been unable to reproduce such a case locally. If you hit this
562 // NOTREACHED(), please file a bug against me. 539 // NOTREACHED(), please file a bug against me.
563 NOTREACHED(); 540 NOTREACHED();
564 } 541 }
565 } 542 }
566 543
567 void AutofillAgent::OnFillFieldWithValue(const base::string16& value) { 544 void AutofillAgent::FillFieldWithValue(const mojo::String& value) {
568 WebInputElement* input_element = toWebInputElement(&element_); 545 WebInputElement* input_element = toWebInputElement(&element_);
569 if (input_element) { 546 if (input_element) {
570 FillFieldWithValue(value, input_element); 547 DoFillFieldWithValue(value.To<base::string16>(), input_element);
571 input_element->setAutofilled(true); 548 input_element->setAutofilled(true);
572 } 549 }
573 } 550 }
574 551
575 void AutofillAgent::OnPreviewFieldWithValue(const base::string16& value) { 552 void AutofillAgent::PreviewFieldWithValue(const mojo::String& value) {
576 WebInputElement* input_element = toWebInputElement(&element_); 553 WebInputElement* input_element = toWebInputElement(&element_);
577 if (input_element) 554 if (input_element)
578 PreviewFieldWithValue(value, input_element); 555 DoPreviewFieldWithValue(value.To<base::string16>(), input_element);
579 } 556 }
580 557
581 void AutofillAgent::OnAcceptDataListSuggestion(const base::string16& value) { 558 void AutofillAgent::AcceptDataListSuggestion(const mojo::String& value) {
582 AcceptDataListSuggestion(value); 559 DoAcceptDataListSuggestion(value.To<base::string16>());
583 } 560 }
584 561
585 void AutofillAgent::OnFillPasswordSuggestion(const base::string16& username, 562 void AutofillAgent::FillPasswordSuggestion(const mojo::String& username,
586 const base::string16& password) { 563 const mojo::String& password) {
587 bool handled = password_autofill_agent_->FillSuggestion( 564 bool handled = password_autofill_agent_->FillSuggestion(
588 element_, 565 element_, username.To<base::string16>(), password.To<base::string16>());
589 username,
590 password);
591 DCHECK(handled); 566 DCHECK(handled);
592 } 567 }
593 568
594 void AutofillAgent::OnPreviewPasswordSuggestion( 569 void AutofillAgent::PreviewPasswordSuggestion(const mojo::String& username,
595 const base::string16& username, 570 const mojo::String& password) {
596 const base::string16& password) {
597 bool handled = password_autofill_agent_->PreviewSuggestion( 571 bool handled = password_autofill_agent_->PreviewSuggestion(
598 element_, 572 element_, username.To<base::string16>(), password.To<base::string16>());
599 username,
600 password);
601 DCHECK(handled); 573 DCHECK(handled);
602 } 574 }
603 575
604 void AutofillAgent::OnShowInitialPasswordAccountSuggestions( 576 void AutofillAgent::ShowInitialPasswordAccountSuggestions(
605 int key, 577 int32_t key,
606 const PasswordFormFillData& form_data) { 578 const PasswordFormFillData& form_data) {
607 std::vector<blink::WebInputElement> elements; 579 std::vector<blink::WebInputElement> elements;
608 std::unique_ptr<RendererSavePasswordProgressLogger> logger; 580 std::unique_ptr<RendererSavePasswordProgressLogger> logger;
609 if (password_autofill_agent_->logging_state_active()) { 581 if (password_autofill_agent_->logging_state_active()) {
610 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id())); 582 logger.reset(new RendererSavePasswordProgressLogger(this, routing_id()));
611 logger->LogMessage(SavePasswordProgressLogger:: 583 logger->LogMessage(SavePasswordProgressLogger::
612 STRING_ON_SHOW_INITIAL_PASSWORD_ACCOUNT_SUGGESTIONS); 584 STRING_ON_SHOW_INITIAL_PASSWORD_ACCOUNT_SUGGESTIONS);
613 } 585 }
614 password_autofill_agent_->GetFillableElementFromFormData( 586 password_autofill_agent_->GetFillableElementFromFormData(
615 key, form_data, logger.get(), &elements); 587 key, form_data, logger.get(), &elements);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 if (input_element) { 727 if (input_element) {
756 // Find the datalist values and send them to the browser process. 728 // Find the datalist values and send them to the browser process.
757 GetDataListSuggestions(*input_element, 729 GetDataListSuggestions(*input_element,
758 &data_list_values, 730 &data_list_values,
759 &data_list_labels); 731 &data_list_labels);
760 TrimStringVectorForIPC(&data_list_values); 732 TrimStringVectorForIPC(&data_list_values);
761 TrimStringVectorForIPC(&data_list_labels); 733 TrimStringVectorForIPC(&data_list_labels);
762 } 734 }
763 735
764 is_popup_possibly_visible_ = true; 736 is_popup_possibly_visible_ = true;
765 Send(new AutofillHostMsg_SetDataList(routing_id(),
766 data_list_values,
767 data_list_labels));
768 737
769 Send(new AutofillHostMsg_QueryFormFieldAutofill( 738 GetAutofillDriver()->SetDataList(
770 routing_id(), 739 mojo::Array<mojo::String>::From(data_list_values),
771 autofill_query_id_, 740 mojo::Array<mojo::String>::From(data_list_labels));
772 form, 741 GetAutofillDriver()->QueryFormFieldAutofill(
773 field, 742 autofill_query_id_, form, field,
774 render_frame()->GetRenderView()->ElementBoundsInWindow(element_))); 743 render_frame()->GetRenderView()->ElementBoundsInWindow(element_));
775 } 744 }
776 745
777 void AutofillAgent::FillFieldWithValue(const base::string16& value, 746 void AutofillAgent::DoFillFieldWithValue(const base::string16& value,
778 WebInputElement* node) { 747 WebInputElement* node) {
779 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true); 748 base::AutoReset<bool> auto_reset(&ignore_text_changes_, true);
780 node->setEditingValue(value.substr(0, node->maxLength())); 749 node->setEditingValue(value.substr(0, node->maxLength()));
781 } 750 }
782 751
783 void AutofillAgent::PreviewFieldWithValue(const base::string16& value, 752 void AutofillAgent::DoPreviewFieldWithValue(const base::string16& value,
784 WebInputElement* node) { 753 WebInputElement* node) {
785 was_query_node_autofilled_ = element_.isAutofilled(); 754 was_query_node_autofilled_ = element_.isAutofilled();
786 node->setSuggestedValue(value.substr(0, node->maxLength())); 755 node->setSuggestedValue(value.substr(0, node->maxLength()));
787 node->setAutofilled(true); 756 node->setAutofilled(true);
788 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node); 757 form_util::PreviewSuggestion(node->suggestedValue(), node->value(), node);
789 } 758 }
790 759
791 void AutofillAgent::ProcessForms() { 760 void AutofillAgent::ProcessForms() {
792 // Record timestamp of when the forms are first seen. This is used to 761 // Record timestamp of when the forms are first seen. This is used to
793 // measure the overhead of the Autofill feature. 762 // measure the overhead of the Autofill feature.
794 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now(); 763 base::TimeTicks forms_seen_timestamp = base::TimeTicks::Now();
795 764
796 WebLocalFrame* frame = render_frame()->GetWebFrame(); 765 WebLocalFrame* frame = render_frame()->GetWebFrame();
797 std::vector<FormData> forms = form_cache_.ExtractNewForms(); 766 std::vector<FormData> forms = form_cache_.ExtractNewForms();
798 767
799 // Always communicate to browser process for topmost frame. 768 // Always communicate to browser process for topmost frame.
800 if (!forms.empty() || !frame->parent()) { 769 if (!forms.empty() || !frame->parent()) {
801 Send(new AutofillHostMsg_FormsSeen(routing_id(), forms, 770 GetAutofillDriver()->FormsSeen(std::move(forms), forms_seen_timestamp);
802 forms_seen_timestamp));
803 } 771 }
804 } 772 }
805 773
806 void AutofillAgent::HidePopup() { 774 void AutofillAgent::HidePopup() {
807 if (!is_popup_possibly_visible_) 775 if (!is_popup_possibly_visible_)
808 return; 776 return;
809 is_popup_possibly_visible_ = false; 777 is_popup_possibly_visible_ = false;
810 is_generation_popup_possibly_visible_ = false; 778 is_generation_popup_possibly_visible_ = false;
811 Send(new AutofillHostMsg_HidePopup(routing_id())); 779
780 GetAutofillDriver()->HidePopup();
812 } 781 }
813 782
814 bool AutofillAgent::IsUserGesture() const { 783 bool AutofillAgent::IsUserGesture() const {
815 return WebUserGestureIndicator::isProcessingUserGesture(); 784 return WebUserGestureIndicator::isProcessingUserGesture();
816 } 785 }
817 786
818 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) { 787 void AutofillAgent::didAssociateFormControls(const WebVector<WebNode>& nodes) {
819 for (size_t i = 0; i < nodes.size(); ++i) { 788 for (size_t i = 0; i < nodes.size(); ++i) {
820 WebLocalFrame* frame = nodes[i].document().frame(); 789 WebLocalFrame* frame = nodes[i].document().frame();
821 // Only monitors dynamic forms created in the top frame. Dynamic forms 790 // Only monitors dynamic forms created in the top frame. Dynamic forms
822 // inserted in iframes are not captured yet. Frame is only processed 791 // inserted in iframes are not captured yet. Frame is only processed
823 // if it has finished loading, otherwise you can end up with a partially 792 // if it has finished loading, otherwise you can end up with a partially
824 // parsed form. 793 // parsed form.
825 if (frame && !frame->isLoading()) { 794 if (frame && !frame->isLoading()) {
826 ProcessForms(); 795 ProcessForms();
827 password_autofill_agent_->OnDynamicFormsSeen(); 796 password_autofill_agent_->OnDynamicFormsSeen();
828 if (password_generation_agent_) 797 if (password_generation_agent_)
829 password_generation_agent_->OnDynamicFormsSeen(); 798 password_generation_agent_->OnDynamicFormsSeen();
830 return; 799 return;
831 } 800 }
832 } 801 }
833 } 802 }
834 803
835 void AutofillAgent::ajaxSucceeded() { 804 void AutofillAgent::ajaxSucceeded() {
836 OnSamePageNavigationCompleted(); 805 OnSamePageNavigationCompleted();
837 password_autofill_agent_->AJAXSucceeded(); 806 password_autofill_agent_->AJAXSucceeded();
838 } 807 }
839 808
840 void AutofillAgent::ConnectToMojoAutofillDriverIfNeeded() { 809 const mojom::AutofillDriverPtr& AutofillAgent::GetAutofillDriver() {
841 if (mojo_autofill_driver_.is_bound() && 810 if (!mojo_autofill_driver_.is_bound() ||
842 !mojo_autofill_driver_.encountered_error()) 811 mojo_autofill_driver_.encountered_error()) {
dcheng 2016/07/12 14:22:12 How comes this check isn't simply !mojo_autofill_d
leonhsl(Using Gerrit) 2016/07/13 03:48:30 En,, seems reconnecting after a connection error i
dcheng 2016/07/14 04:31:44 Shall we remove the reconnecting part?
leonhsl(Using Gerrit) 2016/07/14 09:57:31 Yeah,, I think I've finally figured out that we do
843 return; 812 render_frame()->GetRemoteInterfaces()->GetInterface(
813 mojo::GetProxy(&mojo_autofill_driver_));
814 }
844 815
845 render_frame()->GetRemoteInterfaces()->GetInterface(&mojo_autofill_driver_); 816 return mojo_autofill_driver_;
846 } 817 }
847 818
848 // LegacyAutofillAgent --------------------------------------------------------- 819 // LegacyAutofillAgent ---------------------------------------------------------
849 820
850 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( 821 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent(
851 content::RenderView* render_view, 822 content::RenderView* render_view,
852 AutofillAgent* agent) 823 AutofillAgent* agent)
853 : content::RenderViewObserver(render_view), agent_(agent) { 824 : content::RenderViewObserver(render_view), agent_(agent) {
854 } 825 }
855 826
856 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { 827 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() {
857 } 828 }
858 829
859 void AutofillAgent::LegacyAutofillAgent::Shutdown() { 830 void AutofillAgent::LegacyAutofillAgent::Shutdown() {
860 agent_ = nullptr; 831 agent_ = nullptr;
861 } 832 }
862 833
863 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 834 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
864 // No-op. Don't delete |this|. 835 // No-op. Don't delete |this|.
865 } 836 }
866 837
867 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 838 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
868 if (agent_) 839 if (agent_)
869 agent_->FocusChangeComplete(); 840 agent_->FocusChangeComplete();
870 } 841 }
871 842
872 } // namespace autofill 843 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698