/* Copyright (C) 2013 André Stösel Copyright (C) 2014 Christian Dywan This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. See the file COPYING for the full license text. */ namespace About { private abstract class Page : GLib.Object { public abstract string uri { get; set; } public abstract void get_contents (Midori.View view, string uri); protected void load_html (Midori.View view, string content, string uri) { #if HAVE_WEBKIT2 view.web_view.load_html (content, uri); #else view.web_view.load_html_string (content, uri); #endif } } private class Widgets : Page { public override string uri { get; set; default = "about:widgets"; } public override void get_contents (Midori.View view, string uri) { string[] widgets = { "", "

", "

demo

", "

demo

", "

", "

", "

", "

", "", "

", "", "", "", "", "", "", "Lorem ipsum doloret sit amet…", "", "", "", "

", "" }; string content = """ %s

%s

%s
%s
%s

Popup window

"""; string[] widget_options = {"", " disabled", " class=\"fallback\""}; string[] widgets_formated = {"", "", ""}; for (int i = 0; i < widget_options.length && i < widgets_formated.length; i++) { for (int j = 0; j < widgets.length; j++) { widgets_formated[i] = widgets_formated[i] + widgets[j].printf (widget_options[i]); } } this.load_html (view, content.printf (uri, uri, widgets_formated[0], widgets_formated[1], widgets_formated[2]), uri); } } private class Version : Page { public override string uri { get; set; } private GLib.HashTable about_pages; public Version (string alias, HashTable about_pages) { this.uri = alias; this.about_pages = about_pages; } private string list_about_uris () { string links = ""; foreach (unowned string uri in about_pages.get_keys ()) links = links + "%s  ".printf (uri, uri); return "

%s

".printf (links); } public override void get_contents (Midori.View view, string uri) { string contents = """ about:version

alias a=b; echo Copy carefully #bout:version

%s

%s %s
Command line %s
Platform %s %s %s
Identification %s
%s
%s """; GLib.StringBuilder versions = new GLib.StringBuilder (); Midori.View.list_versions (versions, true); string ident; unowned string architecture; unowned string platform; unowned string sys_name = Midori.WebSettings.get_system_name (out architecture, out platform); view.settings.get ("user-agent", out ident); GLib.StringBuilder video_formats = new GLib.StringBuilder (); view.list_video_formats (video_formats, true); GLib.StringBuilder ns_plugins = new GLib.StringBuilder (); view.list_plugins (ns_plugins, true); /* TODO: list active extensions */ this.load_html (view, contents.printf ( _("Version numbers in brackets show the version used at runtime."), Midori.Paths.get_command_line_str (true), versions.str, platform, sys_name, architecture != null ? architecture : "", ident, video_formats.str, ns_plugins.str, this.list_about_uris () ), uri); } } private class Private : Page { public override string uri { get; set; default = "about:private"; } public override void get_contents (Midori.View view, string uri) { this.load_html (view, """ %s

%s

%s

  • %s
  • %s
  • %s

%s

  • %s
  • %s
  • %s
  • %s

""".printf ( _("Private Browsing"), _("Private Browsing"), _("Midori doesn't store any personal data:"), _("No history or web cookies are being saved."), _("Extensions are disabled."), _("HTML5 storage, local database and application caches are disabled."), _("Midori prevents websites from tracking the user:"), _("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.") ), uri); } } private class Paths : Page { public override string uri { get; set; default = "about:paths"; } public override void get_contents (Midori.View view, string uri) { string res_dir = Midori.Paths.get_res_filename ("about.css"); string lib_dir = Midori.Paths.get_lib_path (PACKAGE_NAME); this.load_html (view, """

%s

config: %s

res: %s

data: %s/%s

lib: %s

cache: %s

tmp: %s

""".printf ( uri, Midori.Paths.get_config_dir_for_reading (), res_dir, Midori.Paths.get_user_data_dir_for_reading (), PACKAGE_NAME, lib_dir, Midori.Paths.get_cache_dir_for_reading (), Midori.Paths.get_tmp_dir () ), uri); } } private class Dial : Page { public override string uri { get; set; default = "about:dial"; } public override void get_contents (Midori.View view, string uri) { var browser = Midori.Browser.get_for_widget (view); Midori.SpeedDial dial; browser.get ("speed-dial", out dial); if (dial == null) return; try { this.load_html (view, dial.get_html (), uri); } catch (Error error) { this.load_html (view, error.message, uri); } } } private class Geolocation : Page { public override string uri { get; set; default = "about:geolocation"; } public override void get_contents (Midori.View view, string uri) { this.load_html (view, """ """, uri); } } private class Redirects : Page { public override string uri { get; set; } private string property; public Redirects (string alias, string property) { this.uri = alias; this.property = property; } public override void get_contents (Midori.View view, string uri) { string new_uri = uri; view.settings.get (property, out new_uri); if (uri == "about:search") new_uri = Midori.URI.for_search (new_uri, ""); view.set_uri (new_uri); } } private class Manager : Midori.Extension { private GLib.HashTable? about_pages; private void register (Page page) { this.about_pages.insert (page.uri, page); } private bool about_content (Midori.View view, string uri) { unowned Page? page = this.about_pages.get (uri); if (page != null) { page.get_contents (view, uri); return true; } return false; } private void tab_added (Midori.Browser browser, Midori.View view) { view.about_content.connect (this.about_content); } private void tab_removed (Midori.Browser browser, Midori.View view) { view.about_content.disconnect (this.about_content); } private void browser_added (Midori.Browser browser) { foreach (Midori.View tab in browser.get_tabs ()) { this.tab_added (browser, tab); } browser.add_tab.connect (this.tab_added); browser.remove_tab.connect (this.tab_removed); } private void browser_removed (Midori.Browser browser) { foreach (Midori.View tab in browser.get_tabs ()) { this.tab_removed (browser, tab); } browser.add_tab.disconnect (this.tab_added); browser.remove_tab.disconnect (this.tab_removed); } public void activated (Midori.App app) { this.about_pages = new GLib.HashTable (GLib.str_hash, GLib.str_equal); register (new Widgets ()); register (new Version ("about:", about_pages)); register (new Version ("about:version", about_pages)); register (new Private ()); register (new Paths ()); register (new Geolocation ()); register (new Redirects ("about:new", "tabhome")); register (new Redirects ("about:home", "homepage")); register (new Redirects ("about:search", "location-entry-search")); register (new Dial ()); foreach (Midori.Browser browser in app.get_browsers ()) { this.browser_added (browser); } app.add_browser.connect (this.browser_added); } public void deactivated () { Midori.App app = this.get_app (); foreach (Midori.Browser browser in app.get_browsers ()) { this.browser_removed (browser); } app.add_browser.disconnect (this.browser_added); this.about_pages = null; } internal Manager () { GLib.Object (name: "About pages", description: "Internal about: handler", version: "0.1", authors: "André Stösel "); this.activate.connect (this.activated); this.deactivate.connect (this.deactivated); } } } public Midori.Extension extension_init () { return new About.Manager (); }