<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[176018] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/176018">176018</a></dd>
<dt>Author</dt> <dd>carlosgc@webkit.org</dd>
<dt>Date</dt> <dd>2014-11-12 04:30:38 -0800 (Wed, 12 Nov 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>[GTK] Expose user script messages to GObject DOM bindings
https://bugs.webkit.org/show_bug.cgi?id=138411
Reviewed by Philippe Normand.
Source/WebCore:
* PlatformGTK.cmake: Add WebKitDOMCustomUnstable.h to the list of
installed headers and make a symlink for it in the DerivedSources dir.
* bindings/gobject/WebKitDOMCustomUnstable.h: Added.
* bindings/gobject/WebKitDOMCustom.cpp:
(webkit_dom_dom_window_get_webkit_namespace):
(webkit_dom_user_message_handlers_namespace_get_handler):
* bindings/scripts/CodeGeneratorGObject.pm:
(HasUnstableCustomAPI): Helper function to check if the given
class has custom unstable API.
(WriteData): Include WebKitDOMCustomUnstable.h header if the class
has API defined there.
Tools:
Add a test case to check that user script messages sent using the
DOM bindings API are also received in the UI process.
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp:
(UserScriptMessageTest::waitUntilMessageReceived):
(UserScriptMessageTest::postMessageAndWaitUntilReceived):
(testUserContentManagerScriptMessageFromDOMBindings):
(beforeAll):
* TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
(documentLoadedCallback):</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorePlatformGTKcmake">trunk/Source/WebCore/PlatformGTK.cmake</a></li>
<li><a href="#trunkSourceWebCorebindingsgobjectWebKitDOMCustomcpp">trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp</a></li>
<li><a href="#trunkSourceWebCorebindingsscriptsCodeGeneratorGObjectpm">trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitUserContentManagercpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWebKit2GtkWebExtensionTestcpp">trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorebindingsgobjectWebKitDOMCustomUnstableh">trunk/Source/WebCore/bindings/gobject/WebKitDOMCustomUnstable.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Source/WebCore/ChangeLog        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -1,5 +1,24 @@
</span><span class="cx"> 2014-11-12 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><ins>+ [GTK] Expose user script messages to GObject DOM bindings
+ https://bugs.webkit.org/show_bug.cgi?id=138411
+
+ Reviewed by Philippe Normand.
+
+ * PlatformGTK.cmake: Add WebKitDOMCustomUnstable.h to the list of
+ installed headers and make a symlink for it in the DerivedSources dir.
+ * bindings/gobject/WebKitDOMCustomUnstable.h: Added.
+ * bindings/gobject/WebKitDOMCustom.cpp:
+ (webkit_dom_dom_window_get_webkit_namespace):
+ (webkit_dom_user_message_handlers_namespace_get_handler):
+ * bindings/scripts/CodeGeneratorGObject.pm:
+ (HasUnstableCustomAPI): Helper function to check if the given
+ class has custom unstable API.
+ (WriteData): Include WebKitDOMCustomUnstable.h header if the class
+ has API defined there.
+
+2014-11-12 Carlos Garcia Campos <cgarcia@igalia.com>
+
</ins><span class="cx"> [GTK] Fix how SerializedScriptValue is exposed to GObject DOM bindings
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=138409
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCorePlatformGTKcmake"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/PlatformGTK.cmake (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/PlatformGTK.cmake        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Source/WebCore/PlatformGTK.cmake        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -635,7 +635,10 @@
</span><span class="cx"> page/PerformanceNavigation.idl
</span><span class="cx"> page/PerformanceTiming.idl
</span><span class="cx"> page/Screen.idl
</span><ins>+ page/UserMessageHandler.idl
+ page/UserMessageHandlersNamespace.idl
</ins><span class="cx"> page/WebKitPoint.idl
</span><ins>+ page/WebKitNamespace.idl
</ins><span class="cx">
</span><span class="cx"> plugins/DOMMimeType.idl
</span><span class="cx"> plugins/DOMMimeTypeArray.idl
</span><span class="lines">@@ -692,6 +695,7 @@
</span><span class="cx">
</span><span class="cx"> set(GObjectDOMBindingsUnstable_INSTALLED_HEADERS
</span><span class="cx"> ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines-unstable.h
</span><ins>+ ${WEBCORE_DIR}/bindings/gobject/WebKitDOMCustomUnstable.h
</ins><span class="cx"> )
</span><span class="cx">
</span><span class="cx"> foreach (file ${GObjectDOMBindingsStable_IDL_FILES})
</span><span class="lines">@@ -733,7 +737,8 @@
</span><span class="cx">
</span><span class="cx"> # Some of the static headers are included by generated public headers with include <webkitdom/WebKitDOMFoo.h>.
</span><span class="cx"> # We need those headers in the derived sources to be in webkitdom directory.
</span><del>-foreach (classname ${GObjectDOMBindings_STATIC_CLASS_LIST})
</del><ins>+set(GObjectDOMBindings_STATIC_HEADER_NAMES ${GObjectDOMBindings_STATIC_CLASS_LIST} CustomUnstable)
+foreach (classname ${GObjectDOMBindings_STATIC_HEADER_NAMES})
</ins><span class="cx"> add_custom_command(
</span><span class="cx"> OUTPUT ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/WebKitDOM${classname}.h
</span><span class="cx"> DEPENDS ${WEBCORE_DIR}/bindings/gobject/WebKitDOM${classname}.h
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsgobjectWebKitDOMCustomcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -20,19 +20,16 @@
</span><span class="cx"> #include "WebKitDOMCustom.h"
</span><span class="cx">
</span><span class="cx"> #include "JSMainThreadExecState.h"
</span><ins>+#include "WebKitDOMDOMWindowPrivate.h"
</ins><span class="cx"> #include "WebKitDOMHTMLInputElement.h"
</span><span class="cx"> #include "WebKitDOMHTMLInputElementPrivate.h"
</span><del>-#include "WebKitDOMHTMLMediaElementPrivate.h"
</del><span class="cx"> #include "WebKitDOMHTMLTextAreaElement.h"
</span><span class="cx"> #include "WebKitDOMHTMLTextAreaElementPrivate.h"
</span><span class="cx"> #include "WebKitDOMPrivate.h"
</span><del>-#include "gobject/ConvertToUTF8String.h"
</del><ins>+#include "WebKitDOMUserMessageHandlerPrivate.h"
+#include "WebKitDOMUserMessageHandlersNamespacePrivate.h"
+#include "WebKitDOMWebKitNamespacePrivate.h"
</ins><span class="cx">
</span><del>-#if ENABLE(VIDEO)
-#include "TextTrack.h"
-#include "WebKitDOMTextTrackPrivate.h"
-#endif
-
</del><span class="cx"> using namespace WebKit;
</span><span class="cx">
</span><span class="cx"> gboolean webkit_dom_html_text_area_element_is_edited(WebKitDOMHTMLTextAreaElement* area)
</span><span class="lines">@@ -49,4 +46,21 @@
</span><span class="cx"> return core(input)->lastChangeWasUserEdit();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+WebKitDOMWebKitNamespace* webkit_dom_dom_window_get_webkit_namespace(WebKitDOMDOMWindow* window)
+{
+ g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(window), nullptr);
</ins><span class="cx">
</span><ins>+ WebCore::DOMWindow* domWindow = core(window);
+ if (!domWindow->shouldHaveWebKitNamespaceForWorld(WebCore::mainThreadNormalWorld()))
+ return nullptr;
+ return kit(domWindow->webkitNamespace());
+}
+
+WebKitDOMUserMessageHandler* webkit_dom_user_message_handlers_namespace_get_handler(WebKitDOMUserMessageHandlersNamespace* handlersNamespace, const gchar* name)
+{
+ g_return_val_if_fail(WEBKIT_DOM_IS_USER_MESSAGE_HANDLERS_NAMESPACE(handlersNamespace), nullptr);
+ g_return_val_if_fail(name, nullptr);
+
+ return kit(core(handlersNamespace)->handler(String::fromUTF8(name), WebCore::mainThreadNormalWorld()));
+}
+
</ins></span></pre></div>
<a id="trunkSourceWebCorebindingsgobjectWebKitDOMCustomUnstableh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/bindings/gobject/WebKitDOMCustomUnstable.h (0 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/gobject/WebKitDOMCustomUnstable.h         (rev 0)
+++ trunk/Source/WebCore/bindings/gobject/WebKitDOMCustomUnstable.h        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -0,0 +1,57 @@
</span><ins>+/*
+ * Copyright (C) 2014 Igalia S.L.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef WebKitDOMCustomUnstable_h
+#define WebKitDOMCustomUnstable_h
+
+#ifdef WEBKIT_DOM_USE_UNSTABLE_API
+
+#include <webkitdom/webkitdomdefines-unstable.h>
+
+G_BEGIN_DECLS
+
+/**
+ * webkit_dom_dom_window_get_webkit_namespace:
+ * @self: A #WebKitDOMDOMWindow
+ *
+ * Returns: (transfer none): A #WebKitDOMWebKitNamespace
+ *
+ * Stability: Unstable
+ * Since: 2.8
+ */
+WEBKIT_API WebKitDOMWebKitNamespace *
+webkit_dom_dom_window_get_webkit_namespace(WebKitDOMDOMWindow* self);
+
+/**
+ * webkit_dom_user_message_handlers_namespace_get_handler:
+ * @self: A #WebKitDOMUserMessageHandlersNamespace
+ * @name: a #gchar
+ *
+ * Returns: (transfer none): A #WebKitDOMUserMessageHandler
+ *
+ * Stability: Unstable
+ * Since: 2.8
+ */
+WEBKIT_API WebKitDOMUserMessageHandler *
+webkit_dom_user_message_handlers_namespace_get_handler(WebKitDOMUserMessageHandlersNamespace* self, const gchar* name);
+
+G_END_DECLS
+
+#endif /* WEBKIT_DOM_USE_UNSTABLE_API */
+
+#endif
</ins></span></pre></div>
<a id="trunkSourceWebCorebindingsscriptsCodeGeneratorGObjectpm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -1580,6 +1580,12 @@
</span><span class="cx"> $object->GenerateEndHeader();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+sub HasUnstableCustomAPI {
+ my $domClassName = shift;
+
+ return scalar(grep {$_ eq $domClassName} qw(WebKitDOMDOMWindow WebKitDOMUserMessageHandlersNamespace));
+}
+
</ins><span class="cx"> sub WriteData {
</span><span class="cx"> my $object = shift;
</span><span class="cx"> my $interface = shift;
</span><span class="lines">@@ -1647,6 +1653,9 @@
</span><span class="cx"> if ($isStableClass) {
</span><span class="cx"> print HEADER "#include <webkitdom/webkitdomdefines.h>\n\n";
</span><span class="cx"> } else {
</span><ins>+ if (HasUnstableCustomAPI($className)) {
+ print HEADER "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
+ }
</ins><span class="cx"> print HEADER "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
</span><span class="cx"> }
</span><span class="cx"> print HEADER @hBodyPre;
</span><span class="lines">@@ -1670,11 +1679,13 @@
</span><span class="cx">
</span><span class="cx"> #ifdef WEBKIT_DOM_USE_UNSTABLE_API
</span><span class="cx">
</span><del>-#include <webkitdom/webkitdomdefines-unstable.h>
</del><span class="cx"> EOF
</span><ins>+ print UNSTABLE $text;
+ if (HasUnstableCustomAPI($className)) {
+ print UNSTABLE "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
+ }
+ print UNSTABLE "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
</ins><span class="cx">
</span><del>- print UNSTABLE $text;
- print UNSTABLE "\n";
</del><span class="cx"> print UNSTABLE "#if ${conditionalString}\n\n" if $conditionalString;
</span><span class="cx"> print UNSTABLE "G_BEGIN_DECLS\n";
</span><span class="cx"> print UNSTABLE "\n";
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Tools/ChangeLog        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -1,5 +1,23 @@
</span><span class="cx"> 2014-11-12 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><ins>+ [GTK] Expose user script messages to GObject DOM bindings
+ https://bugs.webkit.org/show_bug.cgi?id=138411
+
+ Reviewed by Philippe Normand.
+
+ Add a test case to check that user script messages sent using the
+ DOM bindings API are also received in the UI process.
+
+ * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp:
+ (UserScriptMessageTest::waitUntilMessageReceived):
+ (UserScriptMessageTest::postMessageAndWaitUntilReceived):
+ (testUserContentManagerScriptMessageFromDOMBindings):
+ (beforeAll):
+ * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
+ (documentLoadedCallback):
+
+2014-11-12 Carlos Garcia Campos <cgarcia@igalia.com>
+
</ins><span class="cx"> Unreviewed. Fix GTK+ clean build after r175930.
</span><span class="cx">
</span><span class="cx"> Partial rollout of r175930 to not build the new unit test that
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkTestWebKitUserContentManagercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -248,7 +248,7 @@
</span><span class="cx"> test->m_userScriptMessage = webkit_javascript_result_ref(jsResult);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* javascriptValueAsText)
</del><ins>+ WebKitJavascriptResult* waitUntilMessageReceived(const char* handlerName)
</ins><span class="cx"> {
</span><span class="cx"> if (m_userScriptMessage) {
</span><span class="cx"> webkit_javascript_result_unref(m_userScriptMessage);
</span><span class="lines">@@ -258,14 +258,18 @@
</span><span class="cx"> GUniquePtr<char> signalName(g_strdup_printf("script-message-received::%s", handlerName));
</span><span class="cx"> g_signal_connect(m_userContentManager.get(), signalName.get(), G_CALLBACK(scriptMessageReceived), this);
</span><span class="cx">
</span><del>- GUniquePtr<char> javascriptSnippet(g_strdup_printf("window.webkit.messageHandlers.%s.postMessage(%s);", handlerName, javascriptValueAsText));
- webkit_web_view_run_javascript(m_webView, javascriptSnippet.get(), nullptr, nullptr, nullptr);
</del><span class="cx"> g_main_loop_run(m_mainLoop);
</span><del>-
</del><span class="cx"> g_assert(m_userScriptMessage);
</span><span class="cx"> return m_userScriptMessage;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* javascriptValueAsText)
+ {
+ GUniquePtr<char> javascriptSnippet(g_strdup_printf("window.webkit.messageHandlers.%s.postMessage(%s);", handlerName, javascriptValueAsText));
+ webkit_web_view_run_javascript(m_webView, javascriptSnippet.get(), nullptr, nullptr, nullptr);
+ return waitUntilMessageReceived(handlerName);
+ }
+
</ins><span class="cx"> private:
</span><span class="cx"> WebKitJavascriptResult* m_userScriptMessage;
</span><span class="cx"> };
</span><span class="lines">@@ -341,6 +345,19 @@
</span><span class="cx"> test->unregisterHandler("anotherHandler");
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static void testUserContentManagerScriptMessageFromDOMBindings(UserScriptMessageTest* test, gconstpointer)
+{
+ g_assert(test->registerHandler("dom"));
+
+ test->loadHtml("<html></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");
+}
+
</ins><span class="cx"> static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
</span><span class="cx"> {
</span><span class="cx"> soup_message_set_status(message, SOUP_STATUS_OK);
</span><span class="lines">@@ -350,6 +367,7 @@
</span><span class="cx">
</span><span class="cx"> void beforeAll()
</span><span class="cx"> {
</span><ins>+ webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
</ins><span class="cx"> kServer = new WebKitTestServer();
</span><span class="cx"> kServer->run(serverCallback);
</span><span class="cx">
</span><span class="lines">@@ -357,6 +375,7 @@
</span><span class="cx"> UserContentManagerTest::add("WebKitUserContentManager", "injected-style-sheet", testUserContentManagerInjectedStyleSheet);
</span><span class="cx"> UserContentManagerTest::add("WebKitUserContentManager", "injected-script", testUserContentManagerInjectedScript);
</span><span class="cx"> UserScriptMessageTest::add("WebKitUserContentManager", "script-message-received", testUserContentManagerScriptMessageReceived);
</span><ins>+ UserScriptMessageTest::add("WebKitUserContentManager", "script-message-from-dom-bindings", testUserContentManagerScriptMessageFromDOMBindings);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void afterAll()
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebKit2GtkWebExtensionTestcpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp (176017 => 176018)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp        2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp        2014-11-12 12:30:38 UTC (rev 176018)
</span><span class="lines">@@ -33,6 +33,11 @@
</span><span class="cx"> #include <wtf/gobject/GUniquePtr.h>
</span><span class="cx"> #include <wtf/text/CString.h>
</span><span class="cx">
</span><ins>+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMWebKitNamespace.h>
+#include <webkitdom/WebKitDOMUserMessageHandlersNamespace.h>
+#include <webkitdom/WebKitDOMUserMessageHandler.h>
+
</ins><span class="cx"> static const char introspectionXML[] =
</span><span class="cx"> "<node>"
</span><span class="cx"> " <interface name='org.webkit.gtk.WebExtensionTest'>"
</span><span class="lines">@@ -98,8 +103,18 @@
</span><span class="cx"> g_assert(ok);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static void documentLoadedCallback(WebKitWebPage*, WebKitWebExtension* extension)
</del><ins>+static void documentLoadedCallback(WebKitWebPage* webPage, WebKitWebExtension* extension)
</ins><span class="cx"> {
</span><ins>+ // FIXME: Too much code just to send a message, we need convenient custom API for this.
+ WebKitDOMDocument* document = webkit_web_page_get_dom_document(webPage);
+ WebKitDOMDOMWindow* window = webkit_dom_document_get_default_view(document);
+ if (WebKitDOMWebKitNamespace* webkit = webkit_dom_dom_window_get_webkit_namespace(window)) {
+ WebKitDOMUserMessageHandlersNamespace* messageHandlers = webkit_dom_webkit_namespace_get_message_handlers(webkit);
+ if (WebKitDOMUserMessageHandler* handler = webkit_dom_user_message_handlers_namespace_get_handler(messageHandlers, "dom"))
+ webkit_dom_user_message_handler_post_message(handler, "DocumentLoaded");
+ }
+
+
</ins><span class="cx"> gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
</span><span class="cx"> if (data)
</span><span class="cx"> emitDocumentLoaded(G_DBUS_CONNECTION(data));
</span></span></pre>
</div>
</div>
</body>
</html>