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

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 254263002: Password bubble: ManagePasswordsIconView is now a BubbleIconView. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: scoped_ptr. Created 6 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/views/passwords/manage_passwords_bubble_view.h" 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/ui/browser.h" 9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/browser/ui/browser_finder.h" 10 #include "chrome/browser/ui/browser_finder.h"
11 #include "chrome/browser/ui/browser_window.h" 11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h"
13 #include "chrome/browser/ui/passwords/manage_passwords_bubble_ui_controller.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" 15 #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
15 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h" 16 #include "chrome/browser/ui/views/passwords/manage_password_item_view.h"
16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" 17 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h"
17 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
18 #include "content/public/browser/web_contents_view.h" 19 #include "content/public/browser/web_contents_view.h"
19 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/models/combobox_model.h" 22 #include "ui/base/models/combobox_model.h"
22 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
(...skipping 16 matching lines...) Expand all
39 const int kPasswordFieldSize = 22; 40 const int kPasswordFieldSize = 22;
40 41
41 // Returns the width of |type| field. 42 // Returns the width of |type| field.
42 int GetFieldWidth(FieldType type) { 43 int GetFieldWidth(FieldType type) {
43 return ui::ResourceBundle::GetSharedInstance() 44 return ui::ResourceBundle::GetSharedInstance()
44 .GetFontList(ui::ResourceBundle::SmallFont) 45 .GetFontList(ui::ResourceBundle::SmallFont)
45 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize 46 .GetExpectedTextWidth(type == USERNAME_FIELD ? kUsernameFieldSize
46 : kPasswordFieldSize); 47 : kPasswordFieldSize);
47 } 48 }
48 49
49 class SavePasswordRefusalComboboxModel : public ui::ComboboxModel {
50 public:
51 enum { INDEX_NOPE = 0, INDEX_NEVER_FOR_THIS_SITE = 1, };
52
53 SavePasswordRefusalComboboxModel() {
54 items_.push_back(
55 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON));
56 items_.push_back(
57 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON));
58 }
59 virtual ~SavePasswordRefusalComboboxModel() {}
60
61 private:
62 // Overridden from ui::ComboboxModel:
63 virtual int GetItemCount() const OVERRIDE { return items_.size(); }
64 virtual base::string16 GetItemAt(int index) OVERRIDE { return items_[index]; }
65 virtual bool IsItemSeparatorAt(int index) OVERRIDE {
66 return items_[index].empty();
67 }
68 virtual int GetDefaultIndex() const OVERRIDE { return 0; }
69
70 std::vector<base::string16> items_;
71
72 DISALLOW_COPY_AND_ASSIGN(SavePasswordRefusalComboboxModel);
73 };
74
75 } // namespace 50 } // namespace
76 51
77 52
53 // Globals --------------------------------------------------------------------
54
55 namespace chrome {
56
57 void ShowManagePasswordsBubble(content::WebContents* web_contents) {
58 ManagePasswordsBubbleUIController* controller =
59 ManagePasswordsBubbleUIController::FromWebContents(web_contents);
60 ManagePasswordsBubbleView::ShowBubble(
61 web_contents,
62 controller->manage_passwords_bubble_needs_showing() ?
63 ManagePasswordsBubbleView::AUTOMATIC :
64 ManagePasswordsBubbleView::USER_ACTION);
65 }
66
67 } // namespace chrome
68
69
78 // ManagePasswordsBubbleView -------------------------------------------------- 70 // ManagePasswordsBubbleView --------------------------------------------------
79 71
80 // static 72 // static
81 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 73 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
82 NULL; 74 NULL;
83 75
84 // static 76 // static
85 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, 77 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents,
86 DisplayReason reason) { 78 DisplayReason reason) {
87 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 79 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 // a "Save" and "Reject" button. 248 // a "Save" and "Reject" button.
257 ManagePasswordItemView* item = 249 ManagePasswordItemView* item =
258 new ManagePasswordItemView(model(), 250 new ManagePasswordItemView(model(),
259 model()->pending_credentials(), 251 model()->pending_credentials(),
260 first_field_width, 252 first_field_width,
261 second_field_width, 253 second_field_width,
262 ManagePasswordItemView::FIRST_ITEM); 254 ManagePasswordItemView::FIRST_ITEM);
263 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 255 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
264 layout->AddView(item); 256 layout->AddView(item);
265 257
266 refuse_combobox_ = 258 combobox_model_.reset(new SavePasswordRefusalComboboxModel());
267 new views::Combobox(new SavePasswordRefusalComboboxModel()); 259 refuse_combobox_.reset(new views::Combobox(combobox_model_.get()));
268 refuse_combobox_->set_listener(this); 260 refuse_combobox_->set_listener(this);
269 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION); 261 refuse_combobox_->SetStyle(views::Combobox::STYLE_ACTION);
270 262
271 save_button_ = new views::BlueButton( 263 save_button_ = new views::BlueButton(
272 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON)); 264 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON));
273 265
274 layout->StartRowWithPadding( 266 layout->StartRowWithPadding(
275 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); 267 0, DOUBLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
276 layout->AddView(save_button_); 268 layout->AddView(save_button_);
277 layout->AddView(refuse_combobox_); 269 layout->AddView(refuse_combobox_.get());
278 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 270 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
279 } else { 271 } else {
280 // If we have a list of passwords to store for the current site, display 272 // If we have a list of passwords to store for the current site, display
281 // them to the user for management. Otherwise, render a "No passwords for 273 // them to the user for management. Otherwise, render a "No passwords for
282 // this site" message. 274 // this site" message.
283 // 275 //
284 // TODO(mkwst): Do we really want the "No passwords" case? It would probably 276 // TODO(mkwst): Do we really want the "No passwords" case? It would probably
285 // be better to only clear the pending password upon navigation, rather than 277 // be better to only clear the pending password upon navigation, rather than
286 // as soon as the bubble closes. 278 // as soon as the bubble closes.
287 if (!model()->best_matches().empty()) { 279 if (!model()->best_matches().empty()) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 break; 354 break;
363 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE: 355 case SavePasswordRefusalComboboxModel::INDEX_NEVER_FOR_THIS_SITE:
364 model()->OnNeverForThisSiteClicked(); 356 model()->OnNeverForThisSiteClicked();
365 break; 357 break;
366 default: 358 default:
367 NOTREACHED(); 359 NOTREACHED();
368 break; 360 break;
369 } 361 }
370 Close(); 362 Close();
371 } 363 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698