Title: [141096] trunk
Revision
141096
Author
carlo...@webkit.org
Date
2013-01-29 04:01:39 -0800 (Tue, 29 Jan 2013)

Log Message

[GTK] Implement resources API using injected bundle
https://bugs.webkit.org/show_bug.cgi?id=107457

Reviewed by Sam Weinig.

Source/WebKit2:

The ResourceLoaderClient was removed from the UI process in
r140285, and most of the GTK+ API depends on resources. This patch
implements the same API using the ResourceLoaderClient from
injected bundle. It fixes the resources unit tests, as well as
other 14 unit tests that are timing out because they depend on
resource API.

* GNUmakefile.list.am: Add new files to compilation.
* Shared/UserMessageCoders.h:
(WebKit::UserMessageEncoder::baseEncode): Add support for encoding
WebURLResponse and WebError objects in user messages.
(WebKit::UserMessageDecoder::baseDecode): Add support for decoding
WebURLResponse and WebError objects from user messages.
* UIProcess/API/gtk/WebKitInjectedBundleClient.cpp: Added.
(didReceiveWebViewMessageFromInjectedBundle): Handle messages sent
to the WebView. For now it hanldes all the sresource loader client
messages.
(didReceiveMessageFromInjectedBundle): Handle messages received
from injected bundle.
(attachInjectedBundleClientToContext): Initialize the injected
bundle client.
* UIProcess/API/gtk/WebKitInjectedBundleClient.h: Added.
* UIProcess/API/gtk/WebKitWebContext.cpp:
(_WebKitWebContextPrivate): Add a HashMap to map page IDs to
WebKitWebViews.
(createDefaultWebContext): Call
attachInjectedBundleClientToContext() to intialize the injected
bundle client.
(webkitWebContextCreatePageForWebView): Use
webkitWebViewBaseCreateWebPage() to create and initialize a new
WebPageProxy and map the newly created page with the given
WebKitWebView.
(webkitWebContextWebViewDestroyed): Called when the given
WebKitWebView is being destroyed to remove it from the views map.
(webkitWebContextGetWebViewForPage): Returns the WebKitWebView
associated to the given page ID.
* UIProcess/API/gtk/WebKitWebContextPrivate.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewConstructed): Use
webkitWebContextCreatePageForWebView() instead of
webkitWebViewBaseCreateWebPage() directly.
(webkitWebViewDispose): Call webkitWebContextWebViewDestroyed() to
notify the context.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(didInitiateLoadForResource): Send a message to the UI process
with the callback parameters encoded.
(willSendRequestForFrame): Ditto.
(didReceiveResponseForResource): Ditto.
(didReceiveContentLengthForResource): Ditto.
(didFinishLoadForResource): Ditto.
(didFailLoadForResource): Ditto.
(webkitWebPageCreate): Initialize the
WKBundlePageResourceLoadClient.

Tools:

* Scripts/run-gtk-tests:
(TestRunner): Unksip resources unit tests.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (141095 => 141096)


--- trunk/Source/WebKit2/ChangeLog	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/ChangeLog	2013-01-29 12:01:39 UTC (rev 141096)
@@ -1,3 +1,64 @@
+2013-01-29  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Implement resources API using injected bundle
+        https://bugs.webkit.org/show_bug.cgi?id=107457
+
+        Reviewed by Sam Weinig.
+
+        The ResourceLoaderClient was removed from the UI process in
+        r140285, and most of the GTK+ API depends on resources. This patch
+        implements the same API using the ResourceLoaderClient from
+        injected bundle. It fixes the resources unit tests, as well as
+        other 14 unit tests that are timing out because they depend on
+        resource API.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * Shared/UserMessageCoders.h:
+        (WebKit::UserMessageEncoder::baseEncode): Add support for encoding
+        WebURLResponse and WebError objects in user messages.
+        (WebKit::UserMessageDecoder::baseDecode): Add support for decoding
+        WebURLResponse and WebError objects from user messages.
+        * UIProcess/API/gtk/WebKitInjectedBundleClient.cpp: Added.
+        (didReceiveWebViewMessageFromInjectedBundle): Handle messages sent
+        to the WebView. For now it hanldes all the sresource loader client
+        messages.
+        (didReceiveMessageFromInjectedBundle): Handle messages received
+        from injected bundle.
+        (attachInjectedBundleClientToContext): Initialize the injected
+        bundle client.
+        * UIProcess/API/gtk/WebKitInjectedBundleClient.h: Added.
+        * UIProcess/API/gtk/WebKitWebContext.cpp:
+        (_WebKitWebContextPrivate): Add a HashMap to map page IDs to
+        WebKitWebViews.
+        (createDefaultWebContext): Call
+        attachInjectedBundleClientToContext() to intialize the injected
+        bundle client.
+        (webkitWebContextCreatePageForWebView): Use
+        webkitWebViewBaseCreateWebPage() to create and initialize a new
+        WebPageProxy and map the newly created page with the given
+        WebKitWebView.
+        (webkitWebContextWebViewDestroyed): Called when the given
+        WebKitWebView is being destroyed to remove it from the views map.
+        (webkitWebContextGetWebViewForPage): Returns the WebKitWebView
+        associated to the given page ID.
+        * UIProcess/API/gtk/WebKitWebContextPrivate.h:
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewConstructed): Use
+        webkitWebContextCreatePageForWebView() instead of
+        webkitWebViewBaseCreateWebPage() directly.
+        (webkitWebViewDispose): Call webkitWebContextWebViewDestroyed() to
+        notify the context.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (didInitiateLoadForResource): Send a message to the UI process
+        with the callback parameters encoded.
+        (willSendRequestForFrame): Ditto.
+        (didReceiveResponseForResource): Ditto.
+        (didReceiveContentLengthForResource): Ditto.
+        (didFinishLoadForResource): Ditto.
+        (didFailLoadForResource): Ditto.
+        (webkitWebPageCreate): Initialize the
+        WKBundlePageResourceLoadClient.
+
 2013-01-29  Laszlo Gombos  <l.gom...@samsung.com>
 
         [Qt] Remove misspelled ENABLE(SPEECH_INPUT) guard

Modified: trunk/Source/WebKit2/GNUmakefile.list.am (141095 => 141096)


--- trunk/Source/WebKit2/GNUmakefile.list.am	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/GNUmakefile.list.am	2013-01-29 12:01:39 UTC (rev 141096)
@@ -704,6 +704,8 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResult.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitHitTestResultPrivate.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp \
+	Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResult.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitJavascriptResultPrivate.h \

Modified: trunk/Source/WebKit2/Shared/UserMessageCoders.h (141095 => 141096)


--- trunk/Source/WebKit2/Shared/UserMessageCoders.h	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/Shared/UserMessageCoders.h	2013-01-29 12:01:39 UTC (rev 141096)
@@ -35,6 +35,7 @@
 #include "WebCertificateInfo.h"
 #include "WebCoreArgumentCoders.h"
 #include "WebData.h"
+#include "WebError.h"
 #include "WebGeometry.h"
 #include "WebImage.h"
 #include "WebNumber.h"
@@ -44,6 +45,7 @@
 #include "WebString.h"
 #include "WebURL.h"
 #include "WebURLRequest.h"
+#include "WebURLResponse.h"
 #include "WebUserContentURLPattern.h"
 
 namespace WebKit {
@@ -63,6 +65,8 @@
 //   - WebUInt64 -> WebUInt64
 //   - WebURL -> WebURL
 //   - WebURLRequest -> WebURLRequest
+//   - WebURLResponse -> WebURLResponse
+//   - WebError -> WebError
 
 template<typename Owner>
 class UserMessageEncoder {
@@ -177,6 +181,11 @@
             encoder << urlRequestObject->resourceRequest();
             return true;
         }
+        case APIObject::TypeURLResponse: {
+            WebURLResponse* urlResponseObject = static_cast<WebURLResponse*>(m_root);
+            encoder << urlResponseObject->resourceResponse();
+            return true;
+        }
         case APIObject::TypeUserContentURLPattern: {
             WebUserContentURLPattern* urlPattern = static_cast<WebUserContentURLPattern*>(m_root);
             encoder << urlPattern->patternString();
@@ -209,6 +218,11 @@
             encoder << certificateInfo->platformCertificateInfo();
             return true;
         }
+        case APIObject::TypeError: {
+            WebError* errorObject = static_cast<WebError*>(m_root);
+            encoder << errorObject->platformError();
+            return true;
+        }
         default:
             break;
         }
@@ -240,6 +254,8 @@
 //   - WebUInt64 -> WebUInt64
 //   - WebURL -> WebURL
 //   - WebURLRequest -> WebURLRequest
+//   - WebURLResponse -> WebURLResponse
+//   - WebError -> WebError
 
 template<typename Owner>
 class UserMessageDecoder {
@@ -451,6 +467,13 @@
             coder.m_root = WebURLRequest::create(request);
             break;
         }
+        case APIObject::TypeURLResponse: {
+            WebCore::ResourceResponse response;
+            if (!decoder->decode(response))
+                return false;
+            coder.m_root = WebURLResponse::create(response);
+            break;
+        }
         case APIObject::TypeUserContentURLPattern: {
             String string;
             if (!decoder->decode(string))
@@ -487,6 +510,13 @@
             coder.m_root = WebCertificateInfo::create(platformCertificateInfo);
             break;
         }
+        case APIObject::TypeError: {
+            WebCore::ResourceError resourceError;
+            if (!decoder->decode(resourceError))
+                return false;
+            coder.m_root = WebError::create(resourceError);
+            break;
+        }
         default:
             break;
         }

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp (0 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.cpp	2013-01-29 12:01:39 UTC (rev 141096)
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2013 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 "WebKitInjectedBundleClient.h"
+
+#include "WebKitURIRequestPrivate.h"
+#include "WebKitURIResponsePrivate.h"
+#include "WebKitWebContextPrivate.h"
+#include "WebKitWebResourcePrivate.h"
+#include "WebKitWebViewPrivate.h"
+#include <wtf/gobject/GOwnPtr.h>
+
+using namespace WebKit;
+using namespace WebCore;
+
+static void didReceiveWebViewMessageFromInjectedBundle(WebKitWebView* webView, const char* messageName, ImmutableDictionary& message)
+{
+    if (g_str_equal(messageName, "DidInitiateLoadForResource")) {
+        WebFrameProxy* frame = static_cast<WebFrameProxy*>(message.get(String::fromUTF8("Frame")));
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        WebURLRequest* webRequest = static_cast<WebURLRequest*>(message.get(String::fromUTF8("Request")));
+        GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(webRequest->resourceRequest()));
+
+        webkitWebViewResourceLoadStarted(webView, frame, resourceIdentifier->value(), request.get());
+    } else if (g_str_equal(messageName, "DidSendRequestForResource")) {
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        GRefPtr<WebKitWebResource> resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier->value());
+        if (!resource)
+            return;
+
+        WebURLRequest* webRequest = static_cast<WebURLRequest*>(message.get(String::fromUTF8("Request")));
+        GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(webRequest->resourceRequest()));
+        WebURLResponse* webRedirectResponse = static_cast<WebURLResponse*>(message.get(String::fromUTF8("RedirectResponse")));
+        GRefPtr<WebKitURIResponse> redirectResponse = webRedirectResponse ? adoptGRef(webkitURIResponseCreateForResourceResponse(webRedirectResponse->resourceResponse())) : 0;
+
+        webkitWebResourceSentRequest(resource.get(), request.get(), redirectResponse.get());
+    } else if (g_str_equal(messageName, "DidReceiveResponseForResource")) {
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        GRefPtr<WebKitWebResource> resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier->value());
+        if (!resource)
+            return;
+
+        WebURLResponse* webResponse = static_cast<WebURLResponse*>(message.get(String::fromUTF8("Response")));
+        GRefPtr<WebKitURIResponse> response = adoptGRef(webkitURIResponseCreateForResourceResponse(webResponse->resourceResponse()));
+
+        webkitWebResourceSetResponse(resource.get(), response.get());
+    } else if (g_str_equal(messageName, "DidReceiveContentLengthForResource")) {
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        GRefPtr<WebKitWebResource> resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier->value());
+        if (!resource)
+            return;
+
+        WebUInt64* contentLength = static_cast<WebUInt64*>(message.get(String::fromUTF8("ContentLength")));
+        webkitWebResourceNotifyProgress(resource.get(), contentLength->value());
+    } else if (g_str_equal(messageName, "DidFinishLoadForResource")) {
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        GRefPtr<WebKitWebResource> resource = webkitWebViewResourceLoadFinished(webView, resourceIdentifier->value());
+        if (!resource)
+            return;
+
+        webkitWebResourceFinished(resource.get());
+    } else if (g_str_equal(messageName, "DidFailLoadForResource")) {
+        WebUInt64* resourceIdentifier = static_cast<WebUInt64*>(message.get(String::fromUTF8("Identifier")));
+        GRefPtr<WebKitWebResource> resource = webkitWebViewGetLoadingWebResource(webView, resourceIdentifier->value());
+        if (!resource)
+            return;
+
+        WebError* webError = static_cast<WebError*>(message.get(String::fromUTF8("Error")));
+        const ResourceError& platformError = webError->platformError();
+        GOwnPtr<GError> resourceError(g_error_new_literal(g_quark_from_string(platformError.domain().utf8().data()),
+            platformError.errorCode(), platformError.localizedDescription().utf8().data()));
+
+        webkitWebResourceFailed(resource.get(), resourceError.get());
+        webkitWebViewRemoveLoadingWebResource(webView, resourceIdentifier->value());
+    } else
+        ASSERT_NOT_REACHED();
+}
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
+{
+    ASSERT(WKGetTypeID(messageBody) == WKDictionaryGetTypeID());
+    ImmutableDictionary& message = *toImpl(static_cast<WKDictionaryRef>(messageBody));
+
+    CString messageNameCString = toImpl(messageName)->string().utf8();
+    const char* messageNameUTF8 = messageNameCString.data();
+
+    if (g_str_has_prefix(messageNameUTF8, "WebPage.")) {
+        WebPageProxy* page = static_cast<WebPageProxy*>(message.get(String::fromUTF8("Page")));
+        WebKitWebView* webView = webkitWebContextGetWebViewForPage(WEBKIT_WEB_CONTEXT(clientInfo), page);
+        if (!webView)
+            return;
+
+        didReceiveWebViewMessageFromInjectedBundle(webView, messageNameUTF8 + strlen("WebPage."), message);
+    } else
+        ASSERT_NOT_REACHED();
+}
+
+void attachInjectedBundleClientToContext(WebKitWebContext* webContext)
+{
+    WKContextInjectedBundleClient wkInjectedBundleClient = {
+        kWKContextInjectedBundleClientCurrentVersion,
+        webContext, // clientInfo
+        didReceiveMessageFromInjectedBundle,
+        0, // didReceiveSynchronousMessageFromInjectedBundle
+        0 // getInjectedBundleInitializationUserData
+    };
+    WKContextSetInjectedBundleClient(toAPI(webkitWebContextGetContext(webContext)), &wkInjectedBundleClient);
+}

Added: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.h (0 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitInjectedBundleClient.h	2013-01-29 12:01:39 UTC (rev 141096)
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2013 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 WebKitInjectedBundleClient_h
+#define WebKitInjectedBundleClient_h
+
+#include "WebKitWebContext.h"
+
+void attachInjectedBundleClientToContext(WebKitWebContext*);
+
+#endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h (141095 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponsePrivate.h	2013-01-29 12:01:39 UTC (rev 141096)
@@ -26,6 +26,7 @@
 #ifndef WebKitURIResponsePrivate_h
 #define WebKitURIResponsePrivate_h
 
+#include "WebCertificateInfo.h"
 #include "WebKitURIResponse.h"
 #include <WebCore/ResourceResponse.h>
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp (141095 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContext.cpp	2013-01-29 12:01:39 UTC (rev 141096)
@@ -27,6 +27,7 @@
 #include "WebKitDownloadPrivate.h"
 #include "WebKitFaviconDatabasePrivate.h"
 #include "WebKitGeolocationProvider.h"
+#include "WebKitInjectedBundleClient.h"
 #include "WebKitPluginPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitRequestManagerClient.h"
@@ -34,6 +35,7 @@
 #include "WebKitTextChecker.h"
 #include "WebKitURISchemeRequestPrivate.h"
 #include "WebKitWebContextPrivate.h"
+#include "WebKitWebViewBasePrivate.h"
 #include "WebResourceCacheManagerProxy.h"
 #include <WebCore/FileSystem.h>
 #include <WebCore/IconDatabase.h>
@@ -139,6 +141,8 @@
 #endif
     CString faviconDatabaseDirectory;
     WebKitTLSErrorsPolicy tlsErrorsPolicy;
+
+    HashMap<uint64_t, WebKitWebView*> webViews;
 };
 
 static guint signals[LAST_SIGNAL] = { 0, };
@@ -191,6 +195,7 @@
     priv->context->setCacheModel(CacheModelPrimaryWebBrowser);
     priv->tlsErrorsPolicy = WEBKIT_TLS_ERRORS_POLICY_IGNORE;
 
+    attachInjectedBundleClientToContext(webContext.get());
     attachDownloadClientToContext(webContext.get());
     attachRequestManagerClientToContext(webContext.get());
 
@@ -831,3 +836,22 @@
 {
     context->priv->uriSchemeRequests.remove(requestID);
 }
+
+void webkitWebContextCreatePageForWebView(WebKitWebContext* context, WebKitWebView* webView)
+{
+    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView);
+    webkitWebViewBaseCreateWebPage(webViewBase, context->priv->context.get(), 0);
+    WebPageProxy* page = webkitWebViewBaseGetPage(webViewBase);
+    context->priv->webViews.set(page->pageID(), webView);
+}
+
+void webkitWebContextWebViewDestroyed(WebKitWebContext* context, WebKitWebView* webView)
+{
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    context->priv->webViews.remove(page->pageID());
+}
+
+WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext* context, WebPageProxy* page)
+{
+    return page ? context->priv->webViews.get(page->pageID()) : 0;
+}

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h (141095 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebContextPrivate.h	2013-01-29 12:01:39 UTC (rev 141096)
@@ -42,5 +42,8 @@
 void webkitWebContextReceivedURIRequest(WebKitWebContext*, WebKitURISchemeRequest*);
 void webkitWebContextDidFailToLoadURIRequest(WebKitWebContext*, uint64_t requestID);
 void webkitWebContextDidFinishURIRequest(WebKitWebContext*, uint64_t requestID);
+void webkitWebContextCreatePageForWebView(WebKitWebContext*, WebKitWebView*);
+void webkitWebContextWebViewDestroyed(WebKitWebContext*, WebKitWebView*);
+WebKitWebView* webkitWebContextGetWebViewForPage(WebKitWebContext*, WebKit::WebPageProxy*);
 
 #endif // WebKitWebContextPrivate_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp (141095 => 141096)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2013-01-29 12:01:39 UTC (rev 141096)
@@ -455,10 +455,9 @@
 
     WebKitWebView* webView = WEBKIT_WEB_VIEW(object);
     WebKitWebViewPrivate* priv = webView->priv;
-    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView);
+    webkitWebContextCreatePageForWebView(priv->context, webView);
 
-    webkitWebViewBaseCreateWebPage(webViewBase, webkitWebContextGetContext(priv->context), 0);
-    webkitWebViewBaseSetDownloadRequestHandler(webViewBase, webkitWebViewHandleDownloadRequest);
+    webkitWebViewBaseSetDownloadRequestHandler(WEBKIT_WEB_VIEW_BASE(webView), webkitWebViewHandleDownloadRequest);
 
     attachLoaderClientToView(webView);
     attachUIClientToView(webView);
@@ -537,6 +536,8 @@
     webkitWebViewDisconnectSettingsSignalHandlers(webView);
     webkitWebViewDisconnectFaviconDatabaseSignalHandlers(webView);
 
+    webkitWebContextWebViewDestroyed(webView->priv->context, webView);
+
     G_OBJECT_CLASS(webkit_web_view_parent_class)->dispose(object);
 }
 

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp (141095 => 141096)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-01-29 12:01:39 UTC (rev 141096)
@@ -20,9 +20,14 @@
 #include "config.h"
 #include "WebKitWebPage.h"
 
+#include "ImmutableDictionary.h"
+#include "InjectedBundle.h"
+#include "WKBundleAPICast.h"
+#include "WebFrame.h"
 #include "WebKitDOMDocumentPrivate.h"
 #include "WebKitPrivate.h"
 #include "WebKitWebPagePrivate.h"
+#include "WebProcess.h"
 #include <WebCore/Frame.h>
 
 using namespace WebKit;
@@ -34,6 +39,65 @@
 
 WEBKIT_DEFINE_TYPE(WebKitWebPage, webkit_web_page, G_TYPE_OBJECT)
 
+static void didInitiateLoadForResource(WKBundlePageRef page, WKBundleFrameRef frame, uint64_t identifier, WKURLRequestRef request, bool pageLoadIsProvisional, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Frame"), toImpl(frame));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    message.set(String::fromUTF8("Request"), toImpl(request));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidInitiateLoadForResource"), ImmutableDictionary::adopt(message).get());
+}
+
+static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef request, WKURLResponseRef redirectResponse, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    message.set(String::fromUTF8("Request"), toImpl(request));
+    if (!toImpl(redirectResponse)->resourceResponse().isNull())
+        message.set(String::fromUTF8("RedirectResponse"), toImpl(redirectResponse));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), ImmutableDictionary::adopt(message).get());
+
+    WKRetain(request);
+    return request;
+}
+
+static void didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    message.set(String::fromUTF8("Response"), toImpl(response));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveResponseForResource"), ImmutableDictionary::adopt(message).get());
+}
+
+static void didReceiveContentLengthForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, uint64_t length, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    message.set(String::fromUTF8("ContentLength"), WebUInt64::create(length));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidReceiveContentLengthForResource"), ImmutableDictionary::adopt(message).get());
+}
+
+static void didFinishLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFinishLoadForResource"), ImmutableDictionary::adopt(message).get());
+}
+
+static void didFailLoadForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKErrorRef error, const void*)
+{
+    ImmutableDictionary::MapType message;
+    message.set(String::fromUTF8("Page"), toImpl(page));
+    message.set(String::fromUTF8("Identifier"), WebUInt64::create(identifier));
+    message.set(String::fromUTF8("Error"), toImpl(error));
+    WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidFailLoadForResource"), ImmutableDictionary::adopt(message).get());
+}
+
 static void webkit_web_page_class_init(WebKitWebPageClass* klass)
 {
 }
@@ -42,6 +106,21 @@
 {
     WebKitWebPage* page = WEBKIT_WEB_PAGE(g_object_new(WEBKIT_TYPE_WEB_PAGE, NULL));
     page->priv->webPage = webPage;
+
+    WKBundlePageResourceLoadClient resourceLoadClient = {
+        kWKBundlePageResourceLoadClientCurrentVersion,
+        page,
+        didInitiateLoadForResource,
+        willSendRequestForFrame,
+        didReceiveResponseForResource,
+        didReceiveContentLengthForResource,
+        didFinishLoadForResource,
+        didFailLoadForResource,
+        0, // shouldCacheResponse
+        0 // shouldUseCredentialStorage
+    };
+    WKBundlePageSetResourceLoadClient(toAPI(webPage), &resourceLoadClient);
+
     return page;
 }
 

Modified: trunk/Tools/ChangeLog (141095 => 141096)


--- trunk/Tools/ChangeLog	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Tools/ChangeLog	2013-01-29 12:01:39 UTC (rev 141096)
@@ -1,3 +1,13 @@
+2013-01-29  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Implement resources API using injected bundle
+        https://bugs.webkit.org/show_bug.cgi?id=107457
+
+        Reviewed by Sam Weinig.
+
+        * Scripts/run-gtk-tests:
+        (TestRunner): Unksip resources unit tests.
+
 2013-01-29  Michael BrĂ¼ning  <michael.brun...@digia.com>
 
         Unreviewed, updated my email information.

Modified: trunk/Tools/Scripts/run-gtk-tests (141095 => 141096)


--- trunk/Tools/Scripts/run-gtk-tests	2013-01-29 11:58:30 UTC (rev 141095)
+++ trunk/Tools/Scripts/run-gtk-tests	2013-01-29 12:01:39 UTC (rev 141096)
@@ -68,7 +68,7 @@
         SkippedTest("unittests/testwebview", "/webkit/webview/icon-uri", "Test times out in GTK Linux 64-bit Release bot", 82328),
         SkippedTest("unittests/testatk", "/webkit/atk/getTextInParagraphAndBodyModerate", "Test fails", 105538),
         SkippedTest("WebKit2APITests/TestInspectorServer", SkippedTest.ENTIRE_SUITE, "Test times out", 105866),
-        SkippedTest("WebKit2APITests/TestResources", SkippedTest.ENTIRE_SUITE, "Need to be reimplemented using injected bundle", 107421),
+        SkippedTest("WebKit2APITests/TestResources", "/webkit2/WebKitWebView/resources", "Test is flaky in GTK Linux 32-bit Release bot", 82868),
         SkippedTest("WebKit2APITests/TestWebKitAccessibility", "/webkit2/WebKitAccessibility/atspi-basic-hierarchy", "Test fails", 100408),
         SkippedTest("WebKit2APITests/TestWebKitFindController", "/webkit2/WebKitFindController/hide", "Test always fails in Xvfb", 89810),
         SkippedTest("WebKit2APITests/TestWebKitWebContext", "/webkit2/WebKitWebContext/uri-scheme", "Test fails", 104779),
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to