/toolkit/mozapps/plugins/content/pluginInstallerWizard.js

http://github.com/zpao/v8monkey · JavaScript · 697 lines · 462 code · 134 blank · 101 comment · 90 complexity · e067a09993505d957a480c69ccd756ee MD5 · raw file

  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. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. function nsPluginInstallerWizard(){
  38. // create the request array
  39. this.mPluginRequestArray = new Object();
  40. // since the array is a hash, store the length
  41. this.mPluginRequestArrayLength = 0;
  42. // create the plugin info array.
  43. // a hash indexed by plugin id so we don't install
  44. // the same plugin more than once.
  45. this.mPluginInfoArray = new Object();
  46. this.mPluginInfoArrayLength = 0;
  47. // holds plugins we couldn't find
  48. this.mPluginNotFoundArray = new Object();
  49. this.mPluginNotFoundArrayLength = 0;
  50. // array holding pids of plugins that require a license
  51. this.mPluginLicenseArray = new Array();
  52. // how many plugins are to be installed
  53. this.pluginsToInstallNum = 0;
  54. this.mBrowser = null;
  55. this.mSuccessfullPluginInstallation = 0;
  56. this.mNeedsRestart = false;
  57. // arguments[0] is an array that contains two items:
  58. // an array of mimetypes that are missing
  59. // a reference to the browser that needs them,
  60. // so we can notify which browser can be reloaded.
  61. if ("arguments" in window) {
  62. for (var item in window.arguments[0].plugins){
  63. this.mPluginRequestArray[window.arguments[0].plugins[item].mimetype] =
  64. new nsPluginRequest(window.arguments[0].plugins[item]);
  65. this.mPluginRequestArrayLength++;
  66. }
  67. this.mBrowser = window.arguments[0].browser;
  68. }
  69. this.WSPluginCounter = 0;
  70. this.licenseAcceptCounter = 0;
  71. this.prefBranch = null;
  72. }
  73. nsPluginInstallerWizard.prototype.getPluginData = function (){
  74. // for each mPluginRequestArray item, call the datasource
  75. this.WSPluginCounter = 0;
  76. // initiate the datasource call
  77. var rdfUpdater = new nsRDFItemUpdater(this.getOS(), this.getChromeLocale());
  78. for (var item in this.mPluginRequestArray) {
  79. rdfUpdater.checkForPlugin(this.mPluginRequestArray[item]);
  80. }
  81. }
  82. // aPluginInfo is null if the datasource call failed, and pid is -1 if
  83. // no matching plugin was found.
  84. nsPluginInstallerWizard.prototype.pluginInfoReceived = function (aPluginRequestItem, aPluginInfo){
  85. this.WSPluginCounter++;
  86. if (aPluginInfo && (aPluginInfo.pid != -1) ) {
  87. // hash by id
  88. this.mPluginInfoArray[aPluginInfo.pid] = new PluginInfo(aPluginInfo);
  89. this.mPluginInfoArrayLength++;
  90. } else {
  91. this.mPluginNotFoundArray[aPluginRequestItem.mimetype] = aPluginRequestItem;
  92. this.mPluginNotFoundArrayLength++;
  93. }
  94. var progressMeter = document.getElementById("ws_request_progress");
  95. if (progressMeter.getAttribute("mode") == "undetermined")
  96. progressMeter.setAttribute("mode", "determined");
  97. progressMeter.setAttribute("value",
  98. ((this.WSPluginCounter / this.mPluginRequestArrayLength) * 100) + "%");
  99. if (this.WSPluginCounter == this.mPluginRequestArrayLength) {
  100. // check if no plugins were found
  101. if (this.mPluginInfoArrayLength == 0) {
  102. this.advancePage("lastpage");
  103. } else {
  104. this.advancePage(null);
  105. }
  106. } else {
  107. // process more.
  108. }
  109. }
  110. nsPluginInstallerWizard.prototype.showPluginList = function (){
  111. var myPluginList = document.getElementById("pluginList");
  112. var hasPluginWithInstallerUI = false;
  113. // clear children
  114. for (var run = myPluginList.childNodes.length; run > 0; run--)
  115. myPluginList.removeChild(myPluginList.childNodes.item(run));
  116. this.pluginsToInstallNum = 0;
  117. for (var pluginInfoItem in this.mPluginInfoArray){
  118. // [plugin image] [Plugin_Name Plugin_Version]
  119. var pluginInfo = this.mPluginInfoArray[pluginInfoItem];
  120. // create the checkbox
  121. var myCheckbox = document.createElement("checkbox");
  122. myCheckbox.setAttribute("checked", "true");
  123. myCheckbox.setAttribute("oncommand", "gPluginInstaller.toggleInstallPlugin('" + pluginInfo.pid + "', this)");
  124. // XXXlocalize (nit)
  125. myCheckbox.setAttribute("label", pluginInfo.name + " " + (pluginInfo.version ? pluginInfo.version : ""));
  126. myCheckbox.setAttribute("src", pluginInfo.IconUrl);
  127. myPluginList.appendChild(myCheckbox);
  128. if (pluginInfo.InstallerShowsUI == "true")
  129. hasPluginWithInstallerUI = true;
  130. // keep a running count of plugins the user wants to install
  131. this.pluginsToInstallNum++;
  132. }
  133. if (hasPluginWithInstallerUI)
  134. document.getElementById("installerUI").hidden = false;
  135. this.canAdvance(true);
  136. this.canRewind(false);
  137. }
  138. nsPluginInstallerWizard.prototype.toggleInstallPlugin = function (aPid, aCheckbox) {
  139. this.mPluginInfoArray[aPid].toBeInstalled = aCheckbox.checked;
  140. // if no plugins are checked, don't allow to advance
  141. this.pluginsToInstallNum = 0;
  142. for (var pluginInfoItem in this.mPluginInfoArray){
  143. if (this.mPluginInfoArray[pluginInfoItem].toBeInstalled)
  144. this.pluginsToInstallNum++;
  145. }
  146. if (this.pluginsToInstallNum > 0)
  147. this.canAdvance(true);
  148. else
  149. this.canAdvance(false);
  150. }
  151. nsPluginInstallerWizard.prototype.canAdvance = function (aBool){
  152. document.getElementById("plugin-installer-wizard").canAdvance = aBool;
  153. }
  154. nsPluginInstallerWizard.prototype.canRewind = function (aBool){
  155. document.getElementById("plugin-installer-wizard").canRewind = aBool;
  156. }
  157. nsPluginInstallerWizard.prototype.canCancel = function (aBool){
  158. document.documentElement.getButton("cancel").disabled = !aBool;
  159. }
  160. nsPluginInstallerWizard.prototype.showLicenses = function (){
  161. this.canAdvance(false);
  162. this.canRewind(false);
  163. // only add if a license is provided and the plugin was selected to
  164. // be installed
  165. for (var pluginInfoItem in this.mPluginInfoArray){
  166. var myPluginInfoItem = this.mPluginInfoArray[pluginInfoItem];
  167. if (myPluginInfoItem.toBeInstalled && myPluginInfoItem.licenseURL && (myPluginInfoItem.licenseURL != ""))
  168. this.mPluginLicenseArray.push(myPluginInfoItem.pid);
  169. }
  170. if (this.mPluginLicenseArray.length == 0) {
  171. // no plugins require licenses
  172. this.advancePage(null);
  173. } else {
  174. this.licenseAcceptCounter = 0;
  175. // add a nsIWebProgress listener to the license iframe.
  176. var docShell = document.getElementById("licenseIFrame").docShell;
  177. var iiReq = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
  178. var webProgress = iiReq.getInterface(Components.interfaces.nsIWebProgress);
  179. webProgress.addProgressListener(gPluginInstaller.progressListener,
  180. Components.interfaces.nsIWebProgress.NOTIFY_ALL);
  181. this.showLicense();
  182. }
  183. }
  184. nsPluginInstallerWizard.prototype.enableNext = function (){
  185. // if only one plugin exists, don't enable the next button until
  186. // the license is accepted
  187. if (gPluginInstaller.pluginsToInstallNum > 1)
  188. gPluginInstaller.canAdvance(true);
  189. document.getElementById("licenseRadioGroup1").disabled = false;
  190. document.getElementById("licenseRadioGroup2").disabled = false;
  191. }
  192. const nsIWebProgressListener = Components.interfaces.nsIWebProgressListener;
  193. nsPluginInstallerWizard.prototype.progressListener = {
  194. onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
  195. {
  196. if ((aStateFlags & nsIWebProgressListener.STATE_STOP) &&
  197. (aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK)) {
  198. // iframe loaded
  199. gPluginInstaller.enableNext();
  200. }
  201. },
  202. onProgressChange : function(aWebProgress, aRequest, aCurSelfProgress,
  203. aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress)
  204. {},
  205. onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
  206. {},
  207. QueryInterface : function(aIID)
  208. {
  209. if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
  210. aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
  211. aIID.equals(Components.interfaces.nsISupports))
  212. return this;
  213. throw Components.results.NS_NOINTERFACE;
  214. }
  215. }
  216. nsPluginInstallerWizard.prototype.showLicense = function (){
  217. var pluginInfo = this.mPluginInfoArray[this.mPluginLicenseArray[this.licenseAcceptCounter]];
  218. this.canAdvance(false);
  219. var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
  220. document.getElementById("licenseIFrame").webNavigation.loadURI(pluginInfo.licenseURL, loadFlags, null, null, null);
  221. document.getElementById("pluginLicenseLabel").firstChild.nodeValue =
  222. this.getFormattedString("pluginLicenseAgreement.label", [pluginInfo.name]);
  223. document.getElementById("licenseRadioGroup1").disabled = true;
  224. document.getElementById("licenseRadioGroup2").disabled = true;
  225. document.getElementById("licenseRadioGroup").selectedIndex =
  226. pluginInfo.licenseAccepted ? 0 : 1;
  227. }
  228. nsPluginInstallerWizard.prototype.showNextLicense = function (){
  229. var rv = true;
  230. if (this.mPluginLicenseArray.length > 0) {
  231. this.storeLicenseRadioGroup();
  232. this.licenseAcceptCounter++;
  233. if (this.licenseAcceptCounter < this.mPluginLicenseArray.length) {
  234. this.showLicense();
  235. rv = false;
  236. this.canRewind(true);
  237. }
  238. }
  239. return rv;
  240. }
  241. nsPluginInstallerWizard.prototype.showPreviousLicense = function (){
  242. this.storeLicenseRadioGroup();
  243. this.licenseAcceptCounter--;
  244. if (this.licenseAcceptCounter > 0)
  245. this.canRewind(true);
  246. else
  247. this.canRewind(false);
  248. this.showLicense();
  249. // don't allow to return from the license screens
  250. return false;
  251. }
  252. nsPluginInstallerWizard.prototype.storeLicenseRadioGroup = function (){
  253. var pluginInfo = this.mPluginInfoArray[this.mPluginLicenseArray[this.licenseAcceptCounter]];
  254. pluginInfo.licenseAccepted = !document.getElementById("licenseRadioGroup").selectedIndex;
  255. }
  256. nsPluginInstallerWizard.prototype.licenseRadioGroupChange = function(aAccepted) {
  257. // only if one plugin is to be installed should selection change the next button
  258. if (this.pluginsToInstallNum == 1)
  259. this.canAdvance(aAccepted);
  260. }
  261. nsPluginInstallerWizard.prototype.advancePage = function (aPageId){
  262. this.canAdvance(true);
  263. document.getElementById("plugin-installer-wizard").advance(aPageId);
  264. }
  265. nsPluginInstallerWizard.prototype.startPluginInstallation = function (){
  266. this.canAdvance(false);
  267. this.canRewind(false);
  268. var installerPlugins = [];
  269. var xpiPlugins = [];
  270. for (var pluginInfoItem in this.mPluginInfoArray){
  271. var pluginItem = this.mPluginInfoArray[pluginInfoItem];
  272. if (pluginItem.toBeInstalled && pluginItem.licenseAccepted) {
  273. if (pluginItem.InstallerLocation)
  274. installerPlugins.push(pluginItem);
  275. else if (pluginItem.XPILocation)
  276. xpiPlugins.push(pluginItem);
  277. }
  278. }
  279. if (installerPlugins.length > 0 || xpiPlugins.length > 0)
  280. PluginInstallService.startPluginInstallation(installerPlugins,
  281. xpiPlugins);
  282. else
  283. this.advancePage(null);
  284. }
  285. /*
  286. 0 starting download
  287. 1 download finished
  288. 2 starting installation
  289. 3 finished installation
  290. 4 all done
  291. */
  292. nsPluginInstallerWizard.prototype.pluginInstallationProgress = function (aPid, aProgress, aError) {
  293. var statMsg = null;
  294. var pluginInfo = gPluginInstaller.mPluginInfoArray[aPid];
  295. switch (aProgress) {
  296. case 0:
  297. statMsg = this.getFormattedString("pluginInstallation.download.start", [pluginInfo.name]);
  298. break;
  299. case 1:
  300. statMsg = this.getFormattedString("pluginInstallation.download.finish", [pluginInfo.name]);
  301. break;
  302. case 2:
  303. statMsg = this.getFormattedString("pluginInstallation.install.start", [pluginInfo.name]);
  304. var progressElm = document.getElementById("plugin_install_progress");
  305. progressElm.setAttribute("mode", "undetermined");
  306. break;
  307. case 3:
  308. if (aError) {
  309. statMsg = this.getFormattedString("pluginInstallation.install.error", [pluginInfo.name, aError]);
  310. pluginInfo.error = aError;
  311. } else {
  312. statMsg = this.getFormattedString("pluginInstallation.install.finish", [pluginInfo.name]);
  313. pluginInfo.error = null;
  314. }
  315. break;
  316. case 4:
  317. statMsg = this.getString("pluginInstallation.complete");
  318. break;
  319. }
  320. if (statMsg)
  321. document.getElementById("plugin_install_progress_message").value = statMsg;
  322. if (aProgress == 4) {
  323. this.advancePage(null);
  324. }
  325. }
  326. nsPluginInstallerWizard.prototype.pluginInstallationProgressMeter = function (aPid, aValue, aMaxValue){
  327. var progressElm = document.getElementById("plugin_install_progress");
  328. if (progressElm.getAttribute("mode") == "undetermined")
  329. progressElm.setAttribute("mode", "determined");
  330. progressElm.setAttribute("value", Math.ceil((aValue / aMaxValue) * 100) + "%")
  331. }
  332. nsPluginInstallerWizard.prototype.addPluginResultRow = function (aImgSrc, aName, aNameTooltip, aStatus, aStatusTooltip, aManualUrl){
  333. var myRows = document.getElementById("pluginResultList");
  334. var myRow = document.createElement("row");
  335. myRow.setAttribute("align", "center");
  336. // create the image
  337. var myImage = document.createElement("image");
  338. myImage.setAttribute("src", aImgSrc);
  339. myImage.setAttribute("height", "16px");
  340. myImage.setAttribute("width", "16px");
  341. myRow.appendChild(myImage)
  342. // create the labels
  343. var myLabel = document.createElement("label");
  344. myLabel.setAttribute("value", aName);
  345. if (aNameTooltip)
  346. myLabel.setAttribute("tooltiptext", aNameTooltip);
  347. myRow.appendChild(myLabel);
  348. if (aStatus) {
  349. myLabel = document.createElement("label");
  350. myLabel.setAttribute("value", aStatus);
  351. myRow.appendChild(myLabel);
  352. }
  353. // manual install
  354. if (aManualUrl) {
  355. var myButton = document.createElement("button");
  356. var manualInstallLabel = this.getString("pluginInstallationSummary.manualInstall.label");
  357. var manualInstallTooltip = this.getString("pluginInstallationSummary.manualInstall.tooltip");
  358. myButton.setAttribute("label", manualInstallLabel);
  359. myButton.setAttribute("tooltiptext", manualInstallTooltip);
  360. myRow.appendChild(myButton);
  361. // XXX: XUL sucks, need to add the listener after it got added into the document
  362. if (aManualUrl)
  363. myButton.addEventListener("command", function() { gPluginInstaller.loadURL(aManualUrl) }, false);
  364. }
  365. myRows.appendChild(myRow);
  366. }
  367. nsPluginInstallerWizard.prototype.showPluginResults = function (){
  368. var notInstalledList = "?action=missingplugins";
  369. var myRows = document.getElementById("pluginResultList");
  370. // clear children
  371. for (var run = myRows.childNodes.length; run--; run > 0)
  372. myRows.removeChild(myRows.childNodes.item(run));
  373. for (var pluginInfoItem in this.mPluginInfoArray){
  374. // [plugin image] [Plugin_Name Plugin_Version] [Success/Failed] [Manual Install (if Failed)]
  375. var myPluginItem = this.mPluginInfoArray[pluginInfoItem];
  376. if (myPluginItem.toBeInstalled) {
  377. var statusMsg;
  378. var statusTooltip;
  379. if (myPluginItem.error){
  380. statusMsg = this.getString("pluginInstallationSummary.failed");
  381. statusTooltip = myPluginItem.error;
  382. notInstalledList += "&mimetype=" + pluginInfoItem;
  383. } else if (!myPluginItem.licenseAccepted) {
  384. statusMsg = this.getString("pluginInstallationSummary.licenseNotAccepted");
  385. } else if (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation) {
  386. statusMsg = this.getString("pluginInstallationSummary.notAvailable");
  387. notInstalledList += "&mimetype=" + pluginInfoItem;
  388. } else {
  389. this.mSuccessfullPluginInstallation++;
  390. statusMsg = this.getString("pluginInstallationSummary.success");
  391. // only check needsRestart if the plugin was successfully installed.
  392. if (myPluginItem.needsRestart)
  393. this.mNeedsRestart = true;
  394. }
  395. // manual url - either returned from the webservice or the pluginspage attribute
  396. var manualUrl;
  397. if ((myPluginItem.error || (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation)) &&
  398. (myPluginItem.manualInstallationURL || this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage)){
  399. manualUrl = myPluginItem.manualInstallationURL ? myPluginItem.manualInstallationURL : this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage;
  400. }
  401. this.addPluginResultRow(
  402. myPluginItem.IconUrl,
  403. myPluginItem.name + " " + (myPluginItem.version ? myPluginItem.version : ""),
  404. null,
  405. statusMsg,
  406. statusTooltip,
  407. manualUrl);
  408. }
  409. }
  410. // handle plugins we couldn't find
  411. for (pluginInfoItem in this.mPluginNotFoundArray){
  412. var pluginRequest = this.mPluginNotFoundArray[pluginInfoItem];
  413. // if there is a pluginspage, show UI
  414. if (pluginRequest.pluginsPage) {
  415. this.addPluginResultRow(
  416. "",
  417. this.getFormattedString("pluginInstallation.unknownPlugin", [pluginInfoItem]),
  418. null,
  419. null,
  420. null,
  421. pluginRequest.pluginsPage);
  422. }
  423. notInstalledList += "&mimetype=" + pluginInfoItem;
  424. }
  425. // no plugins were found, so change the description of the final page.
  426. if (this.mPluginInfoArrayLength == 0) {
  427. var noPluginsFound = this.getString("pluginInstallation.noPluginsFound");
  428. document.getElementById("pluginSummaryDescription").setAttribute("value", noPluginsFound);
  429. } else if (this.mSuccessfullPluginInstallation == 0) {
  430. // plugins found, but none were installed.
  431. var noPluginsInstalled = this.getString("pluginInstallation.noPluginsInstalled");
  432. document.getElementById("pluginSummaryDescription").setAttribute("value", noPluginsInstalled);
  433. }
  434. document.getElementById("pluginSummaryRestartNeeded").hidden = !this.mNeedsRestart;
  435. var app = Components.classes["@mozilla.org/xre/app-info;1"]
  436. .getService(Components.interfaces.nsIXULAppInfo);
  437. // set the get more info link to contain the mimetypes we couldn't install.
  438. notInstalledList +=
  439. "&appID=" + app.ID +
  440. "&appVersion=" + app.platformBuildID +
  441. "&clientOS=" + this.getOS() +
  442. "&chromeLocale=" + this.getChromeLocale() +
  443. "&appRelease=" + app.version;
  444. document.getElementById("moreInfoLink").addEventListener("click", function() { gPluginInstaller.loadURL("https://pfs.mozilla.org/plugins/" + notInstalledList) }, false);
  445. if (this.mNeedsRestart) {
  446. var cancel = document.getElementById("plugin-installer-wizard").getButton("cancel");
  447. cancel.label = this.getString("pluginInstallation.close.label");
  448. cancel.accessKey = this.getString("pluginInstallation.close.accesskey");
  449. var finish = document.getElementById("plugin-installer-wizard").getButton("finish");
  450. finish.label = this.getFormattedString("pluginInstallation.restart.label", [app.name]);
  451. finish.accessKey = this.getString("pluginInstallation.restart.accesskey");
  452. this.canCancel(true);
  453. }
  454. else {
  455. this.canCancel(false);
  456. }
  457. this.canAdvance(true);
  458. this.canRewind(false);
  459. }
  460. nsPluginInstallerWizard.prototype.loadURL = function (aUrl){
  461. // Check if the page where the plugin came from can load aUrl before
  462. // loading it, and do *not* allow loading URIs that would inherit our
  463. // principal.
  464. var pluginPagePrincipal =
  465. window.opener.content.document.nodePrincipal;
  466. const nsIScriptSecurityManager =
  467. Components.interfaces.nsIScriptSecurityManager;
  468. var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
  469. .getService(nsIScriptSecurityManager);
  470. secMan.checkLoadURIStrWithPrincipal(pluginPagePrincipal, aUrl,
  471. nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
  472. window.opener.open(aUrl);
  473. }
  474. nsPluginInstallerWizard.prototype.getString = function (aName){
  475. return document.getElementById("pluginWizardString").getString(aName);
  476. }
  477. nsPluginInstallerWizard.prototype.getFormattedString = function (aName, aArray){
  478. return document.getElementById("pluginWizardString").getFormattedString(aName, aArray);
  479. }
  480. nsPluginInstallerWizard.prototype.getOS = function (){
  481. var httpService = Components.classes["@mozilla.org/network/protocol;1?name=http"]
  482. .getService(Components.interfaces.nsIHttpProtocolHandler);
  483. return httpService.oscpu;
  484. }
  485. nsPluginInstallerWizard.prototype.getChromeLocale = function (){
  486. var chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"]
  487. .getService(Components.interfaces.nsIXULChromeRegistry);
  488. return chromeReg.getSelectedLocale("global");
  489. }
  490. nsPluginInstallerWizard.prototype.getPrefBranch = function (){
  491. if (!this.prefBranch)
  492. this.prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
  493. .getService(Components.interfaces.nsIPrefBranch);
  494. return this.prefBranch;
  495. }
  496. function nsPluginRequest(aPlugRequest){
  497. this.mimetype = encodeURI(aPlugRequest.mimetype);
  498. this.pluginsPage = aPlugRequest.pluginsPage;
  499. }
  500. function PluginInfo(aResult) {
  501. this.name = aResult.name;
  502. this.pid = aResult.pid;
  503. this.version = aResult.version;
  504. this.IconUrl = aResult.IconUrl;
  505. this.InstallerLocation = aResult.InstallerLocation;
  506. this.InstallerHash = aResult.InstallerHash;
  507. this.XPILocation = aResult.XPILocation;
  508. this.XPIHash = aResult.XPIHash;
  509. this.InstallerShowsUI = aResult.InstallerShowsUI;
  510. this.manualInstallationURL = aResult.manualInstallationURL;
  511. this.requestedMimetype = aResult.requestedMimetype;
  512. this.licenseURL = aResult.licenseURL;
  513. this.needsRestart = (aResult.needsRestart == "true");
  514. this.error = null;
  515. this.toBeInstalled = true;
  516. // no license provided, make it accepted
  517. this.licenseAccepted = this.licenseURL ? false : true;
  518. }
  519. var gPluginInstaller;
  520. function wizardInit(){
  521. gPluginInstaller = new nsPluginInstallerWizard();
  522. gPluginInstaller.canAdvance(false);
  523. gPluginInstaller.getPluginData();
  524. }
  525. function wizardFinish(){
  526. if (gPluginInstaller.mNeedsRestart) {
  527. // Notify all windows that an application quit has been requested.
  528. var os = Components.classes["@mozilla.org/observer-service;1"]
  529. .getService(Components.interfaces.nsIObserverService);
  530. var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"]
  531. .createInstance(Components.interfaces.nsISupportsPRBool);
  532. os.notifyObservers(cancelQuit, "quit-application-requested", "restart");
  533. // Something aborted the quit process.
  534. if (!cancelQuit.data) {
  535. var nsIAppStartup = Components.interfaces.nsIAppStartup;
  536. var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
  537. .getService(nsIAppStartup);
  538. appStartup.quit(nsIAppStartup.eAttemptQuit | nsIAppStartup.eRestart);
  539. return true;
  540. }
  541. }
  542. // don't refresh if no plugins were found or installed
  543. if ((gPluginInstaller.mSuccessfullPluginInstallation > 0) &&
  544. (gPluginInstaller.mPluginInfoArray.length != 0)) {
  545. // reload plugins so JS detection works immediately
  546. try {
  547. var ph = Components.classes["@mozilla.org/plugin/host;1"]
  548. .getService(Components.interfaces.nsIPluginHost);
  549. ph.reloadPlugins(false);
  550. }
  551. catch (e) {
  552. // reloadPlugins throws an exception if there were no plugins to load
  553. }
  554. if (gPluginInstaller.mBrowser) {
  555. // notify listeners that a plugin is installed,
  556. // so that they can reset the UI and update the browser.
  557. var event = document.createEvent("Events");
  558. event.initEvent("NewPluginInstalled", true, true);
  559. gPluginInstaller.mBrowser.dispatchEvent(event);
  560. }
  561. }
  562. return true;
  563. }