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 "chrome/browser/chrome_notification_types.h" | |
8 #include "chrome/browser/ui/browser.h" | 7 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 8 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 9 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
11 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
12 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" | 12 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.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" | |
15 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 14 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
16 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 15 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
17 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 16 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
18 #include "chrome/grit/generated_resources.h" | 17 #include "chrome/grit/generated_resources.h" |
19 #include "content/public/browser/notification_source.h" | |
20 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
21 #include "content/public/browser/web_contents.h" | |
22 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/views/controls/button/blue_button.h" | 21 #include "ui/views/controls/button/blue_button.h" |
25 #include "ui/views/controls/button/label_button.h" | 22 #include "ui/views/controls/button/label_button.h" |
26 #include "ui/views/controls/combobox/combobox.h" | 23 #include "ui/views/controls/combobox/combobox.h" |
27 #include "ui/views/controls/combobox/combobox_listener.h" | 24 #include "ui/views/controls/combobox/combobox_listener.h" |
28 #include "ui/views/controls/link.h" | 25 #include "ui/views/controls/link.h" |
29 #include "ui/views/controls/link_listener.h" | 26 #include "ui/views/controls/link_listener.h" |
30 #include "ui/views/controls/separator.h" | 27 #include "ui/views/controls/separator.h" |
31 #include "ui/views/controls/styled_label.h" | 28 #include "ui/views/controls/styled_label.h" |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 979 |
983 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 980 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
984 return model()->web_contents(); | 981 return model()->web_contents(); |
985 } | 982 } |
986 | 983 |
987 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 984 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
988 content::WebContents* web_contents, | 985 content::WebContents* web_contents, |
989 ManagePasswordsIconView* anchor_view, | 986 ManagePasswordsIconView* anchor_view, |
990 DisplayReason reason) | 987 DisplayReason reason) |
991 : ManagePasswordsBubble(web_contents, reason), | 988 : ManagePasswordsBubble(web_contents, reason), |
992 BubbleDelegateView(anchor_view, | 989 ManagedFullScreenBubbleDelegateView(anchor_view, web_contents), |
993 anchor_view ? views::BubbleBorder::TOP_RIGHT | |
994 : views::BubbleBorder::NONE), | |
995 anchor_view_(anchor_view), | 990 anchor_view_(anchor_view), |
996 initially_focused_view_(NULL) { | 991 initially_focused_view_(NULL) { |
997 // Compensate for built-in vertical padding in the anchor view's image. | 992 // Compensate for built-in vertical padding in the anchor view's image. |
998 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 993 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
999 if (anchor_view) | 994 if (anchor_view) |
1000 anchor_view->SetActive(true); | 995 anchor_view->SetActive(true); |
1001 mouse_handler_.reset(new WebContentMouseHandler(this)); | 996 mouse_handler_.reset(new WebContentMouseHandler(this)); |
1002 | |
1003 // Add observers to close the bubble if the fullscreen state changes. | |
1004 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | |
1005 registrar_.Add( | |
1006 this, | |
1007 chrome::NOTIFICATION_FULLSCREEN_CHANGED, | |
1008 content::Source<FullscreenController>(browser->fullscreen_controller())); | |
1009 } | 997 } |
1010 | 998 |
1011 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 999 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
1012 if (anchor_view_) | 1000 if (anchor_view_) |
1013 anchor_view_->SetActive(false); | 1001 anchor_view_->SetActive(false); |
1014 } | 1002 } |
1015 | 1003 |
1016 void ManagePasswordsBubbleView::AdjustForFullscreen( | 1004 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
1017 const gfx::Rect& screen_bounds) { | 1005 return initially_focused_view_; |
1018 if (GetAnchorView()) | 1006 } |
1019 return; | |
1020 | 1007 |
1021 // The bubble's padding from the screen edge, used in fullscreen. | 1008 void ManagePasswordsBubbleView::Init() { |
1022 const int kFullscreenPaddingEnd = 20; | 1009 views::FillLayout* layout = new views::FillLayout(); |
1023 const size_t bubble_half_width = width() / 2; | 1010 SetLayoutManager(layout); |
1024 const int x_pos = base::i18n::IsRTL() ? | 1011 |
1025 screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd : | 1012 Refresh(); |
1026 screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd; | 1013 } |
1027 SetAnchorRect(gfx::Rect(x_pos, screen_bounds.y(), 0, 0)); | 1014 |
| 1015 void ManagePasswordsBubbleView::WindowClosing() { |
| 1016 // Close() closes the window asynchronously, so by the time we reach here, |
| 1017 // |manage_passwords_bubble_| may have already been reset. |
| 1018 if (manage_passwords_bubble_ == this) |
| 1019 manage_passwords_bubble_ = NULL; |
1028 } | 1020 } |
1029 | 1021 |
1030 void ManagePasswordsBubbleView::Close() { | 1022 void ManagePasswordsBubbleView::Close() { |
1031 mouse_handler_.reset(); | 1023 mouse_handler_.reset(); |
1032 GetWidget()->Close(); | 1024 ManagedFullScreenBubbleDelegateView::Close(); |
1033 } | 1025 } |
1034 | 1026 |
1035 void ManagePasswordsBubbleView::Refresh() { | 1027 void ManagePasswordsBubbleView::Refresh() { |
1036 RemoveAllChildViews(true); | 1028 RemoveAllChildViews(true); |
1037 initially_focused_view_ = NULL; | 1029 initially_focused_view_ = NULL; |
1038 bool need_resize = false; | 1030 bool need_resize = false; |
1039 if (password_manager::ui::IsPendingState(model()->state())) { | 1031 if (password_manager::ui::IsPendingState(model()->state())) { |
1040 if (model()->never_save_passwords()) | 1032 if (model()->never_save_passwords()) |
1041 AddChildView(new ConfirmNeverView(this)); | 1033 AddChildView(new ConfirmNeverView(this)); |
1042 else | 1034 else |
(...skipping 11 matching lines...) Expand all Loading... |
1054 AddChildView(new SetupOSPasswordView(this)); | 1046 AddChildView(new SetupOSPasswordView(this)); |
1055 need_resize = true; | 1047 need_resize = true; |
1056 } else { | 1048 } else { |
1057 AddChildView(new ManageView(this)); | 1049 AddChildView(new ManageView(this)); |
1058 } | 1050 } |
1059 GetLayoutManager()->Layout(this); | 1051 GetLayoutManager()->Layout(this); |
1060 if (need_resize) | 1052 if (need_resize) |
1061 SizeToContents(); | 1053 SizeToContents(); |
1062 } | 1054 } |
1063 | 1055 |
1064 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | |
1065 if (model()->best_matches().empty()) { | |
1066 // Skip confirmation if there are no existing passwords for this site. | |
1067 NotifyConfirmedNeverForThisSite(); | |
1068 } else { | |
1069 model()->OnConfirmationForNeverForThisSite(); | |
1070 Refresh(); | |
1071 } | |
1072 } | |
1073 | |
1074 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() { | 1056 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() { |
1075 model()->OnNeverForThisSiteClicked(); | 1057 model()->OnNeverForThisSiteClicked(); |
1076 Close(); | 1058 Close(); |
1077 } | 1059 } |
1078 | 1060 |
1079 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { | 1061 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { |
1080 model()->OnUndoNeverForThisSite(); | 1062 model()->OnUndoNeverForThisSite(); |
1081 Refresh(); | 1063 Refresh(); |
1082 } | 1064 } |
1083 | 1065 |
1084 void ManagePasswordsBubbleView::Init() { | 1066 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
1085 views::FillLayout* layout = new views::FillLayout(); | 1067 if (model()->best_matches().empty()) { |
1086 SetLayoutManager(layout); | 1068 // Skip confirmation if there are no existing passwords for this site. |
1087 | 1069 NotifyConfirmedNeverForThisSite(); |
1088 Refresh(); | 1070 } else { |
| 1071 model()->OnConfirmationForNeverForThisSite(); |
| 1072 Refresh(); |
| 1073 } |
1089 } | 1074 } |
1090 | |
1091 void ManagePasswordsBubbleView::WindowClosing() { | |
1092 // Close() closes the window asynchronously, so by the time we reach here, | |
1093 // |manage_passwords_bubble_| may have already been reset. | |
1094 if (manage_passwords_bubble_ == this) | |
1095 manage_passwords_bubble_ = NULL; | |
1096 } | |
1097 | |
1098 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | |
1099 return initially_focused_view_; | |
1100 } | |
1101 | |
1102 void ManagePasswordsBubbleView::Observe( | |
1103 int type, | |
1104 const content::NotificationSource& source, | |
1105 const content::NotificationDetails& details) { | |
1106 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | |
1107 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | |
1108 CloseBubble(); | |
1109 } | |
OLD | NEW |