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/autofill/autofill_popup_view.h" | 5 #include "chrome/browser/autofill/autofill_popup_view.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/autofill/autofill_external_delegate.h" | 9 #include "chrome/browser/autofill/autofill_external_delegate.h" |
9 #include "content/public/browser/web_contents.h" | 10 #include "content/public/browser/web_contents.h" |
10 #include "content/public/browser/navigation_controller.h" | 11 #include "content/public/browser/navigation_controller.h" |
11 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_source.h" | 13 #include "content/public/browser/notification_source.h" |
13 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "grit/webkit_resources.h" |
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
15 | 17 |
16 using WebKit::WebAutofillClient; | 18 using WebKit::WebAutofillClient; |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 // Used to indicate that no line is currently selected by the user. | 22 // Used to indicate that no line is currently selected by the user. |
21 const int kNoSelection = -1; | 23 const int kNoSelection = -1; |
22 | 24 |
| 25 struct DataResource { |
| 26 const char* name; |
| 27 int id; |
| 28 }; |
| 29 |
| 30 const DataResource kDataResources[] = { |
| 31 { "americanExpressCC", IDR_AUTOFILL_CC_AMEX }, |
| 32 { "dinersCC", IDR_AUTOFILL_CC_DINERS }, |
| 33 { "discoverCC", IDR_AUTOFILL_CC_DISCOVER }, |
| 34 { "genericCC", IDR_AUTOFILL_CC_GENERIC }, |
| 35 { "jcbCC", IDR_AUTOFILL_CC_JCB }, |
| 36 { "masterCardCC", IDR_AUTOFILL_CC_MASTERCARD }, |
| 37 { "soloCC", IDR_AUTOFILL_CC_SOLO }, |
| 38 { "visaCC", IDR_AUTOFILL_CC_VISA }, |
| 39 }; |
| 40 |
23 } // end namespace | 41 } // end namespace |
24 | 42 |
25 AutofillPopupView::AutofillPopupView( | 43 AutofillPopupView::AutofillPopupView( |
26 content::WebContents* web_contents, | 44 content::WebContents* web_contents, |
27 AutofillExternalDelegate* external_delegate) | 45 AutofillExternalDelegate* external_delegate) |
28 : external_delegate_(external_delegate), | 46 : external_delegate_(external_delegate), |
29 selected_line_(kNoSelection) { | 47 selected_line_(kNoSelection) { |
30 if (!web_contents) | 48 if (!web_contents) |
31 return; | 49 return; |
32 | 50 |
(...skipping 17 matching lines...) Expand all Loading... |
50 | 68 |
51 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, | 69 void AutofillPopupView::Show(const std::vector<string16>& autofill_values, |
52 const std::vector<string16>& autofill_labels, | 70 const std::vector<string16>& autofill_labels, |
53 const std::vector<string16>& autofill_icons, | 71 const std::vector<string16>& autofill_icons, |
54 const std::vector<int>& autofill_unique_ids) { | 72 const std::vector<int>& autofill_unique_ids) { |
55 autofill_values_ = autofill_values; | 73 autofill_values_ = autofill_values; |
56 autofill_labels_ = autofill_labels; | 74 autofill_labels_ = autofill_labels; |
57 autofill_icons_ = autofill_icons; | 75 autofill_icons_ = autofill_icons; |
58 autofill_unique_ids_ = autofill_unique_ids; | 76 autofill_unique_ids_ = autofill_unique_ids; |
59 | 77 |
| 78 has_icons_ = false; |
| 79 for (size_t i = 0; i < autofill_icons_.size(); ++i) { |
| 80 if (!autofill_icons_[i].empty()) { |
| 81 has_icons_ = true; |
| 82 break; |
| 83 } |
| 84 } |
| 85 |
| 86 |
60 ShowInternal(); | 87 ShowInternal(); |
61 } | 88 } |
62 | 89 |
63 void AutofillPopupView::SetSelectedLine(int selected_line) { | 90 void AutofillPopupView::SetSelectedLine(int selected_line) { |
64 if (selected_line_ == selected_line) | 91 if (selected_line_ == selected_line) |
65 return; | 92 return; |
66 | 93 |
67 if (selected_line_ != kNoSelection) | 94 if (selected_line_ != kNoSelection) |
68 InvalidateRow(selected_line_); | 95 InvalidateRow(selected_line_); |
69 | 96 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return true; | 171 return true; |
145 } | 172 } |
146 | 173 |
147 bool AutofillPopupView::IsSeparatorIndex(int index) { | 174 bool AutofillPopupView::IsSeparatorIndex(int index) { |
148 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. | 175 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. |
149 // http://crbug.com/125001 | 176 // http://crbug.com/125001 |
150 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && | 177 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && |
151 autofill_unique_ids_[index] < 0); | 178 autofill_unique_ids_[index] < 0); |
152 } | 179 } |
153 | 180 |
| 181 int AutofillPopupView::GetIconResourceID(const string16& resource_name) { |
| 182 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
| 183 if (resource_name == ASCIIToUTF16(kDataResources[i].name)) |
| 184 return kDataResources[i].id; |
| 185 } |
| 186 |
| 187 return -1; |
| 188 } |
| 189 |
154 bool AutofillPopupView::CanDelete(int id) { | 190 bool AutofillPopupView::CanDelete(int id) { |
155 return id > 0 || | 191 return id > 0 || |
156 id == WebAutofillClient::MenuItemIDAutocompleteEntry || | 192 id == WebAutofillClient::MenuItemIDAutocompleteEntry || |
157 id == WebAutofillClient::MenuItemIDPasswordEntry; | 193 id == WebAutofillClient::MenuItemIDPasswordEntry; |
158 } | 194 } |
159 | 195 |
160 bool AutofillPopupView::HasAutofillEntries() { | 196 bool AutofillPopupView::HasAutofillEntries() { |
161 return autofill_values_.size() != 0 && | 197 return autofill_values_.size() != 0 && |
162 (autofill_unique_ids_[0] > 0 || | 198 (autofill_unique_ids_[0] > 0 || |
163 autofill_unique_ids_[0] == | 199 autofill_unique_ids_[0] == |
164 WebAutofillClient::MenuItemIDAutocompleteEntry || | 200 WebAutofillClient::MenuItemIDAutocompleteEntry || |
165 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || | 201 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || |
166 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); | 202 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); |
167 } | 203 } |
168 | 204 |
169 void AutofillPopupView::Observe(int type, | 205 void AutofillPopupView::Observe(int type, |
170 const content::NotificationSource& source, | 206 const content::NotificationSource& source, |
171 const content::NotificationDetails& details) { | 207 const content::NotificationDetails& details) { |
172 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN | 208 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN |
173 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) | 209 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) |
174 Hide(); | 210 Hide(); |
175 } | 211 } |
OLD | NEW |