Extension Manager UI and updater web service - not enabled yet - bug 170006

This commit is contained in:
ben%bengoodger.com 2004-04-06 00:31:11 +00:00
Родитель a7ad5b9cfc
Коммит 60266e36f7
8 изменённых файлов: 378 добавлений и 8 удалений

Просмотреть файл

@ -365,10 +365,9 @@ var gExtensionsViewController = {
cmd_update: function ()
{
if (gWindowState == "extensions")
gExtensionManager.updateExtension(gExtensionsView.selected ? stripPrefix(gExtensionsView.selected.id) : null);
else if (gWindowState == "themes")
gExtensionManager.updateTheme(gExtensionsView.selected ? stripPrefix(gExtensionsView.selected.id) : null);
openDialog("chrome://mozapps/content/extensions/update.xul", "", "chrome,modal",
gWindowState, gExtensionManager,
gExtensionsView.selected ? stripPrefix(gExtensionsView.selected.id) : null);
},
cmd_uninstall: function ()

Просмотреть файл

@ -0,0 +1,104 @@
var gUpdateDialog = {
_updateType: "",
_extensionManager: "",
_extensionID: "",
_messages: ["update-start",
"update-end",
"update-item-network-start",
"update-item-network-end",
"update-item-processing-start",
"update-item-processing-end",
"update-item-error"],
init: function ()
{
this._updateType = window.arguments[0];
this._extensionManager = window.arguments[1];
this._extensionID = window.arguments[2];
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
for (var i = 0; i < this._messages.length; ++i)
os.addObserver(this, this._messages[i], false);
if (this._updateType == "extensions")
this._extensionManager.updateExtension(this._extensionID);
else if (gUpdateType == "themes")
this._extensionManager.updateTheme(this._extensionID);
},
observe: function (aSubject, aTopic, aData)
{
switch (aTopic) {
case "update-start":
dump("*** update-start: " + aSubject + ", " + aData + "\n");
break;
case "update-item-network-start":
dump("*** update-item-network-start: " + aSubject + ", " + aData + "\n");
break;
case "update-item-network-end":
dump("*** update-item-network-end: " + aSubject + ", " + aData + "\n");
break;
case "update-item-processing-start":
dump("*** update-item-processing-start: " + aSubject + ", " + aData + "\n");
break;
case "update-item-processing-end":
dump("*** update-item-processing-end: " + aSubject + ", " + aData + "\n");
break;
case "update-item-error":
dump("*** update-item-error: " + aSubject + ", " + aData + "\n");
break;
case "update-end":
dump("*** update-end: " + aSubject + ", " + aData + "\n");
// Report Status
// Unhook observers
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
for (var i = 0; i < this._messages.length; ++i)
os.removeObserver(this, this._messages[i]);
break;
}
}
};
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Extension Manager.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

Просмотреть файл

@ -0,0 +1,69 @@
<?xml version="1.0"?>
# -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is The Extension Manager.
#
# The Initial Developer of the Original Code is Ben Goodger.
# Portions created by the Initial Developer are Copyright (C) 2004
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ben Goodger <ben@bengoodger.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<?xml-stylesheet href="chrome://mozapps/skin/extensions/about.css" type="text/css"?>
<!DOCTYPE dialog [
<!ENTITY % updateDTD SYSTEM "chrome://mozapps/locale/extensions/update.dtd">
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd">
%updateDTD;
%brandDTD;
]>
<dialog id="updateProgress" title="&update.title;"
style="width: 30em;"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
buttons="cancel" onload="gUpdateDialog.init();" oncancel="onCancelUpdateCheck();">
<script type="application/x-javascript" src="chrome://mozapps/content/extensions/update.js"/>
<stringbundleset id="updateSet">
<stringbundle id="extensionsStrings" src="chrome://mozapps/locale/extensions/extensions.properties"/>
</stringbundleset>
<label>&intro.label;</label>
<description id="items"/>
<progressmeter id="progress"/>
<description id="status"/>
</dialog>

Просмотреть файл

@ -11,3 +11,8 @@ restartBeforeUninstallMessage=%S will be uninstalled the next time you restart %
queryUninstallExtensionMessage=If you uninstall %S, the functionality it offers will no longer be available. Do you want to uninstall %S?
queryUninstallThemeMessage=Do you want to uninstall %S?
queryUninstallTitle=Uninstall %S
statusConnecting=Connecting to %S, please wait...
statusProcessing=Processing data...
statusConnectionFailed=Connection to %S failed, skipping...
progress=(%S of %S items complete)

Просмотреть файл

@ -0,0 +1,5 @@
<!ENTITY update.title "Checking for Updates">
<!ENTITY intro.label "&brandShortName; is now checking for updates to:">

Просмотреть файл

@ -0,0 +1,84 @@
import java.sql.*;
public class VersionCheck
{
protected Connection getConnection()
{
Class.forName("com.mysql.jdbc.Driver");
return DriverManager.getConnection("jdbc:mysql://localhost/", "", "");
}
public class VersionResult
{
public String xpiURL;
public int version;
}
public VersionResult checkVersion(String aExtensionGUID, String aInstalledVersion, String aTargetApp, String aTargetAppVersion)
{
int extensionVersionParts = getPartCount(aInstalledVersion);
int extensionVersion = parseVersion(aInstalledVersion, extensionVersionParts);
int targetAppVersionParts = getPartCount(aTargetAppVersion);
int targetAppVersion = parseVersion(aTargetAppVersion, targetAppVersionParts);
Connection c = getConnection();
Statement 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 + "'";
ResultSet rs = s.executeQuery(sql);
String xpiURL = "";
int newestExtensionVersion = extensionVersion;
while (rs.next())
{
int minTargetAppVersion = parseVersion(rs.getObject("mintargetappversion").toString(), targetAppVersionParts);
int maxTargetAppVersion = parseVersion(rs.getObject("maxtargetappversion").toString(), targetAppVersionParts);
int version = parseVersion(rs.getObject("version").toString(), extensionVersionParts);
if (version > extensionVersion &&
version > newestExtensionVersion &&
minTargetAppVersion <= targetAppVersion &&
targetAppVersion < maxTargetAppVersion)
{
newestExtensionVersion = version;
xpiURL = rs.getObject("xpiurl").toString();
}
}
rs.close();
VersionResult vr = new VersionResult();
vr.xpiURL = xpiURL;
vr.version = newestExtensionVersion;
return vr;
}
protected int parseVersion(String aVersionString, int aPower)
{
int version = 0;
String[] parts = aVersionString.split(".");
if (aPower == 0)
aPower = parts.length;
for (int i = 0; i < parts.length; ++i)
{
if (parts[i] != "+")
{
version += Integer.parseInt(parts[i]) * Math.pow(10, aPower - i);
}
}
}
protected int getPartCount(String aVersionString)
{
return aVersionString.split(".").length;
}
}

Просмотреть файл

@ -101,7 +101,110 @@ nsExtensionManager.prototype = {
updateExtension: function (aExtensionID)
{
this._ds.getUpdateURLs(aExtensionID);
var os = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var itemCount = 0;
var proxy = null;
function getResults()
{
if (proxy) {
proxy.count();
proxy.contents();
}
}
if (!proxy) {
var listener = {
onLoad: function (aProxy)
{
proxy = aProxy;
proxy.setListener(this);
getResults();
},
onError: function (aError)
{
dump("*** onError ERROR = " + aError + "\n");
},
countCallback: function (aResult)
{
this._count = aResult;
},
contentsCallback: function (aResult)
{
for (var i = 0; i < this._count; ++i)
dump("*** quote " + i + " = " + aResult[i] + "\n");
},
};
var wspFactory = Components.classes["@mozilla.org/xmlextras/proxy/webserviceproxyfactory;1"]
.getService(Components.interfaces.nsIWebServiceProxyFactory);
wspFactory.createProxyAsync("http://localhost:8080/axis/quote.wsdl",
"Quote", "", true, listener);
}
else
getResults();
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);
}
},
// Themes
@ -262,13 +365,11 @@ nsExtensionsDataSource.prototype = {
var urlCount = urlHash[url].length;
for (var i = 0; i < urlCount; ++i)
guidString += escape(urlHash[url][i] + (i < urlCount - 1 ? "," : ""));
dump("*** guidString = " + guidString + "\n");
url = url.replace(/%APP%/g, appID);
url = url.replace(/%ITEM%/g, guidString);
urls.push(url);
}
}
dump("*** urls = " + urls + "\n");
return urls;
},

Просмотреть файл

@ -19,6 +19,8 @@ toolkit.jar:
* content/mozapps/extensions/extensions.css (extensions/content/extensions.css)
* content/mozapps/extensions/about.xul (extensions/content/about.xul)
* content/mozapps/extensions/about.js (extensions/content/about.js)
* content/mozapps/extensions/update.xul (extensions/content/update.xul)
* content/mozapps/extensions/update.js (extensions/content/update.js)
* content/mozapps/shared/richview.xml (shared/content/richview.xml)
content/mozapps/contents.rdf (contents-content.rdf)
@ -33,6 +35,7 @@ en-US.jar:
locale/en-US/mozapps/extensions/extensions.dtd (extensions/locale/extensions.dtd)
locale/en-US/mozapps/extensions/extensions.properties (extensions/locale/extensions.properties)
locale/en-US/mozapps/extensions/about.dtd (extensions/locale/about.dtd)
locale/en-US/mozapps/extensions/update.dtd (extensions/locale/update.dtd)
locale/en-US/mozapps/contents.rdf (contents-locale.rdf)
classic.jar: