!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
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/
8 *
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
12 * License.
13 *
14 * The Original Code is Plugin Finder Service.
15 *
16 * The Initial Developer of the Original Code is
17 * IBM Corporation.
18 * Portions created by the IBM Corporation are Copyright (C) 2004-2005
19 * IBM Corporation. All Rights Reserved.
20 *
21 * Contributor(s):
22 * Doron Rosenberg <doronr@us.ibm.com>
23 *
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.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
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#";
40
nsRDFItemUpdater
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
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);
46
47 var app = Components.classes["@mozilla.org/xre/app-info;1"]
48 .getService(Components.interfaces.nsIXULAppInfo);
49 this.appID = app.ID;
50 this.buildID = app.platformBuildID;
51
52 this.clientOS = aClientOS;
53 this.chromeLocale = aChromeLocale;
54
55 var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
56 .getService(Components.interfaces.nsIPrefBranch);
57 this.dsURI = prefBranch.getCharPref("pfs.datasource.url");
58 }
59
60 nsRDFItemUpdater.prototype = {
checkForPlugin
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
61 checkForPlugin: function (aPluginRequestItem){
62 var dsURI = this.dsURI;
63 // escape the mimetype as mimetypes can contain '+', which will break pfs.
64 dsURI = dsURI.replace(/%PLUGIN_MIMETYPE%/g, encodeURIComponent(aPluginRequestItem.mimetype));
65 dsURI = dsURI.replace(/%APP_ID%/g, this.appID);
66 dsURI = dsURI.replace(/%APP_VERSION%/g, this.buildID);
67 dsURI = dsURI.replace(/%CLIENT_OS%/g, this.clientOS);
68 dsURI = dsURI.replace(/%CHROME_LOCALE%/g, this.chromeLocale);
69
70 var ds = this._rdfService.GetDataSource(dsURI);
71 var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource)
72 if (rds.loaded)
73 this.onDatasourceLoaded(ds, aPluginRequestItem);
74 else {
75 var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
76 sink.addXMLSinkObserver(new nsPluginXMLRDFDSObserver(this, aPluginRequestItem));
77 }
78 },
79
pfs_onDatasourceLoaded
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
80 onDatasourceLoaded: function pfs_onDatasourceLoaded (aDatasource, aPluginRequestItem){
81 var container = Components.classes["@mozilla.org/rdf/container;1"].
82 createInstance(Components.interfaces.nsIRDFContainer);
83 var resultRes = this._rdfService.GetResource("urn:mozilla:plugin-results:" + aPluginRequestItem.mimetype);
84 var pluginList = aDatasource.GetTarget(resultRes, this._rdfService.GetResource(PFS_NS+"plugins"), true);
85
86 var pluginInfo = null;
87
88 container = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
89 try {
90 container.Init(aDatasource, pluginList);
91
92 var children = container.GetElements();
93 var target;
94
95 // get the first item
96 var child = children.getNext();
97 if (child instanceof Components.interfaces.nsIRDFResource){
98 var name = this._rdfService.GetResource("http://www.mozilla.org/2004/pfs-rdf#updates");
99 target = aDatasource.GetTarget(child, name, true);
100 }
101
102 try {
103 container.Init(aDatasource, target);
104 target = null;
105 children = container.GetElements();
106
107 var child = children.getNext();
108 if (child instanceof Components.interfaces.nsIRDFResource){
109 target = child;
110 }
111
112 var rdfs = this._rdfService;
113
getPFSValueFromRDF
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
114 function getPFSValueFromRDF(aValue){
115 var rv = null;
116
117 var myTarget = aDatasource.GetTarget(target, rdfs.GetResource(PFS_NS + aValue), true);
118 if (myTarget)
119 rv = myTarget.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
120
121 return rv;
122 }
123
124 pluginInfo = {
125 name: getPFSValueFromRDF("name"),
126 pid: getPFSValueFromRDF("guid"),
127 version: getPFSValueFromRDF("version"),
128 IconUrl: getPFSValueFromRDF("IconUrl"),
129 InstallerLocation: getPFSValueFromRDF("InstallerLocation"),
130 InstallerHash: getPFSValueFromRDF("InstallerHash"),
131 XPILocation: getPFSValueFromRDF("XPILocation"),
132 XPIHash: getPFSValueFromRDF("XPIHash"),
133 InstallerShowsUI: getPFSValueFromRDF("InstallerShowsUI"),
134 manualInstallationURL: getPFSValueFromRDF("manualInstallationURL"),
135 requestedMimetype: getPFSValueFromRDF("requestedMimetype"),
136 licenseURL: getPFSValueFromRDF("licenseURL"),
137 needsRestart: getPFSValueFromRDF("needsRestart")
138 };
139 }
140 catch (ex){}
141 }
142 catch (ex){}
143
144 gPluginInstaller.pluginInfoReceived(pluginInfo);
145 },
146
pfs_onDatasourceError
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
147 onDatasourceError: function pfs_onDatasourceError (aPluginRequestItem, aError){
148 this._os.notifyObservers(aPluginRequestItem, "error", aError);
149 gPluginInstaller.pluginInfoReceived(null);
150 }
151 };
152
nsPluginXMLRDFDSObserver
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
153 function nsPluginXMLRDFDSObserver(aUpdater, aPluginRequestItem){
154 this._updater = aUpdater;
155 this._item = aPluginRequestItem;
156 }
157
158 nsPluginXMLRDFDSObserver.prototype =
159 {
160 _updater : null,
161 _item : null,
162
163 // nsIRDFXMLSinkObserver
onBeginLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
164 onBeginLoad: function(aSink){},
onInterrupt
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
165 onInterrupt: function(aSink){},
onResume
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
166 onResume: function(aSink){},
onEndLoad
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
167 onEndLoad: function(aSink){
168 aSink.removeXMLSinkObserver(this);
169
170 var ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
171 this._updater.onDatasourceLoaded(ds, this._item);
172 },
173
onError
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
174 onError: function(aSink, aStatus, aErrorMsg){
175 aSink.removeXMLSinkObserver(this);
176 this._updater.onDatasourceError(this._item, aStatus.toString());
177 }
178 };