diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-03 09:55:33 +0100 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2012-02-03 09:55:33 +0100 |
commit | cd44dc59cdfc39534aef4d417e9f3c412e3be139 (patch) | |
tree | 8d89889ba95ed6ec9322e733846cc9cce9d7dff1 /Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp | |
parent | d11f84f5b5cdc0d92a08af01b13472fdd5f9acb9 (diff) | |
download | qtwebkit-cd44dc59cdfc39534aef4d417e9f3c412e3be139.tar.gz |
Imported WebKit commit fce473cb4d55aa9fe9d0b0322a2fffecb731b961 (http://svn.webkit.org/repository/webkit/trunk@106560)
Diffstat (limited to 'Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp')
-rw-r--r-- | Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp | 92 |
1 files changed, 88 insertions, 4 deletions
diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp index 1f9590c52..360b0a627 100644 --- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp +++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp @@ -20,15 +20,29 @@ #include "config.h" #include "WebKitWebContext.h" +#include "WebContext.h" +#include "WebKitDownloadClient.h" +#include "WebKitDownloadPrivate.h" +#include "WebKitPrivate.h" #include "WebKitWebContextPrivate.h" -#include <WebKit2/WKContext.h> -#include <WebKit2/WKRetainPtr.h> -#include <WebKit2/WKType.h> +#include <wtf/HashMap.h> +#include <wtf/gobject/GRefPtr.h> +#include <wtf/text/CString.h> + +using namespace WebKit; + +enum { + DOWNLOAD_STARTED, + + LAST_SIGNAL +}; struct _WebKitWebContextPrivate { WKRetainPtr<WKContextRef> context; }; +static guint signals[LAST_SIGNAL] = { 0, }; + G_DEFINE_TYPE(WebKitWebContext, webkit_web_context, G_TYPE_OBJECT) static void webkitWebContextFinalize(GObject* object) @@ -49,15 +63,32 @@ static void webkit_web_context_class_init(WebKitWebContextClass* webContextClass GObjectClass* gObjectClass = G_OBJECT_CLASS(webContextClass); gObjectClass->finalize = webkitWebContextFinalize; + /** + * WebKitWebContext::download-started: + * @context: the #WebKitWebContext + * @download: the #WebKitDownload associated with this event + * + * This signal is emitted when a new download request is made. + */ + signals[DOWNLOAD_STARTED] = + g_signal_new("download-started", + G_TYPE_FROM_CLASS(gObjectClass), + G_SIGNAL_RUN_LAST, + 0, 0, 0, + g_cclosure_marshal_VOID__OBJECT, + G_TYPE_NONE, 1, + WEBKIT_TYPE_DOWNLOAD); + g_type_class_add_private(webContextClass, sizeof(WebKitWebContextPrivate)); } - static gpointer createDefaultWebContext(gpointer) { WebKitWebContext* webContext = WEBKIT_WEB_CONTEXT(g_object_new(WEBKIT_TYPE_WEB_CONTEXT, NULL)); webContext->priv->context = WKContextGetSharedProcessContext(); WKContextSetCacheModel(webContext->priv->context.get(), kWKCacheModelPrimaryWebBrowser); + attachDownloadClientToContext(webContext); + return webContext; } @@ -152,6 +183,59 @@ WebKitCacheModel webkit_web_context_get_cache_model(WebKitWebContext* context) return WEBKIT_CACHE_MODEL_WEB_BROWSER; } +typedef HashMap<WKDownloadRef, GRefPtr<WebKitDownload> > DownloadsMap; + +static DownloadsMap& downloadsMap() +{ + DEFINE_STATIC_LOCAL(DownloadsMap, downloads, ()); + return downloads; +} + +/** + * webkit_web_context_download_uri: + * @context: a #WebKitWebContext + * @uri: the URI to download + * + * Requests downloading of the specified URI string. + * + * Returns: (transfer full): a new #WebKitDownload representing the + * the download operation. + */ +WebKitDownload* webkit_web_context_download_uri(WebKitWebContext* context, const gchar* uri) +{ + g_return_val_if_fail(WEBKIT_IS_WEB_CONTEXT(context), 0); + g_return_val_if_fail(uri, 0); + + WebKitWebContextPrivate* priv = context->priv; + WKRetainPtr<WKURLRef> wkURL(AdoptWK, WKURLCreateWithUTF8CString(uri)); + WKRetainPtr<WKURLRequestRef> wkRequest(AdoptWK, WKURLRequestCreateWithWKURL(wkURL.get())); + WKRetainPtr<WKDownloadRef> wkDownload = WKContextDownloadURLRequest(priv->context.get(), wkRequest.get()); + WebKitDownload* download = webkitDownloadCreate(wkDownload.get()); + downloadsMap().set(wkDownload.get(), download); + return download; +} + +WebKitDownload* webkitWebContextGetOrCreateDownload(WKDownloadRef wkDownload) +{ + GRefPtr<WebKitDownload> download = downloadsMap().get(wkDownload); + if (download) + return download.get(); + + download = adoptGRef(webkitDownloadCreate(wkDownload)); + downloadsMap().set(wkDownload, download.get()); + return download.get(); +} + +void webkitWebContextRemoveDownload(WKDownloadRef wkDownload) +{ + downloadsMap().remove(wkDownload); +} + +void webkitWebContextDownloadStarted(WebKitWebContext* context, WebKitDownload* download) +{ + g_signal_emit(context, signals[DOWNLOAD_STARTED], 0, download); +} + WKContextRef webkitWebContextGetWKContext(WebKitWebContext* context) { g_assert(WEBKIT_IS_WEB_CONTEXT(context)); |