mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
More 170006 - extension manager update checker service, not available yet.
This commit is contained in:
parent
15728f287e
commit
5438bb8278
@ -24,7 +24,7 @@ var gUpdateDialog = {
|
||||
os.addObserver(this, this._messages[i], false);
|
||||
|
||||
if (this._updateType == "extensions")
|
||||
this._extensionManager.updateExtension(this._extensionID);
|
||||
this._extensionManager.updateExtension(this._extensionID, window);
|
||||
else if (gUpdateType == "themes")
|
||||
this._extensionManager.updateTheme(this._extensionID);
|
||||
},
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
interface nsIInputStream;
|
||||
interface nsIRDFDataSource;
|
||||
interface nsIDOMWindowInternal;
|
||||
|
||||
[scriptable, uuid(c3515b0f-99f4-453b-805e-1fdf5724d6d9)]
|
||||
interface nsIExtensionManager : nsISupports
|
||||
@ -48,7 +49,9 @@ interface nsIExtensionManager : nsISupports
|
||||
void uninstallExtension(in string aExtensionID);
|
||||
void enableExtension(in string aExtensionID);
|
||||
void disableExtension(in string aExtensionID);
|
||||
void updateExtension(in string aExtensionID);
|
||||
/* aDOMWindow param here is temporary hack until xpinstall trigger is accessible
|
||||
via xpconnect */
|
||||
void updateExtension(in string aExtensionID, in nsIDOMWindowInternal aDOMWindow);
|
||||
|
||||
void installTheme(in string aThemeID);
|
||||
void uninstallTheme(in string aThemeID);
|
||||
|
@ -35,9 +35,17 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
/**
|
||||
* VersionCheckSoapBindingImpl.java
|
||||
*
|
||||
* This file was auto-generated from WSDL
|
||||
* by the Apache Axis WSDL2Java emitter.
|
||||
*/
|
||||
|
||||
package org.mozilla.update.extensions;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class VersionCheck
|
||||
{
|
||||
@ -45,24 +53,30 @@ public class VersionCheck
|
||||
{
|
||||
}
|
||||
|
||||
protected Connection getConnection()
|
||||
public static void main(String[] args) throws Exception
|
||||
{
|
||||
Connection c = null;
|
||||
try
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
c = DriverManager.getConnection("jdbc:mysql://localhost/", "", "");
|
||||
VersionCheckSoapBindingImpl impl = new VersionCheckSoapBindingImpl();
|
||||
int id = impl.getNewestExtension("{bb8ee064-ccb9-47fc-94ae-ec335af3fe2d}", "3.0", "{ec8030f7-c20a-464f-9b0e-13a3a9e97384}", "0.8.0+");
|
||||
System.out.println("result = " + impl.getProperty(id, "xpiurl"));
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("e = " + e.getMessage());
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
protected Connection getConnection() throws Exception
|
||||
{
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
return DriverManager.getConnection("jdbc:mysql://localhost/umo_extensions", "root", "");
|
||||
}
|
||||
|
||||
public String getProperty(int aRowID, String aProperty)
|
||||
{
|
||||
String result = null;
|
||||
try
|
||||
try
|
||||
{
|
||||
Connection c = getConnection();
|
||||
Statement s = c.createStatement();
|
||||
@ -71,38 +85,44 @@ public class VersionCheck
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
|
||||
result = rs.next() ? rs.getString(aProperty) : null;
|
||||
if (result == null)
|
||||
result = "query succeeded, but null!";
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
result = e.getMessage();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public int getNewestExtension(String aExtensionGUID,
|
||||
String aInstalledVersion,
|
||||
String aTargetApp,
|
||||
String aTargetAppVersion)
|
||||
String aInstalledVersion,
|
||||
String aTargetApp,
|
||||
String aTargetAppVersion)
|
||||
{
|
||||
int id = -1;
|
||||
int extensionVersionParts = getPartCount(aInstalledVersion);
|
||||
int targetAppVersionParts = getPartCount(aTargetAppVersion);
|
||||
|
||||
int extensionVersion = parseVersion(aInstalledVersion, extensionVersionParts);
|
||||
int targetAppVersion = parseVersion(aTargetAppVersion, targetAppVersionParts);
|
||||
|
||||
Connection c;
|
||||
Statement s;
|
||||
ResultSet rs;
|
||||
try
|
||||
{
|
||||
int extensionVersionParts = getPartCount(aInstalledVersion);
|
||||
int targetAppVersionParts = getPartCount(aTargetAppVersion);
|
||||
|
||||
int extensionVersion = parseVersion(aInstalledVersion, extensionVersionParts);
|
||||
int targetAppVersion = parseVersion(aTargetAppVersion, targetAppVersionParts);
|
||||
|
||||
Connection c = getConnection();
|
||||
|
||||
Statement s = c.createStatement();
|
||||
|
||||
c = getConnection();
|
||||
s = c.createStatement();
|
||||
|
||||
// We need to find all rows matching aExtensionGUID, and filter like so:
|
||||
// 1) version > extensionVersion
|
||||
// 2) targetapp == aTargetApp
|
||||
// 3) mintargetappversion <= targetAppVersion <= maxtargetappversion
|
||||
String sql = "SELECT * FROM extensions WHERE targetapp = '" + aTargetAppVersion + "'AND guid = '" + aExtensionGUID + "'";
|
||||
String sql = "SELECT * FROM extensions WHERE guid = '" + aExtensionGUID + "' AND targetapp = '" + aTargetApp + "'";
|
||||
|
||||
ResultSet rs = s.executeQuery(sql);
|
||||
boolean goat = s.execute(sql);
|
||||
rs = s.getResultSet();
|
||||
|
||||
int newestExtensionVersion = extensionVersion;
|
||||
|
||||
@ -122,6 +142,8 @@ public class VersionCheck
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
s.close();
|
||||
c.close();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -133,23 +155,30 @@ public class VersionCheck
|
||||
protected int parseVersion(String aVersionString, int aPower)
|
||||
{
|
||||
int version = 0;
|
||||
String[] parts = aVersionString.split(".");
|
||||
StringTokenizer tokenizer = new StringTokenizer(aVersionString, ".");
|
||||
|
||||
if (aPower == 0)
|
||||
aPower = parts.length;
|
||||
aPower = tokenizer.countTokens();
|
||||
|
||||
for (int i = 0; i < parts.length; ++i)
|
||||
for (int i = 0; tokenizer.hasMoreTokens(); ++i)
|
||||
{
|
||||
if (parts[i] != "+")
|
||||
String token = tokenizer.nextToken();
|
||||
if (token.endsWith("+"))
|
||||
{
|
||||
version += Integer.parseInt(parts[i]) * Math.pow(10, aPower - i);
|
||||
token = token.substring(0, token.lastIndexOf("+"));
|
||||
version += 1;
|
||||
if (token.length() == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
version += Integer.parseInt(token) * Math.pow(10, aPower - i);
|
||||
}
|
||||
return version;
|
||||
}
|
||||
|
||||
protected int getPartCount(String aVersionString)
|
||||
{
|
||||
return aVersionString.split(".").length;
|
||||
return (new StringTokenizer(aVersionString, ".")).countTokens();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,120 +99,31 @@ nsExtensionManager.prototype = {
|
||||
this._ds.disableExtension(aExtensionID);
|
||||
},
|
||||
|
||||
updateExtension: function (aExtensionID)
|
||||
updateExtension: function (aExtensionID, aDOMWindow)
|
||||
{
|
||||
var pref = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
var appID = pref.getCharPref(PREF_EM_APP_ID);
|
||||
var appVersion = pref.getCharPref(PREF_EM_APP_VERSION);
|
||||
|
||||
var extensionVersion = this._ds.getExtensionProperty(aExtensionID, "version");
|
||||
|
||||
var os = Components.classes["@mozilla.org/observer-service;1"]
|
||||
.getService(Components.interfaces.nsIObserverService);
|
||||
var ds = this._ds;
|
||||
var extensionVersion = ds.getExtensionProperty(aExtensionID, "version");
|
||||
|
||||
var itemCount = 0;
|
||||
|
||||
var proxy = null;
|
||||
function getExtensionUpdateURL(aExtensionGUID, aInstalledVersion,
|
||||
aTargetApp, aTargetAppVersion)
|
||||
|
||||
var trigger = aDOMWindow.InstallTrigger;
|
||||
|
||||
function doneUpdatingExtension(aExtensionID, aXPIURL)
|
||||
{
|
||||
proxy.getNewestExtension(aExtensionGUID, aInstalledVersion, aTargetApp, aTargetAppVersion);
|
||||
var name = ds.getExtensionProperty(aExtensionID, "name");
|
||||
var obj = {};
|
||||
obj[name] = aXPIURL;
|
||||
if (trigger.updateEnabled())
|
||||
trigger.install(obj);
|
||||
}
|
||||
|
||||
if (!proxy) {
|
||||
var listener = {
|
||||
onLoad: function (aProxy)
|
||||
{
|
||||
proxy = aProxy;
|
||||
proxy.setListener(this);
|
||||
getExtensionUpdateURL(aExtensionID, extensionVersion, appID, appVersion);
|
||||
},
|
||||
|
||||
onError: function (aError)
|
||||
{
|
||||
dump("*** onError ERROR = " + aError + "\n");
|
||||
},
|
||||
|
||||
getNewestExtensionCallback: function (aResult)
|
||||
{
|
||||
this._newestID = aResult;
|
||||
dump("*** getNewestExtensionCallback result = " + aResult + "\n");
|
||||
|
||||
if (this._newestID != -1)
|
||||
proxy.getProperty(this._newestID, "xpiurl");
|
||||
},
|
||||
|
||||
getPropertyCallback: function (aResult)
|
||||
{
|
||||
dump("*** UPDATE URL = " + aResult + "\n");
|
||||
}
|
||||
};
|
||||
|
||||
var wspFactory = Components.classes["@mozilla.org/xmlextras/proxy/webserviceproxyfactory;1"]
|
||||
.getService(Components.interfaces.nsIWebServiceProxyFactory);
|
||||
wspFactory.createProxyAsync("http://localhost:8080/axis/services/VersionCheck?wsdl",
|
||||
"VersionCheck", "", true, listener);
|
||||
}
|
||||
else
|
||||
getExtensionUpdateURL(aExtensionID, extensionVersion, appID, appVersion);
|
||||
|
||||
return;
|
||||
|
||||
function RDFSinkObserver()
|
||||
{
|
||||
}
|
||||
RDFSinkObserver.prototype = {
|
||||
onBeginLoad: function (aSink)
|
||||
{
|
||||
os.notifyObservers(aSink, "update-item-network-start", "");
|
||||
},
|
||||
onInterrupt: function (aSink) { },
|
||||
onResume: function (aSink) { },
|
||||
onError: function (aSink, aStatus, aErrorMsg)
|
||||
{
|
||||
dump("*** error; status = " + aStatus + ", msg = " + aErrorMsg + "\n");
|
||||
if (aStatus == Components.results.NS_ERROR_FILE_NOT_FOUND)
|
||||
dump("*** FILE NOT FOUND BOZO\n");
|
||||
aSink.removeXMLSinkObserver(this);
|
||||
os.notifyObservers(aSink, "update-item-error", aErrorMsg);
|
||||
this._checkLastItem();
|
||||
},
|
||||
onEndLoad: function (aSink)
|
||||
{
|
||||
dump("*** done!\n");
|
||||
os.notifyObservers(aSink, "update-item-network-end", "");
|
||||
aSink.removeXMLSinkObserver(this);
|
||||
os.notifyObservers(aSink, "update-item-processing-start", "");
|
||||
dump("*** processing...\n");
|
||||
os.notifyObservers(aSink, "update-item-processing-end", "");
|
||||
this._checkLastItem();
|
||||
},
|
||||
|
||||
_checkLastItem: function ()
|
||||
{
|
||||
if (--itemCount == 0)
|
||||
os.notifyObservers(null, "update-end", "");
|
||||
}
|
||||
};
|
||||
|
||||
os.notifyObservers(null, "update-start", "");
|
||||
|
||||
var urls = this._ds.getUpdateURLs(aExtensionID);
|
||||
var rdfs = Components.classes["@mozilla.org/rdf/rdf-service;1"]
|
||||
.getService(Components.interfaces.nsIRDFService);
|
||||
itemCount = urls.length;
|
||||
for (var i = 0; i < urls.length; ++i) {
|
||||
var observer = new RDFSinkObserver();
|
||||
|
||||
var ds = rdfs.GetDataSource(urls[i]);
|
||||
dump("*** starting " + ds.URI + "\n");
|
||||
var sink = ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
|
||||
var rds = ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
|
||||
if (rds.loaded)
|
||||
observer.onEndLoad(sink);
|
||||
else
|
||||
sink.addXMLSinkObserver(observer);
|
||||
}
|
||||
var updater = new nsExtensionUpdater(aExtensionID, extensionVersion, appID, appVersion);
|
||||
updater.checkForUpdates(doneUpdatingExtension);
|
||||
},
|
||||
|
||||
// Themes
|
||||
@ -264,6 +175,65 @@ nsExtensionManager.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
function nsExtensionUpdater(aExtensionID, aExtensionVersion,
|
||||
aTargetAppID, aTargetAppVersion)
|
||||
{
|
||||
this._extensionID = aExtensionID;
|
||||
this._extensionVersion = aExtensionVersion;
|
||||
this._appID = aTargetAppID;
|
||||
this._appVersion = aTargetAppVersion;
|
||||
}
|
||||
|
||||
nsExtensionUpdater.prototype = {
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
checkForUpdates: function (aDoneUpdatingFunc)
|
||||
{
|
||||
this._doneUpdatingFunc = aDoneUpdatingFunc;
|
||||
|
||||
var wspFactory = Components.classes["@mozilla.org/xmlextras/proxy/webserviceproxyfactory;1"]
|
||||
.getService(Components.interfaces.nsIWebServiceProxyFactory);
|
||||
wspFactory.createProxyAsync("http://localhost:8080/axis/services/VersionCheck?wsdl",
|
||||
"VersionCheck", "", true, this);
|
||||
},
|
||||
|
||||
_proxy: null,
|
||||
|
||||
_getExtensionUpdateURL: function (aExtensionGUID, aInstalledVersion,
|
||||
aTargetApp, aTargetAppVersion)
|
||||
{
|
||||
this._proxy.getNewestExtension(aExtensionGUID, aInstalledVersion, aTargetApp, aTargetAppVersion);
|
||||
},
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// nsIWSDLLoadListener
|
||||
onLoad: function (aProxy)
|
||||
{
|
||||
this._proxy = aProxy;
|
||||
this._proxy.setListener(this);
|
||||
this._getExtensionUpdateURL(this._extensionID, this._extensionVersion, this._appID, this._appVersion);
|
||||
},
|
||||
|
||||
onError: function (aError)
|
||||
{
|
||||
dump("*** onError ERROR = " + aError + "\n");
|
||||
},
|
||||
|
||||
getNewestExtensionCallback: function (aResult)
|
||||
{
|
||||
this._newestID = aResult;
|
||||
|
||||
if (this._newestID != -1)
|
||||
this._proxy.getProperty(this._newestID, "xpiurl");
|
||||
},
|
||||
|
||||
getPropertyCallback: function (aResult)
|
||||
{
|
||||
this._doneUpdatingFunc(this._extensionID, aResult);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const PREF_EM_DEFAULTUPDATEURL = "update.url.extensions";
|
||||
const PREF_EM_APP_ID = "app.id";
|
||||
const PREF_EM_APP_VERSION = "general.useragent.vendorSub";
|
||||
|
Loading…
Reference in New Issue
Block a user