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/timer/timer.h" | 7 #include "base/timer/timer.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.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" |
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 | 907 |
908 // ManagePasswordsBubbleView -------------------------------------------------- | 908 // ManagePasswordsBubbleView -------------------------------------------------- |
909 | 909 |
910 // static | 910 // static |
911 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 911 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
912 NULL; | 912 NULL; |
913 | 913 |
914 // static | 914 // static |
915 void ManagePasswordsBubbleView::ShowBubble( | 915 void ManagePasswordsBubbleView::ShowBubble( |
916 content::WebContents* web_contents, | 916 content::WebContents* web_contents, |
917 ManagePasswordsBubbleModel::DisplayReason reason) { | 917 DisplayReason reason) { |
918 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 918 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
919 DCHECK(browser); | 919 DCHECK(browser); |
920 DCHECK(browser->window()); | 920 DCHECK(browser->window()); |
921 DCHECK(!manage_passwords_bubble_ || | 921 DCHECK(!manage_passwords_bubble_ || |
922 !manage_passwords_bubble_->GetWidget()->IsVisible()); | 922 !manage_passwords_bubble_->GetWidget()->IsVisible()); |
923 | 923 |
924 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 924 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
925 bool is_fullscreen = browser_view->IsFullscreen(); | 925 bool is_fullscreen = browser_view->IsFullscreen(); |
926 ManagePasswordsIconViews* anchor_view = | 926 ManagePasswordsIconViews* anchor_view = |
927 is_fullscreen | 927 is_fullscreen |
928 ? NULL | 928 ? NULL |
929 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 929 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
930 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 930 manage_passwords_bubble_ = new ManagePasswordsBubbleView( |
931 web_contents, anchor_view, reason); | 931 web_contents, anchor_view, reason); |
932 | 932 |
933 if (is_fullscreen) | 933 if (is_fullscreen) |
934 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); | 934 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
935 | 935 |
936 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); | 936 views::BubbleDelegateView::CreateBubble(manage_passwords_bubble_); |
937 | 937 |
938 // Adjust for fullscreen after creation as it relies on the content size. | 938 // Adjust for fullscreen after creation as it relies on the content size. |
939 if (is_fullscreen) { | 939 if (is_fullscreen) { |
940 manage_passwords_bubble_->AdjustForFullscreen( | 940 manage_passwords_bubble_->AdjustForFullscreen( |
941 browser_view->GetBoundsInScreen()); | 941 browser_view->GetBoundsInScreen()); |
942 } | 942 } |
943 if (reason == ManagePasswordsBubbleModel::AUTOMATIC) | 943 |
944 manage_passwords_bubble_->GetWidget()->ShowInactive(); | 944 manage_passwords_bubble_->ShowForReason(reason); |
945 else | |
946 manage_passwords_bubble_->GetWidget()->Show(); | |
947 } | 945 } |
948 | 946 |
949 // static | 947 // static |
950 void ManagePasswordsBubbleView::CloseBubble() { | 948 void ManagePasswordsBubbleView::CloseBubble() { |
951 if (manage_passwords_bubble_) | 949 if (manage_passwords_bubble_) |
952 manage_passwords_bubble_->Close(); | 950 manage_passwords_bubble_->Close(); |
953 } | 951 } |
954 | 952 |
955 // static | 953 // static |
956 void ManagePasswordsBubbleView::ActivateBubble() { | 954 void ManagePasswordsBubbleView::ActivateBubble() { |
957 DCHECK(manage_passwords_bubble_); | 955 DCHECK(manage_passwords_bubble_); |
958 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); | 956 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); |
959 manage_passwords_bubble_->GetWidget()->Activate(); | 957 manage_passwords_bubble_->GetWidget()->Activate(); |
960 } | 958 } |
961 | 959 |
962 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 960 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
963 return model_.web_contents(); | 961 return model_.web_contents(); |
964 } | 962 } |
965 | 963 |
966 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 964 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
967 content::WebContents* web_contents, | 965 content::WebContents* web_contents, |
968 ManagePasswordsIconViews* anchor_view, | 966 ManagePasswordsIconViews* anchor_view, |
969 ManagePasswordsBubbleModel::DisplayReason reason) | 967 DisplayReason reason) |
970 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 968 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
971 model_(web_contents, reason), | 969 model_(web_contents, |
| 970 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
| 971 : ManagePasswordsBubbleModel::USER_ACTION), |
972 anchor_view_(anchor_view), | 972 anchor_view_(anchor_view), |
973 initially_focused_view_(NULL) { | 973 initially_focused_view_(nullptr) { |
974 // Compensate for built-in vertical padding in the anchor view's image. | 974 // Compensate for built-in vertical padding in the anchor view's image. |
975 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 975 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
976 | 976 |
977 const int top_margin = ShouldShowCloseButton() ? margins().top() | 977 const int top_margin = ShouldShowCloseButton() ? margins().top() |
978 : views::kPanelVertMargin; | 978 : views::kPanelVertMargin; |
979 set_margins(gfx::Insets(top_margin, views::kPanelHorizMargin, | 979 set_margins(gfx::Insets(top_margin, views::kPanelHorizMargin, |
980 views::kPanelVertMargin, views::kPanelHorizMargin)); | 980 views::kPanelVertMargin, views::kPanelHorizMargin)); |
981 if (anchor_view) | |
982 anchor_view->SetActive(true); | |
983 mouse_handler_.reset(new WebContentMouseHandler(this)); | 981 mouse_handler_.reset(new WebContentMouseHandler(this)); |
984 } | 982 } |
985 | 983 |
986 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 984 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
987 if (manage_passwords_bubble_ == this) | 985 if (manage_passwords_bubble_ == this) |
988 manage_passwords_bubble_ = NULL; | 986 manage_passwords_bubble_ = NULL; |
989 } | 987 } |
990 | 988 |
991 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 989 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
992 return initially_focused_view_; | 990 return initially_focused_view_; |
993 } | 991 } |
994 | 992 |
995 void ManagePasswordsBubbleView::Init() { | 993 void ManagePasswordsBubbleView::Init() { |
996 views::FillLayout* layout = new views::FillLayout(); | 994 views::FillLayout* layout = new views::FillLayout(); |
997 SetLayoutManager(layout); | 995 SetLayoutManager(layout); |
998 | 996 |
999 Refresh(); | 997 Refresh(); |
1000 } | 998 } |
1001 | 999 |
1002 void ManagePasswordsBubbleView::Close() { | 1000 void ManagePasswordsBubbleView::Close() { |
1003 mouse_handler_.reset(); | 1001 mouse_handler_.reset(); |
1004 LocationBarBubbleDelegateView::Close(); | 1002 LocationBarBubbleDelegateView::Close(); |
1005 } | 1003 } |
1006 | 1004 |
1007 void ManagePasswordsBubbleView::OnWidgetClosing(views::Widget* /*widget*/) { | |
1008 if (anchor_view_) | |
1009 anchor_view_->SetActive(false); | |
1010 } | |
1011 | |
1012 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { | 1005 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { |
1013 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE; | 1006 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE; |
1014 } | 1007 } |
1015 | 1008 |
1016 void ManagePasswordsBubbleView::Refresh() { | 1009 void ManagePasswordsBubbleView::Refresh() { |
1017 RemoveAllChildViews(true); | 1010 RemoveAllChildViews(true); |
1018 initially_focused_view_ = NULL; | 1011 initially_focused_view_ = NULL; |
1019 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 1012 if (model_.state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
1020 AddChildView(new PendingView(this)); | 1013 AddChildView(new PendingView(this)); |
1021 } else if (model_.state() == | 1014 } else if (model_.state() == |
1022 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { | 1015 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
1023 AddChildView(new UpdatePendingView(this)); | 1016 AddChildView(new UpdatePendingView(this)); |
1024 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) { | 1017 } else if (model_.state() == password_manager::ui::CONFIRMATION_STATE) { |
1025 AddChildView(new SaveConfirmationView(this)); | 1018 AddChildView(new SaveConfirmationView(this)); |
1026 } else if (model_.state() == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 1019 } else if (model_.state() == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
1027 AddChildView(new AccountChooserView(this)); | 1020 AddChildView(new AccountChooserView(this)); |
1028 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 1021 } else if (model_.state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
1029 AddChildView(new AutoSigninView(this)); | 1022 AddChildView(new AutoSigninView(this)); |
1030 } else { | 1023 } else { |
1031 AddChildView(new ManageView(this)); | 1024 AddChildView(new ManageView(this)); |
1032 } | 1025 } |
1033 GetLayoutManager()->Layout(this); | 1026 GetLayoutManager()->Layout(this); |
1034 } | 1027 } |
OLD | NEW |