5538
by André Stösel
New extension to manage Netscape plugins like extensions |
1 |
/*
|
2 |
Copyright (C) 2012 André Stösel <andre@stoesel.de>
|
|
3 |
||
4 |
This library is free software; you can redistribute it and/or
|
|
5 |
modify it under the terms of the GNU Lesser General Public
|
|
6 |
License as published by the Free Software Foundation; either
|
|
7 |
version 2.1 of the License, or (at your option) any later version.
|
|
8 |
||
9 |
See the file COPYING for the full license text.
|
|
10 |
*/
|
|
11 |
||
12 |
namespace NSPlugins { |
|
13 |
private int active_plugins = 0; |
|
14 |
||
15 |
private class Extension : Midori.Extension { |
|
16 |
protected WebKit.WebPlugin plugin; |
|
17 |
||
18 |
void activated (Midori.App app) { |
|
19 |
active_plugins += 1; |
|
20 |
this.plugin.set_enabled (true); |
|
21 |
app.settings.enable_plugins = active_plugins > 0; |
|
22 |
}
|
|
23 |
||
24 |
void deactivated () { |
|
25 |
Midori.App app = this.get_app (); |
|
26 |
active_plugins -= 1; |
|
27 |
this.plugin.set_enabled (false); |
|
28 |
app.settings.enable_plugins = active_plugins > 0; |
|
29 |
}
|
|
30 |
||
31 |
internal Extension (WebKit.WebPlugin plugin) { |
|
32 |
string desc = plugin.get_description (); |
|
33 |
try { |
|
34 |
var regex = new Regex ("<a.+href.+>(.+)</a>"); |
|
35 |
desc = regex.replace (desc, -1, 0, "<u>\\1</u>"); |
|
5759
by Paweł Forysiuk
Handle <br> in NS plugin descriptions as \n |
36 |
desc = desc.replace ("<br>", "\n"); |
5538
by André Stösel
New extension to manage Netscape plugins like extensions |
37 |
}
|
38 |
catch (Error error) { } |
|
39 |
GLib.Object (stock_id: Midori.Stock.PLUGINS, |
|
40 |
name: plugin.get_name (), |
|
41 |
description: desc, |
|
42 |
use_markup: true, |
|
43 |
key: GLib.Path.get_basename (plugin.get_path ()), |
|
5560
by Christian Dywan
Put 'Netscape plugins' in version string of plugins |
44 |
version: "(%s)".printf ("Netscape plugins"), |
5538
by André Stösel
New extension to manage Netscape plugins like extensions |
45 |
authors: ""); |
46 |
||
47 |
this.plugin = plugin; |
|
48 |
this.plugin.set_enabled (false); |
|
49 |
||
50 |
this.activate.connect (activated); |
|
51 |
this.deactivate.connect (deactivated); |
|
52 |
}
|
|
53 |
}
|
|
54 |
}
|
|
55 |
||
56 |
public Katze.Array? extension_init () { |
|
5986
by Christian Dywan
Have NS plugin manager honor has_plugin_support |
57 |
if (!Midori.WebSettings.has_plugin_support ()) |
58 |
return null; |
|
59 |
||
5538
by André Stösel
New extension to manage Netscape plugins like extensions |
60 |
var extensions = new Katze.Array( typeof (Midori.Extension)); |
61 |
WebKit.WebPluginDatabase pdb = WebKit.get_web_plugin_database (); |
|
62 |
SList<WebKit.WebPlugin> plugins = pdb.get_plugins (); |
|
63 |
||
64 |
foreach (WebKit.WebPlugin plugin in plugins) { |
|
6015
by Christian Dywan
Implement plugin listing for WebKit2 and abstract skip_plugin |
65 |
if (Midori.WebSettings.skip_plugin (plugin.get_path ())) |
5769
by Paweł Forysiuk
Omit wrapped Netscape plugins from extension list |
66 |
continue; |
5538
by André Stösel
New extension to manage Netscape plugins like extensions |
67 |
extensions.add_item (new NSPlugins.Extension (plugin)); |
68 |
}
|
|
69 |
return extensions; |
|
70 |
}
|
|
71 |