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

Side by Side Diff: chrome/browser/gtk/external_protocol_dialog_gtk.cc

Issue 194002: Add external protocol dialog for Linux.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 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/external_protocol_dialog_gtk.h"
6
7 #include <gtk/gtk.h>
8
9 #include "app/l10n_util.h"
10 #include "base/histogram.h"
11 #include "chrome/browser/external_protocol_handler.h"
12 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/tab_contents/tab_contents_view.h"
14 #include "chrome/browser/tab_contents/tab_util.h"
15 #include "chrome/common/gtk_util.h"
16 #include "grit/chromium_strings.h"
17 #include "grit/generated_resources.h"
18
19 namespace {
20
21 const int kMessageWidth = 400;
22
23 } // namespace
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // ExternalProtocolHandler
27
28 // static
29 void ExternalProtocolHandler::RunExternalProtocolDialog(
30 const GURL& url, int render_process_host_id, int routing_id) {
31 TabContents* tab_contents = tab_util::GetTabContentsByID(
32 render_process_host_id, routing_id);
33 new ExternalProtocolDialogGtk(url, tab_contents);
34 }
35
36 ///////////////////////////////////////////////////////////////////////////////
37 // ExternalProtocolDialogGtk
38
39 ExternalProtocolDialogGtk::ExternalProtocolDialogGtk(
40 const GURL& url, TabContents* tab_contents)
41 : url_(url),
42 creation_time_(base::Time::Now()) {
43 GtkWindow* parent = tab_contents ?
44 tab_contents->view()->GetTopLevelNativeWindow() : NULL;
45
46 dialog_ = gtk_dialog_new_with_buttons(
47 l10n_util::GetStringUTF8(IDS_EXTERNAL_PROTOCOL_TITLE).c_str(),
48 parent,
49 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR),
50 GTK_STOCK_CANCEL,
51 GTK_RESPONSE_REJECT,
52 NULL);
53
54 gtk_util::AddButtonToDialog(dialog_,
55 l10n_util::GetStringUTF8(IDS_EXTERNAL_PROTOCOL_OK_BUTTON_TEXT).c_str(),
56 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT);
57
58 std::string message_text = l10n_util::GetStringFUTF8(
59 IDS_EXTERNAL_PROTOCOL_INFORMATION,
60 ASCIIToUTF16(url.scheme() + ":"),
61 ASCIIToUTF16(url.possibly_invalid_spec())) + "\n\n";
62
63 message_text += l10n_util::GetStringFUTF8(
64 IDS_EXTERNAL_PROTOCOL_APPLICATION_TO_LAUNCH,
65 ASCIIToUTF16(std::string("xdg-open ") + url.spec())) + "\n\n";
66
67 message_text += l10n_util::GetStringUTF8(IDS_EXTERNAL_PROTOCOL_WARNING);
68
69 GtkWidget* label = gtk_label_new(message_text.c_str());
70 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
71 gtk_widget_set_size_request(label, kMessageWidth, -1);
72 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_)->vbox), label, TRUE, TRUE, 0);
73
74 g_signal_connect(dialog_, "response",
75 G_CALLBACK(OnDialogResponse), this);
76
77 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE);
78 gtk_widget_show_all(dialog_);
79 }
80
81 void ExternalProtocolDialogGtk::OnDialogResponse(GtkWidget* widget,
82 int response, ExternalProtocolDialogGtk* dialog) {
83 if (response == GTK_RESPONSE_ACCEPT) {
84 UMA_HISTOGRAM_LONG_TIMES("clickjacking.launch_url",
85 base::Time::Now() - dialog->creation_time_);
86
87 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(dialog->url_);
88 }
89
90 gtk_widget_destroy(widget);
91 delete dialog;
92 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/external_protocol_dialog_gtk.h ('k') | chrome/browser/views/external_protocol_dialog.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698