Title: [271074] trunk/Source/WebCore
Revision
271074
Author
[email protected]
Date
2020-12-23 11:18:10 -0800 (Wed, 23 Dec 2020)

Log Message

Can't login to Skype from Microsoft Outlook account in Safari
https://bugs.webkit.org/show_bug.cgi?id=220106
<rdar://problem/72453487>

Reviewed by Alex Christensen.

This is a temporary quirk to assist a high-traffic website while they
complete the large task of migrating away from logins using
third party cookies. This quirk will be removed when the site is
updated.

No new tests, site-specific quirk.

Create a quirk that will call the Storage Access API on behalf of
Microsoft for skype.com under live.com. This patch also refactors
existing quirks to avoid lots of duplicate code.

* dom/DocumentStorageAccess.cpp:
(WebCore::DocumentStorageAccess::requestStorageAccessQuirk):
* page/Quirks.cpp:
Condense the code which calls the Storage Access API and handles the
click into one function Quirks::requestStorageAccessAndHandleClick.
Call this function if the domain/element pair matches the check in
Quirks::isStorageAccessQuirkDomainElementPair.

(WebCore::isStorageAccessQuirkDomainElementPair):
(WebCore::Quirks::requestStorageAccessAndHandleClick const):
(WebCore::Quirks::mapToTopDomain):
Moved from NetworkStorageSession and adjusted to check the host to
distinguish login.live.com from outlook.live.com which should be
treated differently.

(WebCore::Quirks::triggerOptionalStorageAccessQuirk const):
The BBC case can't be included in the same check as other domains with
quirks because we need to create a pop-up and inject _javascript_ based
on the user's response. So we still need to check for the BBC domain
separately.

(WebCore::isMicrosoftLoginElement): Deleted.
(WebCore::isMicrosoftDomain): Deleted.
(WebCore::isPlaystationLoginElement): Deleted.
* page/Quirks.h:
* platform/network/NetworkStorageSession.cpp:
(WebCore::NetworkStorageSession::storageAccessQuirks):
(WebCore::NetworkStorageSession::mapToTopDomain): Moved.
* platform/network/NetworkStorageSession.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (271073 => 271074)


--- trunk/Source/WebCore/ChangeLog	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/ChangeLog	2020-12-23 19:18:10 UTC (rev 271074)
@@ -1,3 +1,52 @@
+2020-12-23  Kate Cheney  <[email protected]>
+
+        Can't login to Skype from Microsoft Outlook account in Safari
+        https://bugs.webkit.org/show_bug.cgi?id=220106
+        <rdar://problem/72453487>
+
+        Reviewed by Alex Christensen.
+
+        This is a temporary quirk to assist a high-traffic website while they
+        complete the large task of migrating away from logins using
+        third party cookies. This quirk will be removed when the site is
+        updated.
+
+        No new tests, site-specific quirk.
+
+        Create a quirk that will call the Storage Access API on behalf of
+        Microsoft for skype.com under live.com. This patch also refactors
+        existing quirks to avoid lots of duplicate code.
+
+        * dom/DocumentStorageAccess.cpp:
+        (WebCore::DocumentStorageAccess::requestStorageAccessQuirk):
+        * page/Quirks.cpp:
+        Condense the code which calls the Storage Access API and handles the
+        click into one function Quirks::requestStorageAccessAndHandleClick.
+        Call this function if the domain/element pair matches the check in
+        Quirks::isStorageAccessQuirkDomainElementPair.
+
+        (WebCore::isStorageAccessQuirkDomainElementPair):
+        (WebCore::Quirks::requestStorageAccessAndHandleClick const):
+        (WebCore::Quirks::mapToTopDomain):
+        Moved from NetworkStorageSession and adjusted to check the host to
+        distinguish login.live.com from outlook.live.com which should be
+        treated differently.
+
+        (WebCore::Quirks::triggerOptionalStorageAccessQuirk const):
+        The BBC case can't be included in the same check as other domains with
+        quirks because we need to create a pop-up and inject _javascript_ based
+        on the user's response. So we still need to check for the BBC domain
+        separately.
+
+        (WebCore::isMicrosoftLoginElement): Deleted.
+        (WebCore::isMicrosoftDomain): Deleted.
+        (WebCore::isPlaystationLoginElement): Deleted.
+        * page/Quirks.h:
+        * platform/network/NetworkStorageSession.cpp:
+        (WebCore::NetworkStorageSession::storageAccessQuirks):
+        (WebCore::NetworkStorageSession::mapToTopDomain): Moved.
+        * platform/network/NetworkStorageSession.h:
+
 2020-12-23  Simon Fraser  <[email protected]>
 
         REGRESSION: Scroll snapping triggers body scroll

Modified: trunk/Source/WebCore/dom/DocumentStorageAccess.cpp (271073 => 271074)


--- trunk/Source/WebCore/dom/DocumentStorageAccess.cpp	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/dom/DocumentStorageAccess.cpp	2020-12-23 19:18:10 UTC (rev 271074)
@@ -266,7 +266,7 @@
     ASSERT(m_document.settings().storageAccessAPIEnabled());
     RELEASE_ASSERT(m_document.frame() && m_document.frame()->page());
 
-    auto topFrameDomain = NetworkStorageSession::mapToTopDomain(RegistrableDomain(m_document.topDocument().url()));
+    auto topFrameDomain = Quirks::mapToTopDomain(m_document.topDocument().url());
 
     m_document.frame()->page()->chrome().client().requestStorageAccess(WTFMove(requestingDomain), WTFMove(topFrameDomain), *m_document.frame(), m_storageAccessScope, [this, weakThis = makeWeakPtr(*this), completionHandler = WTFMove(completionHandler)] (RequestStorageAccessResult result) mutable {
         if (!weakThis)

Modified: trunk/Source/WebCore/page/Quirks.cpp (271073 => 271074)


--- trunk/Source/WebCore/page/Quirks.cpp	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/page/Quirks.cpp	2020-12-23 19:18:10 UTC (rev 271074)
@@ -963,35 +963,39 @@
     return false;
 }
 
-static bool isMicrosoftLoginElement(const Element& element)
-{
-    if (!element.hasClass())
-        return false;
-
-    auto& classNames = element.classNames();
-    return classNames.contains("glyph_signIn_circle") || classNames.contains("mectrl_headertext") || classNames.contains("mectrl_header") || classNames.contains("ext-button primary") || classNames.contains("ext-primary");
-}
-
-static bool isMicrosoftDomain(const RegistrableDomain& domain)
-{
-    static NeverDestroyed<RegistrableDomain> microsoftDotCom = RegistrableDomain::uncheckedCreateFromRegistrableDomainString("microsoft.com"_s);
-    static NeverDestroyed<RegistrableDomain> liveDotCom = RegistrableDomain::uncheckedCreateFromRegistrableDomainString("live.com"_s);
-
-    return domain == microsoftDotCom || domain == liveDotCom;
-}
-
 bool Quirks::isMicrosoftTeamsRedirectURL(const URL& url)
 {
     return url.host() == "teams.microsoft.com"_s && url.query().toString().contains("Retried+3+times+without+success");
 }
 
-static bool isPlaystationLoginElement(const Element& element)
+static bool isStorageAccessQuirkDomainAndElement(const URL& url, const Element& element)
 {
-    if (!element.hasClass())
-        return false;
+    // Microsoft Teams login case.
+    // FIXME(218779): Remove this quirk once microsoft.com completes their login flow redesign.
+    if (url.host() == "www.microsoft.com"_s || url.host() == "login.live.com"_s) {
+        return element.hasClass()
+        && (element.classNames().contains("glyph_signIn_circle")
+        || element.classNames().contains("mectrl_headertext")
+        || element.classNames().contains("mectrl_header")
+        || element.classNames().contains("ext-button primary")
+        || element.classNames().contains("ext-primary"));
+    }
+    // Skype case.
+    // FIXME(220105): Remove this quirk once Skype under outlook.live.com completes their login flow redesign.
+    if (url.host() == "outlook.live.com"_s) {
+        return element.hasClass()
+        && (element.classNames().contains("_3ioEp2RGR5vb0gqRDsaFPa")
+        || element.classNames().contains("_2Am2jvTaBz17UJ8XnfxFOy"));
+    }
+    // Sony Network Entertainment login case.
+    // FIXME(218760): Remove this quirk once playstation.com completes their login flow redesign.
+    if (url.host() == "www.playstation.com"_s || url.host() == "my.playstation.com"_s) {
+        return element.hasClass()
+        && (element.classNames().contains("web-toolbar__signin-button")
+        || element.classNames().contains("sb-signin-button"));
+    }
 
-    auto& classNames = element.classNames();
-    return classNames.contains("web-toolbar__signin-button") || classNames.contains("sb-signin-button");
+    return false;
 }
 
 bool Quirks::hasStorageAccessForAllLoginDomains(const HashSet<RegistrableDomain>& loginDomains, const RegistrableDomain& topFrameDomain)
@@ -1030,6 +1034,41 @@
     return element.parentElement()->classNames().contains("p_audioButton_buttonInner") && parentElement->parentElement()->classNames().contains("hidden");
 }
 
+Quirks::StorageAccessResult Quirks::requestStorageAccessAndHandleClick(CompletionHandler<void(StorageAccessWasGranted)>&& completionHandler) const
+{
+    auto firstPartyDomain = mapToTopDomain(m_document->topDocument().url());
+    auto domainsInNeedOfStorageAccess = NetworkStorageSession::subResourceDomainsInNeedOfStorageAccessForFirstParty(firstPartyDomain);
+    if (!domainsInNeedOfStorageAccess || domainsInNeedOfStorageAccess.value().isEmpty()) {
+        completionHandler(StorageAccessWasGranted::No);
+        return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+    }
+    if (hasStorageAccessForAllLoginDomains(*domainsInNeedOfStorageAccess, firstPartyDomain)) {
+        completionHandler(StorageAccessWasGranted::No);
+        return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+    }
+
+    auto domainInNeedOfStorageAccess = RegistrableDomain(*domainsInNeedOfStorageAccess.value().begin().get());
+
+    if (!m_document) {
+        completionHandler(StorageAccessWasGranted::No);
+        return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+    }
+
+    DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, WTFMove(domainInNeedOfStorageAccess), [firstPartyDomain, domainInNeedOfStorageAccess, completionHandler = WTFMove(completionHandler)](StorageAccessWasGranted storageAccessGranted) mutable {
+        ResourceLoadObserver::shared().setDomainsWithCrossPageStorageAccess({{ firstPartyDomain, domainInNeedOfStorageAccess }}, [storageAccessGranted, completionHandler = WTFMove(completionHandler)] () mutable {
+            completionHandler(storageAccessGranted);
+        });
+    });
+    return Quirks::StorageAccessResult::ShouldCancelEvent;
+}
+
+RegistrableDomain Quirks::mapToTopDomain(const URL& urlToMap)
+{
+    if (urlToMap.host() == "login.live.com"_s)
+        return RegistrableDomain::uncheckedCreateFromRegistrableDomainString("microsoft.com"_s);
+
+    return RegistrableDomain(urlToMap);
+}
 #endif
 
 Quirks::StorageAccessResult Quirks::triggerOptionalStorageAccessQuirk(Element& element, const PlatformMouseEvent& platformEvent, const AtomString& eventType, int detail, Element* relatedTarget) const
@@ -1108,47 +1147,14 @@
             }
         }
 
-        // Microsoft Teams login case.
-        // FIXME(218779): Remove this quirk once microsoft.com completes their login flow redesign.
-        if (isMicrosoftDomain(domain) && isMicrosoftLoginElement(element)) {
-            auto firstPartyDomain = NetworkStorageSession::mapToTopDomain(RegistrableDomain::uncheckedCreateFromHost(m_document->topDocument().securityOrigin().host()));
-            if (auto loginDomains = NetworkStorageSession::subResourceDomainsInNeedOfStorageAccessForFirstParty(firstPartyDomain)) {
-                if (!hasStorageAccessForAllLoginDomains(*loginDomains, firstPartyDomain)) {
-                    auto loginDomain = RegistrableDomain(*loginDomains.value().begin().get());
-                    DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, WTFMove(loginDomain), [firstPartyDomain, loginDomain, &element, platformEvent, eventType, detail, relatedTarget](StorageAccessWasGranted storageAccessGranted) mutable {
-                        if (storageAccessGranted == StorageAccessWasGranted::Yes) {
-                            ResourceLoadObserver::shared().setDomainsWithCrossPageStorageAccess({{ firstPartyDomain, loginDomain }}, [&element, platformEvent, eventType, detail, relatedTarget] {
-                                element.dispatchMouseEvent(platformEvent, eventType, detail, relatedTarget);
-                            });
-                        }
-                    });
-                    return Quirks::StorageAccessResult::ShouldCancelEvent;
-                }
-            }
-            return Quirks::StorageAccessResult::ShouldNotCancelEvent;
-        }
+        if (isStorageAccessQuirkDomainAndElement(m_document->url(), element)) {
+            return requestStorageAccessAndHandleClick([element = makeWeakPtr(element), platformEvent, eventType, detail, relatedTarget] (StorageAccessWasGranted storageAccessWasGranted) mutable {
+                if (!element)
+                    return;
 
-        // Sony Network Entertainment login case.
-        // FIXME(218760): Remove this quirk once playstation.com completes their login flow redesign.
-        static NeverDestroyed<RegistrableDomain> playStationDomain = RegistrableDomain::uncheckedCreateFromRegistrableDomainString("playstation.com"_s);
-        if (domain == playStationDomain && isPlaystationLoginElement(element)) {
-            auto firstPartyDomain = RegistrableDomain(m_document->topDocument().url());
-            if (auto loginDomains = NetworkStorageSession::subResourceDomainsInNeedOfStorageAccessForFirstParty(firstPartyDomain)) {
-                if (!hasStorageAccessForAllLoginDomains(*loginDomains, firstPartyDomain)) {
-                    // Send only one login domain to avoid changing existing Storage Access code, which can only handle a single domain.
-                    // We will match Sony login domains up when prompting the user and storing the domains.
-                    auto loginDomain = RegistrableDomain(*loginDomains.value().begin().get());
-                    DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, WTFMove(loginDomain), [firstPartyDomain, loginDomain, &element, platformEvent, eventType, detail, relatedTarget](StorageAccessWasGranted storageAccessGranted) mutable {
-                        if (storageAccessGranted == StorageAccessWasGranted::Yes) {
-                            ResourceLoadObserver::shared().setDomainsWithCrossPageStorageAccess({{ firstPartyDomain, loginDomain }}, [&element, platformEvent, eventType, detail, relatedTarget] {
-                                element.dispatchMouseEvent(platformEvent, eventType, detail, relatedTarget);
-                            });
-                        }
-                    });
-                    return Quirks::StorageAccessResult::ShouldCancelEvent;
-                }
-            }
-            return Quirks::StorageAccessResult::ShouldNotCancelEvent;
+                if (storageAccessWasGranted == StorageAccessWasGranted::Yes)
+                    element->dispatchMouseEvent(platformEvent, eventType, detail, relatedTarget);
+            });
         }
 
         static NeverDestroyed<String> BBCRadioPlayerPopUpWindowFeatureString = "featurestring width=400,height=730"_s;
@@ -1156,37 +1162,25 @@
 
         // BBC RadioPlayer case.
         if (isBBCDomain(domain) && isBBCPopUpPlayerElement(element)) {
-            auto firstPartyDomain = RegistrableDomain(m_document->topDocument().url());
-            auto subResourceDomainsInNeedOfStorageAccess = NetworkStorageSession::subResourceDomainsInNeedOfStorageAccessForFirstParty(firstPartyDomain);
-            if (!subResourceDomainsInNeedOfStorageAccess)
-                return Quirks::StorageAccessResult::ShouldNotCancelEvent;
-
-            if (hasStorageAccessForAllLoginDomains(*subResourceDomainsInNeedOfStorageAccess, firstPartyDomain))
-                return Quirks::StorageAccessResult::ShouldNotCancelEvent;
-
-            auto subResourceDomain = RegistrableDomain(*subResourceDomainsInNeedOfStorageAccess.value().begin().get());
-            DocumentStorageAccess::requestStorageAccessForNonDocumentQuirk(*m_document, WTFMove(subResourceDomain), [document = m_document, firstPartyDomain, subResourceDomain](StorageAccessWasGranted storageAccessGranted) mutable {
-                if (storageAccessGranted == StorageAccessWasGranted::No)
+            return requestStorageAccessAndHandleClick([document = m_document] (StorageAccessWasGranted storageAccessWasGranted) mutable {
+                if (!document || storageAccessWasGranted == StorageAccessWasGranted::No)
                     return;
 
-                ResourceLoadObserver::shared().setDomainsWithCrossPageStorageAccess({{ firstPartyDomain, subResourceDomain }}, [document = WTFMove(document)] {
-                    auto domWindow = document->domWindow();
-                    if (domWindow) {
-                        ExceptionOr<RefPtr<WindowProxy>> proxyOrException = domWindow->open(*domWindow, *domWindow, staticRadioPlayerURLString(), emptyString(), BBCRadioPlayerPopUpWindowFeatureString);
-                        if (proxyOrException.hasException())
-                            return;
-                        auto proxy = proxyOrException.releaseReturnValue();
-                        auto* abstractFrame = proxy->frame();
-                        if (is<Frame>(*abstractFrame)) {
-                            auto& frame = downcast<Frame>(*abstractFrame);
-                            auto world = ScriptController::createWorld("bbcRadioPlayerWorld", ScriptController::WorldType::User);
-                            frame.addUserScriptAwaitingNotification(world.get(), BBCUserScript);
-                            return;
-                        }
+                auto domWindow = document->domWindow();
+                if (domWindow) {
+                    ExceptionOr<RefPtr<WindowProxy>> proxyOrException = domWindow->open(*domWindow, *domWindow, staticRadioPlayerURLString(), emptyString(), BBCRadioPlayerPopUpWindowFeatureString);
+                    if (proxyOrException.hasException())
+                        return;
+                    auto proxy = proxyOrException.releaseReturnValue();
+                    auto* abstractFrame = proxy->frame();
+                    if (is<Frame>(abstractFrame)) {
+                        auto* frame = downcast<Frame>(abstractFrame);
+                        auto world = ScriptController::createWorld("bbcRadioPlayerWorld", ScriptController::WorldType::User);
+                        frame->addUserScriptAwaitingNotification(world.get(), BBCUserScript);
+                        return;
                     }
-                });
+                }
             });
-            return Quirks::StorageAccessResult::ShouldCancelEvent;
         }
     }
 #else

Modified: trunk/Source/WebCore/page/Quirks.h (271073 => 271074)


--- trunk/Source/WebCore/page/Quirks.h	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/page/Quirks.h	2020-12-23 19:18:10 UTC (rev 271074)
@@ -38,6 +38,7 @@
 class HTMLVideoElement;
 class LayoutUnit;
 class PlatformMouseEvent;
+enum class StorageAccessWasGranted : bool;
 
 class Quirks {
     WTF_MAKE_NONCOPYABLE(Quirks); WTF_MAKE_FAST_ALLOCATED;
@@ -127,6 +128,8 @@
     static bool hasStorageAccessForAllLoginDomains(const HashSet<RegistrableDomain>&, const RegistrableDomain&);
     static const String& BBCRadioPlayerURLString();
     WEBCORE_EXPORT static const String& staticRadioPlayerURLString();
+    StorageAccessResult requestStorageAccessAndHandleClick(CompletionHandler<void(StorageAccessWasGranted)>&&) const;
+    static RegistrableDomain mapToTopDomain(const URL&);
 #endif
 
 private:

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp (271073 => 271074)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.cpp	2020-12-23 19:18:10 UTC (rev 271074)
@@ -381,12 +381,14 @@
     return m_ageCapForClientSideCookies;
 }
 
-HashMap<RegistrableDomain, HashSet<RegistrableDomain>>& NetworkStorageSession::storageAccessQuirks()
+const HashMap<RegistrableDomain, HashSet<RegistrableDomain>>& NetworkStorageSession::storageAccessQuirks()
 {
     static NeverDestroyed<HashMap<RegistrableDomain, HashSet<RegistrableDomain>>> map = [] {
         HashMap<RegistrableDomain, HashSet<RegistrableDomain>> map;
         map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("microsoft.com"),
             HashSet { RegistrableDomain::uncheckedCreateFromRegistrableDomainString("microsoftonline.com"_s) });
+        map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("live.com"),
+            HashSet { RegistrableDomain::uncheckedCreateFromRegistrableDomainString("skype.com"_s) });
         map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("playstation.com"), HashSet {
             RegistrableDomain::uncheckedCreateFromRegistrableDomainString("sonyentertainmentnetwork.com"_s),
             RegistrableDomain::uncheckedCreateFromRegistrableDomainString("sony.com"_s) });
@@ -427,21 +429,6 @@
     return WTF::nullopt;
 }
 
-RegistrableDomain NetworkStorageSession::mapToTopDomain(const RegistrableDomain& domainToMap)
-{
-    static NeverDestroyed<HashMap<RegistrableDomain, RegistrableDomain>> map = [] {
-        HashMap<RegistrableDomain, RegistrableDomain> map;
-        map.add(RegistrableDomain::uncheckedCreateFromRegistrableDomainString("live.com"),
-            RegistrableDomain::uncheckedCreateFromRegistrableDomainString("microsoft.com"_s));
-        return map;
-    }();
-
-    auto it = map.get().find(domainToMap);
-    if (it != map.get().end())
-        return it->value;
-    return domainToMap;
-}
-
 #endif // ENABLE(RESOURCE_LOAD_STATISTICS)
 
 }

Modified: trunk/Source/WebCore/platform/network/NetworkStorageSession.h (271073 => 271074)


--- trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-12-23 19:13:41 UTC (rev 271073)
+++ trunk/Source/WebCore/platform/network/NetworkStorageSession.h	2020-12-23 19:18:10 UTC (rev 271074)
@@ -215,11 +215,10 @@
     WEBCORE_EXPORT void resetCrossSiteLoadsWithLinkDecorationForTesting();
     WEBCORE_EXPORT void setThirdPartyCookieBlockingMode(ThirdPartyCookieBlockingMode);
 
-    WEBCORE_EXPORT static HashMap<RegistrableDomain, HashSet<RegistrableDomain>>& storageAccessQuirks();
+    WEBCORE_EXPORT const static HashMap<RegistrableDomain, HashSet<RegistrableDomain>>& storageAccessQuirks();
     WEBCORE_EXPORT static bool canRequestStorageAccessForLoginOrCompatibilityPurposesWithoutPriorUserInteraction(const SubResourceDomain&, const TopFrameDomain&);
     WEBCORE_EXPORT static Optional<HashSet<RegistrableDomain>> subResourceDomainsInNeedOfStorageAccessForFirstParty(const RegistrableDomain&);
     WEBCORE_EXPORT static bool loginDomainMatchesRequestingDomain(const TopFrameDomain&, const SubResourceDomain&);
-    WEBCORE_EXPORT static RegistrableDomain mapToTopDomain(const RegistrableDomain&);
     WEBCORE_EXPORT static Optional<RegistrableDomain> findAdditionalLoginDomain(const TopFrameDomain&, const SubResourceDomain&);
 
 #endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to