| 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/cookie_modal_dialog.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "base/string_util.h" | |
| 10 #include "base/utf_string_conversions.h" | |
| 11 #include "chrome/browser/browser_process.h" | |
| 12 #include "chrome/browser/gtk/gtk_chrome_cookie_view.h" | |
| 13 #include "chrome/browser/gtk/gtk_chrome_link_button.h" | |
| 14 #include "chrome/browser/gtk/gtk_util.h" | |
| 15 #include "chrome/browser/prefs/pref_service.h" | |
| 16 #include "chrome/browser/profile.h" | |
| 17 #include "chrome/browser/views/cookie_prompt_view.h" | |
| 18 #include "chrome/browser/tab_contents/tab_contents.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "grit/generated_resources.h" | |
| 21 #include "grit/locale_settings.h" | |
| 22 | |
| 23 void CookiePromptModalDialog::CreateAndShowDialog() { | |
| 24 dialog_ = CreateNativeDialog(); | |
| 25 gtk_util::ShowModalDialogWithMinLocalizedWidth(GTK_WIDGET(dialog_), | |
| 26 IDS_ALERT_DIALOG_WIDTH_CHARS); | |
| 27 } | |
| 28 | |
| 29 void CookiePromptModalDialog::AcceptWindow() { | |
| 30 HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT); | |
| 31 } | |
| 32 | |
| 33 void CookiePromptModalDialog::CancelWindow() { | |
| 34 HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_REJECT); | |
| 35 } | |
| 36 | |
| 37 NativeDialog CookiePromptModalDialog::CreateNativeDialog() { | |
| 38 gtk_util::MakeAppModalWindowGroup(); | |
| 39 | |
| 40 gfx::NativeWindow window = tab_contents_->GetMessageBoxRootWindow(); | |
| 41 CookiePromptModalDialog::DialogType type = dialog_type(); | |
| 42 NativeDialog dialog = gtk_dialog_new_with_buttons( | |
| 43 l10n_util::GetStringFUTF8( | |
| 44 type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? | |
| 45 IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE, | |
| 46 UTF8ToUTF16(origin().host())).c_str(), | |
| 47 window, | |
| 48 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | |
| 49 l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_BLOCK_BUTTON).c_str(), | |
| 50 GTK_RESPONSE_REJECT, | |
| 51 l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ALLOW_BUTTON).c_str(), | |
| 52 GTK_RESPONSE_ACCEPT, | |
| 53 NULL); | |
| 54 gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); | |
| 55 | |
| 56 GtkWidget* content_area = GTK_DIALOG(dialog)->vbox; | |
| 57 gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing); | |
| 58 | |
| 59 string16 display_host = UTF8ToUTF16(origin().host()); | |
| 60 GtkWidget* label = gtk_util::LeftAlignMisc(gtk_label_new( | |
| 61 l10n_util::GetStringFUTF8( | |
| 62 type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ? | |
| 63 IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL, | |
| 64 display_host).c_str())); | |
| 65 gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0); | |
| 66 | |
| 67 // Create a vbox for all the radio buttons so they aren't too far away from | |
| 68 // each other. | |
| 69 GtkWidget* radio_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing); | |
| 70 remember_radio_ = gtk_radio_button_new_with_label(NULL, | |
| 71 l10n_util::GetStringFUTF8(IDS_COOKIE_ALERT_REMEMBER_RADIO, | |
| 72 display_host).c_str()); | |
| 73 gtk_box_pack_start(GTK_BOX(radio_box), remember_radio_, FALSE, FALSE, 0); | |
| 74 | |
| 75 GtkWidget* ask_radio = gtk_radio_button_new_with_label_from_widget( | |
| 76 GTK_RADIO_BUTTON(remember_radio_), | |
| 77 l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ASK_RADIO).c_str()); | |
| 78 gtk_box_pack_start(GTK_BOX(radio_box), ask_radio, FALSE, FALSE, 0); | |
| 79 | |
| 80 gtk_box_pack_start(GTK_BOX(content_area), radio_box, FALSE, FALSE, 0); | |
| 81 | |
| 82 GtkWidget* expander = gtk_expander_new( | |
| 83 l10n_util::GetStringUTF8(IDS_COOKIE_SHOW_DETAILS_LABEL).c_str()); | |
| 84 gtk_expander_set_expanded(GTK_EXPANDER(expander), | |
| 85 tab_contents_->profile()->GetPrefs()-> | |
| 86 GetBoolean(prefs::kCookiePromptExpanded)); | |
| 87 g_signal_connect(expander, "notify::expanded", | |
| 88 G_CALLBACK(OnExpanderActivateThunk), this); | |
| 89 cookie_view_ = gtk_chrome_cookie_view_new(TRUE); | |
| 90 gtk_chrome_cookie_view_clear(GTK_CHROME_COOKIE_VIEW(cookie_view_)); | |
| 91 if (type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE) { | |
| 92 gtk_chrome_cookie_view_display_cookie_string( | |
| 93 GTK_CHROME_COOKIE_VIEW(cookie_view_), | |
| 94 origin(), cookie_line()); | |
| 95 } else if (type == CookiePromptModalDialog::DIALOG_TYPE_LOCAL_STORAGE) { | |
| 96 gtk_chrome_cookie_view_display_local_storage_item( | |
| 97 GTK_CHROME_COOKIE_VIEW(cookie_view_), | |
| 98 origin().host(), | |
| 99 local_storage_key(), | |
| 100 local_storage_value()); | |
| 101 } else if (type == CookiePromptModalDialog::DIALOG_TYPE_DATABASE) { | |
| 102 gtk_chrome_cookie_view_display_database_accessed( | |
| 103 GTK_CHROME_COOKIE_VIEW(cookie_view_), | |
| 104 origin().host(), | |
| 105 database_name(), | |
| 106 display_name(), | |
| 107 estimated_size()); | |
| 108 } else if (type == CookiePromptModalDialog::DIALOG_TYPE_APPCACHE) { | |
| 109 gtk_chrome_cookie_view_display_appcache_created( | |
| 110 GTK_CHROME_COOKIE_VIEW(cookie_view_), | |
| 111 appcache_manifest_url()); | |
| 112 } else { | |
| 113 NOTIMPLEMENTED(); | |
| 114 } | |
| 115 gtk_container_add(GTK_CONTAINER(expander), cookie_view_); | |
| 116 | |
| 117 gtk_box_pack_end(GTK_BOX(content_area), GTK_WIDGET(expander), | |
| 118 FALSE, FALSE, 0); | |
| 119 | |
| 120 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
| 121 g_signal_connect(dialog, "response", | |
| 122 G_CALLBACK(AppModalDialog::OnDialogResponse), | |
| 123 reinterpret_cast<AppModalDialog*>(this)); | |
| 124 | |
| 125 return dialog; | |
| 126 } | |
| 127 | |
| 128 void CookiePromptModalDialog::HandleDialogResponse(GtkDialog* dialog, | |
| 129 gint response_id) { | |
| 130 bool remember_radio = gtk_toggle_button_get_active( | |
| 131 GTK_TOGGLE_BUTTON(remember_radio_)); | |
| 132 if (response_id == GTK_RESPONSE_REJECT) { | |
| 133 BlockSiteData(remember_radio); | |
| 134 } else if (response_id == GTK_RESPONSE_ACCEPT) { | |
| 135 bool expires = gtk_chrome_cookie_view_session_expires( | |
| 136 GTK_CHROME_COOKIE_VIEW(cookie_view_)); | |
| 137 AllowSiteData(remember_radio, expires); | |
| 138 } else { | |
| 139 BlockSiteData(false); | |
| 140 } | |
| 141 gtk_widget_destroy(GTK_WIDGET(dialog)); | |
| 142 | |
| 143 CompleteDialog(); | |
| 144 | |
| 145 gtk_util::AppModalDismissedUngroupWindows(); | |
| 146 delete this; | |
| 147 } | |
| 148 | |
| 149 void CookiePromptModalDialog::OnExpanderActivate(GtkWidget* expander, | |
| 150 GParamSpec* property) { | |
| 151 tab_contents_->profile()->GetPrefs()-> | |
| 152 SetBoolean(prefs::kCookiePromptExpanded, | |
| 153 gtk_expander_get_expanded(GTK_EXPANDER(expander))); | |
| 154 } | |
| OLD | NEW |