~ubuntu-branches/ubuntu/natty/ubufox/natty-proposed

« back to all changes in this revision

Viewing changes to content/pluginInstallerWizard.js

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2011-01-01 14:30:25 UTC
  • Revision ID: james.westby@ubuntu.com-20110101143025-52ew6ngsqev5gcqn
Tags: 0.9~rc2-0ubuntu7
* Add patch to update for Firefox 4:
  - Rename AboutHome to AboutStartup, and have it handle about:startup now 
    (to not conflict with the new about:home handler in Firefox
  - Set default home page to about:startpage
  - Add support for the XPCOM changes in Gecko 2.0
  - In the restart notifier, don't hardcode a list of filenames for different
    browser versions, but just use MOZ_APP_LAUNCHER instead. This will
    indirectly fix LP: #511250 and should prevent it from happening again
  - Look in the new location for the restart-required trigger, it has moved
    to a location not monitored by update-notifier now, so we only get the
    restart required notification in the browser
  - Merge the plugin finder code from Firefox 4. This now uses AddonManager,
    so the MinVersion needs to be bumped
  - Drop the FF2.0 specific code
  - Drop the AddonsOverlay and associated code, this hasn't worked for
    several releases since we started using software-center, and nobody
    really noticed so far. We can reimplement this at a later date if wanted,
    but it throws JS exceptions when loading in FF4.0 now
  - Specify for the extension to be unpacked by the installer. Without this,
    the prefs aren't used
  - Get the distributionID field for the pfs URL from the preferences, rather
    than hard-coding a value

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
  // how many plugins are to be installed
65
65
  this.pluginsToInstallNum = 0;
66
66
 
67
 
  this.mTab = null;
68
67
  this.mBrowser = null;
69
68
  this.mSuccessfullPluginInstallation = 0;
 
69
  this.mNeedsRestart = false;
70
70
 
71
71
  this.mPluginPidArray = new Object();
72
72
  // arguments[0] is an array that contains two items:
73
73
  //     an array of mimetypes that are missing
74
 
  //     a reference to the tab that needs them, so we can reload it
 
74
  //     a reference to the browser that needs them, 
 
75
  //        so we can notify which browser can be reloaded.
75
76
 
76
77
  if ("arguments" in window) {
77
78
    for (var item in window.arguments[0].plugins){
81
82
      this.mPluginRequestArrayLength++;
82
83
    }
83
84
 
84
 
    this.mBrowser = window.arguments[0].browser; // ffox 3
85
 
    this.mTab = window.arguments[0].tab; // ffox 2
 
85
    this.mBrowser = window.arguments[0].browser;
86
86
  }
87
87
 
88
88
  this.WSPluginCounter = 0;
100
100
  // initiate the datasource call
101
101
  var rdfUpdater = new nsRDFItemUpdater(this.getOS(), this.getChromeLocale());
102
102
 
103
 
  for (item in this.mPluginRequestArray) {
 
103
  for (var item in this.mPluginRequestArray) {
104
104
    rdfUpdater.checkForPlugin(this.mPluginRequestArray[item]);
105
105
  }
106
106
}
107
107
 
108
108
// aPluginInfo is null if the datasource call failed, and pid is -1 if
109
109
// no matching plugin was found.
110
 
nsPluginInstallerWizard.prototype.pluginInfoReceived = function (aPluginInfos){
 
110
nsPluginInstallerWizard.prototype.pluginInfoReceived = function (aPluginRequestItem, aPluginInfos){
111
111
  this.WSPluginCounter++;
112
112
 
113
113
  if (aPluginInfos ) {
121
121
      aPluginInfo = aPluginInfos[i];
122
122
      resultSetMimeType = aPluginInfo.requestedMimetype;
123
123
      if (aPluginInfo && aPluginInfo.pid != -1 &&
124
 
          ( aPluginInfo.XPILocation || aPluginInfo.manualInstallationURL )) {
 
124
          ( aPluginInfo.XPILocation || aPluginInfo.manualInstallationURL || aPluginInfo.InstallerLocation)) {
125
125
        hasResults = true;
126
126
        filteredPluginInfoSet.push(aPluginInfo);
127
127
        this.mPluginPidArray[aPluginInfo.pid] = aPluginInfo;
130
130
 
131
131
    if(filteredPluginInfoSet.length > 0)
132
132
    {
133
 
      this.mPluginInfoArray[resultSetMimeType] = filteredPluginInfoSet;
 
133
      this.mPluginInfoArray[aPluginRequestItem.mimetype] = filteredPluginInfoSet;
134
134
      this.mPluginInfoArrayLength++;
135
135
    } else {
136
 
      this.mPluginNotFoundArray[resultSetMimeType] = filteredPluginInfoSet;
 
136
      this.mPluginNotFoundArray[aPluginRequestItem.mimetype] = aPluginRequestItem;
137
137
      this.mPluginNotFoundArrayLength++;
138
138
    }
139
139
  }
148
148
 
149
149
  if (this.WSPluginCounter == this.mPluginRequestArrayLength) {
150
150
    // check if no plugins were found
151
 
    if (this.mPluginInfoArrayLength == 0 && this.mPluginInfoAptArrayLength == 0) {
152
 
      this.advancePage("lastpage", true, false, false);
 
151
    if (this.mPluginInfoArrayLength == 0) {
 
152
      this.advancePage("lastpage");
153
153
    } else {
154
154
      // we want to allow user to cancel
155
 
      this.advancePage(null, true, false, true);
 
155
      this.advancePage(null);
156
156
    }
157
157
  } else {
158
158
    // process more.
159
159
  }
160
160
}
161
161
 
162
 
nsPluginInstallerWizard.prototype.createPluginSetGroupBox = function () {
 
162
nsPluginInstallerWizard.prototype.createPluginSetGroupBox = function (mimetype) {
163
163
 
164
164
  var stringBundle = document.getElementById("ubufoxPluginWizardString");
165
165
  var gbox = document.createElement("vbox");
193
193
  var groupBox = null;
194
194
  var lastSibling = null;
195
195
 
196
 
  for (mimetype in this.mPluginInfoArray){
 
196
  for (var mimetype in this.mPluginInfoArray){
197
197
    // [plugin image] [Plugin_Name Plugin_Version]
198
198
    var pluginInfoSet = this.mPluginInfoArray[mimetype];
199
199
    var firstPluginSet = (groupBox == null);
200
 
    groupBox = this.createPluginSetGroupBox(document, mimetype, pluginInfoSet);
 
200
    groupBox = this.createPluginSetGroupBox(mimetype);
201
201
 
202
202
    if(firstPluginSet) {
203
203
      this.mPluginPlaceHolder = document.getElementById("pluginselection-placeholder");
275
275
    if (pluginInfo.InstallerShowsUI == "true")
276
276
      hasPluginWithInstallerUI = true;
277
277
 
 
278
    // keep a running count of plugins the user wants to install
278
279
    this.pluginsToInstallNum++;
279
280
  }
280
281
 
290
291
  var mime = selectedItem._ubufoxPluginInfoMimeType;
291
292
  this.mMimeTypePluginSelections[mime] = selectedItem._ubufoxPluginInfo.pid;
292
293
 
293
 
  let count  = 0;
294
 
  for (mime in this.mMimeTypePluginSelections) {
 
294
  this.pluginsToInstallNum = 0;
 
295
  for (var mime in this.mMimeTypePluginSelections) {
295
296
    if(this.mMimeTypePluginSelections[mime] && this.mMimeTypePluginSelections[mime] != "-1")
296
 
      count++;
 
297
      this.pluginsToInstallNum++;
297
298
  }
298
299
 
299
300
  // if no plugins are checked, don't allow to advance
300
 
  if (count > 0)
 
301
  if (this.pluginsToInstallNum > 0)
301
302
    this.canAdvance(true);
302
303
  else
303
304
    this.canAdvance(false);
321
322
 
322
323
  // only add if a license is provided and the plugin was selected to
323
324
  // be installed
324
 
  for (mimetype in this.mMimeTypePluginSelections){
 
325
  for (var mimetype in this.mMimeTypePluginSelections){
325
326
    var pid = this.mMimeTypePluginSelections[mimetype];
326
327
    var pluginInfo = this.mPluginPidArray[pid];
327
328
    if (pluginInfo && pluginInfo.licenseURL && (pluginInfo.licenseURL != "")) {
331
332
 
332
333
  if (this.mPluginLicenseArray.length == 0) {
333
334
    // no plugins require licenses
334
 
    this.advancePage(null, true, false, false);
 
335
    this.advancePage(null);
335
336
  } else {
336
337
    this.licenseAcceptCounter = 0;
337
338
 
389
390
 
390
391
  this.canAdvance(false);
391
392
 
392
 
  loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
 
393
  var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
393
394
 
394
395
  document.getElementById("licenseIFrame").webNavigation.loadURI(pluginInfo.licenseURL, loadFlags, null, null, null);
395
396
 
447
448
    this.canAdvance(aAccepted);
448
449
}
449
450
 
450
 
nsPluginInstallerWizard.prototype.advancePage = function (aPageId, aCanAdvance, aCanRewind, aCanCancel){
 
451
nsPluginInstallerWizard.prototype.advancePage = function (aPageId){
451
452
  this.canAdvance(true);
452
453
  document.getElementById("plugin-installer-wizard").advance(aPageId);
453
 
 
454
 
  this.canAdvance(aCanAdvance);
455
 
  this.canRewind(aCanRewind);
456
 
  this.canCancel(aCanCancel);
457
454
}
458
455
 
459
456
nsPluginInstallerWizard.prototype.startPluginInstallation = function (){
460
457
  this.canAdvance(false);
461
458
  this.canRewind(false);
462
459
 
463
 
  // since the user can choose what plugins to install, we need to store
464
 
  // which ones were choosen, as nsIXPInstallManager returns an index and not the
465
 
  // mimetype.  So store the pids.
466
 
 
467
 
  // for ubutfox we deal with multiple cases: first case is XPIInstall, which will
 
460
  // for ubufox we deal with multiple cases: first case is XPIInstall, which will
468
461
  // run the "normal" XPIInstall process; second case is XPIInstall url contains
469
462
  // and apt: protocol url ... this will run apt protocol handler 
470
 
  var pluginURLArray = new Array();
471
 
  var pluginHashArray = new Array();
472
 
  var pluginPidArray = new Array();
473
 
  this.mAptPluginURLArray = new Array();
474
 
  this.mAptPluginPidArray = new Array();
475
 
 
476
 
  for (mime in this.mMimeTypePluginSelections) {
477
 
    var pluginPid = this.mMimeTypePluginSelections[mime];
478
 
    var pluginItem = this.mPluginPidArray[pluginPid];
479
 
 
480
 
    // only push to the array if it has an XPILocation, else nsIXPInstallManager
481
 
    // will complain.
482
 
    if (pluginItem && pluginItem.XPILocation && pluginItem.XPILocation.indexOf("apt:") != 0 && pluginItem.licenseAccepted) {
483
 
      pluginURLArray.push(pluginItem.XPILocation);
484
 
      pluginHashArray.push(pluginItem.XPIHash);
485
 
      pluginPidArray.push(pluginItem.pid);
486
 
    } else if (pluginItem && pluginItem.XPILocation && pluginItem.XPILocation.indexOf("apt:") == 0) {
487
 
      this.mAptPluginURLArray.push(pluginItem.XPILocation);
488
 
      this.mAptPluginPidArray.push(pluginPid);
489
 
    } else {
490
 
      window.alert("Unhandled mime install flavour (supported: vendor, apt)");
491
 
      continue;
 
463
  var installerPlugins = [];
 
464
  var xpiPlugins = [];
 
465
  this.aptPlugins = [];
 
466
 
 
467
  for (var mime in this.mMimeTypePluginSelections) {
 
468
    var pluginItem = this.mPluginPidArray[this.mMimeTypePluginSelections[mime]];
 
469
 
 
470
    if (pluginItem && pluginItem.licenseAccepted) {
 
471
      if (pluginItem.InstallerLocation)
 
472
        installerPlugins.push(pluginItem);
 
473
      else if (pluginItem.XPILocation && pluginItem.XPILocation.indexOf("apt:") != 0)
 
474
        xpiPlugins.push(pluginItem);
 
475
      else if (pluginItem.XPILocation && pluginItem.XPILocation.indexOf("apt:") == 0)
 
476
        this.aptPlugins.push(pluginItem);
 
477
      else {
 
478
        window.alert("Unhandled mime install flavour (supported: vendor, apt)");
 
479
        continue;
 
480
      }
492
481
    }
493
482
  }
494
483
 
495
 
  if (pluginURLArray.length > 0)
496
 
    PluginXPIInstallService.startPluginInstallation(pluginURLArray,
497
 
                                                    pluginHashArray,
498
 
                                                    pluginPidArray);
499
 
  else if (this.mAptPluginURLArray.length > 0)
500
 
    PluginAPTInstallService.startPluginInstallation(this.mAptPluginURLArray,
501
 
                                                    this.mAptPluginPidArray);
 
484
  if (installerPlugins.length > 0 || xpiPlugins.length > 0)
 
485
    PluginXPIInstallService.startPluginInstallation(installerPlugins,
 
486
                                                    xpiPlugins);
 
487
  else if (this.aptPlugins.length > 0)
 
488
    PluginAPTInstallService.startPluginInstallation(this.aptPlugins);
502
489
  else
503
 
    this.advancePage(null, true, false, false);
 
490
    this.advancePage(null);
504
491
}
505
492
 
506
493
/*
530
517
 
531
518
    case 2:
532
519
      statMsg = this.getFormattedString("pluginInstallation.install.start", [pluginInfo.name]);
 
520
      var progressElm = document.getElementById("plugin_install_progress");
 
521
      progressElm.setAttribute("mode", "undetermined");
533
522
      break;
534
523
    case 6:
535
524
      statMsg = "APT - " + this.getFormattedString("pluginInstallation.install.start", [pluginInfo.name]);
555
544
      break;
556
545
 
557
546
    case 4:
558
 
      PluginAPTInstallService.startPluginInstallation(this.mAptPluginURLArray,
559
 
                                                      this.mAptPluginPidArray);
 
547
      PluginAPTInstallService.startPluginInstallation(this.aptPlugins);
560
548
      break;
561
549
    case 8:
562
 
      this.advancePage(null, true, false, false);
 
550
      this.advancePage(null);
563
551
      statMsg = this.getString("pluginInstallation.complete");
564
552
      break;
565
553
    default:
630
618
  var notInstalledList = "?action=missingplugins";
631
619
  var myRows = document.getElementById("pluginResultList");
632
620
 
633
 
  this.mNeedsRestart = false;
634
 
 
635
621
  // clear children
636
622
  for (var run = myRows.childNodes.length; run--; run > 0)
637
623
    myRows.removeChild(myRows.childNodes.item(run));
638
624
 
639
 
  for (mimetype in this.mMimeTypePluginSelections) {
640
 
    var pid = this.mMimeTypePluginSelections[mimetype];
641
 
    var pluginInfoItem = this.mPluginPidArray[pid];
 
625
  for (var mimetype in this.mMimeTypePluginSelections) {
 
626
    var pluginInfoItem = this.mPluginPidArray[this.mMimeTypePluginSelections[mimetype]];
642
627
    // [plugin image] [Plugin_Name Plugin_Version] [Success/Failed] [Manual Install (if Failed)]
643
628
 
644
629
    var myPluginItem = pluginInfoItem; //this.mPluginInfoArray[pluginInfoItem];
651
636
      notInstalledList += "&mimetype=" + pluginInfoItem;
652
637
    } else if (myPluginItem.licenseURL && !myPluginItem.licenseAccepted) {
653
638
      statusMsg = this.getString("pluginInstallationSummary.licenseNotAccepted");
654
 
    } else if (!myPluginItem.XPILocation) {
 
639
    } else if (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation) {
655
640
      statusMsg = this.getString("pluginInstallationSummary.notAvailable");
656
641
      notInstalledList += "&mimetype=" + pluginInfoItem;
657
642
    } else {
660
645
 
661
646
      // only check needsRestart if the plugin was successfully installed.
662
647
      if (myPluginItem.needsRestart)
663
 
        this.mNeedsRestart = false;
 
648
        this.mNeedsRestart = true;
664
649
    }
665
650
 
666
651
    // manual url - either returned from the webservice or the pluginspage attribute
667
652
    var manualUrl;
668
 
    if ((myPluginItem.error || !myPluginItem.XPILocation) && (myPluginItem.manualInstallationURL || this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage)){
 
653
    if ((myPluginItem.error || (!myPluginItem.XPILocation && !myPluginItem.InstallerLocation)) && (myPluginItem.manualInstallationURL || this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage)){
669
654
      manualUrl = myPluginItem.manualInstallationURL ? myPluginItem.manualInstallationURL : this.mPluginRequestArray[myPluginItem.requestedMimetype].pluginsPage;
670
655
    }
671
656
 
680
665
 
681
666
  // handle plugins we couldn't find
682
667
  for (pluginInfoItem in this.mPluginNotFoundArray){
683
 
    var pluginRequest = this.mPluginRequestArray[pluginInfoItem];
 
668
    var pluginRequest = this.mPluginNotFoundArray[pluginInfoItem];
684
669
 
685
670
    // if there is a pluginspage, show UI
686
 
    if (pluginRequest) {
 
671
    if (pluginRequest.pluginsPage) {
687
672
      this.addPluginResultRow(
688
673
          "",
689
674
          this.getFormattedString("pluginInstallation.unknownPlugin", [pluginInfoItem]),
716
701
    "&appID=" + app.ID +
717
702
    "&appVersion=" + app.platformBuildID +
718
703
    "&clientOS=" + this.getOS() +
719
 
    "&chromeLocale=" + this.getChromeLocale();
 
704
    "&chromeLocale=" + this.getChromeLocale() +
 
705
    "&appRelease=" + app.version;
720
706
 
721
707
  document.getElementById("moreInfoLink").addEventListener("click", function() { gPluginInstaller.loadURL("https://pfs.mozilla.org/plugins/" + notInstalledList) }, false);
722
708
 
 
709
  if (this.mNeedsRestart) {
 
710
    var cancel = document.getElementById("plugin-installer-wizard").getButton("cancel");
 
711
    cancel.label = this.getString("pluginInstallation.close.label");
 
712
    cancel.accessKey = this.getString("pluginInstallation.close.accesskey");
 
713
    var finish = document.getElementById("plugin-installer-wizard").getButton("finish");
 
714
    finish.label = this.getFormattedString("pluginInstallation.restart.label", [app.name]);
 
715
    finish.accessKey = this.getString("pluginInstallation.restart.accesskey");
 
716
    this.canCancel(true);
 
717
  }
 
718
  else {
 
719
    this.canCancel(false);
 
720
  }
 
721
 
723
722
  this.canAdvance(true);
724
723
  this.canRewind(false);
725
 
  this.canCancel(false);
726
724
}
727
725
 
728
726
nsPluginInstallerWizard.prototype.loadURL = function (aUrl){
729
727
  // Check if the page where the plugin came from can load aUrl before
730
 
  // loading it, and do *not* allow loading javascript: or data: URIs.
731
 
  var pluginPage = window.opener.content.location.href;
 
728
  // loading it, and do *not* allow loading URIs that would inherit our
 
729
  // principal.
 
730
  
 
731
  var pluginPagePrincipal =
 
732
    window.opener.content.document.nodePrincipal;
732
733
 
733
734
  const nsIScriptSecurityManager =
734
735
    Components.interfaces.nsIScriptSecurityManager;
735
 
  var secMan =
736
 
    Components.classes["@mozilla.org/scriptsecuritymanager;1"]
737
 
    .getService(nsIScriptSecurityManager);
 
736
  var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
 
737
                         .getService(nsIScriptSecurityManager);
738
738
 
739
 
  secMan.checkLoadURIStr(pluginPage, aUrl,
740
 
                         nsIScriptSecurityManager.DISALLOW_SCRIPT_OR_DATA);
 
739
  secMan.checkLoadURIStrWithPrincipal(pluginPagePrincipal, aUrl,
 
740
    nsIScriptSecurityManager.DISALLOW_INHERIT_PRINCIPAL);
741
741
 
742
742
  window.opener.open(aUrl);
743
743
}
792
792
  this.pid = aResult.pid;
793
793
  this.version = aResult.version;
794
794
  this.IconUrl = aResult.IconUrl;
 
795
  this.InstallerLocation = aResult.InstallerLocation;
 
796
  this.InstallerHash = aResult.InstallerHash;
795
797
  this.XPILocation = aResult.XPILocation;
796
798
  this.XPIHash = aResult.XPIHash;
797
799
  this.InstallerShowsUI = aResult.InstallerShowsUI;
816
818
}
817
819
 
818
820
function wizardFinish(){
819
 
  // we restart if we have no choice ...
820
821
  if (gPluginInstaller.mNeedsRestart) {
821
822
    // Notify all windows that an application quit has been requested.
822
823
    var os = Components.classes["@mozilla.org/observer-service;1"]
835
836
    }
836
837
  }
837
838
 
838
 
  if (gPluginInstaller.mBrowser) { // ffox 3 code can autoscan ...
839
 
    // always refresh
840
 
    var event = document.createEvent("Events");
841
 
    event.initEvent("NewPluginInstalled", true, true);
842
 
    var dispatched = gPluginInstaller.mBrowser.dispatchEvent(event);
843
 
  }
844
 
  else if (gPluginInstaller.mTab) { // ffox 2 code can autoscan ...
845
 
    if ((gPluginInstaller.mSuccessfullPluginInstallation > 0) &&
846
 
       (gPluginInstaller.mPluginInfoArrayLength != 0)) {
847
 
      // clear the tab's plugin list only if we installed at least one plugin
848
 
      gPluginInstaller.mTab.missingPlugins = null;
849
 
      // reset UI
850
 
      window.opener.gMissingPluginInstaller.closeNotification();
851
 
      // reload the browser to make the new plugin show
852
 
      window.opener.getBrowser().reloadTab(gPluginInstaller.mTab);
 
839
  // don't refresh if no plugins were found or installed
 
840
  if ((gPluginInstaller.mSuccessfullPluginInstallation > 0) &&
 
841
      (gPluginInstaller.mPluginInfoArray.length != 0)) {
 
842
 
 
843
    // reload plugins so JS detection works immediately
 
844
    try {
 
845
      var ph = Components.classes["@mozilla.org/plugin/host;1"]
 
846
                         .getService(Components.interfaces.nsIPluginHost);
 
847
      ph.reloadPlugins(false);
 
848
    }
 
849
    catch (e) {
 
850
      // reloadPlugins throws an exception if there were no plugins to load
 
851
    }
 
852
 
 
853
    if (gPluginInstaller.mBrowser) {
 
854
      // notify listeners that a plugin is installed,
 
855
      // so that they can reset the UI and update the browser.
 
856
      var event = document.createEvent("Events");
 
857
      event.initEvent("NewPluginInstalled", true, true);
 
858
      gPluginInstaller.mBrowser.dispatchEvent(event);
853
859
    }
854
860
  }
855
861