Title: [220168] branches/safari-604-branch/Source/WebCore

Diff

Modified: branches/safari-604-branch/Source/WebCore/ChangeLog (220167 => 220168)


--- branches/safari-604-branch/Source/WebCore/ChangeLog	2017-08-03 01:32:57 UTC (rev 220167)
+++ branches/safari-604-branch/Source/WebCore/ChangeLog	2017-08-03 01:33:03 UTC (rev 220168)
@@ -1,5 +1,26 @@
 2017-08-02  Jason Marcell  <[email protected]>
 
+        Cherry-pick r220077. rdar://problem/33687398
+
+    2017-07-28  Matt Rajca  <[email protected]>
+
+            Propagate user gesture tokens when script elements are loaded.
+            https://bugs.webkit.org/show_bug.cgi?id=174959
+
+            Reviewed by Eric Carlson.
+
+            Propagate user gesture tokens when script elements are loaded (i.e. between the time an
+            element is created and its onload handler is invoked).
+
+            * dom/ScriptElement.cpp:
+            (WebCore::ScriptElement::ScriptElement):
+            (WebCore::ScriptElement::dispatchLoadEventRespectingUserGestureIndicator):
+            (WebCore::ScriptElement::executeScriptAndDispatchEvent):
+            (WebCore::ScriptElement::executePendingScript):
+            * dom/ScriptElement.h:
+
+2017-08-02  Jason Marcell  <[email protected]>
+
         Cherry-pick r220035. rdar://problem/33687398
 
     2017-07-28  Matt Rajca  <[email protected]>

Modified: branches/safari-604-branch/Source/WebCore/dom/ScriptElement.cpp (220167 => 220168)


--- branches/safari-604-branch/Source/WebCore/dom/ScriptElement.cpp	2017-08-03 01:32:57 UTC (rev 220167)
+++ branches/safari-604-branch/Source/WebCore/dom/ScriptElement.cpp	2017-08-03 01:33:03 UTC (rev 220168)
@@ -56,6 +56,8 @@
 
 namespace WebCore {
 
+static const auto maxUserGesturePropagationTime = 1_s;
+
 ScriptElement::ScriptElement(Element& element, bool parserInserted, bool alreadyStarted)
     : m_element(element)
     , m_startLineNumber(WTF::OrdinalNumber::beforeFirst())
@@ -69,6 +71,8 @@
     , m_forceAsync(!parserInserted)
     , m_willExecuteInOrder(false)
     , m_isModuleScript(false)
+    , m_creationTime(MonotonicTime::now())
+    , m_userGestureToken(UserGestureIndicator::currentUserGesture())
 {
     if (parserInserted && m_element.document().scriptableDocumentParser() && !m_element.document().isInDocumentWrite())
         m_startLineNumber = m_element.document().scriptableDocumentParser()->textPosition().m_line;
@@ -410,6 +414,17 @@
     frame->script().linkAndEvaluateModuleScript(loadableModuleScript);
 }
 
+void ScriptElement::dispatchLoadEventRespectingUserGestureIndicator()
+{
+    if (MonotonicTime::now() - m_creationTime > maxUserGesturePropagationTime) {
+        dispatchLoadEvent();
+        return;
+    }
+
+    UserGestureIndicator indicator(m_userGestureToken);
+    dispatchLoadEvent();
+}
+
 void ScriptElement::executeScriptAndDispatchEvent(LoadableScript& loadableScript)
 {
     if (std::optional<LoadableScript::Error> error = loadableScript.error()) {
@@ -419,7 +434,7 @@
     } else if (!loadableScript.wasCanceled()) {
         ASSERT(!loadableScript.error());
         loadableScript.execute(*this);
-        dispatchLoadEvent();
+        dispatchLoadEventRespectingUserGestureIndicator();
     }
 }
 
@@ -431,7 +446,7 @@
         ASSERT(!pendingScript.error());
         ASSERT_WITH_MESSAGE(scriptType() == ScriptType::Classic, "Module script always have a loadableScript pointer.");
         executeClassicScript(ScriptSourceCode(scriptContent(), m_element.document().url(), pendingScript.startingPosition(), JSC::SourceProviderSourceType::Program, InlineClassicScript::create(*this)));
-        dispatchLoadEvent();
+        dispatchLoadEventRespectingUserGestureIndicator();
     }
 }
 

Modified: branches/safari-604-branch/Source/WebCore/dom/ScriptElement.h (220167 => 220168)


--- branches/safari-604-branch/Source/WebCore/dom/ScriptElement.h	2017-08-03 01:32:57 UTC (rev 220167)
+++ branches/safari-604-branch/Source/WebCore/dom/ScriptElement.h	2017-08-03 01:33:03 UTC (rev 220168)
@@ -23,6 +23,8 @@
 
 #include "ContainerNode.h"
 #include "LoadableScript.h"
+#include "UserGestureIndicator.h"
+#include <wtf/MonotonicTime.h>
 #include <wtf/text/TextPosition.h>
 
 namespace WebCore {
@@ -91,6 +93,7 @@
     std::optional<ScriptType> determineScriptType(LegacyTypeSupport) const;
     bool ignoresLoadRequest() const;
     bool isScriptForEventSupported() const;
+    void dispatchLoadEventRespectingUserGestureIndicator();
 
     bool requestClassicScript(const String& sourceURL);
     bool requestModuleScript(const TextPosition& scriptStartPosition);
@@ -121,6 +124,9 @@
     String m_characterEncoding;
     String m_fallbackCharacterEncoding;
     RefPtr<LoadableScript> m_loadableScript;
+
+    MonotonicTime m_creationTime;
+    RefPtr<UserGestureToken> m_userGestureToken;
 };
 
 // FIXME: replace with is/downcast<ScriptElement>.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to