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

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 1578173005: Move Autofill Payments integration checkbox to the sync settings page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Replace bool with enum in tests Created 4 years, 11 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 "chrome/browser/ui/webui/options/autofill_options_handler.h" 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/guid.h" 14 #include "base/guid.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/strings/string16.h" 17 #include "base/strings/string16.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 21 #include "base/values.h"
22 #include "chrome/browser/autofill/options_util.h" 22 #include "chrome/browser/autofill/options_util.h"
23 #include "chrome/browser/autofill/personal_data_manager_factory.h" 23 #include "chrome/browser/autofill/personal_data_manager_factory.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/sync/profile_sync_service_factory.h"
27 #include "chrome/browser/ui/autofill/country_combobox_model.h" 26 #include "chrome/browser/ui/autofill/country_combobox_model.h"
28 #include "chrome/common/url_constants.h" 27 #include "chrome/common/url_constants.h"
29 #include "chrome/grit/chromium_strings.h" 28 #include "chrome/grit/chromium_strings.h"
30 #include "chrome/grit/generated_resources.h" 29 #include "chrome/grit/generated_resources.h"
31 #include "components/autofill/content/browser/wallet/wallet_service_url.h" 30 #include "components/autofill/content/browser/wallet/wallet_service_url.h"
32 #include "components/autofill/core/browser/autofill_country.h" 31 #include "components/autofill/core/browser/autofill_country.h"
33 #include "components/autofill/core/browser/autofill_profile.h" 32 #include "components/autofill/core/browser/autofill_profile.h"
34 #include "components/autofill/core/browser/credit_card.h" 33 #include "components/autofill/core/browser/credit_card.h"
35 #include "components/autofill/core/browser/personal_data_manager.h" 34 #include "components/autofill/core/browser/personal_data_manager.h"
36 #include "components/autofill/core/browser/phone_number_i18n.h" 35 #include "components/autofill/core/browser/phone_number_i18n.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 localized_strings->Set("autofillDefaultCountryComponents", 202 localized_strings->Set("autofillDefaultCountryComponents",
204 default_country_components.release()); 203 default_country_components.release());
205 localized_strings->SetString("autofillDefaultCountryLanguageCode", 204 localized_strings->SetString("autofillDefaultCountryLanguageCode",
206 default_country_language_code); 205 default_country_language_code);
207 } 206 }
208 207
209 } // namespace 208 } // namespace
210 209
211 namespace options { 210 namespace options {
212 211
213 AutofillOptionsHandler::AutofillOptionsHandler() 212 AutofillOptionsHandler::AutofillOptionsHandler() : personal_data_(NULL) {}
214 : personal_data_(NULL), observer_(this) {
215 }
216 213
217 AutofillOptionsHandler::~AutofillOptionsHandler() { 214 AutofillOptionsHandler::~AutofillOptionsHandler() {
218 if (personal_data_) 215 if (personal_data_)
219 personal_data_->RemoveObserver(this); 216 personal_data_->RemoveObserver(this);
220 } 217 }
221 218
222 ///////////////////////////////////////////////////////////////////////////// 219 /////////////////////////////////////////////////////////////////////////////
223 // OptionsPageUIHandler implementation: 220 // OptionsPageUIHandler implementation:
224 void AutofillOptionsHandler::GetLocalizedValues( 221 void AutofillOptionsHandler::GetLocalizedValues(
225 base::DictionaryValue* localized_strings) { 222 base::DictionaryValue* localized_strings) {
226 DCHECK(localized_strings); 223 DCHECK(localized_strings);
227 224
228 static OptionsStringResource resources[] = { 225 static OptionsStringResource resources[] = {
229 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME }, 226 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME },
230 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME }, 227 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME },
231 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON }, 228 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON },
232 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON }, 229 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON },
233 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON }, 230 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON },
234 { "autofillFromGoogleAccount", IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT }, 231 { "autofillFromGoogleAccount", IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT },
235 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY }, 232 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY },
236 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON }, 233 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON },
237 { "helpButton", IDS_AUTOFILL_HELP_LABEL }, 234 { "helpButton", IDS_AUTOFILL_HELP_LABEL },
238 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION }, 235 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION },
239 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION }, 236 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION },
240 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION }, 237 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION },
241 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION }, 238 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION },
242 { "autofillWalletOption", IDS_AUTOFILL_USE_WALLET_DATA },
243 }; 239 };
244 240
245 RegisterStrings(localized_strings, resources, arraysize(resources)); 241 RegisterStrings(localized_strings, resources, arraysize(resources));
246 RegisterTitle(localized_strings, "autofillOptionsPage", 242 RegisterTitle(localized_strings, "autofillOptionsPage",
247 IDS_AUTOFILL_OPTIONS_TITLE); 243 IDS_AUTOFILL_OPTIONS_TITLE);
248 244
249 localized_strings->SetString("helpUrl", autofill::kHelpURL); 245 localized_strings->SetString("helpUrl", autofill::kHelpURL);
250 246
251 personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile( 247 personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile(
252 Profile::FromWebUI(web_ui())); 248 Profile::FromWebUI(web_ui()));
253 249
254 SetAddressOverlayStrings(localized_strings); 250 SetAddressOverlayStrings(localized_strings);
255 SetCreditCardOverlayStrings(localized_strings); 251 SetCreditCardOverlayStrings(localized_strings);
256 252
257 localized_strings->SetString( 253 localized_strings->SetString(
258 "manageWalletAddressesUrl", 254 "manageWalletAddressesUrl",
259 autofill::wallet::GetManageAddressesUrl(0).spec()); 255 autofill::wallet::GetManageAddressesUrl(0).spec());
260 localized_strings->SetString( 256 localized_strings->SetString(
261 "manageWalletPaymentMethodsUrl", 257 "manageWalletPaymentMethodsUrl",
262 autofill::wallet::GetManageInstrumentsUrl(0).spec()); 258 autofill::wallet::GetManageInstrumentsUrl(0).spec());
263
264 // This is set in loadTimeData to minimize the chance of a load-time flash of
265 // content.
266 ProfileSyncService* service =
267 ProfileSyncServiceFactory::GetInstance()->GetForProfile(
268 Profile::FromWebUI(web_ui()));
269 if (service)
270 observer_.Add(service);
271
272 localized_strings->SetBoolean("autofillWalletIntegrationAvailable",
273 autofill::WalletIntegrationAvailableForProfile(
274 Profile::FromWebUI(web_ui())));
275 } 259 }
276 260
277 void AutofillOptionsHandler::InitializeHandler() { 261 void AutofillOptionsHandler::InitializeHandler() {
278 // personal_data_ is NULL in guest mode on Chrome OS. 262 // personal_data_ is NULL in guest mode on Chrome OS.
279 if (personal_data_) 263 if (personal_data_)
280 personal_data_->AddObserver(this); 264 personal_data_->AddObserver(this);
281 } 265 }
282 266
283 void AutofillOptionsHandler::InitializePage() { 267 void AutofillOptionsHandler::InitializePage() {
284 if (personal_data_) 268 if (personal_data_)
285 LoadAutofillData(); 269 LoadAutofillData();
286
287 // Also update the visibility of the Wallet checkbox (which may have
288 // changed since the localized string dictionary was built).
289 OnStateChanged();
290 } 270 }
291 271
292 void AutofillOptionsHandler::RegisterMessages() { 272 void AutofillOptionsHandler::RegisterMessages() {
293 web_ui()->RegisterMessageCallback( 273 web_ui()->RegisterMessageCallback(
294 "removeData", 274 "removeData",
295 base::Bind(&AutofillOptionsHandler::RemoveData, 275 base::Bind(&AutofillOptionsHandler::RemoveData,
296 base::Unretained(this))); 276 base::Unretained(this)));
297 web_ui()->RegisterMessageCallback( 277 web_ui()->RegisterMessageCallback(
298 "loadAddressEditor", 278 "loadAddressEditor",
299 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, 279 base::Bind(&AutofillOptionsHandler::LoadAddressEditor,
(...skipping 16 matching lines...) Expand all
316 web_ui()->RegisterMessageCallback( 296 web_ui()->RegisterMessageCallback(
317 "clearLocalCardCopy", 297 "clearLocalCardCopy",
318 base::Bind(&AutofillOptionsHandler::RemaskServerCard, 298 base::Bind(&AutofillOptionsHandler::RemaskServerCard,
319 base::Unretained(this))); 299 base::Unretained(this)));
320 } 300 }
321 301
322 ///////////////////////////////////////////////////////////////////////////// 302 /////////////////////////////////////////////////////////////////////////////
323 // PersonalDataManagerObserver implementation: 303 // PersonalDataManagerObserver implementation:
324 void AutofillOptionsHandler::OnPersonalDataChanged() { 304 void AutofillOptionsHandler::OnPersonalDataChanged() {
325 LoadAutofillData(); 305 LoadAutofillData();
326 OnStateChanged();
327 }
328
329 void AutofillOptionsHandler::OnStateChanged() {
330 web_ui()->CallJavascriptFunction(
331 "AutofillOptions.walletIntegrationAvailableStateChanged",
332 base::FundamentalValue(autofill::WalletIntegrationAvailableForProfile(
333 Profile::FromWebUI(web_ui()))));
334 } 306 }
335 307
336 void AutofillOptionsHandler::SetAddressOverlayStrings( 308 void AutofillOptionsHandler::SetAddressOverlayStrings(
337 base::DictionaryValue* localized_strings) { 309 base::DictionaryValue* localized_strings) {
338 localized_strings->SetString("autofillEditAddressTitle", 310 localized_strings->SetString("autofillEditAddressTitle",
339 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); 311 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION));
340 localized_strings->SetString("autofillCountryLabel", 312 localized_strings->SetString("autofillCountryLabel",
341 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); 313 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL));
342 localized_strings->SetString("autofillPhoneLabel", 314 localized_strings->SetString("autofillPhoneLabel",
343 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); 315 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE));
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 scoped_ptr<base::ListValue> components(new base::ListValue); 610 scoped_ptr<base::ListValue> components(new base::ListValue);
639 GetAddressComponents( 611 GetAddressComponents(
640 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), 612 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
641 profile.language_code(), 613 profile.language_code(),
642 components.get(), 614 components.get(),
643 NULL); 615 NULL);
644 address->Set(kComponents, components.release()); 616 address->Set(kComponents, components.release());
645 } 617 }
646 618
647 } // namespace options 619 } // namespace options
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/options/autofill_options_handler.h ('k') | chrome/browser/ui/webui/options/sync_setup_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698