1 /* This file is part of the KDE project
3 * Copyright (C) 2002 David Faure <faure@kde.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public License
14 * along with this library; see the file COPYING.LIB. If not, write to
15 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 * Boston, MA 02110-1301, USA.
19 #ifndef kparts_browserrun_h
20 #define kparts_browserrun_h
24 #include <kparts/browserextension.h>
29 * This class extends KRun to provide additional functionality for browsers:
30 * - "save or open" dialog boxes
31 * - "save" functionality
32 * - support for HTTP POST (including saving the result to a temp file if
33 * opening a separate application)
34 * - warning before launching executables off the web
35 * - custom error handling (i.e. treating errors as HTML pages)
36 * - generation of SSL metadata depending on the previous URL shown by the part
37 * @author David Faure <faure@kde.org>
39 class KPARTS_EXPORT BrowserRun
: public KRun
44 * @param url the URL we're probing
45 * @param args URL args - includes reload, metaData, etc.
46 * @param browserArgs browser-related args - includes data for a HTTP POST, etc.
47 * @param part the part going to open this URL - can be 0 if not created yet
48 * @param window the mainwindow - passed to KIO::Job::setWindow()
49 * @param removeReferrer if true, the "referrer" metadata from @p args isn't passed on
50 * @param trustedSource if false, a warning will be shown before launching an executable.
51 Always pass false for @p trustedSource, except for local directory views.
52 * @param hideErrorDialog if true, no dialog will be shown in case of errors.
54 BrowserRun( const KUrl
& url
,
55 const KParts::OpenUrlArguments
& args
,
56 const KParts::BrowserArguments
& browserArgs
,
57 KParts::ReadOnlyPart
*part
,
59 bool removeReferrer
, bool trustedSource
, bool hideErrorDialog
= false );
61 virtual ~BrowserRun();
63 KParts::OpenUrlArguments
& arguments();
64 KParts::BrowserArguments
& browserArguments();
65 KParts::ReadOnlyPart
* part() const;
68 bool hideErrorDialog() const;
71 * @return Suggested disposition by the server (e.g. HTTP content-disposition)
73 QString
contentDisposition() const;
75 bool serverSuggestsSave() const { return contentDisposition() == QString::fromLatin1("attachment"); }
77 enum AskSaveResult
{ Save
, Open
, Cancel
};
79 * Ask the user whether to save or open a url in another application.
80 * @param url the URL in question
81 * @param offer the application that will be used to open the URL
82 * @param mimeType the mimetype of the URL
83 * @param suggestedFileName optional file name suggested by the server
84 * @return Save, Open or Cancel.
86 static AskSaveResult
askSave( const KUrl
& url
, KService::Ptr offer
, const QString
& mimeType
, const QString
& suggestedFileName
= QString() );
88 enum AskEmbedOrSaveFlags
{ InlineDisposition
= 0, AttachmentDisposition
= 1 };
90 * Similar to askSave but for the case where the current application is
91 * able to embed the url itself (instead of passing it to another app).
92 * @param url the URL in question
93 * @param mimeType the mimetype of the URL
94 * @param suggestedFileName optional filename suggested by the server
95 * @param flags set to AttachmentDisposition if suggested by the server
96 * @return Save, Open or Cancel.
98 static AskSaveResult
askEmbedOrSave( const KUrl
& url
, const QString
& mimeType
, const QString
& suggestedFileName
= QString(), int flags
= 0 );
100 // virtual so that KHTML can implement differently (HTML cache)
101 virtual void save( const KUrl
& url
, const QString
& suggestedFileName
);
103 // static so that it can be called from other classes
104 static void simpleSave( const KUrl
& url
, const QString
& suggestedFileName
,
105 QWidget
* window
=0 );
108 static bool allowExecution( const QString
&mimeType
, const KUrl
&url
);
110 static bool isTextExecutable( const QString
&mimeType
);
114 * Reimplemented from KRun
116 virtual void scanFile();
118 * Reimplemented from KRun
122 * Called when an error happens.
123 * NOTE: @p job could be 0L, if you passed hideErrorDialog=true.
124 * The default implementation shows a message box, but only when job != 0 ....
125 * It is strongly recommended to reimplement this method if
126 * you passed hideErrorDialog=true.
128 virtual void handleError( KJob
* job
);
131 * NotHandled means that foundMimeType should call KRun::foundMimeType,
132 * i.e. launch an external app.
134 enum NonEmbeddableResult
{ Handled
, NotHandled
, Delayed
};
137 * Helper for foundMimeType: call this if the mimetype couldn't be embedded
139 NonEmbeddableResult
handleNonEmbeddable( const QString
& mimeType
);
142 void slotBrowserScanFinished(KJob
*job
);
143 void slotBrowserMimetype(KIO::Job
*job
, const QString
&type
);
144 void slotCopyToTempFileResult(KJob
*job
);
145 virtual void slotStatResult( KJob
*job
);
148 void redirectToError( int error
, const QString
& errorText
);
149 class BrowserRunPrivate
;
150 BrowserRunPrivate
* const d
;