Move the remaining code to decide whether site specific quirks are needed to Quirks...
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2019 11:38:49 +0000 (11:38 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Mar 2019 11:38:49 +0000 (11:38 +0000)
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:

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/fetch/FetchRequest.cpp
Source/WebCore/html/HTMLFormControlElement.cpp
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/MediaElementSession.cpp
Source/WebCore/page/Quirks.cpp
Source/WebCore/page/Quirks.h

index e4b6b38..54aa38c 100644 (file)
@@ -1,3 +1,40 @@
+2019-03-12  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <eocanha@igalia.com>
 
         [Media][MSE] Don't emit timeUpdate after play() if currentTime hasn't changed
index d49fce6..c121f08 100644 (file)
@@ -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 @@ ExceptionOr<void> FetchRequest::initializeOptions(const Init& init)
     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.");
index b24a06f..47cac57 100644 (file)
@@ -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 @@ AutofillData HTMLFormControlElement::autofillData() const
 // 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
index c81873c..641f7c7 100644 (file)
@@ -661,17 +661,6 @@ HTMLMediaElement::~HTMLMediaElement()
     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 @@ SuccessOr<MediaPlaybackDenialReason> HTMLMediaElement::canTransitionFromAutoplay
 
 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 @@ void HTMLMediaElement::didReceiveRemoteControlCommand(PlatformMediaSession::Remo
     }
 }
 
-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
index 2d7f1b7..d330248 100644 (file)
@@ -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 @@ void MediaElementSession::removeBehaviorRestriction(BehaviorRestrictions restric
     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 @@ SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackPermitted() co
     }
 #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");
index 781a3d3..a2b2843 100644 (file)
 #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(Document& document)
 
 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::hasBrokenEncryptedMediaAPISupportQuirk() const
 
 bool Quirks::hasWebSQLSupportQuirk() const
 {
-    if (!m_document || !m_document->settings().needsSiteSpecificQuirks())
+    if (!needsQuirks())
         return false;
     
     if (m_hasWebSQLSupportQuirk)
@@ -69,9 +147,9 @@ bool Quirks::hasWebSQLSupportQuirk() const
     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();
 }
index 2c6a77e..84e8838 100644 (file)
@@ -37,10 +37,18 @@ public:
     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;