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

Side by Side Diff: components/autofill/browser/autofill_manager.cc

Issue 16286020: Abstract WebContentsObserver from Autofill shared code (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add missing DEPS file Created 7 years, 6 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/autofill_manager.h" 5 #include "components/autofill/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "components/autofill/common/form_data_predictions.h" 43 #include "components/autofill/common/form_data_predictions.h"
44 #include "components/autofill/common/form_field_data.h" 44 #include "components/autofill/common/form_field_data.h"
45 #include "components/autofill/common/password_form_fill_data.h" 45 #include "components/autofill/common/password_form_fill_data.h"
46 #include "components/user_prefs/pref_registry_syncable.h" 46 #include "components/user_prefs/pref_registry_syncable.h"
47 #include "content/public/browser/browser_context.h" 47 #include "content/public/browser/browser_context.h"
48 #include "content/public/browser/browser_thread.h" 48 #include "content/public/browser/browser_thread.h"
49 #include "content/public/browser/navigation_details.h" 49 #include "content/public/browser/navigation_details.h"
50 #include "content/public/browser/render_view_host.h" 50 #include "content/public/browser/render_view_host.h"
51 #include "content/public/browser/web_contents.h" 51 #include "content/public/browser/web_contents.h"
52 #include "content/public/browser/web_contents_view.h" 52 #include "content/public/browser/web_contents_view.h"
53 #include "content/public/common/frame_navigate_params.h"
53 #include "content/public/common/url_constants.h" 54 #include "content/public/common/url_constants.h"
54 #include "googleurl/src/gurl.h" 55 #include "googleurl/src/gurl.h"
55 #include "grit/component_resources.h" 56 #include "grit/component_resources.h"
56 #include "ipc/ipc_message_macros.h" 57 #include "ipc/ipc_message_macros.h"
57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
58 #include "ui/base/l10n/l10n_util.h" 59 #include "ui/base/l10n/l10n_util.h"
59 #include "ui/gfx/rect.h" 60 #include "ui/gfx/rect.h"
60 61
61 namespace autofill { 62 namespace autofill {
62 63
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 content::WebContents* contents) { 199 content::WebContents* contents) {
199 return static_cast<AutofillManager*>( 200 return static_cast<AutofillManager*>(
200 contents->GetUserData(kAutofillManagerWebContentsUserDataKey)); 201 contents->GetUserData(kAutofillManagerWebContentsUserDataKey));
201 } 202 }
202 203
203 AutofillManager::AutofillManager( 204 AutofillManager::AutofillManager(
204 content::WebContents* web_contents, 205 content::WebContents* web_contents,
205 autofill::AutofillManagerDelegate* delegate, 206 autofill::AutofillManagerDelegate* delegate,
206 const std::string& app_locale, 207 const std::string& app_locale,
207 AutofillDownloadManagerState enable_download_manager) 208 AutofillDownloadManagerState enable_download_manager)
208 : content::WebContentsObserver(web_contents), 209 : web_contents_(web_contents),
Ilya Sherman 2013/06/05 10:50:02 This doesn't seem safe, as the WebContentsObserver
blundell 2013/06/11 15:35:47 Yes, you're right. Made AutofillDriver an interfac
209 manager_delegate_(delegate), 210 manager_delegate_(delegate),
210 app_locale_(app_locale), 211 app_locale_(app_locale),
211 personal_data_(delegate->GetPersonalDataManager()), 212 personal_data_(delegate->GetPersonalDataManager()),
212 autocomplete_history_manager_(web_contents), 213 autocomplete_history_manager_(web_contents),
213 autocheckout_manager_(this), 214 autocheckout_manager_(this),
214 metric_logger_(new AutofillMetrics), 215 metric_logger_(new AutofillMetrics),
215 has_logged_autofill_enabled_(false), 216 has_logged_autofill_enabled_(false),
216 has_logged_address_suggestions_count_(false), 217 has_logged_address_suggestions_count_(false),
217 did_show_suggestions_(false), 218 did_show_suggestions_(false),
218 user_did_type_(false), 219 user_did_type_(false),
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions, 305 IPC_MESSAGE_HANDLER(AutofillHostMsg_ShowPasswordSuggestions,
305 OnShowPasswordSuggestions) 306 OnShowPasswordSuggestions)
306 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList, 307 IPC_MESSAGE_HANDLER(AutofillHostMsg_SetDataList,
307 OnSetDataList) 308 OnSetDataList)
308 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete, 309 IPC_MESSAGE_HANDLER(AutofillHostMsg_RequestAutocomplete,
309 OnRequestAutocomplete) 310 OnRequestAutocomplete)
310 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed, 311 IPC_MESSAGE_HANDLER(AutofillHostMsg_ClickFailed,
311 OnClickFailed) 312 OnClickFailed)
312 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble, 313 IPC_MESSAGE_HANDLER(AutofillHostMsg_MaybeShowAutocheckoutBubble,
313 OnMaybeShowAutocheckoutBubble) 314 OnMaybeShowAutocheckoutBubble)
315 IPC_MESSAGE_HANDLER(AutofillHostMsg_RemoveAutocompleteEntry,
316 RemoveAutocompleteEntry)
314 IPC_MESSAGE_UNHANDLED(handled = false) 317 IPC_MESSAGE_UNHANDLED(handled = false)
315 IPC_END_MESSAGE_MAP() 318 IPC_END_MESSAGE_MAP()
316 319
317 return handled; 320 return handled;
318 } 321 }
319 322
320 bool AutofillManager::OnFormSubmitted(const FormData& form, 323 bool AutofillManager::OnFormSubmitted(const FormData& form,
321 const TimeTicks& timestamp) { 324 const TimeTicks& timestamp) {
322 // Let AutoComplete know as well. 325 // Let AutoComplete know as well.
323 autocomplete_history_manager_.OnFormSubmitted(form); 326 autocomplete_history_manager_.OnFormSubmitted(form);
324 327
325 if (!IsAutofillEnabled()) 328 if (!IsAutofillEnabled())
326 return false; 329 return false;
327 330
328 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) 331 if (web_contents_->GetBrowserContext()->IsOffTheRecord())
329 return false; 332 return false;
330 333
331 // Don't save data that was submitted through JavaScript. 334 // Don't save data that was submitted through JavaScript.
332 if (!form.user_submitted) 335 if (!form.user_submitted)
333 return false; 336 return false;
334 337
335 // Grab a copy of the form data. 338 // Grab a copy of the form data.
336 scoped_ptr<FormStructure> submitted_form( 339 scoped_ptr<FormStructure> submitted_form(
337 new FormStructure(form, GetAutocheckoutURLPrefix())); 340 new FormStructure(form, GetAutocheckoutURLPrefix()));
338 341
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 400
398 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 401 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
399 const TimeTicks& timestamp, 402 const TimeTicks& timestamp,
400 autofill::FormsSeenState state) { 403 autofill::FormsSeenState state) {
401 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; 404 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
402 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN; 405 bool has_more_forms = state == autofill::PARTIAL_FORMS_SEEN;
403 // If new forms were added via AJAX or DHML, treat as new page. 406 // If new forms were added via AJAX or DHML, treat as new page.
404 if (is_post_document_load) 407 if (is_post_document_load)
405 Reset(); 408 Reset();
406 409
407 RenderViewHost* host = web_contents()->GetRenderViewHost(); 410 RenderViewHost* host = web_contents_->GetRenderViewHost();
408 if (!host) 411 if (!host)
409 return; 412 return;
410 413
411 if (!GetAutocheckoutURLPrefix().empty()) { 414 if (!GetAutocheckoutURLPrefix().empty()) {
412 // If whitelisted URL, fetch all the forms. 415 // If whitelisted URL, fetch all the forms.
413 if (has_more_forms) 416 if (has_more_forms)
414 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID())); 417 host->Send(new AutofillMsg_GetAllForms(host->GetRoutingID()));
415 if (!is_post_document_load) { 418 if (!is_post_document_load) {
416 host->Send( 419 host->Send(
417 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); 420 new AutofillMsg_AutocheckoutSupported(host->GetRoutingID()));
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 708
706 personal_data_->RemoveByGUID(data_model->guid()); 709 personal_data_->RemoveByGUID(data_model->guid());
707 } 710 }
708 711
709 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, 712 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name,
710 const base::string16& value) { 713 const base::string16& value) {
711 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); 714 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value);
712 } 715 }
713 716
714 content::WebContents* AutofillManager::GetWebContents() const { 717 content::WebContents* AutofillManager::GetWebContents() const {
715 return web_contents(); 718 return web_contents_;
716 } 719 }
717 720
718 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { 721 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() {
719 return form_structures_.get(); 722 return form_structures_.get();
720 } 723 }
721 724
722 void AutofillManager::ShowRequestAutocompleteDialog( 725 void AutofillManager::ShowRequestAutocompleteDialog(
723 const FormData& form, 726 const FormData& form,
724 const GURL& source_url, 727 const GURL& source_url,
725 autofill::DialogType dialog_type, 728 autofill::DialogType dialog_type,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 780
778 base::Callback<void(const FormStructure*, const std::string&)> callback = 781 base::Callback<void(const FormStructure*, const std::string&)> callback =
779 base::Bind(&AutofillManager::ReturnAutocompleteData, 782 base::Bind(&AutofillManager::ReturnAutocompleteData,
780 weak_ptr_factory_.GetWeakPtr()); 783 weak_ptr_factory_.GetWeakPtr());
781 ShowRequestAutocompleteDialog( 784 ShowRequestAutocompleteDialog(
782 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback); 785 form, frame_url, autofill::DIALOG_TYPE_REQUEST_AUTOCOMPLETE, callback);
783 } 786 }
784 787
785 void AutofillManager::ReturnAutocompleteResult( 788 void AutofillManager::ReturnAutocompleteResult(
786 WebFormElement::AutocompleteResult result, const FormData& form_data) { 789 WebFormElement::AutocompleteResult result, const FormData& form_data) {
787 // web_contents() will be NULL when the interactive autocomplete is closed due 790 // web_contents_ will be NULL when the interactive autocomplete is closed due
788 // to a tab or browser window closing. 791 // to a tab or browser window closing.
789 if (!web_contents()) 792 if (!web_contents_)
790 return; 793 return;
791 794
792 RenderViewHost* host = web_contents()->GetRenderViewHost(); 795 RenderViewHost* host = web_contents_->GetRenderViewHost();
793 if (!host) 796 if (!host)
794 return; 797 return;
795 798
796 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(), 799 host->Send(new AutofillMsg_RequestAutocompleteResult(host->GetRoutingID(),
797 result, 800 result,
798 form_data)); 801 form_data));
799 } 802 }
800 803
801 void AutofillManager::ReturnAutocompleteData( 804 void AutofillManager::ReturnAutocompleteData(
802 const FormStructure* result, 805 const FormStructure* result,
(...skipping 12 matching lines...) Expand all
815 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data( 818 scoped_ptr<autofill::AutocheckoutPageMetaData> page_meta_data(
816 new autofill::AutocheckoutPageMetaData()); 819 new autofill::AutocheckoutPageMetaData());
817 820
818 // Parse and store the server predictions. 821 // Parse and store the server predictions.
819 FormStructure::ParseQueryResponse(response_xml, 822 FormStructure::ParseQueryResponse(response_xml,
820 form_structures_.get(), 823 form_structures_.get(),
821 page_meta_data.get(), 824 page_meta_data.get(),
822 *metric_logger_); 825 *metric_logger_);
823 826
824 if (page_meta_data->IsInAutofillableFlow()) { 827 if (page_meta_data->IsInAutofillableFlow()) {
825 RenderViewHost* host = web_contents()->GetRenderViewHost(); 828 RenderViewHost* host = web_contents_->GetRenderViewHost();
826 if (host) 829 if (host)
827 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID())); 830 host->Send(new AutofillMsg_AutocheckoutSupported(host->GetRoutingID()));
828 } 831 }
829 832
830 // TODO(ahutter): Remove this once Autocheckout is implemented on other 833 // TODO(ahutter): Remove this once Autocheckout is implemented on other
831 // platforms. See http://crbug.com/173416. 834 // platforms. See http://crbug.com/173416.
832 #if defined(TOOLKIT_VIEWS) 835 #if defined(TOOLKIT_VIEWS)
833 if (!GetAutocheckoutURLPrefix().empty()) 836 if (!GetAutocheckoutURLPrefix().empty())
834 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass()); 837 autocheckout_manager_.OnLoadedPageMetaData(page_meta_data.Pass());
835 #endif // #if defined(TOOLKIT_VIEWS) 838 #endif // #if defined(TOOLKIT_VIEWS)
(...skipping 18 matching lines...) Expand all
854 if (!IsAutofillEnabled()) 857 if (!IsAutofillEnabled())
855 return; 858 return;
856 859
857 autocheckout_manager_.MaybeShowAutocheckoutBubble( 860 autocheckout_manager_.MaybeShowAutocheckoutBubble(
858 source_url, 861 source_url,
859 ssl_status, 862 ssl_status,
860 bounding_box); 863 bounding_box);
861 } 864 }
862 865
863 std::string AutofillManager::GetAutocheckoutURLPrefix() const { 866 std::string AutofillManager::GetAutocheckoutURLPrefix() const {
864 if (!web_contents()) 867 if (!web_contents_)
865 return std::string(); 868 return std::string();
866 869
867 autofill::autocheckout::WhitelistManager* whitelist_manager = 870 autofill::autocheckout::WhitelistManager* whitelist_manager =
868 manager_delegate_->GetAutocheckoutWhitelistManager(); 871 manager_delegate_->GetAutocheckoutWhitelistManager();
869 872
870 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); 873 return whitelist_manager->GetMatchedURLPrefix(web_contents_->GetURL());
871 } 874 }
872 875
873 bool AutofillManager::IsAutofillEnabled() const { 876 bool AutofillManager::IsAutofillEnabled() const {
874 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); 877 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
875 } 878 }
876 879
877 void AutofillManager::SendAutofillTypePredictions( 880 void AutofillManager::SendAutofillTypePredictions(
878 const std::vector<FormStructure*>& forms) const { 881 const std::vector<FormStructure*>& forms) const {
879 if (!CommandLine::ForCurrentProcess()->HasSwitch( 882 if (!CommandLine::ForCurrentProcess()->HasSwitch(
880 switches::kShowAutofillTypePredictions)) 883 switches::kShowAutofillTypePredictions))
881 return; 884 return;
882 885
883 RenderViewHost* host = web_contents()->GetRenderViewHost(); 886 RenderViewHost* host = web_contents_->GetRenderViewHost();
884 if (!host) 887 if (!host)
885 return; 888 return;
886 889
887 std::vector<FormDataPredictions> type_predictions; 890 std::vector<FormDataPredictions> type_predictions;
888 FormStructure::GetFieldTypePredictions(forms, &type_predictions); 891 FormStructure::GetFieldTypePredictions(forms, &type_predictions);
889 host->Send( 892 host->Send(
890 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(), 893 new AutofillMsg_FieldTypePredictionsAvailable(host->GetRoutingID(),
891 type_predictions)); 894 type_predictions));
892 } 895 }
893 896
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 forms_loaded_timestamp_ = TimeTicks(); 961 forms_loaded_timestamp_ = TimeTicks();
959 initial_interaction_timestamp_ = TimeTicks(); 962 initial_interaction_timestamp_ = TimeTicks();
960 963
961 if (external_delegate_) 964 if (external_delegate_)
962 external_delegate_->Reset(); 965 external_delegate_->Reset();
963 } 966 }
964 967
965 AutofillManager::AutofillManager(content::WebContents* web_contents, 968 AutofillManager::AutofillManager(content::WebContents* web_contents,
966 autofill::AutofillManagerDelegate* delegate, 969 autofill::AutofillManagerDelegate* delegate,
967 PersonalDataManager* personal_data) 970 PersonalDataManager* personal_data)
968 : content::WebContentsObserver(web_contents), 971 : web_contents_(web_contents),
969 manager_delegate_(delegate), 972 manager_delegate_(delegate),
970 app_locale_("en-US"), 973 app_locale_("en-US"),
971 personal_data_(personal_data), 974 personal_data_(personal_data),
972 autocomplete_history_manager_(web_contents), 975 autocomplete_history_manager_(web_contents),
973 autocheckout_manager_(this), 976 autocheckout_manager_(this),
974 metric_logger_(new AutofillMetrics), 977 metric_logger_(new AutofillMetrics),
975 has_logged_autofill_enabled_(false), 978 has_logged_autofill_enabled_(false),
976 has_logged_address_suggestions_count_(false), 979 has_logged_address_suggestions_count_(false),
977 did_show_suggestions_(false), 980 did_show_suggestions_(false),
978 user_did_type_(false), 981 user_did_type_(false),
(...skipping 13 matching lines...) Expand all
992 bool AutofillManager::GetHost(RenderViewHost** host) const { 995 bool AutofillManager::GetHost(RenderViewHost** host) const {
993 if (!IsAutofillEnabled()) 996 if (!IsAutofillEnabled())
994 return false; 997 return false;
995 998
996 // No autofill data to return if the profiles are empty. 999 // No autofill data to return if the profiles are empty.
997 if (personal_data_->GetProfiles().empty() && 1000 if (personal_data_->GetProfiles().empty() &&
998 personal_data_->GetCreditCards().empty()) { 1001 personal_data_->GetCreditCards().empty()) {
999 return false; 1002 return false;
1000 } 1003 }
1001 1004
1002 *host = web_contents()->GetRenderViewHost(); 1005 *host = web_contents_->GetRenderViewHost();
1003 if (!*host) 1006 if (!*host)
1004 return false; 1007 return false;
1005 1008
1006 return true; 1009 return true;
1007 } 1010 }
1008 1011
1009 bool AutofillManager::GetProfileOrCreditCard( 1012 bool AutofillManager::GetProfileOrCreditCard(
1010 int unique_id, 1013 int unique_id,
1011 const AutofillDataModel** data_model, 1014 const AutofillDataModel** data_model,
1012 size_t* variant) const { 1015 size_t* variant) const {
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 1299
1297 void AutofillManager::UpdateInitialInteractionTimestamp( 1300 void AutofillManager::UpdateInitialInteractionTimestamp(
1298 const TimeTicks& interaction_timestamp) { 1301 const TimeTicks& interaction_timestamp) {
1299 if (initial_interaction_timestamp_.is_null() || 1302 if (initial_interaction_timestamp_.is_null() ||
1300 interaction_timestamp < initial_interaction_timestamp_) { 1303 interaction_timestamp < initial_interaction_timestamp_) {
1301 initial_interaction_timestamp_ = interaction_timestamp; 1304 initial_interaction_timestamp_ = interaction_timestamp;
1302 } 1305 }
1303 } 1306 }
1304 1307
1305 } // namespace autofill 1308 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698