Title: [242792] trunk/Source/WebCore
Revision
242792
Author
[email protected]
Date
2019-03-12 04:38:49 -0700 (Tue, 12 Mar 2019)

Log Message

Move the remaining code to decide whether site specific quirks are needed to Quirks class
https://bugs.webkit.org/show_bug.cgi?id=195610

Reviewed by Antti Koivisto.

Moved the remaining code scattered across WebCore to decide whether a site specific quirk
is needed or not to Quirks class introduced in r236818.

* Modules/fetch/FetchRequest.cpp:
(WebCore::needsSignalQuirk): Deleted.
(WebCore::processInvalidSignal):
* html/HTMLFormControlElement.cpp:
(WebCore::HTMLFormControlElement::needsMouseFocusableQuirk const):
* html/HTMLMediaElement.cpp:
(WebCore::needsAutoplayPlayPauseEventsQuirk): Deleted.
(WebCore::HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks):
(WebCore::needsSeekingSupportQuirk): Deleted.
(WebCore::HTMLMediaElement::supportsSeeking const):
* html/MediaElementSession.cpp:
(WebCore::needsArbitraryUserGestureAutoplayQuirk): Deleted.
(WebCore::needsPerDocumentAutoplayBehaviorQuirk): Deleted.
(WebCore::MediaElementSession::playbackPermitted const):
* page/Quirks.cpp:
(WebCore::allowedAutoplayQuirks): Added.
(WebCore::Quirks::needsQuirks const): Added.
(WebCore::Quirks::shouldIgnoreInvalidSignal const): Added.
(WebCore::Quirks::needsFormControlToBeMouseFocusable const): Added.
(WebCore::Quirks::needsAutoplayPlayPauseEvents const): Added.
(WebCore::Quirks::needsSeekingSupportDisabled const): Addd.
(WebCore::Quirks::needsPerDocumentAutoplayBehavior const): Added.
(WebCore::Quirks::shouldAutoplayForArbitraryUserGesture const): Added.
(WebCore::Quirks::hasBrokenEncryptedMediaAPISupportQuirk const): Added.
(WebCore::Quirks::hasWebSQLSupportQuirk const): Fixed the coding style.
* page/Quirks.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (242791 => 242792)


--- trunk/Source/WebCore/ChangeLog	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/ChangeLog	2019-03-12 11:38:49 UTC (rev 242792)
@@ -1,3 +1,40 @@
+2019-03-12  Ryosuke Niwa  <[email protected]>
+
+        Move the remaining code to decide whether site specific quirks are needed to Quirks class
+        https://bugs.webkit.org/show_bug.cgi?id=195610
+
+        Reviewed by Antti Koivisto.
+
+        Moved the remaining code scattered across WebCore to decide whether a site specific quirk
+        is needed or not to Quirks class introduced in r236818.
+
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::needsSignalQuirk): Deleted.
+        (WebCore::processInvalidSignal):
+        * html/HTMLFormControlElement.cpp:
+        (WebCore::HTMLFormControlElement::needsMouseFocusableQuirk const):
+        * html/HTMLMediaElement.cpp:
+        (WebCore::needsAutoplayPlayPauseEventsQuirk): Deleted.
+        (WebCore::HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks):
+        (WebCore::needsSeekingSupportQuirk): Deleted.
+        (WebCore::HTMLMediaElement::supportsSeeking const):
+        * html/MediaElementSession.cpp:
+        (WebCore::needsArbitraryUserGestureAutoplayQuirk): Deleted.
+        (WebCore::needsPerDocumentAutoplayBehaviorQuirk): Deleted.
+        (WebCore::MediaElementSession::playbackPermitted const):
+        * page/Quirks.cpp:
+        (WebCore::allowedAutoplayQuirks): Added.
+        (WebCore::Quirks::needsQuirks const): Added.
+        (WebCore::Quirks::shouldIgnoreInvalidSignal const): Added.
+        (WebCore::Quirks::needsFormControlToBeMouseFocusable const): Added.
+        (WebCore::Quirks::needsAutoplayPlayPauseEvents const): Added.
+        (WebCore::Quirks::needsSeekingSupportDisabled const): Addd.
+        (WebCore::Quirks::needsPerDocumentAutoplayBehavior const): Added.
+        (WebCore::Quirks::shouldAutoplayForArbitraryUserGesture const): Added.
+        (WebCore::Quirks::hasBrokenEncryptedMediaAPISupportQuirk const): Added.
+        (WebCore::Quirks::hasWebSQLSupportQuirk const): Fixed the coding style.
+        * page/Quirks.h:
+
 2019-03-12  Enrique Ocaña González  <[email protected]>
 
         [Media][MSE] Don't emit timeUpdate after play() if currentTime hasn't changed

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (242791 => 242792)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2019-03-12 11:38:49 UTC (rev 242792)
@@ -33,6 +33,7 @@
 #include "HTTPParsers.h"
 #include "JSAbortSignal.h"
 #include "Logging.h"
+#include "Quirks.h"
 #include "ScriptExecutionContext.h"
 #include "SecurityOrigin.h"
 #include "Settings.h"
@@ -144,25 +145,12 @@
     return { };
 }
 
-static inline bool needsSignalQuirk(ScriptExecutionContext& context)
-{
-    if (!is<Document>(context))
-        return false;
-
-    auto& document = downcast<Document>(context);
-    if (!document.settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto host = document.topDocument().url().host();
-    return equalLettersIgnoringASCIICase(host, "www.thrivepatientportal.com");
-}
-
 static inline Optional<Exception> processInvalidSignal(ScriptExecutionContext& context)
 {
     ASCIILiteral message { "FetchRequestInit.signal should be undefined, null or an AbortSignal object."_s };
     context.addConsoleMessage(MessageSource::JS, MessageLevel::Warning, message);
 
-    if (needsSignalQuirk(context))
+    if (is<Document>(context) && downcast<Document>(context).quirks().shouldIgnoreInvalidSignal())
         return { };
 
     RELEASE_LOG_ERROR(ResourceLoading, "FetchRequestInit.signal should be undefined, null or an AbortSignal object.");

Modified: trunk/Source/WebCore/html/HTMLFormControlElement.cpp (242791 => 242792)


--- trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/html/HTMLFormControlElement.cpp	2019-03-12 11:38:49 UTC (rev 242792)
@@ -38,6 +38,7 @@
 #include "HTMLInputElement.h"
 #include "HTMLLegendElement.h"
 #include "HTMLTextAreaElement.h"
+#include "Quirks.h"
 #include "RenderBox.h"
 #include "RenderTheme.h"
 #include "Settings.h"
@@ -672,15 +673,7 @@
 // FIXME: We should remove the quirk once <rdar://problem/47334655> is fixed.
 bool HTMLFormControlElement::needsMouseFocusableQuirk() const
 {
-#if PLATFORM(MAC)
-    if (!document().settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto host = document().url().host();
-    return equalLettersIgnoringASCIICase(host, "ceac.state.gov") || host.endsWithIgnoringASCIICase(".ceac.state.gov");
-#else
-    return false;
-#endif
+    return document().quirks().needsFormControlToBeMouseFocusable();
 }
 
 } // namespace Webcore

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (242791 => 242792)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2019-03-12 11:38:49 UTC (rev 242792)
@@ -661,17 +661,6 @@
     m_mediaSession = nullptr;
     schedulePlaybackControlsManagerUpdate();
 }
-
-static bool needsAutoplayPlayPauseEventsQuirk(const Document& document)
-{
-    auto* page = document.page();
-    if (!page || !page->settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto loader = makeRefPtr(document.loader());
-    return loader && loader->allowedAutoplayQuirks().contains(AutoplayQuirk::SynthesizedPauseEvents);
-}
-
 RefPtr<HTMLMediaElement> HTMLMediaElement::bestMediaElementForShowingPlaybackControlsManager(MediaElementSession::PlaybackControlsPurpose purpose)
 {
     auto allSessions = PlatformMediaSessionManager::sharedManager().currentSessionsMatching([] (const PlatformMediaSession& session) {
@@ -2450,8 +2439,7 @@
 
 void HTMLMediaElement::dispatchPlayPauseEventsIfNeedsQuirks()
 {
-    auto& document = this->document();
-    if (!needsAutoplayPlayPauseEventsQuirk(document) && !needsAutoplayPlayPauseEventsQuirk(document.topDocument()))
+    if (!document().quirks().needsAutoplayPlayPauseEvents())
         return;
 
     ALWAYS_LOG(LOGIDENTIFIER);
@@ -7718,18 +7706,9 @@
     }
 }
 
-static bool needsSeekingSupportQuirk(Document& document)
-{
-    if (!document.settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto host = document.topDocument().url().host();
-    return equalLettersIgnoringASCIICase(host, "netflix.com") || host.endsWithIgnoringASCIICase(".netflix.com");
-}
-
 bool HTMLMediaElement::supportsSeeking() const
 {
-    return !needsSeekingSupportQuirk(document()) && !isLiveStream();
+    return !document().quirks().needsSeekingSupportDisabled() && !isLiveStream();
 }
 
 bool HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction(PlatformMediaSession::InterruptionType type) const

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (242791 => 242792)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2019-03-12 11:38:49 UTC (rev 242792)
@@ -41,6 +41,7 @@
 #include "Logging.h"
 #include "Page.h"
 #include "PlatformMediaSessionManager.h"
+#include "Quirks.h"
 #include "RenderMedia.h"
 #include "RenderView.h"
 #include "ScriptController.h"
@@ -244,26 +245,6 @@
     m_restrictions &= ~restriction;
 }
 
-#if PLATFORM(MAC)
-static bool needsArbitraryUserGestureAutoplayQuirk(const Document& document)
-{
-    if (!document.settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto loader = makeRefPtr(document.loader());
-    return loader && loader->allowedAutoplayQuirks().contains(AutoplayQuirk::ArbitraryUserGestures);
-}
-#endif // PLATFORM(MAC)
-
-static bool needsPerDocumentAutoplayBehaviorQuirk(const Document& document)
-{
-    if (!document.settings().needsSiteSpecificQuirks())
-        return false;
-
-    auto loader = makeRefPtr(document.loader());
-    return loader && loader->allowedAutoplayQuirks().contains(AutoplayQuirk::PerDocumentAutoplayBehavior);
-}
-
 SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackPermitted() const
 {
     if (m_element.isSuspended()) {
@@ -301,14 +282,13 @@
     }
 #endif
 
+    // FIXME: Why are we checking top-level document only for PerDocumentAutoplayBehavior?
     const auto& topDocument = document.topDocument();
-    if (topDocument.mediaState() & MediaProducer::HasUserInteractedWithMediaElement && needsPerDocumentAutoplayBehaviorQuirk(topDocument))
+    if (topDocument.mediaState() & MediaProducer::HasUserInteractedWithMediaElement && topDocument.quirks().needsPerDocumentAutoplayBehavior())
         return { };
 
-#if PLATFORM(MAC)
-    if (document.hasHadUserInteraction() && needsArbitraryUserGestureAutoplayQuirk(document))
+    if (document.hasHadUserInteraction() && document.quirks().shouldAutoplayForArbitraryUserGesture())
         return { };
-#endif
 
     if (m_restrictions & RequireUserGestureForVideoRateChange && m_element.isVideo() && !document.processingUserGestureForMedia()) {
         ALWAYS_LOG(LOGIDENTIFIER, "Returning FALSE because a user gesture is required for video rate change restriction");

Modified: trunk/Source/WebCore/page/Quirks.cpp (242791 => 242792)


--- trunk/Source/WebCore/page/Quirks.cpp	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/page/Quirks.cpp	2019-03-12 11:38:49 UTC (rev 242792)
@@ -27,10 +27,22 @@
 #include "Quirks.h"
 
 #include "Document.h"
+#include "DocumentLoader.h"
+#include "HTMLMetaElement.h"
+#include "HTMLObjectElement.h"
 #include "Settings.h"
 
 namespace WebCore {
 
+static inline OptionSet<AutoplayQuirk> allowedAutoplayQuirks(Document& document)
+{
+    auto* loader = document.loader();
+    if (!loader)
+        return { };
+
+    return loader->allowedAutoplayQuirks();
+}
+
 Quirks::Quirks(Document& document)
     : m_document(makeWeakPtr(document))
 {
@@ -38,9 +50,75 @@
 
 Quirks::~Quirks() = default;
 
+inline bool Quirks::needsQuirks() const
+{
+    return m_document && m_document->settings().needsSiteSpecificQuirks();
+}
+
+bool Quirks::shouldIgnoreInvalidSignal() const
+{
+    if (!needsQuirks())
+        return false;
+
+    auto host = m_document->topDocument().url().host();
+    return equalLettersIgnoringASCIICase(host, "www.thrivepatientportal.com");
+}
+
+bool Quirks::needsFormControlToBeMouseFocusable() const
+{
+#if PLATFORM(MAC)
+    if (!needsQuirks())
+        return false;
+
+    auto host = m_document->url().host();
+    return equalLettersIgnoringASCIICase(host, "ceac.state.gov") || host.endsWithIgnoringASCIICase(".ceac.state.gov");
+#else
+    return false;
+#endif
+}
+
+bool Quirks::needsAutoplayPlayPauseEvents() const
+{
+    if (!needsQuirks())
+        return false;
+
+    if (allowedAutoplayQuirks(*m_document).contains(AutoplayQuirk::SynthesizedPauseEvents))
+        return true;
+
+    return allowedAutoplayQuirks(m_document->topDocument()).contains(AutoplayQuirk::SynthesizedPauseEvents);
+}
+
+bool Quirks::needsSeekingSupportDisabled() const
+{
+    if (!needsQuirks())
+        return false;
+
+    auto host = m_document->topDocument().url().host();
+    return equalLettersIgnoringASCIICase(host, "netflix.com") || host.endsWithIgnoringASCIICase(".netflix.com");
+}
+
+bool Quirks::needsPerDocumentAutoplayBehavior() const
+{
+#if PLATFORM(MAC)
+    ASSERT(m_document == &m_document->topDocument());
+    return needsQuirks() && allowedAutoplayQuirks(*m_document).contains(AutoplayQuirk::PerDocumentAutoplayBehavior);
+#else
+    return false;
+#endif
+}
+
+bool Quirks::shouldAutoplayForArbitraryUserGesture() const
+{
+#if PLATFORM(MAC)
+    return needsQuirks() && allowedAutoplayQuirks(*m_document).contains(AutoplayQuirk::ArbitraryUserGestures);
+#else
+    return false;
+#endif
+}
+
 bool Quirks::hasBrokenEncryptedMediaAPISupportQuirk() const
 {
-    if (!m_document || !m_document->settings().needsSiteSpecificQuirks())
+    if (!needsQuirks())
         return false;
 
     if (m_hasBrokenEncryptedMediaAPISupportQuirk)
@@ -60,7 +138,7 @@
 
 bool Quirks::hasWebSQLSupportQuirk() const
 {
-    if (!m_document || !m_document->settings().needsSiteSpecificQuirks())
+    if (!needsQuirks())
         return false;
     
     if (m_hasWebSQLSupportQuirk)
@@ -69,9 +147,9 @@
     auto domain = m_document->securityOrigin().domain().convertToASCIILowercase();
     
     m_hasWebSQLSupportQuirk = domain == "bostonglobe.com"
-    || domain.endsWith(".bostonglobe.com")
-    || domain == "latimes.com"
-    || domain.endsWith(".latimes.com");
+        || domain.endsWith(".bostonglobe.com")
+        || domain == "latimes.com"
+        || domain.endsWith(".latimes.com");
     
     return m_hasWebSQLSupportQuirk.value();
 }

Modified: trunk/Source/WebCore/page/Quirks.h (242791 => 242792)


--- trunk/Source/WebCore/page/Quirks.h	2019-03-12 11:09:45 UTC (rev 242791)
+++ trunk/Source/WebCore/page/Quirks.h	2019-03-12 11:38:49 UTC (rev 242792)
@@ -37,10 +37,18 @@
     Quirks(Document&);
     ~Quirks();
 
+    bool shouldIgnoreInvalidSignal() const;
+    bool needsFormControlToBeMouseFocusable() const;
+    bool needsAutoplayPlayPauseEvents() const;
+    bool needsSeekingSupportDisabled() const;
+    bool needsPerDocumentAutoplayBehavior() const;
+    bool shouldAutoplayForArbitraryUserGesture() const;
     bool hasBrokenEncryptedMediaAPISupportQuirk() const;
     bool hasWebSQLSupportQuirk() const;
 
 private:
+    bool needsQuirks() const;
+
     WeakPtr<Document> m_document;
 
     mutable Optional<bool> m_hasBrokenEncryptedMediaAPISupportQuirk;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to