Changeset 97624 in webkit


Ignore:
Timestamp:
Oct 17, 2011 9:23:51 AM (13 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add methods to get/set a custom text enconding to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=69524

Reviewed by Martin Robinson.

  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkit_web_view_get_custom_charset):
(webkit_web_view_set_custom_charset):

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/tests/TestWebKitWebView.cpp:

(testWebViewCustomCharset):
(beforeAll):

Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r97608 r97624  
     12011-10-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add methods to get/set a custom text enconding to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=69524
     5
     6        Reviewed by Martin Robinson.
     7
     8        * UIProcess/API/gtk/WebKitWebView.cpp:
     9        (webkit_web_view_get_custom_charset):
     10        (webkit_web_view_set_custom_charset):
     11        * UIProcess/API/gtk/WebKitWebView.h:
     12        * UIProcess/API/gtk/tests/TestWebKitWebView.cpp:
     13        (testWebViewCustomCharset):
     14        (beforeAll):
     15
    1162011-10-14  Jesus Sanchez-Palencia  <jesus.palencia@openbossa.org>
    217
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r97364 r97624  
    4444struct _WebKitWebViewPrivate {
    4545    WebKitWebContext* context;
     46    CString customTextEncoding;
    4647
    4748    GRefPtr<WebKitWebLoaderClient> loaderClient;
     
    311312    WKPageGoForward(toAPI(page));
    312313}
     314
     315/**
     316 * webkit_web_view_get_custom_charset:
     317 * @web_view: a #WebKitWebView
     318 *
     319 * Returns the current custom character encoding name of @web_view.
     320 *
     321 * Returns: the current custom character encoding name or %NULL if no
     322 *    custom character encoding has been set.
     323 */
     324const gchar* webkit_web_view_get_custom_charset(WebKitWebView* webView)
     325{
     326    g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
     327
     328    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     329    WKRetainPtr<WKStringRef> wkCustomEncoding(AdoptWK, WKPageCopyCustomTextEncodingName(toAPI(page)));
     330    if (WKStringIsEmpty(wkCustomEncoding.get()))
     331        return 0;
     332
     333    webView->priv->customTextEncoding = toImpl(wkCustomEncoding.get())->string().utf8();
     334    return webView->priv->customTextEncoding.data();
     335}
     336
     337/**
     338 * webkit_web_view_set_custom_charset:
     339 * @web_view: a #WebKitWebView
     340 * @charset: (allow-none): a character encoding name or %NULL
     341 *
     342 * Sets the current custom character encoding override of @web_view. The custom
     343 * character encoding will override any text encoding detected via HTTP headers or
     344 * META tags. Calling this method will stop any current load operation and reload the
     345 * current page. Setting the custom character encoding to %NULL removes the character
     346 * encoding override.
     347 */
     348void webkit_web_view_set_custom_charset(WebKitWebView* webView, const gchar* charset)
     349{
     350    g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
     351
     352    WebPageProxy* page = webkitWebViewBaseGetPage(WEBKIT_WEB_VIEW_BASE(webView));
     353    WKRetainPtr<WKStringRef> wkEncodingName = charset ? adoptWK(WKStringCreateWithUTF8CString(charset)) : 0;
     354    WKPageSetCustomTextEncodingName(toAPI(page), wkEncodingName.get());
     355}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r97047 r97624  
    108108webkit_web_view_go_forward          (WebKitWebView         *web_view);
    109109
     110WEBKIT_API const gchar *
     111webkit_web_view_get_custom_charset  (WebKitWebView         *web_view);
     112
     113WEBKIT_API void
     114webkit_web_view_set_custom_charset  (WebKitWebView         *web_view,
     115                                     const gchar           *charset);
     116
    110117G_END_DECLS
    111118
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

    r97226 r97624  
    2727}
    2828
     29static void testWebViewCustomCharset(WebViewTest* test, gconstpointer)
     30{
     31    g_assert(!webkit_web_view_get_custom_charset(test->m_webView));
     32    webkit_web_view_set_custom_charset(test->m_webView, "utf8");
     33    g_assert_cmpstr(webkit_web_view_get_custom_charset(test->m_webView), ==, "utf8");
     34    // Go back to the default charset.
     35    webkit_web_view_set_custom_charset(test->m_webView, 0);
     36    g_assert(!webkit_web_view_get_custom_charset(test->m_webView));
     37}
     38
     39
    2940void beforeAll()
    3041{
    3142    WebViewTest::add("WebKitWebView", "default-context", testWebViewDefaultContext);
     43    WebViewTest::add("WebKitWebView", "custom-charset", testWebViewCustomCharset);
    3244}
    3345
Note: See TracChangeset for help on using the changeset viewer.