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