View | Details | Raw Unified | Return to bug 16826 | Differences between
and this patch

Collapse All | Expand All

(-)a/ChangeLog (+8 lines)
Lines 1-5 Link Here
1
2009-02-12  Gustavo Noronha Silva  <gns@gnome.org>
1
2009-02-12  Gustavo Noronha Silva  <gns@gnome.org>
2
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        Add new files, webkitdownload.{h,cpp}, to the GTK+ port.
6
7
        * GNUmakefile.am:
8
9
2009-02-12  Gustavo Noronha Silva  <gns@gnome.org>
10
3
        Reviewed by Eric Seidel.
11
        Reviewed by Eric Seidel.
4
12
5
        * configure.ac: Make soup the default HTTP backend for the Gtk port.
13
        * configure.ac: Make soup the default HTTP backend for the Gtk port.
(-)a/GNUmakefile.am (+2 lines)
Lines 304-309 endif Link Here
304
webkitgtk_h_api += \
304
webkitgtk_h_api += \
305
	WebKit/gtk/webkit/webkit.h \
305
	WebKit/gtk/webkit/webkit.h \
306
	WebKit/gtk/webkit/webkitdefines.h \
306
	WebKit/gtk/webkit/webkitdefines.h \
307
	WebKit/gtk/webkit/webkitdownload.h \
307
	WebKit/gtk/webkit/webkitnetworkrequest.h \
308
	WebKit/gtk/webkit/webkitnetworkrequest.h \
308
	WebKit/gtk/webkit/webkitversion.h \
309
	WebKit/gtk/webkit/webkitversion.h \
309
	WebKit/gtk/webkit/webkitwebbackforwardlist.h \
310
	WebKit/gtk/webkit/webkitwebbackforwardlist.h \
Lines 348-353 webkitgtk_sources += \ Link Here
348
	WebKit/gtk/webkit/webkitwebnavigationaction.cpp \
349
	WebKit/gtk/webkit/webkitwebnavigationaction.cpp \
349
	WebKit/gtk/webkit/webkitwebpolicydecision.cpp \
350
	WebKit/gtk/webkit/webkitwebpolicydecision.cpp \
350
	WebKit/gtk/webkit/webkitwebsettings.cpp \
351
	WebKit/gtk/webkit/webkitwebsettings.cpp \
352
	WebKit/gtk/webkit/webkitdownload.cpp \
351
	WebKit/gtk/webkit/webkitwebview.cpp \
353
	WebKit/gtk/webkit/webkitwebview.cpp \
352
	WebKit/gtk/webkit/webkitwebwindowfeatures.cpp
354
	WebKit/gtk/webkit/webkitwebwindowfeatures.cpp
353
355
(-)a/WebCore/ChangeLog (+10 lines)
Lines 1-3 Link Here
1
2009-02-12  Gustavo Noronha Silva  <gns@gnome.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
	Make the Soup backend able to handle requests without a frame,
6
	since we may have such things now that we support downloads.
7
8
        * platform/network/soup/ResourceHandleSoup.cpp:
9
        (WebCore::ResourceHandle::start):
10
1
2009-02-12  Dimitri Glazkov  <dglazkov@chromium.org>
11
2009-02-12  Dimitri Glazkov  <dglazkov@chromium.org>
2
12
3
        Reviewed by Eric Seidel.
13
        Reviewed by Eric Seidel.
(-)a/WebCore/platform/network/soup/ResourceHandleSoup.cpp (-3 / +6 lines)
Lines 412-420 bool ResourceHandle::start(Frame* frame) Link Here
412
{
412
{
413
    ASSERT(!d->m_msg);
413
    ASSERT(!d->m_msg);
414
414
415
    // If we are no longer attached to a Page, this must be an attempted load from an
415
416
    // onUnload handler, so let's just block it.
416
    /* The frame could be null is the ResourceHandle is not associated to any
417
    if (!frame->page())
417
     * Frame, i.e. if we are downloading a file.
418
     * If the frame is not null but the page is null this must be an attempted
419
     * load from an onUnload handler, so let's just block it. */
420
    if (frame && !frame->page())
418
        return false;
421
        return false;
419
422
420
    KURL url = request().url();
423
    KURL url = request().url();
(-)a/WebKit/gtk/ChangeLog (+55 lines)
Lines 1-3 Link Here
1
2009-02-12  Gustavo Noronha Silva  <gns@gnome.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        Implement download, and provide a nice object wrapping the
6
        download process. Initial work done by Marco Barisione and
7
        Pierre-Luc Beaudoin.
8
9
        * WebCoreSupport/ContextMenuClientGtk.cpp:
10
        (WebKit::ContextMenuClient::downloadURL):
11
        * WebCoreSupport/FrameLoaderClientGtk.cpp:
12
        (WebKit::FrameLoaderClient::download):
13
        (WebKit::FrameLoaderClient::startDownload):
14
        * webkit/webkit.h:
15
        * webkit/webkitdefines.h:
16
        * webkit/webkitdownload.cpp: Added.
17
        (_WebKitDownloadPrivate::):
18
        (_WebKitDownloadPrivate::webkit_download_dispose):
19
        (_WebKitDownloadPrivate::webkit_download_finalize):
20
        (_WebKitDownloadPrivate::webkit_download_get_property):
21
        (_WebKitDownloadPrivate::webkit_download_set_property):
22
        (_WebKitDownloadPrivate::webkit_download_class_init):
23
        (_WebKitDownloadPrivate::webkit_download_init):
24
        (_WebKitDownloadPrivate::webkit_download_new):
25
        (_WebKitDownloadPrivate::webkit_download_new_from_request):
26
        (_WebKitDownloadPrivate::webkit_download_open_stream_for_uri):
27
        (_WebKitDownloadPrivate::webkit_download_close_stream):
28
        (_WebKitDownloadPrivate::webkit_download_start):
29
        (_WebKitDownloadPrivate::webkit_download_cancel):
30
        (_WebKitDownloadPrivate::webkit_download_get_uri):
31
        (_WebKitDownloadPrivate::webkit_download_get_network_request):
32
        (_WebKitDownloadPrivate::webkit_download_set_response):
33
        (_WebKitDownloadPrivate::webkit_download_get_suggested_filename):
34
        (_WebKitDownloadPrivate::webkit_download_get_destination_uri):
35
        (_WebKitDownloadPrivate::webkit_download_set_destination_uri):
36
        (_WebKitDownloadPrivate::webkit_download_get_state):
37
        (_WebKitDownloadPrivate::webkit_download_get_total_size):
38
        (_WebKitDownloadPrivate::webkit_download_get_current_size):
39
        (_WebKitDownloadPrivate::webkit_download_get_progress):
40
        (_WebKitDownloadPrivate::webkit_download_get_elapsed_time):
41
        (_WebKitDownloadPrivate::webkit_download_received_data):
42
        (_WebKitDownloadPrivate::webkit_download_finished_loading):
43
        (_WebKitDownloadPrivate::webkit_download_error):
44
        (_WebKitDownloadPrivate::DownloadClient::DownloadClient):
45
        (_WebKitDownloadPrivate::DownloadClient::didReceiveResponse):
46
        (_WebKitDownloadPrivate::DownloadClient::didReceiveData):
47
        (_WebKitDownloadPrivate::DownloadClient::didFinishLoading):
48
        (_WebKitDownloadPrivate::DownloadClient::didFail):
49
        (_WebKitDownloadPrivate::DownloadClient::wasBlocked):
50
        (_WebKitDownloadPrivate::DownloadClient::cannotShowURL):
51
        * webkit/webkitdownload.h: Added.
52
        * webkit/webkitprivate.h:
53
        * webkit/webkitwebview.cpp:
54
        * webkit/webkitwebview.h:
55
1
2009-02-11  Dimitri Dupuis-latour  <dupuislatour@apple.com>
56
2009-02-11  Dimitri Dupuis-latour  <dupuislatour@apple.com>
2
57
3
        Stub out InspectorClient::hiddenPanels.
58
        Stub out InspectorClient::hiddenPanels.
(-)a/WebKit/gtk/WebCoreSupport/ContextMenuClientGtk.cpp (-1 / +13 lines)
Lines 1-5 Link Here
1
/*
1
/*
2
 *  Copyright (C) 2008 Nuanti Ltd.
2
 *  Copyright (C) 2008 Nuanti Ltd.
3
 *  Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
3
 *
4
 *
4
 *  This library is free software; you can redistribute it and/or
5
 *  This library is free software; you can redistribute it and/or
5
 *  modify it under the terms of the GNU Lesser General Public
6
 *  modify it under the terms of the GNU Lesser General Public
Lines 20-25 Link Here
20
#include "ContextMenu.h"
21
#include "ContextMenu.h"
21
#include "ContextMenuClientGtk.h"
22
#include "ContextMenuClientGtk.h"
22
23
24
#include "CString.h"
23
#include "HitTestResult.h"
25
#include "HitTestResult.h"
24
#include "KURL.h"
26
#include "KURL.h"
25
#include "NotImplemented.h"
27
#include "NotImplemented.h"
Lines 163-169 void ContextMenuClient::contextMenuItemSelected(ContextMenuItem*, const ContextM Link Here
163
165
164
void ContextMenuClient::downloadURL(const KURL& url)
166
void ContextMenuClient::downloadURL(const KURL& url)
165
{
167
{
166
    notImplemented();
168
    WebKitDownload* download = webkit_download_new(url.string().utf8().data());
169
    gboolean handled;
170
    g_signal_emit_by_name(m_webView, "download-requested", download, &handled);
171
172
    if (handled) {
173
        webkit_download_start(download);
174
    }
175
    else {
176
        webkit_download_cancel(download);
177
        g_object_unref(download);
178
    }
167
}
179
}
168
180
169
void ContextMenuClient::copyImageToClipboard(const HitTestResult&)
181
void ContextMenuClient::copyImageToClipboard(const HitTestResult&)
(-)a/WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp (-4 / +24 lines)
Lines 3-8 Link Here
3
 *  Copyright (C) 2007, 2008 Holger Hans Peter Freyther
3
 *  Copyright (C) 2007, 2008 Holger Hans Peter Freyther
4
 *  Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
4
 *  Copyright (C) 2007 Christian Dywan <christian@twotoasts.de>
5
 *  Copyright (C) 2008 Collabora Ltd.  All rights reserved.
5
 *  Copyright (C) 2008 Collabora Ltd.  All rights reserved.
6
 *  Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
6
 *
7
 *
7
 *  This library is free software; you can redistribute it and/or
8
 *  This library is free software; you can redistribute it and/or
8
 *  modify it under the terms of the GNU Lesser General Public
9
 *  modify it under the terms of the GNU Lesser General Public
Lines 40-45 Link Here
40
#include "MouseEvent.h"
41
#include "MouseEvent.h"
41
#include "NotImplemented.h"
42
#include "NotImplemented.h"
42
#include "PlatformString.h"
43
#include "PlatformString.h"
44
#include "ResourceHandle.h"
45
#include "ResourceHandleInternal.h"
43
#include "PluginDatabase.h"
46
#include "PluginDatabase.h"
44
#include "RenderPart.h"
47
#include "RenderPart.h"
45
#include "ResourceRequest.h"
48
#include "ResourceRequest.h"
Lines 754-762 void FrameLoaderClient::dispatchDidFailLoad(const ResourceError&) Link Here
754
    g_signal_emit_by_name(m_frame, "load-done", false);
757
    g_signal_emit_by_name(m_frame, "load-done", false);
755
}
758
}
756
759
757
void FrameLoaderClient::download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&)
760
void FrameLoaderClient::download(ResourceHandle* handle, const ResourceRequest& request, const ResourceRequest& initialRequest, const ResourceResponse& response)
758
{
761
{
759
    notImplemented();
762
    // we could reuse the same handle, but our replacing of the
763
    // client seems to make this impossible; the main load fails
764
    // and is stopped
765
    handle->cancel();
766
    startDownload(request);
760
}
767
}
761
768
762
ResourceError FrameLoaderClient::cancelledError(const ResourceRequest&)
769
ResourceError FrameLoaderClient::cancelledError(const ResourceRequest&)
Lines 842-850 void FrameLoaderClient::setMainDocumentError(DocumentLoader*, const ResourceErro Link Here
842
    }
849
    }
843
}
850
}
844
851
845
void FrameLoaderClient::startDownload(const ResourceRequest&)
852
void FrameLoaderClient::startDownload(const ResourceRequest& request)
846
{
853
{
847
    notImplemented();
854
    WebKitWebView* view = getViewFromFrame(m_frame);
855
    WebKitNetworkRequest* networkRequest = webkit_network_request_new(request.url().string().utf8().data());
856
    WebKitDownload* download = webkit_download_new_from_request(networkRequest);
857
858
    gboolean handled;
859
    g_signal_emit_by_name(view, "download-requested", download, &handled);
860
861
    if (handled) {
862
        webkit_download_start(download);
863
    }
864
    else {
865
        webkit_download_cancel(download);
866
        g_object_unref(download);
867
    }
848
}
868
}
849
869
850
void FrameLoaderClient::updateGlobalHistory()
870
void FrameLoaderClient::updateGlobalHistory()
(-)a/WebKit/gtk/webkit/webkit.h (+1 lines)
Lines 24-29 Link Here
24
#include <webkit/webkitversion.h>
24
#include <webkit/webkitversion.h>
25
#include <webkit/webkitdefines.h>
25
#include <webkit/webkitdefines.h>
26
#include <webkit/webkitnetworkrequest.h>
26
#include <webkit/webkitnetworkrequest.h>
27
#include <webkit/webkitdownload.h>
27
#include <webkit/webkitwebframe.h>
28
#include <webkit/webkitwebframe.h>
28
#include <webkit/webkitwebsettings.h>
29
#include <webkit/webkitwebsettings.h>
29
#include <webkit/webkitwebinspector.h>
30
#include <webkit/webkitwebinspector.h>
(-)a/WebKit/gtk/webkit/webkitdefines.h (+3 lines)
Lines 68-73 typedef struct _WebKitWebWindowFeaturesClass WebKitWebWindowFeaturesClass; Link Here
68
typedef struct _WebKitWebView WebKitWebView;
68
typedef struct _WebKitWebView WebKitWebView;
69
typedef struct _WebKitWebViewClass WebKitWebViewClass;
69
typedef struct _WebKitWebViewClass WebKitWebViewClass;
70
70
71
typedef struct _WebKitDownload WebKitDownload;
72
typedef struct _WebKitDownloadClass WebKitDownloadClass;
73
71
G_END_DECLS
74
G_END_DECLS
72
75
73
#endif
76
#endif
(-)a/WebKit/gtk/webkit/webkitdownload.cpp (+801 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2008 Collabora Ltd.
3
 * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Library General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Library General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public License
16
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20
21
#include "config.h"
22
23
#include "CString.h"
24
#include "Noncopyable.h"
25
#include "NotImplemented.h"
26
#include "ResourceHandleClient.h"
27
#include "ResourceRequest.h"
28
#include "ResourceResponse.h"
29
#include "webkitmarshal.h"
30
#include "webkitdownload.h"
31
#include "webkitprivate.h"
32
#include <glib/gstdio.h>
33
34
using namespace WebKit;
35
using namespace WebCore;
36
37
extern "C" {
38
39
class DownloadClient : Noncopyable, public ResourceHandleClient {
40
    public:
41
        DownloadClient(WebKitDownload*);
42
43
        virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);
44
        virtual void didReceiveData(ResourceHandle*, const char*, int, int);
45
        virtual void didFinishLoading(ResourceHandle*);
46
        virtual void didFail(ResourceHandle*, const ResourceError&);
47
        virtual void wasBlocked(ResourceHandle*);
48
        virtual void cannotShowURL(ResourceHandle*);
49
50
    private:
51
        WebKitDownload* m_download;
52
};
53
54
#define WEBKIT_DOWNLOAD_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownloadPrivate))
55
56
struct _WebKitDownloadPrivate {
57
    gchar* destination_uri;
58
    gchar* suggested_filename;
59
    guint current_size;
60
    GTimer* timer;
61
    WebKitDownloadState state;
62
    GFileOutputStream* output_stream;
63
    DownloadClient* download_client;
64
    WebKitNetworkRequest* network_request;
65
    WebCore::ResourceResponse* network_response;
66
    RefPtr<WebCore::ResourceHandle> resource_handle;
67
};
68
69
enum {
70
    /* normal signals */
71
    ERROR,
72
    LAST_SIGNAL
73
};
74
75
static guint webkit_download_signals[LAST_SIGNAL] = { 0, };
76
77
enum {
78
    PROP_0,
79
80
    PROP_NETWORK_REQUEST,
81
    PROP_DESTINATION_URI,
82
    PROP_SUGGESTED_FILENAME,
83
    PROP_PROGRESS,
84
    PROP_CURRENT_SIZE,
85
    PROP_TOTAL_SIZE,
86
};
87
88
G_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT);
89
90
static void webkit_download_dispose(GObject* object)
91
{
92
    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
93
    WebKitDownloadPrivate* priv = download->priv;
94
95
    if (priv->output_stream) {
96
        g_object_unref(priv->output_stream);
97
        priv->output_stream = NULL;
98
    }
99
100
    if (priv->network_request) {
101
        g_object_unref(priv->network_request);
102
        priv->network_request = NULL;
103
    }
104
105
    G_OBJECT_CLASS(webkit_download_parent_class)->dispose(object);
106
}
107
108
static void webkit_download_finalize(GObject* object)
109
{
110
    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
111
    WebKitDownloadPrivate* priv = download->priv;
112
113
    /* We don't call webkit_download_cancel() because we don't want to emit
114
     * signals when finalising an object. */
115
    if (priv->resource_handle) {
116
        if (priv->state == WEBKIT_DOWNLOAD_STATE_STARTED) {
117
            priv->resource_handle->setClient(0);
118
            priv->resource_handle->cancel();
119
        }
120
        priv->resource_handle.release();
121
    }
122
123
    delete priv->download_client;
124
    delete priv->network_response;
125
126
    g_timer_destroy(priv->timer);
127
128
    g_free(priv->destination_uri);
129
    g_free(priv->suggested_filename);
130
131
    G_OBJECT_CLASS(webkit_download_parent_class)->finalize(object);
132
}
133
134
static void webkit_download_get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
135
{
136
    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
137
138
    switch(prop_id) {
139
    case PROP_NETWORK_REQUEST:
140
        g_value_set_object(value, webkit_download_get_network_request(download));
141
        break;
142
    case PROP_DESTINATION_URI:
143
        g_value_set_string(value, webkit_download_get_destination_uri(download));
144
        break;
145
    case PROP_SUGGESTED_FILENAME:
146
        g_value_set_string(value, webkit_download_get_suggested_filename(download));
147
        break;
148
    case PROP_PROGRESS:
149
        g_value_set_double(value, webkit_download_get_progress(download));
150
        break;
151
    case PROP_CURRENT_SIZE:
152
        g_value_set_uint64(value, webkit_download_get_current_size(download));
153
        break;
154
    case PROP_TOTAL_SIZE:
155
        g_value_set_uint64(value, webkit_download_get_total_size(download));
156
        break;
157
    default:
158
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
159
    }
160
}
161
162
static void webkit_download_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec *pspec)
163
{
164
    WebKitDownload* download = WEBKIT_DOWNLOAD(object);
165
    WebKitDownloadPrivate* priv = download->priv;
166
167
    switch(prop_id) {
168
    case PROP_NETWORK_REQUEST:
169
        priv->network_request = (WebKitNetworkRequest*)g_value_dup_object(value);
170
        /* This is safe as network-request is a construct only property and suggested_filename
171
         * is initially null. */
172
        priv->suggested_filename = g_path_get_basename(webkit_network_request_get_uri(priv->network_request));
173
        break;
174
    case PROP_DESTINATION_URI:
175
        webkit_download_set_destination_uri(download, g_value_get_string(value));
176
        break;
177
    default:
178
        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
179
    }
180
}
181
182
static void webkit_download_class_init(WebKitDownloadClass* downloadClass)
183
{
184
    /*
185
     * implementations of virtual methods
186
     */
187
    GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass);
188
    objectClass->dispose = webkit_download_dispose;
189
    objectClass->finalize = webkit_download_finalize;
190
    objectClass->get_property = webkit_download_get_property;
191
    objectClass->set_property = webkit_download_set_property;
192
193
    /**
194
     * WebKitDownload::error:
195
     * @download: the object on which the signal is emitted
196
     * @current_bytes: the current count of bytes downloaded
197
     * @total_bytes: the total bytes count in the downloaded file, aka file size.
198
     *
199
     * Indicates an error in the download.
200
     *
201
     * Since: 1.1.1
202
     */
203
    webkit_download_signals[ERROR] = g_signal_new("error",
204
            G_TYPE_FROM_CLASS(downloadClass),
205
            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
206
            0,
207
            g_signal_accumulator_true_handled,
208
            NULL,
209
            webkit_marshal_BOOLEAN__INT_INT_STRING,
210
            G_TYPE_BOOLEAN, 3,
211
            G_TYPE_INT,
212
            G_TYPE_INT,
213
            G_TYPE_STRING);
214
215
    /*
216
     * properties
217
     */
218
219
    /**
220
    * WebKitDownload:network-request
221
    *
222
    * The #WebKitNetworkRequest instance associated with the download.
223
    *
224
    * Since: 1.1.1
225
    */
226
    g_object_class_install_property(objectClass,
227
                                    PROP_NETWORK_REQUEST,
228
                                    g_param_spec_object(
229
                                    "network-request",
230
                                    "Network Request",
231
                                    "The network request for the URI that should be downloaded",
232
                                    WEBKIT_TYPE_NETWORK_REQUEST,
233
                                    (GParamFlags)(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
234
235
    /**
236
    * WebKitDownload:destination-uri
237
    *
238
    * The URI of the save location for this download.
239
    *
240
    * Since: 1.1.1
241
    */
242
    g_object_class_install_property(objectClass,
243
                                    PROP_DESTINATION_URI,
244
                                    g_param_spec_string(
245
                                    "destination-uri",
246
                                    "Destination URI",
247
                                    "The destination URI where to save the file",
248
                                    "",
249
                                    WEBKIT_PARAM_READWRITE));
250
251
    /**
252
    * WebKitDownload:suggested-filename
253
    *
254
    * The file name suggested as default when saving
255
    *
256
    * Since: 1.1.1
257
    */
258
    g_object_class_install_property(objectClass,
259
                                    PROP_SUGGESTED_FILENAME,
260
                                    g_param_spec_string(
261
                                    "suggested-filename",
262
                                    "Suggested Filename",
263
                                    "The filename suggested as default when saving",
264
                                    "",
265
                                    WEBKIT_PARAM_READABLE));
266
267
   /**
268
   * WebKitDownload:progress:
269
   *
270
   * Determines the current progress of the download.
271
   *
272
   * Since: 1.1.1
273
   */
274
   g_object_class_install_property(objectClass, PROP_PROGRESS,
275
                                   g_param_spec_double("progress",
276
                                                       "Progress",
277
                                                       "Determines the current progress of the download",
278
                                                       0.0, 1.0, 1.0,
279
                                                       WEBKIT_PARAM_READABLE));
280
281
    /**
282
    * WebKitDownload:current-size
283
    *
284
    * The length of the data already downloaded
285
    *
286
    * Since: 1.1.1
287
    */
288
    g_object_class_install_property(objectClass,
289
                                    PROP_CURRENT_SIZE,
290
                                    g_param_spec_uint64(
291
                                    "current-size",
292
                                    "Current Size",
293
                                    "The length of the data already downloaded",
294
                                    0, G_MAXUINT64, 0,
295
                                    WEBKIT_PARAM_READABLE));
296
297
    /**
298
    * WebKitDownload:total-size
299
    *
300
    * The total size of the file
301
    *
302
    * Since: 1.1.1
303
    */
304
    g_object_class_install_property(objectClass,
305
                                    PROP_CURRENT_SIZE,
306
                                    g_param_spec_uint64(
307
                                    "total-size",
308
                                    "Total Size",
309
                                    "The total size of the file",
310
                                    0, G_MAXUINT64, 0,
311
                                    WEBKIT_PARAM_READABLE));
312
313
    g_type_class_add_private(downloadClass, sizeof(WebKitDownloadPrivate));
314
}
315
316
static void webkit_download_init(WebKitDownload* download)
317
{
318
    WebKitDownloadPrivate* priv = WEBKIT_DOWNLOAD_GET_PRIVATE(download);
319
    download->priv = priv;
320
321
    priv->download_client = new DownloadClient(download);
322
    priv->current_size = 0;
323
    priv->state = WEBKIT_DOWNLOAD_STATE_CREATED;
324
}
325
326
/**
327
 * webkit_download_new:
328
 * @uri: a URI
329
 *
330
 * Creates a new #WebKitDownload object for the given URI.
331
 *
332
 * Returns: the new #WebKitDownload
333
 *
334
 * Since: 1.1.1
335
 */
336
WebKitDownload* webkit_download_new(const gchar* uri)
337
{
338
    g_return_val_if_fail(uri, 0);
339
340
    WebKitNetworkRequest* request = webkit_network_request_new(uri);
341
    WebKitDownload* download = webkit_download_new_from_request(request);
342
    g_object_unref(request);
343
    return download;
344
}
345
346
/**
347
 * webkit_download_new_from_request:
348
 * @request: a #WebKitNetworkRequest
349
 *
350
 * Creates a new #WebKitDownload object for the given
351
 * #WebKitNetworkRequest object.
352
 *
353
 * Returns: the new #WebKitDownload
354
 *
355
 * Since: 1.1.1
356
 */
357
WebKitDownload* webkit_download_new_from_request(WebKitNetworkRequest* request)
358
{
359
    g_return_val_if_fail(request, 0);
360
361
    WebKitDownload* download = WEBKIT_DOWNLOAD(g_object_new(WEBKIT_TYPE_DOWNLOAD, "network-request", request, NULL));
362
    return download;
363
}
364
365
static gboolean webkit_download_open_stream_for_uri(WebKitDownload* download, const gchar* uri, gboolean append=FALSE)
366
{
367
    g_return_val_if_fail(uri, FALSE);
368
369
    WebKitDownloadPrivate* priv = download->priv;
370
    GFile* file = g_file_new_for_uri(uri);
371
    GError* error = NULL;
372
373
    if (append)
374
        priv->output_stream = g_file_append_to(file, G_FILE_CREATE_NONE, NULL, &error);
375
    else
376
        priv->output_stream = g_file_replace(file, NULL, TRUE, G_FILE_CREATE_NONE, NULL, &error);
377
378
    g_object_unref(file);
379
380
    if(error) {
381
        gboolean handled;
382
        g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled);
383
        g_error_free(error);
384
        return FALSE;
385
    }
386
387
    return TRUE;
388
}
389
390
static void webkit_download_close_stream(WebKitDownload* download)
391
{
392
    WebKitDownloadPrivate* priv = download->priv;
393
    if (priv->output_stream) {
394
        g_object_unref(priv->output_stream);
395
        priv->output_stream = NULL;
396
    }
397
}
398
399
/**
400
 * webkit_download_start:
401
 * @download: the #WebKitDownload
402
 *
403
 * Initiates the download. Notice that you must have set the
404
 * destination-uri property before calling this method.
405
 *
406
 * Since: 1.1.1
407
 */
408
void webkit_download_start(WebKitDownload* download)
409
{
410
    g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
411
412
    WebKitDownloadPrivate* priv = download->priv;
413
    g_return_if_fail(priv->destination_uri);
414
    g_return_if_fail(priv->state == WEBKIT_DOWNLOAD_STATE_CREATED);
415
    g_return_if_fail(priv->timer == NULL);
416
417
    if (priv->resource_handle)
418
        priv->resource_handle->setClient(priv->download_client);
419
    else {
420
        // FIXME use kit(priv->network_request) when WebKitNetworkRequest will be finished.
421
        ResourceRequest request(webkit_network_request_get_uri(priv->network_request));
422
        priv->resource_handle = ResourceHandle::create(request, priv->download_client, 0, false, false, false);
423
    }
424
425
    priv->timer = g_timer_new ();
426
    webkit_download_open_stream_for_uri(download, priv->destination_uri);
427
}
428
429
/**
430
 * webkit_download_cancel:
431
 * @download: the #WebKitDownload
432
 *
433
 * Cancels the download. Calling this will not free the
434
 * #WebKitDownload object, so you still need to call
435
 * g_object_unref() on it, if you are the owner of a reference. Notice
436
 * that cancelling the download provokes the emission of the
437
 * WebKitDownload::error signal, reporting that the download was
438
 * cancelled.
439
 *
440
 * Since: 1.1.1
441
 */
442
void webkit_download_cancel(WebKitDownload* download)
443
{
444
    g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
445
446
    WebKitDownloadPrivate* priv = download->priv;
447
448
    g_timer_stop(priv->timer);
449
450
    if (priv->resource_handle)
451
        priv->resource_handle->cancel();
452
453
    priv->state = WEBKIT_DOWNLOAD_STATE_CANCELLED;
454
455
    gboolean handled;
456
    g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER, "User cancelled the download", &handled);
457
}
458
459
/**
460
 * webkit_download_get_uri:
461
 * @download: the #WebKitDownload
462
 *
463
 * Convenience method to retrieve the URI from the
464
 * #WebKitNetworkRequest which is being downloaded.
465
 *
466
 * Returns: the uri
467
 *
468
 * Since: 1.1.1
469
 */
470
const gchar* webkit_download_get_uri(WebKitDownload* download)
471
{
472
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL);
473
474
    WebKitDownloadPrivate* priv = download->priv;
475
    return webkit_network_request_get_uri(priv->network_request);
476
}
477
478
/**
479
 * webkit_download_get_network_request:
480
 * @download: the #WebKitDownload
481
 *
482
 * Retrieves the #WebKitNetworkRequest object that backs the download
483
 * process.
484
 *
485
 * Returns: the #WebKitNetworkRequest instance
486
 *
487
 * Since: 1.1.1
488
 */
489
WebKitNetworkRequest* webkit_download_get_network_request(WebKitDownload* download)
490
{
491
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL);
492
493
    WebKitDownloadPrivate* priv = download->priv;
494
    return priv->network_request;
495
}
496
497
static void webkit_download_set_response(WebKitDownload* download, const ResourceResponse& response)
498
{
499
    // FIXME Use WebKitNetworkResponse when it's merged
500
    WebKitDownloadPrivate* priv = download->priv;
501
    priv->network_response = new ResourceResponse(response);
502
}
503
504
/**
505
 * webkit_download_get_suggested_filename:
506
 * @download: the #WebKitDownload
507
 *
508
 * Retrieves the filename that was suggested by the server, or the one
509
 * derived by WebKit from the URI.
510
 *
511
 * Returns: the suggested filename
512
 *
513
 * Since: 1.1.1
514
 */
515
const gchar* webkit_download_get_suggested_filename(WebKitDownload* download)
516
{
517
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL);
518
519
    WebKitDownloadPrivate* priv = download->priv;
520
    return priv->suggested_filename;
521
}
522
523
/**
524
 * webkit_download_get_destination_uri:
525
 * @download: the #WebKitDownload
526
 *
527
 * Obtains the URI to which the downloaded file will be written. This
528
 * must have been set by the application before calling
529
 * webkit_download_start(), and may be %NULL.
530
 *
531
 * Returns: the destination URI or %NULL
532
 *
533
 * Since: 1.1.1
534
 */
535
const gchar* webkit_download_get_destination_uri(WebKitDownload* download)
536
{
537
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL);
538
539
    WebKitDownloadPrivate* priv = download->priv;
540
    return priv->destination_uri;
541
}
542
543
/**
544
 * webkit_download_get_destination_uri:
545
 * @download: the #WebKitDownload
546
 * @destination_uri: the destination URI
547
 *
548
 * Defines the URI that should be used to save the downloaded file to.
549
 *
550
 * Since: 1.1.1
551
 */
552
void webkit_download_set_destination_uri(WebKitDownload* download, const gchar* destination_uri)
553
{
554
    g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
555
    g_return_if_fail(destination_uri);
556
557
    WebKitDownloadPrivate* priv = download->priv;
558
    if (priv->destination_uri && !strcmp(priv->destination_uri, destination_uri))
559
        return;
560
561
    // FIXME can we have a better check?
562
    if (priv->state != WEBKIT_DOWNLOAD_STATE_CREATED && priv->state != WEBKIT_DOWNLOAD_STATE_CANCELLED) {
563
        ASSERT(priv->destination_uri);
564
565
        gboolean downloading = priv->output_stream != NULL;
566
        if (downloading)
567
            webkit_download_close_stream(download);
568
569
        GFile* src = g_file_new_for_uri(priv->destination_uri);
570
        GFile* dest = g_file_new_for_uri(destination_uri);
571
        GError *error = NULL;
572
573
        g_file_move(src, dest, G_FILE_COPY_BACKUP, NULL, NULL, NULL, &error);
574
575
        g_object_unref(src);
576
        g_object_unref(dest);
577
578
        if (error) {
579
            gboolean handled;
580
            g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled);
581
            g_error_free(error);
582
            return;
583
        }
584
585
        if (downloading) {
586
            if (!webkit_download_open_stream_for_uri(download, destination_uri, TRUE)) {
587
                webkit_download_cancel(download);
588
                return;
589
            }
590
        }
591
    }
592
593
    g_free(priv->destination_uri);
594
    priv->destination_uri = g_strdup(destination_uri);
595
    g_object_notify(G_OBJECT(download), "destination-uri");
596
}
597
598
/**
599
 * webkit_download_get_state:
600
 * @download: the #WebKitDownload
601
 *
602
 * Obtains the current state of the download, as a
603
 * #WebKitDownloadState.
604
 *
605
 * Returns: the current #WebKitDownloadState
606
 *
607
 * Since: 1.1.1
608
 */
609
WebKitDownloadState webkit_download_get_state (WebKitDownload* download)
610
{
611
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), WEBKIT_DOWNLOAD_STATE_ERROR);
612
613
    WebKitDownloadPrivate* priv = download->priv;
614
    return priv->state;
615
}
616
617
/**
618
 * webkit_download_get_total_size:
619
 * @download: the #WebKitDownload
620
 *
621
 * Returns the expected total size of the download. This is expected
622
 * because the server may provide incorrect or missing
623
 * Content-Length. Notice that this may grow over time, as it will be
624
 * always the same as current_size in the cases where current size
625
 * surpasses it.
626
 *
627
 * Returns: the expected total size of the downloaded file
628
 *
629
 * Since: 1.1.1
630
 */
631
guint64 webkit_download_get_total_size (WebKitDownload* download)
632
{
633
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
634
635
    WebKitDownloadPrivate* priv = download->priv;
636
    if (!priv->network_response)
637
        return 0;
638
639
    return MAX(priv->current_size, priv->network_response->expectedContentLength());
640
}
641
642
/**
643
 * webkit_download_get_current_size:
644
 * @download: the #WebKitDownload
645
 *
646
 * Current already downloaded size.
647
 *
648
 * Returns: the already downloaded size
649
 *
650
 * Since: 1.1.1
651
 */
652
guint64 webkit_download_get_current_size (WebKitDownload* download)
653
{
654
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
655
656
    WebKitDownloadPrivate* priv = download->priv;
657
    return priv->current_size;
658
}
659
660
/**
661
 * webkit_download_get_progress:
662
 * @web_view: a #WebKitDownload
663
 *
664
 * Determines the current progress of the download.
665
 *
666
 * Returns: a #gdouble ranging from 0.0 to 1.0.
667
 *
668
 * Since: 1.1.1
669
 */
670
gdouble webkit_download_get_progress(WebKitDownload* download)
671
{
672
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 1.0);
673
674
    WebKitDownloadPrivate* priv = download->priv;
675
    gdouble total_size = (gdouble)priv->network_response->expectedContentLength();
676
677
    if (total_size == 0)
678
        return 1.0;
679
680
    return ((gdouble)priv->current_size) / total_size;
681
}
682
683
/**
684
 * webkit_download_get_elapsed_time:
685
 * @web_view: a #WebKitDownload
686
 *
687
 * Elapsed time for the download in seconds, including any fractional
688
 * part. If the download is finished, had an error or was cancelled
689
 * this is the time between its start and the event.
690
 *
691
 * Returns: seconds since the download was started, as a #gdouble
692
 *
693
 * Since: 1.1.1
694
 */
695
gdouble webkit_download_get_elapsed_time(WebKitDownload* download)
696
{
697
    g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0.0);
698
699
    WebKitDownloadPrivate* priv = download->priv;
700
    return g_timer_elapsed(priv->timer, NULL);
701
}
702
703
static void webkit_download_received_data(WebKitDownload* download, const gchar* data, int length)
704
{
705
    WebKitDownloadPrivate* priv = download->priv;
706
707
    if (priv->current_size == 0) {
708
        priv->state = WEBKIT_DOWNLOAD_STATE_STARTED;
709
    }
710
711
    ASSERT(priv->output_stream);
712
713
    gsize bytes_written;
714
    GError *error = NULL;
715
716
    g_output_stream_write_all(G_OUTPUT_STREAM(priv->output_stream),
717
                              data, length, &bytes_written, NULL, &error);
718
719
    if (error) {
720
        gboolean handled;
721
        g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_DESTINATION, error->message, &handled);
722
        g_error_free(error);
723
        return;
724
    }
725
726
    priv->current_size += length;
727
    g_object_notify(G_OBJECT(download), "current-size");
728
729
    ASSERT(priv->network_response);
730
    if (priv->current_size > priv->network_response->expectedContentLength())
731
        g_object_notify(G_OBJECT(download), "total-size");
732
733
    /* FIXME throttle the number of updates?
734
     * should we remove the previous g_object_notify()s if we are going to throttle
735
     * the progress updates? */
736
    g_object_notify(G_OBJECT(download), "progress");
737
}
738
739
static void webkit_download_finished_loading(WebKitDownload* download)
740
{
741
    webkit_download_close_stream(download);
742
743
    WebKitDownloadPrivate* priv = download->priv;
744
745
    g_timer_stop(priv->timer);
746
    priv->state = WEBKIT_DOWNLOAD_STATE_FINISHED;
747
748
    g_object_notify(G_OBJECT(download), "progress");
749
}
750
751
static void webkit_download_error(WebKitDownload* download, const ResourceError& error)
752
{
753
    webkit_download_close_stream(download);
754
755
    WebKitDownloadPrivate* priv = download->priv;
756
757
    g_timer_stop(priv->timer);
758
    priv->state = WEBKIT_DOWNLOAD_STATE_ERROR;
759
760
    gboolean handled;
761
    g_signal_emit_by_name(download, "error", 0, WEBKIT_DOWNLOAD_ERROR_NETWORK, error.localizedDescription().utf8().data(), &handled);
762
}
763
764
DownloadClient::DownloadClient(WebKitDownload* download)
765
    : m_download(download)
766
{
767
}
768
769
void DownloadClient::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)
770
{
771
    webkit_download_set_response(m_download, response);
772
}
773
774
void DownloadClient::didReceiveData(ResourceHandle*, const char* data, int length, int lengthReceived)
775
{
776
    webkit_download_received_data(m_download, data, length);
777
}
778
779
void DownloadClient::didFinishLoading(ResourceHandle*)
780
{
781
    webkit_download_finished_loading(m_download);
782
}
783
784
void DownloadClient::didFail(ResourceHandle*, const ResourceError& error)
785
{
786
    webkit_download_error(m_download, error);
787
}
788
789
void DownloadClient::wasBlocked(ResourceHandle*)
790
{
791
    // FIXME when we have the new frame loader signals and error handling.
792
    notImplemented();
793
}
794
795
void DownloadClient::cannotShowURL(ResourceHandle*)
796
{
797
    // FIXME when we have the new frame loader signals and error handling.
798
    notImplemented();
799
}
800
801
}
(-)a/WebKit/gtk/webkit/webkitdownload.h (+117 lines)
Line 0 Link Here
1
/*
2
 * Copyright (C) 2008 Collabora Ltd.
3
 * Copyright (C) 2009 Gustavo Noronha Silva <gns@gnome.org>
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Library General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2 of the License, or (at your option) any later version.
9
 *
10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Library General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Library General Public License
16
 * along with this library; see the file COPYING.LIB.  If not, write to
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18
 * Boston, MA 02110-1301, USA.
19
 */
20
21
#ifndef WEBKIT_DOWNLOAD_H
22
#define WEBKIT_DOWNLOAD_H
23
24
#include <glib-object.h>
25
26
#include <webkit/webkitdefines.h>
27
28
G_BEGIN_DECLS
29
30
#define WEBKIT_TYPE_DOWNLOAD            (webkit_download_get_type())
31
#define WEBKIT_DOWNLOAD(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownload))
32
#define WEBKIT_DOWNLOAD_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass),  WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass))
33
#define WEBKIT_IS_DOWNLOAD(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DOWNLOAD))
34
#define WEBKIT_IS_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),  WEBKIT_TYPE_DOWNLOAD))
35
#define WEBKIT_DOWNLOAD_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj),  WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass))
36
37
typedef enum {
38
    WEBKIT_DOWNLOAD_STATE_ERROR = -1,
39
    WEBKIT_DOWNLOAD_STATE_CREATED = 0,
40
    WEBKIT_DOWNLOAD_STATE_STARTED,
41
    WEBKIT_DOWNLOAD_STATE_CANCELLED,
42
    WEBKIT_DOWNLOAD_STATE_FINISHED
43
} WebKitDownloadState;
44
45
typedef enum {
46
    WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER,
47
    WEBKIT_DOWNLOAD_ERROR_DESTINATION,
48
    WEBKIT_DOWNLOAD_ERROR_NETWORK
49
} WebKitDownloadError;
50
51
typedef struct _WebKitDownloadPrivate WebKitDownloadPrivate;
52
53
struct _WebKitDownload {
54
    GObject parent;
55
56
    WebKitDownloadPrivate* priv;
57
};
58
59
struct _WebKitDownloadClass {
60
    GObjectClass parent;
61
62
    /* Padding for future expansion */
63
    void (*_webkit_reserved0) (void);
64
    void (*_webkit_reserved1) (void);
65
    void (*_webkit_reserved2) (void);
66
    void (*_webkit_reserved3) (void);
67
};
68
69
WEBKIT_API GType
70
webkit_download_get_type                    (void);
71
72
WEBKIT_API WebKitDownload *
73
webkit_download_new                         (const gchar *uri);
74
75
WEBKIT_API WebKitDownload *
76
webkit_download_new_from_request            (WebKitNetworkRequest *request);
77
78
WEBKIT_API void
79
webkit_download_start                       (WebKitDownload    *download);
80
81
WEBKIT_API void
82
webkit_download_cancel                      (WebKitDownload    *download);
83
84
WEBKIT_API const gchar*
85
webkit_download_get_uri                     (WebKitDownload    *download);
86
87
WEBKIT_API WebKitNetworkRequest*
88
webkit_download_get_network_request         (WebKitDownload    *download);
89
90
WEBKIT_API const gchar*
91
webkit_download_get_suggested_filename      (WebKitDownload    *download);
92
93
WEBKIT_API const gchar*
94
webkit_download_get_destination_uri         (WebKitDownload    *download);
95
96
WEBKIT_API void
97
webkit_download_set_destination_uri         (WebKitDownload    *download,
98
                                             const gchar       *destination_uri);
99
100
WEBKIT_API gdouble
101
webkit_download_get_progress                (WebKitDownload    *download);
102
103
WEBKIT_API gdouble
104
webkit_download_get_elapsed_time            (WebKitDownload    *download);
105
106
WEBKIT_API guint64
107
webkit_download_get_total_size              (WebKitDownload    *download);
108
109
WEBKIT_API guint64
110
webkit_download_get_current_size            (WebKitDownload    *download);
111
112
WEBKIT_API WebKitDownloadState
113
webkit_download_get_state                   (WebKitDownload    *download);
114
115
G_END_DECLS
116
117
#endif
(-)a/WebKit/gtk/webkit/webkitprivate.h (+5 lines)
Lines 32-37 Link Here
32
#include <webkit/webkitwebframe.h>
32
#include <webkit/webkitwebframe.h>
33
#include <webkit/webkitwebpolicydecision.h>
33
#include <webkit/webkitwebpolicydecision.h>
34
#include <webkit/webkitwebnavigationaction.h>
34
#include <webkit/webkitwebnavigationaction.h>
35
#include <webkit/webkitdownload.h>
35
#include <webkit/webkitwebsettings.h>
36
#include <webkit/webkitwebsettings.h>
36
#include <webkit/webkitwebwindowfeatures.h>
37
#include <webkit/webkitwebwindowfeatures.h>
37
#include <webkit/webkitwebbackforwardlist.h>
38
#include <webkit/webkitwebbackforwardlist.h>
Lines 44-52 Link Here
44
#include "InspectorClientGtk.h"
45
#include "InspectorClientGtk.h"
45
#include "FrameLoaderClient.h"
46
#include "FrameLoaderClient.h"
46
#include "WindowFeatures.h"
47
#include "WindowFeatures.h"
48
#include "ResourceHandle.h"
49
#include "ResourceResponse.h"
47
50
48
#include <glib.h>
51
#include <glib.h>
49
52
53
class DownloadClient;
54
50
namespace WebKit {
55
namespace WebKit {
51
    WebKitWebView* getViewFromFrame(WebKitWebFrame*);
56
    WebKitWebView* getViewFromFrame(WebKitWebFrame*);
52
57
(-)a/WebKit/gtk/webkit/webkitwebview.cpp (+30 lines)
Lines 25-30 Link Here
25
25
26
#include "config.h"
26
#include "config.h"
27
27
28
#include "webkitdownload.h"
28
#include "webkitwebview.h"
29
#include "webkitwebview.h"
29
#include "webkitenumtypes.h"
30
#include "webkitenumtypes.h"
30
#include "webkitmarshal.h"
31
#include "webkitmarshal.h"
Lines 133-138 enum { Link Here
133
    COPY_CLIPBOARD,
134
    COPY_CLIPBOARD,
134
    PASTE_CLIPBOARD,
135
    PASTE_CLIPBOARD,
135
    CUT_CLIPBOARD,
136
    CUT_CLIPBOARD,
137
    DOWNLOAD_REQUESTED,
136
    LAST_SIGNAL
138
    LAST_SIGNAL
137
};
139
};
138
140
Lines 811-816 static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView) Link Here
811
    frame->editor()->command("Paste").execute();
813
    frame->editor()->command("Paste").execute();
812
}
814
}
813
815
816
static gboolean webkit_web_view_real_download_requested(WebKitWebView* web_view, WebKitDownload* download)
817
{
818
    webkit_download_cancel(download);
819
    // Return false to indicate it wasn't handled therefore the download is deleted
820
    return FALSE;
821
}
822
814
static void webkit_web_view_dispose(GObject* object)
823
static void webkit_web_view_dispose(GObject* object)
815
{
824
{
816
    WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
825
    WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
Lines 1084-1089 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) Link Here
1084
            G_TYPE_POINTER,
1093
            G_TYPE_POINTER,
1085
            G_TYPE_POINTER);
1094
            G_TYPE_POINTER);
1086
1095
1096
     /**
1097
     * WebKitWebView::download-requested:
1098
     * @web_view: the object on which the signal is emitted
1099
     * @download: the message text
1100
     * @return: TRUE if the download was handled, otherwise it'll be cancelled.
1101
     *
1102
     * A new Download is being requested.
1103
     *
1104
     * Since: 1.1.1
1105
     */
1106
    webkit_web_view_signals[DOWNLOAD_REQUESTED] = g_signal_new("download-requested",
1107
            G_TYPE_FROM_CLASS(webViewClass),
1108
            (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
1109
            G_STRUCT_OFFSET(WebKitWebViewClass, download_requested),
1110
            g_signal_accumulator_true_handled,
1111
            NULL,
1112
            webkit_marshal_BOOLEAN__OBJECT,
1113
            G_TYPE_BOOLEAN, 1,
1114
            G_TYPE_OBJECT);
1115
1087
    /**
1116
    /**
1088
     * WebKitWebView::load-started:
1117
     * WebKitWebView::load-started:
1089
     * @web_view: the object on which the signal is emitted
1118
     * @web_view: the object on which the signal is emitted
Lines 1393-1398 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) Link Here
1393
    webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
1422
    webViewClass->cut_clipboard = webkit_web_view_real_cut_clipboard;
1394
    webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
1423
    webViewClass->copy_clipboard = webkit_web_view_real_copy_clipboard;
1395
    webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
1424
    webViewClass->paste_clipboard = webkit_web_view_real_paste_clipboard;
1425
    webViewClass->download_requested = webkit_web_view_real_download_requested;
1396
1426
1397
    GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
1427
    GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
1398
    objectClass->dispose = webkit_web_view_dispose;
1428
    objectClass->dispose = webkit_web_view_dispose;
(-)a/WebKit/gtk/webkit/webkitwebview.h (-1 / +2 lines)
Lines 102-107 struct _WebKitWebViewClass { Link Here
102
    void                       (* cut_clipboard)          (WebKitWebView        *web_view);
102
    void                       (* cut_clipboard)          (WebKitWebView        *web_view);
103
    void                       (* copy_clipboard)         (WebKitWebView        *web_view);
103
    void                       (* copy_clipboard)         (WebKitWebView        *web_view);
104
    void                       (* paste_clipboard)        (WebKitWebView        *web_view);
104
    void                       (* paste_clipboard)        (WebKitWebView        *web_view);
105
    gboolean                   (* download_requested)     (WebKitWebView        *web_view,
106
                                                           WebKitDownload       *download);
105
107
106
    /*
108
    /*
107
     * internal
109
     * internal
108
- 

Return to bug 16826