Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(231)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 2808823002: MacViews: Allows the toolkit-views Manage Passwords Dialog to be used (Closed)
Patch Set: MacViews: Allows the toolkit-views Manage Passwords Dialog to be used Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_views.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
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
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. The auto-sign-in
tapted 2017/04/11 07:48:58 instead of The auto-sign-in... perhaps Auto-close
varkha 2017/04/12 01:57:28 Done.
249 // bubble may not auto-close when it gets created in a non-active browser.
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
264 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
251 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged( 265 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetActivationChanged(
252 views::Widget* widget, bool active) { 266 views::Widget* widget, bool active) {
253 if (active && !timer_.IsRunning()) 267 if (active && !timer_.IsRunning())
254 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer); 268 timer_.Start(FROM_HERE, GetTimeout(), this, &AutoSigninView::OnTimer);
255 } 269 }
256 270
257 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing( 271 void ManagePasswordsBubbleView::AutoSigninView::OnWidgetClosing(
258 views::Widget* widget) { 272 views::Widget* widget) {
259 observed_browser_.RemoveAll(); 273 observed_browser_.RemoveAll();
260 } 274 }
275 #endif
261 276
262 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { 277 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() {
263 parent_->model()->OnAutoSignInToastTimeout(); 278 parent_->model()->OnAutoSignInToastTimeout();
264 parent_->CloseBubble(); 279 parent_->CloseBubble();
265 } 280 }
266 281
267 // ManagePasswordsBubbleView::PendingView ------------------------------------- 282 // ManagePasswordsBubbleView::PendingView -------------------------------------
268 283
269 // A view offering the user the ability to save credentials. Contains a 284 // A view offering the user the ability to save credentials. Contains a
270 // single ManagePasswordItemsView, along with a "Save Passwords" button 285 // single ManagePasswordItemsView, along with a "Save Passwords" button
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); 706 DCHECK_EQ(range, parent_->model()->title_brand_link_range());
692 parent_->model()->OnBrandLinkClicked(); 707 parent_->model()->OnBrandLinkClicked();
693 } 708 }
694 709
695 // ManagePasswordsBubbleView -------------------------------------------------- 710 // ManagePasswordsBubbleView --------------------------------------------------
696 711
697 // static 712 // static
698 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = 713 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ =
699 NULL; 714 NULL;
700 715
716 #if !defined(OS_MACOSX) || BUILDFLAG(MAC_VIEWS_BROWSER)
701 // static 717 // static
702 void ManagePasswordsBubbleView::ShowBubble( 718 void ManagePasswordsBubbleView::ShowBubble(
703 content::WebContents* web_contents, 719 content::WebContents* web_contents,
704 DisplayReason reason) { 720 DisplayReason reason) {
705 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); 721 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
706 DCHECK(browser); 722 DCHECK(browser);
707 DCHECK(browser->window()); 723 DCHECK(browser->window());
708 DCHECK(!manage_passwords_bubble_ || 724 DCHECK(!manage_passwords_bubble_ ||
709 !manage_passwords_bubble_->GetWidget()->IsVisible()); 725 !manage_passwords_bubble_->GetWidget()->IsVisible());
710 726
711 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); 727 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
712 bool is_fullscreen = browser_view->IsFullscreen(); 728 bool is_fullscreen = browser_view->IsFullscreen();
713 views::View* anchor_view = nullptr; 729 views::View* anchor_view = nullptr;
714 if (!is_fullscreen) { 730 if (!is_fullscreen) {
715 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) { 731 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
716 anchor_view = browser_view->GetLocationBarView(); 732 anchor_view = browser_view->GetLocationBarView();
717 } else { 733 } else {
718 anchor_view = 734 anchor_view =
719 browser_view->GetLocationBarView()->manage_passwords_icon_view(); 735 browser_view->GetLocationBarView()->manage_passwords_icon_view();
720 } 736 }
721 } 737 }
722 manage_passwords_bubble_ = new ManagePasswordsBubbleView( 738 manage_passwords_bubble_ = new ManagePasswordsBubbleView(
723 web_contents, anchor_view, reason); 739 web_contents, anchor_view, gfx::Point(), reason);
724 740
725 if (is_fullscreen) 741 if (is_fullscreen)
726 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView()); 742 manage_passwords_bubble_->set_parent_window(web_contents->GetNativeView());
727 743
728 views::Widget* manage_passwords_bubble_widget = 744 views::Widget* manage_passwords_bubble_widget =
729 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_); 745 views::BubbleDialogDelegateView::CreateBubble(manage_passwords_bubble_);
730 if (anchor_view) { 746 if (anchor_view) {
731 manage_passwords_bubble_widget->AddObserver( 747 manage_passwords_bubble_widget->AddObserver(
732 browser_view->GetLocationBarView()->manage_passwords_icon_view()); 748 browser_view->GetLocationBarView()->manage_passwords_icon_view());
733 } 749 }
734 750
735 // Adjust for fullscreen after creation as it relies on the content size. 751 // Adjust for fullscreen after creation as it relies on the content size.
736 if (is_fullscreen) { 752 if (is_fullscreen) {
737 manage_passwords_bubble_->AdjustForFullscreen( 753 manage_passwords_bubble_->AdjustForFullscreen(
738 browser_view->GetBoundsInScreen()); 754 browser_view->GetBoundsInScreen());
739 } 755 }
740 756
741 manage_passwords_bubble_->ShowForReason(reason); 757 manage_passwords_bubble_->ShowForReason(reason);
742 } 758 }
759 #endif // !OS_MACOSX || MAC_VIEWS_BROWSER
743 760
744 // static 761 // static
745 void ManagePasswordsBubbleView::CloseCurrentBubble() { 762 void ManagePasswordsBubbleView::CloseCurrentBubble() {
746 if (manage_passwords_bubble_) 763 if (manage_passwords_bubble_)
747 manage_passwords_bubble_->CloseBubble(); 764 manage_passwords_bubble_->CloseBubble();
748 } 765 }
749 766
750 // static 767 // static
751 void ManagePasswordsBubbleView::ActivateBubble() { 768 void ManagePasswordsBubbleView::ActivateBubble() {
752 DCHECK(manage_passwords_bubble_); 769 DCHECK(manage_passwords_bubble_);
753 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible()); 770 DCHECK(manage_passwords_bubble_->GetWidget()->IsVisible());
754 manage_passwords_bubble_->GetWidget()->Activate(); 771 manage_passwords_bubble_->GetWidget()->Activate();
755 } 772 }
756 773
774 // static
775 bool ManagePasswordsBubbleView::IsBubbleShown() {
776 return g_bubble_shown_;
777 }
778
757 content::WebContents* ManagePasswordsBubbleView::web_contents() const { 779 content::WebContents* ManagePasswordsBubbleView::web_contents() const {
758 return model_.GetWebContents(); 780 return model_.GetWebContents();
759 } 781 }
760 782
761 ManagePasswordsBubbleView::ManagePasswordsBubbleView( 783 ManagePasswordsBubbleView::ManagePasswordsBubbleView(
762 content::WebContents* web_contents, 784 content::WebContents* web_contents,
763 views::View* anchor_view, 785 views::View* anchor_view,
786 const gfx::Point& anchor_point,
764 DisplayReason reason) 787 DisplayReason reason)
765 : LocationBarBubbleDelegateView(anchor_view, web_contents), 788 : LocationBarBubbleDelegateView(anchor_view,
789 anchor_point,
790 views::BubbleBorder::TOP_RIGHT,
791 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( 799 set_title_margins(
774 gfx::Insets(LayoutDelegate::Get()->GetMetric( 800 gfx::Insets(LayoutDelegate::Get()->GetMetric(
775 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN), 801 LayoutDelegate::Metric::PANEL_CONTENT_MARGIN),
776 side_margin, 0, side_margin)); 802 side_margin, 0, side_margin));
803 g_bubble_shown_ = true;
777 } 804 }
778 805
779 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { 806 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
780 if (manage_passwords_bubble_ == this) 807 if (manage_passwords_bubble_ == this)
781 manage_passwords_bubble_ = NULL; 808 manage_passwords_bubble_ = NULL;
782 } 809 }
783 810
784 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { 811 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
785 return initially_focused_view_; 812 return initially_focused_view_;
786 } 813 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 bool ManagePasswordsBubbleView::ShouldShowWindowIcon() const { 848 bool ManagePasswordsBubbleView::ShouldShowWindowIcon() const {
822 return model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE; 849 return model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE;
823 } 850 }
824 851
825 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const { 852 bool ManagePasswordsBubbleView::ShouldShowCloseButton() const {
826 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE || 853 return model_.state() == password_manager::ui::PENDING_PASSWORD_STATE ||
827 model_.state() == password_manager::ui::CHROME_SIGN_IN_PROMO_STATE || 854 model_.state() == password_manager::ui::CHROME_SIGN_IN_PROMO_STATE ||
828 model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE; 855 model_.state() == password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE;
829 } 856 }
830 857
858 void ManagePasswordsBubbleView::OnWidgetDestroying(views::Widget* widget) {
859 g_bubble_shown_ = false;
tapted 2017/04/11 07:48:58 Does this work just as well in the destructor? --
varkha 2017/04/12 01:57:28 Done.
860 }
861
831 void ManagePasswordsBubbleView::Refresh() { 862 void ManagePasswordsBubbleView::Refresh() {
832 RemoveAllChildViews(true); 863 RemoveAllChildViews(true);
833 initially_focused_view_ = NULL; 864 initially_focused_view_ = NULL;
834 CreateChild(); 865 CreateChild();
835 866
836 // Show/hide the close button. 867 // Show/hide the close button.
837 GetWidget()->non_client_view()->ResetWindowControls(); 868 GetWidget()->non_client_view()->ResetWindowControls();
838 GetWidget()->UpdateWindowIcon(); 869 GetWidget()->UpdateWindowIcon();
839 GetWidget()->UpdateWindowTitle(); 870 GetWidget()->UpdateWindowTitle();
840 SizeToContents(); 871 SizeToContents();
(...skipping 16 matching lines...) Expand all
857 } else if (model_.state() == 888 } else if (model_.state() ==
858 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) { 889 password_manager::ui::CHROME_DESKTOP_IOS_PROMO_STATE) {
859 AddChildView(new DesktopIOSPromotionBubbleView( 890 AddChildView(new DesktopIOSPromotionBubbleView(
860 model_.GetProfile(), 891 model_.GetProfile(),
861 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE)); 892 desktop_ios_promotion::PromotionEntryPoint::SAVE_PASSWORD_BUBBLE));
862 #endif 893 #endif
863 } else { 894 } else {
864 AddChildView(new ManageView(this)); 895 AddChildView(new ManageView(this));
865 } 896 }
866 } 897 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698