Diff
Modified: trunk/Source/WebCore/ChangeLog (176017 => 176018)
--- 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)
@@ -1,5 +1,24 @@
2014-11-12 Carlos Garcia Campos <[email protected]>
+ [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 <[email protected]>
+
[GTK] Fix how SerializedScriptValue is exposed to GObject DOM bindings
https://bugs.webkit.org/show_bug.cgi?id=138409
Modified: trunk/Source/WebCore/PlatformGTK.cmake (176017 => 176018)
--- 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)
@@ -635,7 +635,10 @@
page/PerformanceNavigation.idl
page/PerformanceTiming.idl
page/Screen.idl
+ page/UserMessageHandler.idl
+ page/UserMessageHandlersNamespace.idl
page/WebKitPoint.idl
+ page/WebKitNamespace.idl
plugins/DOMMimeType.idl
plugins/DOMMimeTypeArray.idl
@@ -692,6 +695,7 @@
set(GObjectDOMBindingsUnstable_INSTALLED_HEADERS
${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines-unstable.h
+ ${WEBCORE_DIR}/bindings/gobject/WebKitDOMCustomUnstable.h
)
foreach (file ${GObjectDOMBindingsStable_IDL_FILES})
@@ -733,7 +737,8 @@
# Some of the static headers are included by generated public headers with include <webkitdom/WebKitDOMFoo.h>.
# We need those headers in the derived sources to be in webkitdom directory.
-foreach (classname ${GObjectDOMBindings_STATIC_CLASS_LIST})
+set(GObjectDOMBindings_STATIC_HEADER_NAMES ${GObjectDOMBindings_STATIC_CLASS_LIST} CustomUnstable)
+foreach (classname ${GObjectDOMBindings_STATIC_HEADER_NAMES})
add_custom_command(
OUTPUT ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/WebKitDOM${classname}.h
DEPENDS ${WEBCORE_DIR}/bindings/gobject/WebKitDOM${classname}.h
Modified: trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp (176017 => 176018)
--- 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)
@@ -20,19 +20,16 @@
#include "WebKitDOMCustom.h"
#include "JSMainThreadExecState.h"
+#include "WebKitDOMDOMWindowPrivate.h"
#include "WebKitDOMHTMLInputElement.h"
#include "WebKitDOMHTMLInputElementPrivate.h"
-#include "WebKitDOMHTMLMediaElementPrivate.h"
#include "WebKitDOMHTMLTextAreaElement.h"
#include "WebKitDOMHTMLTextAreaElementPrivate.h"
#include "WebKitDOMPrivate.h"
-#include "gobject/ConvertToUTF8String.h"
+#include "WebKitDOMUserMessageHandlerPrivate.h"
+#include "WebKitDOMUserMessageHandlersNamespacePrivate.h"
+#include "WebKitDOMWebKitNamespacePrivate.h"
-#if ENABLE(VIDEO)
-#include "TextTrack.h"
-#include "WebKitDOMTextTrackPrivate.h"
-#endif
-
using namespace WebKit;
gboolean webkit_dom_html_text_area_element_is_edited(WebKitDOMHTMLTextAreaElement* area)
@@ -49,4 +46,21 @@
return core(input)->lastChangeWasUserEdit();
}
+WebKitDOMWebKitNamespace* webkit_dom_dom_window_get_webkit_namespace(WebKitDOMDOMWindow* window)
+{
+ g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(window), nullptr);
+ 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()));
+}
+
Added: trunk/Source/WebCore/bindings/gobject/WebKitDOMCustomUnstable.h (0 => 176018)
--- 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)
@@ -0,0 +1,57 @@
+/*
+ * 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
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm (176017 => 176018)
--- 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)
@@ -1580,6 +1580,12 @@
$object->GenerateEndHeader();
}
+sub HasUnstableCustomAPI {
+ my $domClassName = shift;
+
+ return scalar(grep {$_ eq $domClassName} qw(WebKitDOMDOMWindow WebKitDOMUserMessageHandlersNamespace));
+}
+
sub WriteData {
my $object = shift;
my $interface = shift;
@@ -1647,6 +1653,9 @@
if ($isStableClass) {
print HEADER "#include <webkitdom/webkitdomdefines.h>\n\n";
} else {
+ if (HasUnstableCustomAPI($className)) {
+ print HEADER "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
+ }
print HEADER "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
}
print HEADER @hBodyPre;
@@ -1670,11 +1679,13 @@
#ifdef WEBKIT_DOM_USE_UNSTABLE_API
-#include <webkitdom/webkitdomdefines-unstable.h>
EOF
+ print UNSTABLE $text;
+ if (HasUnstableCustomAPI($className)) {
+ print UNSTABLE "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
+ }
+ print UNSTABLE "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
- print UNSTABLE $text;
- print UNSTABLE "\n";
print UNSTABLE "#if ${conditionalString}\n\n" if $conditionalString;
print UNSTABLE "G_BEGIN_DECLS\n";
print UNSTABLE "\n";
Modified: trunk/Tools/ChangeLog (176017 => 176018)
--- trunk/Tools/ChangeLog 2014-11-12 12:26:26 UTC (rev 176017)
+++ trunk/Tools/ChangeLog 2014-11-12 12:30:38 UTC (rev 176018)
@@ -1,5 +1,23 @@
2014-11-12 Carlos Garcia Campos <[email protected]>
+ [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 <[email protected]>
+
Unreviewed. Fix GTK+ clean build after r175930.
Partial rollout of r175930 to not build the new unit test that
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp (176017 => 176018)
--- 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)
@@ -248,7 +248,7 @@
test->m_userScriptMessage = webkit_javascript_result_ref(jsResult);
}
- WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* _javascript_ValueAsText)
+ WebKitJavascriptResult* waitUntilMessageReceived(const char* handlerName)
{
if (m_userScriptMessage) {
webkit_javascript_result_unref(m_userScriptMessage);
@@ -258,14 +258,18 @@
GUniquePtr<char> signalName(g_strdup_printf("script-message-received::%s", handlerName));
g_signal_connect(m_userContentManager.get(), signalName.get(), G_CALLBACK(scriptMessageReceived), this);
- GUniquePtr<char> _javascript_Snippet(g_strdup_printf("window.webkit.messageHandlers.%s.postMessage(%s);", handlerName, _javascript_ValueAsText));
- webkit_web_view_run_javascript(m_webView, _javascript_Snippet.get(), nullptr, nullptr, nullptr);
g_main_loop_run(m_mainLoop);
-
g_assert(m_userScriptMessage);
return m_userScriptMessage;
}
+ WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* _javascript_ValueAsText)
+ {
+ GUniquePtr<char> _javascript_Snippet(g_strdup_printf("window.webkit.messageHandlers.%s.postMessage(%s);", handlerName, _javascript_ValueAsText));
+ webkit_web_view_run_javascript(m_webView, _javascript_Snippet.get(), nullptr, nullptr, nullptr);
+ return waitUntilMessageReceived(handlerName);
+ }
+
private:
WebKitJavascriptResult* m_userScriptMessage;
};
@@ -341,6 +345,19 @@
test->unregisterHandler("anotherHandler");
}
+static void testUserContentManagerScriptMessageFromDOMBindings(UserScriptMessageTest* test, gconstpointer)
+{
+ g_assert(test->registerHandler("dom"));
+
+ test->loadHtml("<html></html>", nullptr);
+ WebKitJavascriptResult* _javascript_Result = test->waitUntilMessageReceived("dom");
+ g_assert(_javascript_Result);
+ GUniquePtr<char> valueString(WebViewTest::_javascript_ResultToCString(_javascript_Result));
+ g_assert_cmpstr(valueString.get(), ==, "DocumentLoaded");
+
+ test->unregisterHandler("dom");
+}
+
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
{
soup_message_set_status(message, SOUP_STATUS_OK);
@@ -350,6 +367,7 @@
void beforeAll()
{
+ webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
kServer = new WebKitTestServer();
kServer->run(serverCallback);
@@ -357,6 +375,7 @@
UserContentManagerTest::add("WebKitUserContentManager", "injected-style-sheet", testUserContentManagerInjectedStyleSheet);
UserContentManagerTest::add("WebKitUserContentManager", "injected-script", testUserContentManagerInjectedScript);
UserScriptMessageTest::add("WebKitUserContentManager", "script-message-received", testUserContentManagerScriptMessageReceived);
+ UserScriptMessageTest::add("WebKitUserContentManager", "script-message-from-dom-bindings", testUserContentManagerScriptMessageFromDOMBindings);
}
void afterAll()
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp (176017 => 176018)
--- 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)
@@ -33,6 +33,11 @@
#include <wtf/gobject/GUniquePtr.h>
#include <wtf/text/CString.h>
+#define WEBKIT_DOM_USE_UNSTABLE_API
+#include <webkitdom/WebKitDOMWebKitNamespace.h>
+#include <webkitdom/WebKitDOMUserMessageHandlersNamespace.h>
+#include <webkitdom/WebKitDOMUserMessageHandler.h>
+
static const char introspectionXML[] =
"<node>"
" <interface name='org.webkit.gtk.WebExtensionTest'>"
@@ -98,8 +103,18 @@
g_assert(ok);
}
-static void documentLoadedCallback(WebKitWebPage*, WebKitWebExtension* extension)
+static void documentLoadedCallback(WebKitWebPage* webPage, WebKitWebExtension* extension)
{
+ // 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");
+ }
+
+
gpointer data = "" "dbus-connection");
if (data)
emitDocumentLoaded(G_DBUS_CONNECTION(data));