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 Plugin Finder Service.
16
* The Initial Developer of the Original Code is
18
* Portions created by the IBM Corporation are Copyright (C) 2004
19
* IBM Corporation. All Rights Reserved.
22
* Doron Rosenberg <doronr@us.ibm.com>
23
* Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
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 PluginXPIInstallService = {
47
startPluginInstallation: function (aPluginXPIUrlsArray,
50
this.pluginPidArray = aPluginPidArray;
52
var xpiManager = Components.classes["@mozilla.org/xpinstall/install-manager;1"]
53
.createInstance(Components.interfaces.nsIXPInstallManager);
54
xpiManager.initManagerWithHashes(aPluginXPIUrlsArray, aPluginHashes,
55
aPluginXPIUrlsArray.length, this);
58
// XPI progress listener stuff
59
onStateChange: function (aIndex, aState, aValue)
61
// get the pid to return to the wizard
62
var pid = this.pluginPidArray[aIndex];
65
if (aState == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE) {
67
var xpinstallStrings = document.getElementById("xpinstallStrings");
69
errorMsg = xpinstallStrings.getString("error" + aValue);
72
errorMsg = xpinstallStrings.getFormattedString("unknown.error", [aValue]);
77
gPluginInstaller.pluginXPIInstallationProgress(pid, aState, errorMsg);
81
onProgress: function (aIndex, aValue, aMaxValue)
83
// get the pid to return to the wizard
84
var pid = this.pluginPidArray[aIndex];
86
gPluginInstaller.pluginXPIInstallationProgressMeter(pid, aValue, aMaxValue);
93
mAptInstallerService: null,
98
install: function(aAptUrlArray,
100
aAptInstallerService) {
102
this.mAptInstallerService = aAptInstallerService;
103
this.mAptUrlArray = aAptUrlArray;
104
this.mAptPidArray = aAptPidArray;
105
this.mRunning = true;
107
// var thread = Components.classes["@mozilla.org/thread;1"]
108
// .createInstance(Components.interfaces.nsIThread);
109
// thread.init(this, 0, nsIThread.PRIORITY_NORMAL, nsIThread.SCOPE_LOCAL, nsIThread.STATE_UNJOINABLE);
115
for (var i = 0; i < this.mAptUrlArray.length; i++) {
116
var aptUrl = this.mAptUrlArray[i];
117
var aptPid = this.mAptPidArray[i];
118
this.mAptInstallerService.onNotifyStart(aptUrl, aptPid);
121
Components.classes['@mozilla.org/file/local;1']
122
.createInstance(Components.interfaces.nsILocalFile);
124
executable.initWithPath("/usr/bin/apturl");
126
if(!executable.exists() || !executable.isExecutable()) {
127
window.alert('Unexpected error!');
128
this.mAptInstallerService.onNotifyResult(aptUrl, aptPid, -1 );
133
Components.classes['@mozilla.org/process/util;1']
134
.createInstance(Components.interfaces.nsIProcess);
136
var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
138
procUtil.init(executable);
140
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
141
.getService(Components.interfaces.nsIPrefBranch);
143
var proxyType = prefBranch.getIntPref("network.proxy.type");
144
var proxyHost = prefBranch.getCharPref("network.proxy.http");
145
var proxyPort = prefBranch.getIntPref("network.proxy.http_port");
148
if(proxyType > 0 && proxyHost != null && proxyHost.length > 0)
150
httpProxy = proxyHost;
153
httpProxy = httpProxy + ":" + proxyPort;
157
var args = new Array();
158
if(httpProxy.length > 0)
160
args = new Array("--http-proxy", httpProxy, aptUrl);
162
args = new Array(aptUrl);
164
procUtil.run(true, args, args.length);
165
res = procUtil.exitValue;
167
this.mAptInstallerService.onNotifyResult(aptUrl, aptPid, res);
170
this.mAptInstallerService.onNotifyResult(null, null, -1 );
176
var PluginAPTInstallService = {
182
pluginPidArray: null,
184
startPluginInstallation: function (aPluginAptUrlsArray,
186
AptInstaller.install(aPluginAptUrlsArray, aPluginPidArray, this);
189
onNotifyStart: function (aptUrl, aptPid) {
190
gPluginInstaller.pluginXPIInstallationProgress(aptPid, 6, null);
193
onNotifyResult: function (aptUrl, aptPid, result) {
195
gPluginInstaller.pluginXPIInstallationProgress(aptPid, 7, "Apt Install Failed or Cancelled");
196
} else if (result == 0) {
197
gPluginInstaller.pluginXPIInstallationProgress(aptPid, 7, null);
199
gPluginInstaller.pluginXPIInstallationProgress(null, 8, null);