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