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>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
39 const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
41 function nsRDFItemUpdater(aClientOS, aChromeLocale){
42 this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
43 .getService(Components.interfaces.nsIRDFService);
44 this._os = Components.classes["@mozilla.org/observer-service;1"]
45 .getService(Components.interfaces.nsIObserverService);
47 var app = Components.classes["@mozilla.org/xre/app-info;1"]
48 .getService(Components.interfaces.nsIXULAppInfo);
50 this.buildID = app.platformBuildID;
51 this.appRelease = app.version;
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(/%APP_RELEASE%/g, this.appRelease);
69 dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
70 dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
72 var ds = this._rdfService.GetDataSource(dsURI);
73 var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
75 this.onDatasourceLoaded(ds, aPluginRequestItem);
77 var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
78 sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
82 onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
83 var container = Components.classes["@mozilla.org/rdf/container;1"].
84 createInstance(Components.interfaces.nsIRDFContainer);
85 var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
86 var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
88 var pluginInfo = null;
90 container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
92 container.Init(aDatasource, pluginList);
94 var children = container.GetElements();
98 var child = children.getNext();
99 if (child instanceof Components.interfaces.nsIRDFResource){
100 var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
101 target = aDatasource.GetTarget(child, name, true);
105 container.Init(aDatasource, target);
107 children = container.GetElements();
109 var child = children.getNext();
110 if (child instanceof Components.interfaces.nsIRDFResource){
114 var rdfs = this._rdfService;
116 function getPFSValueFromRDF(aValue){
119 var myTarget = aDatasource.GetTarget(target, 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 InstallerLocation: getPFSValueFromRDF("InstallerLocation"),
132 InstallerHash: getPFSValueFromRDF("InstallerHash"),
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")
146 gPluginInstaller.pluginInfoReceived(pluginInfo);
149 onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
150 this._os.notifyObservers(aPluginRequestItem, "error", aError);
151 gPluginInstaller.pluginInfoReceived(null);
155 function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
156 this._updater = aUpdater;
157 this._item = aPluginRequestItem;
160 nsPluginXMLRDFDSObserver.prototype =
165 // nsIRDFXMLSinkObserver
166 onBeginLoad: function(aSink){},
167 onInterrupt: function(aSink){},
168 onResume: function(aSink){},
169 onEndLoad: function(aSink){
170 aSink.removeXMLSinkObserver(this);
172 var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
173 this._updater.onDatasourceLoaded(ds, this._item);
176 onError: function(aSink, aStatus, aErrorMsg){
177 aSink.removeXMLSinkObserver(this);
178 this._updater.onDatasourceError(this._item, aStatus.toString());