| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | 5 #include "config.h" |
| 6 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "base/command_line.h" | 37 #include "base/command_line.h" |
| 38 #include "base/logging.h" | 38 #include "base/logging.h" |
| 39 #include "base/string_util.h" | 39 #include "base/string_util.h" |
| 40 #include "net/base/mime_util.h" | 40 #include "net/base/mime_util.h" |
| 41 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 42 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 43 #include "webkit/activex_shim/activex_shared.h" | 43 #include "webkit/activex_shim/activex_shared.h" |
| 44 #endif | 44 #endif |
| 45 #include "webkit/glue/autofill_form.h" | 45 #include "webkit/glue/autofill_form.h" |
| 46 #include "webkit/glue/alt_404_page_resource_fetcher.h" | 46 #include "webkit/glue/alt_404_page_resource_fetcher.h" |
| 47 #include "webkit/glue/autocomplete_input_listener.h" | |
| 48 #include "webkit/glue/form_autocomplete_listener.h" | |
| 49 #include "webkit/glue/glue_util.h" | 47 #include "webkit/glue/glue_util.h" |
| 50 #include "webkit/glue/password_form_dom_manager.h" | 48 #include "webkit/glue/password_form_dom_manager.h" |
| 51 #include "webkit/glue/plugins/plugin_list.h" | 49 #include "webkit/glue/plugins/plugin_list.h" |
| 52 #include "webkit/glue/searchable_form_data.h" | 50 #include "webkit/glue/searchable_form_data.h" |
| 53 #include "webkit/glue/webdatasource_impl.h" | 51 #include "webkit/glue/webdatasource_impl.h" |
| 54 #include "webkit/glue/webdocumentloader_impl.h" | 52 #include "webkit/glue/webdocumentloader_impl.h" |
| 55 #include "webkit/glue/weberror_impl.h" | 53 #include "webkit/glue/weberror_impl.h" |
| 56 #include "webkit/glue/webframeloaderclient_impl.h" | 54 #include "webkit/glue/webframeloaderclient_impl.h" |
| 57 #include "webkit/glue/webhistoryitem_impl.h" | 55 #include "webkit/glue/webhistoryitem_impl.h" |
| 58 #include "webkit/glue/webkit_glue.h" | 56 #include "webkit/glue/webkit_glue.h" |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 WebViewImpl* webview = webframe_->webview_impl(); | 319 WebViewImpl* webview = webframe_->webview_impl(); |
| 322 if (webview && webview->delegate()) { | 320 if (webview && webview->delegate()) { |
| 323 webview->delegate()->DidFailLoadingWithError(webview, identifier, | 321 webview->delegate()->DidFailLoadingWithError(webview, identifier, |
| 324 WebErrorImpl(error)); | 322 WebErrorImpl(error)); |
| 325 } | 323 } |
| 326 } | 324 } |
| 327 | 325 |
| 328 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { | 326 void WebFrameLoaderClient::dispatchDidFinishDocumentLoad() { |
| 329 WebViewImpl* webview = webframe_->webview_impl(); | 327 WebViewImpl* webview = webframe_->webview_impl(); |
| 330 WebViewDelegate* d = webview->delegate(); | 328 WebViewDelegate* d = webview->delegate(); |
| 331 // A frame may be reused. This call ensures a new AutoCompleteListener will | 329 |
| 332 // be created for the newly created frame. | 330 // A frame may be reused. This call ensures we don't hold on to our password |
| 333 webframe_->ClearAutocompleteListener(); | 331 // listeners and their associated HTMLInputElements. |
| 332 webframe_->ClearPasswordListeners(); |
| 334 | 333 |
| 335 // The document has now been fully loaded. | 334 // The document has now been fully loaded. |
| 336 // Scan for password forms to be sent to the browser | 335 // Scan for password forms to be sent to the browser |
| 337 PassRefPtr<WebCore::HTMLCollection> forms = | 336 PassRefPtr<WebCore::HTMLCollection> forms = |
| 338 webframe_->frame()->document()->forms(); | 337 webframe_->frame()->document()->forms(); |
| 339 | 338 |
| 340 std::vector<PasswordForm> passwordForms; | 339 std::vector<PasswordForm> passwordForms; |
| 341 | 340 |
| 342 unsigned int form_count = forms->length(); | 341 unsigned int form_count = forms->length(); |
| 343 for (unsigned int i = 0; i < form_count; ++i) { | 342 for (unsigned int i = 0; i < form_count; ++i) { |
| 344 // Strange but true, sometimes item can be NULL. | 343 // Strange but true, sometimes item can be NULL. |
| 345 WebCore::Node* item = forms->item(i); | 344 WebCore::Node* item = forms->item(i); |
| 346 if (item) { | 345 if (item) { |
| 347 WebCore::HTMLFormElement* form = | 346 WebCore::HTMLFormElement* form = |
| 348 static_cast<WebCore::HTMLFormElement*>(item); | 347 static_cast<WebCore::HTMLFormElement*>(item); |
| 349 | 348 |
| 350 // Honour autocomplete=off. | 349 // Honour autocomplete=off. |
| 351 if (!form->autoComplete()) | 350 if (!form->autoComplete()) |
| 352 continue; | 351 continue; |
| 353 | 352 |
| 354 std::set<std::wstring> password_related_fields; | |
| 355 scoped_ptr<PasswordForm> passwordFormPtr( | 353 scoped_ptr<PasswordForm> passwordFormPtr( |
| 356 PasswordFormDomManager::CreatePasswordForm(form)); | 354 PasswordFormDomManager::CreatePasswordForm(form)); |
| 357 | 355 |
| 358 if (passwordFormPtr.get()) { | 356 if (passwordFormPtr.get()) |
| 359 passwordForms.push_back(*passwordFormPtr); | 357 passwordForms.push_back(*passwordFormPtr); |
| 360 | |
| 361 // Let's remember the names of password related fields so we do not | |
| 362 // autofill them with the regular form autofill. | |
| 363 | |
| 364 if (!passwordFormPtr->username_element.empty()) | |
| 365 password_related_fields.insert(passwordFormPtr->username_element); | |
| 366 DCHECK(!passwordFormPtr->password_element.empty()); | |
| 367 password_related_fields.insert(passwordFormPtr->password_element); | |
| 368 if (!passwordFormPtr->old_password_element.empty()) | |
| 369 password_related_fields.insert(passwordFormPtr->old_password_element); | |
| 370 } | |
| 371 | |
| 372 // Now let's register for any text input. | |
| 373 // TODO(jcampan): bug #3847 merge password and form autofill so we | |
| 374 // traverse the form elements only once. | |
| 375 RegisterAutofillListeners(form, password_related_fields); | |
| 376 } | 358 } |
| 377 } | 359 } |
| 378 | 360 |
| 379 if (d && (passwordForms.size() > 0)) | 361 if (d && (passwordForms.size() > 0)) |
| 380 d->OnPasswordFormsSeen(webview, passwordForms); | 362 d->OnPasswordFormsSeen(webview, passwordForms); |
| 381 if (d) | 363 if (d) |
| 382 d->DidFinishDocumentLoadForFrame(webview, webframe_); | 364 d->DidFinishDocumentLoadForFrame(webview, webframe_); |
| 383 } | 365 } |
| 384 | 366 |
| 385 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache( | 367 bool WebFrameLoaderClient::dispatchDidLoadResourceFromMemoryCache( |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() { | 678 NavigationGesture WebFrameLoaderClient::NavigationGestureForLastLoad() { |
| 697 // TODO(timsteele): userGestureHint returns too many false positives | 679 // TODO(timsteele): userGestureHint returns too many false positives |
| 698 // (see bug 1051891) to trust it and assign NavigationGestureUser, so | 680 // (see bug 1051891) to trust it and assign NavigationGestureUser, so |
| 699 // for now we assign Unknown in those cases and Auto otherwise. | 681 // for now we assign Unknown in those cases and Auto otherwise. |
| 700 // (Issue 874811 known false negative as well). | 682 // (Issue 874811 known false negative as well). |
| 701 return webframe_->frame()->loader()->userGestureHint() ? | 683 return webframe_->frame()->loader()->userGestureHint() ? |
| 702 NavigationGestureUnknown : | 684 NavigationGestureUnknown : |
| 703 NavigationGestureAuto; | 685 NavigationGestureAuto; |
| 704 } | 686 } |
| 705 | 687 |
| 706 void WebFrameLoaderClient::RegisterAutofillListeners( | |
| 707 WebCore::HTMLFormElement* form, | |
| 708 const std::set<std::wstring>& excluded_fields) { | |
| 709 | |
| 710 WebViewDelegate* webview_delegate = webframe_->webview_impl()->delegate(); | |
| 711 if (!webview_delegate) | |
| 712 return; | |
| 713 | |
| 714 for (size_t i = 0; i < form->formElements.size(); i++) { | |
| 715 WebCore::HTMLFormControlElement* form_element = form->formElements[i]; | |
| 716 if (!form_element->hasLocalName(WebCore::HTMLNames::inputTag)) | |
| 717 continue; | |
| 718 | |
| 719 WebCore::HTMLInputElement* input_element = | |
| 720 static_cast<WebCore::HTMLInputElement*>(form_element); | |
| 721 if (!input_element->isEnabled() || !input_element->isTextField() || | |
| 722 input_element->isPasswordField() || !input_element->autoComplete()) { | |
| 723 continue; | |
| 724 } | |
| 725 | |
| 726 std::wstring name = webkit_glue::StringToStdWString(input_element->name()); | |
| 727 if (name.empty() || excluded_fields.find(name) != excluded_fields.end()) | |
| 728 continue; | |
| 729 | |
| 730 #if !defined(OS_MACOSX) | |
| 731 // FIXME on Mac | |
| 732 webkit_glue::FormAutocompleteListener* listener = | |
| 733 new webkit_glue::FormAutocompleteListener(webview_delegate); | |
| 734 webframe_->GetAutocompleteListener()->AddInputListener(input_element, | |
| 735 listener); | |
| 736 #endif | |
| 737 } | |
| 738 } | |
| 739 | |
| 740 void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title) { | 688 void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title) { |
| 741 WebViewImpl* webview = webframe_->webview_impl(); | 689 WebViewImpl* webview = webframe_->webview_impl(); |
| 742 WebViewDelegate* d = webview->delegate(); | 690 WebViewDelegate* d = webview->delegate(); |
| 743 if (d) { | 691 if (d) { |
| 744 d->DidReceiveTitle(webview, webkit_glue::StringToStdWString(title), | 692 d->DidReceiveTitle(webview, webkit_glue::StringToStdWString(title), |
| 745 webframe_); | 693 webframe_); |
| 746 } | 694 } |
| 747 } | 695 } |
| 748 | 696 |
| 749 void WebFrameLoaderClient::dispatchDidCommitLoad() { | 697 void WebFrameLoaderClient::dispatchDidCommitLoad() { |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 } | 942 } |
| 995 | 943 |
| 996 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
{ | 944 void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError&)
{ |
| 997 // FIXME | 945 // FIXME |
| 998 } | 946 } |
| 999 | 947 |
| 1000 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, | 948 void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, |
| 1001 PassRefPtr<FormState> form_ref) { | 949 PassRefPtr<FormState> form_ref) { |
| 1002 SearchableFormData* form_data = SearchableFormData::Create(form_ref->form()); | 950 SearchableFormData* form_data = SearchableFormData::Create(form_ref->form()); |
| 1003 WebDocumentLoaderImpl* loader = static_cast<WebDocumentLoaderImpl*>( | 951 WebDocumentLoaderImpl* loader = static_cast<WebDocumentLoaderImpl*>( |
| 1004 webframe_->frame()->loader()->provisionalDocumentLoader()); | 952 webframe_->frame()->loader()->provisionalDocumentLoader()); |
| 1005 // Don't free the SearchableFormData, the loader will do that. | 953 // Don't free the SearchableFormData, the loader will do that. |
| 1006 loader->set_searchable_form_data(form_data); | 954 loader->set_searchable_form_data(form_data); |
| 1007 | 955 |
| 1008 PasswordForm* pass_data = | 956 PasswordForm* pass_data = |
| 1009 PasswordFormDomManager::CreatePasswordForm(form_ref->form()); | 957 PasswordFormDomManager::CreatePasswordForm(form_ref->form()); |
| 1010 // Don't free the PasswordFormData, the loader will do that. | 958 // Don't free the PasswordFormData, the loader will do that. |
| 1011 loader->set_password_form_data(pass_data); | 959 loader->set_password_form_data(pass_data); |
| 1012 | 960 |
| 1013 WebViewImpl* webview = webframe_->webview_impl(); | 961 WebViewImpl* webview = webframe_->webview_impl(); |
| 1014 WebViewDelegate* d = webview->delegate(); | 962 WebViewDelegate* d = webview->delegate(); |
| (...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 if (!middle_or_ctrl && !shift && !alt) | 1478 if (!middle_or_ctrl && !shift && !alt) |
| 1531 return false; | 1479 return false; |
| 1532 | 1480 |
| 1533 DCHECK(disposition); | 1481 DCHECK(disposition); |
| 1534 if (middle_or_ctrl) | 1482 if (middle_or_ctrl) |
| 1535 *disposition = shift ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; | 1483 *disposition = shift ? NEW_FOREGROUND_TAB : NEW_BACKGROUND_TAB; |
| 1536 else | 1484 else |
| 1537 *disposition = shift ? NEW_WINDOW : SAVE_TO_DISK; | 1485 *disposition = shift ? NEW_WINDOW : SAVE_TO_DISK; |
| 1538 return true; | 1486 return true; |
| 1539 } | 1487 } |
| OLD | NEW |