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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" | 10 #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
23 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
24 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
26 #include "ui/views/controls/button/blue_button.h" | 26 #include "ui/views/controls/button/blue_button.h" |
27 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
28 #include "ui/views/controls/combobox/combobox.h" | 28 #include "ui/views/controls/combobox/combobox.h" |
29 #include "ui/views/controls/combobox/combobox_listener.h" | 29 #include "ui/views/controls/combobox/combobox_listener.h" |
30 #include "ui/views/controls/link.h" | 30 #include "ui/views/controls/link.h" |
31 #include "ui/views/controls/link_listener.h" | 31 #include "ui/views/controls/link_listener.h" |
32 #include "ui/views/controls/separator.h" | |
32 #include "ui/views/controls/styled_label.h" | 33 #include "ui/views/controls/styled_label.h" |
33 #include "ui/views/controls/styled_label_listener.h" | 34 #include "ui/views/controls/styled_label_listener.h" |
34 #include "ui/views/layout/fill_layout.h" | 35 #include "ui/views/layout/fill_layout.h" |
35 #include "ui/views/layout/grid_layout.h" | 36 #include "ui/views/layout/grid_layout.h" |
36 #include "ui/views/layout/layout_constants.h" | 37 #include "ui/views/layout/layout_constants.h" |
37 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
38 | 39 |
39 | |
vabr (Chromium)
2014/12/03 14:08:06
nit: As a general rule, formatting changes not rel
melandory
2014/12/04 10:33:47
Done.
| |
40 // Helpers -------------------------------------------------------------------- | 40 // Helpers -------------------------------------------------------------------- |
41 | 41 |
42 namespace { | 42 namespace { |
43 | 43 |
44 const int kDesiredBubbleWidth = 370; | 44 const int kDesiredBubbleWidth = 370; |
45 | 45 |
46 enum ColumnSetType { | 46 enum ColumnSetType { |
47 // | | (FILL, FILL) | | | 47 // | | (FILL, FILL) | | |
48 // Used for the bubble's header, the credentials list, and for simple | 48 // Used for the bubble's header, the credentials list, and for simple |
49 // messages like "No passwords". | 49 // messages like "No passwords". |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 column_set->AddColumn(views::GridLayout::TRAILING, | 115 column_set->AddColumn(views::GridLayout::TRAILING, |
116 views::GridLayout::CENTER, | 116 views::GridLayout::CENTER, |
117 1, | 117 1, |
118 views::GridLayout::USE_PREF, | 118 views::GridLayout::USE_PREF, |
119 0, | 119 0, |
120 0); | 120 0); |
121 } | 121 } |
122 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 122 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
123 } | 123 } |
124 | 124 |
125 // Given |layout| and |color| adds border with |color| using | |
126 // SINGLE_VIEW_COLUMN_SET. | |
127 void AddBorderRow(views::GridLayout* layout, SkColor color) { | |
128 layout->StartRowWithPadding(0, SINGLE_VIEW_COLUMN_SET, 0, | |
129 views::kRelatedControlVerticalSpacing); | |
130 views::Separator* border = new views::Separator(views::Separator::HORIZONTAL); | |
131 border->SetColor(color); | |
132 layout->AddView(border); | |
133 } | |
134 | |
125 // Given a layout and a model, add an appropriate title using a | 135 // Given a layout and a model, add an appropriate title using a |
126 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row. | 136 // SINGLE_VIEW_COLUMN_SET, followed by a spacer row. |
127 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) { | 137 void AddTitleRow(views::GridLayout* layout, ManagePasswordsBubbleModel* model) { |
128 views::Label* title_label = new views::Label(model->title()); | 138 views::Label* title_label = new views::Label(model->title()); |
129 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 139 title_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
130 title_label->SetMultiLine(true); | 140 title_label->SetMultiLine(true); |
131 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 141 title_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
132 ui::ResourceBundle::MediumFont)); | 142 ui::ResourceBundle::MediumFont)); |
133 | 143 |
134 // Add the title to the layout with appropriate padding. | 144 // Add the title to the layout with appropriate padding. |
135 layout->StartRowWithPadding( | 145 layout->StartRowWithPadding( |
136 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); | 146 0, SINGLE_VIEW_COLUMN_SET, 0, views::kRelatedControlSmallVerticalSpacing); |
137 layout->AddView(title_label); | 147 layout->AddView(title_label); |
138 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 148 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
139 } | 149 } |
140 | 150 |
151 // Given a |layout| and |text|, adds a text row with small font using a | |
152 // SINGLE_VIEW_COLUMN_SET. | |
153 void AddTextRow(views::GridLayout* layout, const base::string16& text) { | |
154 views::Label* text_label = new views::Label(text); | |
155 text_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
156 text_label->SetMultiLine(true); | |
157 text_label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
158 ui::ResourceBundle::SmallFont)); | |
159 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
160 layout->AddView(text_label); | |
161 } | |
162 | |
141 } // namespace | 163 } // namespace |
142 | 164 |
143 | 165 |
144 // Globals -------------------------------------------------------------------- | 166 // Globals -------------------------------------------------------------------- |
145 | 167 |
146 namespace chrome { | 168 namespace chrome { |
147 | 169 |
148 void ShowManagePasswordsBubble(content::WebContents* web_contents) { | 170 void ShowManagePasswordsBubble(content::WebContents* web_contents) { |
149 if (ManagePasswordsBubbleView::IsShowing()) { | 171 if (ManagePasswordsBubbleView::IsShowing()) { |
150 // The bubble is currently shown for some other tab. We should close it now | 172 // The bubble is currently shown for some other tab. We should close it now |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 // ManagePasswordsBubbleModel should care about calling a callback in case | 260 // ManagePasswordsBubbleModel should care about calling a callback in case |
239 // the bubble is dismissed by any other means. | 261 // the bubble is dismissed by any other means. |
240 CredentialsItemView* view = static_cast<CredentialsItemView*>(sender); | 262 CredentialsItemView* view = static_cast<CredentialsItemView*>(sender); |
241 parent_->model()->OnChooseCredentials(view->form()); | 263 parent_->model()->OnChooseCredentials(view->form()); |
242 } else { | 264 } else { |
243 parent_->model()->OnNopeClicked(); | 265 parent_->model()->OnNopeClicked(); |
244 } | 266 } |
245 parent_->Close(); | 267 parent_->Close(); |
246 } | 268 } |
247 | 269 |
270 // ManagePasswordsBubbleView::AskUserToSubmitURLView ------------------------- | |
271 | |
272 // Asks users if they want to report the URL when the password manager failed | |
273 // to detect the form. View has following structure: | |
274 // We detected that Chrome password manager failed to handle this URL. | |
275 // Do you want to send this URL to Google to improve Chrome? | |
276 // ------------------------------------------------------------- | |
277 // https://strangesite.com/ | |
278 // ------------------------------------------------------------- | |
279 // [Send URL] [Nope] | |
280 class ManagePasswordsBubbleView::AskUserToSubmitURLView | |
281 : public views::View, | |
282 public views::ButtonListener { | |
283 public: | |
284 explicit AskUserToSubmitURLView(ManagePasswordsBubbleView* parent); | |
285 ~AskUserToSubmitURLView() override; | |
286 | |
287 private: | |
288 // views::ButtonListener: | |
289 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
290 | |
291 ManagePasswordsBubbleView* parent_; | |
292 | |
293 views::BlueButton* send_button_; | |
294 views::BlueButton* no_button_; | |
295 }; | |
296 | |
297 ManagePasswordsBubbleView::AskUserToSubmitURLView::AskUserToSubmitURLView( | |
298 ManagePasswordsBubbleView* parent) | |
299 : parent_(parent) { | |
300 views::GridLayout* layout = new views::GridLayout(this); | |
301 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | |
302 SetLayoutManager(layout); | |
303 | |
304 send_button_ = new views::BlueButton( | |
305 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); | |
306 send_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
307 ui::ResourceBundle::SmallFont)); | |
308 | |
309 no_button_ = new views::BlueButton( | |
310 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SEND_URL_BUTTON)); | |
311 no_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
312 ui::ResourceBundle::SmallFont)); | |
313 | |
314 // Title row. | |
315 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | |
316 AddTitleRow(layout, parent_->model()); | |
317 // Confirmation text. | |
318 AddTextRow(layout, l10n_util::GetStringUTF16( | |
319 IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TEXT)); | |
320 GURL origin = parent->model()->origin(); | |
321 // Better to omit url if it's incorrect or empty. | |
vabr (Chromium)
2014/12/03 14:08:07
But what is the purpose of asking the user, if the
melandory
2014/12/04 10:33:47
Moved this check to PasswordManager::RecordFailur
| |
322 if (origin.is_valid() && !origin.is_empty() && origin.has_host()) { | |
323 // Border row. | |
324 SkColor color = GetNativeTheme()->GetSystemColor( | |
325 ui::NativeTheme::kColorId_EnabledMenuButtonBorderColor); | |
326 AddBorderRow(layout, color); | |
327 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
328 // URL row. | |
329 AddTextRow(layout, base::UTF8ToUTF16(parent->model()->origin().host())); | |
330 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
331 // Border row. | |
332 AddBorderRow(layout, color); | |
333 } | |
334 // Button row. | |
335 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); | |
336 layout->StartRowWithPadding(0, DOUBLE_BUTTON_COLUMN_SET, 0, | |
337 views::kRelatedControlVerticalSpacing); | |
338 layout->AddView(no_button_); | |
339 layout->AddView(send_button_); | |
340 | |
341 // Extra padding for visual awesomeness. | |
342 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
343 | |
344 parent_->set_initially_focused_view(send_button_); | |
vabr (Chromium)
2014/12/03 14:08:06
Please make sure that the choice of the default wa
melandory
2014/12/04 10:33:47
sabineb@ said that nope as default is better.
Done
| |
345 } | |
346 | |
347 ManagePasswordsBubbleView::AskUserToSubmitURLView::~AskUserToSubmitURLView() { | |
348 } | |
349 | |
350 void ManagePasswordsBubbleView::AskUserToSubmitURLView::ButtonPressed( | |
351 views::Button* sender, | |
352 const ui::Event& event) { | |
353 DCHECK(sender == send_button_ || sender == no_button_); | |
354 // TODO(melandory): Add actions on button clicks: url reporting, pref saving. | |
355 parent_->Close(); | |
356 } | |
357 | |
248 // ManagePasswordsBubbleView::PendingView ------------------------------------- | 358 // ManagePasswordsBubbleView::PendingView ------------------------------------- |
249 | 359 |
250 // A view offering the user the ability to save credentials. Contains a | 360 // A view offering the user the ability to save credentials. Contains a |
251 // single ManagePasswordItemsView, along with a "Save Passwords" button | 361 // single ManagePasswordItemsView, along with a "Save Passwords" button |
252 // and a rejection combobox. | 362 // and a rejection combobox. |
253 class ManagePasswordsBubbleView::PendingView : public views::View, | 363 class ManagePasswordsBubbleView::PendingView : public views::View, |
254 public views::ButtonListener, | 364 public views::ButtonListener, |
255 public views::ComboboxListener { | 365 public views::ComboboxListener { |
256 public: | 366 public: |
257 explicit PendingView(ManagePasswordsBubbleView* parent); | 367 explicit PendingView(ManagePasswordsBubbleView* parent); |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
764 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 874 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
765 NULL; | 875 NULL; |
766 | 876 |
767 // static | 877 // static |
768 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 878 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
769 DisplayReason reason) { | 879 DisplayReason reason) { |
770 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 880 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
771 DCHECK(browser); | 881 DCHECK(browser); |
772 DCHECK(browser->window()); | 882 DCHECK(browser->window()); |
773 DCHECK(browser->fullscreen_controller()); | 883 DCHECK(browser->fullscreen_controller()); |
774 | |
775 if (IsShowing()) | 884 if (IsShowing()) |
776 return; | 885 return; |
777 | |
778 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); | 886 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser); |
779 bool is_fullscreen = browser_view->IsFullscreen(); | 887 bool is_fullscreen = browser_view->IsFullscreen(); |
780 ManagePasswordsIconView* anchor_view = | 888 ManagePasswordsIconView* anchor_view = |
781 is_fullscreen | 889 is_fullscreen |
782 ? NULL | 890 ? NULL |
783 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); | 891 : browser_view->GetLocationBarView()->manage_passwords_icon_view(); |
784 manage_passwords_bubble_ = new ManagePasswordsBubbleView( | 892 manage_passwords_bubble_ = new ManagePasswordsBubbleView( |
785 web_contents, anchor_view, reason); | 893 web_contents, anchor_view, reason); |
786 | 894 |
787 if (is_fullscreen) { | 895 if (is_fullscreen) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
876 } | 984 } |
877 | 985 |
878 void ManagePasswordsBubbleView::Refresh() { | 986 void ManagePasswordsBubbleView::Refresh() { |
879 RemoveAllChildViews(true); | 987 RemoveAllChildViews(true); |
880 initially_focused_view_ = NULL; | 988 initially_focused_view_ = NULL; |
881 if (password_manager::ui::IsPendingState(model()->state())) { | 989 if (password_manager::ui::IsPendingState(model()->state())) { |
882 if (never_save_passwords_) | 990 if (never_save_passwords_) |
883 AddChildView(new ConfirmNeverView(this)); | 991 AddChildView(new ConfirmNeverView(this)); |
884 else | 992 else |
885 AddChildView(new PendingView(this)); | 993 AddChildView(new PendingView(this)); |
994 } else if (IsAskSubmitURLState(model()->state())) { | |
995 AddChildView(new AskUserToSubmitURLView(this)); | |
886 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { | 996 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { |
887 AddChildView(new BlacklistedView(this)); | 997 AddChildView(new BlacklistedView(this)); |
888 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { | 998 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { |
889 AddChildView(new SaveConfirmationView(this)); | 999 AddChildView(new SaveConfirmationView(this)); |
890 } else if (password_manager::ui::IsCredentialsState(model()->state())) { | 1000 } else if (password_manager::ui::IsCredentialsState(model()->state())) { |
891 AddChildView(new AccountChooserView(this)); | 1001 AddChildView(new AccountChooserView(this)); |
892 } else { | 1002 } else { |
893 AddChildView(new ManageView(this)); | 1003 AddChildView(new ManageView(this)); |
894 } | 1004 } |
895 GetLayoutManager()->Layout(this); | 1005 GetLayoutManager()->Layout(this); |
(...skipping 15 matching lines...) Expand all Loading... | |
911 } | 1021 } |
912 | 1022 |
913 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { | 1023 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { |
914 never_save_passwords_ = false; | 1024 never_save_passwords_ = false; |
915 Refresh(); | 1025 Refresh(); |
916 } | 1026 } |
917 | 1027 |
918 void ManagePasswordsBubbleView::Init() { | 1028 void ManagePasswordsBubbleView::Init() { |
919 views::FillLayout* layout = new views::FillLayout(); | 1029 views::FillLayout* layout = new views::FillLayout(); |
920 SetLayoutManager(layout); | 1030 SetLayoutManager(layout); |
921 | |
922 Refresh(); | 1031 Refresh(); |
923 } | 1032 } |
924 | 1033 |
925 void ManagePasswordsBubbleView::WindowClosing() { | 1034 void ManagePasswordsBubbleView::WindowClosing() { |
926 // Close() closes the window asynchronously, so by the time we reach here, | 1035 // Close() closes the window asynchronously, so by the time we reach here, |
927 // |manage_passwords_bubble_| may have already been reset. | 1036 // |manage_passwords_bubble_| may have already been reset. |
928 if (manage_passwords_bubble_ == this) | 1037 if (manage_passwords_bubble_ == this) |
929 manage_passwords_bubble_ = NULL; | 1038 manage_passwords_bubble_ = NULL; |
930 } | 1039 } |
931 | 1040 |
932 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 1041 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
933 return initially_focused_view_; | 1042 return initially_focused_view_; |
934 } | 1043 } |
935 | 1044 |
936 void ManagePasswordsBubbleView::Observe( | 1045 void ManagePasswordsBubbleView::Observe( |
937 int type, | 1046 int type, |
938 const content::NotificationSource& source, | 1047 const content::NotificationSource& source, |
939 const content::NotificationDetails& details) { | 1048 const content::NotificationDetails& details) { |
940 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 1049 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
941 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 1050 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
942 CloseBubble(); | 1051 CloseBubble(); |
943 } | 1052 } |
OLD | NEW |