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 | |
247 // auto-sign-in dialog is not implemented for a Cocoa browser when a bubble is | |
248 // shown in a non-active browser window. | |
tapted
2017/04/19 03:31:06
perhaps add "This matches the behaviour on Mac whe
varkha
2017/04/19 08:34:17
Done.
| |
249 // See http://crbug.com/468281. | |
250 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
239 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 251 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
240 observed_browser_.Add(browser_view->GetWidget()); | 252 observed_browser_.Add(browser_view->GetWidget()); |
241 | 253 #endif |
242 if (browser_view->IsActive()) | 254 if (browser->window()->IsActive()) |
243 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); | 255 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); |
244 } | 256 } |
245 | 257 |
246 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( | 258 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( |
247 views::Button* sender, const ui::Event& event) { | 259 views::Button* sender, const ui::Event& event) { |
248 NOTREACHED(); | 260 NOTREACHED(); |
249 } | 261 } |
250 | 262 |
251 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( | 263 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( |
252 views::Widget* widget, bool active) { | 264 views::Widget* widget, bool active) { |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 // static | 713 // static |
702 void ManagePasswordsBubbleView::ShowBubble( | 714 void ManagePasswordsBubbleView::ShowBubble( |
703 content::WebContents* web_contents, | 715 content::WebContents* web_contents, |
704 DisplayReason reason) { | 716 DisplayReason reason) { |
705 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 717 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
706 DCHECK(browser); | 718 DCHECK(browser); |
707 DCHECK(browser->window()); | 719 DCHECK(browser->window()); |
708 DCHECK(!manage_passwords_bubble_ || | 720 DCHECK(!manage_passwords_bubble_ || |
709 !manage_passwords_bubble_->GetWidget()->IsVisible()); | 721 !manage_passwords_bubble_->GetWidget()->IsVisible()); |
710 | 722 |
723 views::View* anchor_view = nullptr; | |
724 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
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; | |
714 if (!is_fullscreen) { | 727 if (!is_fullscreen) { |
715 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { | 728 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { |
716 anchor_view = browser_view->GetLocationBarView(); | 729 anchor_view = browser_view->GetLocationBarView(); |
717 } else { | 730 } else { |
718 anchor_view = | 731 anchor_view = |
719 browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 732 browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
720 } | 733 } |
721 } | 734 } |
722 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 735 #endif |
723 web_contents, anchor_view, reason); | |
724 | 736 |
737 new ManagePasswordsBubbleView(web_contents, anchor_view, gfx::Point(), | |
tapted
2017/04/19 03:31:06
the gfx::Point() here doesn't look right - where d
varkha
2017/04/19 08:34:17
This code path is now only used not on Mac views a
| |
738 reason); | |
739 DCHECK(manage_passwords_bubble_); | |
740 | |
741 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER) | |
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. |
tapted
2017/04/19 03:31:06
We can do this still: we just need
bool is_fullsc
varkha
2017/04/19 08:34:16
Talked about this offline, we probably don't want
| |
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 } |
757 #else | |
758 gfx::NativeView parent = | |
759 platform_util::GetViewForWindow(browser->window()->GetNativeWindow()); | |
760 DCHECK(parent); | |
761 manage_passwords_bubble_->set_arrow(views::BubbleBorder::TOP_RIGHT); | |
762 manage_passwords_bubble_->set_parent_window(parent); | |
763 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); | |
764 #endif | |
740 | 765 |
741 manage_passwords_bubble_->ShowForReason(reason); | 766 manage_passwords_bubble_->ShowForReason(reason); |
742 } | 767 } |
743 | 768 |
744 // static | 769 // static |
745 void ManagePasswordsBubbleView::CloseCurrentBubble() { | 770 void ManagePasswordsBubbleView::CloseCurrentBubble() { |
746 if (manage_passwords_bubble_) | 771 if (manage_passwords_bubble_) |
747 manage_passwords_bubble_->CloseBubble(); | 772 manage_passwords_bubble_->CloseBubble(); |
748 } | 773 } |
749 | 774 |
750 // static | 775 // static |
751 void ManagePasswordsBubbleView::ActivateBubble() { | 776 void ManagePasswordsBubbleView::ActivateBubble() { |
752 DCHECK(manage_passwords_bubble_); | 777 DCHECK(manage_passwords_bubble_); |
753 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); | 778 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); |
754 manage_passwords_bubble_->GetWidget()->Activate(); | 779 manage_passwords_bubble_->GetWidget()->Activate(); |
755 } | 780 } |
756 | 781 |
757 content::WebContents* ManagePasswordsBubbleView::web_contents() const { | 782 content::WebContents* ManagePasswordsBubbleView::web_contents() const { |
758 return model_.GetWebContents(); | 783 return model_.GetWebContents(); |
759 } | 784 } |
760 | 785 |
761 ManagePasswordsBubbleView::ManagePasswordsBubbleView( | 786 ManagePasswordsBubbleView::ManagePasswordsBubbleView( |
762 content::WebContents* web_contents, | 787 content::WebContents* web_contents, |
763 views::View* anchor_view, | 788 views::View* anchor_view, |
789 const gfx::Point& anchor_point, | |
764 DisplayReason reason) | 790 DisplayReason reason) |
765 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 791 : LocationBarBubbleDelegateView(anchor_view, anchor_point, web_contents), |
766 model_(PasswordsModelDelegateFromWebContents(web_contents), | 792 model_(PasswordsModelDelegateFromWebContents(web_contents), |
767 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC | 793 reason == AUTOMATIC ? ManagePasswordsBubbleModel::AUTOMATIC |
768 : ManagePasswordsBubbleModel::USER_ACTION), | 794 : ManagePasswordsBubbleModel::USER_ACTION), |
769 initially_focused_view_(nullptr) { | 795 initially_focused_view_(nullptr) { |
770 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); | 796 mouse_handler_.reset(new WebContentMouseHandler(this, this->web_contents())); |
771 // Set title margins to make the title and the content left aligned. | 797 // Set title margins to make the title and the content left aligned. |
772 const int side_margin = margins().left(); | 798 const int side_margin = margins().left(); |
773 set_title_margins(gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric( | 799 set_title_margins(gfx::Insets(ChromeLayoutProvider::Get()->GetDistanceMetric( |
774 DISTANCE_PANEL_CONTENT_MARGIN), | 800 DISTANCE_PANEL_CONTENT_MARGIN), |
775 side_margin, 0, side_margin)); | 801 side_margin, 0, side_margin)); |
802 manage_passwords_bubble_ = this; | |
776 } | 803 } |
777 | 804 |
778 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 805 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
779 if (manage_passwords_bubble_ == this) | 806 if (manage_passwords_bubble_ == this) |
780 manage_passwords_bubble_ = NULL; | 807 manage_passwords_bubble_ = nullptr; |
781 } | 808 } |
782 | 809 |
783 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 810 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
784 return initially_focused_view_; | 811 return initially_focused_view_; |
785 } | 812 } |
786 | 813 |
787 void ManagePasswordsBubbleView::Init() { | 814 void ManagePasswordsBubbleView::Init() { |
788 SetLayoutManager(new views::FillLayout); | 815 SetLayoutManager(new views::FillLayout); |
789 | 816 |
790 CreateChild(); | 817 CreateChild(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
863 } else if (model_.state() == | 890 } else if (model_.state() == |
864 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { | 891 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { |
865 AddChildView(new DesktopIOSPromotionBubbleView( | 892 AddChildView(new DesktopIOSPromotionBubbleView( |
866 model_.GetProfile(), | 893 model_.GetProfile(), |
867 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); | 894 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); |
868 #endif | 895 #endif |
869 } else { | 896 } else { |
870 AddChildView(new ManageView(this)); | 897 AddChildView(new ManageView(this)); |
871 } | 898 } |
872 } | 899 } |
OLD | NEW |