Log Message
[GTK] Add WebKitDownload to WebKit2 GTK+ API https://bugs.webkit.org/show_bug.cgi?id=72949
Reviewed by Martin Robinson. Source/_javascript_Core: * wtf/gobject/GOwnPtr.cpp: (WTF::GTimer): Use g_timer_destroy() to free a GTimer. * wtf/gobject/GOwnPtr.h: Add GTimer template. * wtf/gobject/GTypedefs.h: Add GTimer forward declaration. Source/WebKit2: * GNUmakefile.am: Add new files to compilation. * UIProcess/API/gtk/WebKitDownload.cpp: Added. (webkitDownloadFinalize): (webkitDownloadGetProperty): (webkitDownloadDecideDestination): (webkit_download_init): (webkit_download_class_init): (webkitDownloadCreate): Create a new WebKitDownload for a given WKDownloadRef. (webkitDownloadSetResponse): Set the network response of the download. (webkitDownloadIsCancelled): Whether the download has been cancelled by the user. (webkitDownloadNotifyProgress): Emit notify::estimated-progress if needed. (webkitDownloadFailed): Emit WebKitDownload::failed with the given error. (webkitDownloadCancelled): Emit WebKitDownload::failed with cancelled error. (webkitDownloadFinished): Emit WebKitDownload::finished. (webkitDownloadDecideDestinationWithSuggestedFilename): Emit WebKitDownload::decide-destination. (webkitDownloadDestinationCreated): Emit WebKitDownload::created-destination. (webkit_download_get_destination): Return the destination URI of the download. (webkit_download_set_destination): Set the destination URI of the download. (webkit_download_get_response): Return the response received by the server. (webkit_download_cancel): Cancel the download. (webkit_download_get_estimated_progress): Return the estimated progress. (webkit_download_get_elapsed_time): Return the time elapsed since the download started. * UIProcess/API/gtk/WebKitDownload.h: Added. * UIProcess/API/gtk/WebKitDownloadPrivate.h: Added. * UIProcess/API/gtk/WebKitPrivate.h: * UIProcess/API/gtk/WebKitURIResponse.cpp: (webkitURIResponseGetResourceResponse): * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols. * UIProcess/API/gtk/docs/webkit2gtk.types: Add webkit_download_get_type(). * UIProcess/API/gtk/webkit2.h: Include WebKitDownload.h. * UIProcess/API/gtk/webkit2marshal.list:
Modified Paths
- trunk/Source/_javascript_Core/ChangeLog
- trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.cpp
- trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.h
- trunk/Source/_javascript_Core/wtf/gobject/GTypedefs.h
- trunk/Source/WebKit2/ChangeLog
- trunk/Source/WebKit2/GNUmakefile.am
- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h
- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml
- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types
- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h
- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list
Added Paths
Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (105703 => 105704)
--- trunk/Source/_javascript_Core/ChangeLog 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/_javascript_Core/ChangeLog 2012-01-24 08:49:47 UTC (rev 105704)
@@ -1,3 +1,15 @@
+2012-01-23 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Add WebKitDownload to WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=72949
+
+ Reviewed by Martin Robinson.
+
+ * wtf/gobject/GOwnPtr.cpp:
+ (WTF::GTimer): Use g_timer_destroy() to free a GTimer.
+ * wtf/gobject/GOwnPtr.h: Add GTimer template.
+ * wtf/gobject/GTypedefs.h: Add GTimer forward declaration.
+
2012-01-24 Ilya Tikhonovsky <[email protected]>
Unreviewed build fix for Qt LinuxSH4 build after r105698.
Modified: trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.cpp (105703 => 105704)
--- trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.cpp 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.cpp 2012-01-24 08:49:47 UTC (rev 105704)
@@ -49,6 +49,12 @@
g_dir_close(ptr);
}
+template <> void freeOwnedGPtr<GTimer>(GTimer* ptr)
+{
+ if (ptr)
+ g_timer_destroy(ptr);
+}
+
} // namespace WTF
#endif // ENABLE(GLIB_SUPPORT)
Modified: trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.h (105703 => 105704)
--- trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.h 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/_javascript_Core/wtf/gobject/GOwnPtr.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -37,6 +37,7 @@
template<> void freeOwnedGPtr<GList>(GList*);
template<> void freeOwnedGPtr<GPatternSpec>(GPatternSpec*);
template<> void freeOwnedGPtr<GDir>(GDir*);
+template<> void freeOwnedGPtr<GTimer>(GTimer*);
template <typename T> class GOwnPtr {
WTF_MAKE_NONCOPYABLE(GOwnPtr);
Modified: trunk/Source/_javascript_Core/wtf/gobject/GTypedefs.h (105703 => 105704)
--- trunk/Source/_javascript_Core/wtf/gobject/GTypedefs.h 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/_javascript_Core/wtf/gobject/GTypedefs.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -58,6 +58,7 @@
typedef struct _GSource GSource;
typedef struct _GVariant GVariant;
typedef union _GdkEvent GdkEvent;
+typedef struct _GTimer GTimer;
#if USE(CAIRO)
typedef struct _cairo_surface cairo_surface_t;
Modified: trunk/Source/WebKit2/ChangeLog (105703 => 105704)
--- trunk/Source/WebKit2/ChangeLog 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/ChangeLog 2012-01-24 08:49:47 UTC (rev 105704)
@@ -1,3 +1,56 @@
+2012-01-23 Carlos Garcia Campos <[email protected]>
+
+ [GTK] Add WebKitDownload to WebKit2 GTK+ API
+ https://bugs.webkit.org/show_bug.cgi?id=72949
+
+ Reviewed by Martin Robinson.
+
+ * GNUmakefile.am: Add new files to compilation.
+ * UIProcess/API/gtk/WebKitDownload.cpp: Added.
+ (webkitDownloadFinalize):
+ (webkitDownloadGetProperty):
+ (webkitDownloadDecideDestination):
+ (webkit_download_init):
+ (webkit_download_class_init):
+ (webkitDownloadCreate): Create a new WebKitDownload for a given
+ WKDownloadRef.
+ (webkitDownloadSetResponse): Set the network response of the
+ download.
+ (webkitDownloadIsCancelled): Whether the download has been
+ cancelled by the user.
+ (webkitDownloadNotifyProgress): Emit notify::estimated-progress if
+ needed.
+ (webkitDownloadFailed): Emit WebKitDownload::failed with the given
+ error.
+ (webkitDownloadCancelled): Emit WebKitDownload::failed with
+ cancelled error.
+ (webkitDownloadFinished): Emit WebKitDownload::finished.
+ (webkitDownloadDecideDestinationWithSuggestedFilename): Emit
+ WebKitDownload::decide-destination.
+ (webkitDownloadDestinationCreated): Emit
+ WebKitDownload::created-destination.
+ (webkit_download_get_destination): Return the destination URI of
+ the download.
+ (webkit_download_set_destination): Set the destination URI of the
+ download.
+ (webkit_download_get_response): Return the response received by
+ the server.
+ (webkit_download_cancel): Cancel the download.
+ (webkit_download_get_estimated_progress): Return the estimated
+ progress.
+ (webkit_download_get_elapsed_time): Return the time elapsed since
+ the download started.
+ * UIProcess/API/gtk/WebKitDownload.h: Added.
+ * UIProcess/API/gtk/WebKitDownloadPrivate.h: Added.
+ * UIProcess/API/gtk/WebKitPrivate.h:
+ * UIProcess/API/gtk/WebKitURIResponse.cpp:
+ (webkitURIResponseGetResourceResponse):
+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
+ * UIProcess/API/gtk/docs/webkit2gtk.types: Add
+ webkit_download_get_type().
+ * UIProcess/API/gtk/webkit2.h: Include WebKitDownload.h.
+ * UIProcess/API/gtk/webkit2marshal.list:
+
2012-01-23 Geoffrey Garen <[email protected]>
JSValue::toString() should return a JSString* instead of a UString
Modified: trunk/Source/WebKit2/GNUmakefile.am (105703 => 105704)
--- trunk/Source/WebKit2/GNUmakefile.am 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/GNUmakefile.am 2012-01-24 08:49:47 UTC (rev 105704)
@@ -83,6 +83,7 @@
$(WebKit2)/UIProcess/API/gtk/WebKitBackForwardList.h \
$(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \
$(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \
+ $(WebKit2)/UIProcess/API/gtk/WebKitDownload.h \
$(WebKit2)/UIProcess/API/gtk/WebKitError.h \
$(WebKit2)/UIProcess/API/gtk/WebKitWebContext.h \
$(WebKit2)/UIProcess/API/gtk/WebKitSettings.h \
@@ -521,6 +522,9 @@
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h \
Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp \
+ Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h \
+ Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h \
Source/WebKit2/UIProcess/API/gtk/WebKitError.h \
Source/WebKit2/UIProcess/API/gtk/WebKitError.cpp \
Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h \
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp (0 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.cpp 2012-01-24 08:49:47 UTC (rev 105704)
@@ -0,0 +1,510 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "WebKitDownload.h"
+
+#include "WebKitDownloadPrivate.h"
+#include "WebKitMarshal.h"
+#include "WebKitURIResponsePrivate.h"
+#include <WebCore/ErrorsGtk.h>
+#include <WebCore/ResourceResponse.h>
+#include <glib/gi18n-lib.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
+
+using namespace WebKit;
+using namespace WebCore;
+
+enum {
+ RECEIVED_DATA,
+ FINISHED,
+ FAILED,
+ DECIDE_DESTINATION,
+ CREATED_DESTINATION,
+
+ LAST_SIGNAL
+};
+
+enum {
+ PROP_0,
+
+ PROP_DESTINATION,
+ PROP_RESPONSE,
+ PROP_ESTIMATED_PROGRESS
+};
+
+struct _WebKitDownloadPrivate {
+ WKRetainPtr<WKDownloadRef> wkDownload;
+
+ GRefPtr<WebKitURIResponse> response;
+ CString destinationURI;
+ guint64 currentSize;
+ bool isCancelled;
+ GOwnPtr<GTimer> timer;
+ gdouble lastProgress;
+ gdouble lastElapsed;
+};
+
+static guint signals[LAST_SIGNAL] = { 0, };
+
+G_DEFINE_TYPE(WebKitDownload, webkit_download, G_TYPE_OBJECT)
+
+static void webkitDownloadFinalize(GObject* object)
+{
+ WEBKIT_DOWNLOAD(object)->priv->~WebKitDownloadPrivate();
+ G_OBJECT_CLASS(webkit_download_parent_class)->finalize(object);
+}
+
+static void webkitDownloadGetProperty(GObject* object, guint propId, GValue* value, GParamSpec* paramSpec)
+{
+ WebKitDownload* download = WEBKIT_DOWNLOAD(object);
+
+ switch (propId) {
+ case PROP_DESTINATION:
+ g_value_set_string(value, webkit_download_get_destination(download));
+ break;
+ case PROP_RESPONSE:
+ g_value_set_object(value, webkit_download_get_response(download));
+ break;
+ case PROP_ESTIMATED_PROGRESS:
+ g_value_set_double(value, webkit_download_get_estimated_progress(download));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
+ }
+}
+
+static gboolean webkitDownloadDecideDestination(WebKitDownload* download, const gchar* suggestedFilename)
+{
+ if (!download->priv->destinationURI.isNull())
+ return FALSE;
+ GOwnPtr<char> destination(g_build_filename(g_get_user_special_dir(G_USER_DIRECTORY_DOWNLOAD), suggestedFilename, NULL));
+ GOwnPtr<char> destinationURI(g_filename_to_uri(destination.get(), 0, 0));
+ download->priv->destinationURI = destinationURI.get();
+ g_object_notify(G_OBJECT(download), "destination");
+ return TRUE;
+}
+
+static void webkit_download_init(WebKitDownload* download)
+{
+ WebKitDownloadPrivate* priv = G_TYPE_INSTANCE_GET_PRIVATE(download, WEBKIT_TYPE_DOWNLOAD, WebKitDownloadPrivate);
+ download->priv = priv;
+ new (priv) WebKitDownloadPrivate();
+}
+
+static void webkit_download_class_init(WebKitDownloadClass* downloadClass)
+{
+ GObjectClass* objectClass = G_OBJECT_CLASS(downloadClass);
+ objectClass->get_property = webkitDownloadGetProperty;
+ objectClass->finalize = webkitDownloadFinalize;
+
+ downloadClass->decide_destination = webkitDownloadDecideDestination;
+
+ /**
+ * WebKitDownload:destination:
+ *
+ * The local URI to where the download will be saved.
+ */
+ g_object_class_install_property(objectClass,
+ PROP_DESTINATION,
+ g_param_spec_string("destination",
+ _("Destination"),
+ _("The local URI to where the download will be saved"),
+ 0,
+ WEBKIT_PARAM_READABLE));
+
+ /**
+ * WebKitDownload:response:
+ *
+ * The #WebKitURIResponse associated with this download.
+ */
+ g_object_class_install_property(objectClass,
+ PROP_RESPONSE,
+ g_param_spec_object("response",
+ _("Response"),
+ _("The response of the download"),
+ WEBKIT_TYPE_URI_RESPONSE,
+ WEBKIT_PARAM_READABLE));
+
+ /**
+ * WebKitDownload:estimated-progress:
+ *
+ * An estimate of the percent completion for the download operation.
+ * This value will range from 0.0 to 1.0. The value is an estimate
+ * based on the total number of bytes expected to be received for
+ * a download.
+ * If you need a more accurate progress information you can connect to
+ * #WebKitDownload::received-data signal to track the progress.
+ */
+ g_object_class_install_property(objectClass,
+ PROP_ESTIMATED_PROGRESS,
+ g_param_spec_double("estimated-progress",
+ _("Estimated Progress"),
+ _("Determines the current progress of the download"),
+ 0.0, 1.0, 1.0,
+ WEBKIT_PARAM_READABLE));
+
+ /**
+ * WebKitDownload::received-data:
+ * @download: the #WebKitDownload
+ * @data_length: the length of data received in bytes
+ *
+ * This signal is emitted after response is received,
+ * every time new data has been written to the destination. It's
+ * useful to know the progress of the download operation.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[RECEIVED_DATA] =
+ g_signal_new("received-data",
+ G_TYPE_FROM_CLASS(objectClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitDownloadClass, received_data),
+ g_signal_accumulator_true_handled, NULL,
+ webkit_marshal_BOOLEAN__UINT64,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_UINT64);
+
+ /**
+ * WebKitDownload::finished:
+ * @download: the #WebKitDownload
+ *
+ * This signal is emitted when download finishes successfully or due to an error.
+ * In case of errors #WebKitDownload::failed signal is emitted before this one.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[FINISHED] =
+ g_signal_new("finished",
+ G_TYPE_FROM_CLASS(objectClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitDownloadClass, finished),
+ g_signal_accumulator_true_handled, NULL,
+ webkit_marshal_BOOLEAN__VOID,
+ G_TYPE_BOOLEAN, 0);
+
+ /**
+ * WebKitDownload::failed:
+ * @download: the #WebKitDownload
+ * @error: the #GError that was triggered
+ *
+ * This signal is emitted when an error occurs during the download
+ * operation. The given @error, of the domain %WEBKIT_DOWNLOAD_ERROR,
+ * contains further details of the failure. If the download is cancelled
+ * with webkit_download_cancel(), this signal is emitted with error
+ * %WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER. The download operation finishes
+ * after an error and #WebKitDownload::finished signal is emitted after this one.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[FAILED] =
+ g_signal_new("failed",
+ G_TYPE_FROM_CLASS(objectClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitDownloadClass, failed),
+ g_signal_accumulator_true_handled, NULL,
+ webkit_marshal_BOOLEAN__POINTER,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_POINTER);
+
+ /**
+ * WebKitDownload::decide-destination:
+ * @download: the #WebKitDownload
+ * @suggested_filename: the filename suggested for the download
+ *
+ * This signal is emitted after response is received to
+ * decide a destination URI for the download. If this signal is not
+ * handled the file will be downloaded to %G_USER_DIRECTORY_DOWNLOAD
+ * directory using @suggested_filename.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[DECIDE_DESTINATION] =
+ g_signal_new("decide-destination",
+ G_TYPE_FROM_CLASS(objectClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitDownloadClass, decide_destination),
+ g_signal_accumulator_true_handled, NULL,
+ webkit_marshal_BOOLEAN__STRING,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING);
+
+ /**
+ * WebKitDownload::created-destination:
+ * @download: the #WebKitDownload
+ * @destination: the destination URI
+ *
+ * This signal is emitted after #WebKitDownload::decide-destination and before
+ * #WebKitDownload::received-data to notify that destination file has been
+ * created successfully at @destination.
+ *
+ * Returns: %TRUE to stop other handlers from being invoked for the event.
+ * %FALSE to propagate the event further.
+ */
+ signals[CREATED_DESTINATION] =
+ g_signal_new("created-destination",
+ G_TYPE_FROM_CLASS(objectClass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(WebKitDownloadClass, created_destination),
+ g_signal_accumulator_true_handled, NULL,
+ webkit_marshal_BOOLEAN__STRING,
+ G_TYPE_BOOLEAN, 1,
+ G_TYPE_STRING);
+
+ g_type_class_add_private(downloadClass, sizeof(WebKitDownloadPrivate));
+}
+
+WebKitDownload* webkitDownloadCreate(WKDownloadRef wkDownload)
+{
+ ASSERT(wkDownload);
+ WebKitDownload* download = WEBKIT_DOWNLOAD(g_object_new(WEBKIT_TYPE_DOWNLOAD, NULL));
+ download->priv->wkDownload = wkDownload;
+ return download;
+}
+
+void webkitDownloadSetResponse(WebKitDownload* download, WebKitURIResponse* response)
+{
+ download->priv->response = response;
+ g_object_notify(G_OBJECT(download), "response");
+}
+
+bool webkitDownloadIsCancelled(WebKitDownload* download)
+{
+ return download->priv->isCancelled;
+}
+
+void webkitDownloadNotifyProgress(WebKitDownload* download, guint64 bytesReceived)
+{
+ WebKitDownloadPrivate* priv = download->priv;
+ if (priv->isCancelled)
+ return;
+
+ if (!download->priv->timer)
+ download->priv->timer.set(g_timer_new());
+
+ priv->currentSize += bytesReceived;
+ gboolean returnValue;
+ g_signal_emit(download, signals[RECEIVED_DATA], 0, bytesReceived, &returnValue);
+
+ // Throttle progress notification to not consume high amounts of
+ // CPU on fast links, except when the last notification occured
+ // more than 0.016 secs ago (60 FPS), or the last notified progress
+ // is passed in 1% or we reached the end.
+ gdouble currentElapsed = g_timer_elapsed(priv->timer.get(), 0);
+ gdouble currentProgress = webkit_download_get_estimated_progress(download);
+
+ if (priv->lastElapsed
+ && priv->lastProgress
+ && (currentElapsed - priv->lastElapsed) < 0.016
+ && (currentProgress - priv->lastProgress) < 0.01
+ && currentProgress < 1.0) {
+ return;
+ }
+ priv->lastElapsed = currentElapsed;
+ priv->lastProgress = currentProgress;
+ g_object_notify(G_OBJECT(download), "estimated-progress");
+}
+
+void webkitDownloadFailed(WebKitDownload* download, const ResourceError& resourceError)
+{
+ GOwnPtr<GError> webError(g_error_new_literal(g_quark_from_string(resourceError.domain().utf8().data()),
+ resourceError.errorCode(),
+ resourceError.localizedDescription().utf8().data()));
+ if (download->priv->timer)
+ g_timer_stop(download->priv->timer.get());
+ gboolean returnValue;
+ g_signal_emit(download, signals[FAILED], 0, webError.get(), &returnValue);
+ g_signal_emit(download, signals[FINISHED], 0, &returnValue);
+}
+
+void webkitDownloadCancelled(WebKitDownload* download)
+{
+ WebKitDownloadPrivate* priv = download->priv;
+ webkitDownloadFailed(download, downloadCancelledByUserError(priv->response ? webkitURIResponseGetResourceResponse(priv->response.get()) : ResourceResponse()));
+}
+
+void webkitDownloadFinished(WebKitDownload* download)
+{
+ if (download->priv->isCancelled) {
+ // Since cancellation is asynchronous, didFinish might be called even
+ // if the download was cancelled. User cancelled the download,
+ // so we should fail with cancelled error even if the download
+ // actually finished successfully.
+ webkitDownloadCancelled(download);
+ return;
+ }
+ if (download->priv->timer)
+ g_timer_stop(download->priv->timer.get());
+ gboolean returnValue;
+ g_signal_emit(download, signals[FINISHED], 0, &returnValue);
+}
+
+CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload* download, const CString& suggestedFilename)
+{
+ if (download->priv->isCancelled)
+ return "";
+ gboolean returnValue;
+ g_signal_emit(download, signals[DECIDE_DESTINATION], 0, suggestedFilename.data(), &returnValue);
+ return download->priv->destinationURI;
+}
+
+void webkitDownloadDestinationCreated(WebKitDownload* download, const CString& destinationURI)
+{
+ if (download->priv->isCancelled)
+ return;
+ gboolean returnValue;
+ g_signal_emit(download, signals[CREATED_DESTINATION], 0, destinationURI.data(), &returnValue);
+}
+
+/**
+ * webkit_download_get_destination:
+ * @download: a #WebKitDownload
+ *
+ * Obtains the URI to which the downloaded file will be written. You
+ * can connect to #WebKitDownload::created-destination to make
+ * sure this method returns a valid destination.
+ *
+ * Returns: the destination URI or %NULL
+ */
+const gchar* webkit_download_get_destination(WebKitDownload* download)
+{
+ g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
+
+ return download->priv->destinationURI.data();
+}
+
+/**
+ * webkit_download_set_destination:
+ * @download: a #WebKitDownload
+ * @uri: the destination URI
+ *
+ * Sets the URI to which the downloaded file will be written.
+ * This method should be called before the download transfer
+ * starts or it will not have any effect on the ongoing download
+ * operation. To set the destination using the filename suggested
+ * by the server connect to #WebKitDownload::decide-destination
+ * signal and call webkit_download_set_destination(). If you want to
+ * set a fixed destination URI that doesn't depend on the suggested
+ * filename you can connect to notify::response signal and call
+ * webkit_download_set_destination().
+ * If #WebKitDownload::decide-destination signal is not handled
+ * and destination URI is not set when the download tranfer starts,
+ * the file will be saved with the filename suggested by the server in
+ * %G_USER_DIRECTORY_DOWNLOAD directory.
+ */
+void webkit_download_set_destination(WebKitDownload* download, const gchar* uri)
+{
+ g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
+ g_return_if_fail(uri);
+
+ WebKitDownloadPrivate* priv = download->priv;
+ if (priv->destinationURI == uri)
+ return;
+
+ priv->destinationURI = uri;
+ g_object_notify(G_OBJECT(download), "destination");
+}
+
+/**
+ * webkit_download_get_response:
+ * @download: a #WebKitDownload
+ *
+ * Retrieves the #WebKitURIResponse object that backs the download
+ * process. This method returns %NULL if called before the response
+ * is received from the server. You can connect to notify::response
+ * signal to be notified when the response is received.
+ *
+ * Returns: (transfer none): the #WebKitURIResponse, or %NULL if
+ * the response hasn't been received yet.
+ */
+WebKitURIResponse* webkit_download_get_response(WebKitDownload* download)
+{
+ g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
+
+ return download->priv->response.get();
+}
+
+/**
+ * webkit_download_cancel:
+ * @download: a #WebKitDownload
+ *
+ * Cancels the download. When the ongoing download
+ * operation is effectively cancelled the signal
+ * #WebKitDownload::failed is emitted with
+ * %WEBKIT_DOWNLOAD_ERROR_CANCELLED_BY_USER error.
+ */
+void webkit_download_cancel(WebKitDownload* download)
+{
+ g_return_if_fail(WEBKIT_IS_DOWNLOAD(download));
+
+ download->priv->isCancelled = true;
+ WKDownloadCancel(download->priv->wkDownload.get());
+}
+
+/**
+ * webkit_download_get_estimated_progress:
+ * @download: a #WebKitDownload
+ *
+ * Gets the value of the #WebKitDownload:estimated-progress property.
+ * You can monitor the estimated progress of the download operation by
+ * connecting to the notify::estimated-progress signal of @download.
+ *
+ * Returns: an estimate of the of the percent complete for a download
+ * as a range from 0.0 to 1.0.
+ */
+gdouble webkit_download_get_estimated_progress(WebKitDownload* download)
+{
+ g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
+
+ WebKitDownloadPrivate* priv = download->priv;
+ if (!priv->response)
+ return 0;
+
+ guint64 contentLength = webkit_uri_response_get_content_length(priv->response.get());
+ if (!contentLength)
+ return 0;
+
+ return static_cast<gdouble>(priv->currentSize) / static_cast<gdouble>(contentLength);
+}
+
+/**
+ * webkit_download_get_elapsed_time:
+ * @download: a #WebKitDownload
+ *
+ * Gets the elapsed time in seconds, including any fractional part.
+ * If the download finished, had an error or was cancelled this is
+ * the time between its start and the event.
+ *
+ * Returns: seconds since the download was started
+ */
+gdouble webkit_download_get_elapsed_time(WebKitDownload* download)
+{
+ g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), 0);
+
+ WebKitDownloadPrivate* priv = download->priv;
+ if (!priv->timer)
+ return 0;
+
+ return g_timer_elapsed(priv->timer.get(), 0);
+}
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h (0 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitDownload_h
+#define WebKitDownload_h
+
+#include <glib-object.h>
+#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitURIResponse.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_DOWNLOAD (webkit_download_get_type())
+#define WEBKIT_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownload))
+#define WEBKIT_IS_DOWNLOAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DOWNLOAD))
+#define WEBKIT_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass))
+#define WEBKIT_IS_DOWNLOAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_DOWNLOAD))
+#define WEBKIT_DOWNLOAD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_DOWNLOAD, WebKitDownloadClass))
+
+typedef struct _WebKitDownload WebKitDownload;
+typedef struct _WebKitDownloadClass WebKitDownloadClass;
+typedef struct _WebKitDownloadPrivate WebKitDownloadPrivate;
+
+struct _WebKitDownload {
+ GObject parent;
+
+ WebKitDownloadPrivate *priv;
+};
+
+struct _WebKitDownloadClass {
+ GObjectClass parent_class;
+
+ gboolean (* received_data) (WebKitDownload *download,
+ guint64 data_length);
+ gboolean (* finished) (WebKitDownload *download);
+ gboolean (* failed) (WebKitDownload *download,
+ GError *error);
+ gboolean (* decide_destination) (WebKitDownload *download,
+ const gchar *suggested_filename);
+ gboolean (* created_destination) (WebKitDownload *download,
+ const gchar *destination);
+};
+
+WEBKIT_API GType
+webkit_download_get_type (void);
+
+WEBKIT_API const gchar *
+webkit_download_get_destination (WebKitDownload *download);
+
+WEBKIT_API void
+webkit_download_set_destination (WebKitDownload *download,
+ const gchar *uri);
+
+WEBKIT_API WebKitURIResponse*
+webkit_download_get_response (WebKitDownload *download);
+
+WEBKIT_API void
+webkit_download_cancel (WebKitDownload *download);
+
+WEBKIT_API gdouble
+webkit_download_get_estimated_progress (WebKitDownload *download);
+
+WEBKIT_API gdouble
+webkit_download_get_elapsed_time (WebKitDownload *download);
+
+G_END_DECLS
+
+#endif
Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h (0 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownloadPrivate.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef WebKitDownloadPrivate_h
+#define WebKitDownloadPrivate_h
+
+#include "WebKitDownload.h"
+#include "WebKitPrivate.h"
+#include <WebCore/ResourceError.h>
+#include <wtf/text/CString.h>
+
+WebKitDownload* webkitDownloadCreate(WKDownloadRef);
+bool webkitDownloadIsCancelled(WebKitDownload*);
+void webkitDownloadSetResponse(WebKitDownload*, WebKitURIResponse*);
+void webkitDownloadNotifyProgress(WebKitDownload*, guint64 bytesReceived);
+void webkitDownloadFailed(WebKitDownload*, const WebCore::ResourceError&);
+void webkitDownloadCancelled(WebKitDownload*);
+void webkitDownloadFinished(WebKitDownload*);
+CString webkitDownloadDecideDestinationWithSuggestedFilename(WebKitDownload*, const CString& suggestedFilename);
+void webkitDownloadDestinationCreated(WebKitDownload*, const CString& destinationURI);
+
+#endif // WebKitDownloadPrivate_h
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrivate.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -27,6 +27,7 @@
#define WebKitPrivate_h
#include <WebKit2/WKAPICast.h>
+#include <WebKit2/WKDownload.h>
#include <WebKit2/WKRetainPtr.h>
#include <WebKit2/WebKit2.h>
#include <glib.h>
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp 2012-01-24 08:49:47 UTC (rev 105704)
@@ -176,3 +176,8 @@
uriResponse->priv->resourceResponse = resourceResponse;
return uriResponse;
}
+
+const WebCore::ResourceResponse& webkitURIResponseGetResourceResponse(WebKitURIResponse* uriResponse)
+{
+ return uriResponse->priv->resourceResponse;
+}
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml 2012-01-24 08:49:47 UTC (rev 105704)
@@ -20,6 +20,7 @@
<xi:include href=""
<xi:include href=""
<xi:include href=""
+ <xi:include href=""
<xi:include href=""
</chapter>
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt 2012-01-24 08:49:47 UTC (rev 105704)
@@ -287,6 +287,30 @@
</SECTION>
<SECTION>
+<FILE>WebKitDownload</FILE>
+WebKitDownload
+webkit_download_get_destination
+webkit_download_set_destination
+webkit_download_get_response
+webkit_download_cancel
+webkit_download_get_estimated_progress
+webkit_download_get_elapsed_time
+
+<SUBSECTION Standard>
+WebKitDownloadClass
+WEBKIT_TYPE_DOWNLOAD
+WEBKIT_DOWNLOAD
+WEBKIT_IS_DOWNLOAD
+WEBKIT_DOWNLOAD_CLASS
+WEBKIT_IS_DOWNLOAD_CLASS
+WEBKIT_DOWNLOAD_GET_CLASS
+
+<SUBSECTION Private>
+WebKitDownloadPrivate
+webkit_download_get_type
+</SECTION>
+
+<SECTION>
<FILE>WebKitError</FILE>
WEBKIT_NETWORK_ERROR
WEBKIT_PLUGIN_ERROR
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types 2012-01-24 08:49:47 UTC (rev 105704)
@@ -8,3 +8,5 @@
webkit_uri_response_get_type
webkit_uri_request_get_type
webkit_window_properties_get_type
+webkit_download_get_type
+
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h 2012-01-24 08:49:47 UTC (rev 105704)
@@ -26,6 +26,7 @@
#include <webkit2/WebKitBackForwardList.h>
#include <webkit2/WebKitBackForwardListItem.h>
#include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitDownload.h>
#include <webkit2/WebKitEnumTypes.h>
#include <webkit2/WebKitError.h>
#include <webkit2/WebKitSettings.h>
Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list (105703 => 105704)
--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list 2012-01-24 08:35:21 UTC (rev 105703)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list 2012-01-24 08:49:47 UTC (rev 105704)
@@ -1,7 +1,12 @@
BOOLEAN:ENUM,STRING,POINTER
+BOOLEAN:OBJECT
+BOOLEAN:OBJECT,STRING,POINTER
+BOOLEAN:POINTER
BOOLEAN:STRING
BOOLEAN:STRING,POINTER
BOOLEAN:STRING,STRING,POINTER
+BOOLEAN:UINT64
+BOOLEAN:VOID
OBJECT:VOID
VOID:ENUM
VOID:OBJECT,POINTER
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes
