Title: [287281] trunk/Source/WebCore
- Revision
- 287281
- Author
- [email protected]
- Date
- 2021-12-20 15:01:20 -0800 (Mon, 20 Dec 2021)
Log Message
Adopt ChromeClient::classifyModalContainerControls() in ModalContainerObserver
https://bugs.webkit.org/show_bug.cgi?id=234323
Reviewed by Devin Rousso.
Hook into the new chrome client method introduced in bug #234320 in ModalContainerObserver, by propagating the
identified strings through the client layer for classification, and then using the predicted class labels to
fulfill the document loader's ModalContainerObservationPolicy.
* page/ModalContainerObserver.cpp:
(WebCore::ModalContainerObserver::updateModalContainerIfNeeded):
(WebCore::ModalContainerObserver::collectClickableElementsTimerFired):
Use the predicted class labels to find a suitable element on which we should dispatch a simulated click.
* page/ModalContainerObserver.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (287280 => 287281)
--- trunk/Source/WebCore/ChangeLog 2021-12-20 22:55:58 UTC (rev 287280)
+++ trunk/Source/WebCore/ChangeLog 2021-12-20 23:01:20 UTC (rev 287281)
@@ -1,3 +1,22 @@
+2021-12-20 Wenson Hsieh <[email protected]>
+
+ Adopt ChromeClient::classifyModalContainerControls() in ModalContainerObserver
+ https://bugs.webkit.org/show_bug.cgi?id=234323
+
+ Reviewed by Devin Rousso.
+
+ Hook into the new chrome client method introduced in bug #234320 in ModalContainerObserver, by propagating the
+ identified strings through the client layer for classification, and then using the predicted class labels to
+ fulfill the document loader's ModalContainerObservationPolicy.
+
+ * page/ModalContainerObserver.cpp:
+ (WebCore::ModalContainerObserver::updateModalContainerIfNeeded):
+ (WebCore::ModalContainerObserver::collectClickableElementsTimerFired):
+
+ Use the predicted class labels to find a suitable element on which we should dispatch a simulated click.
+
+ * page/ModalContainerObserver.h:
+
2021-12-20 Alan Bujtas <[email protected]>
[LFC][IFC] Move display builder files under /display directory
Modified: trunk/Source/WebCore/page/ModalContainerObserver.cpp (287280 => 287281)
--- trunk/Source/WebCore/page/ModalContainerObserver.cpp 2021-12-20 22:55:58 UTC (rev 287280)
+++ trunk/Source/WebCore/page/ModalContainerObserver.cpp 2021-12-20 23:01:20 UTC (rev 287281)
@@ -42,10 +42,12 @@
#include "HTMLElement.h"
#include "HTMLImageElement.h"
#include "HTMLInputElement.h"
+#include "ModalContainerControlType.h"
#include "Page.h"
#include "RenderDescendantIterator.h"
#include "RenderText.h"
#include "RenderView.h"
+#include "SimulatedClickOptions.h"
#include "Text.h"
#include <wtf/Scope.h>
#include <wtf/URL.h>
@@ -113,6 +115,9 @@
if (m_container)
return;
+ if (m_hasAttemptedToFulfillPolicy)
+ return;
+
if (!view.hasViewportConstrainedObjects())
return;
@@ -256,7 +261,7 @@
if (!m_container)
return;
- m_container->document().eventLoop().queueTask(TaskSource::InternalAsyncTask, [observer = this, weakDocument = WeakPtr { m_container->document() }] {
+ m_container->document().eventLoop().queueTask(TaskSource::InternalAsyncTask, [observer = this, weakDocument = WeakPtr { m_container->document() }]() mutable {
RefPtr document = weakDocument.get();
if (!document)
return;
@@ -270,7 +275,83 @@
if (classifiableControls.isEmpty())
return;
- // FIXME(234323): Classify strings by propagating them through the client layer.
+ auto* page = document->page();
+ if (!page) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ page->chrome().client().classifyModalContainerControls(WTFMove(controlTextsToClassify), [weakDocument = WTFMove(weakDocument), observer, controls = WTFMove(classifiableControls)] (auto&& types) mutable {
+ if (types.size() != controls.size())
+ return;
+
+ RefPtr document = weakDocument.get();
+ if (!document)
+ return;
+
+ RefPtr documentLoader = document->loader();
+ if (!documentLoader) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ if (observer != document->modalContainerObserverIfExists()) {
+ ASSERT_NOT_REACHED();
+ return;
+ }
+
+ Vector<Ref<HTMLElement>> positiveControls;
+ Vector<Ref<HTMLElement>> neutralControls;
+ Vector<Ref<HTMLElement>> negativeControls;
+ for (size_t index = 0; index < types.size(); ++index) {
+ auto control = controls[index];
+ if (!control)
+ continue;
+
+ switch (types[index]) {
+ case ModalContainerControlType::Positive:
+ positiveControls.append(*control);
+ break;
+ case ModalContainerControlType::Negative:
+ negativeControls.append(*control);
+ break;
+ case ModalContainerControlType::Neutral:
+ neutralControls.append(*control);
+ break;
+ case ModalContainerControlType::Other:
+ break;
+ }
+ }
+
+ RefPtr<HTMLElement> controlToClick;
+ switch (documentLoader->modalContainerObservationPolicy()) {
+ case ModalContainerObservationPolicy::Disabled:
+ ASSERT_NOT_REACHED();
+ break;
+ case ModalContainerObservationPolicy::Allow: {
+ if (!positiveControls.isEmpty())
+ controlToClick = positiveControls[0].ptr();
+ else if (!neutralControls.isEmpty())
+ controlToClick = neutralControls[0].ptr();
+ break;
+ }
+ case ModalContainerObservationPolicy::Disallow: {
+ if (!negativeControls.isEmpty())
+ controlToClick = negativeControls[0].ptr();
+ else if (!neutralControls.isEmpty())
+ controlToClick = neutralControls[0].ptr();
+ break;
+ }
+ case ModalContainerObservationPolicy::Prompt:
+ // Not supported yet.
+ break;
+ }
+
+ observer->m_hasAttemptedToFulfillPolicy = true;
+
+ if (controlToClick)
+ controlToClick->dispatchSimulatedClick(nullptr, SendMouseUpDownEvents, DoNotShowPressedLook);
+ });
});
}
Modified: trunk/Source/WebCore/page/ModalContainerObserver.h (287280 => 287281)
--- trunk/Source/WebCore/page/ModalContainerObserver.h 2021-12-20 22:55:58 UTC (rev 287280)
+++ trunk/Source/WebCore/page/ModalContainerObserver.h 2021-12-20 23:01:20 UTC (rev 287281)
@@ -60,6 +60,7 @@
WeakPtr<Element> m_container;
Timer m_collectClickableElementsTimer;
bool m_collectingClickableElements { false };
+ bool m_hasAttemptedToFulfillPolicy { false };
};
} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes