Fix the Downlaod Manager to not be totally hoarked on Mac, by not using hiddenWindow.xul as an overlay, and fixing mismatches between persistent descriptors and full paths in the code. r=ccarlen, sr=jag

This commit is contained in:
sfraser%netscape.com 2002-12-30 22:06:13 +00:00
Родитель 2af4d47c8a
Коммит b0fa6129c2
13 изменённых файлов: 280 добавлений и 54 удалений

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

@ -26,8 +26,15 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
DIRS = win
else
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
DIRS = mac
DIRS = mac
else
DIRS = unix
endif
endif
include $(topsrcdir)/config/rules.mk

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

@ -61,8 +61,8 @@ function selectDownload(aDownload)
gDownloadView.treeBoxObject.ensureRowIsVisible(dlIndex);
}
function Startup()
{
function DLManagerStartup()
{
if (!window.arguments.length)
return;
@ -162,7 +162,8 @@ var downloadViewController = {
if (!selectionCount) return false;
var selectedItem = getSelectedItem();
var isDownloading = gDownloadManager.getDownload(selectedItem.id);
var isDownloading = selectedItem && gDownloadManager.getDownload(selectedItem.id);
switch (aCommand) {
case "cmd_openfile":
try {
@ -187,7 +188,7 @@ var downloadViewController = {
case "cmd_remove":
// XXX ensure selection isn't still in progress
// and how to handle multiple selection?
return !isDownloading;
return selectionCount > 0 && !isDownloading;
case "cmd_selectAll":
return gDownloadView.view.rowCount != selectionCount;
default:
@ -203,28 +204,33 @@ var downloadViewController = {
switch (aCommand) {
case "cmd_properties":
selectedItem = getSelectedItem();
gDownloadManager.openProgressDialogFor(selectedItem.id, window);
if (selectedItem)
gDownloadManager.openProgressDialogFor(selectedItem.id, window);
break;
case "cmd_openfile":
selectedItem = getSelectedItem();
file = getFileForItem(selectedItem);
file.launch();
if (selectedItem) {
file = getFileForItem(selectedItem);
file.launch();
}
break;
case "cmd_showinshell":
selectedItem = getSelectedItem();
file = getFileForItem(selectedItem);
// on unix, open a browser window rooted at the parent
if (navigator.platform.indexOf("Win") == -1 && navigator.platform.indexOf("Mac") == -1) {
file = file.QueryInterface(Components.interfaces.nsIFile);
var parent = file.parent;
if (parent) {
const browserURL = "chrome://navigator/content/navigator.xul";
window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", parent.path);
if (selectedItem) {
file = getFileForItem(selectedItem);
// on unix, open a browser window rooted at the parent
if (navigator.platform.indexOf("Win") == -1 && navigator.platform.indexOf("Mac") == -1) {
file = file.QueryInterface(Components.interfaces.nsIFile);
var parent = file.parent;
if (parent) {
const browserURL = "chrome://navigator/content/navigator.xul";
window.openDialog(browserURL, "_blank", "chrome,all,dialog=no", parent.path);
}
}
else {
file.reveal();
}
}
else {
file.reveal();
}
break;
case "cmd_pause":
@ -296,7 +302,9 @@ var downloadViewController = {
function getSelectedItem()
{
return gDownloadView.contentView.getItemAtIndex(gDownloadView.currentIndex);
if (gDownloadView.currentIndex != -1)
return gDownloadView.contentView.getItemAtIndex(gDownloadView.currentIndex);
return null;
}
function getSelectedItems()
@ -334,7 +342,7 @@ function createLocalFile(aFilePath)
return lf;
}
function Shutdown()
function DLManagerShutdown()
{
try {
var observerService = Components.classes[kObserverServiceProgID]

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

@ -27,9 +27,6 @@
<?xml-stylesheet href="chrome://communicator/skin/"?>
<?xul-overlay href="chrome://communicator/content/tasksOverlay.xul"?>
<?xul-overlay href="chrome://communicator/content/utilityOverlay.xul"?>
<!DOCTYPE window [
<!ENTITY % downloadManagerDTD SYSTEM "chrome://communicator/locale/downloadmanager/downloadmanager.dtd">
%downloadManagerDTD;
@ -44,8 +41,8 @@
width="500" height="300" screenX="10" screenY="10"
persist="width height screenX screenY"
title="&downloadManager.title;"
onload="Startup();"
onunload="Shutdown();">
onload="DLManagerStartup();"
onunload="DLManagerShutdown();">
<script type="application/x-javascript" src="chrome://global/content/globalOverlay.js"/>

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

@ -21,7 +21,8 @@
</RDF:Seq>
<RDF:Seq about="chrome://communicator/content/downloadmanager/downloadmanager.xul">
<RDF:li>chrome://global/content/hiddenWindow.xul</RDF:li>
<RDF:li>chrome://communicator/content/downloadmanager/dlmanagermenuoverlay.xul</RDF:li>
<RDF:li>chrome://navigator/content/navigatorOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

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

@ -0,0 +1,57 @@
<?xml version="1.0"?>
<!--
The contents of this file are subject to the Netscape 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/NPL/
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 mozilla.org code.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Simon Fraser <sfrase@netscape.com>
-->
<?xul-overlay href="chrome://navigator/content/navigatorOverlay.xul"?>
<overlay id="dlmanagermenuoverlay.xul"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- JS from navigator.xul, to handle the menu commands -->
<script type="application/x-javascript" src="chrome://navigator/content/browser.js"/>
<script type="application/x-javascript" src="chrome://navigator/content/navigator.js"/>
<stringbundleset id="stringbundleset"/>
<!-- keys are appended from the overlay -->
<keyset id="tasksKeys">
<keyset id="navKeys">
<key id="showHideSidebar"/>
</keyset>
</keyset>
<!-- commands are appended from the overlay -->
<commandset id="commands">
<commandset id="tasksCommands"/>
<commandset id="globalEditMenuItems"/>
<commandset id="selectEditMenuItems"/>
<commandset id="undoEditMenuItems"/>
<commandset id="clipboardEditMenuItems"/>
</commandset>
<broadcasterset id="navBroadcasters"/>
<toolbox id="toolbox" position="0">
<menubar id="main-menubar" position="1"/>
</toolbox>
</overlay>

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

@ -0,0 +1,45 @@
# ***** BEGIN LICENSE BLOCK *****
# 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 mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2002
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:download-manager"/>
</RDF:Seq>
<RDF:Description about="urn:mozilla:package:download-manager"
chrome:displayName="Unix-specific dl mgr files"
chrome:author="mozilla.org"
chrome:name="dlmgr"
chrome:localeVersion="1.2"
chrome:skinVersion="1.2">
</RDF:Description>
<!-- overlay information -->
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://communicator/content/downloadmanager/downloadmanager.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://communicator/content/downloadmanager/downloadmanager.xul">
<RDF:li>chrome://communicator/content/tasksOverlay.xul</RDF:li>
<RDF:li>chrome://communicator/content/utilityOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

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

@ -0,0 +1,3 @@
comm.jar:
content/communicator/downloadmanager/contents.rdf (contents.rdf)

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

@ -0,0 +1,45 @@
# ***** BEGIN LICENSE BLOCK *****
# 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 mozilla.org code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 2002
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# 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 *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,28 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
<RDF:Seq about="urn:mozilla:package:root">
<RDF:li resource="urn:mozilla:package:download-manager"/>
</RDF:Seq>
<RDF:Description about="urn:mozilla:package:download-manager"
chrome:displayName="Win-specific dl mgr files"
chrome:author="mozilla.org"
chrome:name="dlmgr"
chrome:localeVersion="1.2"
chrome:skinVersion="1.2">
</RDF:Description>
<!-- overlay information -->
<RDF:Seq about="urn:mozilla:overlays">
<RDF:li resource="chrome://communicator/content/downloadmanager/downloadmanager.xul"/>
</RDF:Seq>
<RDF:Seq about="chrome://communicator/content/downloadmanager/downloadmanager.xul">
<RDF:li>chrome://communicator/content/tasksOverlay.xul</RDF:li>
<RDF:li>chrome://communicator/content/utilityOverlay.xul</RDF:li>
</RDF:Seq>
</RDF:RDF>

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

@ -0,0 +1,3 @@
comm.jar:
content/communicator/downloadmanager/contents.rdf (contents.rdf)

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

@ -428,12 +428,14 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
internalDownload->SetSource(aSource);
// the persistent descriptor of the target is the unique identifier we use
nsCAutoString path;
rv = aTarget->GetNativePath(path);
nsAutoString path;
rv = aTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
NS_ConvertUCS2toUTF8 utf8Path(path);
nsCOMPtr<nsIRDFResource> downloadRes;
gRDFService->GetResource(path.get(), getter_AddRefs(downloadRes));
gRDFService->GetResource(utf8Path.get(), getter_AddRefs(downloadRes));
nsCOMPtr<nsIRDFNode> node;
@ -471,7 +473,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
// Assert file information
nsCOMPtr<nsIRDFResource> fileResource;
gRDFService->GetResource(path.get(), getter_AddRefs(fileResource));
gRDFService->GetResource(utf8Path.get(), getter_AddRefs(fileResource));
rv = mDataSource->Assert(downloadRes, gNC_File, fileResource, PR_TRUE);
if (NS_FAILED(rv)) return rv;
@ -505,7 +507,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
aPersist->SetProgressListener(listener);
}
nsCStringKey key(path);
nsCStringKey key(utf8Path);
if (mCurrDownloads.Exists(&key))
mCurrDownloads.Remove(&key);
@ -835,17 +837,19 @@ nsDownloadManager::Observe(nsISupports* aSubject, const char* aTopic, const PRUn
nsCOMPtr<nsILocalFile> target;
dialog->GetTarget(getter_AddRefs(target));
nsCAutoString path;
rv = target->GetNativePath(path);
nsAutoString path;
rv = target->GetPath(path);
if (NS_FAILED(rv)) return rv;
NS_ConvertUCS2toUTF8 utf8Path(path);
nsCStringKey key(path);
nsCStringKey key(utf8Path);
if (mCurrDownloads.Exists(&key)) {
// unset dialog since it's closing
nsDownload* download = NS_STATIC_CAST(nsDownload*, mCurrDownloads.Get(&key));
download->SetDialog(nsnull);
return CancelDownload(path.get());
return CancelDownload(utf8Path.get());
}
}
else if (nsCRT::strcmp(aTopic, "quit-application") == 0) {
@ -890,11 +894,11 @@ nsDownload::nsDownload():mDownloadState(NOTSTARTED),
nsDownload::~nsDownload()
{
nsCAutoString path;
nsresult rv = mTarget->GetNativePath(path);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return;
mDownloadManager->AssertProgressInfoFor(path.get());
mDownloadManager->AssertProgressInfoFor(NS_ConvertUCS2toUTF8(path).get());
}
nsresult
@ -1016,12 +1020,12 @@ nsDownload::OnProgressChange(nsIWebProgress *aWebProgress,
mLastUpdate = now;
if (mDownloadState == NOTSTARTED) {
nsCAutoString path;
nsresult rv = mTarget->GetNativePath(path);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
mDownloadState = DOWNLOADING;
mDownloadManager->DownloadStarted(path.get());
mDownloadManager->DownloadStarted(NS_ConvertUCS2toUTF8(path).get());
}
if (aMaxTotalProgress > 0)
@ -1081,10 +1085,10 @@ nsDownload::OnStatusChange(nsIWebProgress *aWebProgress,
{
if (NS_FAILED(aStatus)) {
mDownloadState = FAILED;
nsCAutoString path;
nsresult rv = mTarget->GetNativePath(path);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_SUCCEEDED(rv))
mDownloadManager->DownloadEnded(path.get(), aMessage);
mDownloadManager->DownloadEnded(NS_ConvertUCS2toUTF8(path).get(), aMessage);
}
if (mListener)
@ -1158,11 +1162,11 @@ nsDownload::OnStateChange(nsIWebProgress* aWebProgress,
mCurrBytes = mMaxBytes;
mPercentComplete = 100;
nsCAutoString path;
nsresult rv = mTarget->GetNativePath(path);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
mDownloadManager->DownloadEnded(path.get(), nsnull);
mDownloadManager->DownloadEnded(NS_ConvertUCS2toUTF8(path).get(), nsnull);
}
// break the cycle we created in AddDownload
@ -1218,11 +1222,11 @@ nsDownload::SetDisplayName(const PRUnichar* aDisplayName)
nsCOMPtr<nsIRDFLiteral> nameLiteral;
nsCOMPtr<nsIRDFResource> res;
nsCAutoString path;
nsresult rv = mTarget->GetNativePath(path);
nsAutoString path;
nsresult rv = mTarget->GetPath(path);
if (NS_FAILED(rv)) return rv;
gRDFService->GetResource(path.get(), getter_AddRefs(res));
gRDFService->GetResource(NS_ConvertUCS2toUTF8(path).get(), getter_AddRefs(res));
gRDFService->GetLiteral(aDisplayName, getter_AddRefs(nameLiteral));
ds->Assert(res, gNC_Name, nameLiteral, PR_TRUE);

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

@ -59,7 +59,7 @@ nsDownloadProgressListener.prototype = {
{
if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
{
var aDownloadID = aDownload.target.persistentDescriptor;
var aDownloadID = aDownload.target.path;
var elt = this.doc.getElementById(aDownloadID).firstChild.firstChild;
var timeRemainingCol = elt.nextSibling.nextSibling.nextSibling;
@ -95,7 +95,7 @@ nsDownloadProgressListener.prototype = {
else
rate = 0;
var aDownloadID = aDownload.target.persistentDescriptor;
var aDownloadID = aDownload.target.path
var elt = this.doc.getElementById(aDownloadID).firstChild.firstChild;
if (this.doc.getElementById("TimeElapsed").getAttribute("hidden") != "true") {
elapsedCol = elt.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling.nextSibling;