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