| OLD | NEW |
| 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 "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/prefs/pref_service.h" |
| 10 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 11 #include "base/string_split.h" | 13 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/autofill/autofill_country.h" | 16 #include "chrome/browser/autofill/autofill_country.h" |
| 15 #include "chrome/browser/autofill/autofill_manager.h" | 17 #include "chrome/browser/autofill/autofill_manager.h" |
| 16 #include "chrome/browser/autofill/autofill_type.h" | 18 #include "chrome/browser/autofill/autofill_type.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 19 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 20 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
| 21 #include "chrome/browser/autofill/risk/fingerprint.h" |
| 22 #include "chrome/browser/autofill/risk/proto/fingerprint.pb.h" |
| 19 #include "chrome/browser/autofill/validation.h" | 23 #include "chrome/browser/autofill/validation.h" |
| 20 #include "chrome/browser/autofill/wallet/full_wallet.h" | 24 #include "chrome/browser/autofill/wallet/full_wallet.h" |
| 21 #include "chrome/browser/autofill/wallet/wallet_items.h" | 25 #include "chrome/browser/autofill/wallet/wallet_items.h" |
| 22 #include "chrome/browser/autofill/wallet/wallet_service_url.h" | 26 #include "chrome/browser/autofill/wallet/wallet_service_url.h" |
| 27 #include "chrome/browser/extensions/shell_window_registry.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 29 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
| 25 #include "chrome/browser/ui/autofill/data_model_wrapper.h" | 30 #include "chrome/browser/ui/autofill/data_model_wrapper.h" |
| 31 #include "chrome/browser/ui/base_window.h" |
| 32 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" |
| 34 #include "chrome/browser/ui/browser_window.h" |
| 35 #include "chrome/browser/ui/extensions/native_app_window.h" |
| 36 #include "chrome/browser/ui/extensions/shell_window.h" |
| 26 #include "chrome/common/form_data.h" | 37 #include "chrome/common/form_data.h" |
| 27 #include "content/public/browser/navigation_controller.h" | 38 #include "content/public/browser/navigation_controller.h" |
| 28 #include "content/public/browser/navigation_details.h" | 39 #include "content/public/browser/navigation_details.h" |
| 29 #include "content/public/browser/navigation_entry.h" | 40 #include "content/public/browser/navigation_entry.h" |
| 30 #include "content/public/browser/notification_service.h" | 41 #include "content/public/browser/notification_service.h" |
| 31 #include "content/public/browser/notification_types.h" | 42 #include "content/public/browser/notification_types.h" |
| 32 #include "content/public/browser/web_contents.h" | 43 #include "content/public/browser/web_contents.h" |
| 44 #include "content/public/browser/web_contents_view.h" |
| 33 #include "content/public/common/url_constants.h" | 45 #include "content/public/common/url_constants.h" |
| 34 #include "grit/chromium_strings.h" | 46 #include "grit/chromium_strings.h" |
| 35 #include "grit/generated_resources.h" | 47 #include "grit/generated_resources.h" |
| 36 #include "net/base/cert_status_flags.h" | 48 #include "net/base/cert_status_flags.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 49 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 50 #include "ui/base/resource/resource_bundle.h" |
| 39 | 51 |
| 40 namespace autofill { | 52 namespace autofill { |
| 41 | 53 |
| 42 namespace { | 54 namespace { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // Initializes |form_group| from user-entered data. | 127 // Initializes |form_group| from user-entered data. |
| 116 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, | 128 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, |
| 117 FormGroup* form_group) { | 129 FormGroup* form_group) { |
| 118 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); | 130 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); |
| 119 iter != detail_outputs.end(); ++iter) { | 131 iter != detail_outputs.end(); ++iter) { |
| 120 if (!iter->second.empty()) | 132 if (!iter->second.empty()) |
| 121 form_group->SetRawInfo(iter->first->type, iter->second); | 133 form_group->SetRawInfo(iter->first->type, iter->second); |
| 122 } | 134 } |
| 123 } | 135 } |
| 124 | 136 |
| 137 // Returns the containing window for the given |web_contents|. The containing |
| 138 // window might be a browser window for a Chrome tab, or it might be a shell |
| 139 // window for a platform app. |
| 140 BaseWindow* GetBaseWindowForWebContents( |
| 141 const content::WebContents* web_contents) { |
| 142 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 143 if (browser) |
| 144 return browser->window(); |
| 145 |
| 146 gfx::NativeWindow native_window = |
| 147 web_contents->GetView()->GetTopLevelNativeWindow(); |
| 148 ShellWindow* shell_window = |
| 149 extensions::ShellWindowRegistry:: |
| 150 GetShellWindowForNativeWindowAnyProfile(native_window); |
| 151 return shell_window->GetBaseWindow(); |
| 152 } |
| 153 |
| 125 } // namespace | 154 } // namespace |
| 126 | 155 |
| 127 AutofillDialogController::~AutofillDialogController() {} | 156 AutofillDialogController::~AutofillDialogController() {} |
| 128 | 157 |
| 129 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 158 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| 130 content::WebContents* contents, | 159 content::WebContents* contents, |
| 131 const FormData& form, | 160 const FormData& form, |
| 132 const GURL& source_url, | 161 const GURL& source_url, |
| 133 const content::SSLStatus& ssl_status, | 162 const content::SSLStatus& ssl_status, |
| 134 const AutofillMetrics& metric_logger, | 163 const AutofillMetrics& metric_logger, |
| 135 DialogType dialog_type, | 164 DialogType dialog_type, |
| 136 const base::Callback<void(const FormStructure*)>& callback) | 165 const base::Callback<void(const FormStructure*)>& callback) |
| 137 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 166 : profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 138 contents_(contents), | 167 contents_(contents), |
| 139 form_structure_(form, std::string()), | 168 form_structure_(form, std::string()), |
| 140 source_url_(source_url), | 169 source_url_(source_url), |
| 141 ssl_status_(ssl_status), | 170 ssl_status_(ssl_status), |
| 142 callback_(callback), | 171 callback_(callback), |
| 143 wallet_client_(profile_->GetRequestContext()), | 172 wallet_client_(profile_->GetRequestContext()), |
| 144 refresh_wallet_items_queued_(false), | 173 refresh_wallet_items_queued_(false), |
| 145 had_wallet_error_(false), | 174 had_wallet_error_(false), |
| 146 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), | 175 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_email_(this)), |
| 147 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), | 176 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_(this)), |
| 148 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), | 177 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_billing_(this)), |
| 149 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), | 178 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_cc_billing_(this)), |
| 150 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), | 179 ALLOW_THIS_IN_INITIALIZER_LIST(suggested_shipping_(this)), |
| 151 section_showing_popup_(SECTION_BILLING), | 180 section_showing_popup_(SECTION_BILLING), |
| 181 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
| 152 metric_logger_(metric_logger), | 182 metric_logger_(metric_logger), |
| 153 dialog_type_(dialog_type) { | 183 dialog_type_(dialog_type) { |
| 154 // TODO(estade): |this| should observe PersonalDataManager. | 184 // TODO(estade): |this| should observe PersonalDataManager. |
| 155 // TODO(estade): remove duplicates from |form|? | 185 // TODO(estade): remove duplicates from |form|? |
| 156 | 186 |
| 157 content::NavigationEntry* entry = contents->GetController().GetActiveEntry(); | 187 content::NavigationEntry* entry = contents->GetController().GetActiveEntry(); |
| 158 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); | 188 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); |
| 159 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); | 189 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); |
| 160 } | 190 } |
| 161 | 191 |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1145 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( | 1175 DetailInputs* AutofillDialogControllerImpl::MutableRequestedFieldsForSection( |
| 1146 DialogSection section) { | 1176 DialogSection section) { |
| 1147 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 1177 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 1148 } | 1178 } |
| 1149 | 1179 |
| 1150 void AutofillDialogControllerImpl::HidePopup() { | 1180 void AutofillDialogControllerImpl::HidePopup() { |
| 1151 if (popup_controller_) | 1181 if (popup_controller_) |
| 1152 popup_controller_->Hide(); | 1182 popup_controller_->Hide(); |
| 1153 } | 1183 } |
| 1154 | 1184 |
| 1185 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { |
| 1186 // TODO(dbeam): Add a CHECK or otherwise strong guarantee that the ToS have |
| 1187 // been accepted prior to calling into this method. Also, ensure that the UI |
| 1188 // contains a clear indication to the user as to what data will be collected. |
| 1189 // Until then, this code should not be called. |
| 1190 |
| 1191 int64 gaia_id = 0; |
| 1192 bool success = |
| 1193 base::StringToInt64(wallet_items_->obfuscated_gaia_id(), &gaia_id); |
| 1194 DCHECK(success); |
| 1195 |
| 1196 gfx::Rect window_bounds = |
| 1197 GetBaseWindowForWebContents(web_contents())->GetBounds(); |
| 1198 |
| 1199 risk::GetFingerprint( |
| 1200 gaia_id, window_bounds, *web_contents(), *profile_->GetPrefs(), |
| 1201 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, |
| 1202 weak_ptr_factory_.GetWeakPtr())); |
| 1203 } |
| 1204 |
| 1205 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
| 1206 scoped_ptr<risk::Fingerprint> fingerprint) { |
| 1207 NOTIMPLEMENTED(); |
| 1208 } |
| 1209 |
| 1155 } // namespace autofill | 1210 } // namespace autofill |
| OLD | NEW |