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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 return true; | 162 return true; |
145 } | 163 } |
146 | 164 |
147 bool AutofillPopupView::IsSeparatorIndex(int index) { | 165 bool AutofillPopupView::IsSeparatorIndex(int index) { |
148 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. | 166 // TODO(csharp): Use WebAutofillClient::MenuItemIDSeparator instead. |
149 // http://crbug.com/125001 | 167 // http://crbug.com/125001 |
150 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && | 168 return (index > 0 && autofill_unique_ids_[index - 1] >= 0 && |
151 autofill_unique_ids_[index] < 0); | 169 autofill_unique_ids_[index] < 0); |
152 } | 170 } |
153 | 171 |
| 172 int AutofillPopupView::GetIconResourceID(const string16& resource_name) { |
| 173 for (size_t i = 0; i < arraysize(kDataResources); ++i) { |
| 174 if (resource_name == ASCIIToUTF16(kDataResources[i].name)) |
| 175 return kDataResources[i].id; |
| 176 } |
| 177 |
| 178 return -1; |
| 179 } |
| 180 |
154 bool AutofillPopupView::CanDelete(int id) { | 181 bool AutofillPopupView::CanDelete(int id) { |
155 return id > 0 || | 182 return id > 0 || |
156 id == WebAutofillClient::MenuItemIDAutocompleteEntry || | 183 id == WebAutofillClient::MenuItemIDAutocompleteEntry || |
157 id == WebAutofillClient::MenuItemIDPasswordEntry; | 184 id == WebAutofillClient::MenuItemIDPasswordEntry; |
158 } | 185 } |
159 | 186 |
160 bool AutofillPopupView::HasAutofillEntries() { | 187 bool AutofillPopupView::HasAutofillEntries() { |
161 return autofill_values_.size() != 0 && | 188 return autofill_values_.size() != 0 && |
162 (autofill_unique_ids_[0] > 0 || | 189 (autofill_unique_ids_[0] > 0 || |
163 autofill_unique_ids_[0] == | 190 autofill_unique_ids_[0] == |
164 WebAutofillClient::MenuItemIDAutocompleteEntry || | 191 WebAutofillClient::MenuItemIDAutocompleteEntry || |
165 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || | 192 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDPasswordEntry || |
166 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); | 193 autofill_unique_ids_[0] == WebAutofillClient::MenuItemIDDataListEntry); |
167 } | 194 } |
168 | 195 |
169 void AutofillPopupView::Observe(int type, | 196 void AutofillPopupView::Observe(int type, |
170 const content::NotificationSource& source, | 197 const content::NotificationSource& source, |
171 const content::NotificationDetails& details) { | 198 const content::NotificationDetails& details) { |
172 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN | 199 if (type == content::NOTIFICATION_WEB_CONTENTS_HIDDEN |
173 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) | 200 || type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) |
174 Hide(); | 201 Hide(); |
175 } | 202 } |
OLD | NEW |