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;
53
this.clientOS = aClientOS;
54
this.chromeLocale = aChromeLocale;
56
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
57
.getService(Components.interfaces.nsIPrefBranch);
58
this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
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);
71
var ds = this._rdfService.GetDataSource(dsURI);
72
var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
74
this.onDatasourceLoaded(ds, aPluginRequestItem);
76
var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
77
sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
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();
88
container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
90
container.Init(aDatasource, pluginList);
92
var children = container.GetElements();
94
while(children.hasMoreElements()) {
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);
104
container.Init(aDatasource, target);
106
var children2 = container.GetElements();
108
while (children2.hasMoreElements()) {
109
var child2 = children2.getNext();
110
if (child2 instanceof Components.interfaces.nsIRDFResource){
114
var rdfs = this._rdfService;
116
function getPFSValueFromRDF(aValue){
119
var myTarget = aDatasource.GetTarget(target2, rdfs.GetResource(PFS_NS + aValue), true);
121
rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
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")
143
pluginInfos.push(pluginInfo);
151
gPluginInstaller.pluginInfoReceived(pluginInfos);
154
onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
155
this._os.notifyObservers(aPluginRequestItem, "error", aError);
156
gPluginInstaller.pluginInfoReceived(null);
160
function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
161
this._updater = aUpdater;
162
this._item = aPluginRequestItem;
165
nsPluginXMLRDFDSObserver.prototype =
170
// nsIRDFXMLSinkObserver
171
onBeginLoad: function(aSink){},
172
onInterrupt: function(aSink){},
173
onResume: function(aSink){},
174
onEndLoad: function(aSink){
175
aSink.removeXMLSinkObserver(this);
177
var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
178
this._updater.onDatasourceLoaded(ds, this._item);
181
onError: function(aSink, aStatus, aErrorMsg){
182
aSink.removeXMLSinkObserver(this);
183
this._updater.onDatasourceError(this._item, aStatus.toString());