Chromium Code Reviews| 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/metrics/histogram.h" |
| 8 #include "chrome/browser/autofill/password_generator.h" | 8 #include "chrome/browser/autofill/password_generator.h" |
| 9 #include "chrome/browser/password_manager/password_manager.h" | 9 #include "chrome/browser/password_manager/password_manager.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
| 13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | 13 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" |
| 14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 14 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
| 15 #include "chrome/browser/ui/gtk/gtk_util.h" | 15 #include "chrome/browser/ui/gtk/gtk_util.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 17 #include "chrome/common/autofill_messages.h" | 17 #include "chrome/common/autofill_messages.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 gtk_widget_grab_focus(text_field_); | 86 gtk_widget_grab_focus(text_field_); |
| 87 | 87 |
| 88 bubble_ = BubbleGtk::Show(tab->web_contents()->GetContentNativeView(), | 88 bubble_ = BubbleGtk::Show(tab->web_contents()->GetContentNativeView(), |
| 89 &anchor_rect, | 89 &anchor_rect, |
| 90 content, | 90 content, |
| 91 BubbleGtk::ARROW_LOCATION_TOP_LEFT, | 91 BubbleGtk::ARROW_LOCATION_TOP_LEFT, |
| 92 BubbleGtk::MATCH_SYSTEM_THEME | | 92 BubbleGtk::MATCH_SYSTEM_THEME | |
| 93 BubbleGtk::POPUP_WINDOW | | 93 BubbleGtk::POPUP_WINDOW | |
| 94 BubbleGtk::GRAB_INPUT, | 94 BubbleGtk::GRAB_INPUT, |
| 95 GtkThemeService::GetFrom(tab_->profile()), | 95 GtkThemeService::GetFrom(tab_->profile()), |
| 96 NULL); // delegate | 96 this); // delegate |
| 97 | 97 |
| 98 g_signal_connect(content, "destroy", | 98 g_signal_connect(content, "destroy", |
| 99 G_CALLBACK(&OnDestroyThunk), this); | 99 G_CALLBACK(&OnDestroyThunk), this); |
| 100 g_signal_connect(accept_button, "clicked", | 100 g_signal_connect(accept_button, "clicked", |
| 101 G_CALLBACK(&OnAcceptClickedThunk), this); | 101 G_CALLBACK(&OnAcceptClickedThunk), this); |
| 102 g_signal_connect(text_field_, "icon-press", | 102 g_signal_connect(text_field_, "icon-press", |
| 103 G_CALLBACK(&OnRegenerateClickedThunk), this); | 103 G_CALLBACK(&OnRegenerateClickedThunk), this); |
| 104 g_signal_connect(text_field_, "changed", | |
| 105 G_CALLBACK(&OnPasswordEditedThunk), this); | |
| 104 g_signal_connect(learn_more_link, "clicked", | 106 g_signal_connect(learn_more_link, "clicked", |
| 105 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); | 107 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); |
| 106 } | 108 } |
| 107 | 109 |
| 108 PasswordGenerationBubbleGtk::~PasswordGenerationBubbleGtk() {} | 110 PasswordGenerationBubbleGtk::~PasswordGenerationBubbleGtk() {} |
| 109 | 111 |
| 112 void PasswordGenerationBubbleGtk::BubbleClosing( | |
| 113 BubbleGtk* bubble, bool closed_by_escape) { | |
| 114 // Send the password generation status to the renderer. | |
| 115 RenderViewHost* render_view_host = tab_->web_contents()->GetRenderViewHost(); | |
| 116 render_view_host->Send(new AutofillMsg_PasswordGenerationBubbleClosed( | |
| 117 render_view_host->GetRoutingID(), | |
| 118 password_generation_status_)); | |
|
Ilya Sherman
2012/07/18 05:36:15
What's the advantage of sending the status to the
Ilya Sherman
2012/07/18 05:38:14
Reading back through the comments on this CL, I th
Garrett Casto
2012/07/18 17:20:03
Yeah, I just meant that for those particular stats
zysxqn
2012/07/18 19:16:46
Done.
| |
| 119 } | |
| 120 | |
| 110 void PasswordGenerationBubbleGtk::OnDestroy(GtkWidget* widget) { | 121 void PasswordGenerationBubbleGtk::OnDestroy(GtkWidget* widget) { |
| 111 // We are self deleting, we have a destroy signal setup to catch when we are | 122 // We are self deleting, we have a destroy signal setup to catch when we are |
| 112 // destroyed (via the BubbleGtk being destroyed), and delete ourself. | 123 // destroyed (via the BubbleGtk being destroyed), and delete ourself. |
| 113 delete this; | 124 delete this; |
| 114 } | 125 } |
| 115 | 126 |
| 116 void PasswordGenerationBubbleGtk::OnAcceptClicked(GtkWidget* widget) { | 127 void PasswordGenerationBubbleGtk::OnAcceptClicked(GtkWidget* widget) { |
| 117 RenderViewHost* render_view_host = tab_->web_contents()->GetRenderViewHost(); | 128 password_generation_status_.password_accepted = true; |
| 118 render_view_host->Send(new AutofillMsg_GeneratedPasswordAccepted( | 129 password_generation_status_.generated_password = |
| 119 render_view_host->GetRoutingID(), | 130 gtk_entry_get_text(GTK_ENTRY(text_field_)); |
| 120 UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(text_field_))))); | |
| 121 tab_->password_manager()->SetFormHasGeneratedPassword(form_); | 131 tab_->password_manager()->SetFormHasGeneratedPassword(form_); |
| 122 bubble_->Close(); | 132 bubble_->Close(); |
| 123 } | 133 } |
| 124 | 134 |
| 125 void PasswordGenerationBubbleGtk::OnRegenerateClicked( | 135 void PasswordGenerationBubbleGtk::OnRegenerateClicked( |
| 126 GtkWidget* widget, | 136 GtkWidget* widget, |
| 127 GtkEntryIconPosition icon_pos, | 137 GtkEntryIconPosition icon_pos, |
| 128 GdkEvent* event) { | 138 GdkEvent* event) { |
| 129 gtk_entry_set_text(GTK_ENTRY(text_field_), | 139 gtk_entry_set_text(GTK_ENTRY(text_field_), |
| 130 password_generator_->Generate().c_str()); | 140 password_generator_->Generate().c_str()); |
| 141 password_generation_status_.password_regenerated = true; | |
| 142 } | |
| 143 | |
| 144 void PasswordGenerationBubbleGtk::OnPasswordEdited(GtkWidget* widget) { | |
| 145 password_generation_status_.password_edited = true; | |
| 131 } | 146 } |
| 132 | 147 |
| 133 void PasswordGenerationBubbleGtk::OnLearnMoreLinkClicked(GtkButton* button) { | 148 void PasswordGenerationBubbleGtk::OnLearnMoreLinkClicked(GtkButton* button) { |
| 149 password_generation_status_.learn_more_visited = true; | |
| 134 Browser* browser = browser::FindBrowserWithWebContents(tab_->web_contents()); | 150 Browser* browser = browser::FindBrowserWithWebContents(tab_->web_contents()); |
| 135 content::OpenURLParams params( | 151 content::OpenURLParams params( |
| 136 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), | 152 GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(), |
| 137 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); | 153 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false); |
| 138 browser->OpenURL(params); | 154 browser->OpenURL(params); |
| 139 bubble_->Close(); | 155 bubble_->Close(); |
| 140 } | 156 } |
| OLD | NEW |