<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>50386</bug_id>
          
          <creation_ts>2010-12-02 07:26:38 -0800</creation_ts>
          <short_desc>Event::fromUserGesture() should be based on Event creation</short_desc>
          <delta_ts>2010-12-03 22:20:09 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Kristian Monsen">kristianm</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>abarth</cc>
    
    <cc>ap</cc>
    
    <cc>jnd</cc>
    
    <cc>jorlow</cc>
    
    <cc>steveblock</cc>
    
    <cc>tony</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>316135</commentid>
    <comment_count>0</comment_count>
    <who name="Kristian Monsen">kristianm</who>
    <bug_when>2010-12-02 07:26:38 -0800</bug_when>
    <thetext>At the moment a Event is considered a UserGesture if UserGestureIndicator::processingUserGesture() returns true when the event is handled.

The correct thing to do is to base it on what UserGestureIndicator::processingUserGesture() returns when the event is created. If the JS engine handles the event on a different call stack, Event::fromUserGesture() should still return true.

This is similar to how ScheduledNavigation works.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316137</commentid>
    <comment_count>1</comment_count>
      <attachid>75374</attachid>
    <who name="Kristian Monsen">kristianm</who>
    <bug_when>2010-12-02 07:30:49 -0800</bug_when>
    <thetext>Created attachment 75374
Proposed patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316328</commentid>
    <comment_count>2</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-12-02 12:16:25 -0800</bug_when>
    <thetext>Shouldn&apos;t the &quot;other call stack&quot; just have UserGestureIndicator::processingUserGesture() respond appropriately?

It&apos;s best to implement unusual single platform features in a way that doesn&apos;t require modifications to core WebKit, as otherwise we&apos;d keep unknowingly breaking them.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316365</commentid>
    <comment_count>3</comment_count>
    <who name="Kristian Monsen">kristianm</who>
    <bug_when>2010-12-02 12:53:18 -0800</bug_when>
    <thetext>(In reply to comment #2)
&gt; Shouldn&apos;t the &quot;other call stack&quot; just have UserGestureIndicator::processingUserGesture() respond appropriately?
&gt; 
&gt; It&apos;s best to implement unusual single platform features in a way that doesn&apos;t require modifications to core WebKit, as otherwise we&apos;d keep unknowingly breaking them.

Hi Alexey, thanks for the review!

I didn&apos;t think it was Android related, which is why I wanted reviews here without Android guards. We are using V8, so I am quite sure it can be reproduced on other V8 platforms as well.

You are right that there are other solutions, but this should at least always be correct? To do it they way you suggest will require larger changes, and will depend on the JS implementation. The problem with this solution is that there might be many other similar problems.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316377</commentid>
    <comment_count>4</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-12-02 13:06:50 -0800</bug_when>
    <thetext>Yes, I don&apos;t see any specific problem with this patch - other that it leaves the code in a confusing state (when exactly can we use UserGestureIndicator::processingUserGesture() without breaking Android?).

There are some folks CC&apos;ed who recently worked on user gestures, and who would be better qualified to officially review this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>316935</commentid>
    <comment_count>5</comment_count>
    <who name="Johnny(Jianning) Ding">jnd</who>
    <bug_when>2010-12-03 11:45:53 -0800</bug_when>
    <thetext>Hi kristianm,
Thanks for your patch. I am not a reviewer, I recently work on the gesture APIs, so I&apos;d like to share my different point.

Yes, currently  Event is considered as a UserGesture if UserGestureIndicator::processingUserGesture() returns true when the event is handled, that is because when event is out of event handling process, it is not user gesture any more. The gesture status should not be cached when event is created.  Please take a look the following test case.

&lt;a onclick=&quot;alert(event.type);window.open(&apos;http://www.google.com&apos;)&quot; id=&quot;test&quot;&gt; open a new window &lt;/a&gt;
&lt;script&gt;
function dispatchEvent(obj, evt)  { 
  return function() {
     return obj.dispatchEvent(evt);
  }
}
function simulateClick() {
  var evt = document.createEvent(&quot;MouseEvents&quot;);
  evt.initMouseEvent(&quot;click&quot;, true, true, window,
    0, 0, 0, 0, 0, false, false, false, false, 0, null);
  var cb = document.getElementById(&quot;test&quot;); 
  setTimeout(dispatchEvent(cb, evt), 3000);
}
&lt;/script&gt;
&lt;input type=&quot;button&quot; onclick=&quot;simulateClick();&quot; value=&quot;click me&quot; id=&quot;btn&quot;&gt;

On this case, when clicking button &quot;click me&quot;, the evt is created and will be delayed to dispatch 3 seconds later and trigger a popup window to www.google.com.

In original gesture implementation, when the evt is dispatched, since the original real click event is gone, UserGestureIndicator::processingUserGesture() returns false, the popup window is considered as not user-initiated, the popup blocker can block it.

Using your way, the evt was created under a gesture and kept the status in this test case. When the evt is dispatched, it is considered as a user gesture, so the popup blocker let the popup window pass.  Some sites can use the way to create lots of events in a legal user-initiated event and dispatch them in any time they want, and popup blocker can not do anything under this case.

In NavigationScheduler, since there is no chance to create event, so it&apos;s fine to cache the gesture status.

Please correct me if I misunderstand your point. 

Adam is expert in the area, he may have more thoughts.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>317027</commentid>
    <comment_count>6</comment_count>
      <attachid>75374</attachid>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2010-12-03 13:42:26 -0800</bug_when>
    <thetext>Comment on attachment 75374
Proposed patch

That&apos;s quite convincing, marking r-.

We should probably land a test case like this to avoid future regressions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>317044</commentid>
    <comment_count>7</comment_count>
    <who name="Johnny(Jianning) Ding">jnd</who>
    <bug_when>2010-12-03 14:09:21 -0800</bug_when>
    <thetext>(In reply to comment #6)
&gt; (From update of attachment 75374 [details])
&gt; That&apos;s quite convincing, marking r-.
&gt; 
&gt; We should probably land a test case like this to avoid future regressions.

Will do.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>317214</commentid>
    <comment_count>8</comment_count>
    <who name="Johnny(Jianning) Ding">jnd</who>
    <bug_when>2010-12-03 19:06:17 -0800</bug_when>
    <thetext>Filed another bug https://bugs.webkit.org/show_bug.cgi?id=50508 and provided patch.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>75374</attachid>
            <date>2010-12-02 07:30:49 -0800</date>
            <delta_ts>2010-12-03 13:42:25 -0800</delta_ts>
            <desc>Proposed patch</desc>
            <filename>patch.txt</filename>
            <type>text/plain</type>
            <size>2805</size>
            <attacher name="Kristian Monsen">kristianm</attacher>
            
              <data encoding="base64">SW5kZXg6IFdlYkNvcmUvQ2hhbmdlTG9nCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIFdlYkNvcmUvQ2hhbmdlTG9n
CShyZXZpc2lvbiA3MzEzMCkKKysrIFdlYkNvcmUvQ2hhbmdlTG9nCSh3b3JraW5nIGNvcHkpCkBA
IC0xLDMgKzEsMjIgQEAKKzIwMTAtMTItMDIgIEtyaXN0aWFuIE1vbnNlbiAgPGtyaXN0aWFubUBn
b29nbGUuY29tPgorCisgICAgICAgIFJldmlld2VkIGJ5IE5PQk9EWSAoT09QUyEpLgorCisgICAg
ICAgIEV2ZW50Ojpmcm9tVXNlckdlc3R1cmUoKSBzaG91bGQgYmUgYmFzZWQgb24gRXZ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GFzZTsKICAgICAgICAgRXZlbnRUYXJnZXQqIG1fY3Vy
cmVudFRhcmdldDsK
</data>
<flag name="review"
          id="66161"
          type_id="1"
          status="-"
          setter="ap"
    />
    <flag name="commit-queue"
          id="66162"
          type_id="3"
          status="-"
          setter="ap"
    />
          </attachment>
      

    </bug>

</bugzilla>