Changeset 185040 in webkit


Ignore:
Timestamp:
May 31, 2015 4:38:06 AM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

Async XMLHttpRequest should get access to AppCache resources stored as flat files
https://bugs.webkit.org/show_bug.cgi?id=138506

Reviewed by Darin Adler.

Source/WebCore:

This patch reads flat file data when DocumentLoader substituteResource delivery timer is fired.
Refactoring to remove ApplicationCacheHost/DocumentLoader friend link.
Added ResourceLoader::deliverResponseAndData helper function, taking a SharedBuffer as input to remove an unneeded copy for flat files (no change for other files).

Test: http/tests/appcache/simple-video-async.html

  • loader/DocumentLoader.cpp:

(WebCore::DocumentLoader::substituteResourceDeliveryTimerFired):
(WebCore::DocumentLoader::scheduleArchiveLoad):
(WebCore::DocumentLoader::scheduleSubstituteResourceLoad): Helper function to remove ApplicationCacheHost friend link.

  • loader/DocumentLoader.h:
  • loader/ResourceLoader.cpp:

(WebCore::ResourceLoader::deliverResponseAndData): Helper function, code mostly moved from DocumentLoader::substituteResourceDeliveryTimerFired.

  • loader/ResourceLoader.h:
  • loader/SubstituteResource.h:

(WebCore::SubstituteResource::deliver): Introduced to be overriden by ApplicationCacheResource to take care of flat file case.

  • loader/appcache/ApplicationCacheHost.cpp:

(WebCore::ApplicationCacheHost::maybeLoadResource):
(WebCore::ApplicationCacheHost::scheduleLoadFallbackResourceFromApplicationCache):

  • loader/appcache/ApplicationCacheResource.cpp:

(WebCore::ApplicationCacheResource::deliver): Use SharedBuffer::createWithContentsOfFile to load data stored in flat file.

  • loader/appcache/ApplicationCacheResource.h:

LayoutTests:

  • http/tests/appcache/resources/simple-video-async.manifest: Added.
  • http/tests/appcache/simple-video-async-expected.txt: Added.
  • http/tests/appcache/simple-video-async.html: Added.
Location:
trunk
Files:
3 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r185039 r185040  
     12015-05-31  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        Async XMLHttpRequest should get access to AppCache resources stored as flat files
     4        https://bugs.webkit.org/show_bug.cgi?id=138506
     5
     6        Reviewed by Darin Adler.
     7
     8        * http/tests/appcache/resources/simple-video-async.manifest: Added.
     9        * http/tests/appcache/simple-video-async-expected.txt: Added.
     10        * http/tests/appcache/simple-video-async.html: Added.
     11
    1122015-05-31  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
    213
  • trunk/Source/WebCore/ChangeLog

    r185039 r185040  
     12015-05-31  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        Async XMLHttpRequest should get access to AppCache resources stored as flat files
     4        https://bugs.webkit.org/show_bug.cgi?id=138506
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch reads flat file data when DocumentLoader substituteResource delivery timer is fired.
     9        Refactoring to remove ApplicationCacheHost/DocumentLoader friend link.
     10        Added ResourceLoader::deliverResponseAndData helper function, taking a SharedBuffer as input to remove an unneeded copy for flat files (no change for other files).
     11
     12        Test: http/tests/appcache/simple-video-async.html
     13
     14        * loader/DocumentLoader.cpp:
     15        (WebCore::DocumentLoader::substituteResourceDeliveryTimerFired):
     16        (WebCore::DocumentLoader::scheduleArchiveLoad):
     17        (WebCore::DocumentLoader::scheduleSubstituteResourceLoad): Helper function to remove ApplicationCacheHost friend link.
     18        * loader/DocumentLoader.h:
     19        * loader/ResourceLoader.cpp:
     20        (WebCore::ResourceLoader::deliverResponseAndData): Helper function, code mostly moved from DocumentLoader::substituteResourceDeliveryTimerFired.
     21        * loader/ResourceLoader.h:
     22        * loader/SubstituteResource.h:
     23        (WebCore::SubstituteResource::deliver): Introduced to be overriden by ApplicationCacheResource to take care of flat file case.
     24        * loader/appcache/ApplicationCacheHost.cpp:
     25        (WebCore::ApplicationCacheHost::maybeLoadResource):
     26        (WebCore::ApplicationCacheHost::scheduleLoadFallbackResourceFromApplicationCache):
     27        * loader/appcache/ApplicationCacheResource.cpp:
     28        (WebCore::ApplicationCacheResource::deliver): Use SharedBuffer::createWithContentsOfFile to load data stored in flat file.
     29        * loader/appcache/ApplicationCacheResource.h:
     30
    1312015-05-31  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
    232
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r184947 r185040  
    11201120        SubstituteResource* resource = it->value.get();
    11211121       
    1122         if (resource) {
    1123             SharedBuffer* data = resource->data();
    1124        
    1125             loader->didReceiveResponse(resource->response());
    1126 
    1127             // Calling ResourceLoader::didReceiveResponse can end up cancelling the load,
    1128             // so we need to check if the loader has reached its terminal state.
    1129             if (loader->reachedTerminalState())
    1130                 return;
    1131 
    1132             loader->didReceiveData(data->data(), data->size(), data->size(), DataPayloadWholeResource);
    1133 
    1134             // Calling ResourceLoader::didReceiveData can end up cancelling the load,
    1135             // so we need to check if the loader has reached its terminal state.
    1136             if (loader->reachedTerminalState())
    1137                 return;
    1138 
    1139             loader->didFinishLoading(0);
    1140         } else {
     1122        if (resource)
     1123            resource->deliver(*loader);
     1124        else {
    11411125            // A null resource means that we should fail the load.
    11421126            // FIXME: Maybe we should use another error here - something like "not in cache".
     
    11661150{
    11671151    if (ArchiveResource* resource = archiveResourceForURL(request.url())) {
    1168         m_pendingSubstituteResources.set(loader, resource);
    1169         deliverSubstituteResourcesAfterDelay();
     1152        scheduleSubstituteResourceLoad(*loader, *resource);
    11701153        return true;
    11711154    }
     
    11891172}
    11901173#endif // ENABLE(WEB_ARCHIVE)
     1174
     1175void DocumentLoader::scheduleSubstituteResourceLoad(ResourceLoader& loader, SubstituteResource& resource)
     1176{
     1177    m_pendingSubstituteResources.set(&loader, &resource);
     1178    deliverSubstituteResourcesAfterDelay();
     1179}
    11911180
    11921181void DocumentLoader::addResponse(const ResourceResponse& r)
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r184941 r185040  
    159159        WEBCORE_EXPORT bool scheduleArchiveLoad(ResourceLoader*, const ResourceRequest&);
    160160#endif
     161        void scheduleSubstituteResourceLoad(ResourceLoader&, SubstituteResource&);
    161162
    162163        // Return the ArchiveResource for the URL only when loading an Archive
     
    432433        ShouldOpenExternalURLsPolicy m_shouldOpenExternalURLsPolicy { ShouldOpenExternalURLsPolicy::ShouldNotAllow };
    433434
    434         friend class ApplicationCacheHost;  // for substitute resource delivery
    435435        std::unique_ptr<ApplicationCacheHost> m_applicationCacheHost;
    436436
  • trunk/Source/WebCore/loader/ResourceLoader.cpp

    r182016 r185040  
    165165}
    166166
     167void ResourceLoader::deliverResponseAndData(const ResourceResponse& response, RefPtr<SharedBuffer>&& buffer)
     168{
     169    Ref<ResourceLoader> protect(*this);
     170
     171    didReceiveResponse(response);
     172    if (reachedTerminalState())
     173        return;
     174
     175    if (buffer) {
     176        unsigned size = buffer->size();
     177        didReceiveBuffer(buffer.release(), size, DataPayloadWholeResource);
     178        if (reachedTerminalState())
     179            return;
     180    }
     181
     182    didFinishLoading(0);
     183}
     184
    167185void ResourceLoader::start()
    168186{
  • trunk/Source/WebCore/loader/ResourceLoader.h

    r182016 r185040  
    6565    virtual bool init(const ResourceRequest&);
    6666
     67    void deliverResponseAndData(const ResourceResponse&, RefPtr<SharedBuffer>&&);
     68
    6769#if PLATFORM(IOS)
    6870    virtual bool startLoading()
  • trunk/Source/WebCore/loader/SubstituteResource.h

    r156550 r185040  
    2727#define SubstituteResource_h
    2828
    29 #include <wtf/RefCounted.h>
    30 
    31 #include "URL.h"
     29#include "ResourceLoader.h"
    3230#include "ResourceResponse.h"
    3331#include "SharedBuffer.h"
    34 
    35 #include <wtf/RefPtr.h>
    3632
    3733namespace WebCore {
     
    4541    SharedBuffer* data() const { return m_data.get(); }
    4642
     43    virtual void deliver(ResourceLoader& loader) { loader.deliverResponseAndData(m_response, m_data->copy()); }
     44
    4745protected:
    4846    SubstituteResource(const URL& url, const ResourceResponse& response, PassRefPtr<SharedBuffer> data)
     
    5351        ASSERT(m_data);
    5452    }
    55    
     53
    5654private:
    5755    URL m_url;
     
    5957    RefPtr<SharedBuffer> m_data;
    6058};
    61    
     59
    6260}
    6361
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheHost.cpp

    r184598 r185040  
    179179        return false;
    180180
    181     m_documentLoader.m_pendingSubstituteResources.set(loader, resource);
    182     m_documentLoader.deliverSubstituteResourcesAfterDelay();
    183 
     181    m_documentLoader.scheduleSubstituteResourceLoad(*loader, *resource);
    184182    return true;
    185183}
     
    437435    loader->willSwitchToSubstituteResource();
    438436
    439     m_documentLoader.m_pendingSubstituteResources.set(loader, resource);
    440     m_documentLoader.deliverSubstituteResourcesAfterDelay();
     437    m_documentLoader.scheduleSubstituteResourceLoad(*loader, *resource);
    441438
    442439    return true;
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheResource.cpp

    r161634 r185040  
    3737    , m_path(path)
    3838{
     39}
     40
     41void ApplicationCacheResource::deliver(ResourceLoader& loader)
     42{
     43    RefPtr<SharedBuffer> buffer;
     44    if (m_path.isEmpty())
     45        buffer = data()->copy();
     46    else
     47        buffer = SharedBuffer::createWithContentsOfFile(m_path);
     48    loader.deliverResponseAndData(response(), WTF::move(buffer));
    3949}
    4050
  • trunk/Source/WebCore/loader/appcache/ApplicationCacheResource.h

    r177733 r185040  
    6565    ApplicationCacheResource(const URL&, const ResourceResponse&, unsigned type, PassRefPtr<SharedBuffer>, const String& path);
    6666
     67    virtual void deliver(ResourceLoader&) override;
     68
    6769    unsigned m_type;
    6870    unsigned m_storageID;
Note: See TracChangeset for help on using the changeset viewer.