1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
23
* Pierre Phaneuf <pp@ludusdesign.com>
26
* Alternatively, the contents of this file may be used under the terms of
27
* either the GNU General Public License Version 2 or later (the "GPL"), or
28
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
* in which case the provisions of the GPL or the LGPL are applicable instead
30
* of those above. If you wish to allow use of your version of this file only
31
* under the terms of either the GPL or the LGPL, and not to allow others to
32
* use your version of this file under the terms of the NPL, indicate your
33
* decision by deleting the provisions above and replace them with the notice
34
* and other provisions required by the GPL or the LGPL. If you do not delete
35
* the provisions above, a recipient may use your version of this file under
36
* the terms of any one of the NPL, the GPL or the LGPL.
38
* ***** END LICENSE BLOCK ***** */
40
#include "nsUnknownContentTypeHandler.h"
41
#include "nsIGenericFactory.h"
42
#include "nsIDOMWindowInternal.h"
43
#include "nsIInterfaceRequestor.h"
44
#include "nsIInterfaceRequestorUtils.h"
45
#include "nsIDocShell.h"
46
#include "mimetype/nsIMIMEInfo.h"
48
#include "nsILocalFile.h"
50
#include "EmbedPrivate.h"
51
#include "PtMozilla.h"
53
nsUnknownContentTypeHandler::nsUnknownContentTypeHandler( ) {
55
///* ATENTIE */ printf( "In nsUnknownContentTypeHandler constructor\n" );
58
nsUnknownContentTypeHandler::~nsUnknownContentTypeHandler( )
60
///* ATENTIE */ printf( "In nsUnknownContentTypeHandler destr\n" );
64
NS_IMETHODIMP nsUnknownContentTypeHandler::Show( nsIHelperAppLauncher *aLauncher, nsISupports *aContext, PRBool aForced )
66
return aLauncher->SaveToDisk( nsnull, PR_FALSE );
69
NS_IMETHODIMP nsUnknownContentTypeHandler::PromptForSaveToFile( nsIHelperAppLauncher* aLauncher,
70
nsISupports *aWindowContext,
71
const PRUnichar *aDefaultFile,
72
const PRUnichar *aSuggestedFileExtension,
73
nsILocalFile **_retval )
75
///* ATENTIE */ printf("PromptForSaveToFile!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
76
NS_ENSURE_ARG_POINTER(_retval);
79
/* try to get the PtMozillawidget_t* pointer form the aContext - use the fact the the WebBrowserContainer is
80
registering itself as nsIDocumentLoaderObserver ( SetDocLoaderObserver ) */
81
nsCOMPtr<nsIDOMWindow> domw( do_GetInterface( aWindowContext ) );
83
domw->GetParent( &parent );
84
PtWidget_t *w = GetWebBrowser( parent );
85
PtMozillaWidget_t *moz = ( PtMozillaWidget_t * ) w;
87
/* get the suggested filename */
88
NS_ConvertUCS2toUTF8 theUnicodeString( aDefaultFile );
89
const char *filename = theUnicodeString.get( );
92
nsCOMPtr<nsIURI> aSourceUrl;
93
aLauncher->GetSource( getter_AddRefs(aSourceUrl) );
95
nsCAutoString specString;
96
aSourceUrl->GetSpec(specString);
97
url = specString.get();
99
/* get the mime type */
100
nsCOMPtr<nsIMIMEInfo> mimeInfo;
101
aLauncher->GetMIMEInfo( getter_AddRefs(mimeInfo) );
103
mimeInfo->GetMIMEType( &mimeType );
106
PtCallbackInfo_t cbinfo;
107
PtWebUnknownWithNameCallback_t cb;
109
memset( &cbinfo, 0, sizeof( cbinfo ) );
110
cbinfo.reason = Pt_CB_MOZ_UNKNOWN;
112
cb.action = Pt_WEB_ACTION_OK;
113
cb.content_type = mimeType;
114
cb.url = (char *)url;
115
cb.content_length = strlen( cb.url );
116
cb.suggested_filename = (char*)filename;
117
PtInvokeCallbackList( moz->web_unknown_cb, (PtWidget_t *)moz, &cbinfo );
118
/* this will modal wait for a Pt_ARG_WEB_UNKNOWN_RESP, in mozserver */
120
/* we have the result in moz->moz_unknown_ctrl */
121
if( moz->moz_unknown_ctrl->response != Pt_WEB_RESPONSE_OK ) return NS_ERROR_ABORT;
123
/* the user chosen filename is moz->moz_unknown_ctrl->filename */
124
nsCOMPtr<nsILocalFile> file(do_CreateInstance("@mozilla.org/file/local;1"));
125
NS_ENSURE_TRUE(file, NS_ERROR_FAILURE);
127
nsCString s ( moz->moz_unknown_ctrl->filename );
128
file->InitWithNativePath( s );
129
if( !file ) return NS_ERROR_FAILURE;
132
NS_ADDREF( *_retval );
134
/* add this download to our list */
135
EmbedDownload *download = new EmbedDownload( moz, moz->moz_unknown_ctrl->download_ticket, url );
136
download->mLauncher = aLauncher;
137
aLauncher->SetWebProgressListener( download );
143
PtWidget_t *nsUnknownContentTypeHandler::GetWebBrowser(nsIDOMWindow *aWindow)
145
nsCOMPtr<nsIWebBrowserChrome> chrome;
148
nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
149
if (!wwatch) return nsnull;
152
nsCOMPtr<nsIDOMWindow> fosterParent;
153
if (!aWindow) { // it will be a dependent window. try to find a foster parent.
154
wwatch->GetActiveWindow(getter_AddRefs(fosterParent));
155
aWindow = fosterParent;
157
wwatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));
161
nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));
163
site->GetSiteWindow(reinterpret_cast<void **>(&val));
170
//#######################################################################################
172
#define className nsUnknownContentTypeHandler
173
#define interfaceName nsIHelperAppLauncherDialog
174
#define contractId NS_IUNKNOWNCONTENTTYPEHANDLER_CONTRACTID
176
/* Component's implementation of Initialize. */
177
/* nsISupports Implementation for the class */
178
NS_IMPL_ADDREF( className );
179
NS_IMPL_RELEASE( className )
182
/* QueryInterface implementation for this class. */
183
NS_IMETHODIMP className::QueryInterface( REFNSIID anIID, void **anInstancePtr ) {
185
///* ATENTIE */ printf("QueryInterface!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\n\n");
187
/* Check for place to return result. */
188
if( !anInstancePtr ) rv = NS_ERROR_NULL_POINTER;
191
if ( anIID.Equals( NS_GET_IID(nsIHelperAppLauncherDialog) ) ) {
192
*anInstancePtr = (void*) (nsIHelperAppLauncherDialog*)this;
195
else if ( anIID.Equals( NS_GET_IID(nsISupports) ) ) {
196
*anInstancePtr = (void*) ( (nsISupports*) (interfaceName*)this );
199
else rv = NS_NOINTERFACE;
204
NS_GENERIC_FACTORY_CONSTRUCTOR( nsUnknownContentTypeHandler )
206
// The list of components we register
207
static nsModuleComponentInfo info[] = {
209
"nsUnknownContentTypeHandler",
210
NS_IHELPERAPPLAUNCHERDIALOG_IID,
211
NS_IHELPERAPPLAUNCHERDLG_CONTRACTID,
212
nsUnknownContentTypeHandlerConstructor
216
int Init_nsUnknownContentTypeHandler_Factory( ) {
219
// create a generic factory for UnkHandler
220
nsCOMPtr<nsIGenericFactory> factory;
221
rv = NS_NewGenericFactory( getter_AddRefs(factory), info );
225
// register this factory with the component manager.
226
rv = nsComponentManager::RegisterFactory( kCID, "nsUnknownContentTypeHandler", NS_IHELPERAPPLAUNCHERDLG_CONTRACTID, factory, PR_TRUE);