/* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is Plugin Finder Service. * * The Initial Developer of the Original Code is * IBM Corporation. * Portions created by the IBM Corporation are Copyright (C) 2004 * IBM Corporation. All Rights Reserved. * * Contributor(s): * Doron Rosenberg * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ function nsPluginInstallerWizard(){ // create the request array this.mPluginRequestArray = new Object(); // since the array is a hash, store the length this.mPluginRequestArrayLength = 0; // create the plugin info array. // a hash indexed by plugin id so we don't install // the same plugin more than once. this.mPluginInfoArray = new Object(); this.mPluginInfoArrayLength = 0; this.mTab = null; this.mSuccessfulPluginInstallation = 0; // arguments[0] is an array that contains two items: // an array of mimetypes that are missing // a reference to the tab that needs them, so we can reload it if ("arguments" in window) { for (var item in window.arguments[0].plugins){ this.mPluginRequestArray[window.arguments[0].plugins[item].mimetype] = new nsPluginRequest(window.arguments[0].plugins[item]); this.mPluginRequestArrayLength++; } this.mTab = window.arguments[0].tab; } this.WSPluginCounter = 0; } nsPluginInstallerWizard.prototype.getPluginData = function (){ // for each mPluginRequestArray item, call the webservice this.WSPluginCounter = 0; // initiate the web service call var wsdlUrl = this.getString("pluginInstallationWebService.wsdl"); ws_start(wsdlUrl); } nsPluginInstallerWizard.prototype.proxyLoaded = function (){ var clientOS = this.getOS(); var chromeLocale = this.getChromeLocale(); for (item in this.mPluginRequestArray) { gWSProxy.getPluginInfo(this.mPluginRequestArray[item].mimetype, clientOS, chromeLocale); } } // aPluginInfo is null if the WS call failed, and pid is -1 if // no matching plugin was found. nsPluginInstallerWizard.prototype.pluginInfoReceived = function (aPluginInfo){ this.WSPluginCounter++; if (aPluginInfo && (aPluginInfo.pid != -1) ) { // hash by id this.mPluginInfoArray[aPluginInfo.pid] = new PluginInfo(aPluginInfo); this.mPluginInfoArrayLength++ } var progressMeter = document.getElementById("ws_request_progress"); if (progressMeter.getAttribute("mode") == "undetermined") progressMeter.setAttribute("mode", "determined"); progressMeter.setAttribute("value", ((this.WSPluginCounter / this.mPluginRequestArrayLength) * 100) + "%"); if (this.WSPluginCounter == this.mPluginRequestArrayLength) { // check if no plugins were found if (this.mPluginInfoArrayLength == 0) { this.advancePage("lastpage", true, false, false); } else { this.advancePage(null, true, false, true); } } else { // process more. } } nsPluginInstallerWizard.prototype.showPluginList = function (){ var myPluginList = document.getElementById("pluginList"); var hasPluginWithInstallerUI = false; // clear children for (var run = myPluginList.childNodes.length; run > 0; run--) myPluginList.removeChild(myPluginList.childNodes.item(run)); for (pluginInfoItem in this.mPluginInfoArray){ // [plugin image] [Plugin_Name Plugin_Version] var pluginInfo = this.mPluginInfoArray[pluginInfoItem]; var myRow = document.createElement("row"); // create the checkbox var myCheckbox = document.createElement("checkbox"); myCheckbox.setAttribute("checked", "true"); myCheckbox.setAttribute("oncommand", "gPluginInstaller.toggleInstallPlugin('" + pluginInfo.pid + "', this)"); myCheckbox.setAttribute("label", pluginInfo.name + " " + (pluginInfo.version + "")); myCheckbox.setAttribute("src", pluginInfo.IconUrl); myRow.appendChild(myCheckbox); myPluginList.appendChild(myRow); if (pluginInfo.InstallerShowsUI) hasPluginWithInstallerUI = true; } if (hasPluginWithInstallerUI) document.getElementById("installerUI").hidden = false; this.canAdvance(true); this.canRewind(false); } nsPluginInstallerWizard.prototype.toggleInstallPlugin = function (aPid, aCheckbox) { this.mPluginInfoArray[aPid].toBeInstalled = aCheckbox.checked; // if no plugins are checked, don't allow to advance var pluginsToInstallNum = 0; for (pluginInfoItem in this.mPluginInfoArray){ if (this.mPluginInfoArray[pluginInfoItem].toBeInstalled) pluginsToInstallNum++; } if (pluginsToInstallNum > 0) this.canAdvance(true); else this.canAdvance(false); } nsPluginInstallerWizard.prototype.canAdvance = function (aBool){ document.getElementById("plugin-installer-wizard").canAdvance = aBool; } nsPluginInstallerWizard.prototype.canRewind = function (aBool){ document.getElementById("plugin-installer-wizard").canRewind = aBool; } nsPluginInstallerWizard.prototype.canCancel = function (aBool){ document.documentElement.getButton("cancel").disabled = !aBool; } nsPluginInstallerWizard.prototype.advancePage = function (aPageId, aCanAdvance, aCanRewind, aCanCancel){ this.canAdvance(true); document.getElementById("plugin-installer-wizard").advance(aPageId); this.canAdvance(aCanAdvance); this.canRewind(aCanRewind); this.canCancel(aCanCancel); } nsPluginInstallerWizard.prototype.startPluginInstallation = function (){ this.canAdvance(false); this.canRewind(false); // since the user can choose what plugins to install, we need to store // which ones were choosen, as nsIXPInstallManager returns an index and not the // mimetype. So store the pids. var pluginURLArray = new Array(); var pluginPidArray = new Array(); for (pluginInfoItem in this.mPluginInfoArray){ if (this.mPluginInfoArray[pluginInfoItem].toBeInstalled) { pluginURLArray.push(this.mPluginInfoArray[pluginInfoItem].XPILocation); pluginPidArray.push(this.mPluginInfoArray[pluginInfoItem].pid); } } if (pluginURLArray.length > 0) PluginInstallService.startPluginInsallation(pluginURLArray, pluginPidArray); } /* 0 starting download 1 download finished 2 starting installation 3 finished installation 4 all done */ nsPluginInstallerWizard.prototype.pluginInstallationProgress = function (aPid, aProgress, aError){ var statMsg = null; var pluginInfo = gPluginInstaller.mPluginInfoArray[aPid]; switch (aProgress) { case 0: statMsg = this.getFormattedString("pluginInstallation.download.start", [pluginInfo.name]); break; case 1: statMsg = this.getFormattedString("pluginInstallation.download.finish", [pluginInfo.name]); break; case 2: statMsg = this.getFormattedString("pluginInstallation.install.start", [pluginInfo.name]); break; case 3: if (aError) { statMsg = this.getFormattedString("pluginInstallation.install.error", [pluginInfo.name, aError]); pluginInfo.error = aError; } else { statMsg = this.getFormattedString("pluginInstallation.install.finish", [pluginInfo.name]); pluginInfo.error = null; } break; case 4: statMsg = this.getString("pluginInstallation.complete"); break; } if (statMsg) document.getElementById("plugin_install_progress_message").value = statMsg; if (aProgress == 4) { this.advancePage(null, true, false, false); } } nsPluginInstallerWizard.prototype.pluginInstallationProgressMeter = function (aPid, aValue, aMaxValue){ var progressElm = document.getElementById("plugin_install_progress"); if (progressElm.getAttribute("mode") == "undetermined") progressElm.setAttribute("mode", "determined"); progressElm.setAttribute("value", Math.ceil((aValue / aMaxValue) * 100) + "%") } nsPluginInstallerWizard.prototype.showPluginResults = function (){ var myRows = document.getElementById("pluginResultList"); // clear children for (var run = myRows.childNodes.length; run--; run > 0) myRows.removeChild(myRows.childNodes.item(run)); for (pluginInfoItem in this.mPluginInfoArray){ // [plugin image] [Plugin_Name Plugin_Version] [Success/Failed] [Manual Install (if Failed)] var myPluginItem = this.mPluginInfoArray[pluginInfoItem]; if (myPluginItem.toBeInstalled) { var myRow = document.createElement("row"); myRow.setAttribute("align", "center"); // create the image var myImage = document.createElement("image"); myImage.setAttribute("src", myPluginItem.IconUrl); myImage.setAttribute("height", "16px"); myImage.setAttribute("width", "16px"); myRow.appendChild(myImage) // create the labels var myLabel = document.createElement("label"); myLabel.setAttribute("value", myPluginItem.name + " " + (myPluginItem.version + "")); myRow.appendChild(myLabel) myLabel = document.createElement("label"); var statusMsg; if (myPluginItem.error){ statusMsg = this.getString("pluginInstallationSummary.failed"); myLabel.setAttribute("tooltiptext", myPluginItem.error); } else { this.mSuccessfulPluginInstallation++; statusMsg = this.getString("pluginInstallationSummary.success"); } myLabel.setAttribute("value", statusMsg); myRow.appendChild(myLabel) // manual url - either returned from the webservice or the pluginspage attribute if (myPluginItem.error && (myPluginItem.manualInstallationURL || this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage)){ var myButton = document.createElement("button"); var manualInstallLabel = this.getString("pluginInstallationSummary.manualInstall.label"); var manualInstallTooltip = this.getString("pluginInstallationSummary.manualInstall.tooltip"); myButton.setAttribute("label", manualInstallLabel); myButton.setAttribute("tooltiptext", manualInstallTooltip); var manualUrl = myPluginItem.manualInstallationURL ? myPluginItem.manualInstallationURL : this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage; myButton.setAttribute("oncommand","gPluginInstaller.doManualPluginInstall('" + manualUrl + "')"); myRow.appendChild(myButton); } myRows.appendChild(myRow); } } // no plugins were found, so change the description of the final page. if (this.mPluginInfoArrayLength == 0) { var noPluginsFound = this.getString("pluginInstallation.noPluginsFound"); document.getElementById("pluginSummaryDescription").setAttribute("value", noPluginsFound); } // clear the tab's plugin list this.mTab.missingPlugins = null; this.canAdvance(true); this.canRewind(false); this.canCancel(false); } nsPluginInstallerWizard.prototype.doManualPluginInstall = function (aUrl){ window.open(aUrl); } nsPluginInstallerWizard.prototype.getString = function (aName){ return document.getElementById("pluginWizardString").getString(aName); } nsPluginInstallerWizard.prototype.getFormattedString = function (aName, aArray){ return document.getElementById("pluginWizardString").getFormattedString(aName, aArray); } nsPluginInstallerWizard.prototype.getOS = function (){ var httpService = Components.classes["@mozilla.org/network/protocol;1?name=http"] .getService(Components.interfaces.nsIHttpProtocolHandler); return httpService.oscpu; } nsPluginInstallerWizard.prototype.getChromeLocale = function (){ var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"] .getService(Components.interfaces.nsIXULChromeRegistry); return chromeReg.getSelectedLocale("global"); } function nsPluginRequest(aPlugRequest){ this.mimetype = encodeURI(aPlugRequest.mimetype); this.pluginsPage = aPlugRequest.pluginsPage; } function PluginInfo(aResult) { this.name = aResult.name; this.pid = aResult.pid; this.version = aResult.version; this.IconUrl = aResult.IconUrl; this.XPILocation = aResult.XPILocation; this.InstallerShowsUI = aResult.InstallerShowsUI; this.manualInstallationURL = aResult.manualInstallationURL; this.requestedMimetype = aResult.requestedMimetype; this.error = null; this.toBeInstalled = true; } var gPluginInstaller; function wizardInit(){ gPluginInstaller = new nsPluginInstallerWizard(); gPluginInstaller.canAdvance(false); gPluginInstaller.getPluginData(); } function wizardFinish(){ // don't refresh if no plugins were found or installed if ((gPluginInstaller.mSuccessfulPluginInstallation > 0) && (gPluginInstaller.mPluginInfoArray.length != 0) && gPluginInstaller.mTab) { window.opener.getBrowser().reloadTab(gPluginInstaller.mTab); } return true; }