Modified: trunk/Source/WebCore/ChangeLog (263991 => 263992)
--- trunk/Source/WebCore/ChangeLog 2020-07-06 22:25:04 UTC (rev 263991)
+++ trunk/Source/WebCore/ChangeLog 2020-07-06 23:01:18 UTC (rev 263992)
@@ -1,3 +1,27 @@
+2020-07-06 John Wilander <[email protected]>
+
+ Storage Access API: Add the capability to open a popup and get user interaction so we can call the Storage Access API as a quirk, on behalf of websites that should be doing it themselves
+ https://bugs.webkit.org/show_bug.cgi?id=213910
+ <rdar://problem/65058017>
+
+ Reviewed by Darin Adler.
+
+ This patch not only adds the capability but also adds a site-specific quirk for
+ the family of Kinja sites so that no previous user interaction with kinja.com
+ results in a login popup for kinja.com.
+
+ No new tests. This is for site-specific quirks.
+
+ * dom/Element.cpp:
+ (WebCore::Element::dispatchMouseEvent):
+ Just a change in the call into the quirk function.
+ * page/Quirks.cpp:
+ (WebCore::Quirks::isKinjaLoginAvatarElement const):
+ Convenience function for telling if the given element is the Kinja login avatar.
+ (WebCore::Quirks::triggerOptionalStorageAccessQuirk const):
+ Now takes the whole Element to be able to look at both classes and attributes.
+ * page/Quirks.h:
+
2020-07-06 Peng Liu <[email protected]>
Cleanup WebVideoFullscreenControllerAVKit.mm and PlaybackSessionInterfaceAVKit.mm
Modified: trunk/Source/WebCore/dom/Element.cpp (263991 => 263992)
--- trunk/Source/WebCore/dom/Element.cpp 2020-07-06 22:25:04 UTC (rev 263991)
+++ trunk/Source/WebCore/dom/Element.cpp 2020-07-06 23:01:18 UTC (rev 263992)
@@ -362,7 +362,7 @@
if (dispatchPointerEventIfNeeded(*this, mouseEvent.get(), platformEvent, didNotSwallowEvent) == ShouldIgnoreMouseEvent::Yes)
return false;
- if (hasClass() && Quirks::StorageAccessResult::ShouldCancelEvent == document().quirks().triggerOptionalStorageAccessQuirk(eventType, classNames()))
+ if (Quirks::StorageAccessResult::ShouldCancelEvent == document().quirks().triggerOptionalStorageAccessQuirk(*this, eventType))
return false;
ASSERT(!mouseEvent->target() || mouseEvent->target() != relatedTarget);
Modified: trunk/Source/WebCore/page/Quirks.cpp (263991 => 263992)
--- trunk/Source/WebCore/page/Quirks.cpp 2020-07-06 22:25:04 UTC (rev 263991)
+++ trunk/Source/WebCore/page/Quirks.cpp 2020-07-06 23:01:18 UTC (rev 263992)
@@ -26,6 +26,7 @@
#include "config.h"
#include "Quirks.h"
+#include "Attr.h"
#include "DOMTokenList.h"
#include "DOMWindow.h"
#include "Document.h"
@@ -39,11 +40,19 @@
#include "HTMLObjectElement.h"
#include "JSEventListener.h"
#include "LayoutUnit.h"
+#include "NamedNodeMap.h"
#include "ResourceLoadObserver.h"
#include "RuntimeEnabledFeatures.h"
+#include "SVGPathElement.h"
+#include "SVGSVGElement.h"
+#include "ScriptController.h"
+#include "ScriptSourceCode.h"
#include "Settings.h"
#include "SpaceSplitString.h"
#include "UserAgent.h"
+#include "UserContentTypes.h"
+#include "UserScript.h"
+#include "UserScriptTypes.h"
namespace WebCore {
@@ -842,8 +851,38 @@
#endif
}
-Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(const AtomString& eventType, const SpaceSplitString& classNames) const
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+bool Quirks::isKinjaLoginAvatarElement(const Element& element) const
{
+ // The click event handler has been found to trigger on a div or
+ // span with these class names, or the svg, or the svg's path.
+ if (element.hasClass()) {
+ auto& classNames = element.classNames();
+ if (classNames.contains("js_switch-to-burner-login")
+ || classNames.contains("js_header-userbutton")
+ || classNames.contains("sc-1il3uru-3") || classNames.contains("cIhKfd")
+ || classNames.contains("iyvn34-0") || classNames.contains("bYIjtl"))
+ return true;
+ }
+
+ const Element* svgElement = nullptr;
+ if (is<SVGSVGElement>(element))
+ svgElement = &element;
+ else if (is<SVGPathElement>(element) && is<SVGSVGElement>(element.parentElement()))
+ svgElement = element.parentElement();
+
+ if (svgElement && svgElement->hasAttributes()) {
+ auto ariaLabelAttr = svgElement->attributes().getNamedItem("aria-label");
+ if (ariaLabelAttr && ariaLabelAttr->value() == "UserFilled icon")
+ return true;
+ }
+
+ return false;
+}
+#endif
+
+Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(const Element& element, const AtomString& eventType) const
+{
#if ENABLE(RESOURCE_LOAD_STATISTICS)
if (!needsQuirks())
return Quirks::StorageAccessResult::ShouldNotCancelEvent;
@@ -865,36 +904,59 @@
set.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("theinventory.com"_s));
return set;
}();
- static NeverDestroyed<RegistrableDomain> kinjaDomain = RegistrableDomain::uncheckedCreateFromRegistrableDomainString("kinja.com"_s);
+ static NeverDestroyed<URL> kinjaURL = URL(URL(), "https://kinja.com");
+ static NeverDestroyed<RegistrableDomain> kinjaDomain { kinjaURL };
static NeverDestroyed<RegistrableDomain> youTubeDomain = RegistrableDomain::uncheckedCreateFromRegistrableDomainString("youtube.com"_s);
+
+ static NeverDestroyed<String> loginPopupWindowFeatureString = "toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=599,height=600,top=420,left=980.5"_s;
+ static NeverDestroyed<UserScript> kinjaLoginUserScript { "function triggerLoginForm() { let elements = document.getElementsByClassName('js_header-userbutton'); if (elements && elements[0]) { elements[0].click(); clearInterval(interval); } } let interval = setInterval(triggerLoginForm, 200);", URL(aboutBlankURL()), Vector<String>(), Vector<String>(), UserScriptInjectionTime::DocumentEnd, UserContentInjectedFrames::InjectInTopFrameOnly, WaitForNotificationBeforeInjecting::Yes };
+
if (eventType == "click") {
// Embedded YouTube case.
- if (domain == youTubeDomain && !m_document->isTopDocument() && ResourceLoadObserver::shared().hasHadUserInteraction(youTubeDomain) && (classNames.contains("ytp-watch-later-icon") || classNames.contains("ytp-watch-later-icon"))) {
- if (ResourceLoadObserver::shared().hasHadUserInteraction(youTubeDomain)) {
- DocumentStorageAccess::requestStorageAccessForDocumentQuirk(*m_document, [](StorageAccessWasGranted) {
- // FIXME: Add appropriate logging.
- });
- return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+ if (element.hasClass() && domain == youTubeDomain && !m_document->isTopDocument() && ResourceLoadObserver::shared().hasHadUserInteraction(youTubeDomain)) {
+ auto& classNames = element.classNames();
+ if (classNames.contains("ytp-watch-later-icon") || classNames.contains("ytp-watch-later-icon")) {
+ if (ResourceLoadObserver::shared().hasHadUserInteraction(youTubeDomain)) {
+ DocumentStorageAccess::requestStorageAccessForDocumentQuirk(*m_document, [](StorageAccessWasGranted) { });
+ return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+ }
}
+ return Quirks::StorageAccessResult::ShouldNotCancelEvent;
}
- // Kinja burner account login case.
- if (kinjaQuirks.get().contains(domain) && classNames.contains("js_switch-to-burner-login")) {
+ // Kinja login case.
+ if (kinjaQuirks.get().contains(domain) && isKinjaLoginAvatarElement(element)) {
if (ResourceLoadObserver::shared().hasHadUserInteraction(kinjaDomain)) {
- DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, kinjaDomain.get().isolatedCopy(), [](StorageAccessWasGranted) {
- // FIXME: Add appropriate logging.
- });
+ DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, kinjaDomain.get().isolatedCopy(), [](StorageAccessWasGranted) { });
return Quirks::StorageAccessResult::ShouldNotCancelEvent;
}
- // FIXME: Take the user to kinja.com in the else case.
+
+ auto* domWindow = m_document->domWindow();
+ if (!domWindow)
+ return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+
+ ExceptionOr<RefPtr<WindowProxy>> proxyOrException = domWindow->open(*domWindow, *domWindow, kinjaURL->string(), emptyString(), loginPopupWindowFeatureString);
+ if (proxyOrException.hasException())
+ return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+ auto proxy = proxyOrException.releaseReturnValue();
+
+ auto* abstractFrame = proxy->frame();
+ if (abstractFrame && is<Frame>(*abstractFrame)) {
+ auto& frame = downcast<Frame>(*abstractFrame);
+ if (auto* page = frame.page()) {
+ auto world = ScriptController::createWorld("kinjaComQuirkWorld", ScriptController::WorldType::User);
+ page->addUserScriptAwaitingNotification(world.get(), kinjaLoginUserScript);
+ return Quirks::StorageAccessResult::ShouldCancelEvent;
+ }
+ }
}
}
#else
+ UNUSED_PARAM(element);
UNUSED_PARAM(eventType);
- UNUSED_PARAM(classNames);
#endif
return Quirks::StorageAccessResult::ShouldNotCancelEvent;
}
Modified: trunk/Source/WebCore/page/Quirks.h (263991 => 263992)
--- trunk/Source/WebCore/page/Quirks.h 2020-07-06 22:25:04 UTC (rev 263991)
+++ trunk/Source/WebCore/page/Quirks.h 2020-07-06 23:01:18 UTC (rev 263992)
@@ -36,7 +36,6 @@
class EventTarget;
class HTMLElement;
class LayoutUnit;
-class SpaceSplitString;
class Quirks {
WTF_MAKE_NONCOPYABLE(Quirks); WTF_MAKE_FAST_ALLOCATED;
@@ -107,7 +106,7 @@
bool shouldAvoidPastingImagesAsWebContent() const;
enum StorageAccessResult : bool { ShouldNotCancelEvent, ShouldCancelEvent };
- StorageAccessResult triggerOptionalStorageAccessQuirk(const AtomString& eventType, const SpaceSplitString& classNames) const;
+ StorageAccessResult triggerOptionalStorageAccessQuirk(const Element&, const AtomString& eventType) const;
private:
bool needsQuirks() const;
@@ -117,6 +116,10 @@
bool isGoogleMaps() const;
#endif
+#if ENABLE(RESOURCE_LOAD_STATISTICS)
+ bool isKinjaLoginAvatarElement(const Element&) const;
+#endif
+
WeakPtr<Document> m_document;
mutable Optional<bool> m_hasBrokenEncryptedMediaAPISupportQuirk;