Changeset 189445 in webkit


Ignore:
Timestamp:
Sep 6, 2015 11:40:21 AM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

XHR2 timeout property should allow late updates
https://bugs.webkit.org/show_bug.cgi?id=98156

Reviewed by Darin Adler.

Source/WebCore:

Adding a timer within XMLHttpRequest to handle timeouts for asynchronous requests.
This allows easy update of the timeout even after request is sent.
Timeout is still handled by the network backend for synchronous requests (Web worker context).

Covered by updated tests.

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::XMLHttpRequest): Adding timeout timer initialization.
(WebCore::XMLHttpRequest::setTimeout): Updating timeout timer state if request is sent.
(WebCore::XMLHttpRequest::createRequest): Starting timeout timer if needed.
(WebCore::XMLHttpRequest::internalAbort): Stopping timeout timer if needed.
(WebCore::XMLHttpRequest::didFail): Adding comment.
(WebCore::XMLHttpRequest::didFinishLoading): Stopping timeout timer if needed.

  • xml/XMLHttpRequest.h:

LayoutTests:

Activating test checking that timeout can be updated after request is sent.

  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides-expected.txt:
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides.js:
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overrides-expected.txt:
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r189440 r189445  
     12015-09-06  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        XHR2 timeout property should allow late updates
     4        https://bugs.webkit.org/show_bug.cgi?id=98156
     5
     6        Reviewed by Darin Adler.
     7
     8        Activating test checking that timeout can be updated after request is sent.
     9
     10        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides-expected.txt:
     11        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides.js:
     12        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overrides-expected.txt:
     13
    1142015-09-04  Jon Honeycutt  <jhoneycutt@apple.com>
    215
  • trunk/LayoutTests/http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides-expected.txt

    r150973 r189445  
    66PASS XHR2 Timeout Property Tests
    77PASS XHR2 Timeout Property Tests 1
     8PASS XHR2 Timeout Property Tests 2
    89
  • trunk/LayoutTests/http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overrides.js

    r150973 r189445  
    33
    44runTestRequests([ new RequestTracker(true, "timeout disabled after initially set", TIME_NORMAL_LOAD, TIME_REGULAR_TIMEOUT, 0),
    5                   // new RequestTracker(true, "timeout overrides load after a delay", TIME_NORMAL_LOAD, TIME_DELAY, TIME_REGULAR_TIMEOUT),
     5                  new RequestTracker(true, "timeout overrides load after a delay", TIME_NORMAL_LOAD, TIME_DELAY, TIME_REGULAR_TIMEOUT),
    66                  new RequestTracker(true, "timeout enabled after initially disabled", 0, TIME_REGULAR_TIMEOUT, TIME_NORMAL_LOAD) ]);
  • trunk/LayoutTests/http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overrides-expected.txt

    r150973 r189445  
    66PASS XHR2 Timeout Property Tests in Worker
    77PASS XHR2 Timeout Property Tests in Worker 1
     8PASS XHR2 Timeout Property Tests in Worker 2
    89
  • trunk/Source/WebCore/ChangeLog

    r189441 r189445  
     12015-09-06  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        XHR2 timeout property should allow late updates
     4        https://bugs.webkit.org/show_bug.cgi?id=98156
     5
     6        Reviewed by Darin Adler.
     7
     8        Adding a timer within XMLHttpRequest to handle timeouts for asynchronous requests.
     9        This allows easy update of the timeout even after request is sent.
     10        Timeout is still handled by the network backend for synchronous requests (Web worker context).
     11
     12        Covered by updated tests.
     13
     14        * xml/XMLHttpRequest.cpp:
     15        (WebCore::XMLHttpRequest::XMLHttpRequest): Adding timeout timer initialization.
     16        (WebCore::XMLHttpRequest::setTimeout): Updating timeout timer state if request is sent.
     17        (WebCore::XMLHttpRequest::createRequest): Starting timeout timer if needed.
     18        (WebCore::XMLHttpRequest::internalAbort): Stopping timeout timer if needed.
     19        (WebCore::XMLHttpRequest::didFail): Adding comment.
     20        (WebCore::XMLHttpRequest::didFinishLoading): Stopping timeout timer if needed.
     21        * xml/XMLHttpRequest.h:
     22
    1232015-09-05  Jaehun Lim  <ljaehun.lim@samsung.com>
    224
  • trunk/Source/WebCore/xml/XMLHttpRequest.cpp

    r188333 r189445  
    121121    , m_async(true)
    122122    , m_includeCredentials(false)
    123 #if ENABLE(XHR_TIMEOUT)
    124     , m_timeoutMilliseconds(0)
    125 #endif
    126123    , m_state(UNSENT)
    127124    , m_createdDocument(false)
     
    139136    , m_resumeTimer(*this, &XMLHttpRequest::resumeTimerFired)
    140137    , m_dispatchErrorOnResuming(false)
     138#if ENABLE(XHR_TIMEOUT)
     139    , m_timeoutTimer(*this, &XMLHttpRequest::didTimeout)
     140#endif
    141141{
    142142#ifndef NDEBUG
     
    273273
    274274#if ENABLE(XHR_TIMEOUT)
    275 void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionCode& ec)
    276 {
    277     // FIXME: Need to trigger or update the timeout Timer here, if needed. http://webkit.org/b/98156
    278     // XHR2 spec, 4.7.3. "This implies that the timeout attribute can be set while fetching is in progress. If that occurs it will still be measured relative to the start of fetching."
     275void XMLHttpRequest::setTimeout(unsigned timeout, ExceptionCode& ec)
     276{
    279277    if (scriptExecutionContext()->isDocument() && !m_async) {
    280278        logConsoleError(scriptExecutionContext(), "XMLHttpRequest.timeout cannot be set for synchronous HTTP(S) requests made from the window context.");
     
    283281    }
    284282    m_timeoutMilliseconds = timeout;
     283    if (!m_timeoutTimer.isActive())
     284        return;
     285    if (!m_timeoutMilliseconds) {
     286        m_timeoutTimer.stop();
     287        return;
     288    }
     289    std::chrono::duration<double> interval = std::chrono::milliseconds { m_timeoutMilliseconds } - (std::chrono::steady_clock::now() - m_sendingTime);
     290    m_timeoutTimer.startOneShot(std::max(0.0, interval.count()));
    285291}
    286292#endif
     
    768774
    769775#if ENABLE(XHR_TIMEOUT)
    770     if (m_timeoutMilliseconds)
    771         request.setTimeoutInterval(m_timeoutMilliseconds / 1000.0);
     776    if (m_timeoutMilliseconds) {
     777        if (!m_async)
     778            request.setTimeoutInterval(m_timeoutMilliseconds / 1000.0);
     779        else {
     780            m_sendingTime = std::chrono::steady_clock::now();
     781            m_timeoutTimer.startOneShot(std::chrono::milliseconds { m_timeoutMilliseconds });
     782        }
     783    }
    772784#endif
    773785
     
    835847
    836848    m_decoder = nullptr;
     849
     850#if ENABLE(XHR_TIMEOUT)
     851    if (m_timeoutTimer.isActive())
     852        m_timeoutTimer.stop();
     853#endif
    837854
    838855    if (!m_loader)
     
    10791096
    10801097#if ENABLE(XHR_TIMEOUT)
     1098    // In case of worker sync timeouts.
    10811099    if (error.isTimeout()) {
    10821100        didTimeout();
     
    11191137    m_responseEncoding = String();
    11201138    m_decoder = nullptr;
     1139
     1140#if ENABLE(XHR_TIMEOUT)
     1141    if (m_timeoutTimer.isActive())
     1142        m_timeoutTimer.stop();
     1143#endif
    11211144
    11221145    if (hadLoader)
  • trunk/Source/WebCore/xml/XMLHttpRequest.h

    r182544 r189445  
    115115    Blob* optionalResponseBlob() const { return m_responseBlob.get(); }
    116116#if ENABLE(XHR_TIMEOUT)
    117     unsigned long timeout() const { return m_timeoutMilliseconds; }
    118     void setTimeout(unsigned long timeout, ExceptionCode&);
     117    unsigned timeout() const { return m_timeoutMilliseconds; }
     118    void setTimeout(unsigned timeout, ExceptionCode&);
    119119#endif
    120120
     
    217217    bool m_async;
    218218    bool m_includeCredentials;
    219 #if ENABLE(XHR_TIMEOUT)
    220     unsigned long m_timeoutMilliseconds;
    221 #endif
    222219    RefPtr<Blob> m_responseBlob;
    223220
     
    260257    Timer m_resumeTimer;
    261258    bool m_dispatchErrorOnResuming;
     259
     260#if ENABLE(XHR_TIMEOUT)
     261    unsigned m_timeoutMilliseconds { 0 };
     262    std::chrono::steady_clock::time_point m_sendingTime;
     263    Timer m_timeoutTimer;
     264#endif
    262265};
    263266
Note: See TracChangeset for help on using the changeset viewer.