[GTK] Add support for running JavaScript from GResources
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 13:31:18 +0000 (13:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Oct 2012 13:31:18 +0000 (13:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=98488

Patch by Simon Pena <spena@igalia.com> on 2012-10-09
Reviewed by Carlos Garcia Campos.

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

Source/WebKit2:

For this, methods run_javascript_from_gresource and
run_javascript_from_gresource_finish are added, which load the resource
asynchronously and, when it is ready, run the JavaScript.

* UIProcess/API/gtk/WebKitWebView.cpp: Include the new methods.
(resourcesStreamReadCallback):
(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/TestMain.cpp: Register the resources in the tests,
so that they can be accessed in all of them.
(register_gresource):
(main):
* 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@130755 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
ChangeLog
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h
Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt
Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am
Source/WebKit2/UIProcess/API/gtk/tests/TestMain.cpp
Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebView.cpp
Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp
Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h
Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml [new file with mode: 0644]
configure.ac

index e723af3..b1b7cea 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2012-10-09  Simon Pena  <spena@igalia.com>
+
+        [GTK] Add support for running JavaScript from GResources
+        https://bugs.webkit.org/show_bug.cgi?id=98488
+
+        Reviewed by Carlos Garcia Campos.
+
+        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-09  Zan Dobersek  <zandobersek@gmail.com>
 
         Unreviewed GTK build fix after r130689.
index 94c67ca..4c1b021 100644 (file)
@@ -1,3 +1,45 @@
+2012-10-09  Simon Pena  <spena@igalia.com>
+
+        [GTK] Add support for running JavaScript from GResources
+        https://bugs.webkit.org/show_bug.cgi?id=98488
+
+        Reviewed by Carlos Garcia Campos.
+
+        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
+        asynchronously and, when it is ready, run the JavaScript.
+
+        * UIProcess/API/gtk/WebKitWebView.cpp: Include the new methods.
+        (resourcesStreamReadCallback):
+        (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/TestMain.cpp: Register the resources in the tests,
+        so that they can be accessed in all of them.
+        (register_gresource):
+        (main):
+        * 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-08  Kiran Muppala  <cmuppala@apple.com>
 
         Throttle DOM timers on hidden pages.
index 4e43a0c..236a4f3 100644 (file)
@@ -2429,6 +2429,94 @@ WebKitJavascriptResult* webkit_web_view_run_javascript_finish(WebKitWebView* web
     return data->scriptResult ? webkit_javascript_result_ref(data->scriptResult) : 0;
 }
 
+static void resourcesStreamReadCallback(GObject* object, GAsyncResult* result, gpointer userData)
+{
+    GOutputStream* outputStream = G_OUTPUT_STREAM(object);
+    GRefPtr<GSimpleAsyncResult> runJavascriptResult = adoptGRef(G_SIMPLE_ASYNC_RESULT(userData));
+
+    GError* error = 0;
+    g_output_stream_splice_finish(outputStream, result, &error);
+    if (error) {
+        g_simple_async_result_take_error(runJavascriptResult.get(), error);
+        g_simple_async_result_complete(runJavascriptResult.get());
+        return;
+    }
+
+    GRefPtr<WebKitWebView> webView = adoptGRef(WEBKIT_WEB_VIEW(g_async_result_get_source_object(G_ASYNC_RESULT(runJavascriptResult.get()))));
+    gpointer outputStreamData = g_memory_output_stream_get_data(G_MEMORY_OUTPUT_STREAM(outputStream));
+    getPage(webView.get())->runJavaScriptInMainFrame(String::fromUTF8(reinterpret_cast<const gchar*>(outputStreamData)),
+                                                     ScriptValueCallback::create(runJavascriptResult.leakRef(), webkitWebViewRunJavaScriptCallback));
+}
+
+/**
+ * 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_from_gresource_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<GInputStream> inputStream = adoptGRef(g_resources_open_stream(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;
+    }
+
+    GRefPtr<GOutputStream> outputStream = adoptGRef(g_memory_output_stream_new(0, 0, fastRealloc, fastFree));
+    g_output_stream_splice_async(outputStream.get(), inputStream.get(),
+                                 static_cast<GOutputStreamSpliceFlags>(G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET),
+                                 G_PRIORITY_DEFAULT,
+                                 cancellable, resourcesStreamReadCallback, result.leakRef());
+}
+
+/**
+ * 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().
+ *
+ * Check webkit_web_view_run_javascript_finish() for a usage example.
+ *
+ * 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
index 37add3a..ac2e281 100644 (file)
@@ -191,173 +191,185 @@ struct _WebKitWebViewClass {
 };
 
 WEBKIT_API GType
-webkit_web_view_get_type                           (void);
+webkit_web_view_get_type                             (void);
 
 WEBKIT_API GtkWidget *
-webkit_web_view_new                                (void);
+webkit_web_view_new                                  (void);
 
 WEBKIT_API GtkWidget *
-webkit_web_view_new_with_context                   (WebKitWebContext          *context);
+webkit_web_view_new_with_context                     (WebKitWebContext          *context);
 
 WEBKIT_API WebKitWebContext *
-webkit_web_view_get_context                        (WebKitWebView             *web_view);
+webkit_web_view_get_context                          (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_load_uri                           (WebKitWebView             *web_view,
-                                                    const gchar               *uri);
+webkit_web_view_load_uri                             (WebKitWebView             *web_view,
+                                                      const gchar               *uri);
 
 WEBKIT_API void
-webkit_web_view_load_html                          (WebKitWebView             *web_view,
-                                                    const gchar               *content,
-                                                    const gchar               *base_uri);
+webkit_web_view_load_html                            (WebKitWebView             *web_view,
+                                                      const gchar               *content,
+                                                      const gchar               *base_uri);
 WEBKIT_API void
-webkit_web_view_load_alternate_html                (WebKitWebView             *web_view,
-                                                    const gchar               *content,
-                                                    const gchar               *content_uri,
-                                                    const gchar               *base_uri);
+webkit_web_view_load_alternate_html                  (WebKitWebView             *web_view,
+                                                      const gchar               *content,
+                                                      const gchar               *content_uri,
+                                                      const gchar               *base_uri);
 WEBKIT_API void
-webkit_web_view_load_plain_text                    (WebKitWebView             *web_view,
-                                                    const gchar               *plain_text);
+webkit_web_view_load_plain_text                      (WebKitWebView             *web_view,
+                                                      const gchar               *plain_text);
 
 WEBKIT_API void
-webkit_web_view_load_request                       (WebKitWebView             *web_view,
-                                                    WebKitURIRequest          *request);
+webkit_web_view_load_request                         (WebKitWebView             *web_view,
+                                                      WebKitURIRequest          *request);
 
 WEBKIT_API void
-webkit_web_view_stop_loading                       (WebKitWebView             *web_view);
+webkit_web_view_stop_loading                         (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_is_loading                         (WebKitWebView             *web_view);
+webkit_web_view_is_loading                           (WebKitWebView             *web_view);
 
 WEBKIT_API const gchar *
-webkit_web_view_get_title                          (WebKitWebView             *web_view);
+webkit_web_view_get_title                            (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_reload                             (WebKitWebView             *web_view);
+webkit_web_view_reload                               (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_reload_bypass_cache                (WebKitWebView             *web_view);
+webkit_web_view_reload_bypass_cache                  (WebKitWebView             *web_view);
 
 WEBKIT_API gdouble
-webkit_web_view_get_estimated_load_progress        (WebKitWebView             *web_view);
+webkit_web_view_get_estimated_load_progress          (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_back                            (WebKitWebView             *web_view);
+webkit_web_view_go_back                              (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_can_go_back                        (WebKitWebView             *web_view);
+webkit_web_view_can_go_back                          (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_forward                         (WebKitWebView             *web_view);
+webkit_web_view_go_forward                           (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_can_go_forward                     (WebKitWebView             *web_view);
+webkit_web_view_can_go_forward                       (WebKitWebView             *web_view);
 
 WEBKIT_API WebKitBackForwardList *
-webkit_web_view_get_back_forward_list              (WebKitWebView             *web_view);
+webkit_web_view_get_back_forward_list                (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_go_to_back_forward_list_item       (WebKitWebView             *web_view,
-                                                    WebKitBackForwardListItem *list_item);
+webkit_web_view_go_to_back_forward_list_item         (WebKitWebView             *web_view,
+                                                      WebKitBackForwardListItem *list_item);
 WEBKIT_API const gchar *
-webkit_web_view_get_uri                            (WebKitWebView             *web_view);
+webkit_web_view_get_uri                              (WebKitWebView             *web_view);
 
 WEBKIT_API cairo_surface_t *
-webkit_web_view_get_favicon                        (WebKitWebView             *web_view);
+webkit_web_view_get_favicon                          (WebKitWebView             *web_view);
 
 WEBKIT_API const gchar *
-webkit_web_view_get_custom_charset                 (WebKitWebView             *web_view);
+webkit_web_view_get_custom_charset                   (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_set_custom_charset                 (WebKitWebView             *web_view,
-                                                    const gchar               *charset);
+webkit_web_view_set_custom_charset                   (WebKitWebView             *web_view,
+                                                      const gchar               *charset);
 
 WEBKIT_API void
-webkit_web_view_set_settings                       (WebKitWebView             *web_view,
-                                                    WebKitSettings            *settings);
+webkit_web_view_set_settings                         (WebKitWebView             *web_view,
+                                                      WebKitSettings            *settings);
 
 WEBKIT_API WebKitSettings *
-webkit_web_view_get_settings                       (WebKitWebView             *web_view);
+webkit_web_view_get_settings                         (WebKitWebView             *web_view);
 
 WEBKIT_API WebKitWindowProperties *
-webkit_web_view_get_window_properties              (WebKitWebView             *web_view);
+webkit_web_view_get_window_properties                (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_set_zoom_level                     (WebKitWebView             *web_view,
-                                                    gdouble                    zoom_level);
+webkit_web_view_set_zoom_level                       (WebKitWebView             *web_view,
+                                                      gdouble                    zoom_level);
 WEBKIT_API gdouble
-webkit_web_view_get_zoom_level                     (WebKitWebView             *web_view);
+webkit_web_view_get_zoom_level                       (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_can_execute_editing_command        (WebKitWebView             *web_view,
-                                                    const gchar               *command,
-                                                    GCancellable              *cancellable,
-                                                    GAsyncReadyCallback        callback,
-                                                    gpointer                   user_data);
+webkit_web_view_can_execute_editing_command          (WebKitWebView             *web_view,
+                                                      const gchar               *command,
+                                                      GCancellable              *cancellable,
+                                                      GAsyncReadyCallback        callback,
+                                                      gpointer                   user_data);
 
 WEBKIT_API gboolean
-webkit_web_view_can_execute_editing_command_finish (WebKitWebView             *web_view,
-                                                    GAsyncResult              *result,
-                                                    GError                   **error);
+webkit_web_view_can_execute_editing_command_finish   (WebKitWebView             *web_view,
+                                                      GAsyncResult              *result,
+                                                      GError                   **error);
 
 WEBKIT_API void
-webkit_web_view_execute_editing_command            (WebKitWebView             *web_view,
-                                                    const gchar               *command);
+webkit_web_view_execute_editing_command              (WebKitWebView             *web_view,
+                                                      const gchar               *command);
 
 WEBKIT_API WebKitFindController *
-webkit_web_view_get_find_controller                (WebKitWebView             *web_view);
+webkit_web_view_get_find_controller                  (WebKitWebView             *web_view);
 
 WEBKIT_API JSGlobalContextRef
-webkit_web_view_get_javascript_global_context      (WebKitWebView             *web_view);
+webkit_web_view_get_javascript_global_context        (WebKitWebView             *web_view);
 
 WEBKIT_API void
-webkit_web_view_run_javascript                     (WebKitWebView             *web_view,
-                                                    const gchar               *script,
-                                                    GCancellable              *cancellable,
-                                                    GAsyncReadyCallback        callback,
-                                                    gpointer                   user_data);
+webkit_web_view_run_javascript                       (WebKitWebView             *web_view,
+                                                      const gchar               *script,
+                                                      GCancellable              *cancellable,
+                                                      GAsyncReadyCallback        callback,
+                                                      gpointer                   user_data);
 WEBKIT_API WebKitJavascriptResult *
-webkit_web_view_run_javascript_finish              (WebKitWebView             *web_view,
-                                                    GAsyncResult              *result,
-                                                    GError                   **error);
+webkit_web_view_run_javascript_finish                (WebKitWebView             *web_view,
+                                                      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);
+webkit_web_view_get_main_resource                    (WebKitWebView             *web_view);
 
 WEBKIT_API GList *
-webkit_web_view_get_subresources                   (WebKitWebView             *web_view);
+webkit_web_view_get_subresources                     (WebKitWebView             *web_view);
 
 WEBKIT_API WebKitWebInspector *
-webkit_web_view_get_inspector                      (WebKitWebView             *web_view);
+webkit_web_view_get_inspector                        (WebKitWebView             *web_view);
 
 WEBKIT_API gboolean
-webkit_web_view_can_show_mime_type                 (WebKitWebView             *web_view,
-                                                    const gchar               *mime_type);
+webkit_web_view_can_show_mime_type                   (WebKitWebView             *web_view,
+                                                      const gchar               *mime_type);
 
 WEBKIT_API void
-webkit_web_view_save                               (WebKitWebView             *web_view,
-                                                    WebKitSaveMode             save_mode,
-                                                    GCancellable              *cancellable,
-                                                    GAsyncReadyCallback        callback,
-                                                    gpointer                   user_data);
+webkit_web_view_save                                 (WebKitWebView             *web_view,
+                                                      WebKitSaveMode             save_mode,
+                                                      GCancellable              *cancellable,
+                                                      GAsyncReadyCallback        callback,
+                                                      gpointer                   user_data);
 
 WEBKIT_API GInputStream *
-webkit_web_view_save_finish                        (WebKitWebView             *web_view,
-                                                    GAsyncResult              *result,
-                                                    GError                   **error);
+webkit_web_view_save_finish                          (WebKitWebView             *web_view,
+                                                      GAsyncResult              *result,
+                                                      GError                   **error);
 
 WEBKIT_API void
-webkit_web_view_save_to_file                       (WebKitWebView             *web_view,
-                                                    GFile                     *file,
-                                                    WebKitSaveMode             save_mode,
-                                                    GCancellable              *cancellable,
-                                                    GAsyncReadyCallback        callback,
-                                                    gpointer                   user_data);
+webkit_web_view_save_to_file                         (WebKitWebView             *web_view,
+                                                      GFile                     *file,
+                                                      WebKitSaveMode             save_mode,
+                                                      GCancellable              *cancellable,
+                                                      GAsyncReadyCallback        callback,
+                                                      gpointer                   user_data);
 
 WEBKIT_API gboolean
-webkit_web_view_save_to_file_finish                (WebKitWebView             *web_view,
-                                                    GAsyncResult              *result,
-                                                    GError                   **error);
+webkit_web_view_save_to_file_finish                  (WebKitWebView             *web_view,
+                                                      GAsyncResult              *result,
+                                                      GError                   **error);
 
 G_END_DECLS
 
index de32de3..f56267b 100644 (file)
@@ -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
index 8555af5..06ea1af 100644 (file)
@@ -30,6 +30,7 @@ endif
 webkit2_tests_cppflags = \
        -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs\" \
        -DWEBKIT_SRC_DIR=\"${shell pwd}/${srcdir}\" \
+       -DWEBKIT_DERIVED_SRC_DIR=\"${shell pwd}/${top_builddir}/DerivedSources\" \
        $(javascriptcore_cppflags) \
        -I$(srcdir)/Source/JavaScriptCore \
        -I$(srcdir)/Source \
@@ -56,6 +57,12 @@ webkit2_tests_ldflags = \
        -no-install \
        -no-fast-install
 
+DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource: Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies $(srcdir)/Source/WebKit2/UIProcess/API/gtk/tests/resources/webkit2gtk-tests.gresource.xml)
+       $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=$(srcdir) $<
+
+DISTCLEANFILES += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource
+noinst_DATA += DerivedSources/WebKit2/webkit2gtk-tests-resources.gresource
+
 noinst_LTLIBRARIES += Libraries/libWebKit2APITestCore.la
 Libraries_libWebKit2APITestCore_la_SOURCES = \
        Source/WebKit2/UIProcess/API/gtk/tests/LoadTrackingTest.cpp \
@@ -70,7 +77,9 @@ 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 \
+       Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js
 
 Programs_WebKit2APITests_TestWebKitWebContext_SOURCES = \
        Source/WebKit2/UIProcess/API/gtk/tests/TestWebKitWebContext.cpp
index 8622af1..9db47f8 100644 (file)
 void beforeAll();
 void afterAll();
 
+static void registerGResource(void)
+{
+    GOwnPtr<char> resourcesPath(g_build_filename(WEBKIT_DERIVED_SRC_DIR, "WebKit2", "webkit2gtk-tests-resources.gresource", NULL));
+    GResource* resource = g_resource_load(resourcesPath.get(), 0);
+    g_assert(resource);
+
+    g_resources_register(resource);
+    g_resource_unref(resource);
+}
+
 int main(int argc, char** argv)
 {
     gtk_test_init(&argc, &argv, 0);
     g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
     g_test_bug_base("https://bugs.webkit.org/");
 
+    registerGResource();
+
     beforeAll();
     int returnValue = g_test_run();
     afterAll();
index 02e8138..f5197b9 100644 (file)
@@ -643,6 +643,17 @@ static void testWebViewRunJavaScript(WebViewTest* test, gconstpointer)
     g_assert(!error.get());
     g_assert(WebViewTest::javascriptResultIsUndefined(javascriptResult));
 
+    javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/org/webkit/webkit2gtk/tests/link-title.js", &error.outPtr());
+    g_assert(javascriptResult);
+    g_assert(!error.get());
+    valueString.set(WebViewTest::javascriptResultToCString(javascriptResult));
+    g_assert_cmpstr(valueString.get(), ==, "WebKitGTK+ Title");
+
+    javascriptResult = test->runJavaScriptFromGResourceAndWaitUntilFinished("/wrong/path/to/resource.js", &error.outPtr());
+    g_assert(!javascriptResult);
+    g_assert_error(error.get(), G_RESOURCE_ERROR, G_RESOURCE_ERROR_NOT_FOUND);
+    error.clear();
+
     javascriptResult = test->runJavaScriptAndWaitUntilFinished("foo();", &error.outPtr());
     g_assert(!javascriptResult);
     g_assert_error(error.get(), WEBKIT_JAVASCRIPT_ERROR, WEBKIT_JAVASCRIPT_ERROR_SCRIPT_FAILED);
index 0474748..7e7eb01 100644 (file)
@@ -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);
index 25209ca..06f398f 100644 (file)
@@ -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/link-title.js b/Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js
new file mode 100644 (file)
index 0000000..2c824da
--- /dev/null
@@ -0,0 +1 @@
+window.document.getElementById('WebKitLink').title;
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 (file)
index 0000000..4f1e5a6
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+  <gresource prefix="/org/webkit/webkit2gtk/tests/">
+    <file alias="link-title.js">Source/WebKit2/UIProcess/API/gtk/tests/resources/link-title.js</file>
+  </gresource>
+</gresources>
index bcc0a8e..7dddfec 100644 (file)
@@ -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