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" | |
18 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" | 19 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h" |
19 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 20 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
20 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" | 21 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
21 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 22 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
22 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" | 23 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_views.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "components/strings/grit/components_strings.h" | 25 #include "components/strings/grit/components_strings.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/base/material_design/material_design_controller.h" | 27 #include "ui/base/material_design/material_design_controller.h" |
27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/base/ui_features.h" | |
28 #include "ui/gfx/color_palette.h" | 30 #include "ui/gfx/color_palette.h" |
29 #include "ui/gfx/image/image_skia.h" | 31 #include "ui/gfx/image/image_skia.h" |
30 #include "ui/native_theme/native_theme.h" | 32 #include "ui/native_theme/native_theme.h" |
31 #include "ui/views/controls/button/blue_button.h" | 33 #include "ui/views/controls/button/blue_button.h" |
32 #include "ui/views/controls/button/md_text_button.h" | 34 #include "ui/views/controls/button/md_text_button.h" |
33 #include "ui/views/controls/link.h" | 35 #include "ui/views/controls/link.h" |
34 #include "ui/views/controls/link_listener.h" | 36 #include "ui/views/controls/link_listener.h" |
35 #include "ui/views/controls/separator.h" | 37 #include "ui/views/controls/separator.h" |
36 #include "ui/views/controls/styled_label.h" | 38 #include "ui/views/controls/styled_label.h" |
37 #include "ui/views/controls/styled_label_listener.h" | 39 #include "ui/views/controls/styled_label_listener.h" |
38 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
39 #include "ui/views/layout/grid_layout.h" | 41 #include "ui/views/layout/grid_layout.h" |
40 #include "ui/views/layout/layout_constants.h" | 42 #include "ui/views/layout/layout_constants.h" |
41 #include "ui/views/widget/widget.h" | 43 #include "ui/views/widget/widget.h" |
42 | 44 |
45 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
46 #include "chrome/browser/ui/views/frame/browser_view.h" | |
47 #endif | |
48 | |
43 #if defined(OS_WIN) | 49 #if defined(OS_WIN) |
44 #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" |
45 #endif | 51 #endif |
46 | 52 |
47 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; | 53 int ManagePasswordsBubbleView::auto_signin_toast_timeout_ = 3; |
48 | 54 |
49 // Helpers -------------------------------------------------------------------- | 55 // Helpers -------------------------------------------------------------------- |
50 | 56 |
51 namespace { | 57 namespace { |
52 | 58 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 form.username_value), | 235 form.username_value), |
230 kButtonHoverColor, &form, | 236 kButtonHoverColor, &form, |
231 parent_->model()->GetProfile()->GetRequestContext()); | 237 parent_->model()->GetProfile()->GetRequestContext()); |
232 credential->SetEnabled(false); | 238 credential->SetEnabled(false); |
233 AddChildView(credential); | 239 AddChildView(credential); |
234 | 240 |
235 // Setup the observer and maybe start the timer. | 241 // Setup the observer and maybe start the timer. |
236 Browser* browser = | 242 Browser* browser = |
237 chrome::FindBrowserWithWebContents(parent_->web_contents()); | 243 chrome::FindBrowserWithWebContents(parent_->web_contents()); |
238 DCHECK(browser); | 244 DCHECK(browser); |
245 | |
246 // On MacOS the BrowserView should but does not yet exist. Auto-close of the | |
msw
2017/04/19 18:23:17
Perhaps this comment isn't as elucidating as it co
varkha
2017/04/20 04:14:20
Done.
| |
247 // auto sign-in dialog when a bubble is shown in a non-active browser window is | |
248 // not implemented for a Cocoa browser. This makes toolkit-views behavior match | |
249 // the behaviour on Mac when using a Cocoa bubble. | |
msw
2017/04/19 18:23:17
nit: consistent behavior/our spelling with line ab
varkha
2017/04/20 04:14:20
Acknowledged.
| |
250 // See http://crbug.com/468281. | |
251 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
239 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 252 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
240 observed_browser_.Add(browser_view->GetWidget()); | 253 observed_browser_.Add(browser_view->GetWidget()); |
241 | 254 #endif |
242 if (browser_view->IsActive()) | 255 if (browser->window()->IsActive()) |
243 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | 256 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
244 } | 257 } |
245 | 258 |
246 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 259 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
247 views::Button* sender, const ui::Event& event) { | 260 views::Button* sender, const ui::Event& event) { |
248 NOTREACHED(); | 261 NOTREACHED(); |
249 } | 262 } |
250 | 263 |
251 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( | 264 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
252 views::Widget* widget, bool active) { | 265 views::Widget* widget, bool active) { |
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
691 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); | 704 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
692 parent_->model()->OnBrandLinkClicked(); | 705 parent_->model()->OnBrandLinkClicked(); |
693 } | 706 } |
694 | 707 |
695 // ManagePasswordsBubbleView -------------------------------------------------- | 708 // ManagePasswordsBubbleView -------------------------------------------------- |
696 | 709 |
697 // static | 710 // static |
698 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 711 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
699 NULL; | 712 NULL; |
700 | 713 |
714 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
701 // static | 715 // static |
702 void ManagePasswordsBubbleView::ShowBubble( | 716 void ManagePasswordsBubbleView::ShowBubble( |
703 content::WebContents* web_contents, | 717 content::WebContents* web_contents, |
704 DisplayReason reason) { | 718 DisplayReason reason) { |
705 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 719 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
706 DCHECK(browser); | 720 DCHECK(browser); |
707 DCHECK(browser->window()); | 721 DCHECK(browser->window()); |
708 DCHECK(!manage_passwords_bubble_ || | 722 DCHECK(!manage_passwords_bubble_ || |
709 !manage_passwords_bubble_->GetWidget()->IsVisible()); | 723 !manage_passwords_bubble_->GetWidget()->IsVisible()); |
710 | 724 |
711 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 725 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
712 bool is_fullscreen = browser_view->IsFullscreen(); | 726 bool is_fullscreen = browser_view->IsFullscreen(); |
713 views::View* anchor_view = nullptr; | 727 views::View* anchor_view = nullptr; |
714 if (!is_fullscreen) { | 728 if (!is_fullscreen) { |
715 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 729 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
716 anchor_view = browser_view->GetLocationBarView(); | 730 anchor_view = browser_view->GetLocationBarView(); |
717 } else { | 731 } else { |
718 anchor_view = | 732 anchor_view = |
719 browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 733 browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
720 } | 734 } |
721 } | 735 } |
722 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 736 new ManagePasswordsBubbleView(web_contents, anchor_view, gfx::Point(), |
723 web_contents, anchor_view, reason); | 737 reason); |
738 DCHECK(manage_passwords_bubble_); | |
724 | 739 |
725 if (is_fullscreen) | 740 if (is_fullscreen) |
726 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); | 741 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); |
727 | 742 |
728 views::Widget* manage_passwords_bubble_widget = | 743 views::Widget* manage_passwords_bubble_widget = |
729 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); | 744 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); |
730 if (anchor_view) { | 745 if (anchor_view) { |
731 manage_passwords_bubble_widget->AddObserver( | 746 manage_passwords_bubble_widget->AddObserver( |
732 browser_view->GetLocationBarView()->manage_passwords_icon_view()); | 747 browser_view->GetLocationBarView()->manage_passwords_icon_view()); |
733 } | 748 } |
734 | 749 |
735 // Adjust for fullscreen after creation as it relies on the content size. | 750 // Adjust for fullscreen after creation as it relies on the content size. |
736 if (is_fullscreen) { | 751 if (is_fullscreen) { |
737 manage_passwords_bubble_->AdjustForFullscreen( | 752 manage_passwords_bubble_->AdjustForFullscreen( |
738 browser_view->GetBoundsInScreen()); | 753 browser_view->GetBoundsInScreen()); |
739 } | 754 } |
740 | 755 |
741 manage_passwords_bubble_->ShowForReason(reason); | 756 manage_passwords_bubble_->ShowForReason(reason); |
742 } | 757 } |
758 #endif // !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
743 | 759 |
744 // static | 760 // static |
745 void ManagePasswordsBubbleView::CloseCurrentBubble() { | 761 void ManagePasswordsBubbleView::CloseCurrentBubble() { |
746 if (manage_passwords_bubble_) | 762 if (manage_passwords_bubble_) |
747 manage_passwords_bubble_->CloseBubble(); | 763 manage_passwords_bubble_->CloseBubble(); |
748 } | 764 } |
749 | 765 |
750 // static | 766 // static |
751 void ManagePasswordsBubbleView::ActivateBubble() { | 767 void ManagePasswordsBubbleView::ActivateBubble() { |
752 DCHECK(manage_passwords_bubble_); | 768 DCHECK(manage_passwords_bubble_); |
753 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); | 769 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); |
754 manage_passwords_bubble_->GetWidget()->Activate(); | 770 manage_passwords_bubble_->GetWidget()->Activate(); |
755 } | 771 } |
756 | 772 |
757 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 773 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
758 return model_.GetWebContents(); | 774 return model_.GetWebContents(); |
759 } | 775 } |
760 | 776 |
761 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 777 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
762 content::WebContents* web_contents, | 778 content::WebContents* web_contents, |
763 views::View* anchor_view, | 779 views::View* anchor_view, |
780 const gfx::Point& anchor_point, | |
764 DisplayReason reason) | 781 DisplayReason reason) |
765 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 782 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), |
766 model_(PasswordsModelDelegateFromWebContents(web_contents), | 783 model_(PasswordsModelDelegateFromWebContents(web_contents), |
767 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 784 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
768 : ManagePasswordsBubbleModel::USER_ACTION), | 785 : ManagePasswordsBubbleModel::USER_ACTION), |
769 initially_focused_view_(nullptr) { | 786 initially_focused_view_(nullptr) { |
770 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); | 787 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
771 // Set title margins to make the title and the content left aligned. | 788 // Set title margins to make the title and the content left aligned. |
772 const int side_margin = margins().left(); | 789 const int side_margin = margins().left(); |
773 set_title_margins(gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric( | 790 set_title_margins(gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric( |
774 DISTANCE_PANEL_CONTENT_MARGIN), | 791 DISTANCE_PANEL_CONTENT_MARGIN), |
775 side_margin, 0, side_margin)); | 792 side_margin, 0, side_margin)); |
793 manage_passwords_bubble_ = this; | |
776 } | 794 } |
777 | 795 |
778 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 796 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
779 if (manage_passwords_bubble_ == this) | 797 if (manage_passwords_bubble_ == this) |
780 manage_passwords_bubble_ = NULL; | 798 manage_passwords_bubble_ = nullptr; |
781 } | 799 } |
782 | 800 |
783 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 801 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
784 return initially_focused_view_; | 802 return initially_focused_view_; |
785 } | 803 } |
786 | 804 |
787 void ManagePasswordsBubbleView::Init() { | 805 void ManagePasswordsBubbleView::Init() { |
788 SetLayoutManager(new views::FillLayout); | 806 SetLayoutManager(new views::FillLayout); |
789 | 807 |
790 CreateChild(); | 808 CreateChild(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 } else if (model_.state() == | 881 } else if (model_.state() == |
864 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { | 882 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { |
865 AddChildView(new DesktopIOSPromotionBubbleView( | 883 AddChildView(new DesktopIOSPromotionBubbleView( |
866 model_.GetProfile(), | 884 model_.GetProfile(), |
867 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); | 885 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); |
868 #endif | 886 #endif |
869 } else { | 887 } else { |
870 AddChildView(new ManageView(this)); | 888 AddChildView(new ManageView(this)); |
871 } | 889 } |
872 } | 890 } |
OLD | NEW |