Changeset 176018 in webkit


Ignore:
Timestamp:
Nov 12, 2014 4:30:38 AM (9 years ago)
Author:
Carlos Garcia Campos
Message:

[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):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r176017 r176018  
     12014-11-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Expose user script messages to GObject DOM bindings
     4        https://bugs.webkit.org/show_bug.cgi?id=138411
     5
     6        Reviewed by Philippe Normand.
     7
     8        * PlatformGTK.cmake: Add WebKitDOMCustomUnstable.h to the list of
     9        installed headers and make a symlink for it in the DerivedSources dir.
     10        * bindings/gobject/WebKitDOMCustomUnstable.h: Added.
     11        * bindings/gobject/WebKitDOMCustom.cpp:
     12        (webkit_dom_dom_window_get_webkit_namespace):
     13        (webkit_dom_user_message_handlers_namespace_get_handler):
     14        * bindings/scripts/CodeGeneratorGObject.pm:
     15        (HasUnstableCustomAPI): Helper function to check if the given
     16        class has custom unstable API.
     17        (WriteData): Include WebKitDOMCustomUnstable.h header if the class
     18        has API defined there.
     19
    1202014-11-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    221
  • trunk/Source/WebCore/PlatformGTK.cmake

    r176016 r176018  
    636636    page/PerformanceTiming.idl
    637637    page/Screen.idl
     638    page/UserMessageHandler.idl
     639    page/UserMessageHandlersNamespace.idl
    638640    page/WebKitPoint.idl
     641    page/WebKitNamespace.idl
    639642
    640643    plugins/DOMMimeType.idl
     
    693696set(GObjectDOMBindingsUnstable_INSTALLED_HEADERS
    694697     ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/webkitdomdefines-unstable.h
     698     ${WEBCORE_DIR}/bindings/gobject/WebKitDOMCustomUnstable.h
    695699)
    696700
     
    734738# Some of the static headers are included by generated public headers with include <webkitdom/WebKitDOMFoo.h>.
    735739# We need those headers in the derived sources to be in webkitdom directory.
    736 foreach (classname ${GObjectDOMBindings_STATIC_CLASS_LIST})
     740set(GObjectDOMBindings_STATIC_HEADER_NAMES ${GObjectDOMBindings_STATIC_CLASS_LIST} CustomUnstable)
     741foreach (classname ${GObjectDOMBindings_STATIC_HEADER_NAMES})
    737742    add_custom_command(
    738743        OUTPUT ${DERIVED_SOURCES_GOBJECT_DOM_BINDINGS_DIR}/WebKitDOM${classname}.h
  • trunk/Source/WebCore/bindings/gobject/WebKitDOMCustom.cpp

    r170173 r176018  
    2121
    2222#include "JSMainThreadExecState.h"
     23#include "WebKitDOMDOMWindowPrivate.h"
    2324#include "WebKitDOMHTMLInputElement.h"
    2425#include "WebKitDOMHTMLInputElementPrivate.h"
    25 #include "WebKitDOMHTMLMediaElementPrivate.h"
    2626#include "WebKitDOMHTMLTextAreaElement.h"
    2727#include "WebKitDOMHTMLTextAreaElementPrivate.h"
    2828#include "WebKitDOMPrivate.h"
    29 #include "gobject/ConvertToUTF8String.h"
    30 
    31 #if ENABLE(VIDEO)
    32 #include "TextTrack.h"
    33 #include "WebKitDOMTextTrackPrivate.h"
    34 #endif
     29#include "WebKitDOMUserMessageHandlerPrivate.h"
     30#include "WebKitDOMUserMessageHandlersNamespacePrivate.h"
     31#include "WebKitDOMWebKitNamespacePrivate.h"
    3532
    3633using namespace WebKit;
     
    5047}
    5148
     49WebKitDOMWebKitNamespace* webkit_dom_dom_window_get_webkit_namespace(WebKitDOMDOMWindow* window)
     50{
     51    g_return_val_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(window), nullptr);
    5252
     53    WebCore::DOMWindow* domWindow = core(window);
     54    if (!domWindow->shouldHaveWebKitNamespaceForWorld(WebCore::mainThreadNormalWorld()))
     55        return nullptr;
     56    return kit(domWindow->webkitNamespace());
     57}
     58
     59WebKitDOMUserMessageHandler* webkit_dom_user_message_handlers_namespace_get_handler(WebKitDOMUserMessageHandlersNamespace* handlersNamespace, const gchar* name)
     60{
     61    g_return_val_if_fail(WEBKIT_DOM_IS_USER_MESSAGE_HANDLERS_NAMESPACE(handlersNamespace), nullptr);
     62    g_return_val_if_fail(name, nullptr);
     63
     64    return kit(core(handlersNamespace)->handler(String::fromUTF8(name), WebCore::mainThreadNormalWorld()));
     65}
     66
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorGObject.pm

    r176017 r176018  
    15811581}
    15821582
     1583sub HasUnstableCustomAPI {
     1584    my $domClassName = shift;
     1585
     1586    return scalar(grep {$_ eq $domClassName} qw(WebKitDOMDOMWindow WebKitDOMUserMessageHandlersNamespace));
     1587}
     1588
    15831589sub WriteData {
    15841590    my $object = shift;
     
    16481654        print HEADER "#include <webkitdom/webkitdomdefines.h>\n\n";
    16491655    } else {
     1656        if (HasUnstableCustomAPI($className)) {
     1657            print HEADER "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
     1658        }
    16501659        print HEADER "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
    16511660    }
     
    16711680#ifdef WEBKIT_DOM_USE_UNSTABLE_API
    16721681
    1673 #include <webkitdom/webkitdomdefines-unstable.h>
    1674 EOF
    1675 
     1682EOF
    16761683        print UNSTABLE $text;
    1677         print UNSTABLE "\n";
     1684        if (HasUnstableCustomAPI($className)) {
     1685            print UNSTABLE "#include <webkitdom/WebKitDOMCustomUnstable.h>\n";
     1686        }
     1687        print UNSTABLE "#include <webkitdom/webkitdomdefines-unstable.h>\n\n";
     1688
    16781689        print UNSTABLE "#if ${conditionalString}\n\n" if $conditionalString;
    16791690        print UNSTABLE "G_BEGIN_DECLS\n";
  • trunk/Tools/ChangeLog

    r176015 r176018  
     12014-11-12  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Expose user script messages to GObject DOM bindings
     4        https://bugs.webkit.org/show_bug.cgi?id=138411
     5
     6        Reviewed by Philippe Normand.
     7
     8        Add a test case to check that user script messages sent using the
     9        DOM bindings API are also received in the UI process.
     10
     11        * TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp:
     12        (UserScriptMessageTest::waitUntilMessageReceived):
     13        (UserScriptMessageTest::postMessageAndWaitUntilReceived):
     14        (testUserContentManagerScriptMessageFromDOMBindings):
     15        (beforeAll):
     16        * TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp:
     17        (documentLoadedCallback):
     18
    1192014-11-12  Carlos Garcia Campos  <cgarcia@igalia.com>
    220
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitUserContentManager.cpp

    r175414 r176018  
    249249    }
    250250
    251     WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* javascriptValueAsText)
     251    WebKitJavascriptResult* waitUntilMessageReceived(const char* handlerName)
    252252    {
    253253        if (m_userScriptMessage) {
     
    259259        g_signal_connect(m_userContentManager.get(), signalName.get(), G_CALLBACK(scriptMessageReceived), this);
    260260
     261        g_main_loop_run(m_mainLoop);
     262        g_assert(m_userScriptMessage);
     263        return m_userScriptMessage;
     264    }
     265
     266    WebKitJavascriptResult* postMessageAndWaitUntilReceived(const char* handlerName, const char* javascriptValueAsText)
     267    {
    261268        GUniquePtr<char> javascriptSnippet(g_strdup_printf("window.webkit.messageHandlers.%s.postMessage(%s);", handlerName, javascriptValueAsText));
    262269        webkit_web_view_run_javascript(m_webView, javascriptSnippet.get(), nullptr, nullptr, nullptr);
    263         g_main_loop_run(m_mainLoop);
    264 
    265         g_assert(m_userScriptMessage);
    266         return m_userScriptMessage;
     270        return waitUntilMessageReceived(handlerName);
    267271    }
    268272
     
    342346}
    343347
     348static void testUserContentManagerScriptMessageFromDOMBindings(UserScriptMessageTest* test, gconstpointer)
     349{
     350    g_assert(test->registerHandler("dom"));
     351
     352    test->loadHtml("<html></html>", nullptr);
     353    WebKitJavascriptResult* javascriptResult = test->waitUntilMessageReceived("dom");
     354    g_assert(javascriptResult);
     355    GUniquePtr<char> valueString(WebViewTest::javascriptResultToCString(javascriptResult));
     356    g_assert_cmpstr(valueString.get(), ==, "DocumentLoaded");
     357
     358    test->unregisterHandler("dom");
     359}
     360
    344361static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer)
    345362{
     
    351368void beforeAll()
    352369{
     370    webkit_web_context_set_web_extensions_directory(webkit_web_context_get_default(), WEBKIT_TEST_WEB_EXTENSIONS_DIR);
    353371    kServer = new WebKitTestServer();
    354372    kServer->run(serverCallback);
     
    358376    UserContentManagerTest::add("WebKitUserContentManager", "injected-script", testUserContentManagerInjectedScript);
    359377    UserScriptMessageTest::add("WebKitUserContentManager", "script-message-received", testUserContentManagerScriptMessageReceived);
     378    UserScriptMessageTest::add("WebKitUserContentManager", "script-message-from-dom-bindings", testUserContentManagerScriptMessageFromDOMBindings);
    360379}
    361380
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Gtk/WebExtensionTest.cpp

    r175694 r176018  
    3434#include <wtf/text/CString.h>
    3535
     36#define WEBKIT_DOM_USE_UNSTABLE_API
     37#include <webkitdom/WebKitDOMWebKitNamespace.h>
     38#include <webkitdom/WebKitDOMUserMessageHandlersNamespace.h>
     39#include <webkitdom/WebKitDOMUserMessageHandler.h>
     40
    3641static const char introspectionXML[] =
    3742    "<node>"
     
    99104}
    100105
    101 static void documentLoadedCallback(WebKitWebPage*, WebKitWebExtension* extension)
    102 {
     106static void documentLoadedCallback(WebKitWebPage* webPage, WebKitWebExtension* extension)
     107{
     108    // FIXME: Too much code just to send a message, we need convenient custom API for this.
     109    WebKitDOMDocument* document = webkit_web_page_get_dom_document(webPage);
     110    WebKitDOMDOMWindow* window = webkit_dom_document_get_default_view(document);
     111    if (WebKitDOMWebKitNamespace* webkit = webkit_dom_dom_window_get_webkit_namespace(window)) {
     112        WebKitDOMUserMessageHandlersNamespace* messageHandlers = webkit_dom_webkit_namespace_get_message_handlers(webkit);
     113        if (WebKitDOMUserMessageHandler* handler = webkit_dom_user_message_handlers_namespace_get_handler(messageHandlers, "dom"))
     114            webkit_dom_user_message_handler_post_message(handler, "DocumentLoaded");
     115    }
     116
     117
    103118    gpointer data = g_object_get_data(G_OBJECT(extension), "dbus-connection");
    104119    if (data)
Note: See TracChangeset for help on using the changeset viewer.