home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ubufox / chrome / ubufox.jar / content / pluginInstallerService.js < prev    next >
Encoding:
JavaScript  |  2009-04-14  |  6.4 KB  |  203 lines

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3.  *
  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/
  8.  *
  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
  12.  * License.
  13.  *
  14.  * The Original Code is Plugin Finder Service.
  15.  *
  16.  * The Initial Developer of the Original Code is
  17.  * IBM Corporation.
  18.  * Portions created by the IBM Corporation are Copyright (C) 2004
  19.  * IBM Corporation. All Rights Reserved.
  20.  *
  21.  * Contributor(s):
  22.  *   Doron Rosenberg <doronr@us.ibm.com>
  23.  *   Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
  24.  *
  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.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39. var PluginXPIInstallService = {
  40.   
  41.   init: function () 
  42.   {
  43.   },
  44.  
  45.   pluginPidArray: null,
  46.  
  47.   startPluginInstallation: function (aPluginXPIUrlsArray,
  48.                      aPluginHashes,
  49.                      aPluginPidArray) {
  50.      this.pluginPidArray = aPluginPidArray;
  51.  
  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);
  56.   },
  57.  
  58.   // XPI progress listener stuff
  59.   onStateChange: function (aIndex, aState, aValue)
  60.   {
  61.     // get the pid to return to the wizard
  62.     var pid = this.pluginPidArray[aIndex];
  63.     var errorMsg;
  64.  
  65.     if (aState == Components.interfaces.nsIXPIProgressDialog.INSTALL_DONE) {
  66.       if (aValue != 0) {
  67.         var xpinstallStrings = document.getElementById("xpinstallStrings");
  68.         try {
  69.           errorMsg = xpinstallStrings.getString("error" + aValue);
  70.         }
  71.         catch (e) {
  72.           errorMsg = xpinstallStrings.getFormattedString("unknown.error", [aValue]);
  73.         }
  74.       }
  75.     }
  76.  
  77.     gPluginInstaller.pluginXPIInstallationProgress(pid, aState, errorMsg);
  78.  
  79.   },
  80.  
  81.   onProgress: function (aIndex, aValue, aMaxValue)
  82.   {
  83.     // get the pid to return to the wizard
  84.     var pid = this.pluginPidArray[aIndex];
  85.  
  86.     gPluginInstaller.pluginXPIInstallationProgressMeter(pid, aValue, aMaxValue);
  87.   }
  88. }
  89.  
  90.  
  91. var AptInstaller = {
  92.  
  93.   mAptInstallerService: null,
  94.   mAptUrlArray: null,
  95.   mAptPidArray: null,
  96.   mRunning: false,
  97.  
  98.   install: function(aAptUrlArray,
  99.             aAptPidArray,
  100.             aAptInstallerService) {
  101.  
  102.     this.mAptInstallerService = aAptInstallerService;
  103.     this.mAptUrlArray = aAptUrlArray;
  104.     this.mAptPidArray = aAptPidArray;
  105.     this.mRunning = true;
  106.  
  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);
  110.     this.run();
  111.   },
  112.  
  113.   run: function()
  114.   {
  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);
  119.  
  120.       var executable =
  121.         Components.classes['@mozilla.org/file/local;1']
  122.        .createInstance(Components.interfaces.nsILocalFile);
  123.  
  124.       executable.initWithPath("/usr/bin/python");
  125.  
  126.       if(!executable.exists() || !executable.isExecutable()) {
  127.         window.alert('Unexpected error!');
  128.         this.mAptInstallerService.onNotifyResult(aptUrl, aptPid, -1 );
  129.         continue;
  130.       }
  131.  
  132.       var procUtil =
  133.         Components.classes['@mozilla.org/process/util;1']
  134.         .createInstance(Components.interfaces.nsIProcess);
  135.  
  136.       var nsFile = executable.QueryInterface(Components.interfaces.nsIFile);
  137.  
  138.       procUtil.init(executable);
  139.  
  140.       var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  141.                                 .getService(Components.interfaces.nsIPrefBranch);
  142.  
  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");
  146.  
  147.       var httpProxy = "";
  148.       if(proxyType > 0 && proxyHost != null && proxyHost.length > 0)
  149.       {
  150.         httpProxy = proxyHost;
  151.         if(proxyPort > 0)
  152.         {
  153.           httpProxy = httpProxy + ":" + proxyPort;
  154.         }
  155.       }
  156.  
  157.       var args = new Array();
  158.       if(httpProxy.length > 0)
  159.       {
  160.         args = new Array("/usr/bin/apturl", "--http-proxy", httpProxy, aptUrl);
  161.       } else {
  162.         args = new Array("/usr/bin/apturl", aptUrl);
  163.       }
  164.       procUtil.run(true, args, args.length);
  165.       res = procUtil.exitValue;
  166.  
  167.       this.mAptInstallerService.onNotifyResult(aptUrl, aptPid, res);
  168.     }
  169.  
  170.     this.mAptInstallerService.onNotifyResult(null, null, -1 );
  171.     mRunning = false;
  172.     return true;
  173.   }
  174. }
  175.  
  176. var PluginAPTInstallService = {
  177.   
  178.   init: function () 
  179.   {
  180.   },
  181.  
  182.   pluginPidArray: null,
  183.  
  184.   startPluginInstallation: function (aPluginAptUrlsArray,
  185.                      aPluginPidArray) {
  186.     AptInstaller.install(aPluginAptUrlsArray, aPluginPidArray, this);
  187.   },
  188.  
  189.   onNotifyStart: function (aptUrl, aptPid) {
  190.     gPluginInstaller.pluginXPIInstallationProgress(aptPid, 6, null);
  191.   },
  192.  
  193.   onNotifyResult: function (aptUrl, aptPid, result) {
  194.     if(result > 0) {
  195.       gPluginInstaller.pluginXPIInstallationProgress(aptPid, 7, "Apt Install Failed or Cancelled");
  196.     } else if (result == 0) {
  197.       gPluginInstaller.pluginXPIInstallationProgress(aptPid, 7, null);
  198.     } else {
  199.       gPluginInstaller.pluginXPIInstallationProgress(null, 8, null);
  200.     }
  201.   }
  202. }
  203.