Merge lp:~lemonboy/capnet-assist/ssl-status into lp:~elementary-apps/capnet-assist/trunk

Proposed by The Lemon Man
Status: Merged
Approved by: Marcus Wichelmann
Approved revision: 38
Merged at revision: 29
Proposed branch: lp:~lemonboy/capnet-assist/ssl-status
Merge into: lp:~elementary-apps/capnet-assist/trunk
Diff against target: 255 lines (+156/-23)
2 files modified
src/CMakeLists.txt (+6/-1)
src/CaptiveLogin.vala (+150/-22)
To merge this branch: bzr merge lp:~lemonboy/capnet-assist/ssl-status
Reviewer Review Type Date Requested Status
Marcus Wichelmann (community) code Approve
Danielle Foré ux Approve
Review via email: mp+275629@code.launchpad.net

Commit message

Show ssl certificates

To post a comment you must log in.
28. By The Lemon Man

Show the state of the SSL certificate in the UI.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Can we add the "flat" class to the icon.

Also, would it be possible to put it next to the title? (still to the left). Right now, it feels very disassociated.

Clicking the button doesn't seem to do anything for me

review: Needs Fixing
29. By The Lemon Man

Show a popover with some informations about the certificate.

30. By The Lemon Man

Move the button near the title.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Please use Gtk.STYLE_CLASS_FLAT and not Gtk.ReliefStyle.NONE

Also, add the "title" class to the title label instead of hardcoding style with pango

Corentin would probably say to use Gtk.Grid and not Gtk.Box

review: Needs Fixing
31. By The Lemon Man

Set the appropriate class for the widgets.

Revision history for this message
Danielle Foré (danrabbit) wrote :

Hm, I'm not 100% sure why but there's a difference between the height of the titlebar here and what it would normally be.

Can we add a 3px margin to the title box and also add the class "titlebutton" to the SSL button (just to make sure that it's round)?

32. By The Lemon Man

Minor UI touchups.

33. By The Lemon Man

Revert to the http scheme for DUMMY_URL

34. By The Lemon Man

Minor UI touchups.

35. By The Lemon Man

Use a ToggleButton instead of a Button.

36. By The Lemon Man

Revert to the http scheme for DUMMY_URL

37. By The Lemon Man

Use a more appropriate placeholder icon

Revision history for this message
Danielle Foré (danrabbit) wrote :

Works as expected. UX Approve.

Needs proper code review

review: Approve (ux)
Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

The code looks good, I've only marked some style-stuff and things that might not be needed.
See comments.

review: Needs Fixing (code)
38. By The Lemon Man

Stylistic touchups

Revision history for this message
Marcus Wichelmann (l-admin-3) wrote :

Looks good now!
Since dan said he has tested it I think this branch is ready for merge.

Nice work!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2015-10-21 20:43:21 +0000
3+++ src/CMakeLists.txt 2015-10-26 01:07:19 +0000
4@@ -2,6 +2,8 @@
5 gtk+-3.0
6 gio-2.0
7 webkit2gtk-4.0
8+ gcr-3
9+ gcr-ui-3
10 )
11 add_definitions(${DEPS_CFLAGS})
12
13@@ -13,11 +15,12 @@
14 -D_VERSION=\"${VERSION}\"
15 -D_INSTALL_PREFIX=\"${CMAKE_INSTALL_PREFIX}\"
16 -D_SOURCE_ROOT_DIR=\"${CMAKE_SOURCE_DIR}\"
17+ -DGCR_API_SUBJECT_TO_CHANGE
18 -g
19 )
20
21 set(CAPTIVE_LOGIN_PACKAGES
22- gtk+-3.0 gio-2.0 webkit2gtk-4.0
23+ gtk+-3.0 gio-2.0 webkit2gtk-4.0 gcr-3 gcr-ui-3
24 )
25
26 set(VALAC_OPTIONS
27@@ -36,6 +39,8 @@
28 ${VALAC_OPTIONS}
29 )
30
31+add_definitions(${CFLAGS})
32+
33 #Here we define our executable name.
34 add_executable(captive-login ${VALA_C} )
35
36
37=== modified file 'src/CaptiveLogin.vala'
38--- src/CaptiveLogin.vala 2015-10-25 20:43:09 +0000
39+++ src/CaptiveLogin.vala 2015-10-26 01:07:19 +0000
40@@ -23,31 +23,53 @@
41 private const string DUMMY_URL = "http://elementary.io";
42
43 private WebKit.WebView web_view;
44+ private Gtk.ToggleButton tls_button;
45+ private Gtk.Label title_label;
46
47 public ValaBrowser () {
48 set_default_size (1000, 680);
49 set_keep_above (true);
50 set_skip_taskbar_hint (true);
51
52+ create_widgets ();
53+ connect_signals ();
54+ }
55+
56+ private void create_widgets () {
57 var header = new Gtk.HeaderBar ();
58 header.set_show_close_button (true);
59 header.get_style_context ().remove_class ("header-bar");
60
61 this.set_titlebar (header);
62- this.title = ValaBrowser.TITLE;
63-
64- create_widgets ();
65- connect_signals ();
66- }
67-
68- private void create_widgets () {
69- this.web_view = new WebKit.WebView ();
70+
71+ tls_button = new Gtk.ToggleButton ();
72+ tls_button.set_image (new Gtk.Image.from_icon_name ("content-loading-symbolic", Gtk.IconSize.BUTTON));
73+ var tls_button_style_context = tls_button.get_style_context ();
74+ tls_button_style_context.add_class (Gtk.STYLE_CLASS_FLAT);
75+ tls_button_style_context.add_class ("titlebutton");
76+ tls_button.set_sensitive (false);
77+ tls_button.toggled.connect (on_tls_button_click);
78+
79+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
80+ hbox.set_margin_top (3);
81+ hbox.set_margin_bottom (3);
82+ hbox.pack_start (tls_button);
83+
84+ title_label = new Gtk.Label (ValaBrowser.TITLE);
85+ title_label.get_style_context ().add_class (Gtk.STYLE_CLASS_TITLE);
86+ hbox.pack_start (title_label);
87+
88+ header.set_custom_title (hbox);
89+
90+ web_view = new WebKit.WebView ();
91+
92 var scrolled_window = new Gtk.ScrolledWindow (null, null);
93 scrolled_window.set_policy (Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC);
94- scrolled_window.add (this.web_view);
95+ scrolled_window.add (web_view);
96+
97 var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
98- vbox.set_homogeneous (false);
99 vbox.pack_start (scrolled_window, true, true, 0);
100+
101 add (vbox);
102 }
103
104@@ -72,25 +94,131 @@
105 return message.status_code == 204;
106 }
107
108+ private void update_tls_info () {
109+ TlsCertificate cert;
110+ TlsCertificateFlags cert_flags;
111+ Icon icon;
112+ bool is_secure;
113+
114+ if (!web_view.get_tls_info (out cert, out cert_flags)) {
115+ // The page is served over HTTP
116+ is_secure = false;
117+ } else {
118+ // The page is served over HTTPS, if cert_flags is set then there's
119+ // some problem with the certificate provided by the website.
120+ is_secure = (cert_flags == 0);
121+ }
122+
123+ if (is_secure) {
124+ icon = new ThemedIcon.from_names ({"channel-secure-symbolic", "security-high"});
125+ tls_button.set_tooltip_text ("The page is served over a protected connection.");
126+ } else {
127+ icon = new ThemedIcon.from_names ({"channel-insecure-symbolic", "security-low"});
128+ tls_button.set_tooltip_text ("The page is served over an unprotected connection.");
129+ }
130+
131+ var image = new Gtk.Image.from_gicon (icon, Gtk.IconSize.BUTTON);
132+ tls_button.set_image (image);
133+ }
134+
135+ private void on_tls_button_click () {
136+ TlsCertificate cert;
137+ TlsCertificateFlags cert_flags;
138+
139+ if (!tls_button.get_active ()) {
140+ return;
141+ }
142+ if (!web_view.get_tls_info (out cert, out cert_flags)) {
143+ return;
144+ }
145+
146+ var popover = new Gtk.Popover (tls_button);
147+ popover.set_border_width (6);
148+ var vbox = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
149+ popover.add (vbox);
150+
151+ // Wonderful hack we got here, the vapi for Gtk has a wrong definition
152+ // for the get_gicon () method, it's not reported as an out parameter
153+ // hence we're stuck with passing everything by value.
154+ // Since we're badass we pass the INVALID constant that evaluates to 0
155+ // which is casted into a NULL pointer and allows us to save the date.
156+ Icon button_icon;
157+ (tls_button.get_image () as Gtk.Image).get_gicon (out button_icon, Gtk.IconSize.INVALID);
158+
159+ var hbox = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
160+ hbox.pack_start (new Gtk.Image.from_gicon (button_icon, Gtk.IconSize.LARGE_TOOLBAR), false, false);
161+ hbox.pack_start (new Gtk.Label (tls_button.get_tooltip_text ()), false, false);
162+ vbox.pack_start (hbox, false, false);
163+
164+ var gcr_cert = new Gcr.SimpleCertificate (cert.certificate.data);
165+ var cert_details = new Gcr.CertificateWidget (gcr_cert);
166+ vbox.pack_start (cert_details);
167+
168+ // This hack has been borrowed from midori, the widget provided by the
169+ // GCR library would fail with an assertion when the 'details' button was
170+ // clicked
171+ popover.button_press_event.connect ((event) => {
172+ return true;
173+ });
174+ popover.button_release_event.connect ((event) => {
175+ var child = popover.get_child ();
176+ var event_widget = Gtk.get_event_widget (event);
177+
178+ if (child != null && event.window == popover.get_window ()) {
179+ Gtk.Allocation child_alloc;
180+ popover.get_allocation (out child_alloc);
181+
182+ if (event.x < child_alloc.x ||
183+ event.x > child_alloc.x + child_alloc.width ||
184+ event.y < child_alloc.y ||
185+ event.y > child_alloc.y + child_alloc.height) {
186+ popover.hide ();
187+ tls_button.set_active (false);
188+ }
189+ }
190+ else if (event_widget != null && !event_widget.is_ancestor (popover)) {
191+ popover.hide ();
192+ tls_button.set_active (false);
193+ }
194+
195+ return true;
196+ });
197+
198+ popover.show_all ();
199+
200+ return;
201+ }
202+
203 private void connect_signals () {
204 this.destroy.connect (Gtk.main_quit);
205 //should title change?
206- this.web_view.notify["title"].connect ((view, param_spec) => {
207- this.title = this.web_view.get_title ();
208+ web_view.notify["title"].connect ((view, param_spec) => {
209+ title_label.set_text (web_view.get_title ());
210 });
211
212- this.web_view.load_changed.connect ((view, event) => {
213- if (event == WebKit.LoadEvent.FINISHED) {
214- if (isLoggedIn ()) {
215- debug ("Logged in!");
216- Gtk.main_quit ();
217- } else {
218- debug ("Still not logged in.");
219- }
220+ web_view.load_changed.connect ((view, event) => {
221+ switch (event) {
222+ case WebKit.LoadEvent.FINISHED:
223+ if (isLoggedIn ()) {
224+ debug ("Logged in!");
225+ Gtk.main_quit ();
226+ } else {
227+ debug ("Still not logged in.");
228+ }
229+ break;
230+
231+ case WebKit.LoadEvent.STARTED:
232+ tls_button.set_sensitive (false);
233+ break;
234+
235+ case WebKit.LoadEvent.COMMITTED:
236+ update_tls_info ();
237+ tls_button.set_sensitive (true);
238+ break;
239 }
240 });
241
242- this.web_view.load_failed.connect ((event, uri, error) => {
243+ web_view.load_failed.connect ((event, uri, error) => {
244 // The user has canceled the page loading eg. by clicking on a link.
245 if ((Error)error is WebKit.NetworkError.CANCELLED) {
246 return true;
247@@ -103,7 +231,7 @@
248
249 public void start () {
250 show_all ();
251- this.web_view.load_uri (ValaBrowser.DUMMY_URL);
252+ web_view.load_uri (ValaBrowser.DUMMY_URL);
253 }
254
255 public static int main (string[] args) {

Subscribers

People subscribed via source and target branches

to all changes: