Title: [99176] trunk/Source/WebKit2
Revision
99176
Author
[email protected]
Date
2011-11-03 05:52:48 -0700 (Thu, 03 Nov 2011)

Log Message

Add webkit_web_view_load_html and webkit_web_view_load_plain_text APIs.
https://bugs.webkit.org/show_bug.cgi?id=69249

Patch by Nayan Kumar K <[email protected]> on 2011-11-03
Reviewed by Philippe Normand.

This patch adds support for 2 more load APIs, namely
webkit_web_view_load_html and webkit_web_view_load_plain_text.

* UIProcess/API/gtk/WebKitWebView.cpp:
(webkit_web_view_load_html): New API to load html string.
(webkit_web_view_load_plain_text): New API to load plain text.
* UIProcess/API/gtk/WebKitWebView.h: Public API addition.
* UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:
(testLoadHtml): Test webkit_web_view_load_html API.
(testLoadPlainText): Test webkit_web_view_load_plain_text API.
(beforeAll): Add new tests.
* UIProcess/API/gtk/tests/WebViewTest.cpp:
(WebViewTest::loadHtml): Test webkit_web_view_load_html API.
(WebViewTest::loadPlainText): Test webkit_web_view_load_plain_text API.
* UIProcess/API/gtk/tests/WebViewTest.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (99175 => 99176)


--- trunk/Source/WebKit2/ChangeLog	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/ChangeLog	2011-11-03 12:52:48 UTC (rev 99176)
@@ -1,3 +1,26 @@
+2011-11-03  Nayan Kumar K  <[email protected]>
+
+        Add webkit_web_view_load_html and webkit_web_view_load_plain_text APIs.
+        https://bugs.webkit.org/show_bug.cgi?id=69249
+
+        Reviewed by Philippe Normand.
+
+        This patch adds support for 2 more load APIs, namely
+        webkit_web_view_load_html and webkit_web_view_load_plain_text.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkit_web_view_load_html): New API to load html string.
+        (webkit_web_view_load_plain_text): New API to load plain text.
+        * UIProcess/API/gtk/WebKitWebView.h: Public API addition.
+        * UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp:
+        (testLoadHtml): Test webkit_web_view_load_html API.
+        (testLoadPlainText): Test webkit_web_view_load_plain_text API.
+        (beforeAll): Add new tests.
+        * UIProcess/API/gtk/tests/WebViewTest.cpp:
+        (WebViewTest::loadHtml): Test webkit_web_view_load_html API.
+        (WebViewTest::loadPlainText): Test webkit_web_view_load_plain_text API.
+        * UIProcess/API/gtk/tests/WebViewTest.h:
+
 2011-11-03  Simon Hausmann  <[email protected]>
 
         [Qt][WK2] Failing assertion with desktop webview when touch mocking in MinBrowser

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp	2011-11-03 12:52:48 UTC (rev 99176)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Igalia S.L.
+ * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -312,6 +313,50 @@
 }
 
 /**
+ * webkit_web_view_load_html:
+ * @web_view: a #WebKitWebView
+ * @content: The HTML string to load
+ * @base_uri: (allow-none): The base URI for relative locations or %NULL
+ *
+ * Load the given @content string with the specified @base_uri. 
+ * Relative URLs in the @content will be resolved against @base_uri.
+ * When @base_uri is %NULL, it defaults to "about:blank". The mime type 
+ * of the document will be "text/html". You can monitor the status of 
+ * the load operation using the #WebKitWebLoaderClient of @web_view. 
+ * See webkit_web_view_get_loader_client().
+ */
+void webkit_web_view_load_html(WebKitWebView* webView, const gchar* content, const gchar* baseURI)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(content);
+
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKRetainPtr<WKStringRef> contentRef(AdoptWK,  WKStringCreateWithUTF8CString(content));
+    WKRetainPtr<WKURLRef> baseURIRef = baseURI ? adoptWK(WKURLCreateWithUTF8CString(baseURI)) : 0;
+    WKPageLoadHTMLString(toAPI(page), contentRef.get(), baseURIRef.get());
+}
+
+/**
+ * webkit_web_view_load_plain_text:
+ * @web_view: a #WebKitWebView
+ * @plain_text: The plain text to load
+ *
+ * Load the specified @plain_text string into @web_view. The mime type of
+ * document will be "text/plain". You can monitor  the status of the load 
+ * operation using the #WebKitWebLoaderClient of @web_view. 
+ * See webkit_web_view_get_loader_client().
+ */
+void webkit_web_view_load_plain_text(WebKitWebView* webView, const gchar* plainText)
+{
+    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
+    g_return_if_fail(plainText);
+
+    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
+    WKRetainPtr<WKStringRef> plainTextRef(AdoptWK, WKStringCreateWithUTF8CString(plainText));
+    WKPageLoadPlainTextString(toAPI(page), plainTextRef.get());
+}
+
+/**
  * webkit_web_view_load_alternate_html:
  * @web_view: a #WebKitWebView
  * @content: the alternate content to display as the main page of the @web_view

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h	2011-11-03 12:52:48 UTC (rev 99176)
@@ -3,6 +3,7 @@
  * Copyright (C) 2007, 2008 Alp Toker <[email protected]>
  * Copyright (C) 2008 Collabora Ltd.
  * Copyright (C) 2011 Igalia S.L.
+ * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -90,6 +91,15 @@
                                               const gchar               *uri);
 
 WEBKIT_API void
+webkit_web_view_load_html                    (WebKitWebView         *web_view,
+                                              const gchar           *content,
+                                              const gchar           *base_uri);
+
+WEBKIT_API void
+webkit_web_view_load_plain_text              (WebKitWebView         *web_view,
+                                              const gchar           *plain_text);
+
+WEBKIT_API void
 webkit_web_view_load_alternate_html          (WebKitWebView             *web_view,
                                               const gchar               *content,
                                               const gchar               *base_uri,

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


--- trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt	2011-11-03 12:52:48 UTC (rev 99176)
@@ -50,6 +50,8 @@
 webkit_web_view_get_loader_client
 webkit_web_view_set_loader_client
 webkit_web_view_load_uri
+webkit_web_view_load_html
+webkit_web_view_load_plain_text
 webkit_web_view_load_alternate_html
 webkit_web_view_can_go_back
 webkit_web_view_go_back

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp (99175 => 99176)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebLoaderClient.cpp	2011-11-03 12:52:48 UTC (rev 99176)
@@ -1,6 +1,7 @@
 /*
  * Copyright (C) 2009, 2010 Gustavo Noronha Silva
  * Copyright (C) 2009, 2011 Igalia S.L.
+ * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -62,6 +63,20 @@
     events.clear();
 }
 
+static void testLoadHtml(LoadTrackingTest* test, gconstpointer)
+{
+    test->loadHtml("<html><body>Hello WebKit-GTK+</body></html>", 0);
+    test->waitUntilLoadFinished();
+    assertNormalLoadHappenedAndClearEvents(test->m_loadEvents);
+}
+
+static void testLoadPlainText(LoadTrackingTest* test, gconstpointer)
+{
+    test->loadPlainText("Hello WebKit-GTK+");
+    test->waitUntilLoadFinished();
+    assertNormalLoadHappenedAndClearEvents(test->m_loadEvents);
+}
+
 static void testLoadAlternateContent(LoadTrackingTest* test, gconstpointer)
 {
     test->loadAlternateHTML("<html><body>Alternate Content</body></html>", 0, kServer->getURIForPath("/alternate").data());
@@ -220,6 +235,8 @@
 
     LoadTrackingTest::add("WebKitWebLoaderClient", "loading-status", testLoadingStatus);
     LoadTrackingTest::add("WebKitWebLoaderClient", "loading-error", testLoadingError);
+    LoadTrackingTest::add("WebKitWebView", "load-html", testLoadHtml);
+    LoadTrackingTest::add("WebKitWebView", "load-plain-text", testLoadPlainText);
     LoadTrackingTest::add("WebKitWebLoaderClient", "load-alternate-content", testLoadAlternateContent);
     LoadStopTrackingTest::add("WebKitWebView", "stop-loading", testLoadCancelled);
     LoadTrackingTest::add("WebKitWebView", "progress", testLoadProgress);

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp (99175 => 99176)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp	2011-11-03 12:52:48 UTC (rev 99176)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Igalia S.L.
+ * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -45,6 +46,18 @@
     webkit_web_view_load_uri(m_webView, uri);
 }
 
+void WebViewTest::loadHtml(const char* html, const char* baseURI)
+{
+    m_activeURI = "about:blank";
+    webkit_web_view_load_html(m_webView, html, baseURI);
+}
+
+void WebViewTest::loadPlainText(const char* plainText)
+{
+    m_activeURI = "about:blank";
+    webkit_web_view_load_plain_text(m_webView, plainText);
+}
+
 void WebViewTest::loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI)
 {
     m_activeURI = "about:blank";

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h (99175 => 99176)


--- trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2011-11-03 12:49:15 UTC (rev 99175)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h	2011-11-03 12:52:48 UTC (rev 99176)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Igalia S.L.
+ * Portions Copyright (c) 2011 Motorola Mobility, Inc.  All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -31,6 +32,8 @@
     virtual ~WebViewTest();
 
     void loadURI(const char* uri);
+    void loadHtml(const char* html, const char* baseURI);
+    void loadPlainText(const char* plainText);
     void loadAlternateHTML(const char* html, const char* baseURI, const char* unreachableURI);
     void goBack();
     void goForward();
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to