43
43
this.set_titlebar (header);
45
this.tls_button = new Gtk.ToggleButton ();
46
this.tls_button.set_image (new Gtk.Image.from_icon_name ("content-loading-symbolic", Gtk.IconSize.BUTTON));
47
this.tls_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
48
this.tls_button.get_style_context ().add_class ("titlebutton");
49
this.tls_button.set_sensitive (false);
50
this.tls_button.toggled.connect (on_tls_button_click);
45
tls_button = new Gtk.ToggleButton ();
46
tls_button.set_image (new Gtk.Image.from_icon_name ("content-loading-symbolic", Gtk.IconSize.BUTTON));
47
var tls_button_style_context = tls_button.get_style_context ();
48
tls_button_style_context.add_class (Gtk.STYLE_CLASS_FLAT);
49
tls_button_style_context.add_class ("titlebutton");
50
tls_button.set_sensitive (false);
51
tls_button.toggled.connect (on_tls_button_click);
52
53
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
53
54
hbox.set_margin_top (3);
54
55
hbox.set_margin_bottom (3);
55
hbox.pack_start (this.tls_button);
56
this.title_label = new Gtk.Label (ValaBrowser.TITLE);
57
this.title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);
56
hbox.pack_start (tls_button);
58
title_label = new Gtk.Label (ValaBrowser.TITLE);
59
title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);
58
60
hbox.pack_start (title_label);
60
62
header.set_custom_title (hbox);
62
this.web_view = new WebKit.WebView ();
64
web_view = new WebKit.WebView ();
64
66
var scrolled_window = new Gtk.ScrolledWindow (null, null);
65
67
scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
66
scrolled_window.add (this.web_view);
68
scrolled_window.add (web_view);
68
70
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
69
vbox.set_homogeneous (false);
70
71
vbox.pack_start (scrolled_window, true, true, 0);
112
113
icon = new ThemedIcon.from_names ({"channel-secure-symbolic", "security-high"});
113
this.tls_button.set_tooltip_text ("The page is served over a protected connection.");
114
tls_button.set_tooltip_text ("The page is served over a protected connection.");
115
116
icon = new ThemedIcon.from_names ({"channel-insecure-symbolic", "security-low"});
116
this.tls_button.set_tooltip_text ("The page is served over an unprotected connection.");
117
tls_button.set_tooltip_text ("The page is served over an unprotected connection.");
119
120
var image = new Gtk.Image.from_gicon (icon, Gtk.IconSize.BUTTON);
120
this.tls_button.set_image (image);
121
tls_button.set_image (image);
123
124
private void on_tls_button_click () {
124
125
TlsCertificate cert;
125
126
TlsCertificateFlags cert_flags;
127
if (!this.tls_button.get_active ()) {
131
if (!this.web_view.get_tls_info (out cert, out cert_flags)) {
135
var popover = new Gtk.Popover (this.tls_button);
128
if (!tls_button.get_active ()) {
131
if (!web_view.get_tls_info (out cert, out cert_flags)) {
135
var popover = new Gtk.Popover (tls_button);
136
136
popover.set_border_width (6);
137
137
var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
138
vbox.set_homogeneous (false);
139
138
popover.add (vbox);
140
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
141
hbox.set_homogeneous (false);
142
140
// Wonderful hack we got here, the vapi for Gtk has a wrong definition
143
141
// for the get_gicon () method, it's not reported as an out parameter
144
142
// hence we're stuck with passing everything by value.
145
143
// Since we're badass we pass the INVALID constant that evaluates to 0
146
144
// which is casted into a NULL pointer and allows us to save the date.
147
145
Icon button_icon;
148
(this.tls_button.get_image () as Gtk.Image).get_gicon (out button_icon, Gtk.IconSize.INVALID);
146
(tls_button.get_image () as Gtk.Image).get_gicon (out button_icon, Gtk.IconSize.INVALID);
148
var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
149
149
hbox.pack_start (new Gtk.Image.from_gicon (button_icon, Gtk.IconSize.LARGE_TOOLBAR), false, false);
150
hbox.pack_start (new Gtk.Label (this.tls_button.get_tooltip_text ()), false, false);
150
hbox.pack_start (new Gtk.Label (tls_button.get_tooltip_text ()), false, false);
151
151
vbox.pack_start (hbox, false, false);
153
153
var gcr_cert = new Gcr.SimpleCertificate (cert.certificate.data);
173
173
event.y < child_alloc.y ||
174
174
event.y > child_alloc.y + child_alloc.height) {
176
this.tls_button.set_active (false);
176
tls_button.set_active (false);
180
179
else if (event_widget != null && !event_widget.is_ancestor (popover)) {
182
this.tls_button.set_active (false);
181
tls_button.set_active (false);
193
192
private void connect_signals () {
194
193
this.destroy.connect (Gtk.main_quit);
195
194
//should title change?
196
this.web_view.notify["title"].connect ((view, param_spec) => {
197
this.title_label.set_text (this.web_view.get_title ());
195
web_view.notify["title"].connect ((view, param_spec) => {
196
title_label.set_text (web_view.get_title ());
200
this.web_view.load_changed.connect ((view, event) => {
199
web_view.load_changed.connect ((view, event) => {
202
case WebKit.LoadEvent.FINISHED:
204
debug ("Logged in!");
207
debug ("Still not logged in.");
211
case WebKit.LoadEvent.STARTED:
212
this.tls_button.set_sensitive (false);
215
case WebKit.LoadEvent.COMMITTED:
217
this.tls_button.set_sensitive (true);
201
case WebKit.LoadEvent.FINISHED:
203
debug ("Logged in!");
206
debug ("Still not logged in.");
210
case WebKit.LoadEvent.STARTED:
211
tls_button.set_sensitive (false);
214
case WebKit.LoadEvent.COMMITTED:
216
tls_button.set_sensitive (true);
222
this.web_view.load_failed.connect ((event, uri, error) => {
221
web_view.load_failed.connect ((event, uri, error) => {
223
222
// The user has canceled the page loading eg. by clicking on a link.
224
223
if ((Error)error is WebKit.NetworkError.CANCELLED) {