toolkit/mozapps/plugins/content/pluginInstallerWizard.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial