~ubuntu-branches/ubuntu/oneiric/ubufox/oneiric-proposed

« back to all changes in this revision

Viewing changes to .pc/06_firefox-4.patch/content/pluginInstallerDatasource.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:
 
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-2005
 
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
const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
 
40
const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
 
41
 
 
42
function nsRDFItemUpdater(aClientOS, aChromeLocale){
 
43
  this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
 
44
                        .getService(Components.interfaces.nsIRDFService);
 
45
  this._os = Components.classes["@mozilla.org/observer-service;1"]
 
46
                       .getService(Components.interfaces.nsIObserverService);
 
47
 
 
48
  var app = Components.classes["@mozilla.org/xre/app-info;1"]
 
49
                      .getService(Components.interfaces.nsIXULAppInfo);
 
50
  this.appID = app.ID;
 
51
  this.buildID = app.platformBuildID;
 
52
 
 
53
  this.clientOS = aClientOS;
 
54
  this.chromeLocale = aChromeLocale;
 
55
 
 
56
  var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
 
57
                             .getService(Components.interfaces.nsIPrefBranch);
 
58
  this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
 
59
}
 
60
 
 
61
nsRDFItemUpdater.prototype = {
 
62
  checkForPlugin: function (aPluginRequestItem){
 
63
    var dsURI = this.dsURI;
 
64
    // escape the mimetype as mimetypes can contain '+', which will break pfs.
 
65
    dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
 
66
    dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
 
67
    dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
 
68
    dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
 
69
    dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
 
70
 
 
71
    var ds = this._rdfService.GetDataSource(dsURI);
 
72
    var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
 
73
    if (rds.loaded)
 
74
      this.onDatasourceLoaded(ds, aPluginRequestItem);
 
75
    else {
 
76
      var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
 
77
      sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
 
78
    }
 
79
  },
 
80
 
 
81
  onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
 
82
    var container = Components.classes["@mozilla.org/rdf/container;1"].
 
83
                  createInstance(Components.interfaces.nsIRDFContainer);
 
84
    var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
 
85
    var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
 
86
    var pluginInfos = new Array();
 
87
  
 
88
    container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
 
89
    try {
 
90
      container.Init(aDatasource, pluginList);
 
91
 
 
92
      var children = container.GetElements();
 
93
      // get the first item
 
94
      while(children.hasMoreElements()) {
 
95
 
 
96
        var target;
 
97
        var child = children.getNext();
 
98
        if (child instanceof Components.interfaces.nsIRDFResource){
 
99
          var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
 
100
          target = aDatasource.GetTarget(child, name, true);
 
101
        }
 
102
 
 
103
        try {
 
104
          container.Init(aDatasource, target);
 
105
          var target2 = null;
 
106
          var children2 = container.GetElements();
 
107
 
 
108
          while (children2.hasMoreElements()) {
 
109
            var child2 = children2.getNext();
 
110
            if (child2 instanceof Components.interfaces.nsIRDFResource){
 
111
              target2 = child2;
 
112
            }
 
113
 
 
114
            var rdfs = this._rdfService;
 
115
 
 
116
            function getPFSValueFromRDF(aValue){
 
117
              var rv = null;
 
118
 
 
119
              var myTarget = aDatasource.GetTarget(target2, rdfs.GetResource(PFS_NS + aValue), true);
 
120
              if (myTarget)
 
121
                rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
 
122
 
 
123
              return rv;
 
124
            }
 
125
 
 
126
            var pluginInfo = {
 
127
              name: getPFSValueFromRDF("name"),
 
128
              pid: getPFSValueFromRDF("guid"),
 
129
              version: getPFSValueFromRDF("version"),
 
130
              IconUrl: getPFSValueFromRDF("IconUrl"),
 
131
              desc: getPFSValueFromRDF("description"), 
 
132
              homepage: getPFSValueFromRDF("homepage"),
 
133
              XPILocation: getPFSValueFromRDF("XPILocation"),
 
134
              XPIHash: getPFSValueFromRDF("XPIHash"),
 
135
              InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"),
 
136
              manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"),
 
137
              requestedMimetype: getPFSValueFromRDF("requestedMimetype"),
 
138
              licenseURL: getPFSValueFromRDF("licenseURL"),
 
139
              needsRestart: getPFSValueFromRDF("needsRestart"),
 
140
              fileHint: getPFSValueFromRDF("filehint")
 
141
            };
 
142
 
 
143
            pluginInfos.push(pluginInfo);
 
144
          }
 
145
        }
 
146
        catch (ex){}
 
147
      }
 
148
    }
 
149
    catch (ex){}
 
150
    
 
151
    gPluginInstaller.pluginInfoReceived(pluginInfos);
 
152
  },
 
153
 
 
154
  onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
 
155
    this._os.notifyObservers(aPluginRequestItem, "error", aError);
 
156
    gPluginInstaller.pluginInfoReceived(null);
 
157
  },
 
158
};
 
159
 
 
160
function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
 
161
  this._updater = aUpdater;
 
162
  this._item    = aPluginRequestItem;
 
163
}
 
164
 
 
165
nsPluginXMLRDFDSObserver.prototype = 
 
166
 
167
  _updater  : null,
 
168
  _item     : null,
 
169
 
 
170
  // nsIRDFXMLSinkObserver
 
171
  onBeginLoad: function(aSink){},
 
172
  onInterrupt: function(aSink){},
 
173
  onResume: function(aSink){},
 
174
  onEndLoad: function(aSink){
 
175
    aSink.removeXMLSinkObserver(this);
 
176
    
 
177
    var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
 
178
    this._updater.onDatasourceLoaded(ds, this._item);
 
179
  },
 
180
  
 
181
  onError: function(aSink, aStatus, aErrorMsg){  
 
182
    aSink.removeXMLSinkObserver(this);   
 
183
    this._updater.onDatasourceError(this._item, aStatus.toString());
 
184
  }
 
185
};