Allow embeddors to override helper apps. Bug 147142, patch by

philipl@mail.utexas.edu (Philip Langdale), r=bzbarsky, sr=blake
This commit is contained in:
bzbarsky%mit.edu 2002-06-28 01:35:57 +00:00
Родитель b477bcd31e
Коммит 5d73971f2e
11 изменённых файлов: 61 добавлений и 234 удалений

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

@ -62,7 +62,7 @@ function nsProgressDialog() {
this.strings = new Array;
this.mSource = null;
this.mTarget = null;
this.mApp = null;
this.mMIMEInfo = null;
this.mDialog = null;
this.mDisplayName = null;
this.mPaused = null;
@ -85,7 +85,8 @@ nsProgressDialog.prototype = {
dialogFeatures: "chrome,titlebar,minimizable=yes",
// getters/setters
get saving() { return this.openingWith == null || this.openingWith == ""; },
get saving() { return this.MIMEInfo == null ||
this.MIMEInfo.preferredAction == Components.interfaces.nsIMIMEInfo.saveToDisk; },
get parent() { return this.mParent; },
set parent(newval) { return this.mParent = newval; },
get operation() { return this.mOperation; },
@ -106,8 +107,8 @@ nsProgressDialog.prototype = {
set source(newval) { return this.mSource = newval; },
get target() { return this.mTarget; },
set target(newval) { return this.mTarget = newval; },
get openingWith() { return this.mApp; },
set openingWith(newval) { return this.mApp = newval; },
get MIMEInfo() { return this.mMIMEInfo; },
set MIMEInfo(newval) { return this.mMIMEInfo = newval; },
get dialog() { return this.mDialog; },
set dialog(newval) { return this.mDialog = newval; },
get displayName() { return this.mDisplayName; },
@ -145,11 +146,11 @@ nsProgressDialog.prototype = {
this );
},
init: function( aSource, aTarget, aDisplayName, aOpeningWith, aStartTime, aOperation ) {
init: function( aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, aOperation ) {
this.source = aSource;
this.target = aTarget;
this.displayName = aDisplayName;
this.openingWith = aOpeningWith;
this.MIMEInfo = aMIMEInfo;
if ( aStartTime ) {
this.startTime = aStartTime;
}
@ -364,15 +365,20 @@ nsProgressDialog.prototype = {
// Put proper label on source field.
this.setValue( "sourceLabel", this.getString( "openingSource" ) );
// Target is the "opening with" application. Hide if empty.
if ( this.openingWith.length == 0 ) {
this.hide( "targetRow" );
} else {
// Use the "with:" label.
this.setValue( "targetLabel", this.getString( "openingTarget" ) );
// Name of application.
this.setValue( "target", this.openingWith );
}
// Target is the "preferred" application. Hide if empty.
if ( this.MIMEInfo && this.MIMEInfo.preferredApplicationHandler ) {
var appName = this.MIMEInfo.preferredApplicationHandler.leafName;
if ( appName == null || appName.length == 0 ) {
this.hide( "targetRow" );
} else {
// Use the "with:" label.
this.setValue( "targetLabel", this.getString( "openingTarget" ) );
// Name of application.
this.setValue( "target", appName );
}
} else {
this.hide( "targetRow" );
}
} else {
// Target is the destination file.
this.setValue( "target", this.target.path );

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

@ -43,6 +43,7 @@ interface nsILocalFile;
interface nsIObserver;
interface nsIWebBrowserPersist;
interface nsIWebProgressListener;
interface nsIMIMEInfo;
[scriptable, uuid(06cb92f2-1dd2-11b2-95f2-96dfdfb804a1)]
interface nsIDownload : nsISupports {
@ -56,6 +57,10 @@ interface nsIDownload : nsISupports {
*
* @param aDisplayName The user-readable description of the download.
*
* @param aMIMEInfo The MIME info associated with the download file,
* including MIME type and helper app when appropriate.
* This parameter is optional.
*
* @param aPersist The "persist" used to transfer the download. If set,
* the manager will set its listener to the download item
* and use it for cancellation. If not set, the client
@ -67,7 +72,7 @@ interface nsIDownload : nsISupports {
void init(in nsIURI aSource,
in nsILocalFile aTarget,
in wstring aDisplayName,
in wstring openingWith,
in nsIMIMEInfo aMIMEInfo,
in long long startTime,
in nsIWebBrowserPersist aPersist);
@ -107,10 +112,11 @@ interface nsIDownload : nsISupports {
readonly attribute long long startTime;
/**
* Set this attribute to indicate that the download will be
* opened with a helper application upon completion.
* Optional. If set, it will contain the download's relevant MIME information.
* This includes it's MIME Type, helper app, and whether that helper should be
* executed.
*/
readonly attribute wstring openingWith;
readonly attribute nsIMIMEInfo MIMEInfo;
/**
* Optional; downloading information is passed to this listener and used to
@ -130,4 +136,4 @@ interface nsIDownload : nsISupports {
// {E3FA9D0A-1DD1-11B2-BDEF-8C720B597445}
#define NS_DOWNLOAD_CID \
{ 0xe3fa9d0a, 0x1dd1, 0x11b2, { 0xbd, 0xef, 0x8c, 0x72, 0x0b, 0x59, 0x74, 0x45 } }
%}
%}

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

@ -1471,32 +1471,10 @@ nsresult nsExternalAppHandler::InitializeDownload(nsIDownload* aDownload)
{
nsresult rv;
nsXPIDLString openWith(NS_LITERAL_STRING(""));
nsMIMEInfoHandleAction action = nsIMIMEInfo::saveToDisk;
mMimeInfo->GetPreferredAction(&action);
if (action != nsIMIMEInfo::saveToDisk)
{
// Opening with an application; use either description or application file name.
mMimeInfo->GetApplicationDescription(getter_Copies(openWith));
if (openWith.IsEmpty())
{
nsCOMPtr<nsIFile> appl;
mMimeInfo->GetPreferredApplicationHandler(getter_AddRefs(appl));
if (appl)
{
nsCOMPtr<nsILocalFile> file = do_QueryInterface(appl);
if (file)
{
file->GetLeafName(openWith);
}
}
}
}
nsCOMPtr<nsILocalFile> local = do_QueryInterface(mFinalFileDestination);
rv = aDownload->Init(mSourceUrl, local, nsnull,
openWith, mTimeDownloadStarted, nsnull);
mMimeInfo, mTimeDownloadStarted, nsnull);
if (NS_FAILED(rv)) return rv;
rv = aDownload->SetObserver(this);

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

@ -45,9 +45,10 @@ REQUIRES = xpcom \
dom \
downloadmanager \
alerts\
uriloader \
webbrowserpersist \
progressDlg \
uriloader \
mimetype \
webbrowserpersist \
progressDlg \
pref \
docshell \
webshell \

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

@ -1,111 +0,0 @@
#!gmake
#
# 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):
DEPTH=..\..\..
MODULE=appcomps
LIBRARY_NAME=appcomps
MODULE_NAME=application
REQUIRES = xpcom \
string \
rdf \
necko \
necko2 \
nkcache \
intl \
locale \
mork \
widget \
dom \
pref \
docshell \
downloadmanager \
webshell \
timebomb \
bookmarks \
content \
history \
search \
alerts \
progressDlg \
related \
urlbarhistory \
uriloader \
mozldap \
webbrowserpersist \
appshell \
$(NULL)
LCFLAGS = -DWIN32_LEAN_AND_MEAN
!if !defined(DISABLE_LDAP)
LCFLAGS = $(LCFLAGS) -DMOZ_LDAP_XPCOM
!endif
CPP_OBJS= \
.\$(OBJDIR)\nsModule.obj \
$(NULL)
SUB_LIBRARIES= \
$(DIST)\lib\autocomplete_s.lib \
$(DIST)\lib\bookmarks_s.lib \
$(DIST)\lib\directory_s.lib \
$(DIST)\lib\downloadmanager_s.lib \
$(DIST)\lib\history_s.lib \
$(DIST)\lib\appcompintl_s.lib \
$(DIST)\lib\related_s.lib \
$(DIST)\lib\search_s.lib \
$(DIST)\lib\alerts_s.lib \
$(DIST)\lib\timebomb_s.lib \
$(DIST)\lib\urlbarhistory_s.lib \
$(DIST)\lib\urlwidgt_s.lib \
$(DIST)\lib\windowds_s.lib \
$(DIST)\lib\winhooks_s.lib \
$(NULL)
WIN_LIBS = \
ole32.lib \
shell32.lib \
$(NULL)
LLIBS= \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\unicharutil_s.lib \
$(LIBNSPR) \
$(NULL)
INCS = $(INCS) \
-I$(DEPTH)\xpfe\components\autocomplete\src \
-I$(DEPTH)\xpfe\components\bookmarks\src \
-I$(DEPTH)\xpfe\components\directory \
-I$(DEPTH)\xpfe\components\download-manager\src \
-I$(DEPTH)\xpfe\components\history\src \
-I$(DEPTH)\xpfe\components\related\src \
-I$(DEPTH)\xpfe\components\search\src \
-I$(DEPTH)\xpfe\components\timebomb \
-I$(DEPTH)\xpfe\components\urlbarhistory\src \
-I$(DEPTH)\xpfe\components\urlwidget \
-I$(DEPTH)\xpfe\components\windowds \
-I$(DEPTH)\xpfe\components\winhooks \
-I$(DEPTH)\xpfe\components\alerts\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

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

@ -46,6 +46,7 @@ interface nsIURI;
interface nsILocalFile;
interface nsIDownload;
interface nsIWebBrowserPersist;
interface nsIMIMEInfo;
[scriptable, uuid(9be66cc0-1dd1-11b2-8617-e3a3ed26e3b0)]
interface nsIDownloadManager : nsISupports {
@ -75,7 +76,7 @@ interface nsIDownloadManager : nsISupports {
nsIDownload addDownload(in nsIURI aSource,
in nsILocalFile aTarget,
in wstring aDisplayName,
in wstring openingWith,
in nsIMIMEInfo aMIMEInfo,
in long long startTime,
in nsIWebBrowserPersist aPersist);
@ -166,4 +167,4 @@ interface nsIDownloadManager : nsISupports {
// {EDB0490E-1DD1-11B2-83B8-DBF8D85906A6}
#define NS_DOWNLOADMANAGER_CID \
{ 0xedb0490e, 0x1dd1, 0x11b2, { 0x83, 0xb8, 0xdb, 0xf8, 0xd8, 0x59, 0x06, 0xa6 } }
%}
%}

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

@ -34,6 +34,7 @@ REQUIRES = xpcom \
string \
rdf \
uriloader \
mimetype \
necko \
progressDlg \
intl \

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

@ -1,58 +0,0 @@
#!nmake
#
# 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):
DEPTH=..\..\..\..
MODULE=downloadmanager
REQUIRES = xpcom \
string \
rdf \
uriloader \
necko \
progressDlg \
intl \
windowwatcher \
webbrowserpersist \
appshell \
dom \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsDownloadManager.obj \
$(NULL)
LIBRARY_NAME=downloadmanager_s
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs::
$(MAKE_INSTALL) nsDownloadProgressListener.js $(DIST)\bin\components
clobber_all::
!rm -f $(DIST)\bin\components\nsDownloadProgressListener.js
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

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

@ -397,7 +397,7 @@ NS_IMETHODIMP
nsDownloadManager::AddDownload(nsIURI* aSource,
nsILocalFile* aTarget,
const PRUnichar* aDisplayName,
const PRUnichar* aOpeningWith,
nsIMIMEInfo *aMIMEInfo,
PRInt64 aStartTime,
nsIWebBrowserPersist* aPersist,
nsIDownload** aDownload)
@ -480,7 +480,7 @@ nsDownloadManager::AddDownload(nsIURI* aSource,
return rv;
}
internalDownload->SetOpeningWith(aOpeningWith);
internalDownload->SetMIMEInfo(aMIMEInfo);
internalDownload->SetStartTime(aStartTime);
// Assert file information
@ -797,10 +797,10 @@ nsDownloadManager::OpenProgressDialogFor(const char* aPath, nsIDOMWindow* aParen
download->GetTarget(getter_AddRefs(target));
// helper app...
nsXPIDLString openingWith;
download->GetOpeningWith(getter_Copies(openingWith));
nsCOMPtr<nsIMIMEInfo> mimeInfo;
download->GetMIMEInfo(getter_AddRefs(mimeInfo));
dl->Init(source, target, nsnull, openingWith, startTime, nsnull);
dl->Init(source, target, nsnull, mimeInfo, startTime, nsnull);
dl->SetObserver(this);
// now set the listener so we forward notifications to the dialog
@ -904,7 +904,7 @@ nsDownload::nsDownload():mStartTime(0),
mMaxBytes(0),
mDownloadState(NOTSTARTED),
mLastUpdate(-500),
mOpeningWith(nsnull)
mMIMEInfo(nsnull)
{
NS_INIT_ISUPPORTS();
}
@ -1006,9 +1006,9 @@ nsDownload::SetStartTime(PRInt64 aStartTime)
}
nsresult
nsDownload::SetOpeningWith(const PRUnichar* aOpeningWith)
nsDownload::SetMIMEInfo(nsIMIMEInfo *aMIMEInfo)
{
mOpeningWith = aOpeningWith;
mMIMEInfo = aMIMEInfo;
return NS_OK;
}
@ -1221,7 +1221,7 @@ NS_IMETHODIMP
nsDownload::Init(nsIURI* aSource,
nsILocalFile* aTarget,
const PRUnichar* aDisplayName,
const PRUnichar* aOpeningWith,
nsIMIMEInfo *aMIMEInfo,
PRInt64 aStartTime,
nsIWebBrowserPersist* aPersist)
{
@ -1327,8 +1327,9 @@ nsDownload::GetObserver(nsIObserver** aObserver)
}
NS_IMETHODIMP
nsDownload::GetOpeningWith(PRUnichar** aOpeningWith)
nsDownload::GetMIMEInfo(nsIMIMEInfo** aMIMEInfo)
{
*aOpeningWith = ToNewUnicode(mOpeningWith);
*aMIMEInfo = mMIMEInfo;
NS_IF_ADDREF(*aMIMEInfo);
return NS_OK;
}

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

@ -58,6 +58,7 @@
#include "nsIObserver.h"
#include "nsIStringBundle.h"
#include "nsIProgressDialog.h"
#include "nsIMIMEInfo.h"
enum DownloadState { NOTSTARTED = -1, DOWNLOADING, FINISHED, FAILED, CANCELED };
@ -123,13 +124,12 @@ protected:
nsresult GetTransferInformation(PRInt32* aCurr, PRInt32* aMax);
nsresult GetDownloadState(DownloadState* aState);
nsresult SetDownloadState(DownloadState aState);
nsresult SetOpeningWith(const PRUnichar* aOpeningWith);
nsresult SetMIMEInfo(nsIMIMEInfo* aMIMEInfo);
nsresult SetStartTime(PRInt64 aStartTime);
private:
nsDownloadManager* mDownloadManager;
nsString mDisplayName;
nsString mOpeningWith;
nsCOMPtr<nsILocalFile> mTarget;
nsCOMPtr<nsIURI> mSource;
@ -139,6 +139,7 @@ private:
nsCOMPtr<nsIRequest> mRequest;
nsCOMPtr<nsIProgressDialog> mDialog;
nsCOMPtr<nsIObserver> mObserver;
nsCOMPtr<nsIMIMEInfo> mMIMEInfo;
DownloadState mDownloadState;
PRInt32 mPercentComplete;

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

@ -43,6 +43,7 @@
#include "nsIDownloadManager.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsIMIMEInfo.h"
#define DOWNLOAD_MANAGER_BEHAVIOR_PREF "browser.downloadmanager.behavior"
@ -59,14 +60,14 @@ public:
NS_IMETHODIMP Init(nsIURI* aSource,
nsILocalFile* aTarget,
const PRUnichar* aDisplayName,
const PRUnichar* aOpeningWith,
nsIMIMEInfo *aMIMEInfo,
PRInt64 aStartTime,
nsIWebBrowserPersist* aPersist) {
nsresult rv;
nsCOMPtr<nsIDownloadManager> dm = do_GetService("@mozilla.org/download-manager;1", &rv);
if (NS_FAILED(rv)) return rv;
rv = dm->AddDownload(aSource, aTarget, aDisplayName, aOpeningWith, aStartTime, aPersist, getter_AddRefs(mInner));
rv = dm->AddDownload(aSource, aTarget, aDisplayName, aMIMEInfo, aStartTime, aPersist, getter_AddRefs(mInner));
if (NS_FAILED(rv)) return rv;
PRInt32 behavior = 0;
@ -97,9 +98,9 @@ public:
return mInner->SetDisplayName(aDisplayName);
}
NS_IMETHODIMP GetOpeningWith(PRUnichar** aOpeningWith)
NS_IMETHODIMP GetMIMEInfo(nsIMIMEInfo** aMIMEInfo)
{
return mInner->GetOpeningWith(aOpeningWith);
return mInner->GetMIMEInfo(aMIMEInfo);
}
NS_IMETHODIMP GetSource(nsIURI** aSource)