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

Side by Side Diff: chrome/browser/dom_ui/autofill_options_handler.cc

Issue 3140026: DOMUI: Implement the 'Remove...' button on the AutoFill page. (Closed)
Patch Set: DOMUI fixes. Created 10 years, 4 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/dom_ui/autofill_options_handler.h" 5 #include "chrome/browser/dom_ui/autofill_options_handler.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // PersonalDataManager::Observer implementation: 65 // PersonalDataManager::Observer implementation:
66 void AutoFillOptionsHandler::OnPersonalDataLoaded() { 66 void AutoFillOptionsHandler::OnPersonalDataLoaded() {
67 LoadAutoFillData(); 67 LoadAutoFillData();
68 } 68 }
69 69
70 void AutoFillOptionsHandler::OnPersonalDataChanged() { 70 void AutoFillOptionsHandler::OnPersonalDataChanged() {
71 LoadAutoFillData(); 71 LoadAutoFillData();
72 } 72 }
73 73
74 void AutoFillOptionsHandler::RegisterMessages() { 74 void AutoFillOptionsHandler::RegisterMessages() {
75 dom_ui_->RegisterMessageCallback(
76 "removeAddress",
77 NewCallback(this, &AutoFillOptionsHandler::RemoveAddress));
78
79 dom_ui_->RegisterMessageCallback(
80 "removeCreditCard",
81 NewCallback(this, &AutoFillOptionsHandler::RemoveCreditCard));
75 } 82 }
76 83
77 void AutoFillOptionsHandler::LoadAutoFillData() { 84 void AutoFillOptionsHandler::LoadAutoFillData() {
78 if (!personal_data_->IsDataLoaded()) 85 if (!personal_data_->IsDataLoaded())
79 return; 86 return;
80 87
81 ListValue addresses; 88 ListValue addresses;
82 for (std::vector<AutoFillProfile*>::const_iterator i = 89 for (std::vector<AutoFillProfile*>::const_iterator i =
83 personal_data_->profiles().begin(); 90 personal_data_->profiles().begin();
84 i != personal_data_->profiles().end(); ++i) { 91 i != personal_data_->profiles().end(); ++i) {
85 DictionaryValue* address = new DictionaryValue(); 92 DictionaryValue* address = new DictionaryValue();
86 address->SetString("label", (*i)->PreviewSummary()); 93 address->SetString("label", (*i)->PreviewSummary());
94 address->SetInteger("unique_id", (*i)->unique_id());
87 addresses.Append(address); 95 addresses.Append(address);
88 } 96 }
89 97
90 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateAddresses", 98 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateAddresses",
91 addresses); 99 addresses);
92 100
93 ListValue credit_cards; 101 ListValue credit_cards;
94 for (std::vector<CreditCard*>::const_iterator i = 102 for (std::vector<CreditCard*>::const_iterator i =
95 personal_data_->credit_cards().begin(); 103 personal_data_->credit_cards().begin();
96 i != personal_data_->credit_cards().end(); ++i) { 104 i != personal_data_->credit_cards().end(); ++i) {
97 DictionaryValue* credit_card = new DictionaryValue(); 105 DictionaryValue* credit_card = new DictionaryValue();
98 credit_card->SetString("label", (*i)->PreviewSummary()); 106 credit_card->SetString("label", (*i)->PreviewSummary());
107 credit_card->SetInteger("unique_id", (*i)->unique_id());
99 credit_cards.Append(credit_card); 108 credit_cards.Append(credit_card);
100 } 109 }
101 110
102 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateCreditCards", 111 dom_ui_->CallJavascriptFunction(L"AutoFillOptions.updateCreditCards",
103 credit_cards); 112 credit_cards);
104 } 113 }
114
115 void AutoFillOptionsHandler::RemoveAddress(const ListValue* args) {
116 if (!personal_data_->IsDataLoaded())
117 return;
118
119 int unique_id = 0;
120 if (!ExtractIntegerValue(args, &unique_id)) {
121 NOTREACHED();
122 return;
123 }
124
125 personal_data_->RemoveProfile(unique_id);
126 }
127
128 void AutoFillOptionsHandler::RemoveCreditCard(const ListValue* args) {
129 if (!personal_data_->IsDataLoaded())
130 return;
131
132 int unique_id = 0;
133 if (!ExtractIntegerValue(args, &unique_id)) {
134 NOTREACHED();
135 return;
136 }
137
138 personal_data_->RemoveCreditCard(unique_id);
139 }
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/autofill_options_handler.h ('k') | chrome/browser/resources/options/autofill_options.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698