Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | const PFS_NS = "http://www.mozilla.org/2004/pfs-rdf#"; |
michael@0 | 6 | |
michael@0 | 7 | function nsRDFItemUpdater(aClientOS, aChromeLocale) { |
michael@0 | 8 | this._rdfService = Components.classes["@mozilla.org/rdf/rdf-service;1"] |
michael@0 | 9 | .getService(Components.interfaces.nsIRDFService); |
michael@0 | 10 | this._os = Components.classes["@mozilla.org/observer-service;1"] |
michael@0 | 11 | .getService(Components.interfaces.nsIObserverService); |
michael@0 | 12 | |
michael@0 | 13 | var app = Components.classes["@mozilla.org/xre/app-info;1"] |
michael@0 | 14 | .getService(Components.interfaces.nsIXULAppInfo); |
michael@0 | 15 | this.appID = app.ID; |
michael@0 | 16 | this.buildID = app.platformBuildID; |
michael@0 | 17 | this.appRelease = app.version; |
michael@0 | 18 | |
michael@0 | 19 | this.clientOS = aClientOS; |
michael@0 | 20 | this.chromeLocale = aChromeLocale; |
michael@0 | 21 | |
michael@0 | 22 | var prefBranch = Components.classes["@mozilla.org/preferences-service;1"] |
michael@0 | 23 | .getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 24 | this.dsURI = prefBranch.getCharPref("pfs.datasource.url"); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | nsRDFItemUpdater.prototype = { |
michael@0 | 28 | checkForPlugin: function (aPluginRequestItem) { |
michael@0 | 29 | var dsURI = this.dsURI; |
michael@0 | 30 | // escape the mimetype as mimetypes can contain '+', which will break pfs. |
michael@0 | 31 | dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype)); |
michael@0 | 32 | dsURI = dsURI.replace(/%APP_ID%/g, this.appID); |
michael@0 | 33 | dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID); |
michael@0 | 34 | dsURI = dsURI.replace(/%APP_RELEASE%/g, this.appRelease); |
michael@0 | 35 | dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS); |
michael@0 | 36 | dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale); |
michael@0 | 37 | |
michael@0 | 38 | var ds = this._rdfService.GetDataSource(dsURI); |
michael@0 | 39 | var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource) |
michael@0 | 40 | if (rds.loaded) |
michael@0 | 41 | this.onDatasourceLoaded(ds, aPluginRequestItem); |
michael@0 | 42 | else { |
michael@0 | 43 | var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink); |
michael@0 | 44 | sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem)); |
michael@0 | 45 | } |
michael@0 | 46 | }, |
michael@0 | 47 | |
michael@0 | 48 | onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem) { |
michael@0 | 49 | var container = Components.classes["@mozilla.org/rdf/container;1"] |
michael@0 | 50 | .createInstance(Components.interfaces.nsIRDFContainer); |
michael@0 | 51 | var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype); |
michael@0 | 52 | var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true); |
michael@0 | 53 | |
michael@0 | 54 | var pluginInfo = null; |
michael@0 | 55 | |
michael@0 | 56 | try { |
michael@0 | 57 | container.Init(aDatasource, pluginList); |
michael@0 | 58 | |
michael@0 | 59 | var children = container.GetElements(); |
michael@0 | 60 | var target; |
michael@0 | 61 | |
michael@0 | 62 | // get the first item |
michael@0 | 63 | var child = children.getNext(); |
michael@0 | 64 | if (child instanceof Components.interfaces.nsIRDFResource) { |
michael@0 | 65 | var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates"); |
michael@0 | 66 | target = aDatasource.GetTarget(child, name, true); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | try { |
michael@0 | 70 | container.Init(aDatasource, target); |
michael@0 | 71 | target = null; |
michael@0 | 72 | children = container.GetElements(); |
michael@0 | 73 | |
michael@0 | 74 | var child = children.getNext(); |
michael@0 | 75 | if (child instanceof Components.interfaces.nsIRDFResource) { |
michael@0 | 76 | target = child; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | var rdfs = this._rdfService; |
michael@0 | 80 | |
michael@0 | 81 | function getPFSValueFromRDF(aValue) { |
michael@0 | 82 | var rv = null; |
michael@0 | 83 | |
michael@0 | 84 | var myTarget = aDatasource.GetTarget(target, rdfs.GetResource(PFS_NS + aValue), true); |
michael@0 | 85 | if (myTarget) |
michael@0 | 86 | rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value; |
michael@0 | 87 | |
michael@0 | 88 | return rv; |
michael@0 | 89 | } |
michael@0 | 90 | |
michael@0 | 91 | pluginInfo = { |
michael@0 | 92 | name: getPFSValueFromRDF("name"), |
michael@0 | 93 | pid: getPFSValueFromRDF("guid"), |
michael@0 | 94 | version: getPFSValueFromRDF("version"), |
michael@0 | 95 | IconUrl: getPFSValueFromRDF("IconUrl"), |
michael@0 | 96 | InstallerLocation: getPFSValueFromRDF("InstallerLocation"), |
michael@0 | 97 | InstallerHash: getPFSValueFromRDF("InstallerHash"), |
michael@0 | 98 | XPILocation: getPFSValueFromRDF("XPILocation"), |
michael@0 | 99 | XPIHash: getPFSValueFromRDF("XPIHash"), |
michael@0 | 100 | InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"), |
michael@0 | 101 | manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"), |
michael@0 | 102 | requestedMimetype: getPFSValueFromRDF("requestedMimetype"), |
michael@0 | 103 | licenseURL: getPFSValueFromRDF("licenseURL"), |
michael@0 | 104 | needsRestart: getPFSValueFromRDF("needsRestart") |
michael@0 | 105 | }; |
michael@0 | 106 | } |
michael@0 | 107 | catch (ex) { |
michael@0 | 108 | Components.utils.reportError(ex); |
michael@0 | 109 | } |
michael@0 | 110 | } |
michael@0 | 111 | catch (ex) { |
michael@0 | 112 | Components.utils.reportError(ex); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | gPluginInstaller.pluginInfoReceived(aPluginRequestItem, pluginInfo); |
michael@0 | 116 | }, |
michael@0 | 117 | |
michael@0 | 118 | onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError) { |
michael@0 | 119 | this._os.notifyObservers(aPluginRequestItem, "error", aError); |
michael@0 | 120 | Components.utils.reportError(aError); |
michael@0 | 121 | gPluginInstaller.pluginInfoReceived(aPluginRequestItem, null); |
michael@0 | 122 | } |
michael@0 | 123 | }; |
michael@0 | 124 | |
michael@0 | 125 | function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem) { |
michael@0 | 126 | this._updater = aUpdater; |
michael@0 | 127 | this._item = aPluginRequestItem; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | nsPluginXMLRDFDSObserver.prototype = |
michael@0 | 131 | { |
michael@0 | 132 | _updater : null, |
michael@0 | 133 | _item : null, |
michael@0 | 134 | |
michael@0 | 135 | // nsIRDFXMLSinkObserver |
michael@0 | 136 | onBeginLoad: function(aSink) {}, |
michael@0 | 137 | onInterrupt: function(aSink) {}, |
michael@0 | 138 | onResume: function(aSink) {}, |
michael@0 | 139 | onEndLoad: function(aSink) { |
michael@0 | 140 | aSink.removeXMLSinkObserver(this); |
michael@0 | 141 | |
michael@0 | 142 | var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource); |
michael@0 | 143 | this._updater.onDatasourceLoaded(ds, this._item); |
michael@0 | 144 | }, |
michael@0 | 145 | |
michael@0 | 146 | onError: function(aSink, aStatus, aErrorMsg) { |
michael@0 | 147 | aSink.removeXMLSinkObserver(this); |
michael@0 | 148 | this._updater.onDatasourceError(this._item, aStatus.toString()); |
michael@0 | 149 | } |
michael@0 | 150 | }; |