OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gtk/password_generation_bubble_gtk.h" | 5 #include "chrome/browser/ui/gtk/password_generation_bubble_gtk.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/autofill/password_generator.h" |
8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 11 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
11 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 12 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
12 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 13 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
13 #include "chrome/browser/ui/gtk/gtk_util.h" | 14 #include "chrome/browser/ui/gtk/gtk_util.h" |
14 #include "chrome/common/autofill_messages.h" | 15 #include "chrome/common/autofill_messages.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
16 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
19 #include "ui/base/gtk/gtk_hig_constants.h" | 20 #include "ui/base/gtk/gtk_hig_constants.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 | 22 |
22 const int kContentBorder = 4; | 23 const int kContentBorder = 4; |
23 const int kHorizontalSpacing = 4; | 24 const int kHorizontalSpacing = 4; |
24 | 25 |
25 PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk( | 26 PasswordGenerationBubbleGtk::PasswordGenerationBubbleGtk( |
26 const gfx::Rect& anchor_rect, | 27 const gfx::Rect& anchor_rect, |
27 GtkWidget* anchor_widget, | 28 GtkWidget* anchor_widget, |
28 Profile* profile, | 29 Profile* profile, |
29 content::RenderViewHost* render_view_host) | 30 content::RenderViewHost* render_view_host, |
30 : profile_(profile), render_view_host_(render_view_host) { | 31 autofill::PasswordGenerator* password_generator) |
| 32 : profile_(profile), |
| 33 render_view_host_(render_view_host) { |
| 34 password_generator_.reset(password_generator); |
| 35 |
31 // TODO(gcasto): Localize text after we have finalized the UI. | 36 // TODO(gcasto): Localize text after we have finalized the UI. |
32 // crbug.com/118062 | 37 // crbug.com/118062 |
33 GtkWidget* content = gtk_vbox_new(FALSE, 5); | 38 GtkWidget* content = gtk_vbox_new(FALSE, 5); |
34 | 39 |
35 // We have two lines of content. The first is the title and learn more link. | 40 // We have two lines of content. The first is the title and learn more link. |
36 GtkWidget* title_line = gtk_hbox_new(FALSE, 0); | 41 GtkWidget* title_line = gtk_hbox_new(FALSE, 0); |
37 GtkWidget* title = gtk_label_new("Password Suggestion"); | 42 GtkWidget* title = gtk_label_new("Password Suggestion"); |
38 gtk_box_pack_start(GTK_BOX(title_line), title, FALSE, FALSE, 0); | 43 gtk_box_pack_start(GTK_BOX(title_line), title, FALSE, FALSE, 0); |
39 GtkWidget* learn_more_link = gtk_chrome_link_button_new( | 44 GtkWidget* learn_more_link = gtk_chrome_link_button_new( |
40 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | 45 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); |
41 gtk_button_set_alignment(GTK_BUTTON(learn_more_link), 0.0, 0.5); | 46 gtk_button_set_alignment(GTK_BUTTON(learn_more_link), 0.0, 0.5); |
42 gtk_box_pack_start(GTK_BOX(title_line), | 47 gtk_box_pack_start(GTK_BOX(title_line), |
43 gtk_util::IndentWidget(learn_more_link), | 48 gtk_util::IndentWidget(learn_more_link), |
44 FALSE, FALSE, 0); | 49 FALSE, FALSE, 0); |
45 | 50 |
46 // The second contains the password in a text field and an accept button. | 51 // The second contains the password in a text field and an accept button. |
47 GtkWidget* password_line = gtk_hbox_new(FALSE, kHorizontalSpacing); | 52 GtkWidget* password_line = gtk_hbox_new(FALSE, kHorizontalSpacing); |
48 text_field_ = gtk_entry_new(); | 53 text_field_ = gtk_entry_new(); |
49 gtk_entry_set_text(GTK_ENTRY(text_field_), | 54 gtk_entry_set_text(GTK_ENTRY(text_field_), |
50 password_generator_.Generate().c_str()); | 55 password_generator_->Generate().c_str()); |
51 gtk_entry_set_max_length(GTK_ENTRY(text_field_), 15); | 56 gtk_entry_set_max_length(GTK_ENTRY(text_field_), 15); |
52 GtkWidget* accept_button = gtk_button_new_with_label("Try It"); | 57 GtkWidget* accept_button = gtk_button_new_with_label("Try It"); |
53 gtk_box_pack_start(GTK_BOX(password_line), text_field_, TRUE, TRUE, 0); | 58 gtk_box_pack_start(GTK_BOX(password_line), text_field_, TRUE, TRUE, 0); |
54 gtk_box_pack_start(GTK_BOX(password_line), accept_button, TRUE, TRUE, 0); | 59 gtk_box_pack_start(GTK_BOX(password_line), accept_button, TRUE, TRUE, 0); |
55 | 60 |
56 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); | 61 gtk_container_set_border_width(GTK_CONTAINER(content), kContentBorder); |
57 gtk_box_pack_start(GTK_BOX(content), title_line, TRUE, TRUE, 0); | 62 gtk_box_pack_start(GTK_BOX(content), title_line, TRUE, TRUE, 0); |
58 gtk_box_pack_start(GTK_BOX(content), password_line, TRUE, TRUE, 0); | 63 gtk_box_pack_start(GTK_BOX(content), password_line, TRUE, TRUE, 0); |
59 | 64 |
60 bubble_ = BubbleGtk::Show(anchor_widget, | 65 bubble_ = BubbleGtk::Show(anchor_widget, |
(...skipping 30 matching lines...) Expand all Loading... |
91 } | 96 } |
92 | 97 |
93 void PasswordGenerationBubbleGtk::OnLearnMoreLinkClicked(GtkButton* button) { | 98 void PasswordGenerationBubbleGtk::OnLearnMoreLinkClicked(GtkButton* button) { |
94 Browser* browser = browser::FindLastActiveWithProfile(profile_); | 99 Browser* browser = browser::FindLastActiveWithProfile(profile_); |
95 content::OpenURLParams params( | 100 content::OpenURLParams params( |
96 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), | 101 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), |
97 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | 102 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); |
98 browser->OpenURL(params); | 103 browser->OpenURL(params); |
99 bubble_->Close(); | 104 bubble_->Close(); |
100 } | 105 } |
OLD | NEW |