Title: [171740] trunk
Revision
171740
Author
carlo...@webkit.org
Date
2014-07-29 04:35:52 -0700 (Tue, 29 Jul 2014)

Log Message

Implement webkit_web_view_load_string() in WebKit2
https://bugs.webkit.org/show_bug.cgi?id=134735

Reviewed by Sergio Villar Senin.

Source/WebKit2:
Add webkit_web_view_load_bytes() that receives a GBytes to load
random data in the web view using the given MIME-Type, encoding
and base URL.

* UIProcess/API/gtk/WebKitWebView.cpp:
(releaseGBytes):
(webkit_web_view_load_bytes):
* UIProcess/API/gtk/WebKitWebView.h:
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
* UIProcess/API/gtk/docs/webkit2gtk-sections.txt:

Tools:
Add /webkit2/WebKitWebView/load-bytes test case and simplify
TestDOMXPathNSResolver by using webkit_web_view_load_bytes()
instead of a soup server just to sent the Content-type header.

* TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp:
(testWebKitDOMXPathNSResolverNative):
(testWebKitDOMXPathNSResolverCustom):
(beforeAll):
(afterAll):
(serverCallback): Deleted.
* TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp:
(testLoadBytes):
(beforeAll):
* TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp:
(LoadTrackingTest::loadBytes):
* TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h:
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
(WebViewTest::loadBytes):
* TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (171739 => 171740)


--- trunk/Source/WebKit2/ChangeLog	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-29 11:35:52 UTC (rev 171740)
@@ -1,3 +1,21 @@
+2014-07-29  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        Implement webkit_web_view_load_string() in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=134735
+
+        Reviewed by Sergio Villar Senin.
+
+        Add webkit_web_view_load_bytes() that receives a GBytes to load
+        random data in the web view using the given MIME-Type, encoding
+        and base URL.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (releaseGBytes):
+        (webkit_web_view_load_bytes):
+        * UIProcess/API/gtk/WebKitWebView.h:
+        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml:
+        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt:
+
 2014-07-29  Ryuan Choi  <ryuan.c...@samsung.com>
 
         [EFL] Alpha value of ewk_view_bg_color_set is not working

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2014-07-29 11:35:52 UTC (rev 171740)
@@ -2135,7 +2135,46 @@
     getPage(webView)->loadPlainTextString(String::fromUTF8(plainText));
 }
 
+static void releaseGBytes(unsigned char*, const void* bytes)
+{
+    // Balanced by g_bytes_ref in webkit_web_view_load_bytes().
+    g_bytes_unref(static_cast<GBytes*>(const_cast<void*>(bytes)));
+}
+
 /**
+ * webkit_web_view_load_bytes:
+ * @web_view: a #WebKitWebView
+ * @bytes: input data to load
+ * @mime_type: (allow-none): the MIME type of @bytes, or %NULL
+ * @encoding: (allow-none): the character encoding of @bytes, or %NULL
+ * @base_uri: (allow-none): the base URI for relative locations or %NULL
+ *
+ * Load the specified @bytes into @web_view using the given @mime_type and @encoding.
+ * When @mime_type is %NULL, it defaults to "text/html".
+ * When @encoding is %NULL, it defaults to "UTF-8".
+ * When @base_uri is %NULL, it defaults to "about:blank".
+ * You can monitor the load operation by connecting to #WebKitWebView::load-changed signal.
+ *
+ * Since: 2.6
+ */
+void webkit_web_view_load_bytes(WebKitWebView* webView, GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(bytes);
+
+    gsize bytesDataSize;
+    gconstpointer bytesData = g_bytes_get_data(bytes, &bytesDataSize);
+    g_return_if_fail(bytesDataSize);
+
+    // Balanced by g_bytes_unref in releaseGBytes.
+    g_bytes_ref(bytes);
+
+    RefPtr<API::Data> data = "" unsigned char*>(bytesData), bytesDataSize, releaseGBytes, bytes);
+    getPage(webView)->loadData(data.get(), mimeType ? String::fromUTF8(mimeType) : String::fromUTF8("text/html"),
+        encoding ? String::fromUTF8(encoding) : String::fromUTF8("UTF-8"), String::fromUTF8(baseURI));
+}
+
+/**
  * webkit_web_view_load_request:
  * @web_view: a #WebKitWebView
  * @request: a #WebKitURIRequest to load

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2014-07-29 11:35:52 UTC (rev 171740)
@@ -288,6 +288,13 @@
                                                       const gchar               *plain_text);
 
 WEBKIT_API void
+webkit_web_view_load_bytes                           (WebKitWebView             *web_view,
+                                                      GBytes                    *bytes,
+                                                      const gchar               *mime_type,
+                                                      const gchar               *encoding,
+                                                      const gchar               *base_uri);
+
+WEBKIT_API void
 webkit_web_view_load_request                         (WebKitWebView             *web_view,
                                                       WebKitURIRequest          *request);
 

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml (171739 => 171740)


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml	2014-07-29 11:35:52 UTC (rev 171740)
@@ -69,5 +69,10 @@
     <xi:include href="" /></xi:include>
   </index>
 
+  <index id="api-index-2-6" role="2.6">
+    <title>Index of new symbols in 2.6</title>
+    <xi:include href="" /></xi:include>
+  </index>
+
   <xi:include href="" /></xi:include>
 </book>

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2014-07-29 11:35:52 UTC (rev 171740)
@@ -143,6 +143,7 @@
 webkit_web_view_load_html
 webkit_web_view_load_alternate_html
 webkit_web_view_load_plain_text
+webkit_web_view_load_bytes
 webkit_web_view_load_request
 webkit_web_view_can_go_back
 webkit_web_view_go_back

Modified: trunk/Tools/ChangeLog (171739 => 171740)


--- trunk/Tools/ChangeLog	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/ChangeLog	2014-07-29 11:35:52 UTC (rev 171740)
@@ -1,3 +1,30 @@
+2014-07-29  Carlos Garcia Campos  <cgar...@igalia.com>
+
+        Implement webkit_web_view_load_string() in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=134735
+
+        Reviewed by Sergio Villar Senin.
+
+        Add /webkit2/WebKitWebView/load-bytes test case and simplify
+        TestDOMXPathNSResolver by using webkit_web_view_load_bytes()
+        instead of a soup server just to sent the Content-type header.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp:
+        (testWebKitDOMXPathNSResolverNative):
+        (testWebKitDOMXPathNSResolverCustom):
+        (beforeAll):
+        (afterAll):
+        (serverCallback): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp:
+        (testLoadBytes):
+        (beforeAll):
+        * TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp:
+        (LoadTrackingTest::loadBytes):
+        * TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h:
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp:
+        (WebViewTest::loadBytes):
+        * TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h:
+
 2014-07-28  Daniel Bates  <daba...@apple.com>
 
         Add support for running the Clang static analyzer when building WebKit and JSC

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestDOMXPathNSResolver.cpp	2014-07-29 11:35:52 UTC (rev 171740)
@@ -19,14 +19,12 @@
 
 #include "config.h"
 
-#include "WebKitTestServer.h"
 #include "WebProcessTestRunner.h"
 #include "WebViewTest.h"
 #include <gtk/gtk.h>
 #include <webkit2/webkit2.h>
 
 static WebProcessTestRunner* testRunner;
-static WebKitTestServer* kServer;
 
 static void runTest(WebViewTest* test, const char* name)
 {
@@ -38,46 +36,24 @@
 
 static void testWebKitDOMXPathNSResolverNative(WebViewTest* test, gconstpointer)
 {
-    test->loadURI(kServer->getURIForPath("/native").data());
+    static const char* nativeXML = "<root xmlns:foo='http://www.example.org'><foo:child>SUCCESS</foo:child></root>";
+    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(nativeXML, strlen(nativeXML)));
+    test->loadBytes(bytes.get(), "text/xml", nullptr, nullptr);
     test->waitUntilLoadFinished();
     runTest(test, "native");
 }
 
 static void testWebKitDOMXPathNSResolverCustom(WebViewTest* test, gconstpointer)
 {
-    test->loadURI(kServer->getURIForPath("/custom").data());
+    static const char* customXML = "<root xmlns='http://www.example.com'><child>SUCCESS</child></root>";
+    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_static(customXML, strlen(customXML)));
+    test->loadBytes(bytes.get(), "text/xml", nullptr, nullptr);
     test->waitUntilLoadFinished();
     runTest(test, "custom");
 }
 
-static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
-{
-    if (message->method != SOUP_METHOD_GET) {
-        soup_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED);
-        return;
-    }
-
-    if (g_str_equal(path, "/native")) {
-        soup_message_set_status(message, SOUP_STATUS_OK);
-        soup_message_headers_append(message->response_headers, "Content-Type", "text/xml");
-        static const char* nativeXML = "<root xmlns:foo='http://www.example.org'><foo:child>SUCCESS</foo:child></root>";
-        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, nativeXML, strlen(nativeXML));
-        soup_message_body_complete(message->response_body);
-    } else if (g_str_equal(path, "/custom")) {
-        soup_message_set_status(message, SOUP_STATUS_OK);
-        soup_message_headers_append(message->response_headers, "Content-Type", "text/xml");
-        static const char* customXML = "<root xmlns='http://www.example.com'><child>SUCCESS</child></root>";
-        soup_message_body_append(message->response_body, SOUP_MEMORY_STATIC, customXML, strlen(customXML));
-        soup_message_body_complete(message->response_body);
-    } else
-        soup_message_set_status(message, SOUP_STATUS_NOT_FOUND);
-}
-
 void beforeAll()
 {
-    kServer = new WebKitTestServer();
-    kServer->run(serverCallback);
-
     testRunner = new WebProcessTestRunner();
     webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
 
@@ -88,5 +64,4 @@
 void afterAll()
 {
     delete testRunner;
-    delete kServer;
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestLoaderClient.cpp	2014-07-29 11:35:52 UTC (rev 171740)
@@ -89,6 +89,18 @@
     assertNormalLoadHappened(test->m_loadEvents);
 }
 
+static void testLoadBytes(LoadTrackingTest* test, gconstpointer)
+{
+    GUniquePtr<char> filePath(g_build_filename(Test::getResourcesDir().data(), "blank.ico", nullptr));
+    char* contents;
+    gsize contentsLength;
+    g_file_get_contents(filePath.get(), &contents, &contentsLength, nullptr);
+    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_take(contents, contentsLength));
+    test->loadBytes(bytes.get(), "image/vnd.microsoft.icon", nullptr, nullptr);
+    test->waitUntilLoadFinished();
+    assertNormalLoadHappened(test->m_loadEvents);
+}
+
 static void testLoadRequest(LoadTrackingTest* test, gconstpointer)
 {
     GRefPtr<WebKitURIRequest> request(webkit_uri_request_new(kServer->getURIForPath("/normal").data()));
@@ -442,6 +454,7 @@
     LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml);
     LoadTrackingTest::add("WebKitWebView", "load-alternate-html", testLoadAlternateHTML);
     LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText);
+    LoadTrackingTest::add("WebKitWebView", "load-bytes", testLoadBytes);
     LoadTrackingTest::add("WebKitWebView", "load-request", testLoadRequest);
     LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled);
     LoadTrackingTest::add("WebKitWebView", "title", testWebViewTitle);

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.cpp	2014-07-29 11:35:52 UTC (rev 171740)
@@ -174,6 +174,14 @@
     WebViewTest::loadPlainText(plainText);
 }
 
+void LoadTrackingTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI)
+{
+    m_loadEvents.clear();
+    m_estimatedProgress = 0;
+    m_error.reset();
+    WebViewTest::loadBytes(bytes, mimeType, encoding, baseURI);
+}
+
 void LoadTrackingTest::loadRequest(WebKitURIRequest* request)
 {
     m_loadEvents.clear();

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/LoadTrackingTest.h	2014-07-29 11:35:52 UTC (rev 171740)
@@ -43,6 +43,7 @@
     void loadHtml(const char* html, const char* baseURI);
     void loadPlainText(const char* plainText);
     void loadRequest(WebKitURIRequest*);
+    void loadBytes(GBytes*, const char* mimeType, const char* encoding, const char* baseURI);
     void reload();
     void goBack();
     void goForward();

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.cpp	2014-07-29 11:35:52 UTC (rev 171740)
@@ -71,6 +71,15 @@
     webkit_web_view_load_plain_text(m_webView, plainText);
 }
 
+void WebViewTest::loadBytes(GBytes* bytes, const char* mimeType, const char* encoding, const char* baseURI)
+{
+    if (!baseURI)
+        m_activeURI = "about:blank";
+    else
+        m_activeURI = baseURI;
+    webkit_web_view_load_bytes(m_webView, bytes, mimeType, encoding, baseURI);
+}
+
 void WebViewTest::loadRequest(WebKitURIRequest* request)
 {
     m_activeURI = webkit_uri_request_get_uri(request);

Modified: trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h (171739 => 171740)


--- trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h	2014-07-29 08:52:49 UTC (rev 171739)
+++ trunk/Tools/TestWebKitAPI/gtk/WebKit2Gtk/WebViewTest.h	2014-07-29 11:35:52 UTC (rev 171740)
@@ -36,6 +36,7 @@
     virtual void loadHtml(const char* html, const char* baseURI);
     virtual void loadPlainText(const char* plainText);
     virtual void loadRequest(WebKitURIRequest*);
+    virtual void loadBytes(GBytes*, const char* mimeType, const char* encoding, const char* baseURI);
     void loadAlternateHTML(const char* html, const char* contentURI, const char* baseURI);
     void goBack();
     void goForward();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to