diff options
author | Christian Dywan <christian@twotoasts.de> | 2018-09-10 21:16:21 +0200 |
---|---|---|
committer | Christian Dywan <christian@twotoasts.de> | 2018-09-10 21:16:21 +0200 |
commit | 880cf8921097673816429093b7d7d47efb5ddd0e (patch) | |
tree | b68855eacc4ebad8580004aba636428a95a9c3cc | |
parent | 2e94e9866b42e2ccf7cd0fa7677b7ecb11de151f (diff) | |
download | midori-git-private-browsing-intro.tar.gz |
Implement private browsing intro as URI schemeprivate-browsing-intro
Fixes: #36
-rw-r--r-- | core/app.vala | 67 | ||||
-rw-r--r-- | core/browser.vala | 2 | ||||
-rw-r--r-- | core/tab.vala | 2 | ||||
-rw-r--r-- | data/about.css | 3 | ||||
-rw-r--r-- | data/error.html | 5 | ||||
-rw-r--r-- | data/speed-dial.html | 1 |
6 files changed, 75 insertions, 5 deletions
diff --git a/core/app.vala b/core/app.vala index a495effc..46b2baa5 100644 --- a/core/app.vala +++ b/core/app.vala @@ -203,6 +203,73 @@ namespace Midori { request.unref (); } + internal WebKit.WebContext ephemeral_context () { + var context = new WebKit.WebContext.ephemeral (); + context.register_uri_scheme ("internal", (request) => { + request.ref (); + private_scheme.begin (request); + }); + context.register_uri_scheme ("stock", (request) => { + request.ref (); + stock_scheme.begin (request); + }); + context.register_uri_scheme ("res", (request) => { + try { + var stream = resources_open_stream (request.get_path (), + ResourceLookupFlags.NONE); + request.finish (stream, -1, null); + } catch (Error error) { + request.finish_error (error); + critical ("Failed to load resource %s: %s", request.get_uri (), error.message); + } + }); + return context; + } + + async void private_scheme (WebKit.URISchemeRequest request) { + string[] suggestions = { + _("No history or web cookies are being saved."), + _("Extensions are disabled."), + _("HTML5 storage, local database and application caches are disabled."), + }; + string[] notes = { + _("Referrer URLs are stripped down to the hostname."), + _("DNS prefetching is disabled."), + _("The language and timezone are not revealed to websites."), + _("Flash and other Netscape plugins cannot be listed by websites."), + }; + + try { + string description = "<ul>"; + foreach (var suggestion in suggestions) { + description += "<li>%s</li>".printf (suggestion); + } + description += "</ul>"; + description += "<b>%s</b><br>".printf (_("Midori prevents websites from tracking the user:")); + description += "<ul>"; + foreach (var note in notes) { + description += "<li>%s</li>".printf (note); + } + description += "</ul>"; + string stylesheet = (string)resources_lookup_data ("/data/about.css", + ResourceLookupFlags.NONE).get_data (); + string html = ((string)resources_lookup_data ("/data/error.html", + ResourceLookupFlags.NONE).get_data ()) + .replace ("{title}", _("Private Browsing")) + .replace ("{icon}", "user-not-tracked") + .replace ("{message}", _("Midori doesn't store any personal data:")) + .replace ("{description}", description) + .replace ("{tryagain}", "") + .replace ("{stylesheet}", stylesheet); + var stream = new MemoryInputStream.from_data (html.data, free); + request.finish (stream, html.length, "text/html"); + } catch (Error error) { + request.finish_error (error); + critical ("Failed to render %s: %s", request.get_uri (), error.message); + } + request.unref (); + } + void win_new_activated (Action action, Variant? parameter) { var browser = incognito ? new Browser.incognito (this) diff --git a/core/browser.vala b/core/browser.vala index c22b2417..6d04c4a2 100644 --- a/core/browser.vala +++ b/core/browser.vala @@ -253,7 +253,7 @@ namespace Midori { public Browser.incognito (App app) { Object (application: app, - web_context: new WebKit.WebContext.ephemeral ()); + web_context: app.ephemeral_context ()); profile.sensitive = false; remove_action ("clear-private-data"); diff --git a/core/tab.vala b/core/tab.vala index e920d864..9bdf87e0 100644 --- a/core/tab.vala +++ b/core/tab.vala @@ -186,7 +186,7 @@ namespace Midori { .replace ("{title}", title) .replace ("{message}", message) .replace ("{description}", description ?? "") - .replace ("{tryagain}", _("Try Again")) + .replace ("{tryagain}", "<span>%s</span>".printf (_("Try Again"))) .replace ("{uri}", display_uri); load_alternate_html (html, display_uri, display_uri); return true; diff --git a/data/about.css b/data/about.css index ab1d85ff..cc2144ee 100644 --- a/data/about.css +++ b/data/about.css @@ -51,6 +51,9 @@ button span { vertical-align: middle; padding: 2pt 1pt; } +button:empty { + display: none; +} .message { overflow: hidden; diff --git a/data/error.html b/data/error.html index 06026c00..89b265d5 100644 --- a/data/error.html +++ b/data/error.html @@ -10,6 +10,7 @@ --> <html> <head> + <meta charset="utf-8"> <title>{title}</title> <link ref="shortcut icon" href="stock:///{icon}" /> <style type="text/css"> @@ -26,9 +27,7 @@ <p class="message">{message}</p> <span class="description">{description}</span> <div class="action"> - <button onclick="window.location = '{uri}'"> - <span>{tryagain}</span> - </button> + <button onclick="window.location = '{uri}'">{tryagain}</button> </div> </div> </div> diff --git a/data/speed-dial.html b/data/speed-dial.html index c1e89d36..72cc7604 100644 --- a/data/speed-dial.html +++ b/data/speed-dial.html @@ -10,6 +10,7 @@ --> <html> <head> + <meta charset="utf-8"> <title>{title}</title> <link ref="shortcut icon" href="stock:///{icon}" /> <style type="text/css"> |