Changeset 245176 in webkit


Ignore:
Timestamp:
May 10, 2019 9:46:39 AM (5 years ago)
Author:
Michael Catanzaro
Message:

[WPE][GTK] Add webkit_frame_get_id() API
https://bugs.webkit.org/show_bug.cgi?id=197270

Reviewed by Carlos Garcia Campos.

Source/WebKit:

It's as simple as can be: just an API to return the ID of a frame.

  • UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
  • WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp:

(webkit_frame_get_id):

  • WebProcess/InjectedBundle/API/gtk/WebKitFrame.h:
  • WebProcess/InjectedBundle/API/wpe/WebKitFrame.h:
  • WebProcess/InjectedBundle/API/wpe/docs/wpe-webextensions-1.0-sections.txt:

Tools:

This was hard, but I added a test to verify that two different WebKitFrames of the same
WebKitWebPage return two different frame IDs.

  • TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp:

(WebKitFrameTest::willSubmitFormCallback):
(WebKitFrameTest::testSubframe):
(registerTests):

  • TestWebKitAPI/Tests/WebKitGLib/TestFrame.cpp:

(testWebKitFrameSubframe):
(beforeAll):

  • TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:

(willSubmitFormCallback):

  • TestWebKitAPI/Tests/WebKitGLib/resources/form-in-frame.html: Added.
  • TestWebKitAPI/Tests/WebKitGLib/resources/webkitglib-tests.gresource.xml:
Location:
trunk
Files:
1 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245174 r245176  
     12019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [WPE][GTK] Add webkit_frame_get_id() API
     4        https://bugs.webkit.org/show_bug.cgi?id=197270
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        It's as simple as can be: just an API to return the ID of a frame.
     9
     10        * UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt:
     11        * WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp:
     12        (webkit_frame_get_id):
     13        * WebProcess/InjectedBundle/API/gtk/WebKitFrame.h:
     14        * WebProcess/InjectedBundle/API/wpe/WebKitFrame.h:
     15        * WebProcess/InjectedBundle/API/wpe/docs/wpe-webextensions-1.0-sections.txt:
     16
    1172019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
    218
  • trunk/Source/WebKit/UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt

    r244260 r245176  
    16001600<FILE>WebKitFrame</FILE>
    16011601WebKitFrame
     1602webkit_frame_get_id
    16021603webkit_frame_is_main_frame
    16031604webkit_frame_get_uri
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitFrame.cpp

    r229973 r245176  
    6060
    6161/**
     62 * webkit_frame_get_id:
     63 * @frame: a #WebKitFrame
     64 *
     65 * Gets the process-unique identifier of this #WebKitFrame. No other
     66 * frame in the same web process will have the same ID; however, frames
     67 * in other web processes may.
     68 *
     69 * Returns: the identifier of @frame
     70 *
     71 * Since: 2.26
     72 */
     73guint64 webkit_frame_get_id(WebKitFrame* frame)
     74{
     75    g_return_val_if_fail(WEBKIT_IS_FRAME(frame), 0);
     76
     77    return frame->priv->webFrame->frameID();
     78}
     79
     80/**
    6281 * webkit_frame_is_main_frame:
    6382 * @frame: a #WebKitFrame
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/gtk/WebKitFrame.h

    r229973 r245176  
    5858webkit_frame_get_type                                    (void);
    5959
     60WEBKIT_API guint64
     61webkit_frame_get_id                                      (WebKitFrame       *frame);
     62
    6063WEBKIT_API gboolean
    6164webkit_frame_is_main_frame                               (WebKitFrame       *frame);
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/wpe/WebKitFrame.h

    r229973 r245176  
    5757webkit_frame_get_type                                    (void);
    5858
     59WEBKIT_API guint64
     60webkit_frame_get_id                                      (WebKitFrame       *frame);
     61
    5962WEBKIT_API gboolean
    6063webkit_frame_is_main_frame                               (WebKitFrame       *frame);
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/wpe/docs/wpe-webextensions-1.0-sections.txt

    r243073 r245176  
    7777<FILE>WebKitFrame</FILE>
    7878WebKitFrame
     79webkit_frame_get_id
    7980webkit_frame_is_main_frame
    8081webkit_frame_get_uri
  • trunk/Tools/ChangeLog

    r245174 r245176  
     12019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
     2
     3        [WPE][GTK] Add webkit_frame_get_id() API
     4        https://bugs.webkit.org/show_bug.cgi?id=197270
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        This was hard, but I added a test to verify that two different WebKitFrames of the same
     9        WebKitWebPage return two different frame IDs.
     10
     11        * TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp:
     12        (WebKitFrameTest::willSubmitFormCallback):
     13        (WebKitFrameTest::testSubframe):
     14        (registerTests):
     15        * TestWebKitAPI/Tests/WebKitGLib/TestFrame.cpp:
     16        (testWebKitFrameSubframe):
     17        (beforeAll):
     18        * TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
     19        (willSubmitFormCallback):
     20        * TestWebKitAPI/Tests/WebKitGLib/resources/form-in-frame.html: Added.
     21        * TestWebKitAPI/Tests/WebKitGLib/resources/webkitglib-tests.gresource.xml:
     22
    1232019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
    224
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/FrameTest.cpp

    r239772 r245176  
    132132    }
    133133
     134    static void willSubmitFormCallback(WebKitWebPage* page, WebKitDOMElement*, WebKitFormSubmissionStep, WebKitFrame* sourceFrame, WebKitFrame*, GPtrArray*, GPtrArray*, gpointer userData)
     135    {
     136        // The form is submitted from a subframe. It should have a different ID than the main frame.
     137        WebKitFrame* mainFrame = webkit_web_page_get_main_frame(page);
     138        g_assert_cmpuint(webkit_frame_get_id(mainFrame), !=, webkit_frame_get_id(sourceFrame));
     139
     140        auto* test = static_cast<WebKitFrameTest*>(userData);
     141        g_main_loop_quit(test->m_mainLoop.get());
     142    }
     143
     144    bool testSubframe(WebKitWebPage* page)
     145    {
     146        WebKitFrame* mainFrame = webkit_web_page_get_main_frame(page);
     147        g_assert_true(WEBKIT_IS_FRAME(mainFrame));
     148
     149        GRefPtr<JSCContext> jsContext = adoptGRef(webkit_frame_get_js_context(mainFrame));
     150        g_assert_true(JSC_IS_CONTEXT(jsContext.get()));
     151        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsContext.get()));
     152
     153        GRefPtr<JSCValue> jsParentDocument = adoptGRef(jsc_context_get_value(jsContext.get(), "document"));
     154        g_assert_true(JSC_IS_VALUE(jsParentDocument.get()));
     155        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(jsParentDocument.get()));
     156
     157        GRefPtr<JSCValue> subframe = adoptGRef(jsc_value_object_invoke_method(jsParentDocument.get(), "getElementById", G_TYPE_STRING, "frame", G_TYPE_NONE));
     158        g_assert_true(JSC_IS_VALUE(subframe.get()));
     159        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(subframe.get()));
     160
     161        GRefPtr<JSCValue> contentWindow = adoptGRef(jsc_value_object_get_property(subframe.get(), "contentWindow"));
     162        g_assert_true(JSC_IS_VALUE(contentWindow.get()));
     163        assertObjectIsDeletedWhenTestFinishes(G_OBJECT(contentWindow.get()));
     164
     165        GRefPtr<JSCValue> undefined = adoptGRef(jsc_value_object_invoke_method(contentWindow.get(), "postMessage", G_TYPE_STRING, "submit the form!", G_TYPE_STRING, "*", G_TYPE_NONE));
     166        g_assert_true(JSC_IS_VALUE(undefined.get()));
     167        g_assert_true(jsc_value_is_undefined(undefined.get()));
     168
     169        g_signal_connect(page, "will-submit-form", reinterpret_cast<GCallback>(willSubmitFormCallback), this);
     170
     171        m_mainLoop = adoptGRef(g_main_loop_new(nullptr, FALSE));
     172        g_main_loop_run(m_mainLoop.get());
     173
     174        return true;
     175    }
     176
    134177    bool runTest(const char* testName, WebKitWebPage* page) override
    135178    {
     
    142185        if (!strcmp(testName, "javascript-values"))
    143186            return testJavaScriptValues(page);
     187        if (!strcmp(testName, "subframe"))
     188            return testSubframe(page);
    144189
    145190        g_assert_not_reached();
    146191        return false;
    147192    }
     193
     194    GRefPtr<GMainLoop> m_mainLoop;
    148195};
    149196
     
    154201    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/javascript-context");
    155202    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/javascript-values");
     203    REGISTER_TEST(WebKitFrameTest, "WebKitFrame/subframe");
    156204}
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestFrame.cpp

    r239772 r245176  
    4343}
    4444
     45static void testWebKitFrameSubframe(WebViewTest* test, gconstpointer)
     46{
     47    static const char* testHTML = "<html><body><iframe src='resource:///org/webkit/glib/tests/form-in-frame.html' id='frame'></iframe></body></html>";
     48    g_assert_true(test->runWebProcessTest("WebKitFrame", "subframe", testHTML));
     49}
     50
    4551void beforeAll()
    4652{
     
    4955    WebViewTest::add("WebKitFrame", "javascript-context", testWebKitFrameJavaScriptContext);
    5056    WebViewTest::add("WebKitFrame", "javascript-values", testWebKitFrameJavaScriptValues);
     57    WebViewTest::add("WebKitFrame", "subframe", testWebKitFrameSubframe);
    5158}
    5259
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp

    r245174 r245176  
    387387    G_GNUC_END_IGNORE_DEPRECATIONS;
    388388#endif
    389     GRefPtr<JSCValue> jsFormElement = adoptGRef(webkit_frame_get_js_value_for_dom_object(webkit_web_page_get_main_frame(webPage), WEBKIT_DOM_OBJECT(formElement)));
     389    GRefPtr<JSCValue> jsFormElement = adoptGRef(webkit_frame_get_js_value_for_dom_object(sourceFrame, WEBKIT_DOM_OBJECT(formElement)));
    390390    g_assert_true(JSC_IS_VALUE(jsFormElement.get()));
    391391    g_assert_true(jsc_value_is_object(jsFormElement.get()));
  • trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/resources/webkitglib-tests.gresource.xml

    r218685 r245176  
    33  <gresource prefix="/org/webkit/glib/tests/">
    44    <file alias="boring.html">Tools/TestWebKitAPI/Tests/WebKitGLib/resources/boring.html</file>
     5    <file alias="form-in-frame.html">Tools/TestWebKitAPI/Tests/WebKitGLib/resources/form-in-frame.html</file>
    56    <file alias="link-title.js">Tools/TestWebKitAPI/Tests/WebKitGLib/resources/link-title.js</file>
    67  </gresource>
Note: See TracChangeset for help on using the changeset viewer.