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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 } | 977 } |
867 | 978 |
868 void ManagePasswordsBubbleView::Refresh() { | 979 void ManagePasswordsBubbleView::Refresh() { |
869 RemoveAllChildViews(true); | 980 RemoveAllChildViews(true); |
870 initially_focused_view_ = NULL; | 981 initially_focused_view_ = NULL; |
871 if (password_manager::ui::IsPendingState(model()->state())) { | 982 if (password_manager::ui::IsPendingState(model()->state())) { |
872 if (model()->never_save_passwords()) | 983 if (model()->never_save_passwords()) |
873 AddChildView(new ConfirmNeverView(this)); | 984 AddChildView(new ConfirmNeverView(this)); |
874 else | 985 else |
875 AddChildView(new PendingView(this)); | 986 AddChildView(new PendingView(this)); |
| 987 } else if (IsAskSubmitURLState(model()->state())) { |
| 988 AddChildView(new AskUserToSubmitURLView(this)); |
876 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { | 989 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { |
877 AddChildView(new BlacklistedView(this)); | 990 AddChildView(new BlacklistedView(this)); |
878 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { | 991 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { |
879 AddChildView(new SaveConfirmationView(this)); | 992 AddChildView(new SaveConfirmationView(this)); |
880 } else if (password_manager::ui::IsCredentialsState(model()->state())) { | 993 } else if (password_manager::ui::IsCredentialsState(model()->state())) { |
881 AddChildView(new AccountChooserView(this)); | 994 AddChildView(new AccountChooserView(this)); |
882 } else { | 995 } else { |
883 AddChildView(new ManageView(this)); | 996 AddChildView(new ManageView(this)); |
884 } | 997 } |
885 GetLayoutManager()->Layout(this); | 998 GetLayoutManager()->Layout(this); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 } | 1037 } |
925 | 1038 |
926 void ManagePasswordsBubbleView::Observe( | 1039 void ManagePasswordsBubbleView::Observe( |
927 int type, | 1040 int type, |
928 const content::NotificationSource& source, | 1041 const content::NotificationSource& source, |
929 const content::NotificationDetails& details) { | 1042 const content::NotificationDetails& details) { |
930 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); | 1043 DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED); |
931 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); | 1044 GetWidget()->SetVisibilityAnimationTransition(views::Widget::ANIMATE_NONE); |
932 CloseBubble(); | 1045 CloseBubble(); |
933 } | 1046 } |
OLD | NEW |