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/platform_util.h" |
11 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 16 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
15 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" | 17 #include "chrome/browser/ui/passwords/password_dialog_prompts.h" |
16 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" | 18 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
18 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 20 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
19 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" | 21 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
20 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 22 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
21 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 23 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
22 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
23 #include "components/strings/grit/components_strings.h" | 25 #include "components/strings/grit/components_strings.h" |
24 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/material_design/material_design_controller.h" | 27 #include "ui/base/material_design/material_design_controller.h" |
26 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/base/ui_features.h" |
27 #include "ui/gfx/color_palette.h" | 30 #include "ui/gfx/color_palette.h" |
28 #include "ui/gfx/image/image_skia.h" | 31 #include "ui/gfx/image/image_skia.h" |
29 #include "ui/native_theme/native_theme.h" | 32 #include "ui/native_theme/native_theme.h" |
30 #include "ui/views/controls/button/blue_button.h" | 33 #include "ui/views/controls/button/blue_button.h" |
31 #include "ui/views/controls/button/md_text_button.h" | 34 #include "ui/views/controls/button/md_text_button.h" |
32 #include "ui/views/controls/link.h" | 35 #include "ui/views/controls/link.h" |
33 #include "ui/views/controls/link_listener.h" | 36 #include "ui/views/controls/link_listener.h" |
34 #include "ui/views/controls/separator.h" | 37 #include "ui/views/controls/separator.h" |
35 #include "ui/views/controls/styled_label.h" | 38 #include "ui/views/controls/styled_label.h" |
36 #include "ui/views/controls/styled_label_listener.h" | 39 #include "ui/views/controls/styled_label_listener.h" |
37 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
38 #include "ui/views/layout/grid_layout.h" | 41 #include "ui/views/layout/grid_layout.h" |
39 #include "ui/views/layout/layout_constants.h" | 42 #include "ui/views/layout/layout_constants.h" |
40 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
41 | 44 |
| 45 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) |
| 46 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 47 #endif |
| 48 |
42 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
43 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" | 50 #include "chrome/browser/ui/views/desktop_ios_promotion/desktop_ios_promotion_bu
bble_view.h" |
44 #endif | 51 #endif |
45 | 52 |
46 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; | 53 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; |
47 | 54 |
48 // Helpers -------------------------------------------------------------------- | 55 // Helpers -------------------------------------------------------------------- |
49 | 56 |
50 namespace { | 57 namespace { |
51 | 58 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 form.username_value), | 235 form.username_value), |
229 kButtonHoverColor, &form, | 236 kButtonHoverColor, &form, |
230 parent_->model()->GetProfile()->GetRequestContext()); | 237 parent_->model()->GetProfile()->GetRequestContext()); |
231 credential->SetEnabled(false); | 238 credential->SetEnabled(false); |
232 AddChildView(credential); | 239 AddChildView(credential); |
233 | 240 |
234 // Setup the observer and maybe start the timer. | 241 // Setup the observer and maybe start the timer. |
235 Browser* browser = | 242 Browser* browser = |
236 chrome::FindBrowserWithWebContents(parent_->web_contents()); | 243 chrome::FindBrowserWithWebContents(parent_->web_contents()); |
237 DCHECK(browser); | 244 DCHECK(browser); |
| 245 |
| 246 // Sign-in dialogs opened for inactive browser windows do not auto-close on |
| 247 // MacOS. This matches existing Cocoa bubble behavior. |
| 248 // TODO(varkha): Remove the limitation as part of http://crbug/671916 . |
| 249 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) |
238 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 250 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
239 observed_browser_.Add(browser_view->GetWidget()); | 251 observed_browser_.Add(browser_view->GetWidget()); |
240 | 252 #endif |
241 if (browser_view->IsActive()) | 253 if (browser->window()->IsActive()) |
242 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | 254 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
243 } | 255 } |
244 | 256 |
245 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 257 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
246 views::Button* sender, const ui::Event& event) { | 258 views::Button* sender, const ui::Event& event) { |
247 NOTREACHED(); | 259 NOTREACHED(); |
248 } | 260 } |
249 | 261 |
250 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( | 262 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
251 views::Widget* widget, bool active) { | 263 views::Widget* widget, bool active) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); | 702 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
691 parent_->model()->OnBrandLinkClicked(); | 703 parent_->model()->OnBrandLinkClicked(); |
692 } | 704 } |
693 | 705 |
694 // ManagePasswordsBubbleView -------------------------------------------------- | 706 // ManagePasswordsBubbleView -------------------------------------------------- |
695 | 707 |
696 // static | 708 // static |
697 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 709 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
698 NULL; | 710 NULL; |
699 | 711 |
| 712 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) |
700 // static | 713 // static |
701 void ManagePasswordsBubbleView::ShowBubble( | 714 void ManagePasswordsBubbleView::ShowBubble( |
702 content::WebContents* web_contents, | 715 content::WebContents* web_contents, |
703 DisplayReason reason) { | 716 DisplayReason reason) { |
704 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 717 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
705 DCHECK(browser); | 718 DCHECK(browser); |
706 DCHECK(browser->window()); | 719 DCHECK(browser->window()); |
707 DCHECK(!manage_passwords_bubble_ || | 720 DCHECK(!manage_passwords_bubble_ || |
708 !manage_passwords_bubble_->GetWidget()->IsVisible()); | 721 !manage_passwords_bubble_->GetWidget()->IsVisible()); |
709 | 722 |
710 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 723 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
711 bool is_fullscreen = browser_view->IsFullscreen(); | 724 bool is_fullscreen = browser_view->IsFullscreen(); |
712 views::View* anchor_view = nullptr; | 725 views::View* anchor_view = nullptr; |
713 if (!is_fullscreen) { | 726 if (!is_fullscreen) { |
714 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 727 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
715 anchor_view = browser_view->GetLocationBarView(); | 728 anchor_view = browser_view->GetLocationBarView(); |
716 } else { | 729 } else { |
717 anchor_view = | 730 anchor_view = |
718 browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 731 browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
719 } | 732 } |
720 } | 733 } |
721 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 734 new ManagePasswordsBubbleView(web_contents, anchor_view, gfx::Point(), |
722 web_contents, anchor_view, reason); | 735 reason); |
| 736 DCHECK(manage_passwords_bubble_); |
723 | 737 |
724 if (is_fullscreen) | 738 if (is_fullscreen) |
725 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); | 739 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
726 | 740 |
727 views::Widget* manage_passwords_bubble_widget = | 741 views::Widget* manage_passwords_bubble_widget = |
728 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); | 742 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); |
729 if (anchor_view) { | 743 if (anchor_view) { |
730 manage_passwords_bubble_widget->AddObserver( | 744 manage_passwords_bubble_widget->AddObserver( |
731 browser_view->GetLocationBarView()->manage_passwords_icon_view()); | 745 browser_view->GetLocationBarView()->manage_passwords_icon_view()); |
732 } | 746 } |
733 | 747 |
734 // Adjust for fullscreen after creation as it relies on the content size. | 748 // Adjust for fullscreen after creation as it relies on the content size. |
735 if (is_fullscreen) { | 749 if (is_fullscreen) { |
736 manage_passwords_bubble_->AdjustForFullscreen( | 750 manage_passwords_bubble_->AdjustForFullscreen( |
737 browser_view->GetBoundsInScreen()); | 751 browser_view->GetBoundsInScreen()); |
738 } | 752 } |
739 | 753 |
740 manage_passwords_bubble_->ShowForReason(reason); | 754 manage_passwords_bubble_->ShowForReason(reason); |
741 } | 755 } |
| 756 #endif // !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) |
742 | 757 |
743 // static | 758 // static |
744 void ManagePasswordsBubbleView::CloseCurrentBubble() { | 759 void ManagePasswordsBubbleView::CloseCurrentBubble() { |
745 if (manage_passwords_bubble_) | 760 if (manage_passwords_bubble_) |
746 manage_passwords_bubble_->CloseBubble(); | 761 manage_passwords_bubble_->CloseBubble(); |
747 } | 762 } |
748 | 763 |
749 // static | 764 // static |
750 void ManagePasswordsBubbleView::ActivateBubble() { | 765 void ManagePasswordsBubbleView::ActivateBubble() { |
751 DCHECK(manage_passwords_bubble_); | 766 DCHECK(manage_passwords_bubble_); |
752 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); | 767 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); |
753 manage_passwords_bubble_->GetWidget()->Activate(); | 768 manage_passwords_bubble_->GetWidget()->Activate(); |
754 } | 769 } |
755 | 770 |
756 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 771 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
757 return model_.GetWebContents(); | 772 return model_.GetWebContents(); |
758 } | 773 } |
759 | 774 |
760 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 775 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
761 content::WebContents* web_contents, | 776 content::WebContents* web_contents, |
762 views::View* anchor_view, | 777 views::View* anchor_view, |
| 778 const gfx::Point& anchor_point, |
763 DisplayReason reason) | 779 DisplayReason reason) |
764 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 780 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), |
765 model_(PasswordsModelDelegateFromWebContents(web_contents), | 781 model_(PasswordsModelDelegateFromWebContents(web_contents), |
766 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 782 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
767 : ManagePasswordsBubbleModel::USER_ACTION), | 783 : ManagePasswordsBubbleModel::USER_ACTION), |
768 initially_focused_view_(nullptr) { | 784 initially_focused_view_(nullptr) { |
769 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); | 785 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
| 786 manage_passwords_bubble_ = this; |
770 } | 787 } |
771 | 788 |
772 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 789 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
773 if (manage_passwords_bubble_ == this) | 790 if (manage_passwords_bubble_ == this) |
774 manage_passwords_bubble_ = NULL; | 791 manage_passwords_bubble_ = nullptr; |
775 } | 792 } |
776 | 793 |
777 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 794 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
778 return initially_focused_view_; | 795 return initially_focused_view_; |
779 } | 796 } |
780 | 797 |
781 void ManagePasswordsBubbleView::Init() { | 798 void ManagePasswordsBubbleView::Init() { |
782 SetLayoutManager(new views::FillLayout); | 799 SetLayoutManager(new views::FillLayout); |
783 | 800 |
784 CreateChild(); | 801 CreateChild(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 } else if (model_.state() == | 874 } else if (model_.state() == |
858 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { | 875 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { |
859 AddChildView(new DesktopIOSPromotionBubbleView( | 876 AddChildView(new DesktopIOSPromotionBubbleView( |
860 model_.GetProfile(), | 877 model_.GetProfile(), |
861 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); | 878 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); |
862 #endif | 879 #endif |
863 } else { | 880 } else { |
864 AddChildView(new ManageView(this)); | 881 AddChildView(new ManageView(this)); |
865 } | 882 } |
866 } | 883 } |
OLD | NEW |