1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is ubufox.
16
* The Initial Developer of the Original Code is
18
* Portions created by the Initial Developer are Copyright (C) 2008
19
* the Initial Developer. All Rights Reserved.
22
* Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
23
* Arzhel Younsi <xionox@gmail.com>
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the MPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the MPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
40
var pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
42
const APP_ICON_ATTR_NAME = "appHandlerIcon";
44
window.addEventListener("load", showContentList, false);
46
var gBrowser = document.getElementById("content");
47
var usedMimeTypes = new Array();
48
var allHandledMimeTypes = new Array();
49
var filteredMimeTypes = null;
51
for (var item in window.arguments[0].plugins){
52
usedMimeTypes.push(window.arguments[0].plugins[item].mimetype);
55
let store = new Object();
56
for (let i = 0; i < navigator.mimeTypes.length; i++) {
57
if(!navigator.mimeTypes.item(i).enabledPlugin)
59
let mtype = navigator.mimeTypes.item(i).type;
61
allHandledMimeTypes.push(mtype);
65
var filehintNameMap = null;
68
function parseFilehintNameText (text)
71
var array = new Array();
75
next = text.indexOf("\n", start);
78
array.push(text.substring(start, next));
80
next = text.indexOf("\n", start);
82
array.push(text.substring(start));
90
for (let a = 0; a < array.length; a++) {
92
separator = line.indexOf(":");
93
left = line.substring(0, separator);
94
right = line.substring(separator+2);
95
if (left == "filehint")
97
else if(left == "name") {
104
function getFilehintNameMap () {
106
return filehintNameMap;
108
var url = "http://localhost/~asac/cgi-bin/plugin-finder.py?op=filehint2name&distributionID=9.04";
110
url = prefBranch.getCharPref("pfs.filehint.url");
113
var distID = prefBranch.getCharPref("extensions.ubufox@ubuntu.com.release");
114
url.replace(/%DIST_ID%/g, distID);
116
var req = new XMLHttpRequest();
117
req.open('GET', url, true); /* 3rd argument, true, marks this as async */
118
req.onreadystatechange = function (aEvt) {
119
if (req.readyState == 4) {
120
if(req.status == 200) {
121
filehintNameMap = parseFilehintNameText (req.responseText);
130
if (!filehintNameMap)
131
getFilehintNameMap();
133
function showContentList(){
135
if(!filteredMimeTypes) {
136
let showSelectedRadio = document.getElementById ("radioShowSelectedPlugins");
137
let showAllRadio = document.getElementById ("radioShowAllPlugins");
138
let containingRadio = document.getElementById ("radioShowParent");
139
if(usedMimeTypes.length <= 0)
140
filteredMimeTypes = allHandledMimeTypes;
142
filteredMimeTypes = usedMimeTypes;
144
// select the right initial choice
145
containingRadio.selectedItem = usedMimeTypes.length <= 0 ? showAllRadio : showSelectedRadio;
147
var _list = document.getElementById("pluginsList");
148
while (_list.hasChildNodes())
149
_list.removeChild(_list.lastChild);
150
for each (let mimeType in filteredMimeTypes) {
152
let item = document.createElement("richlistitem");
153
item.setAttribute("type", mimeType);
154
contentName = getDescByMime(mimeType);
155
item.setAttribute("typeDescription",contentName);
156
item.setAttribute("actionDescription", describePreferredAction(mimeType));
157
item.setAttribute(APP_ICON_ATTR_NAME, "plugin");
158
item.setAttribute("typeIcon", "moz-icon://goat?size=" + 16 + "&contentType=" + mimeType);
159
_list.appendChild(item);
164
function describePreferredAction(mimeType){
165
var filehintNameMap = getFilehintNameMap();
167
var preferredFileName = null;
169
preferredFileName = prefBranch.getCharPref("modules.plugins.mimetype." + mimeType);
172
var perfectMatchPlugin = null;
174
if (preferredFileName) {
175
for (let i =0; i < navigator.plugins.length; i++) {
176
var plugIn = navigator.plugins.item(i);
177
if(preferredFileName == plugIn.filename) {
178
perfectMatchPlugin = plugIn;
184
var L = navigator.mimeTypes.length;
185
for(var i=0; i<L && perfectMatchPlugin == null; i++) {
186
if (navigator.mimeTypes.item(i).type == mimeType)
188
perfectMatchPlugin = navigator.mimeTypes.item(i).enabledPlugin;
192
if(!perfectMatchPlugin)
195
for (betterNameCarrierKey in filehintNameMap) {
196
if (perfectMatchPlugin.filename && perfectMatchPlugin.filename.indexOf(betterNameCarrierKey) > -1) {
197
return filehintNameMap[betterNameCarrierKey];
201
if(perfectMatchPlugin.name.indexOf("Shockwave Flash") >= 0 ||
202
perfectMatchPlugin.name.indexOf("Windows Media Player") >= 0)
203
return perfectMatchPlugin.description;
204
return perfectMatchPlugin.name;
207
function getDescByMime(aMimeType){
208
for(let i = 0; i < navigator.mimeTypes.length; i++) {
209
let mimeType = navigator.mimeTypes[i];
210
if (mimeType.type == aMimeType && mimeType.description != null && mimeType.description.length > 0)
211
return mimeType.description + " (" + aMimeType + ")";
216
function onSelectionChanged() {
217
var _list = document.getElementById("pluginsList");
218
if (_list.selectedItem)
219
_list.setAttribute("lastSelectedType", _list.selectedItem.getAttribute("type"));
222
function onSelectUsedPlugins (e) {
223
filteredMimeTypes = usedMimeTypes;
227
function onSelectAllPlugins (e) {
228
filteredMimeTypes = allHandledMimeTypes;
232
var gApplicationsPane = {
234
rebuildActionsMenu: function() {
235
var filehintNameMap = getFilehintNameMap();
236
var _list = document.getElementById("pluginsList");
237
var typeItem = _list.selectedItem;
238
var menu = document.getAnonymousElementByAttribute(typeItem, "class", "actionsMenu");
239
var menuPopup = menu.menupopup;
240
var pluginArrayLength = navigator.plugins.length;
242
while (menuPopup.hasChildNodes())
243
menuPopup.removeChild(menuPopup.lastChild);
246
for each (let mimeType in filteredMimeTypes) {
247
for (var i = 0; i < pluginArrayLength; i++) {
248
var plugin = navigator.plugins[i];
249
for (var j = 0; j < plugin.length; j++) {
250
if(plugin.item(j).type == mimeType && typeItem.type == mimeType){
251
menuItem = document.createElement("menuitem");
252
var pluginName = plugin.name;
253
if(pluginName.indexOf("Shockwave Flash") >= 0)
254
pluginName = plugin.description;
255
for (betterNameCarrierKey in filehintNameMap) {
256
if (plugin.filename && plugin.filename.indexOf(betterNameCarrierKey) > -1) {
257
pluginName = filehintNameMap[betterNameCarrierKey];
260
menuItem.setAttribute("label", pluginName);
261
menuItem.setAttribute("id", pluginName);
262
menuItem.ubufoxPluginFilename = plugin.filename;
263
menuItem.setAttribute(APP_ICON_ATTR_NAME, "plugin");
264
menuPopup.appendChild(menuItem);
269
var strbundle = document.getElementById("ubufox-alt-strings")
270
var search = strbundle.getString("ubufox.altplugins.search");
272
menuItem = document.createElement("menuitem");
273
menuItem.setAttribute("id", "install-plugin-handler");
274
menuItem.setAttribute("label", search);
275
menuItem.type = typeItem.type;
276
menuPopup.appendChild(menuItem);
279
onSelectAction: function(aActionItem) {
280
var _list = document.getElementById("pluginsList");
281
var typeItem = _list.selectedItem;
283
var id = aActionItem.getAttribute ("id");
284
if (id == "install-plugin-handler") {
285
var pluginInfoArray = {};
286
var fakePluginInfo = new Object();
287
fakePluginInfo.mimetype = typeItem.type;
288
fakePluginInfo.pluginsPage = "";
289
pluginInfoArray[typeItem.type] = fakePluginInfo;
291
window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul",
292
"PFSWindow", "chrome,centerscreen,resizable=yes,width=600,height=600",
293
{plugins: pluginInfoArray, browser: gBrowser});
295
pluginHost.reloadPlugins(true);
299
prefBranch.setCharPref("modules.plugins.mimetype." + typeItem.type, aActionItem.ubufoxPluginFilename);
300
pluginHost.reloadPlugins(true);