Source/WebKit2/ChangeLog

 12012-10-05 Simon Pena <spena@igalia.com>
 2
 3 [GTK] Add support for running JavaScript from GResources
 4 https://bugs.webkit.org/show_bug.cgi?id=98488
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 GResources allow embedding certain resources, frequently used, in a "bundle"
 9 which can be kept separated or stored in the binary. This patch adds
 10 support for running JavaScript from GResources.
 11
 12 For this, methods run_javascript_from_gresource and
 13 run_javascript_from_gresource_finish are added, which load the resource
 14 and run the JavaScript.
 15
 16 * UIProcess/API/gtk/WebKitWebView.cpp: Include the new methods.
 17 (webkit_web_view_run_javascript_from_gresource):
 18 (webkit_web_view_run_javascript_from_gresource_finish):
 19 * UIProcess/API/gtk/WebKitWebView.h:
 20 * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include the new
 21 methods in the documentation.
 22 * UIProcess/API/gtk/tests/GNUmakefile.am: Add the test resources to the
 23 build infrastructure.
 24 * UIProcess/API/gtk/tests/TestWebKitWebView.cpp: Test the
 25 run_javascript_from_gresource method.
 26 (testWebViewRunJavaScript):
 27 * UIProcess/API/gtk/tests/WebViewTest.cpp: Add a method for testing the
 28 new run_javascript_from_gresource method.
 29 (runJavaScriptFromGResourceReadyCallback):
 30 (WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished):
 31 * UIProcess/API/gtk/tests/WebViewTest.h:
 32 * UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml: Added.
 33 Resource bundle containing the resources.
 34 * UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js: Added.
 35 Example JavaScript file to test the GResources support.
 36
1372012-10-04 Jocelyn Turcotte <jocelyn.turcotte@digia.com>
238
339 [Qt] Fix the tst_QQuickWebView::scrollRequest auto test

Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

@@WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* web
24302430}
24312431
24322432/**
 2433 * webkit_web_view_run_javascript_from_gresource:
 2434 * @web_view: a #WebKitWebView
 2435 * @resource: the location of the resource to load
 2436 * @cancellable: (allow-none): a #GCancellable or %NULL to ignore
 2437 * @callback: (scope async): a #GAsyncReadyCallback to call when the script finished
 2438 * @user_data: (closure): the data to pass to callback function
 2439 *
 2440 * Asynchronously run the script from @resource in the context of the
 2441 * current page in @web_view.
 2442 *
 2443 * When the operation is finished, @callback will be called. You can
 2444 * then call webkit_web_view_run_javascript_finish() to get the result
 2445 * of the operation.
 2446 */
 2447void webkit_web_view_run_javascript_from_gresource(WebKitWebView* webView, const gchar* resource, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData)
 2448{
 2449 g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
 2450 g_return_if_fail(resource);
 2451
 2452 GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(webView), callback, userData,
 2453 reinterpret_cast<gpointer>(webkit_web_view_run_javascript_from_gresource)));
 2454 RunJavaScriptAsyncData* data = createRunJavaScriptAsyncData();
 2455 data->cancellable = cancellable;
 2456 g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyRunJavaScriptAsyncData));
 2457
 2458 GError* error = 0;
 2459 GRefPtr<GBytes> resourceBytes = adoptGRef(g_resources_lookup_data(resource, G_RESOURCE_LOOKUP_FLAGS_NONE, &error));
 2460 if (error) {
 2461 g_simple_async_result_take_error(result.get(), error);
 2462 g_simple_async_result_complete_in_idle(result.get());
 2463 return;
 2464 }
 2465 getPage(webView)->runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(g_bytes_get_data(resourceBytes.get(), 0))),
 2466 ScriptValueCallback::create(result.leakRef(), webkitWebViewRunJavaScriptCallback));
 2467}
 2468
 2469/**
 2470 * webkit_web_view_run_javascript_from_gresource_finish:
 2471 * @web_view: a #WebKitWebView
 2472 * @result: a #GAsyncResult
 2473 * @error: return location for error or %NULL to ignore
 2474 *
 2475 * Finish an asynchronous operation started with webkit_web_view_run_javascript_from_gresource().
 2476 *
 2477 * This is an example of using webkit_web_view_run_javascript_from_gresource() with a script returning
 2478 * a number:
 2479 *
 2480 * <informalexample><programlisting>
 2481 * static void
 2482 * web_view_javascript_finished (GObject *object,
 2483 * GAsyncResult *result,
 2484 * gpointer user_data)
 2485 * {
 2486 * WebKitJavascriptResult *js_result;
 2487 * JSValueRef value;
 2488 * JSGlobalContextRef context;
 2489 * GError *error = NULL;
 2490 *
 2491 * js_result = webkit_web_view_run_javascript_from_gresource_finish (WEBKIT_WEB_VIEW (object), result, &error);
 2492 * if (!js_result) {
 2493 * g_warning ("Error running javascript: %s", error->message);
 2494 * g_error_free (error);
 2495 * return;
 2496 * }
 2497 *
 2498 * context = webkit_javascript_result_get_global_context (js_result);
 2499 * value = webkit_javascript_result_get_value (js_result);
 2500 * if (JSValueIsString (context, value)) {
 2501 * JSStringRef js_str_value;
 2502 * gchar *str_value;
 2503 * gsize str_length;
 2504 *
 2505 * js_str_value = JSValueToStringCopy (context, value, NULL);
 2506 * str_length = JSStringGetMaximumUTF8CStringSize (js_str_value);
 2507 * str_value = (gchar *)g_malloc (str_length);
 2508 * JSStringGetUTF8CString (js_str_value, str_value, str_length);
 2509 * JSStringRelease (js_str_value);
 2510 * g_print ("Script result: %s\n", str_value);
 2511 * g_free (str_value);
 2512 * } else {
 2513 * g_warning ("Error running javascript: unexpected return value");
 2514 * }
 2515 * webkit_javascript_result_unref (js_result);
 2516 * }
 2517 *
 2518 * static void
 2519 * web_view_do_javascript_operation (WebKitWebView *web_view)
 2520 * {
 2521 * const gchar *resource = "/org/gnome/appname/resource.js";
 2522 *
 2523 * // Assuming a script like "a = 2.5;" is stored in the resource
 2524 * webkit_web_view_run_javascript_from_gresource (web_view, resource, NULL, web_view_javascript_finished, NULL);
 2525 * }
 2526 * </programlisting></informalexample>
 2527 *
 2528 * Returns: (transfer full): a #WebKitJavascriptResult with the result of the last executed statement in @script
 2529 * or %NULL in case of error
 2530 */
 2531WebKitJavascriptResult* webkit_web_view_run_javascript_from_gresource_finish(WebKitWebView* webView, GAsyncResult* result, GError** error)
 2532{
 2533 g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0);
 2534 g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0);
 2535
 2536 GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result);
 2537 g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_web_view_run_javascript_from_gresource);
 2538
 2539 if (g_simple_async_result_propagate_error(simpleResult, error))
 2540 return 0;
 2541
 2542 RunJavaScriptAsyncData* data = static_cast<RunJavaScriptAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult));
 2543 return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0;
 2544}
 2545
 2546/**
24332547 * webkit_web_view_get_main_resource:
24342548 * @web_view: a #WebKitWebView
24352549 *

Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

@@webkit_web_view_run_javascript_finish (WebKitWebView *w
321321 GAsyncResult *result,
322322 GError **error);
323323
 324WEBKIT_API void
 325webkit_web_view_run_javascript_from_gresource (WebKitWebView *web_view,
 326 const gchar *resource,
 327 GCancellable *cancellable,
 328 GAsyncReadyCallback callback,
 329 gpointer user_data);
 330
 331WEBKIT_API WebKitJavascriptResult *
 332webkit_web_view_run_javascript_from_gresource_finish(WebKitWebView *web_view,
 333 GAsyncResult *result,
 334 GError **error);
 335
324336WEBKIT_API WebKitWebResource *
325337webkit_web_view_get_main_resource (WebKitWebView *web_view);
326338

Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

@@webkit_web_view_get_inspector
115115webkit_web_view_get_javascript_global_context
116116webkit_web_view_run_javascript
117117webkit_web_view_run_javascript_finish
 118webkit_web_view_run_javascript_from_gresource
 119webkit_web_view_run_javascript_from_gresource_finish
118120webkit_web_view_can_show_mime_type
119121webkit_web_view_save
120122webkit_web_view_save_finish

Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am

@@webkit2_tests_ldflags = \
5656 -no-install \
5757 -no-fast-install
5858
 59
 60DerivedSources/WebKit2/webkit2gtk-tests-resources.c: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js DerivedSources/WebKit2/webkit2gtk-tests-resources.h
 61 $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --generate-source --sourcedir=$(srcdir) $<
 62
 63DerivedSources/WebKit2/webkit2gtk-tests-resources.h: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml
 64 $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --generate-header --sourcedir=$(srcdir) $<
 65
5966noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la
6067Libraries_libWebKit2APITestCore_la_SOURCES = \
6168 Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \

@@Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags)
7077
7178EXTRA_DIST += \
7279 Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem \
73  Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem
 80 Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem \
 81 Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml
7482
7583Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \
7684 Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp

@@Programs_WebKit2APITests_TestWebKitWebContext_LDADD = $(webkit2_tests_ldadd)
8189Programs_WebKit2APITests_TestWebKitWebContext_LDFLAGS = $(webkit2_tests_ldflags)
8290
8391Programs_WebKit2APITests_TestWebKitWebView_SOURCES = \
84  Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
 92 Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp \
 93 DerivedSources/WebKit2/webkit2gtk-tests-resources.c \
 94 DerivedSources/WebKit2/webkit2gtk-tests-resources.h
8595Programs_WebKit2APITests_TestWebKitWebView_CPPFLAGS = $(webkit2_tests_cppflags)
8696Programs_WebKit2APITests_TestWebKitWebView_LDADD = $(webkit2_tests_ldadd)
8797Programs_WebKit2APITests_TestWebKitWebView_LDFLAGS = $(webkit2_tests_ldflags)

Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp

@@static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer)
643643 g_assert(!error.get());
644644 g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult));
645645
 646 javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/webkit2gtk/tests/wk2gtk-test.js", &error.outPtr());
 647 g_assert(javascriptResult);
 648 g_assert(!error.get());
 649 valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
 650 g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");
 651
646652 javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr());
647653 g_assert(!javascriptResult);
648654 g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);

Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp

@@static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTe
313313 g_main_loop_quit(test->m_mainLoop);
314314}
315315
 316static void runJavaScriptFromGResourceReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test)
 317{
 318 test->m_javascriptResult = webkit_web_view_run_javascript_from_gresource_finish(test->m_webView, result, test->m_javascriptError);
 319 g_main_loop_quit(test->m_mainLoop);
 320}
 321
316322WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error)
317323{
318324 if (m_javascriptResult)

@@WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const cha
325331 return m_javascriptResult;
326332}
327333
 334WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError** error)
 335{
 336 if (m_javascriptResult)
 337 webkit_javascript_result_unref(m_javascriptResult);
 338 m_javascriptResult = 0;
 339 m_javascriptError = error;
 340 webkit_web_view_run_javascript_from_gresource(m_webView, resource, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptFromGResourceReadyCallback), this);
 341 g_main_loop_run(m_mainLoop);
 342
 343 return m_javascriptResult;
 344}
 345
328346static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value)
329347{
330348 g_assert(value);

Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h

@@public:
5555 void keyStroke(unsigned int keyVal, unsigned int keyModifiers = 0);
5656
5757 WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**);
 58 WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**);
5859
5960 // Javascript result helpers.
6061 static char* javascriptResultToCString(WebKitJavascriptResult*);

Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml

 1<?xml version="1.0" encoding="UTF-8"?>
 2<gresources>
 3 <gresource prefix="/org/webkit/webkit2gtk/tests/">
 4 <file alias="wk2gtk-test.js">Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js</file>
 5 </gresource>
 6</gresources>

Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js

 1window.document.getElementById('WebKitLink').title;

ChangeLog

 12012-10-05 Simon Pena <spena@igalia.com>
 2
 3 [GTK] Add support for running JavaScript from GResources
 4 https://bugs.webkit.org/show_bug.cgi?id=98488
 5
 6 Reviewed by NOBODY (OOPS!).
 7
 8 GResources allow embedding certain resources, frequently used, in a "bundle"
 9 which can be kept separated or stored in the binary. This patch adds
 10 support for running JavaScript from GResources.
 11
 12 * configure.ac: Add support for compiling GResources
 13
1142012-10-03 Ryuan Choi <ryuan.choi@samsung.com>
215
316 [EFL] Default.edj should be generated although ENABLE_WEBKIT disabled.

configure.ac

@@AM_PATH_GLIB_2_0($GLIB_REQUIRED_VERSION, :, :, gmodule gobject gthread gio)
390390if test -z "$GLIB_GENMARSHAL" || test -z "$GLIB_MKENUMS"; then
391391 AC_MSG_ERROR([You need the GLib dev tools in your path])
392392fi
 393
 394# GResources
 395GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0`
 396AC_SUBST(GLIB_COMPILE_RESOURCES)
 397
393398GLIB_GSETTINGS
394399
395400# Check and identify which unicode backend to use