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/macros.h" | 7 #include "base/macros.h" |
8 #include "base/metrics/user_metrics.h" | 8 #include "base/metrics/user_metrics.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/browser_window.h" | |
14 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 15 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
15 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" | 16 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" |
16 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 17 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | |
18 #include "chrome/browser/ui/views/harmony/layout_delegate.h" | 18 #include "chrome/browser/ui/views/harmony/layout_delegate.h" |
19 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 19 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
20 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" | 20 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
21 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 21 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
22 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 22 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
23 #include "chrome/grit/generated_resources.h" | 23 #include "chrome/grit/generated_resources.h" |
24 #include "components/strings/grit/components_strings.h" | 24 #include "components/strings/grit/components_strings.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/material_design/material_design_controller.h" | 26 #include "ui/base/material_design/material_design_controller.h" |
27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
28 #include "ui/base/ui_features.h" | |
28 #include "ui/gfx/color_palette.h" | 29 #include "ui/gfx/color_palette.h" |
29 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
30 #include "ui/native_theme/native_theme.h" | 31 #include "ui/native_theme/native_theme.h" |
31 #include "ui/views/controls/button/blue_button.h" | 32 #include "ui/views/controls/button/blue_button.h" |
32 #include "ui/views/controls/button/md_text_button.h" | 33 #include "ui/views/controls/button/md_text_button.h" |
33 #include "ui/views/controls/link.h" | 34 #include "ui/views/controls/link.h" |
34 #include "ui/views/controls/link_listener.h" | 35 #include "ui/views/controls/link_listener.h" |
35 #include "ui/views/controls/separator.h" | 36 #include "ui/views/controls/separator.h" |
36 #include "ui/views/controls/styled_label.h" | 37 #include "ui/views/controls/styled_label.h" |
37 #include "ui/views/controls/styled_label_listener.h" | 38 #include "ui/views/controls/styled_label_listener.h" |
38 #include "ui/views/layout/fill_layout.h" | 39 #include "ui/views/layout/fill_layout.h" |
39 #include "ui/views/layout/grid_layout.h" | 40 #include "ui/views/layout/grid_layout.h" |
40 #include "ui/views/layout/layout_constants.h" | 41 #include "ui/views/layout/layout_constants.h" |
41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
42 | 43 |
44 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
45 #include "chrome/browser/ui/views/frame/browser_view.h" | |
46 #endif | |
47 | |
43 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
44 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" | 49 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu bble_view.h" |
45 #endif | 50 #endif |
46 | 51 |
47 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; | 52 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; |
53 bool g_bubble_shown_ = false; | |
48 | 54 |
49 // Helpers -------------------------------------------------------------------- | 55 // Helpers -------------------------------------------------------------------- |
50 | 56 |
51 namespace { | 57 namespace { |
52 | 58 |
53 enum ColumnSetType { | 59 enum ColumnSetType { |
54 // | | (FILL, FILL) | | | 60 // | | (FILL, FILL) | | |
55 // Used for the bubble's header, the credentials list, and for simple | 61 // Used for the bubble's header, the credentials list, and for simple |
56 // messages like "No passwords". | 62 // messages like "No passwords". |
57 SINGLE_VIEW_COLUMN_SET, | 63 SINGLE_VIEW_COLUMN_SET, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 : public views::View, | 198 : public views::View, |
193 public views::ButtonListener, | 199 public views::ButtonListener, |
194 public views::WidgetObserver { | 200 public views::WidgetObserver { |
195 public: | 201 public: |
196 explicit AutoSigninView(ManagePasswordsBubbleView* parent); | 202 explicit AutoSigninView(ManagePasswordsBubbleView* parent); |
197 | 203 |
198 private: | 204 private: |
199 // views::ButtonListener: | 205 // views::ButtonListener: |
200 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 206 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
201 | 207 |
208 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
202 // views::WidgetObserver: | 209 // views::WidgetObserver: |
203 // Tracks the state of the browser window. | 210 // Tracks the state of the browser window. |
204 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; | 211 void OnWidgetActivationChanged(views::Widget* widget, bool active) override; |
205 void OnWidgetClosing(views::Widget* widget) override; | 212 void OnWidgetClosing(views::Widget* widget) override; |
213 #endif | |
206 | 214 |
207 void OnTimer(); | 215 void OnTimer(); |
208 static base::TimeDelta GetTimeout() { | 216 static base::TimeDelta GetTimeout() { |
209 return base::TimeDelta::FromSeconds( | 217 return base::TimeDelta::FromSeconds( |
210 ManagePasswordsBubbleView::auto_signin_toast_timeout_); | 218 ManagePasswordsBubbleView::auto_signin_toast_timeout_); |
211 } | 219 } |
212 | 220 |
213 base::OneShotTimer timer_; | 221 base::OneShotTimer timer_; |
214 ManagePasswordsBubbleView* parent_; | 222 ManagePasswordsBubbleView* parent_; |
215 ScopedObserver<views::Widget, views::WidgetObserver> observed_browser_; | 223 ScopedObserver<views::Widget, views::WidgetObserver> observed_browser_; |
(...skipping 13 matching lines...) Expand all Loading... | |
229 form.username_value), | 237 form.username_value), |
230 kButtonHoverColor, &form, | 238 kButtonHoverColor, &form, |
231 parent_->model()->GetProfile()->GetRequestContext()); | 239 parent_->model()->GetProfile()->GetRequestContext()); |
232 credential->SetEnabled(false); | 240 credential->SetEnabled(false); |
233 AddChildView(credential); | 241 AddChildView(credential); |
234 | 242 |
235 // Setup the observer and maybe start the timer. | 243 // Setup the observer and maybe start the timer. |
236 Browser* browser = | 244 Browser* browser = |
237 chrome::FindBrowserWithWebContents(parent_->web_contents()); | 245 chrome::FindBrowserWithWebContents(parent_->web_contents()); |
238 DCHECK(browser); | 246 DCHECK(browser); |
247 | |
248 // On MacOS the BrowserView should but does not yet exist. Auto-close of the | |
249 // auto-sign-in dialog is not implemented for a Cocoa browser when a bubble is | |
250 // shown in a non-active browser window. | |
tapted
2017/04/12 05:08:42
Can we say "This matches the current Mac behavior
varkha
2017/04/12 09:16:43
I think it is safer to do more of the same that ot
| |
251 // See http://crbug.com/468281. | |
252 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
239 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 253 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
240 observed_browser_.Add(browser_view->GetWidget()); | 254 observed_browser_.Add(browser_view->GetWidget()); |
241 | 255 #endif |
242 if (browser_view->IsActive()) | 256 if (browser->window()->IsActive()) |
243 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | 257 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
244 } | 258 } |
245 | 259 |
246 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 260 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
247 views::Button* sender, const ui::Event& event) { | 261 views::Button* sender, const ui::Event& event) { |
248 NOTREACHED(); | 262 NOTREACHED(); |
249 } | 263 } |
250 | 264 |
265 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
tapted
2017/04/12 05:08:42
Although it's dead code, I think it's safer if we
varkha
2017/04/12 09:16:43
Done.
| |
251 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( | 266 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
252 views::Widget* widget, bool active) { | 267 views::Widget* widget, bool active) { |
253 if (active && !timer_.IsRunning()) | 268 if (active && !timer_.IsRunning()) |
254 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | 269 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
255 } | 270 } |
256 | 271 |
257 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( | 272 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( |
258 views::Widget* widget) { | 273 views::Widget* widget) { |
259 observed_browser_.RemoveAll(); | 274 observed_browser_.RemoveAll(); |
260 } | 275 } |
276 #endif | |
261 | 277 |
262 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { | 278 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { |
263 parent_->model()->OnAutoSignInToastTimeout(); | 279 parent_->model()->OnAutoSignInToastTimeout(); |
264 parent_->CloseBubble(); | 280 parent_->CloseBubble(); |
265 } | 281 } |
266 | 282 |
267 // ManagePasswordsBubbleView::PendingView ------------------------------------- | 283 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
268 | 284 |
269 // A view offering the user the ability to save credentials. Contains a | 285 // A view offering the user the ability to save credentials. Contains a |
270 // single ManagePasswordItemsView, along with a "Save Passwords" button | 286 // single ManagePasswordItemsView, along with a "Save Passwords" button |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); | 707 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
692 parent_->model()->OnBrandLinkClicked(); | 708 parent_->model()->OnBrandLinkClicked(); |
693 } | 709 } |
694 | 710 |
695 // ManagePasswordsBubbleView -------------------------------------------------- | 711 // ManagePasswordsBubbleView -------------------------------------------------- |
696 | 712 |
697 // static | 713 // static |
698 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 714 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
699 NULL; | 715 NULL; |
700 | 716 |
717 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
701 // static | 718 // static |
702 void ManagePasswordsBubbleView::ShowBubble( | 719 void ManagePasswordsBubbleView::ShowBubble( |
703 content::WebContents* web_contents, | 720 content::WebContents* web_contents, |
704 DisplayReason reason) { | 721 DisplayReason reason) { |
705 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 722 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
706 DCHECK(browser); | 723 DCHECK(browser); |
707 DCHECK(browser->window()); | 724 DCHECK(browser->window()); |
708 DCHECK(!manage_passwords_bubble_ || | 725 DCHECK(!manage_passwords_bubble_ || |
709 !manage_passwords_bubble_->GetWidget()->IsVisible()); | 726 !manage_passwords_bubble_->GetWidget()->IsVisible()); |
710 | 727 |
711 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 728 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
712 bool is_fullscreen = browser_view->IsFullscreen(); | 729 bool is_fullscreen = browser_view->IsFullscreen(); |
713 views::View* anchor_view = nullptr; | 730 views::View* anchor_view = nullptr; |
714 if (!is_fullscreen) { | 731 if (!is_fullscreen) { |
715 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 732 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
716 anchor_view = browser_view->GetLocationBarView(); | 733 anchor_view = browser_view->GetLocationBarView(); |
717 } else { | 734 } else { |
718 anchor_view = | 735 anchor_view = |
719 browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 736 browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
720 } | 737 } |
721 } | 738 } |
722 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 739 manage_passwords_bubble_ = new ManagePasswordsBubbleView( |
723 web_contents, anchor_view, reason); | 740 web_contents, anchor_view, gfx::Point(), reason); |
724 | 741 |
725 if (is_fullscreen) | 742 if (is_fullscreen) |
726 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); | 743 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
727 | 744 |
728 views::Widget* manage_passwords_bubble_widget = | 745 views::Widget* manage_passwords_bubble_widget = |
729 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); | 746 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); |
730 if (anchor_view) { | 747 if (anchor_view) { |
731 manage_passwords_bubble_widget->AddObserver( | 748 manage_passwords_bubble_widget->AddObserver( |
732 browser_view->GetLocationBarView()->manage_passwords_icon_view()); | 749 browser_view->GetLocationBarView()->manage_passwords_icon_view()); |
733 } | 750 } |
734 | 751 |
735 // Adjust for fullscreen after creation as it relies on the content size. | 752 // Adjust for fullscreen after creation as it relies on the content size. |
736 if (is_fullscreen) { | 753 if (is_fullscreen) { |
737 manage_passwords_bubble_->AdjustForFullscreen( | 754 manage_passwords_bubble_->AdjustForFullscreen( |
738 browser_view->GetBoundsInScreen()); | 755 browser_view->GetBoundsInScreen()); |
739 } | 756 } |
740 | 757 |
741 manage_passwords_bubble_->ShowForReason(reason); | 758 manage_passwords_bubble_->ShowForReason(reason); |
742 } | 759 } |
760 #endif // !OS_MACOSX || MAC_VIEWS_BROWSER | |
743 | 761 |
744 // static | 762 // static |
745 void ManagePasswordsBubbleView::CloseCurrentBubble() { | 763 void ManagePasswordsBubbleView::CloseCurrentBubble() { |
746 if (manage_passwords_bubble_) | 764 if (manage_passwords_bubble_) |
747 manage_passwords_bubble_->CloseBubble(); | 765 manage_passwords_bubble_->CloseBubble(); |
748 } | 766 } |
749 | 767 |
750 // static | 768 // static |
751 void ManagePasswordsBubbleView::ActivateBubble() { | 769 void ManagePasswordsBubbleView::ActivateBubble() { |
752 DCHECK(manage_passwords_bubble_); | 770 DCHECK(manage_passwords_bubble_); |
753 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); | 771 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); |
754 manage_passwords_bubble_->GetWidget()->Activate(); | 772 manage_passwords_bubble_->GetWidget()->Activate(); |
755 } | 773 } |
756 | 774 |
775 // static | |
776 bool ManagePasswordsBubbleView::IsBubbleShown() { | |
777 return g_bubble_shown_; | |
778 } | |
779 | |
757 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 780 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
758 return model_.GetWebContents(); | 781 return model_.GetWebContents(); |
759 } | 782 } |
760 | 783 |
761 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 784 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
762 content::WebContents* web_contents, | 785 content::WebContents* web_contents, |
763 views::View* anchor_view, | 786 views::View* anchor_view, |
787 const gfx::Point& anchor_point, | |
764 DisplayReason reason) | 788 DisplayReason reason) |
765 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 789 : LocationBarBubbleDelegateView(anchor_view, |
790 anchor_point, | |
791 views::BubbleBorder::TOP_RIGHT, | |
792 web_contents), | |
766 model_(PasswordsModelDelegateFromWebContents(web_contents), | 793 model_(PasswordsModelDelegateFromWebContents(web_contents), |
767 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 794 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
768 : ManagePasswordsBubbleModel::USER_ACTION), | 795 : ManagePasswordsBubbleModel::USER_ACTION), |
769 initially_focused_view_(nullptr) { | 796 initially_focused_view_(nullptr) { |
770 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); | 797 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
771 // Set title margins to make the title and the content left aligned. | 798 // Set title margins to make the title and the content left aligned. |
772 const int side_margin = margins().left(); | 799 const int side_margin = margins().left(); |
773 set_title_margins( | 800 set_title_margins( |
774 gfx::Insets(LayoutDelegate::Get()->GetMetric( | 801 gfx::Insets(LayoutDelegate::Get()->GetMetric( |
775 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), | 802 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), |
776 side_margin, 0, side_margin)); | 803 side_margin, 0, side_margin)); |
804 g_bubble_shown_ = true; | |
777 } | 805 } |
778 | 806 |
779 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 807 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
808 g_bubble_shown_ = false; | |
780 if (manage_passwords_bubble_ == this) | 809 if (manage_passwords_bubble_ == this) |
tapted
2017/04/12 05:08:42
huh - I just noticed this. Can we implement IsBubb
varkha
2017/04/12 09:16:43
Done.
| |
781 manage_passwords_bubble_ = NULL; | 810 manage_passwords_bubble_ = NULL; |
782 } | 811 } |
783 | 812 |
784 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 813 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
785 return initially_focused_view_; | 814 return initially_focused_view_; |
786 } | 815 } |
787 | 816 |
788 void ManagePasswordsBubbleView::Init() { | 817 void ManagePasswordsBubbleView::Init() { |
789 SetLayoutManager(new views::FillLayout); | 818 SetLayoutManager(new views::FillLayout); |
790 | 819 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 } else if (model_.state() == | 886 } else if (model_.state() == |
858 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { | 887 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { |
859 AddChildView(new DesktopIOSPromotionBubbleView( | 888 AddChildView(new DesktopIOSPromotionBubbleView( |
860 model_.GetProfile(), | 889 model_.GetProfile(), |
861 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); | 890 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); |
862 #endif | 891 #endif |
863 } else { | 892 } else { |
864 AddChildView(new ManageView(this)); | 893 AddChildView(new ManageView(this)); |
865 } | 894 } |
866 } | 895 } |
OLD | NEW |