Title: [148679] trunk/Source/WebKit2
Revision
148679
Author
carlo...@webkit.org
Date
2013-04-18 09:12:12 -0700 (Thu, 18 Apr 2013)

Log Message

[GTK] Add WebKitWebPage::send-request signal to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=83681

Reviewed by Anders Carlsson.

Add WebKitWebPage::send-request signal emitted in willSendRequest
callback to allow web process extensions to modify requests before
they are sent or cancel the resource load.
This patch makes WebKitURIRequest and WebKitURIResponse objects
shareable between UI process and web extensions APIs. Since both
APIs force single header includes, the WebKitDefines.h header has
been split moving the forward declarations specific to the UI
process API to a new file WebKitForwardDeclarations.h. This way we
can also  share the WebKitDefines.h header and remove the
WebKitWebExtensionDefines.h header used in the web extensions API.

* GNUmakefile.list.am: Add new files to compilation.
* UIProcess/API/gtk/WebKitContextMenu.h: Include WebKitForward.h.
* UIProcess/API/gtk/WebKitContextMenuItem.h: Ditto.
* UIProcess/API/gtk/WebKitDefines.h: Remove forward declarations.
* UIProcess/API/gtk/WebKitDownload.h: Include WebKitForward.h.
* UIProcess/API/gtk/WebKitFindController.h: Ditto.
* UIProcess/API/gtk/WebKitForwardDeclarations.h: Added. Contains
the forward declarations moved from WebKitDefines.h.
* UIProcess/API/gtk/WebKitPrintOperation.h: Include WebKitForward.h.
* UIProcess/API/gtk/WebKitURIRequest.cpp:
(webkitURIRequestSetProperty): Use webkit_uri_request_set_uri() to
set the new URI.
(webkit_uri_request_class_init): Make URI property construct
instead of construct-only, since it can be updated once
constructed. It should never be NULL, so set default value to
about:blank instad of NULL.
(webkit_uri_request_set_uri): New public method to set the URI of
the WebKitURIRequest.
* UIProcess/API/gtk/WebKitURIRequest.h: Allow to include this file
from webkit-web-extension.h.
* UIProcess/API/gtk/WebKitURIResponse.h: Ditto.
* UIProcess/API/gtk/WebKitURISchemeRequest.h: Include
WebKitForward.h.
* UIProcess/API/gtk/WebKitWebView.h: Ditto.
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add
webkit_uri_request_set_uri.
* UIProcess/API/gtk/tests/TestResources.cpp:
(testWebResourceSendRequest):
(serverCallback):
(beforeAll):
* UIProcess/API/gtk/tests/WebExtensionTest.cpp:
(sendRequestCallback):
(pageCreatedCallback):
* UIProcess/API/gtk/webkit2marshal.list:
* WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h: Include
WebKitDefines.h instead of WebKitWebExtensionDefines.h.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
(willSendRequestForFrame): Emit WebKitWebPage::send-request and
return early if the load is cancelled.
(webkit_web_page_class_init): Add WebKitWebPage::send-request
signal.
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h: Include
WebKitDefines.h instead of WebKitWebExtensionDefines.h.
* WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (148678 => 148679)


--- trunk/Source/WebKit2/ChangeLog	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/ChangeLog	2013-04-18 16:12:12 UTC (rev 148679)
@@ -1,3 +1,66 @@
+2013-04-18  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        [GTK] Add WebKitWebPage::send-request signal to WebKit2 GTK+ API
+        https://bugs.webkit.org/show_bug.cgi?id=83681
+
+        Reviewed by Anders Carlsson.
+
+        Add WebKitWebPage::send-request signal emitted in willSendRequest
+        callback to allow web process extensions to modify requests before
+        they are sent or cancel the resource load.
+        This patch makes WebKitURIRequest and WebKitURIResponse objects
+        shareable between UI process and web extensions APIs. Since both
+        APIs force single header includes, the WebKitDefines.h header has
+        been split moving the forward declarations specific to the UI
+        process API to a new file WebKitForwardDeclarations.h. This way we
+        can also  share the WebKitDefines.h header and remove the
+        WebKitWebExtensionDefines.h header used in the web extensions API.
+
+        * GNUmakefile.list.am: Add new files to compilation.
+        * UIProcess/API/gtk/WebKitContextMenu.h: Include WebKitForward.h.
+        * UIProcess/API/gtk/WebKitContextMenuItem.h: Ditto.
+        * UIProcess/API/gtk/WebKitDefines.h: Remove forward declarations.
+        * UIProcess/API/gtk/WebKitDownload.h: Include WebKitForward.h.
+        * UIProcess/API/gtk/WebKitFindController.h: Ditto.
+        * UIProcess/API/gtk/WebKitForwardDeclarations.h: Added. Contains
+        the forward declarations moved from WebKitDefines.h.
+        * UIProcess/API/gtk/WebKitPrintOperation.h: Include WebKitForward.h.
+        * UIProcess/API/gtk/WebKitURIRequest.cpp:
+        (webkitURIRequestSetProperty): Use webkit_uri_request_set_uri() to
+        set the new URI.
+        (webkit_uri_request_class_init): Make URI property construct
+        instead of construct-only, since it can be updated once
+        constructed. It should never be NULL, so set default value to
+        about:blank instad of NULL.
+        (webkit_uri_request_set_uri): New public method to set the URI of
+        the WebKitURIRequest.
+        * UIProcess/API/gtk/WebKitURIRequest.h: Allow to include this file
+        from webkit-web-extension.h.
+        * UIProcess/API/gtk/WebKitURIResponse.h: Ditto.
+        * UIProcess/API/gtk/WebKitURISchemeRequest.h: Include
+        WebKitForward.h.
+        * UIProcess/API/gtk/WebKitWebView.h: Ditto.
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add
+        webkit_uri_request_set_uri.
+        * UIProcess/API/gtk/tests/TestResources.cpp:
+        (testWebResourceSendRequest):
+        (serverCallback):
+        (beforeAll):
+        * UIProcess/API/gtk/tests/WebExtensionTest.cpp:
+        (sendRequestCallback):
+        (pageCreatedCallback):
+        * UIProcess/API/gtk/webkit2marshal.list:
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h: Include
+        WebKitDefines.h instead of WebKitWebExtensionDefines.h.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+        (willSendRequestForFrame): Emit WebKitWebPage::send-request and
+        return early if the load is cancelled.
+        (webkit_web_page_class_init): Add WebKitWebPage::send-request
+        signal.
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h: Include
+        WebKitDefines.h instead of WebKitWebExtensionDefines.h.
+        * WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h:
+
 2013-04-18  Bruno de Oliveira Abinader  <bruno.abina...@basyskom.com>
 
         [WK2] CoordinatedGraphicsLayerState is a struct, not a class

Modified: trunk/Source/WebKit2/GNUmakefile.list.am (148678 => 148679)


--- trunk/Source/WebKit2/GNUmakefile.list.am	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/GNUmakefile.list.am	2013-04-18 16:12:12 UTC (rev 148679)
@@ -107,6 +107,7 @@
 	$(WebKit2)/UIProcess/API/gtk/WebKitFileChooserRequest.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitFindController.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitFormSubmissionRequest.h \
+	$(WebKit2)/UIProcess/API/gtk/WebKitForwardDeclarations.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitHitTestResult.h \
 	$(WebKit2)/UIProcess/API/gtk/WebKitJavascriptResult.h \
@@ -133,7 +134,6 @@
 
 webkit2_web_extension_h_api += \
 	$(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h \
-	$(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h \
 	$(WebKit2)/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h \
 	$(WebKit2)/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h
 
@@ -688,6 +688,7 @@
 	Source/WebKit2/UIProcess/API/gtk/WebKitFormSubmissionRequestPrivate.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFormClient.h \
+	Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.cpp \
 	Source/WebKit2/UIProcess/API/gtk/WebKitFullscreenClient.h \
 	Source/WebKit2/UIProcess/API/gtk/WebKitGeolocationPermissionRequest.cpp \
@@ -1038,7 +1039,6 @@
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.cpp \
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h \
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionPrivate.h \
-	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h \
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp \
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h \
 	Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPagePrivate.h \

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -27,6 +27,7 @@
 #include <glib-object.h>
 #include <webkit2/WebKitContextMenuItem.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -28,6 +28,7 @@
 #include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitContextMenu.h>
 #include <webkit2/WebKitContextMenuActions.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -23,7 +23,7 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__)
 #error "Only <webkit2/webkit2.h> can be included directly."
 #endif
 
@@ -32,12 +32,6 @@
 
 #include <glib.h>
 
-typedef struct _WebKitPrintOperation  WebKitPrintOperation;
-typedef struct _WebKitFindController  WebKitFindController;
-typedef struct _WebKitWebView         WebKitWebView;
-typedef struct _WebKitContextMenu     WebKitContextMenu;
-typedef struct _WebKitContextMenuItem WebKitContextMenuItem;
-
 #ifdef G_OS_WIN32
 #    ifdef BUILDING_WEBKIT
 #        define WEBKIT_API __declspec(dllexport)

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDownload.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 #include <webkit2/WebKitURIRequest.h>
 #include <webkit2/WebKitURIResponse.h>
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitFindController.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 
 G_BEGIN_DECLS
 

Copied: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h (from rev 148678, trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h) (0 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitForwardDeclarations.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2013 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#error "Only <webkit2/webkit2.h> can be included directly."
+#endif
+
+#ifndef WebKitForward_h
+#define WebKitForward_h
+
+typedef struct _WebKitPrintOperation  WebKitPrintOperation;
+typedef struct _WebKitFindController  WebKitFindController;
+typedef struct _WebKitWebView         WebKitWebView;
+typedef struct _WebKitContextMenu     WebKitContextMenu;
+typedef struct _WebKitContextMenuItem WebKitContextMenuItem;
+
+#endif // WebKitForward_h

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitPrintOperation.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 #include <webkit2/WebKitWebView.h>
 
 G_BEGIN_DECLS

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.cpp	2013-04-18 16:12:12 UTC (rev 148679)
@@ -70,7 +70,7 @@
 
     switch (propId) {
     case PROP_URI:
-        request->priv->resourceRequest.setURL(KURL(KURL(), g_value_get_string(value)));
+        webkit_uri_request_set_uri(request, g_value_get_string(value));
         break;
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, paramSpec);
@@ -92,8 +92,8 @@
                                     g_param_spec_string("uri",
                                                         _("URI"),
                                                         _("The URI to which the request will be made."),
-                                                        0,
-                                                        static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)));
+                                                        "about:blank",
+                                                        static_cast<GParamFlags>(WEBKIT_PARAM_READWRITE | G_PARAM_CONSTRUCT)));
 }
 
 /**
@@ -125,6 +125,26 @@
     return request->priv->uri.data();
 }
 
+/**
+ * webkit_uri_request_set_uri:
+ * @request: a #WebKitURIRequest
+ * @uri: an URI
+ *
+ * Set the URI of @request
+ */
+void webkit_uri_request_set_uri(WebKitURIRequest* request, const char* uri)
+{
+    g_return_if_fail(WEBKIT_IS_URI_REQUEST(request));
+    g_return_if_fail(uri);
+
+    KURL url(KURL(), uri);
+    if (url == request->priv->resourceRequest.url())
+        return;
+
+    request->priv->resourceRequest.setURL(url);
+    g_object_notify(G_OBJECT(request), "uri");
+}
+
 WebKitURIRequest* webkitURIRequestCreateForResourceRequest(const WebCore::ResourceRequest& resourceRequest)
 {
     WebKitURIRequest* uriRequest = WEBKIT_URI_REQUEST(g_object_new(WEBKIT_TYPE_URI_REQUEST, NULL));

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIRequest.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__)
 #error "Only <webkit2/webkit2.h> can be included directly."
 #endif
 
@@ -61,6 +61,10 @@
 WEBKIT_API const gchar *
 webkit_uri_request_get_uri  (WebKitURIRequest *request);
 
+WEBKIT_API void
+webkit_uri_request_set_uri  (WebKitURIRequest *request,
+                             const gchar      *uri);
+
 G_END_DECLS
 
 #endif

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURIResponse.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -17,7 +17,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
+#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION) && !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__)
 #error "Only <webkit2/webkit2.h> can be included directly."
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitURISchemeRequest.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -26,6 +26,7 @@
 
 #include <glib-object.h>
 #include <webkit2/WebKitDefines.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -34,6 +34,7 @@
 #include <webkit2/WebKitFileChooserRequest.h>
 #include <webkit2/WebKitFindController.h>
 #include <webkit2/WebKitFormSubmissionRequest.h>
+#include <webkit2/WebKitForwardDeclarations.h>
 #include <webkit2/WebKitHitTestResult.h>
 #include <webkit2/WebKitJavascriptResult.h>
 #include <webkit2/WebKitPermissionRequest.h>

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2013-04-18 16:12:12 UTC (rev 148679)
@@ -334,6 +334,7 @@
 WebKitURIRequest
 webkit_uri_request_new
 webkit_uri_request_get_uri
+webkit_uri_request_set_uri
 
 <SUBSECTION Standard>
 WebKitURIRequestClass

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestResources.cpp	2013-04-18 16:12:12 UTC (rev 148679)
@@ -558,6 +558,75 @@
     g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, simpleStyleCSSURI.data());
 }
 
+class SendRequestTest: public SingleResourceLoadTest {
+public:
+    MAKE_GLIB_TEST_FIXTURE(SendRequestTest);
+
+    void resourceSentRequest(WebKitWebResource* resource, WebKitURIRequest* request, WebKitURIResponse* redirectResponse)
+    {
+        if (resource != m_resource)
+            return;
+
+        g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, m_expectedNewResourceURI.data());
+        g_assert_cmpstr(webkit_uri_request_get_uri(request), ==, webkit_web_resource_get_uri(resource));
+
+        SingleResourceLoadTest::resourceSentRequest(resource, request, redirectResponse);
+    }
+
+    void resourceFailed(WebKitWebResource* resource, GError* error)
+    {
+        if (resource != m_resource)
+            return;
+
+        g_assert_cmpstr(webkit_web_resource_get_uri(resource), ==, m_expectedCancelledResourceURI.data());
+        g_assert_error(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED);
+
+        SingleResourceLoadTest::resourceFailed(resource, error);
+    }
+
+    void setExpectedNewResourceURI(const CString& uri)
+    {
+        m_expectedNewResourceURI = uri;
+    }
+
+    void setExpectedCancelledResourceURI(const CString& uri)
+    {
+        m_expectedCancelledResourceURI = uri;
+    }
+
+    CString m_expectedNewResourceURI;
+    CString m_expectedCancelledResourceURI;
+};
+
+static void testWebResourceSendRequest(SendRequestTest* test, gconstpointer)
+{
+    test->setExpectedNewResourceURI(kServer->getURIForPath("/_javascript_.js"));
+    test->loadURI(kServer->getURIForPath("relative-_javascript_.html").data());
+    test->waitUntilResourceLoadFinished();
+    g_assert(test->m_resource);
+
+    Vector<SingleResourceLoadTest::LoadEvents>& events = test->m_loadEvents;
+    g_assert_cmpint(events.size(), ==, 5);
+    g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started);
+    g_assert_cmpint(events[1], ==, SingleResourceLoadTest::SentRequest);
+    g_assert_cmpint(events[2], ==, SingleResourceLoadTest::ReceivedResponse);
+    g_assert_cmpint(events[3], ==, SingleResourceLoadTest::ReceivedData);
+    g_assert_cmpint(events[4], ==, SingleResourceLoadTest::Finished);
+    events.clear();
+
+    // Cancel request.
+    test->setExpectedCancelledResourceURI(kServer->getURIForPath("/cancel-this.js"));
+    test->loadURI(kServer->getURIForPath("/resource-to-cancel.html").data());
+    test->waitUntilResourceLoadFinished();
+    g_assert(test->m_resource);
+
+    g_assert_cmpint(events.size(), ==, 3);
+    g_assert_cmpint(events[0], ==, SingleResourceLoadTest::Started);
+    g_assert_cmpint(events[1], ==, SingleResourceLoadTest::Failed);
+    g_assert_cmpint(events[2], ==, SingleResourceLoadTest::Finished);
+    events.clear();
+}
+
 static void addCacheHTTPHeadersToResponse(SoupMessage* message)
 {
     // The actual date doesn't really matter.
@@ -611,6 +680,12 @@
         soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, kJavascript, strlen(kJavascript));
         soup_message_headers_append(message->response_headers, "Content-Type", "text/_javascript_");
         soup_message_headers_append(message->response_headers, "Content-Disposition", "filename=_javascript_.js");
+    } else if (g_str_equal(path, "/relative-_javascript_.html")) {
+        static const char* _javascript_RelativeHTML = "<html><head><script language='_javascript_' src=''></script></head><body></body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, _javascript_RelativeHTML, strlen(_javascript_RelativeHTML));
+    } else if (g_str_equal(path, "/resource-to-cancel.html")) {
+        static const char* resourceToCancelHTML = "<html><head><script language='_javascript_' src=''></script></head><body></body></html>";
+        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, resourceToCancelHTML, strlen(resourceToCancelHTML));
     } else if (g_str_equal(path, "/blank.ico")) {
         GOwnPtr<char> filePath(g_build_filename(Test::getWebKit1TestResoucesDir().data(), path, NULL));
         char* contents;
@@ -641,6 +716,8 @@
     kServer = new WebKitTestServer();
     kServer->run(serverCallback);
 
+    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
+
     ResourcesTest::add("WebKitWebView", "resources", testWebViewResources);
     SingleResourceLoadTest::add("WebKitWebResource", "loading", testWebResourceLoading);
     SingleResourceLoadTest::add("WebKitWebResource", "response", testWebResourceResponse);
@@ -649,6 +726,7 @@
     ResourceURITrackingTest::add("WebKitWebResource", "active-uri", testWebResourceActiveURI);
     ResourcesTest::add("WebKitWebResource", "get-data", testWebResourceGetData);
     SingleResourceLoadTest::add("WebKitWebView", "history-cache", testWebViewResourcesHistoryCache);
+    SendRequestTest::add("WebKitWebPage", "send-request", testWebResourceSendRequest);
 }
 
 void afterAll()

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebExtensionTest.cpp	2013-04-18 16:12:12 UTC (rev 148679)
@@ -21,6 +21,7 @@
 
 #include <gio/gio.h>
 #include <stdlib.h>
+#include <string.h>
 
 #include <webkit2/webkit-web-extension.h>
 #include <wtf/gobject/GOwnPtr.h>
@@ -66,10 +67,26 @@
     g_assert(ok);
 }
 
+static gboolean sendRequestCallback(WebKitWebPage*, WebKitURIRequest* request, WebKitURIResponse*, gpointer)
+{
+    const char* requestURI = webkit_uri_request_get_uri(request);
+    g_assert(requestURI);
+
+    if (const char* suffix = g_strrstr(requestURI, "/remove-this/_javascript_.js")) {
+        GOwnPtr<char> prefix(g_strndup(requestURI, strlen(requestURI) - strlen(suffix)));
+        GOwnPtr<char> newURI(g_strdup_printf("%s/_javascript_.js", prefix.get()));
+        webkit_uri_request_set_uri(request, newURI.get());
+    } else if (g_str_has_suffix(requestURI, "/cancel-this.js"))
+        return TRUE;
+
+    return FALSE;
+}
+
 static void pageCreatedCallback(WebKitWebExtension*, WebKitWebPage* webPage, gpointer userData)
 {
     g_signal_connect(webPage, "document-loaded", G_CALLBACK(documentLoadedCallback), userData);
     g_signal_connect(webPage, "notify::uri", G_CALLBACK(uriChangedCallback), userData);
+    g_signal_connect(webPage, "send-request", G_CALLBACK(sendRequestCallback), 0);
 }
 
 static void methodCallCallback(GDBusConnection* connection, const char* sender, const char* objectPath, const char* interfaceName, const char* methodName, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer userData)

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list (148678 => 148679)


--- trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list	2013-04-18 16:12:12 UTC (rev 148679)
@@ -3,6 +3,7 @@
 BOOLEAN:OBJECT
 BOOLEAN:OBJECT,BOXED,OBJECT
 BOOLEAN:OBJECT,ENUM
+BOOLEAN:OBJECT,OBJECT
 BOOLEAN:STRING
 BOOLEAN:VOID
 OBJECT:VOID

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h (148678 => 148679)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtension.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -25,7 +25,7 @@
 #define WebKitWebExtension_h
 
 #include <glib-object.h>
-#include <webkit2/WebKitWebExtensionDefines.h>
+#include <webkit2/WebKitDefines.h>
 #include <webkit2/WebKitWebPage.h>
 
 G_BEGIN_DECLS

Deleted: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h (148678 => 148679)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebExtensionDefines.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2012 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#if !defined(__WEBKIT_WEB_EXTENSION_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
-#error "Only <webkit2/webkit-web-extension.h> can be included directly."
-#endif
-
-#ifndef WebKitWebExtensionDefines_h
-#define WebKitWebExtensionDefines_h
-
-#include <glib.h>
-
-#ifdef G_OS_WIN32
-#    ifdef BUILDING_WEBKIT
-#        define WEBKIT_API __declspec(dllexport)
-#    else
-#        define WEBKIT_API __declspec(dllimport)
-#    endif
-#    define WEBKIT_OBSOLETE_API WEBKIT_API
-#else
-#    define WEBKIT_API __attribute__((visibility("default")))
-#    define WEBKIT_OBSOLETE_API WEBKIT_API __attribute__((deprecated))
-#endif
-
-#endif // WebKitWebExtensionDefines_h

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


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp	2013-04-18 16:12:12 UTC (rev 148679)
@@ -28,7 +28,10 @@
 #include "WebFrame.h"
 #include "WebImage.h"
 #include "WebKitDOMDocumentPrivate.h"
+#include "WebKitMarshal.h"
 #include "WebKitPrivate.h"
+#include "WebKitURIRequestPrivate.h"
+#include "WebKitURIResponsePrivate.h"
 #include "WebKitWebPagePrivate.h"
 #include "WebProcess.h"
 #include <WebCore/Document.h>
@@ -43,6 +46,7 @@
 
 enum {
     DOCUMENT_LOADED,
+    SEND_REQUEST,
 
     LAST_SIGNAL
 };
@@ -123,18 +127,27 @@
     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*)
+static WKURLRequestRef willSendRequestForFrame(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLRequestRef wkRequest, WKURLResponseRef wkRedirectResponse, const void* clientInfo)
 {
+    GRefPtr<WebKitURIRequest> request = adoptGRef(webkitURIRequestCreateForResourceRequest(toImpl(wkRequest)->resourceRequest()));
+    GRefPtr<WebKitURIResponse> redirectResponse = wkRedirectResponse ? adoptGRef(webkitURIResponseCreateForResourceResponse(toImpl(wkRedirectResponse)->resourceResponse())) : 0;
+
+    gboolean returnValue;
+    g_signal_emit(WEBKIT_WEB_PAGE(clientInfo), signals[SEND_REQUEST], 0, request.get(), redirectResponse.get(), &returnValue);
+    if (returnValue)
+        return 0;
+
+    RefPtr<WebURLRequest> newRequest = WebURLRequest::create(webkitURIRequestGetResourceRequest(request.get()));
+
     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));
+    message.set(String::fromUTF8("Request"), newRequest.get());
+    if (!toImpl(wkRedirectResponse)->resourceResponse().isNull())
+        message.set(String::fromUTF8("RedirectResponse"), toImpl(wkRedirectResponse));
     WebProcess::shared().injectedBundle()->postMessage(String::fromUTF8("WebPage.DidSendRequestForResource"), ImmutableDictionary::adopt(message).get());
 
-    WKRetain(request);
-    return request;
+    return toAPI(newRequest.release().leakRef());
 }
 
 static void didReceiveResponseForResource(WKBundlePageRef page, WKBundleFrameRef, uint64_t identifier, WKURLResponseRef response, const void*)
@@ -223,6 +236,37 @@
         0, 0, 0,
         g_cclosure_marshal_VOID__OBJECT,
         G_TYPE_NONE, 0);
+
+    /**
+     * WebKitWebPage::send-request:
+     * @web_page: the #WebKitWebPage on which the signal is emitted
+     * @request: a #WebKitURIRequest
+     * @redirected_response: a #WebKitURIResponse, or %NULL
+     *
+     * This signal is emitted when @request is about to be sent to
+     * the server. This signal can be used to modify the #WebKitURIRequest
+     * that will be sent to the server. You can also cancel the resource load
+     * operation by connecting to this signal and returning %TRUE.
+     *
+     * In case of a server redirection this signal is
+     * emitted again with the @request argument containing the new
+     * request to be sent to the server due to the redirection and the
+     * @redirected_response parameter containing the response
+     * received by the server for the initial request.
+     *
+     * Returns: %TRUE to stop other handlers from being invoked for the event.
+     *    %FALSE to continue emission of the event.
+     */
+    signals[SEND_REQUEST] = g_signal_new(
+        "send-request",
+        G_TYPE_FROM_CLASS(klass),
+        G_SIGNAL_RUN_LAST,
+        0,
+        g_signal_accumulator_true_handled, 0,
+        webkit_marshal_BOOLEAN__OBJECT_OBJECT,
+        G_TYPE_BOOLEAN, 2,
+        WEBKIT_TYPE_URI_REQUEST,
+        WEBKIT_TYPE_URI_RESPONSE);
 }
 
 WebKitWebPage* webkitWebPageCreate(WebPage* webPage)

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h (148678 => 148679)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -25,7 +25,7 @@
 #define WebKitWebPage_h
 
 #include <glib-object.h>
-#include <webkit2/WebKitWebExtensionDefines.h>
+#include <webkit2/WebKitDefines.h>
 #include <webkitdom/webkitdom.h>
 
 G_BEGIN_DECLS

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h (148678 => 148679)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h	2013-04-18 15:01:32 UTC (rev 148678)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/gtk/webkit-web-extension.h	2013-04-18 16:12:12 UTC (rev 148679)
@@ -22,6 +22,8 @@
 
 #define __WEBKIT_WEB_EXTENSION_H_INSIDE__
 
+#include <webkit2/WebKitURIRequest.h>
+#include <webkit2/WebKitURIResponse.h>
 #include <webkit2/WebKitWebExtension.h>
 #include <webkit2/WebKitWebPage.h>
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to