⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 201856 in webkit


Ignore:
Timestamp:
Jun 8, 2016, 11:55:26 PM (10 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

Introduce ResourceErrorBase::type
https://bugs.webkit.org/show_bug.cgi?id=158299

Reviewed by Alex Christensen.

Source/WebCore:

Introducing an enum type for ResourceErrorBase.
In most cases, the type is set at construction time.
By default, constructor with no parameters will set type to Null.
Constructor with parameters will set type to General.

Removed boolean state error fields.

Introduced a type setter. It should only be used to make the type
more precise (when type is Null or General).

Updating related calling code.

No change of behavior.

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::stopLoadingForPolicyChange):

  • loader/DocumentThreadableLoader.cpp:

(WebCore::DocumentThreadableLoader::cancel):

  • loader/EmptyClients.h:
  • loader/FrameLoader.cpp:

(WebCore::FrameLoader::cancelledError):
(WebCore::FrameLoader::blockedError):

  • loader/WorkerThreadableLoader.cpp:

(WebCore::WorkerThreadableLoader::MainThreadBridge::cancel):

  • platform/network/ResourceErrorBase.cpp:

(WebCore::ResourceErrorBase::isolatedCopy):
(WebCore::ResourceErrorBase::setType):
(WebCore::ResourceErrorBase::compare):

  • platform/network/ResourceErrorBase.h:

(WebCore::ResourceErrorBase::isNull):
(WebCore::ResourceErrorBase::isCancellation):
(WebCore::ResourceErrorBase::isTimeout):
(WebCore::ResourceErrorBase::type):
(WebCore::ResourceErrorBase::ResourceErrorBase):
(WebCore::ResourceErrorBase::domain):

  • platform/network/cf/ResourceError.h:

(WebCore::ResourceError::ResourceError):

  • platform/network/cf/ResourceErrorCF.cpp:

(WebCore::ResourceError::ResourceError):
(WebCore::ResourceError::cfError):

  • platform/network/curl/ResourceError.h:

(WebCore::ResourceError::ResourceError):

  • platform/network/mac/ResourceErrorMac.mm:

(WebCore::m_platformError):
(WebCore::ResourceError::nsError):
(WebCore::ResourceError::ResourceError):
(WebCore::ResourceError::platformLazyInit):

  • platform/network/soup/ResourceError.h:

(WebCore::ResourceError::ResourceError):

  • platform/network/soup/ResourceErrorSoup.cpp:

(WebCore::ResourceError::timeoutError):

Source/WebKit2:

  • Shared/soup/WebCoreArgumentCodersSoup.cpp:

(IPC::ArgumentCoder<ResourceError>::encodePlatformData):
(IPC::ArgumentCoder<ResourceError>::decodePlatformData):

Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201854 r201856  
     12016-06-08  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        Introduce ResourceErrorBase::type
     4        https://bugs.webkit.org/show_bug.cgi?id=158299
     5
     6        Reviewed by Alex Christensen.
     7
     8        Introducing an enum type for ResourceErrorBase.
     9        In most cases, the type is set at construction time.
     10        By default, constructor with no parameters will set type to Null.
     11        Constructor with parameters will set type to General.
     12
     13        Removed boolean state error fields.
     14
     15        Introduced a type setter. It should only be used to  make the type
     16        more precise (when type is Null or General).
     17
     18        Updating related calling code.
     19
     20        No change of behavior.
     21
     22        * loader/DocumentLoader.cpp:
     23        (WebCore::DocumentLoader::stopLoadingForPolicyChange):
     24        * loader/DocumentThreadableLoader.cpp:
     25        (WebCore::DocumentThreadableLoader::cancel):
     26        * loader/EmptyClients.h:
     27        * loader/FrameLoader.cpp:
     28        (WebCore::FrameLoader::cancelledError):
     29        (WebCore::FrameLoader::blockedError):
     30        * loader/WorkerThreadableLoader.cpp:
     31        (WebCore::WorkerThreadableLoader::MainThreadBridge::cancel):
     32        * platform/network/ResourceErrorBase.cpp:
     33        (WebCore::ResourceErrorBase::isolatedCopy):
     34        (WebCore::ResourceErrorBase::setType):
     35        (WebCore::ResourceErrorBase::compare):
     36        * platform/network/ResourceErrorBase.h:
     37        (WebCore::ResourceErrorBase::isNull):
     38        (WebCore::ResourceErrorBase::isCancellation):
     39        (WebCore::ResourceErrorBase::isTimeout):
     40        (WebCore::ResourceErrorBase::type):
     41        (WebCore::ResourceErrorBase::ResourceErrorBase):
     42        (WebCore::ResourceErrorBase::domain):
     43        * platform/network/cf/ResourceError.h:
     44        (WebCore::ResourceError::ResourceError):
     45        * platform/network/cf/ResourceErrorCF.cpp:
     46        (WebCore::ResourceError::ResourceError):
     47        (WebCore::ResourceError::cfError):
     48        * platform/network/curl/ResourceError.h:
     49        (WebCore::ResourceError::ResourceError):
     50        * platform/network/mac/ResourceErrorMac.mm:
     51        (WebCore::m_platformError):
     52        (WebCore::ResourceError::nsError):
     53        (WebCore::ResourceError::ResourceError):
     54        (WebCore::ResourceError::platformLazyInit):
     55        * platform/network/soup/ResourceError.h:
     56        (WebCore::ResourceError::ResourceError):
     57        * platform/network/soup/ResourceErrorSoup.cpp:
     58        (WebCore::ResourceError::timeoutError):
     59
    1602016-06-08  Frederic Wang  <fwang@igalia.com>
    261
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r201761 r201856  
    843843{
    844844    ResourceError error = interruptedForPolicyChangeError();
    845     error.setIsCancellation(true);
     845    error.setType(ResourceError::Type::Cancellation);
    846846    cancelMainResourceLoad(error);
    847847}
  • trunk/Source/WebCore/loader/DocumentThreadableLoader.cpp

    r201414 r201856  
    161161    if (m_client && m_resource) {
    162162        // FIXME: This error is sent to the client in didFail(), so it should not be an internal one. Use FrameLoaderClient::cancelledError() instead.
    163         ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled");
    164         error.setIsCancellation(true);
     163        ResourceError error(errorDomainWebKitInternal, 0, m_resource->url(), "Load cancelled", ResourceError::Type::Cancellation);
    165164        didFail(m_resource->identifier(), error);
    166165    }
  • trunk/Source/WebCore/loader/EmptyClients.h

    r201056 r201856  
    331331    void finishedLoading(DocumentLoader*) override { }
    332332
    333     ResourceError cancelledError(const ResourceRequest&) override { ResourceError error("", 0, URL(), ""); error.setIsCancellation(true); return error; }
    334     ResourceError blockedError(const ResourceRequest&) override { return ResourceError("", 0, URL(), ""); }
    335     ResourceError blockedByContentBlockerError(const ResourceRequest&) override { return ResourceError("", 0, URL(), ""); }
    336     ResourceError cannotShowURLError(const ResourceRequest&) override { return ResourceError("", 0, URL(), ""); }
    337     ResourceError interruptedForPolicyChangeError(const ResourceRequest&) override { return ResourceError("", 0, URL(), ""); }
    338 
    339     ResourceError cannotShowMIMETypeError(const ResourceResponse&) override { return ResourceError("", 0, URL(), ""); }
    340     ResourceError fileDoesNotExistError(const ResourceResponse&) override { return ResourceError("", 0, URL(), ""); }
    341     ResourceError pluginWillHandleLoadError(const ResourceResponse&) override { return ResourceError("", 0, URL(), ""); }
     333    ResourceError cancelledError(const ResourceRequest&) override { return ResourceError(ResourceError::Type::Cancellation); }
     334    ResourceError blockedError(const ResourceRequest&) override { return { }; }
     335    ResourceError blockedByContentBlockerError(const ResourceRequest&) override { return { }; }
     336    ResourceError cannotShowURLError(const ResourceRequest&) override { return { }; }
     337    ResourceError interruptedForPolicyChangeError(const ResourceRequest&) override { return { }; }
     338
     339    ResourceError cannotShowMIMETypeError(const ResourceResponse&) override { return { }; }
     340    ResourceError fileDoesNotExistError(const ResourceResponse&) override { return { }; }
     341    ResourceError pluginWillHandleLoadError(const ResourceResponse&) override { return { }; }
    342342
    343343    bool shouldFallBack(const ResourceError&) override { return false; }
  • trunk/Source/WebCore/loader/FrameLoader.cpp

    r201753 r201856  
    34243424{
    34253425    ResourceError error = m_client.cancelledError(request);
    3426     error.setIsCancellation(true);
     3426    error.setType(ResourceError::Type::Cancellation);
    34273427    return error;
    34283428}
     
    34363436{
    34373437    ResourceError error = m_client.blockedError(request);
    3438     error.setIsCancellation(true);
     3438    error.setType(ResourceError::Type::Cancellation);
    34393439    return error;
    34403440}
  • trunk/Source/WebCore/loader/WorkerThreadableLoader.cpp

    r201637 r201856  
    139139        // If the client hasn't reached a termination state, then transition it by sending a cancellation error.
    140140        // Note: no more client callbacks will be done after this method -- the clearClientWrapper() call ensures that.
    141         ResourceError error(String(), 0, URL(), String());
    142         error.setIsCancellation(true);
     141        ResourceError error(ResourceError::Type::Cancellation);
    143142        clientWrapper->didFail(error);
    144143    }
  • trunk/Source/WebCore/platform/network/ResourceErrorBase.cpp

    r201623 r201856  
    4646    errorCopy.m_failingURL = m_failingURL.isolatedCopy();
    4747    errorCopy.m_localizedDescription = m_localizedDescription.isolatedCopy();
    48     errorCopy.m_isNull = m_isNull;
    49     errorCopy.m_isCancellation = m_isCancellation;
    50     errorCopy.m_isTimeout = m_isTimeout;
     48    errorCopy.m_type = m_type;
    5149
    5250    errorCopy.doPlatformIsolatedCopy(asResourceError());
     
    6058}
    6159
     60void ResourceErrorBase::setType(Type type)
     61{
     62    ASSERT(m_type == Type::General || m_type == Type::Null);
     63    m_type = type;
     64}
     65
    6266bool ResourceErrorBase::compare(const ResourceError& a, const ResourceError& b)
    6367{
     
    6569        return true;
    6670
    67     if (a.isNull() || b.isNull())
     71    if (a.type() != b.type())
    6872        return false;
    6973
     
    8084        return false;
    8185
    82     if (a.isCancellation() != b.isCancellation())
    83         return false;
    84 
    85     if (a.isTimeout() != b.isTimeout())
    86         return false;
    87 
    8886    return ResourceError::platformCompare(a, b);
    8987}
  • trunk/Source/WebCore/platform/network/ResourceErrorBase.h

    r201623 r201856  
    11/*
    22 * Copyright (C) 2006 Apple Inc.  All rights reserved.
     3 * Copyright (C) 2016 Canon Inc.  All rights reserved.
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2122 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2223 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2425 */
    2526
     
    3940    ResourceError isolatedCopy() const;
    4041
    41     bool isNull() const { return m_isNull; }
    42 
    4342    const String& domain() const { lazyInit(); return m_domain; }
    4443    int errorCode() const { lazyInit(); return m_errorCode; }
     
    4645    const String& localizedDescription() const { lazyInit(); return m_localizedDescription; }
    4746
    48     void setIsCancellation(bool isCancellation) { m_isCancellation = isCancellation; }
    49     bool isCancellation() const { return m_isCancellation; }
     47    enum class Type {
     48        Null,
     49        General,
     50        Cancellation,
     51        Timeout
     52    };
    5053
    51     void setIsTimeout(bool isTimeout) { m_isTimeout = isTimeout; }
    52     bool isTimeout() const { return m_isTimeout; }
     54    bool isNull() const { return m_type == Type::Null; }
     55    bool isCancellation() const { return m_type == Type::Cancellation; }
     56    bool isTimeout() const { return m_type == Type::Timeout; }
    5357
    5458    static bool compare(const ResourceError&, const ResourceError&);
    5559
     60    void setType(Type);
     61    Type type() const { return m_type; }
     62
    5663protected:
    57     ResourceErrorBase()
    58         : m_errorCode(0)
    59         , m_isNull(true)
    60         , m_isCancellation(false)
    61         , m_isTimeout(false)
    62     {
    63     }
     64    ResourceErrorBase(Type type) : m_type(type) { }
    6465
    65     ResourceErrorBase(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription)
     66    ResourceErrorBase(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, Type type)
    6667        : m_domain(domain)
    6768        , m_failingURL(failingURL)
    6869        , m_localizedDescription(localizedDescription)
    6970        , m_errorCode(errorCode)
    70         , m_isNull(false)
    71         , m_isCancellation(false)
    72         , m_isTimeout(false)
     71        , m_type(type)
    7372    {
    7473    }
     
    8584    URL m_failingURL;
    8685    String m_localizedDescription;
    87     int m_errorCode;
    88     bool m_isNull : 1;
    89     bool m_isCancellation : 1;
    90     bool m_isTimeout : 1;
     86    int m_errorCode { 0 };
     87    Type m_type { Type::General };
    9188
    9289private:
  • trunk/Source/WebCore/platform/network/cf/ResourceError.h

    r201623 r201856  
    4545class ResourceError : public ResourceErrorBase {
    4646public:
    47     ResourceError()
    48         : m_dataIsUpToDate(true)
     47    ResourceError(Type type = Type::Null)
     48        : ResourceErrorBase(type)
     49        , m_dataIsUpToDate(true)
    4950    {
    5051    }
    5152
    52     ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription)
    53         : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription)
     53    ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, Type type = Type::General)
     54        : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, type)
    5455        , m_dataIsUpToDate(true)
    5556    {
  • trunk/Source/WebCore/platform/network/cf/ResourceErrorCF.cpp

    r201623 r201856  
    4141
    4242ResourceError::ResourceError(CFErrorRef cfError)
    43     : m_dataIsUpToDate(false)
     43    : ResourceErrorBase(Type::Null)
     44    , m_dataIsUpToDate(false)
    4445    , m_platformError(cfError)
    4546{
    46     m_isNull = !cfError;
    47     if (!m_isNull)
    48         m_isTimeout = CFErrorGetCode(m_platformError.get()) == kCFURLErrorTimedOut;
     47    if (cfError)
     48        setType((CFErrorGetCode(m_platformError.get()) == kCFURLErrorTimedOut) ? Type::Timeout : Type::General);
    4949}
    5050
    5151#if PLATFORM(WIN)
    5252ResourceError::ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, CFDataRef certificate)
    53     : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription)
     53    : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, Type::General)
    5454    , m_dataIsUpToDate(true)
    5555    , m_certificate(certificate)
     
    137137CFErrorRef ResourceError::cfError() const
    138138{
    139     if (m_isNull) {
     139    if (isNull()) {
    140140        ASSERT(!m_platformError);
    141141        return 0;
     
    173173// FIXME: Once <rdar://problem/5050841> is fixed we can remove this constructor.
    174174ResourceError::ResourceError(CFStreamError error)
    175     : m_dataIsUpToDate(true)
    176 {
    177     m_isNull = false;
     175    : ResourceErrorBase(Type::General)
     176    , m_dataIsUpToDate(true)
     177{
    178178    m_errorCode = error.error;
    179179
  • trunk/Source/WebCore/platform/network/curl/ResourceError.h

    r201623 r201856  
    4141{
    4242public:
    43     ResourceError() : m_sslErrors(0)
     43    ResourceError(Type type = Type::Null)
     44        : ResourceErrorBase(type)
     45        , m_sslErrors(0)
    4446    {
    4547    }
    4648
    47     ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription)
    48         : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription), m_sslErrors(0)
     49    ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, Type type = Type::Null)
     50        : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, type)
     51        , m_sslErrors(0)
    4952    {
    5053    }
  • trunk/Source/WebCore/platform/network/mac/ResourceErrorMac.mm

    r201623 r201856  
    194194
    195195ResourceError::ResourceError(NSError *error)
    196     : m_dataIsUpToDate(false)
     196    , m_dataIsUpToDate(false)
    197197    , m_platformError(reinterpret_cast<CFErrorRef>(error))
    198198{
    199     m_isNull = !error;
    200     if (!m_isNull)
    201         m_isTimeout = [error code] == NSURLErrorTimedOut;
     199    if (error)
     200        setType(([error code] == NSURLErrorTimedOut) ? Type::Timeout : Type::General);
    202201}
    203202
    204203NSError *ResourceError::nsError() const
    205204{
    206     if (m_isNull) {
     205    if (isNull()) {
    207206        ASSERT(!m_platformError);
    208207        return nil;
     
    239238
    240239ResourceError::ResourceError(NSError *nsError)
    241     : m_dataIsUpToDate(false)
     240    : ResourceErrorBase(Type::Null)
     241    , m_dataIsUpToDate(false)
    242242    , m_platformError(nsError)
    243243{
    244     m_isNull = !nsError;
    245     if (!m_isNull)
    246         m_isTimeout = [m_platformError.get() code] == NSURLErrorTimedOut;
     244    if (nsError)
     245        setType(([m_platformError.get() code] == NSURLErrorTimedOut) ? Type::Timeout : Type::General);
    247246}
    248247
    249248ResourceError::ResourceError(CFErrorRef cfError)
    250     : m_dataIsUpToDate(false)
    251     , m_platformError((NSError *)cfError)
    252 {
    253     m_isNull = !cfError;
    254     if (!m_isNull)
    255         m_isTimeout = [m_platformError.get() code] == NSURLErrorTimedOut;
     249    : ResourceError((NSError *)cfError)
     250{
    256251}
    257252
     
    288283NSError *ResourceError::nsError() const
    289284{
    290     if (m_isNull) {
     285    if (isNull()) {
    291286        ASSERT(!m_platformError);
    292287        return nil;
  • trunk/Source/WebCore/platform/network/soup/ResourceError.h

    r201623 r201856  
    4242{
    4343public:
    44     ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription)
    45         : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription)
     44    ResourceError(Type type = Type::Null)
     45        : ResourceErrorBase(type)
    4646        , m_tlsErrors(0)
    4747    {
    4848    }
    4949
    50     ResourceError()
    51         : m_tlsErrors(0)
     50    ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, Type type = Type::General)
     51        : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, type)
     52        , m_tlsErrors(0)
    5253    {
    5354    }
  • trunk/Source/WebCore/platform/network/soup/ResourceErrorSoup.cpp

    r201623 r201856  
    9393    static const int timeoutError = -1001;
    9494    static const char* const  errorDomain = "WebKitNetworkError";
    95     ResourceError error = ResourceError(errorDomain, timeoutError, failingURL, "Request timed out");
    96     error.setIsTimeout(true);
    97     return error;
     95    return ResourceError(errorDomain, timeoutError, failingURL, "Request timed out", ResourceError::Type::Timeout);
    9896}
    9997
  • trunk/Source/WebKit2/ChangeLog

    r201838 r201856  
     12016-06-08  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        Introduce ResourceErrorBase::type
     4        https://bugs.webkit.org/show_bug.cgi?id=158299
     5
     6        Reviewed by Alex Christensen.
     7
     8        * Shared/soup/WebCoreArgumentCodersSoup.cpp:
     9        (IPC::ArgumentCoder<ResourceError>::encodePlatformData):
     10        (IPC::ArgumentCoder<ResourceError>::decodePlatformData):
     11
    1122016-06-08  Beth Dakin  <bdakin@apple.com>
    213
  • trunk/Source/WebKit2/Shared/soup/WebCoreArgumentCodersSoup.cpp

    r194496 r201856  
    187187void ArgumentCoder<ResourceError>::encodePlatformData(ArgumentEncoder& encoder, const ResourceError& resourceError)
    188188{
    189     bool errorIsNull = resourceError.isNull();
    190     encoder << errorIsNull;
    191     if (errorIsNull)
     189    encoder.encodeEnum(resourceError.type());
     190    if (resourceError.isNull())
    192191        return;
    193192
     
    196195    encoder << resourceError.failingURL().string();
    197196    encoder << resourceError.localizedDescription();
    198     encoder << resourceError.isCancellation();
    199     encoder << resourceError.isTimeout();
    200197
    201198    encoder << CertificateInfo(resourceError);
     
    204201bool ArgumentCoder<ResourceError>::decodePlatformData(ArgumentDecoder& decoder, ResourceError& resourceError)
    205202{
    206     bool errorIsNull;
    207     if (!decoder.decode(errorIsNull))
    208         return false;
    209     if (errorIsNull) {
    210         resourceError = ResourceError();
     203    ResourceErrorBase::Type errorType;
     204    if (!decoder.decodeEnum(errorType))
     205        return false;
     206    if (errorType == ResourceErrorBase::Type::Null) {
     207        resourceError = { };
    211208        return true;
    212209    }
     
    228225        return false;
    229226
    230     bool isCancellation;
    231     if (!decoder.decode(isCancellation))
    232         return false;
    233 
    234     bool isTimeout;
    235     if (!decoder.decode(isTimeout))
    236         return false;
    237 
    238227    resourceError = ResourceError(domain, errorCode, URL(URL(), failingURL), localizedDescription);
    239     resourceError.setIsCancellation(isCancellation);
    240     resourceError.setIsTimeout(isTimeout);
     228    resourceError.setType(errorType);
    241229
    242230    CertificateInfo certificateInfo;
Note: See TracChangeset for help on using the changeset viewer.