~ubuntu-branches/ubuntu/vivid/ubufox/vivid

« back to all changes in this revision

Viewing changes to content/pluginInstallerDatasource.js

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2012-01-03 12:54:26 UTC
  • mfrom: (1.1.28)
  • Revision ID: package-import@ubuntu.com-20120103125426-6huvc70js97j10i4
Tags: 1.5-0ubuntu1
* New upstream release
  - Update for Firefox 12.0a1 compatibility
  - Rewrite the plugin installer code to natively support aptdaemon
    (instead of apturl).
    + Note, this only affects plugin installation - search still happens
      using the online PFS.
  - Simplify the update restart notification code
  - Set the update restart notification reminder period to 15 minutes
* Drop dependency on apturl, and add dependency on aptdaemon and
  libglib2.0-0 (we're using GDBus via ctypes)
  - update debian/control

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