summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cookie_modal_dialog_gtk.cc
diff options
context:
space:
mode:
authorerg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 20:05:13 +0000
committererg@chromium.org <erg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 20:05:13 +0000
commitba6da1fa11a1d7635e8ad5ab282734f80e2effa2 (patch)
tree25ef44da05e764cb90e995e09b75e40387ae5ce2 /chrome/browser/cookie_modal_dialog_gtk.cc
parentfc9e60e86ec510dcf50fa27b6d5c9bf29cb7976f (diff)
downloadchromium_src-ba6da1fa11a1d7635e8ad5ab282734f80e2effa2.zip
chromium_src-ba6da1fa11a1d7635e8ad5ab282734f80e2effa2.tar.gz
chromium_src-ba6da1fa11a1d7635e8ad5ab282734f80e2effa2.tar.bz2
GTK: Add modal cookies confirmation prompt.
BUG=35178,36183 TEST=none Review URL: http://codereview.chromium.org/652172 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39914 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cookie_modal_dialog_gtk.cc')
-rw-r--r--chrome/browser/cookie_modal_dialog_gtk.cc127
1 files changed, 127 insertions, 0 deletions
diff --git a/chrome/browser/cookie_modal_dialog_gtk.cc b/chrome/browser/cookie_modal_dialog_gtk.cc
new file mode 100644
index 0000000..104ec80
--- /dev/null
+++ b/chrome/browser/cookie_modal_dialog_gtk.cc
@@ -0,0 +1,127 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/cookie_modal_dialog.h"
+
+#include "app/l10n_util.h"
+#include "base/logging.h"
+#include "chrome/browser/gtk/gtk_chrome_link_button.h"
+#include "chrome/browser/views/cookie_prompt_view.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/common/gtk_util.h"
+#include "grit/generated_resources.h"
+#include "grit/locale_settings.h"
+
+void CookiePromptModalDialog::CreateAndShowDialog() {
+ dialog_ = CreateNativeDialog();
+ gtk_widget_show_all(GTK_WIDGET(GTK_DIALOG(dialog_)));
+
+ // Suggest a minimum size.
+ gint width;
+ GtkRequisition req;
+ gtk_widget_size_request(dialog_, &req);
+ gtk_util::GetWidgetSizeFromResources(dialog_, IDS_ALERT_DIALOG_WIDTH_CHARS, 0,
+ &width, NULL);
+ if (width > req.width)
+ gtk_widget_set_size_request(dialog_, width, -1);
+}
+
+int CookiePromptModalDialog::GetDialogButtons() {
+ return 0;
+}
+
+void CookiePromptModalDialog::AcceptWindow() {
+ HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_ACCEPT);
+}
+
+void CookiePromptModalDialog::CancelWindow() {
+ HandleDialogResponse(GTK_DIALOG(dialog_), GTK_RESPONSE_REJECT);
+}
+
+NativeDialog CookiePromptModalDialog::CreateNativeDialog() {
+ gfx::NativeWindow window = tab_contents_->GetMessageBoxRootWindow();
+ CookiePromptModalDialog::DialogType type = dialog_type();
+ NativeDialog dialog = gtk_dialog_new_with_buttons(
+ l10n_util::GetStringFUTF8(
+ type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ?
+ IDS_COOKIE_ALERT_TITLE : IDS_DATA_ALERT_TITLE,
+ UTF8ToUTF16(origin().host())).c_str(),
+ window,
+ GTK_DIALOG_MODAL,
+ l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_BLOCK_BUTTON).c_str(),
+ GTK_RESPONSE_REJECT,
+ l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ALLOW_BUTTON).c_str(),
+ GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ GtkWidget* content_area = GTK_DIALOG(dialog)->vbox;
+ gtk_box_set_spacing(GTK_BOX(content_area), gtk_util::kContentAreaSpacing);
+
+ string16 display_host = UTF8ToUTF16(origin().host());
+ GtkWidget* label = gtk_label_new(
+ l10n_util::GetStringFUTF8(
+ type == CookiePromptModalDialog::DIALOG_TYPE_COOKIE ?
+ IDS_COOKIE_ALERT_LABEL : IDS_DATA_ALERT_LABEL,
+ display_host).c_str());
+
+ gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0);
+
+ // Create a vbox for all the radio buttons so they aren't too far away from
+ // each other.
+ GtkWidget* radio_box = gtk_vbox_new(FALSE, gtk_util::kControlSpacing);
+ remember_radio_ = gtk_radio_button_new_with_label(NULL,
+ l10n_util::GetStringFUTF8(IDS_COOKIE_ALERT_REMEMBER_RADIO,
+ display_host).c_str());
+ gtk_box_pack_start(GTK_BOX(radio_box), remember_radio_, FALSE, FALSE, 0);
+
+ GtkWidget* ask_radio = gtk_radio_button_new_with_label_from_widget(
+ GTK_RADIO_BUTTON(remember_radio_),
+ l10n_util::GetStringUTF8(IDS_COOKIE_ALERT_ASK_RADIO).c_str());
+ gtk_box_pack_start(GTK_BOX(radio_box), ask_radio, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(content_area), radio_box, FALSE, FALSE, 0);
+
+ // Now we create the details link and align it left in the button box.
+ GtkWidget* details_button = gtk_chrome_link_button_new(
+ l10n_util::GetStringUTF8(IDS_COOKIE_SHOW_DETAILS_LABEL).c_str());
+ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->action_area),
+ details_button, FALSE, FALSE, 0);
+ gtk_widget_set_sensitive(details_button, FALSE);
+ gtk_button_box_set_child_secondary(
+ GTK_BUTTON_BOX(GTK_DIALOG(dialog)->action_area),
+ details_button,
+ TRUE);
+
+ // TODO(erg): http://crbug.com/35178 : Needs to implement the cookie details
+ // box here.
+
+ gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+ g_signal_connect(dialog, "response",
+ G_CALLBACK(AppModalDialog::OnDialogResponse),
+ reinterpret_cast<AppModalDialog*>(this));
+
+ gtk_util::MakeAppModalWindowGroup();
+
+ return dialog;
+}
+
+void CookiePromptModalDialog::HandleDialogResponse(GtkDialog* dialog,
+ gint response_id) {
+ bool remember_radio = gtk_toggle_button_get_active(
+ GTK_TOGGLE_BUTTON(remember_radio_));
+ if (response_id == GTK_RESPONSE_REJECT) {
+ BlockSiteData(remember_radio);
+ } else if (response_id == GTK_RESPONSE_ACCEPT) {
+ // TODO(erg): Needs to use |session_expire_| instead of true.
+ AllowSiteData(remember_radio, true);
+ } else {
+ BlockSiteData(false);
+ }
+ gtk_widget_destroy(GTK_WIDGET(dialog));
+
+ CompleteDialog();
+
+ gtk_util::AppModalDismissedUngroupWindows();
+ delete this;
+}