WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
bug-98488-20121005102413.patch (text/plain), 18.28 KB, created by
Simon Pena
on 2012-10-05 01:25:05 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Simon Pena
Created:
2012-10-05 01:25:05 PDT
Size:
18.28 KB
patch
obsolete
>Subversion Revision: 130382 >diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog >index bc9c30f19c8d6781e83db24dfc24250ff2918ece..f515a779a15fd85bc7e1f294ae5f48bd28465f33 100644 >--- a/Source/WebKit2/ChangeLog >+++ b/Source/WebKit2/ChangeLog >@@ -1,3 +1,39 @@ >+2012-10-05 Simon Pena <spena@igalia.com> >+ >+ [GTK] Add support for running JavaScript from GResources >+ https://bugs.webkit.org/show_bug.cgi?id=98488 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ GResources allow embedding certain resources, frequently used, in a "bundle" >+ which can be kept separated or stored in the binary. This patch adds >+ support for running JavaScript from GResources. >+ >+ For this, methods run_javascript_from_gresource and >+ run_javascript_from_gresource_finish are added, which load the resource >+ and run the JavaScript. >+ >+ * UIProcess/API/gtk/WebKitWebView.cpp: Include the new methods. >+ (webkit_web_view_run_javascript_from_gresource): >+ (webkit_web_view_run_javascript_from_gresource_finish): >+ * UIProcess/API/gtk/WebKitWebView.h: >+ * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Include the new >+ methods in the documentation. >+ * UIProcess/API/gtk/tests/GNUmakefile.am: Add the test resources to the >+ build infrastructure. >+ * UIProcess/API/gtk/tests/TestWebKitWebView.cpp: Test the >+ run_javascript_from_gresource method. >+ (testWebViewRunJavaScript): >+ * UIProcess/API/gtk/tests/WebViewTest.cpp: Add a method for testing the >+ new run_javascript_from_gresource method. >+ (runJavaScriptFromGResourceReadyCallback): >+ (WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished): >+ * UIProcess/API/gtk/tests/WebViewTest.h: >+ * UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml: Added. >+ Resource bundle containing the resources. >+ * UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js: Added. >+ Example JavaScript file to test the GResources support. >+ > 2012-10-04 Jocelyn Turcotte <jocelyn.turcotte@digia.com> > > [Qt] Fix the tst_QQuickWebView::scrollRequest auto test >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >index 3258a0f094a8da0f68fd1fa07824d54d37ad0376..99109773a29c67f7bd5eee63ef92116a251072c6 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp >@@ -2430,6 +2430,120 @@ WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* web > } > > /** >+ * webkit_web_view_run_javascript_from_gresource: >+ * @web_view: a #WebKitWebView >+ * @resource: the location of the resource to load >+ * @cancellable: (allow-none): a #GCancellable or %NULL to ignore >+ * @callback: (scope async): a #GAsyncReadyCallback to call when the script finished >+ * @user_data: (closure): the data to pass to callback function >+ * >+ * Asynchronously run the script from @resource in the context of the >+ * current page in @web_view. >+ * >+ * When the operation is finished, @callback will be called. You can >+ * then call webkit_web_view_run_javascript_finish() to get the result >+ * of the operation. >+ */ >+void webkit_web_view_run_javascript_from_gresource(WebKitWebView* webView, const gchar* resource, GCancellable* cancellable, GAsyncReadyCallback callback, gpointer userData) >+{ >+ g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView)); >+ g_return_if_fail(resource); >+ >+ GRefPtr<GSimpleAsyncResult> result = adoptGRef(g_simple_async_result_new(G_OBJECT(webView), callback, userData, >+ reinterpret_cast<gpointer>(webkit_web_view_run_javascript_from_gresource))); >+ RunJavaScriptAsyncData* data = createRunJavaScriptAsyncData(); >+ data->cancellable = cancellable; >+ g_simple_async_result_set_op_res_gpointer(result.get(), data, reinterpret_cast<GDestroyNotify>(destroyRunJavaScriptAsyncData)); >+ >+ GError* error = 0; >+ GRefPtr<GBytes> resourceBytes = adoptGRef(g_resources_lookup_data(resource, G_RESOURCE_LOOKUP_FLAGS_NONE, &error)); >+ if (error) { >+ g_simple_async_result_take_error(result.get(), error); >+ g_simple_async_result_complete_in_idle(result.get()); >+ return; >+ } >+ getPage(webView)->runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(g_bytes_get_data(resourceBytes.get(), 0))), >+ ScriptValueCallback::create(result.leakRef(), webkitWebViewRunJavaScriptCallback)); >+} >+ >+/** >+ * webkit_web_view_run_javascript_from_gresource_finish: >+ * @web_view: a #WebKitWebView >+ * @result: a #GAsyncResult >+ * @error: return location for error or %NULL to ignore >+ * >+ * Finish an asynchronous operation started with webkit_web_view_run_javascript_from_gresource(). >+ * >+ * This is an example of using webkit_web_view_run_javascript_from_gresource() with a script returning >+ * a number: >+ * >+ * <informalexample><programlisting> >+ * static void >+ * web_view_javascript_finished (GObject *object, >+ * GAsyncResult *result, >+ * gpointer user_data) >+ * { >+ * WebKitJavascriptResult *js_result; >+ * JSValueRef value; >+ * JSGlobalContextRef context; >+ * GError *error = NULL; >+ * >+ * js_result = webkit_web_view_run_javascript_from_gresource_finish (WEBKIT_WEB_VIEW (object), result, &error); >+ * if (!js_result) { >+ * g_warning ("Error running javascript: %s", error->message); >+ * g_error_free (error); >+ * return; >+ * } >+ * >+ * context = webkit_javascript_result_get_global_context (js_result); >+ * value = webkit_javascript_result_get_value (js_result); >+ * if (JSValueIsString (context, value)) { >+ * JSStringRef js_str_value; >+ * gchar *str_value; >+ * gsize str_length; >+ * >+ * js_str_value = JSValueToStringCopy (context, value, NULL); >+ * str_length = JSStringGetMaximumUTF8CStringSize (js_str_value); >+ * str_value = (gchar *)g_malloc (str_length); >+ * JSStringGetUTF8CString (js_str_value, str_value, str_length); >+ * JSStringRelease (js_str_value); >+ * g_print ("Script result: %s\n", str_value); >+ * g_free (str_value); >+ * } else { >+ * g_warning ("Error running javascript: unexpected return value"); >+ * } >+ * webkit_javascript_result_unref (js_result); >+ * } >+ * >+ * static void >+ * web_view_do_javascript_operation (WebKitWebView *web_view) >+ * { >+ * const gchar *resource = "/org/gnome/appname/resource.js"; >+ * >+ * // Assuming a script like "a = 2.5;" is stored in the resource >+ * webkit_web_view_run_javascript_from_gresource (web_view, resource, NULL, web_view_javascript_finished, NULL); >+ * } >+ * </programlisting></informalexample> >+ * >+ * Returns: (transfer full): a #WebKitJavascriptResult with the result of the last executed statement in @script >+ * or %NULL in case of error >+ */ >+WebKitJavascriptResult* webkit_web_view_run_javascript_from_gresource_finish(WebKitWebView* webView, GAsyncResult* result, GError** error) >+{ >+ g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), 0); >+ g_return_val_if_fail(G_IS_ASYNC_RESULT(result), 0); >+ >+ GSimpleAsyncResult* simpleResult = G_SIMPLE_ASYNC_RESULT(result); >+ g_warn_if_fail(g_simple_async_result_get_source_tag(simpleResult) == webkit_web_view_run_javascript_from_gresource); >+ >+ if (g_simple_async_result_propagate_error(simpleResult, error)) >+ return 0; >+ >+ RunJavaScriptAsyncData* data = static_cast<RunJavaScriptAsyncData*>(g_simple_async_result_get_op_res_gpointer(simpleResult)); >+ return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0; >+} >+ >+/** > * webkit_web_view_get_main_resource: > * @web_view: a #WebKitWebView > * >diff --git a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >index 37add3a40dfa26e71c6c49c4b55007818d88d151..c336ae64b726022cc552673d9d511cd134c0149f 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >+++ b/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h >@@ -321,6 +321,18 @@ webkit_web_view_run_javascript_finish (WebKitWebView *w > GAsyncResult *result, > GError **error); > >+WEBKIT_API void >+webkit_web_view_run_javascript_from_gresource (WebKitWebView *web_view, >+ const gchar *resource, >+ GCancellable *cancellable, >+ GAsyncReadyCallback callback, >+ gpointer user_data); >+ >+WEBKIT_API WebKitJavascriptResult * >+webkit_web_view_run_javascript_from_gresource_finish(WebKitWebView *web_view, >+ GAsyncResult *result, >+ GError **error); >+ > WEBKIT_API WebKitWebResource * > webkit_web_view_get_main_resource (WebKitWebView *web_view); > >diff --git a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >index 94dc6aa2bc31faa32ec005193be3e11b73fc2874..8545a41aef3331229cc027f824804458368acf16 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >+++ b/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt >@@ -115,6 +115,8 @@ webkit_web_view_get_inspector > webkit_web_view_get_javascript_global_context > webkit_web_view_run_javascript > webkit_web_view_run_javascript_finish >+webkit_web_view_run_javascript_from_gresource >+webkit_web_view_run_javascript_from_gresource_finish > webkit_web_view_can_show_mime_type > webkit_web_view_save > webkit_web_view_save_finish >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am >index 8555af5958eaa466b30190b789cedf882d431c8e..a2c0cb02006fdc9077232b7549012bf928ef811c 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am >@@ -56,6 +56,13 @@ webkit2_tests_ldflags = \ > -no-install \ > -no-fast-install > >+ >+DerivedSources/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 >+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --generate-source --sourcedir=$(srcdir) $< >+ >+DerivedSources/WebKit2/webkit2gtk-tests-resources.h: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml >+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --generate-header --sourcedir=$(srcdir) $< >+ > noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la > Libraries_libWebKit2APITestCore_la_SOURCES = \ > Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \ >@@ -70,7 +77,8 @@ Libraries_libWebKit2APITestCore_la_CPPFLAGS = $(webkit2_tests_cppflags) > > EXTRA_DIST += \ > Source/WebKit2/UIProcess/API/gtk/tests/resources/test-cert.pem \ >- Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem >+ Source/WebKit2/UIProcess/API/gtk/tests/resources/test-key.pem \ >+ Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml > > Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \ > Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp >@@ -81,7 +89,9 @@ Programs_WebKit2APITests_TestWebKitWebContext_LDADD = $(webkit2_tests_ldadd) > Programs_WebKit2APITests_TestWebKitWebContext_LDFLAGS = $(webkit2_tests_ldflags) > > Programs_WebKit2APITests_TestWebKitWebView_SOURCES = \ >- Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp >+ Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp \ >+ DerivedSources/WebKit2/webkit2gtk-tests-resources.c \ >+ DerivedSources/WebKit2/webkit2gtk-tests-resources.h > Programs_WebKit2APITests_TestWebKitWebView_CPPFLAGS = $(webkit2_tests_cppflags) > Programs_WebKit2APITests_TestWebKitWebView_LDADD = $(webkit2_tests_ldadd) > Programs_WebKit2APITests_TestWebKitWebView_LDFLAGS = $(webkit2_tests_ldflags) >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp >index 02e8138ded4ad2c4674c87c1de02f534f31246a4..c5af698d392c62d69db946210f7e69bd79543eef 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp >@@ -643,6 +643,12 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer) > g_assert(!error.get()); > g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult)); > >+ javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/webkit2gtk/tests/wk2gtk-test.js", &error.outPtr()); >+ g_assert(javascriptResult); >+ g_assert(!error.get()); >+ valueString.set(WebViewTest::javascriptResultToCString(javascriptResult)); >+ g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title"); >+ > javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr()); > g_assert(!javascriptResult); > g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED); >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp >index 04747480e08089a26da8afb7883d505f053e8610..7e7eb01675821a5ab2e3da42cc25e60ae1718b9a 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp >@@ -313,6 +313,12 @@ static void runJavaScriptReadyCallback(GObject*, GAsyncResult* result, WebViewTe > g_main_loop_quit(test->m_mainLoop); > } > >+static void runJavaScriptFromGResourceReadyCallback(GObject*, GAsyncResult* result, WebViewTest* test) >+{ >+ test->m_javascriptResult = webkit_web_view_run_javascript_from_gresource_finish(test->m_webView, result, test->m_javascriptError); >+ g_main_loop_quit(test->m_mainLoop); >+} >+ > WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const char* javascript, GError** error) > { > if (m_javascriptResult) >@@ -325,6 +331,18 @@ WebKitJavascriptResult* WebViewTest::runJavaScriptAndWaitUntilFinished(const cha > return m_javascriptResult; > } > >+WebKitJavascriptResult* WebViewTest::runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError** error) >+{ >+ if (m_javascriptResult) >+ webkit_javascript_result_unref(m_javascriptResult); >+ m_javascriptResult = 0; >+ m_javascriptError = error; >+ webkit_web_view_run_javascript_from_gresource(m_webView, resource, 0, reinterpret_cast<GAsyncReadyCallback>(runJavaScriptFromGResourceReadyCallback), this); >+ g_main_loop_run(m_mainLoop); >+ >+ return m_javascriptResult; >+} >+ > static char* jsValueToCString(JSGlobalContextRef context, JSValueRef value) > { > g_assert(value); >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h >index 25209caa31971c5980255e4f6fb345593c023803..06f398f962650863ccf46aac948ce60fd2dbc46c 100644 >--- a/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h >@@ -55,6 +55,7 @@ public: > void keyStroke(unsigned int keyVal, unsigned int keyModifiers = 0); > > WebKitJavascriptResult* runJavaScriptAndWaitUntilFinished(const char* javascript, GError**); >+ WebKitJavascriptResult* runJavaScriptFromGResourceAndWaitUntilFinished(const char* resource, GError**); > > // Javascript result helpers. > static char* javascriptResultToCString(WebKitJavascriptResult*); >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml >new file mode 100644 >index 0000000000000000000000000000000000000000..b2f6e5d0b26312301a58fb1605c0c37c902bf8ba >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml >@@ -0,0 +1,6 @@ >+<?xml version="1.0" encoding="UTF-8"?> >+<gresources> >+ <gresource prefix="/org/webkit/webkit2gtk/tests/"> >+ <file alias="wk2gtk-test.js">Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js</file> >+ </gresource> >+</gresources> >diff --git a/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js >new file mode 100644 >index 0000000000000000000000000000000000000000..2c824da38642a02fe7b985c1359b8044536d0c3e >--- /dev/null >+++ b/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.test.js >@@ -0,0 +1 @@ >+window.document.getElementById('WebKitLink').title; >diff --git a/ChangeLog b/ChangeLog >index 317ce97507c297939bb47432381c38cb71f2a171..89b10947d64a71dc1e3aa9c2a8275a0b8f8a7e86 100644 >--- a/ChangeLog >+++ b/ChangeLog >@@ -1,3 +1,16 @@ >+2012-10-05 Simon Pena <spena@igalia.com> >+ >+ [GTK] Add support for running JavaScript from GResources >+ https://bugs.webkit.org/show_bug.cgi?id=98488 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ GResources allow embedding certain resources, frequently used, in a "bundle" >+ which can be kept separated or stored in the binary. This patch adds >+ support for running JavaScript from GResources. >+ >+ * configure.ac: Add support for compiling GResources >+ > 2012-10-03 Ryuan Choi <ryuan.choi@samsung.com> > > [EFL] Default.edj should be generated although ENABLE_WEBKIT disabled. >diff --git a/configure.ac b/configure.ac >index c8f110dc1404359bc37bb2f6cc0f6b14ea96d006..d8bab0bd269aff47912328d81a56883e64aeb224 100644 >--- a/configure.ac >+++ b/configure.ac >@@ -390,6 +390,11 @@ AM_PATH_GLIB_2_0($GLIB_REQUIRED_VERSION, :, :, gmodule gobject gthread gio) > if test -z "$GLIB_GENMARSHAL" || test -z "$GLIB_MKENUMS"; then > AC_MSG_ERROR([You need the GLib dev tools in your path]) > fi >+ >+# GResources >+GLIB_COMPILE_RESOURCES=`$PKG_CONFIG --variable glib_compile_resources gio-2.0` >+AC_SUBST(GLIB_COMPILE_RESOURCES) >+ > GLIB_GSETTINGS > > # Check and identify which unicode backend to use
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 98488
:
167279
|
167545
|
167730
|
167743