| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/options/passwords_exceptions_window_gtk.h" | |
| 6 | |
| 7 #include <gtk/gtk.h> | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "app/l10n_util.h" | |
| 12 #include "base/message_loop.h" | |
| 13 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" | |
| 14 #include "chrome/browser/gtk/gtk_util.h" | |
| 15 #include "chrome/browser/gtk/options/passwords_exceptions_page_gtk.h" | |
| 16 #include "chrome/browser/gtk/options/passwords_page_gtk.h" | |
| 17 #include "chrome/browser/profiles/profile.h" | |
| 18 #include "chrome/browser/ui/options/options_window.h" | |
| 19 #include "grit/chromium_strings.h" | |
| 20 #include "grit/generated_resources.h" | |
| 21 #include "grit/locale_settings.h" | |
| 22 | |
| 23 /////////////////////////////////////////////////////////////////////////////// | |
| 24 // PasswordsExceptionsWindowGtk | |
| 25 // | |
| 26 // The contents of the Passwords and Exceptions dialog window. | |
| 27 | |
| 28 class PasswordsExceptionsWindowGtk { | |
| 29 public: | |
| 30 explicit PasswordsExceptionsWindowGtk(Profile* profile); | |
| 31 ~PasswordsExceptionsWindowGtk(); | |
| 32 | |
| 33 void Show(); | |
| 34 | |
| 35 private: | |
| 36 static void OnWindowDestroy(GtkWidget* widget, | |
| 37 PasswordsExceptionsWindowGtk* window); | |
| 38 | |
| 39 // The passwords and exceptions dialog. | |
| 40 GtkWidget *dialog_; | |
| 41 | |
| 42 // The container of the password and exception pages. | |
| 43 GtkWidget *notebook_; | |
| 44 | |
| 45 // The Profile associated with these passwords and exceptions. | |
| 46 Profile* profile_; | |
| 47 | |
| 48 // The passwords page. | |
| 49 PasswordsPageGtk passwords_page_; | |
| 50 | |
| 51 // The exceptions page. | |
| 52 PasswordsExceptionsPageGtk exceptions_page_; | |
| 53 | |
| 54 // Helper object to manage accessibility metadata. | |
| 55 scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(PasswordsExceptionsWindowGtk); | |
| 58 }; | |
| 59 | |
| 60 // The singleton passwords and exceptions window object. | |
| 61 static PasswordsExceptionsWindowGtk* passwords_exceptions_window = NULL; | |
| 62 | |
| 63 /////////////////////////////////////////////////////////////////////////////// | |
| 64 // PasswordsExceptionsWindowGtk, public: | |
| 65 | |
| 66 PasswordsExceptionsWindowGtk::PasswordsExceptionsWindowGtk(Profile* profile) | |
| 67 : profile_(profile), | |
| 68 passwords_page_(profile_), | |
| 69 exceptions_page_(profile_) { | |
| 70 std::string dialog_name = l10n_util::GetStringUTF8( | |
| 71 IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); | |
| 72 dialog_ = gtk_dialog_new_with_buttons( | |
| 73 dialog_name.c_str(), | |
| 74 // Passwords and exceptions window is shared between all browser windows. | |
| 75 NULL, | |
| 76 // Non-modal. | |
| 77 GTK_DIALOG_NO_SEPARATOR, | |
| 78 GTK_STOCK_CLOSE, | |
| 79 GTK_RESPONSE_CLOSE, | |
| 80 NULL); | |
| 81 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(dialog_)->vbox), | |
| 82 gtk_util::kContentAreaSpacing); | |
| 83 | |
| 84 accessible_widget_helper_.reset(new AccessibleWidgetHelper( | |
| 85 dialog_, profile)); | |
| 86 accessible_widget_helper_->SendOpenWindowNotification(dialog_name); | |
| 87 | |
| 88 notebook_ = gtk_notebook_new(); | |
| 89 | |
| 90 gtk_notebook_append_page( | |
| 91 GTK_NOTEBOOK(notebook_), | |
| 92 passwords_page_.get_page_widget(), | |
| 93 gtk_label_new(l10n_util::GetStringUTF8( | |
| 94 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE).c_str())); | |
| 95 | |
| 96 gtk_notebook_append_page( | |
| 97 GTK_NOTEBOOK(notebook_), | |
| 98 exceptions_page_.get_page_widget(), | |
| 99 gtk_label_new(l10n_util::GetStringUTF8( | |
| 100 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE).c_str())); | |
| 101 | |
| 102 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog_)->vbox), notebook_); | |
| 103 | |
| 104 // We only have one button and don't do any special handling, so just hook it | |
| 105 // directly to gtk_widget_destroy. | |
| 106 g_signal_connect(dialog_, "response", G_CALLBACK(gtk_widget_destroy), NULL); | |
| 107 | |
| 108 g_signal_connect(dialog_, "destroy", G_CALLBACK(OnWindowDestroy), this); | |
| 109 | |
| 110 gtk_util::ShowDialogWithLocalizedSize(dialog_, | |
| 111 IDS_PASSWORDS_DIALOG_WIDTH_CHARS, | |
| 112 IDS_PASSWORDS_DIALOG_HEIGHT_LINES, | |
| 113 true); | |
| 114 } | |
| 115 | |
| 116 PasswordsExceptionsWindowGtk::~PasswordsExceptionsWindowGtk() { | |
| 117 } | |
| 118 | |
| 119 void PasswordsExceptionsWindowGtk::Show() { | |
| 120 // Bring options window to front if it already existed and isn't already | |
| 121 // in front | |
| 122 gtk_util::PresentWindow(dialog_, 0); | |
| 123 } | |
| 124 | |
| 125 /////////////////////////////////////////////////////////////////////////////// | |
| 126 // PasswordsExceptionsWindowGtk, private: | |
| 127 | |
| 128 // static | |
| 129 void PasswordsExceptionsWindowGtk::OnWindowDestroy(GtkWidget* widget, | |
| 130 PasswordsExceptionsWindowGtk* window) { | |
| 131 passwords_exceptions_window = NULL; | |
| 132 MessageLoop::current()->DeleteSoon(FROM_HERE, window); | |
| 133 } | |
| 134 | |
| 135 /////////////////////////////////////////////////////////////////////////////// | |
| 136 // Factory/finder method: | |
| 137 | |
| 138 void ShowPasswordsExceptionsWindow(Profile* profile) { | |
| 139 DCHECK(profile); | |
| 140 // If there's already an existing passwords and exceptions window, use it. | |
| 141 if (!passwords_exceptions_window) { | |
| 142 passwords_exceptions_window = new PasswordsExceptionsWindowGtk(profile); | |
| 143 } | |
| 144 passwords_exceptions_window->Show(); | |
| 145 } | |
| OLD | NEW |