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

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: 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 } 213 }
216 214
217 AutofillOptionsHandler::~AutofillOptionsHandler() { 215 AutofillOptionsHandler::~AutofillOptionsHandler() {
218 if (personal_data_) 216 if (personal_data_)
219 personal_data_->RemoveObserver(this); 217 personal_data_->RemoveObserver(this);
220 } 218 }
221 219
222 ///////////////////////////////////////////////////////////////////////////// 220 /////////////////////////////////////////////////////////////////////////////
223 // OptionsPageUIHandler implementation: 221 // OptionsPageUIHandler implementation:
224 void AutofillOptionsHandler::GetLocalizedValues( 222 void AutofillOptionsHandler::GetLocalizedValues(
225 base::DictionaryValue* localized_strings) { 223 base::DictionaryValue* localized_strings) {
226 DCHECK(localized_strings); 224 DCHECK(localized_strings);
227 225
228 static OptionsStringResource resources[] = { 226 static OptionsStringResource resources[] = {
229 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME }, 227 { "autofillAddresses", IDS_AUTOFILL_ADDRESSES_GROUP_NAME },
230 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME }, 228 { "autofillCreditCards", IDS_AUTOFILL_CREDITCARDS_GROUP_NAME },
231 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON }, 229 { "autofillAddAddress", IDS_AUTOFILL_ADD_ADDRESS_BUTTON },
232 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON }, 230 { "autofillAddCreditCard", IDS_AUTOFILL_ADD_CREDITCARD_BUTTON },
233 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON }, 231 { "autofillEditProfileButton", IDS_AUTOFILL_EDIT_PROFILE_BUTTON },
234 { "autofillFromGoogleAccount", IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT }, 232 { "autofillFromGoogleAccount", IDS_AUTOFILL_FROM_GOOGLE_ACCOUNT },
235 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY }, 233 { "autofillDescribeLocalCopy", IDS_AUTOFILL_DESCRIBE_LOCAL_COPY },
236 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON }, 234 { "autofillClearLocalCopyButton", IDS_AUTOFILL_CLEAR_LOCAL_COPY_BUTTON },
237 { "helpButton", IDS_AUTOFILL_HELP_LABEL }, 235 { "helpButton", IDS_AUTOFILL_HELP_LABEL },
238 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION }, 236 { "addAddressTitle", IDS_AUTOFILL_ADD_ADDRESS_CAPTION },
239 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION }, 237 { "editAddressTitle", IDS_AUTOFILL_EDIT_ADDRESS_CAPTION },
240 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION }, 238 { "addCreditCardTitle", IDS_AUTOFILL_ADD_CREDITCARD_CAPTION },
241 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION }, 239 { "editCreditCardTitle", IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION },
242 { "autofillWalletOption", IDS_AUTOFILL_USE_WALLET_DATA },
243 }; 240 };
244 241
245 RegisterStrings(localized_strings, resources, arraysize(resources)); 242 RegisterStrings(localized_strings, resources, arraysize(resources));
246 RegisterTitle(localized_strings, "autofillOptionsPage", 243 RegisterTitle(localized_strings, "autofillOptionsPage",
247 IDS_AUTOFILL_OPTIONS_TITLE); 244 IDS_AUTOFILL_OPTIONS_TITLE);
248 245
249 localized_strings->SetString("helpUrl", autofill::kHelpURL); 246 localized_strings->SetString("helpUrl", autofill::kHelpURL);
250 247
251 personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile( 248 personal_data_ = autofill::PersonalDataManagerFactory::GetForProfile(
252 Profile::FromWebUI(web_ui())); 249 Profile::FromWebUI(web_ui()));
253 250
254 SetAddressOverlayStrings(localized_strings); 251 SetAddressOverlayStrings(localized_strings);
255 SetCreditCardOverlayStrings(localized_strings); 252 SetCreditCardOverlayStrings(localized_strings);
256 253
257 localized_strings->SetString( 254 localized_strings->SetString(
258 "manageWalletAddressesUrl", 255 "manageWalletAddressesUrl",
259 autofill::wallet::GetManageAddressesUrl(0).spec()); 256 autofill::wallet::GetManageAddressesUrl(0).spec());
260 localized_strings->SetString( 257 localized_strings->SetString(
261 "manageWalletPaymentMethodsUrl", 258 "manageWalletPaymentMethodsUrl",
262 autofill::wallet::GetManageInstrumentsUrl(0).spec()); 259 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 } 260 }
276 261
277 void AutofillOptionsHandler::InitializeHandler() { 262 void AutofillOptionsHandler::InitializeHandler() {
278 // personal_data_ is NULL in guest mode on Chrome OS. 263 // personal_data_ is NULL in guest mode on Chrome OS.
279 if (personal_data_) 264 if (personal_data_)
280 personal_data_->AddObserver(this); 265 personal_data_->AddObserver(this);
281 } 266 }
282 267
283 void AutofillOptionsHandler::InitializePage() { 268 void AutofillOptionsHandler::InitializePage() {
284 if (personal_data_) 269 if (personal_data_)
285 LoadAutofillData(); 270 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 } 271 }
291 272
292 void AutofillOptionsHandler::RegisterMessages() { 273 void AutofillOptionsHandler::RegisterMessages() {
293 web_ui()->RegisterMessageCallback( 274 web_ui()->RegisterMessageCallback(
294 "removeData", 275 "removeData",
295 base::Bind(&AutofillOptionsHandler::RemoveData, 276 base::Bind(&AutofillOptionsHandler::RemoveData,
296 base::Unretained(this))); 277 base::Unretained(this)));
297 web_ui()->RegisterMessageCallback( 278 web_ui()->RegisterMessageCallback(
298 "loadAddressEditor", 279 "loadAddressEditor",
299 base::Bind(&AutofillOptionsHandler::LoadAddressEditor, 280 base::Bind(&AutofillOptionsHandler::LoadAddressEditor,
(...skipping 16 matching lines...) Expand all
316 web_ui()->RegisterMessageCallback( 297 web_ui()->RegisterMessageCallback(
317 "clearLocalCardCopy", 298 "clearLocalCardCopy",
318 base::Bind(&AutofillOptionsHandler::RemaskServerCard, 299 base::Bind(&AutofillOptionsHandler::RemaskServerCard,
319 base::Unretained(this))); 300 base::Unretained(this)));
320 } 301 }
321 302
322 ///////////////////////////////////////////////////////////////////////////// 303 /////////////////////////////////////////////////////////////////////////////
323 // PersonalDataManagerObserver implementation: 304 // PersonalDataManagerObserver implementation:
324 void AutofillOptionsHandler::OnPersonalDataChanged() { 305 void AutofillOptionsHandler::OnPersonalDataChanged() {
325 LoadAutofillData(); 306 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 } 307 }
335 308
336 void AutofillOptionsHandler::SetAddressOverlayStrings( 309 void AutofillOptionsHandler::SetAddressOverlayStrings(
337 base::DictionaryValue* localized_strings) { 310 base::DictionaryValue* localized_strings) {
338 localized_strings->SetString("autofillEditAddressTitle", 311 localized_strings->SetString("autofillEditAddressTitle",
339 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); 312 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION));
340 localized_strings->SetString("autofillCountryLabel", 313 localized_strings->SetString("autofillCountryLabel",
341 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); 314 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL));
342 localized_strings->SetString("autofillPhoneLabel", 315 localized_strings->SetString("autofillPhoneLabel",
343 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); 316 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); 611 scoped_ptr<base::ListValue> components(new base::ListValue);
639 GetAddressComponents( 612 GetAddressComponents(
640 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), 613 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)),
641 profile.language_code(), 614 profile.language_code(),
642 components.get(), 615 components.get(),
643 NULL); 616 NULL);
644 address->Set(kComponents, components.release()); 617 address->Set(kComponents, components.release());
645 } 618 }
646 619
647 } // namespace options 620 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698