1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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
14
* The Original Code is Plugin Finder Service.
16
* The Initial Developer of the Original Code is
18
* Portions created by the IBM Corporation are Copyright (C) 2004-2005
19
* IBM Corporation. All Rights Reserved.
22
* Doron Rosenberg <doronr@us.ibm.com>
23
* Alexander Sack <asac@jwsdot.com> - Canonical Ltd.
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.
37
* ***** END LICENSE BLOCK ***** */
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#";
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);
48
var app = Components.classes["@mozilla.org/xre/app-info;1"]
49
.getService(Components.interfaces.nsIXULAppInfo);
51
this.buildID = app.platformBuildID;
52
this.appRelease = app.version;
54
this.clientOS = aClientOS;
55
this.chromeLocale = aChromeLocale;
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");
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);
75
var ds = this._rdfService.GetDataSource(dsURI);
76
var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
78
this.onDatasourceLoaded(ds, aPluginRequestItem);
80
var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
81
sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
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();
93
container.Init(aDatasource, pluginList);
95
var children = container.GetElements();
97
while(children.hasMoreElements()) {
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);
107
container.Init(aDatasource, target);
109
var children2 = container.GetElements();
111
while (children2.hasMoreElements()) {
112
var child2 = children2.getNext();
113
if (child2 instanceof Components.interfaces.nsIRDFResource) {
117
var rdfs = this._rdfService;
119
function getPFSValueFromRDF(aValue) {
122
var myTarget = aDatasource.GetTarget(target2, rdfs.GetResource(PFS_NS + aValue), true);
124
rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
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")
147
// no license provided, make it accepted
148
pluginInfo.licenseAccepted = pluginInfo.licenseURL ? false : true;
150
pluginInfos.push(pluginInfo);
154
Components.utils.reportError(ex);
159
Components.utils.reportError(ex);
162
gPluginInstaller.pluginInfoReceived(aPluginRequestItem, pluginInfos);
165
onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError) {
166
this._os.notifyObservers(aPluginRequestItem, "error", aError);
167
Components.utils.reportError(aError);
168
gPluginInstaller.pluginInfoReceived(aPluginRequestItem, null);
172
function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem) {
173
this._updater = aUpdater;
174
this._item = aPluginRequestItem;
177
nsPluginXMLRDFDSObserver.prototype =
182
// nsIRDFXMLSinkObserver
183
onBeginLoad: function(aSink) {},
184
onInterrupt: function(aSink) {},
185
onResume: function(aSink) {},
186
onEndLoad: function(aSink) {
187
aSink.removeXMLSinkObserver(this);
189
var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
190
this._updater.onDatasourceLoaded(ds, this._item);
193
onError: function(aSink, aStatus, aErrorMsg) {
194
aSink.removeXMLSinkObserver(this);
195
this._updater.onDatasourceError(this._item, aStatus.toString());