[GTK] Provide convenience API in DOM bindings to post messages to user message handlers
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Nov 2014 12:46:15 +0000 (12:46 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 20 Nov 2014 12:46:15 +0000 (12:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=138871

Patch by Adrian Perez de Castro <aperez@igalia.com> on 2014-11-20
Reviewed by Carlos Garcia Campos.

Source/WebCore:

Adds a convenience function in the WebKitGTK+ DOM bindings to post
messages to user message handlers in a way convenient way more
convenient than using the autogenerated bindings.

* bindings/gobject/WebKitDOMCustom.cpp:
(webkit_dom_dom_window_webkit_message_handlers_post_message):
Added new convenience API function to post messages to user message
handlers.
* bindings/gobject/WebKitDOMCustom.h: Ditto.
* bindings/gobject/WebKitDOMCustom.symbols: Ditto.

Tools:

Add a test case for the convenience API for posting user messages
added to the DOM bindings.

* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp:
(testUserContentManagerMessageFromConvenienceDOMBindings):
(beforeAll):
* TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
(documentLoadedCallback):

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

Source/WebCore/ChangeLog
Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp
Source/WebCore/bindings/gobject/WebKitDOMCustom.h
Source/WebCore/bindings/gobject/WebKitDOMCustom.symbols
Source/WebCore/bindings/gobject/webkitdom.symbols
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp
Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp

index df41f0f..35a1ab8 100644 (file)
@@ -1,3 +1,21 @@
+2014-11-20  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK] Provide convenience API in DOM bindings to post messages to user message handlers
+        https://bugs.webkit.org/show_bug.cgi?id=138871
+
+        Reviewed by Carlos Garcia Campos.
+
+        Adds a convenience function in the WebKitGTK+ DOM bindings to post
+        messages to user message handlers in a way convenient way more
+        convenient than using the autogenerated bindings.
+
+        * bindings/gobject/WebKitDOMCustom.cpp:
+        (webkit_dom_dom_window_webkit_message_handlers_post_message):
+        Added new convenience API function to post messages to user message
+        handlers.
+        * bindings/gobject/WebKitDOMCustom.h: Ditto.
+        * bindings/gobject/WebKitDOMCustom.symbols: Ditto.
+
 2014-11-12  Sergio Villar Senin  <svillar@igalia.com>
 
         [CSS Grid Layout] Replace the usage of size_t by unsigned
index c77190d..cfdb132 100644 (file)
@@ -20,6 +20,7 @@
 #include "WebKitDOMCustom.h"
 
 #include "JSMainThreadExecState.h"
+#include "SerializedScriptValue.h"
 #include "WebKitDOMDOMWindowPrivate.h"
 #include "WebKitDOMHTMLInputElement.h"
 #include "WebKitDOMHTMLInputElementPrivate.h"
@@ -64,3 +65,25 @@ WebKitDOMUserMessageHandler* webkit_dom_user_message_handlers_namespace_get_hand
     return kit(core(handlersNamespace)->handler(String::fromUTF8(name), WebCore::mainThreadNormalWorld()));
 }
 
+gboolean webkit_dom_dom_window_webkit_message_handlers_post_message(WebKitDOMDOMWindow* window, const gchar* handlerName, const gchar* message)
+{
+    g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(window), FALSE);
+    g_return_val_if_fail(handlerName, FALSE);
+    g_return_val_if_fail(message, FALSE);
+
+    WebCore::DOMWindow* domWindow = core(window);
+    if (!domWindow->shouldHaveWebKitNamespaceForWorld(WebCore::mainThreadNormalWorld()))
+        return FALSE;
+
+    auto webkitNamespace = domWindow->webkitNamespace();
+    if (!webkitNamespace)
+        return FALSE;
+
+    auto handler = webkitNamespace->messageHandlers()->handler(String::fromUTF8(handlerName), WebCore::mainThreadNormalWorld());
+    if (!handler)
+        return FALSE;
+
+    WebCore::JSMainThreadNullState state;
+    handler->postMessage(WebCore::SerializedScriptValue::create(String::fromUTF8(message)));
+    return TRUE;
+}
index bd1563d..d3a05c3 100644 (file)
@@ -41,6 +41,18 @@ WEBKIT_API gboolean webkit_dom_html_text_area_element_is_edited(WebKitDOMHTMLTex
  */
 WEBKIT_API gboolean webkit_dom_html_input_element_is_edited(WebKitDOMHTMLInputElement* input);
 
+/**
+ * webkit_dom_dom_window_post_user_message:
+ * @window: A #WebKitDOMDOMWindow
+ * @handler: Name of the user message handler.
+ * @message: JavaScript value to be sent.
+ *
+ * Returns: Whether the message was successfully sent.
+ *
+ * Since: 2.8
+ */
+gboolean webkit_dom_dom_window_webkit_message_handlers_post_message(WebKitDOMDOMWindow* window, const gchar* handler, const gchar* message);
+
 G_END_DECLS
 
 #endif
index 286c175..bfdfa3e 100644 (file)
@@ -1,2 +1,3 @@
 gboolean webkit_dom_html_text_area_element_is_edited(WebKitDOMHTMLTextAreaElement*)
 gboolean webkit_dom_html_input_element_is_edited(WebKitDOMHTMLInputElement*)
+gboolean webkit_dom_dom_window_webkit_message_handlers_post_message(WebKitDOMDOMWindow*, const gchar*, const gchar*)
index 4da1619..d02c67a 100644 (file)
@@ -22,6 +22,7 @@ WebKitDOMDocument* webkit_dom_dom_implementation_create_document(WebKitDOMDOMImp
 WebKitDOMCSSStyleSheet* webkit_dom_dom_implementation_create_css_style_sheet(WebKitDOMDOMImplementation*, const gchar*, const gchar*, GError**)
 WebKitDOMHTMLDocument* webkit_dom_dom_implementation_create_html_document(WebKitDOMDOMImplementation*, const gchar*)
 GType webkit_dom_dom_window_get_type(void)
+gboolean webkit_dom_dom_window_webkit_message_handlers_post_message(WebKitDOMDOMWindow*, const gchar*, const gchar*)
 GType webkit_dom_document_get_type(void)
 WebKitDOMDocumentType* webkit_dom_document_get_doctype(WebKitDOMDocument*)
 WebKitDOMHTMLCollection* webkit_dom_document_get_images(WebKitDOMDocument*)
index e18b5a3..41c8adb 100644 (file)
@@ -1,3 +1,19 @@
+2014-11-20  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK] Provide convenience API in DOM bindings to post messages to user message handlers
+        https://bugs.webkit.org/show_bug.cgi?id=138871
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add a test case for the convenience API for posting user messages
+        added to the DOM bindings.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp:
+        (testUserContentManagerMessageFromConvenienceDOMBindings):
+        (beforeAll):
+        * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
+        (documentLoadedCallback):
+
 2014-11-19  Dana Burkart  <dburkart@apple.com>
 
         Work around the fact that different masters may have different names for their codebases.
index c240a5b..9f49d1d 100644 (file)
@@ -349,13 +349,23 @@ static void testUserContentManagerScriptMessageFromDOMBindings(UserScriptMessage
 {
     g_assert(test->registerHandler("dom"));
 
-    test->loadHtml("<html></html>", nullptr);
+    test->loadHtml("<html>1</html>", nullptr);
     WebKitJavascriptResult* javascriptResult = test->waitUntilMessageReceived("dom");
     g_assert(javascriptResult);
     GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
     g_assert_cmpstr(valueString.get(), ==, "DocumentLoaded");
 
     test->unregisterHandler("dom");
+
+    g_assert(test->registerHandler("dom-convenience"));
+
+    test->loadHtml("<html>2</html>", nullptr);
+    javascriptResult = test->waitUntilMessageReceived("dom-convenience");
+    g_assert(javascriptResult);
+    valueString.reset(WebViewTest::javascriptResultToCString(javascriptResult));
+    g_assert_cmpstr(valueString.get(), ==, "DocumentLoaded");
+
+    test->unregisterHandler("dom-convenience");
 }
 
 static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
index 54b5438..fd09596 100644 (file)
@@ -109,6 +109,7 @@ static void documentLoadedCallback(WebKitWebPage* webPage, WebKitWebExtension* e
             webkit_dom_user_message_handler_post_message(handler, "DocumentLoaded");
     }
 
+    webkit_dom_dom_window_webkit_message_handlers_post_message(window, "dom-convenience", "DocumentLoaded");
 
     gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
     if (data)