2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
const RDF_NS = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
|
|
|
|
const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#";
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
function nsRDFItemUpdater(aClientOS, aChromeLocale) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
2009-03-26 04:13:18 -07:00
|
|
|
.getService(Components.interfaces.nsIRDFService);
|
2007-03-22 10:30:00 -07:00
|
|
|
this._os = Components.classes["@mozilla.org/observer-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIObserverService);
|
|
|
|
|
|
|
|
var app = Components.classes["@mozilla.org/xre/app-info;1"]
|
|
|
|
.getService(Components.interfaces.nsIXULAppInfo);
|
|
|
|
this.appID = app.ID;
|
|
|
|
this.buildID = app.platformBuildID;
|
2008-05-28 11:49:32 -07:00
|
|
|
this.appRelease = app.version;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
this.clientOS = aClientOS;
|
|
|
|
this.chromeLocale = aChromeLocale;
|
|
|
|
|
|
|
|
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRDFItemUpdater.prototype = {
|
2009-03-26 04:13:18 -07:00
|
|
|
checkForPlugin: function (aPluginRequestItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var dsURI = this.dsURI;
|
|
|
|
// escape the mimetype as mimetypes can contain '+', which will break pfs.
|
|
|
|
dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
|
|
|
|
dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
|
|
|
|
dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
|
2008-05-28 11:49:32 -07:00
|
|
|
dsURI = dsURI.replace(/%APP_RELEASE%/g, this.appRelease);
|
2007-03-22 10:30:00 -07:00
|
|
|
dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
|
|
|
|
dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
|
|
|
|
|
|
|
|
var ds = this._rdfService.GetDataSource(dsURI);
|
|
|
|
var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
|
|
|
|
if (rds.loaded)
|
|
|
|
this.onDatasourceLoaded(ds, aPluginRequestItem);
|
|
|
|
else {
|
|
|
|
var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
|
|
|
|
sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem) {
|
|
|
|
var container = Components.classes["@mozilla.org/rdf/container;1"]
|
|
|
|
.createInstance(Components.interfaces.nsIRDFContainer);
|
2007-03-22 10:30:00 -07:00
|
|
|
var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
|
|
|
|
var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
|
|
|
|
|
|
|
|
var pluginInfo = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
container.Init(aDatasource, pluginList);
|
|
|
|
|
|
|
|
var children = container.GetElements();
|
|
|
|
var target;
|
|
|
|
|
|
|
|
// get the first item
|
|
|
|
var child = children.getNext();
|
2009-03-26 04:13:18 -07:00
|
|
|
if (child instanceof Components.interfaces.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
|
|
|
|
target = aDatasource.GetTarget(child, name, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
container.Init(aDatasource, target);
|
|
|
|
target = null;
|
|
|
|
children = container.GetElements();
|
|
|
|
|
|
|
|
var child = children.getNext();
|
2009-03-26 04:13:18 -07:00
|
|
|
if (child instanceof Components.interfaces.nsIRDFResource) {
|
2007-03-22 10:30:00 -07:00
|
|
|
target = child;
|
|
|
|
}
|
|
|
|
|
2007-06-19 09:12:49 -07:00
|
|
|
var rdfs = this._rdfService;
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
function getPFSValueFromRDF(aValue) {
|
2007-03-22 10:30:00 -07:00
|
|
|
var rv = null;
|
|
|
|
|
2007-06-19 09:12:49 -07:00
|
|
|
var myTarget = aDatasource.GetTarget(target, rdfs.GetResource(PFS_NS + aValue), true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (myTarget)
|
|
|
|
rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2007-06-19 09:12:49 -07:00
|
|
|
pluginInfo = {
|
|
|
|
name: getPFSValueFromRDF("name"),
|
|
|
|
pid: getPFSValueFromRDF("guid"),
|
|
|
|
version: getPFSValueFromRDF("version"),
|
|
|
|
IconUrl: getPFSValueFromRDF("IconUrl"),
|
2007-07-25 11:54:46 -07:00
|
|
|
InstallerLocation: getPFSValueFromRDF("InstallerLocation"),
|
|
|
|
InstallerHash: getPFSValueFromRDF("InstallerHash"),
|
2007-06-19 09:12:49 -07:00
|
|
|
XPILocation: getPFSValueFromRDF("XPILocation"),
|
|
|
|
XPIHash: getPFSValueFromRDF("XPIHash"),
|
|
|
|
InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"),
|
|
|
|
manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"),
|
|
|
|
requestedMimetype: getPFSValueFromRDF("requestedMimetype"),
|
|
|
|
licenseURL: getPFSValueFromRDF("licenseURL"),
|
|
|
|
needsRestart: getPFSValueFromRDF("needsRestart")
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-03-26 04:13:18 -07:00
|
|
|
catch (ex) {
|
|
|
|
Components.utils.reportError(ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
Components.utils.reportError(ex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
gPluginInstaller.pluginInfoReceived(aPluginRequestItem, pluginInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._os.notifyObservers(aPluginRequestItem, "error", aError);
|
2009-03-26 04:13:18 -07:00
|
|
|
Components.utils.reportError(aError);
|
|
|
|
gPluginInstaller.pluginInfoReceived(aPluginRequestItem, null);
|
2007-07-25 11:54:46 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this._updater = aUpdater;
|
|
|
|
this._item = aPluginRequestItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPluginXMLRDFDSObserver.prototype =
|
|
|
|
{
|
|
|
|
_updater : null,
|
|
|
|
_item : null,
|
|
|
|
|
|
|
|
// nsIRDFXMLSinkObserver
|
2009-03-26 04:13:18 -07:00
|
|
|
onBeginLoad: function(aSink) {},
|
|
|
|
onInterrupt: function(aSink) {},
|
|
|
|
onResume: function(aSink) {},
|
|
|
|
onEndLoad: function(aSink) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aSink.removeXMLSinkObserver(this);
|
|
|
|
|
|
|
|
var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
|
|
|
|
this._updater.onDatasourceLoaded(ds, this._item);
|
|
|
|
},
|
|
|
|
|
2009-03-26 04:13:18 -07:00
|
|
|
onError: function(aSink, aStatus, aErrorMsg) {
|
2007-03-22 10:30:00 -07:00
|
|
|
aSink.removeXMLSinkObserver(this);
|
|
|
|
this._updater.onDatasourceError(this._item, aStatus.toString());
|
|
|
|
}
|
|
|
|
};
|