[WPE][GTK] Add WebKitWebPage::did-associate-form-controls-for-frame and deprecate...
authormcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 16:05:34 +0000 (16:05 +0000)
committermcatanzaro@igalia.com <mcatanzaro@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 10 May 2019 16:05:34 +0000 (16:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=197271

Reviewed by Youenn Fablet.

Source/WebCore:

* dom/Document.cpp:
(WebCore::Document::didAssociateFormControlsTimerFired):
* loader/EmptyClients.h:
* page/ChromeClient.h:

Source/WebKit:

* WebProcess/InjectedBundle/API/c/WKBundlePageFormClient.h:
* WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp:
(webkit_web_page_class_init):
* WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
(-[WKWebProcessPlugInBrowserContextController _setFormDelegate:]):
* WebProcess/InjectedBundle/APIInjectedBundleFormClient.h:
(API::InjectedBundle::FormClient::didAssociateFormControls):
* WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp:
(WebKit::InjectedBundlePageFormClient::didAssociateFormControls):
* WebProcess/InjectedBundle/InjectedBundlePageFormClient.h:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::didAssociateFormControls):
* WebProcess/WebCoreSupport/WebChromeClient.h:

Tools:

* TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
(formControlsAssociatedForFrameCallback):
(pageCreatedCallback):
(formControlsAssociatedCallback): Deleted.

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

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/dom/Document.cpp
Source/WebCore/loader/EmptyClients.h
Source/WebCore/page/ChromeClient.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundlePageFormClient.h
Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp
Source/WebKit/WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm
Source/WebKit/WebProcess/InjectedBundle/APIInjectedBundleFormClient.h
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp
Source/WebKit/WebProcess/InjectedBundle/InjectedBundlePageFormClient.h
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp

index 8cb18e7..e498e8d 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [WPE][GTK] Add WebKitWebPage::did-associate-form-controls-for-frame and deprecate original did-associate-form-controls
+        https://bugs.webkit.org/show_bug.cgi?id=197271
+
+        Reviewed by Youenn Fablet.
+
+        * dom/Document.cpp:
+        (WebCore::Document::didAssociateFormControlsTimerFired):
+        * loader/EmptyClients.h:
+        * page/ChromeClient.h:
+
 2019-05-09  Simon Fraser  <simon.fraser@apple.com>
 
         Implement backing-sharing in compositing layers, allowing overlap layers to paint into the backing store of another layer
index 7614bf5..a2fbd8f 100644 (file)
@@ -6959,8 +6959,10 @@ void Document::didAssociateFormControlsTimerFired()
 {
     auto vector = copyToVector(m_associatedFormControls);
     m_associatedFormControls.clear();
-    if (auto* page = this->page())
-        page->chrome().client().didAssociateFormControls(vector);
+    if (auto* page = this->page()) {
+        ASSERT(m_frame);
+        page->chrome().client().didAssociateFormControls(vector, *m_frame);
+    }
 }
 
 void Document::setCachedDOMCookies(const String& cookies)
index 6a663f8..d45228e 100644 (file)
@@ -194,7 +194,7 @@ class EmptyChromeClient : public ChromeClient {
     
     bool isEmptyChromeClient() const final { return true; }
 
-    void didAssociateFormControls(const Vector<RefPtr<Element>>&) final { }
+    void didAssociateFormControls(const Vector<RefPtr<Element>>&, Frame&) final { }
     bool shouldNotifyOnFormChanges() final { return false; }
 
     RefPtr<Icon> createIconForFiles(const Vector<String>& /* filenames */) final { return nullptr; }
index 871e415..340a6af 100644 (file)
@@ -428,7 +428,7 @@ public:
     virtual String plugInExtraStyleSheet() const { return String(); }
     virtual String plugInExtraScript() const { return String(); }
 
-    virtual void didAssociateFormControls(const Vector<RefPtr<Element>>&) { };
+    virtual void didAssociateFormControls(const Vector<RefPtr<Element>>&, Frame&) { };
     virtual bool shouldNotifyOnFormChanges() { return false; };
 
     virtual void didAddHeaderLayer(GraphicsLayer&) { }
index bfd5839..1b60328 100644 (file)
@@ -1,3 +1,24 @@
+2019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [WPE][GTK] Add WebKitWebPage::did-associate-form-controls-for-frame and deprecate original did-associate-form-controls
+        https://bugs.webkit.org/show_bug.cgi?id=197271
+
+        Reviewed by Youenn Fablet.
+
+        * WebProcess/InjectedBundle/API/c/WKBundlePageFormClient.h:
+        * WebProcess/InjectedBundle/API/glib/WebKitWebPage.cpp:
+        (webkit_web_page_class_init):
+        * WebProcess/InjectedBundle/API/mac/WKWebProcessPlugInBrowserContextController.mm:
+        (-[WKWebProcessPlugInBrowserContextController _setFormDelegate:]):
+        * WebProcess/InjectedBundle/APIInjectedBundleFormClient.h:
+        (API::InjectedBundle::FormClient::didAssociateFormControls):
+        * WebProcess/InjectedBundle/InjectedBundlePageFormClient.cpp:
+        (WebKit::InjectedBundlePageFormClient::didAssociateFormControls):
+        * WebProcess/InjectedBundle/InjectedBundlePageFormClient.h:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::didAssociateFormControls):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
 2019-05-09  Rob Buis  <rbuis@igalia.com>
 
         Limit number of prefetches of a given page
index 3fc33b9..362a44d 100644 (file)
@@ -39,6 +39,7 @@ typedef void (*WKBundlePageWillSendSubmitEventCallback)(WKBundlePageRef page, WK
 typedef void (*WKBundlePageDidFocusTextFieldCallback)(WKBundlePageRef page, WKBundleNodeHandleRef htmlInputElementHandle, WKBundleFrameRef frame, const void* clientInfo);
 typedef bool (*WKBundlePageShouldNotifyOnFormChangesCallback)(WKBundlePageRef page, const void* clientInfo);
 typedef void (*WKBundlePageDidAssociateFormControlsCallback)(WKBundlePageRef page, WKArrayRef elementHandles, const void* clientInfo);
+typedef void (*WKBundlePageDidAssociateFormControlsForFrameCallback)(WKBundlePageRef page, WKArrayRef elementHandles, WKBundleFrameRef frame, const void* clientInfo);
 
 typedef struct WKBundlePageFormClientBase {
     int                                                                 version;
@@ -92,4 +93,27 @@ typedef struct WKBundlePageFormClientV2 {
     WKBundlePageDidAssociateFormControlsCallback                        didAssociateFormControls;
 } WKBundlePageFormClientV2;
 
+typedef struct WKBundlePageFormClientV3 {
+    WKBundlePageFormClientBase                                          base;
+
+    // Version 0.
+    WKBundlePageTextFieldDidBeginEditingCallback                        textFieldDidBeginEditing;
+    WKBundlePageTextFieldDidEndEditingCallback                          textFieldDidEndEditing;
+    WKBundlePageTextDidChangeInTextFieldCallback                        textDidChangeInTextField;
+    WKBundlePageTextDidChangeInTextAreaCallback                         textDidChangeInTextArea;
+    WKBundlePageShouldPerformActionInTextFieldCallback                  shouldPerformActionInTextField;
+    WKBundlePageWillSubmitFormCallback                                  willSubmitForm;
+
+    // Version 1.
+    WKBundlePageWillSendSubmitEventCallback                             willSendSubmitEvent;
+
+    // version 2.
+    WKBundlePageDidFocusTextFieldCallback                               didFocusTextField;
+    WKBundlePageShouldNotifyOnFormChangesCallback                       shouldNotifyOnFormChanges;
+    WKBundlePageDidAssociateFormControlsCallback                        didAssociateFormControls;
+
+    // version 3.
+    WKBundlePageDidAssociateFormControlsForFrameCallback                didAssociateFormControlsForFrame;
+} WKBundlePageFormClientV3;
+
 #endif // WKBundlePageFormClient_h
index 47f0f04..e57e2e7 100644 (file)
@@ -68,6 +68,7 @@ enum {
     CONTEXT_MENU,
     CONSOLE_MESSAGE_SENT,
     FORM_CONTROLS_ASSOCIATED,
+    FORM_CONTROLS_ASSOCIATED_FOR_FRAME,
     WILL_SUBMIT_FORM,
 
     LAST_SIGNAL
@@ -380,13 +381,14 @@ public:
         fireFormSubmissionEvent(WEBKIT_FORM_SUBMISSION_WILL_SEND_DOM_EVENT, formElement, frame, sourceFrame, values);
     }
 
-    void didAssociateFormControls(WebPage*, const Vector<RefPtr<Element>>& elements) override
+    void didAssociateFormControls(WebPage*, const Vector<RefPtr<Element>>& elements, WebFrame* frame) override
     {
         GRefPtr<GPtrArray> formElements = adoptGRef(g_ptr_array_sized_new(elements.size()));
         for (size_t i = 0; i < elements.size(); ++i)
             g_ptr_array_add(formElements.get(), WebKit::kit(elements[i].get()));
 
         g_signal_emit(m_webPage, signals[FORM_CONTROLS_ASSOCIATED], 0, formElements.get());
+        g_signal_emit(m_webPage, signals[FORM_CONTROLS_ASSOCIATED_FOR_FRAME], 0, formElements.get(), webkitFrameGetOrCreate(frame));
     }
 
     bool shouldNotifyOnFormChanges(WebPage*) override { return true; }
@@ -565,17 +567,48 @@ static void webkit_web_page_class_init(WebKitWebPageClass* klass)
      * keep them alive after the signal handler returns.
      *
      * Since: 2.16
+     *
+     * Deprecated: 2.26, use #WebKitWebPage::form-controls-associated-for-frame instead.
      */
     signals[FORM_CONTROLS_ASSOCIATED] = g_signal_new(
         "form-controls-associated",
         G_TYPE_FROM_CLASS(klass),
-        G_SIGNAL_RUN_LAST,
+        static_cast<GSignalFlags>(G_SIGNAL_RUN_LAST | G_SIGNAL_DEPRECATED),
         0, 0, nullptr,
         g_cclosure_marshal_VOID__BOXED,
         G_TYPE_NONE, 1,
         G_TYPE_PTR_ARRAY);
 
     /**
+     * WebKitWebPage::form-controls-associated-for-frame:
+     * @web_page: the #WebKitWebPage on which the signal is emitted
+     * @elements: (element-type WebKitDOMElement) (transfer none): a #GPtrArray of
+     *     #WebKitDOMElement with the list of forms in the page
+     * @frame: the #WebKitFrame
+     *
+     * Emitted after form elements (or form associated elements) are associated to a particular web
+     * page. This is useful to implement form auto filling for web pages where form fields are added
+     * dynamically. This signal might be emitted multiple times for the same web page.
+     *
+     * Note that this signal could be also emitted when form controls are moved between forms. In
+     * that case, the @elements array carries the list of those elements which have moved.
+     *
+     * Clients should take a reference to the members of the @elements array if it is desired to
+     * keep them alive after the signal handler returns.
+     *
+     * Since: 2.26
+     */
+    signals[FORM_CONTROLS_ASSOCIATED_FOR_FRAME] = g_signal_new(
+        "form-controls-associated-for-frame",
+        G_TYPE_FROM_CLASS(klass),
+        G_SIGNAL_RUN_LAST,
+        0, 0, nullptr,
+        g_cclosure_marshal_generic,
+        G_TYPE_NONE, 2,
+        G_TYPE_PTR_ARRAY,
+        WEBKIT_TYPE_FRAME);
+
+    /**
      * WebKitWebPage::will-submit-form:
      * @web_page: the #WebKitWebPage on which the signal is emitted
      * @form: the #WebKitDOMElement to be submitted, which will always correspond to an HTMLFormElement
index 80caa2d..48800bb 100644 (file)
@@ -526,7 +526,7 @@ static void setUpResourceLoadClient(WKWebProcessPlugInBrowserContextController *
             return [formDelegate _webProcessPlugInBrowserContextControllerShouldNotifyOnFormChanges:m_controller];
         }
 
-        void didAssociateFormControls(WebKit::WebPage*, const Vector<RefPtr<WebCore::Element>>& elements) override
+        void didAssociateFormControls(WebKit::WebPage*, const Vector<RefPtr<WebCore::Element>>& elements, WebKit::WebFrame*) override
         {
             auto formDelegate = m_controller->_formDelegate.get();
 
index 92ebcfe..0395b32 100644 (file)
@@ -70,7 +70,7 @@ public:
     virtual bool shouldPerformActionInTextField(WebKit::WebPage*, WebCore::HTMLInputElement*, InputFieldAction, WebKit::WebFrame*) { return false; }
     virtual void willSubmitForm(WebKit::WebPage*, WebCore::HTMLFormElement*, WebKit::WebFrame*, WebKit::WebFrame*, const Vector<std::pair<WTF::String, WTF::String>>&, RefPtr<API::Object>& userData) { UNUSED_PARAM(userData); }
     virtual void willSendSubmitEvent(WebKit::WebPage*, WebCore::HTMLFormElement*, WebKit::WebFrame*, WebKit::WebFrame*, const Vector<std::pair<WTF::String, WTF::String>>&) { }
-    virtual void didAssociateFormControls(WebKit::WebPage*, const Vector<RefPtr<WebCore::Element>>&) { }
+    virtual void didAssociateFormControls(WebKit::WebPage*, const Vector<RefPtr<WebCore::Element>>&, WebKit::WebFrame*) { }
     virtual bool shouldNotifyOnFormChanges(WebKit::WebPage*) { return false; }
     virtual void willBeginInputSession(WebKit::WebPage*, WebCore::Element*, WebKit::WebFrame*, bool userIsInteracting, RefPtr<API::Object>& userData) { UNUSED_PARAM(userData); }
 };
index 02b5b53..10f8fef 100644 (file)
@@ -157,9 +157,9 @@ void InjectedBundlePageFormClient::willSubmitForm(WebPage* page, HTMLFormElement
     userData = adoptRef(toImpl(userDataToPass));
 }
 
-void InjectedBundlePageFormClient::didAssociateFormControls(WebPage* page, const Vector<RefPtr<WebCore::Element>>& elements)
+void InjectedBundlePageFormClient::didAssociateFormControls(WebPage* page, const Vector<RefPtr<WebCore::Element>>& elements, WebFrame* frame)
 {
-    if (!m_client.didAssociateFormControls)
+    if (!m_client.didAssociateFormControls && !m_client.didAssociateFormControlsForFrame)
         return;
 
     Vector<RefPtr<API::Object>> elementHandles;
@@ -168,7 +168,12 @@ void InjectedBundlePageFormClient::didAssociateFormControls(WebPage* page, const
     for (const auto& element : elements)
         elementHandles.uncheckedAppend(InjectedBundleNodeHandle::getOrCreate(element.get()));
 
-    m_client.didAssociateFormControls(toAPI(page), toAPI(API::Array::create(WTFMove(elementHandles)).ptr()), m_client.base.clientInfo);
+    if (!m_client.didAssociateFormControlsForFrame) {
+        m_client.didAssociateFormControls(toAPI(page), toAPI(API::Array::create(WTFMove(elementHandles)).ptr()), m_client.base.clientInfo);
+        return;
+    }
+
+    m_client.didAssociateFormControlsForFrame(toAPI(page), toAPI(API::Array::create(WTFMove(elementHandles)).ptr()), toAPI(frame), m_client.base.clientInfo);
 }
 
 bool InjectedBundlePageFormClient::shouldNotifyOnFormChanges(WebPage* page)
index e9df531..e35b21f 100644 (file)
@@ -33,7 +33,7 @@
 namespace API {
 
 template<> struct ClientTraits<WKBundlePageFormClientBase> {
-    typedef std::tuple<WKBundlePageFormClientV0, WKBundlePageFormClientV1, WKBundlePageFormClientV2> Versions;
+    typedef std::tuple<WKBundlePageFormClientV0, WKBundlePageFormClientV1, WKBundlePageFormClientV2, WKBundlePageFormClientV3> Versions;
 };
 }
 
@@ -51,7 +51,7 @@ public:
     bool shouldPerformActionInTextField(WebPage*, WebCore::HTMLInputElement*, InputFieldAction, WebFrame*) override;    
     void willSubmitForm(WebPage*, WebCore::HTMLFormElement*, WebFrame*, WebFrame* sourceFrame, const Vector<std::pair<String, String>>&, RefPtr<API::Object>& userData) override;
     void willSendSubmitEvent(WebPage*, WebCore::HTMLFormElement*, WebFrame*, WebFrame* sourceFrame, const Vector<std::pair<String, String>>&) override;
-    void didAssociateFormControls(WebPage*, const Vector<RefPtr<WebCore::Element>>&) override;
+    void didAssociateFormControls(WebPage*, const Vector<RefPtr<WebCore::Element>>&, WebFrame*) override;
     bool shouldNotifyOnFormChanges(WebPage*) override;
 };
 
index 6bca275..66e53a2 100644 (file)
@@ -847,9 +847,11 @@ RefPtr<Icon> WebChromeClient::createIconForFiles(const Vector<String>& filenames
 
 #endif
 
-void WebChromeClient::didAssociateFormControls(const Vector<RefPtr<Element>>& elements)
+void WebChromeClient::didAssociateFormControls(const Vector<RefPtr<Element>>& elements, WebCore::Frame& frame)
 {
-    return m_page.injectedBundleFormClient().didAssociateFormControls(&m_page, elements);
+    WebFrame* webFrame = WebFrame::fromCoreFrame(frame);
+    ASSERT(webFrame);
+    return m_page.injectedBundleFormClient().didAssociateFormControls(&m_page, elements, webFrame);
 }
 
 bool WebChromeClient::shouldNotifyOnFormChanges()
index 7925331..1121215 100644 (file)
@@ -206,7 +206,7 @@ private:
     void requestPointerUnlock() final;
 #endif
 
-    void didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>&) final;
+    void didAssociateFormControls(const Vector<RefPtr<WebCore::Element>>&, WebCore::Frame&) final;
     bool shouldNotifyOnFormChanges() final;
 
     bool selectItemWritingDirectionIsNatural() final;
index 1efa592..3694911 100644 (file)
@@ -1,3 +1,15 @@
+2019-05-10  Michael Catanzaro  <mcatanzaro@igalia.com>
+
+        [WPE][GTK] Add WebKitWebPage::did-associate-form-controls-for-frame and deprecate original did-associate-form-controls
+        https://bugs.webkit.org/show_bug.cgi?id=197271
+
+        Reviewed by Youenn Fablet.
+
+        * TestWebKitAPI/Tests/WebKitGLib/WebExtensionTest.cpp:
+        (formControlsAssociatedForFrameCallback):
+        (pageCreatedCallback):
+        (formControlsAssociatedCallback): Deleted.
+
 2019-05-10  Adrian Perez de Castro  <aperez@igalia.com>
 
         [Flatpak] Use the safe PyYAML loader if available
index 2664555..1a56584 100644 (file)
@@ -316,9 +316,8 @@ static void emitFormControlsAssociated(GDBusConnection* connection, const char*
     g_assert_true(ok);
 }
 
-static void formControlsAssociatedCallback(WebKitWebPage* webPage, GPtrArray* formElements, WebKitWebExtension* extension)
+static void formControlsAssociatedForFrameCallback(WebKitWebPage* webPage, GPtrArray* formElements, WebKitFrame* frame, WebKitWebExtension* extension)
 {
-    auto* frame = webkit_web_page_get_main_frame(webPage);
     GString* formIdsBuilder = g_string_new(nullptr);
     for (guint i = 0; i < formElements->len; ++i) {
         g_assert_true(WEBKIT_DOM_IS_ELEMENT(g_ptr_array_index(formElements, i)));
@@ -413,7 +412,7 @@ static void pageCreatedCallback(WebKitWebExtension* extension, WebKitWebPage* we
     g_signal_connect(webPage, "send-request", G_CALLBACK(sendRequestCallback), nullptr);
     g_signal_connect(webPage, "console-message-sent", G_CALLBACK(consoleMessageSentCallback), nullptr);
     g_signal_connect(webPage, "context-menu", G_CALLBACK(contextMenuCallback), nullptr);
-    g_signal_connect(webPage, "form-controls-associated", G_CALLBACK(formControlsAssociatedCallback), extension);
+    g_signal_connect(webPage, "form-controls-associated-for-frame", G_CALLBACK(formControlsAssociatedForFrameCallback), extension);
     g_signal_connect(webPage, "will-submit-form", G_CALLBACK(willSubmitFormCallback), extension);
 }