Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: content/shell/shell_login_dialog_gtk.cc

Issue 10823099: Add login prompt dialog support for GTK content shell. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase the patch Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/shell/shell_login_dialog.cc ('k') | content/shell/shell_resource_dispatcher_host_delegate.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/shell/shell_login_dialog_gtk.cc
diff --git a/content/shell/shell_login_dialog_gtk.cc b/content/shell/shell_login_dialog_gtk.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1748f0487d6c1535e3319f17ed25830679840e62
--- /dev/null
+++ b/content/shell/shell_login_dialog_gtk.cc
@@ -0,0 +1,111 @@
+// Copyright (c) 2012 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 "content/shell/shell_login_dialog.h"
+
+#include <gtk/gtk.h>
+
+#include "base/logging.h"
+#include "base/string16.h"
+#include "base/utf_string_conversions.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/resource_dispatcher_host.h"
+#include "content/public/browser/resource_request_info.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+#include "ui/base/gtk/gtk_hig_constants.h"
+
+namespace content {
+
+void ShellLoginDialog::PlatformCreateDialog(const string16& message) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
+ int render_process_id;
+ int render_view_id;
+ if (!ResourceRequestInfo::ForRequest(request_)->GetAssociatedRenderView(
+ &render_process_id, &render_view_id)) {
+ NOTREACHED();
+ }
+
+ WebContents* web_contents = NULL;
+ RenderViewHost* render_view_host =
+ RenderViewHost::FromID(render_process_id, render_view_id);
+ if (render_view_host)
+ web_contents = WebContents::FromRenderViewHost(render_view_host);
+ DCHECK(web_contents);
+
+ gfx::NativeWindow parent_window =
+ web_contents->GetView()->GetTopLevelNativeWindow();
+
+ root_ = gtk_message_dialog_new(parent_window,
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK_CANCEL,
+ "Please log in.");
+
+ GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(root_));
+ GtkWidget* label = gtk_label_new(UTF16ToUTF8(message).c_str());
+ gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
+ gtk_box_pack_start(GTK_BOX(content_area), label, FALSE, FALSE, 0);
+
+ username_entry_ = gtk_entry_new();
+ gtk_entry_set_activates_default(GTK_ENTRY(username_entry_), TRUE);
+
+ password_entry_ = gtk_entry_new();
+ gtk_entry_set_activates_default(GTK_ENTRY(password_entry_), TRUE);
+ gtk_entry_set_visibility(GTK_ENTRY(password_entry_), FALSE);
+
+ GtkWidget* table = gtk_table_new(2, 2, FALSE);
+ gtk_table_set_col_spacing(GTK_TABLE(table), 0, ui::kLabelSpacing);
+ gtk_table_set_row_spacings(GTK_TABLE(table), ui::kControlSpacing);
+
+ GtkWidget* username_label = gtk_label_new("Username:");
+ gtk_misc_set_alignment(GTK_MISC(username_label), 0, 0.5);
+
+ gtk_table_attach(GTK_TABLE(table), username_label, 0, 1, 0, 1, GTK_FILL,
+ GTK_FILL, 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), username_entry_, 1, 2, 0, 1);
+
+ GtkWidget* password_label = gtk_label_new("Password:");
+ gtk_misc_set_alignment(GTK_MISC(password_label), 0, 0.5);
+
+ gtk_table_attach(GTK_TABLE(table), password_label, 0, 1, 1, 2, GTK_FILL,
+ GTK_FILL, 0, 0);
+ gtk_table_attach_defaults(GTK_TABLE(table), password_entry_, 1, 2, 1, 2);
+
+ gtk_box_pack_start(GTK_BOX(content_area), table, FALSE, FALSE, 0);
+
+ g_signal_connect(root_, "response", G_CALLBACK(OnResponseThunk), this);
+ gtk_widget_grab_focus(username_entry_);
+ gtk_widget_show_all(GTK_WIDGET(root_));
+}
+
+void ShellLoginDialog::PlatformCleanUp() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+void ShellLoginDialog::PlatformRequestCancelled() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+}
+
+void ShellLoginDialog::OnResponse(GtkWidget* sender, int response_id) {
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ UserAcceptedAuth(
+ UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(username_entry_))),
+ UTF8ToUTF16(gtk_entry_get_text(GTK_ENTRY(password_entry_))));
+ break;
+ case GTK_RESPONSE_CANCEL:
+ case GTK_RESPONSE_DELETE_EVENT:
+ UserCancelledAuth();
+ break;
+ default:
+ NOTREACHED();
+ }
+
+ gtk_widget_destroy(root_);
+}
+
+} // namespace content
« no previous file with comments | « content/shell/shell_login_dialog.cc ('k') | content/shell/shell_resource_dispatcher_host_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698