Changeset 132252 in webkit


Ignore:
Timestamp:
Oct 23, 2012 11:49:20 AM (11 years ago)
Author:
dominik.rottsches@intel.com
Message:

Add timeout support to XMLHttpRequest
https://bugs.webkit.org/show_bug.cgi?id=74802

Reviewed by Nate Chapin.

Source/WebCore:

An implementation of XHR2 timeouts by using ResourceRequest's setTimeoutInterval.
This made several changes necessary in CachedResource and SubresourceLoader in order
to distinguish and forward the timeout case from there.

The case of late updates to the timeout property, changing the timeout value after send()
is not supported yet and handled separately in bug 98156.

XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
permission to reuse them under PD/BSD license
in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
I adapted them for W3C testharness.js and split them into groups with shorter test running time
so that they can be used as WebKit layout tests.

Tests: http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html

http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html
http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html

  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::notifyFinished): Forward information about timeout case.

  • loader/SubresourceLoader.cpp:

(WebCore::SubresourceLoader::didFail): Distinguish timeout case when informing client.

  • loader/cache/CachedResource.h: Distinguishing timeout case for errors.

(WebCore::CachedResource::errorOccurred):
(WebCore::CachedResource::loadFailedOrCanceled):
(WebCore::CachedResource::timedOut):

  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::XMLHttpRequest): Initializing m_timeout value to zero.
(WebCore::XMLHttpRequest::setTimeout): Setter function, possibly raising JS exception.
(WebCore):
(WebCore::XMLHttpRequest::open): Open call may raise exception for synchronous requests when timeout value is set.
(WebCore::XMLHttpRequest::createRequest): Assigning timeout value to ResourceRequest.
(WebCore::XMLHttpRequest::didFail): Handling timeout case separately.
(WebCore::XMLHttpRequest::didTimeout): Timeout case state transisition and event firing as spec'ed.

  • xml/XMLHttpRequest.h: New event listener, member and callback for handling timeout.

(WebCore::XMLHttpRequest::timeout):
(XMLHttpRequest):

  • xml/XMLHttpRequest.idl: New event listener and property added.
  • xml/XMLHttpRequestException.cpp:
  • xml/XMLHttpRequestException.h: Added an exception value for the timeout case.

LayoutTests:

XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
permission to reuse them under PD/BSD license
in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
I adapted them for W3C testharness.js and split them into groups with shorter test running time
so that they can be used as WebKit layout tests. Each individual test should
complete in less than 20 seconds.

The case of late updates to the timeout property, changing the timeout value after send()
is not supported yet and handled separately in bug 98156. Tests that are testing this feature
are commented out until this bug is tackled.

The suffix of the html test filename matches the groups in xmlhttprequest-timeout.js which contains
all tests that are run. The result of assertions is reported back to testharness.js.

For example, the "overrides" group is currently not run yet since all tests in that group are cases
of late updates, see above. Once late updates are supported we can add a file
xmlhttprequest-timeout-overrides.html to run them.

  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-runner.js: Added. Distinguishes which group of tests to run based on filename suffix.

(testResultCallbackHandler.return):
(groupFromLocation):

  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice-expected.txt: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html: Added.
  • http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout.js: Added. Contains test cases for all individual test html files.

(message): Wrapper for postMessage in worker and document context case.
(is),
(ok): Assertion functions.
(RequestTracker): Class for variations of the regular timeout case.
(RequestTracker.prototype.startXHR.handleEvent):
(RequestTracker.prototype.startXHR):
(RequestTracker.prototype.getMessage):
(RequestTracker.prototype.handleEvent):
(AbortedRequest): Class for testing timeout event vs. abort events.
(AbortedRequest.prototype.startXHR.handleEvent):
(AbortedRequest.prototype.startXHR.abortReq):
(AbortedRequest.prototype.startXHR.else):
(AbortedRequest.prototype.startXHR):
(AbortedRequest.prototype.noEventsFired):
(AbortedRequest.prototype.getMessage):
(AbortedRequest.prototype.handleEvent):
(SyncRequestSettingTimeoutAfterOpen.startXHR),
(SyncRequestSettingTimeoutBeforeOpen.startXHR): Test classes for synchronous XHR cases.
(TestCounter.testComplete),
(TestCounter.next): Used for cycling through tests.

  • platform/chromium/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
  • platform/gtk/TestExpectations: Marking XHR timeout cases as slow in order to run them with a longer test timeout threshold.
  • platform/qt/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
Location:
trunk
Files:
25 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r132251 r132252  
     12012-10-23  Dominik Röttsches  <dominik.rottsches@intel.com>
     2
     3        Add timeout support to XMLHttpRequest
     4        https://bugs.webkit.org/show_bug.cgi?id=74802
     5
     6        Reviewed by Nate Chapin.
     7
     8        XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
     9        permission to reuse them under PD/BSD license
     10        in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
     11        I adapted them for W3C testharness.js and split them into groups with shorter test running time
     12        so that they can be used as WebKit layout tests. Each individual test should
     13        complete in less than 20 seconds.
     14
     15        The case of late updates to the timeout property, changing the timeout value after send()
     16        is not supported yet and handled separately in bug 98156. Tests that are testing this feature
     17        are commented out until this bug is tackled.
     18
     19        The suffix of the html test filename matches the groups in xmlhttprequest-timeout.js which contains
     20        all tests that are run. The result of assertions is reported back to testharness.js.
     21
     22        For example, the "overrides" group is currently not run yet since all tests in that group are cases
     23        of late updates, see above. Once late updates are supported we can add a file
     24        xmlhttprequest-timeout-overrides.html to run them.
     25
     26        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted-expected.txt: Added.
     27        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html: Added.
     28        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain-expected.txt: Added.
     29        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html: Added.
     30        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires-expected.txt: Added.
     31        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html: Added.
     32        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-runner.js: Added. Distinguishes which group of tests to run based on filename suffix.
     33        (testResultCallbackHandler.return):
     34        (groupFromLocation):
     35        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple-expected.txt: Added.
     36        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html: Added.
     37        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain-expected.txt: Added.
     38        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html: Added.
     39        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice-expected.txt: Added.
     40        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html: Added.
     41        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted-expected.txt: Added.
     42        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html: Added.
     43        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires-expected.txt: Added.
     44        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html: Added.
     45        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple-expected.txt: Added.
     46        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html: Added.
     47        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker-expected.txt: Added.
     48        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html: Added.
     49        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice-expected.txt: Added.
     50        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html: Added.
     51        * http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout.js: Added. Contains test cases for all individual test html files.
     52        (message): Wrapper for postMessage in worker and document context case.
     53        (is),
     54        (ok): Assertion functions.
     55        (RequestTracker): Class for variations of the regular timeout case.
     56        (RequestTracker.prototype.startXHR.handleEvent):
     57        (RequestTracker.prototype.startXHR):
     58        (RequestTracker.prototype.getMessage):
     59        (RequestTracker.prototype.handleEvent):
     60        (AbortedRequest): Class for testing timeout event vs. abort events.
     61        (AbortedRequest.prototype.startXHR.handleEvent):
     62        (AbortedRequest.prototype.startXHR.abortReq):
     63        (AbortedRequest.prototype.startXHR.else):
     64        (AbortedRequest.prototype.startXHR):
     65        (AbortedRequest.prototype.noEventsFired):
     66        (AbortedRequest.prototype.getMessage):
     67        (AbortedRequest.prototype.handleEvent):
     68        (SyncRequestSettingTimeoutAfterOpen.startXHR),
     69        (SyncRequestSettingTimeoutBeforeOpen.startXHR): Test classes for synchronous XHR cases.
     70        (TestCounter.testComplete),
     71        (TestCounter.next): Used for cycling through tests.
     72        * platform/chromium/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
     73        * platform/gtk/TestExpectations: Marking XHR timeout cases as slow in order to run them with a longer test timeout threshold.
     74        * platform/qt/TestExpectations: Skipping XHR timeout cases since setTimeoutInterval is not supported in Chromium's HTTP stack.
     75
    1762012-10-23  Levi Weintraub  <leviw@chromium.org>
    277
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r132251 r132252  
    985985webkit.org/b/98452 [ Linux Win ] fast/text/vertical-rl-rtl-linebreak.html [ Failure ]
    986986
     987# ResourceRequest needs to support setTimeoutInterval
     988webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html [ Failure ]
     989webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html [ Failure ]
     990webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html [ Failure ]
     991webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html [ Failure ]
     992webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html [ Failure ]
     993webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html [ Failure ]
     994webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html [ Failure ]
     995webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html [ Failure ]
     996webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html [ Failure ]
     997webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html [ Failure ]
     998webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html [ Failure ]
     999
    9871000# -----------------------------------------------------------------
    9881001# Inspector tests
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r132236 r132252  
    617617Bug(GTK) tables/mozilla/other/slashlogo.html [ Pass Slow ]
    618618
     619Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html [ Pass Slow ]
     620Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html [ Pass Slow ]
     621Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html [ Pass Slow ]
     622Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html [ Pass Slow ]
     623Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html [ Pass Slow ]
     624Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html [ Pass Slow ]
     625Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html [ Pass Slow ]
     626Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html [ Pass Slow ]
     627Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html [ Pass Slow ]
     628Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html [ Pass Slow ]
     629Bug(GTK) http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html [ Pass Slow ]
     630
    619631#////////////////////////////////////////////////////////////////////////////////////////
    620632# End of slow tests
  • trunk/LayoutTests/platform/qt/TestExpectations

    r132218 r132252  
    798798http/tests/xmlhttprequest/xmlhttprequest-check-get-readystate-for-404-without-body.html
    799799
     800# ResourceRequest needs to support setTimeoutInterval
     801webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html [ Failure ]
     802webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html [ Failure ]
     803webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html [ Failure ]
     804webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html [ Failure ]
     805webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html [ Failure ]
     806webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html [ Failure ]
     807webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html [ Failure ]
     808webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html [ Failure ]
     809webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html [ Failure ]
     810webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html [ Failure ]
     811webkit.org/b/98397 http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html [ Failure ]
     812
    800813# =========================================================================== #
    801814#       Failing editing/inserting tests.                                      #
  • trunk/Source/WebCore/ChangeLog

    r132246 r132252  
     12012-10-23  Dominik Röttsches  <dominik.rottsches@intel.com>
     2
     3        Add timeout support to XMLHttpRequest
     4        https://bugs.webkit.org/show_bug.cgi?id=74802
     5
     6        Reviewed by Nate Chapin.
     7
     8        An implementation of XHR2 timeouts by using ResourceRequest's setTimeoutInterval.
     9        This made several changes necessary in CachedResource and SubresourceLoader in order
     10        to distinguish and forward the timeout case from there.
     11
     12        The case of late updates to the timeout property, changing the timeout value after send()
     13        is not supported yet and handled separately in bug 98156.
     14
     15        XHR2 timeout tests were initially written by Mozilla's Alex Vincent's. He granted
     16        permission to reuse them under PD/BSD license
     17        in https://bugzilla.mozilla.org/show_bug.cgi?id=525816#c86 - big thanks!
     18        I adapted them for W3C testharness.js and split them into groups with shorter test running time
     19        so that they can be used as WebKit layout tests.
     20
     21        Tests: http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-aborted.html
     22               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-abortedonmain.html
     23               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-overridesexpires.html
     24               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-simple.html
     25               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-synconmain.html
     26               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-twice.html
     27               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-aborted.html
     28               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-overridesexpires.html
     29               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-simple.html
     30               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-synconworker.html
     31               http/tests/xmlhttprequest/timeout/xmlhttprequest-timeout-worker-twice.html
     32
     33        * loader/DocumentThreadableLoader.cpp:
     34        (WebCore::DocumentThreadableLoader::notifyFinished): Forward information about timeout case.
     35        * loader/SubresourceLoader.cpp:
     36        (WebCore::SubresourceLoader::didFail): Distinguish timeout case when informing client.
     37        * loader/cache/CachedResource.h: Distinguishing timeout case for errors.
     38        (WebCore::CachedResource::errorOccurred):
     39        (WebCore::CachedResource::loadFailedOrCanceled):
     40        (WebCore::CachedResource::timedOut):
     41        * xml/XMLHttpRequest.cpp:
     42        (WebCore::XMLHttpRequest::XMLHttpRequest): Initializing m_timeout value to zero.
     43        (WebCore::XMLHttpRequest::setTimeout): Setter function, possibly raising JS exception.
     44        (WebCore):
     45        (WebCore::XMLHttpRequest::open): Open call may raise exception for synchronous requests when timeout value is set.
     46        (WebCore::XMLHttpRequest::createRequest): Assigning timeout value to ResourceRequest.
     47        (WebCore::XMLHttpRequest::didFail): Handling timeout case separately.
     48        (WebCore::XMLHttpRequest::didTimeout): Timeout case state transisition and event firing as spec'ed.
     49        * xml/XMLHttpRequest.h: New event listener, member and callback for handling timeout.
     50        (WebCore::XMLHttpRequest::timeout):
     51        (XMLHttpRequest):
     52        * xml/XMLHttpRequest.idl: New event listener and property added.
     53        * xml/XMLHttpRequestException.cpp:
     54        * xml/XMLHttpRequestException.h: Added an exception value for the timeout case.
     55
     56
    1572012-10-23  Christophe Dumez  <christophe.dumez@intel.com>
    258
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r132157 r132252  
    310310        if (m_resource->wasCanceled())
    311311            error.setIsCancellation(true);
     312        if (m_resource->timedOut())
     313            error.setIsTimeout(true);
    312314        didFail(error);
    313315    } else
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r131919 r132252  
    284284    CachedResourceHandle<CachedResource> protectResource(m_resource);
    285285    m_state = Finishing;
    286     m_resource->error(CachedResource::LoadError);
     286    if (error.isTimeout())
     287        m_resource->error(CachedResource::TimeoutError);
     288    else
     289        m_resource->error(CachedResource::LoadError);
    287290    if (!m_resource->isPreloaded())
    288291        memoryCache()->remove(m_resource);
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r131660 r132252  
    9191        Canceled,
    9292        LoadError,
     93        TimeoutError,
    9394        DecodeError
    9495    };
     
    208209
    209210    bool wasCanceled() const { return m_status == Canceled; }
    210     bool errorOccurred() const { return (m_status == LoadError || m_status == DecodeError); }
    211     bool loadFailedOrCanceled() { return m_status == Canceled || m_status == LoadError; }
     211    bool errorOccurred() const { return (m_status == LoadError || m_status == DecodeError || m_status == TimeoutError); }
     212    bool loadFailedOrCanceled() { return m_status == Canceled || m_status == LoadError || m_status == TimeoutError; }
     213    bool timedOut() const { return m_status == TimeoutError; }
    212214
    213215    bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks == SendCallbacks; }
  • trunk/Source/WebCore/xml/XMLHttpRequest.cpp

    r130612 r132252  
    44 *  Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
    55 *  Copyright (C) 2008, 2011 Google Inc. All rights reserved.
     6 *  Copyright (C) 2012 Intel Corporation
    67 *
    78 *  This library is free software; you can redistribute it and/or
     
    176177    , m_async(true)
    177178    , m_includeCredentials(false)
     179    , m_timeoutMilliseconds(0)
    178180    , m_state(UNSENT)
    179181    , m_createdDocument(false)
     
    327329}
    328330
     331void XMLHttpRequest::setTimeout(unsigned long timeout, ExceptionCode& ec)
     332{
     333    // FIXME: Need to trigger or update the timeout Timer here, if needed. http://webkit.org/b/98156
     334    // 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."
     335    if (scriptExecutionContext()->isDocument() && !m_async) {
     336        logConsoleError(scriptExecutionContext(), "XMLHttpRequest.timeout cannot be set for synchronous HTTP(S) requests made from the window context.");
     337        ec = INVALID_ACCESS_ERR;
     338        return;
     339    }
     340    m_timeoutMilliseconds = timeout;
     341}
     342
     343
    329344void XMLHttpRequest::setResponseType(const String& responseType, ExceptionCode& ec)
    330345{
     
    493508        if (url.protocolIsInHTTPFamily() && m_responseTypeCode != ResponseTypeDefault) {
    494509            logConsoleError(scriptExecutionContext(), "Synchronous HTTP(S) requests made from the window context cannot have XMLHttpRequest.responseType set.");
     510            ec = INVALID_ACCESS_ERR;
     511            return;
     512        }
     513
     514        // Similarly, timeouts are disabled for synchronous requests as well.
     515        if (m_timeoutMilliseconds > 0) {
     516            logConsoleError(scriptExecutionContext(), "Synchronous XMLHttpRequests must not have a timeout value set.");
    495517            ec = INVALID_ACCESS_ERR;
    496518            return;
     
    742764    options.crossOriginRequestPolicy = UseAccessControl;
    743765    options.securityOrigin = securityOrigin();
     766
     767    if (m_timeoutMilliseconds)
     768        request.setTimeoutInterval(m_timeoutMilliseconds / 1000.0);
    744769
    745770    m_exceptionCode = 0;
     
    10591084    }
    10601085
     1086    if (error.isTimeout()) {
     1087        didTimeout();
     1088        return;
     1089    }
     1090
    10611091    // Network failures are already reported to Web Inspector by ResourceLoader.
    10621092    if (error.domain() == errorDomainWebKitInternal)
     
    11831213}
    11841214
     1215void XMLHttpRequest::didTimeout()
     1216{
     1217    // internalAbort() calls dropProtection(), which may release the last reference.
     1218    RefPtr<XMLHttpRequest> protect(this);
     1219    internalAbort();
     1220
     1221    clearResponse();
     1222    clearRequest();
     1223
     1224    m_error = true;
     1225    m_exceptionCode = XMLHttpRequestException::TIMEOUT_ERR;
     1226
     1227    if (!m_async) {
     1228        m_state = DONE;
     1229        m_exceptionCode = TIMEOUT_ERR;
     1230        return;
     1231    }
     1232
     1233    changeState(DONE);
     1234
     1235    if (!m_uploadComplete) {
     1236        m_uploadComplete = true;
     1237        if (m_upload && m_uploadEventsAllowed)
     1238            m_upload->dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent));
     1239    }
     1240    m_progressEventThrottle.dispatchEventAndLoadEnd(XMLHttpRequestProgressEvent::create(eventNames().timeoutEvent));
     1241}
     1242
    11851243bool XMLHttpRequest::canSuspend() const
    11861244{
  • trunk/Source/WebCore/xml/XMLHttpRequest.h

    r128580 r132252  
    33 *  Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com>
    44 *  Copyright (C) 2011 Google Inc. All rights reserved.
     5 *  Copyright (C) 2012 Intel Corporation
    56 *
    67 *  This library is free software; you can redistribute it and/or
     
    7071
    7172    virtual void contextDestroyed();
     73    virtual void didTimeout();
    7274    virtual bool canSuspend() const;
    7375    virtual void suspend(ReasonForSuspension);
     
    105107    Blob* responseBlob(ExceptionCode&);
    106108    Blob* optionalResponseBlob() const { return m_responseBlob.get(); }
     109    unsigned long timeout() const { return m_timeoutMilliseconds; }
     110    void setTimeout(unsigned long timeout, ExceptionCode&);
    107111
    108112    void sendFromInspector(PassRefPtr<FormData>, ExceptionCode&);
     
    134138    DEFINE_ATTRIBUTE_EVENT_LISTENER(loadstart);
    135139    DEFINE_ATTRIBUTE_EVENT_LISTENER(progress);
     140    DEFINE_ATTRIBUTE_EVENT_LISTENER(timeout);
    136141
    137142    using RefCounted<XMLHttpRequest>::ref;
     
    192197    bool m_async;
    193198    bool m_includeCredentials;
     199    unsigned long m_timeoutMilliseconds;
    194200    RefPtr<Blob> m_responseBlob;
    195201
  • trunk/Source/WebCore/xml/XMLHttpRequest.idl

    r131172 r132252  
    4444    attribute EventListener onloadstart;
    4545    attribute EventListener onprogress;
     46    attribute EventListener ontimeout;
    4647
    4748    // event handler attributes
     
    5556    const unsigned short DONE = 4;
    5657
     58    attribute unsigned long timeout
     59        setter raises(DOMException);
    5760    readonly attribute unsigned short readyState;
    5861
     
    118121        raises(EventException);
    119122};
    120 
  • trunk/Source/WebCore/xml/XMLHttpRequestException.cpp

    r113679 r132252  
    3737} exceptions[] = {
    3838    { "NETWORK_ERR", "A network error occurred in synchronous requests." },
    39     { "ABORT_ERR", "The user aborted a request in synchronous requests." }
     39    { "ABORT_ERR", "The user aborted a request in synchronous requests." },
     40    { "TIMEOUT_ERR", "A timeout error occured in synchronous requests." }
    4041};
    4142
  • trunk/Source/WebCore/xml/XMLHttpRequestException.h

    r127852 r132252  
    4646    enum XMLHttpRequestExceptionCode {
    4747        NETWORK_ERR = XMLHttpRequestExceptionOffset + 101,
    48         ABORT_ERR
     48        ABORT_ERR,
     49        TIMEOUT_ERR
    4950    };
    5051
Note: See TracChangeset for help on using the changeset viewer.