Changeset 167183 in webkit


Ignore:
Timestamp:
Apr 12, 2014 12:10:56 PM (10 years ago)
Author:
Darin Adler
Message:

Some small loader refinements and refactoring
https://bugs.webkit.org/show_bug.cgi?id=131541

Reviewed by Alexey Proskuryakov.

Cut down on use of ResourceLoader::handle, which always returns null when
using a network process. Also streamlined conditionals and did some other
small refactoring.

  • loader/DocumentLoader.h: Use references rather than pointers for SchedulePair.
  • loader/ResourceLoader.cpp:

(WebCore::ResourceLoader::didChangePriority): Use m_handle instead of handle(),
since we'd like to delete handle() entirely soon.
(WebCore::ResourceLoader::didReceiveAuthenticationChallenge): Ditto.
(WebCore::ResourceLoader::schedule): Added.
(WebCore::ResourceLoader::unschedule): Ditto.

  • loader/ResourceLoader.h: Rearranged header to eliminate nested conditionals.

Added schedule and unschedule functions for Mac.

  • loader/mac/DocumentLoaderMac.cpp:

(WebCore::scheduleAll): Changed to take a reference and call ResourceLoader::schedule.
(WebCore::unscheduleAll): Ditto.
(WebCore::DocumentLoader::schedule): Ditto.
(WebCore::DocumentLoader::unschedule): Ditto.

  • page/mac/PageMac.cpp:

(WebCore::Page::addSchedulePair): Pass a reference rather than a pointer to schedule.
(WebCore::Page::removeSchedulePair): Ditto.

  • platform/network/ResourceHandle.h: Did a bit of reformatting and reorganizing of

conditionals.

  • platform/network/ResourceHandleInternal.h: Removed a tiny bit of unneeded declaration.
  • platform/network/mac/ResourceHandleMac.mm:

(WebCore::ResourceHandle::schedule): Updated to take a reference rather than a pointer.
(WebCore::ResourceHandle::unschedule): Ditto.

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r167181 r167183  
     12014-04-11  Darin Adler  <darin@apple.com>
     2
     3        Some small loader refinements and refactoring
     4        https://bugs.webkit.org/show_bug.cgi?id=131541
     5
     6        Reviewed by Alexey Proskuryakov.
     7
     8        Cut down on use of ResourceLoader::handle, which always returns null when
     9        using a network process. Also streamlined conditionals and did some other
     10        small refactoring.
     11
     12        * loader/DocumentLoader.h: Use references rather than pointers for SchedulePair.
     13
     14        * loader/ResourceLoader.cpp:
     15        (WebCore::ResourceLoader::didChangePriority): Use m_handle instead of handle(),
     16        since we'd like to delete handle() entirely soon.
     17        (WebCore::ResourceLoader::didReceiveAuthenticationChallenge): Ditto.
     18        (WebCore::ResourceLoader::schedule): Added.
     19        (WebCore::ResourceLoader::unschedule): Ditto.
     20        * loader/ResourceLoader.h: Rearranged header to eliminate nested conditionals.
     21        Added schedule and unschedule functions for Mac.
     22
     23        * loader/mac/DocumentLoaderMac.cpp:
     24        (WebCore::scheduleAll): Changed to take a reference and call ResourceLoader::schedule.
     25        (WebCore::unscheduleAll): Ditto.
     26        (WebCore::DocumentLoader::schedule): Ditto.
     27        (WebCore::DocumentLoader::unschedule): Ditto.
     28
     29        * page/mac/PageMac.cpp:
     30        (WebCore::Page::addSchedulePair): Pass a reference rather than a pointer to schedule.
     31        (WebCore::Page::removeSchedulePair): Ditto.
     32
     33        * platform/network/ResourceHandle.h: Did a bit of reformatting and reorganizing of
     34        conditionals.
     35
     36        * platform/network/ResourceHandleInternal.h: Removed a tiny bit of unneeded declaration.
     37
     38        * platform/network/mac/ResourceHandleMac.mm:
     39        (WebCore::ResourceHandle::schedule): Updated to take a reference rather than a pointer.
     40        (WebCore::ResourceHandle::unschedule): Ditto.
     41
    1422014-04-11  Andreas Kling  <akling@apple.com>
    243
  • trunk/Source/WebCore/loader/DocumentLoader.h

    r165676 r167183  
    5252#endif
    5353
    54 namespace WTF {
    55 class SchedulePair;
    56 }
    57 
    5854namespace WebCore {
     55
    5956    class ApplicationCacheHost;
    60 #if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
    6157    class Archive;
    62 #endif
    6358    class ArchiveResource;
    6459    class ArchiveResourceCollection;
     
    145140        const String& overrideEncoding() const { return m_overrideEncoding; }
    146141
    147 #if PLATFORM(COCOA)
    148         void schedule(WTF::SchedulePair*);
    149         void unschedule(WTF::SchedulePair*);
     142#if PLATFORM(MAC)
     143        void schedule(SchedulePair&);
     144        void unschedule(SchedulePair&);
    150145#endif
    151146
     
    158153
    159154        bool scheduleArchiveLoad(ResourceLoader*, const ResourceRequest&);
    160 #endif // ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
     155#endif
    161156
    162157        // Return the ArchiveResource for the URL only when loading an Archive
  • trunk/Source/WebCore/loader/ResourceLoader.cpp

    r165676 r167183  
    397397void ResourceLoader::didChangePriority(ResourceLoadPriority loadPriority)
    398398{
    399     if (handle())
    400         handle()->didChangePriority(loadPriority);
     399    if (m_handle)
     400        m_handle->didChangePriority(loadPriority);
    401401}
    402402
     
    537537void ResourceLoader::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
    538538{
    539     ASSERT(handle()->hasAuthenticationChallenge());
     539    ASSERT(m_handle->hasAuthenticationChallenge());
    540540
    541541    // Protect this in this delegate method since the additional processing can do
     
    553553#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(CURL) || PLATFORM(GTK) || PLATFORM(EFL)
    554554    challenge.authenticationClient()->receivedRequestToContinueWithoutCredential(challenge);
    555     ASSERT(!handle() || !handle()->hasAuthenticationChallenge());
     555    ASSERT(!m_handle || !m_handle->hasAuthenticationChallenge());
    556556#else
    557557    didFail(blockedError());
     
    568568
    569569#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
     570
    570571bool ResourceLoader::canAuthenticateAgainstProtectionSpace(const ProtectionSpace& protectionSpace)
    571572{
     
    573574    return frameLoader()->client().canAuthenticateAgainstProtectionSpace(documentLoader(), identifier(), protectionSpace);
    574575}
     576
    575577#endif
    576578   
    577579#if PLATFORM(IOS)
     580
    578581RetainPtr<CFDictionaryRef> ResourceLoader::connectionProperties(ResourceHandle*)
    579582{
    580583    return frameLoader()->connectionProperties(this);
    581584}
     585
    582586#endif
    583587
     
    587591}
    588592
    589 }
     593#if PLATFORM(MAC)
     594
     595void ResourceLoader::schedule(SchedulePair& pair)
     596{
     597    if (m_handle)
     598        m_handle->schedule(pair);
     599}
     600
     601void ResourceLoader::unschedule(SchedulePair& pair)
     602{
     603    if (m_handle)
     604        m_handle->unschedule(pair);
     605}
     606
     607#endif
     608
     609}
  • trunk/Source/WebCore/loader/ResourceLoader.h

    r165908 r167183  
    3535#include "ResourceRequest.h"
    3636#include "ResourceResponse.h"
    37 
    3837#include <wtf/Forward.h>
    39 #include <wtf/RefCounted.h>
    4038
    4139#if USE(QUICK_LOOK)
    4240#include "QuickLook.h"
    4341#endif
     42
     43namespace WTF {
     44class SchedulePair;
     45}
    4446
    4547namespace WebCore {
     
    5153class URL;
    5254class ResourceBuffer;
    53 class ResourceHandle;
    5455
    5556class ResourceLoader : public RefCounted<ResourceLoader>, protected ResourceHandleClient {
     
    127128    virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) override { didReceiveAuthenticationChallenge(challenge); }
    128129    virtual void didCancelAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge) override { didCancelAuthenticationChallenge(challenge); }
     130    virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) override { receivedCancellation(challenge); }
     131
    129132#if USE(NETWORK_CFDATA_ARRAY_CALLBACK)
    130133    virtual void didReceiveDataArray(ResourceHandle*, CFArrayRef dataArray) override;
    131134#endif
     135
    132136#if USE(PROTECTION_SPACE_AUTH_CALLBACK)
    133137    virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace& protectionSpace) override { return canAuthenticateAgainstProtectionSpace(protectionSpace); }
    134138#endif
    135     virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge& challenge) override { receivedCancellation(challenge); }
    136 #if PLATFORM(COCOA)
    137 #if USE(CFNETWORK)
     139
     140#if PLATFORM(COCOA) && USE(CFNETWORK)
    138141    virtual CFCachedURLResponseRef willCacheResponse(ResourceHandle*, CFCachedURLResponseRef) override;
    139 #else
    140     virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
    141 #endif
    142 #endif // PLATFORM(COCOA)
     142#endif
     143
    143144#if PLATFORM(WIN) && USE(CFNETWORK)
    144145    // FIXME: Windows should use willCacheResponse - <https://bugs.webkit.org/show_bug.cgi?id=57257>.
     
    146147#endif
    147148
    148     const URL& url() const { return m_request.url(); }
     149#if PLATFORM(COCOA) && !USE(CFNETWORK)
     150    virtual NSCachedURLResponse* willCacheResponse(ResourceHandle*, NSCachedURLResponse*) override;
     151#endif
     152
     153    const URL& url() const { return m_request.url(); }
    149154    ResourceHandle* handle() const { return m_handle.get(); }
    150155    bool shouldSendResourceLoadCallbacks() const { return m_options.sendLoadCallbacks == SendCallbacks; }
     
    162167    QuickLookHandle* quickLookHandle() const { return m_quickLookHandle.get(); }
    163168    void setQuickLookHandle(PassOwnPtr<QuickLookHandle> handle) { m_quickLookHandle = handle; }
     169#endif
     170
     171#if PLATFORM(MAC)
     172    void schedule(WTF::SchedulePair&);
     173    void unschedule(WTF::SchedulePair&);
    164174#endif
    165175
  • trunk/Source/WebCore/loader/mac/DocumentLoaderMac.cpp

    r165676 r167183  
    2929#include "config.h"
    3030#include "DocumentLoader.h"
    31 #include "ResourceHandle.h"
     31
    3232#include "ResourceLoader.h"
    33 #include <wtf/SchedulePair.h>
    3433
    3534namespace WebCore {
    3635
    37 #if !PLATFORM(IOS)
    38 static void scheduleAll(const ResourceLoaderMap& loaders, SchedulePair* pair)
     36#if PLATFORM(MAC)
     37
     38static void scheduleAll(const ResourceLoaderMap& loaders, SchedulePair& pair)
    3939{
    4040    Vector<RefPtr<ResourceLoader>> loadersCopy;
    4141    copyValuesToVector(loaders, loadersCopy);
    42     for (auto& loader : loadersCopy) {
    43         if (ResourceHandle* handle = loader->handle())
    44             handle->schedule(pair);
    45     }
     42    for (auto& loader : loadersCopy)
     43        loader->schedule(pair);
    4644}
    4745
    48 static void unscheduleAll(const ResourceLoaderMap& loaders, SchedulePair* pair)
     46static void unscheduleAll(const ResourceLoaderMap& loaders, SchedulePair& pair)
    4947{
    5048    Vector<RefPtr<ResourceLoader>> loadersCopy;
    5149    copyValuesToVector(loaders, loadersCopy);
    52     for (auto& loader : loadersCopy) {
    53         if (ResourceHandle* handle = loader->handle())
    54             handle->unschedule(pair);
    55     }
     50    for (auto& loader : loadersCopy)
     51        loader->unschedule(pair);
    5652}
    57 #endif
    5853
    59 void DocumentLoader::schedule(SchedulePair* pair)
     54void DocumentLoader::schedule(SchedulePair& pair)
    6055{
    61 #if !PLATFORM(IOS)
    62     if (mainResourceLoader() && mainResourceLoader()->handle())
    63         mainResourceLoader()->handle()->schedule(pair);
     56    if (mainResourceLoader())
     57        mainResourceLoader()->schedule(pair);
    6458    scheduleAll(m_subresourceLoaders, pair);
    6559    scheduleAll(m_plugInStreamLoaders, pair);
    6660    scheduleAll(m_multipartSubresourceLoaders, pair);
    67 #else
    68     UNUSED_PARAM(pair);
    69 #endif
    7061}
    7162
    72 void DocumentLoader::unschedule(SchedulePair* pair)
     63void DocumentLoader::unschedule(SchedulePair& pair)
    7364{
    74 #if !PLATFORM(IOS)
    75     if (mainResourceLoader() && mainResourceLoader()->handle())
    76         mainResourceLoader()->handle()->unschedule(pair);
     65    if (mainResourceLoader())
     66        mainResourceLoader()->unschedule(pair);
    7767    unscheduleAll(m_subresourceLoaders, pair);
    7868    unscheduleAll(m_plugInStreamLoaders, pair);
    7969    unscheduleAll(m_multipartSubresourceLoaders, pair);
    80 #else
    81     UNUSED_PARAM(pair);
    82 #endif
    8370}
    8471
     72#endif
     73
    8574} // namespace
  • trunk/Source/WebCore/page/mac/PageMac.cpp

    r165676 r167183  
    4848    for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
    4949        if (DocumentLoader* documentLoader = frame->loader().documentLoader())
    50             documentLoader->schedule(pair.get());
     50            documentLoader->schedule(*pair);
    5151        if (DocumentLoader* documentLoader = frame->loader().provisionalDocumentLoader())
    52             documentLoader->schedule(pair.get());
     52            documentLoader->schedule(*pair);
    5353    }
    5454#endif
     
    6969    for (Frame* frame = m_mainFrame.get(); frame; frame = frame->tree().traverseNext()) {
    7070        if (DocumentLoader* documentLoader = frame->loader().documentLoader())
    71             documentLoader->unschedule(pair.get());
     71            documentLoader->unschedule(*pair);
    7272        if (DocumentLoader* documentLoader = frame->loader().provisionalDocumentLoader())
    73             documentLoader->unschedule(pair.get());
     73            documentLoader->unschedule(*pair);
    7474    }
    7575#endif
  • trunk/Source/WebCore/platform/network/ResourceHandle.h

    r166186 r167183  
    3434#include <wtf/RefCounted.h>
    3535
     36#if PLATFORM(COCOA) || USE(CFNETWORK)
     37#include <wtf/RetainPtr.h>
     38#endif
     39
    3640#if USE(QUICK_LOOK)
    3741#include "QuickLook.h"
    38 #endif // USE(QUICK_LOOK)
     42#endif
    3943
    4044#if USE(SOUP)
     
    5357typedef void* LPVOID;
    5458typedef LPVOID HINTERNET;
    55 #endif
    56 
    57 #if PLATFORM(COCOA) || USE(CFNETWORK)
    58 #include <wtf/RetainPtr.h>
    5959#endif
    6060
     
    8585
    8686namespace WebCore {
     87
    8788class AuthenticationChallenge;
    8889class Credential;
     
    114115    void willSendRequest(ResourceRequest&, const ResourceResponse& redirectResponse);
    115116#endif
     117
    116118#if PLATFORM(COCOA) || USE(CFNETWORK) || USE(CURL) || USE(SOUP)
    117119    bool shouldUseCredentialStorage();
     
    122124#endif
    123125
    124 #if PLATFORM(COCOA)
    125 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)
     126#if PLATFORM(COCOA) && USE(PROTECTION_SPACE_AUTH_CALLBACK)
    126127    bool canAuthenticateAgainstProtectionSpace(const ProtectionSpace&);
    127128#endif
    128 #if !USE(CFNETWORK)
     129
     130#if PLATFORM(COCOA) && !USE(CFNETWORK)
    129131    void didCancelAuthenticationChallenge(const AuthenticationChallenge&);
    130132    NSURLConnection *connection() const;
     
    133135#endif
    134136
    135     void schedule(WTF::SchedulePair*);
    136     void unschedule(WTF::SchedulePair*);
    137 #endif
     137#if PLATFORM(MAC)
     138    void schedule(WTF::SchedulePair&);
     139    void unschedule(WTF::SchedulePair&);
     140#endif
     141
    138142#if USE(CFNETWORK)
    139143    CFURLStorageSessionRef storageSession() const;
     
    143147    static void setHostAllowsAnyHTTPSCertificate(const String&);
    144148    static void setClientCertificate(const String& host, CFDataRef);
     149#endif
    145150
    146151#if USE(QUICK_LOOK)
    147152    QuickLookHandle* quickLookHandle() { return m_quickLook.get(); }
    148153    void setQuickLookHandle(PassOwnPtr<QuickLookHandle> handle) { m_quickLook = handle; }
    149 #endif // USE(QUICK_LOOK)
    150 
    151 #endif // USE(CFNETWORK)
     154#endif
    152155
    153156#if PLATFORM(WIN) && USE(CURL)
     
    155158    static void setClientCertificateInfo(const String&, const String&, const String&);
    156159#endif
     160
    157161#if PLATFORM(WIN) && USE(CURL) && USE(CF)
    158162    static void setClientCertificate(const String& host, CFDataRef);
     
    216220#if USE(CFNETWORK)
    217221    void continueWillCacheResponse(CFCachedURLResponseRef);
    218 #elif PLATFORM(COCOA)
     222#endif
     223#if PLATFORM(COCOA) && !USE(CFNETWORK)
    219224    void continueWillCacheResponse(NSCachedURLResponse *);
    220225#endif
     
    237242    static CFStringRef synchronousLoadRunLoopMode();
    238243#endif
     244
    239245#if PLATFORM(IOS) && USE(CFNETWORK)
    240246    static CFMutableDictionaryRef createSSLPropertiesFromNSURLRequest(const ResourceRequest&);
     
    272278
    273279#if PLATFORM(COCOA) || USE(CFNETWORK)
    274     enum class SchedulingBehavior {
    275         Asynchronous,
    276         Synchronous
    277     };
     280    enum class SchedulingBehavior { Asynchronous, Synchronous };
     281#endif
    278282
    279283#if USE(CFNETWORK)
    280284    void createCFURLConnection(bool shouldUseCredentialStorage, bool shouldContentSniff, SchedulingBehavior, CFDictionaryRef clientProperties);
    281 #else
     285#endif
     286
     287#if PLATFORM(COCOA) && !USE(CFNETWORK)
    282288    void createNSURLConnection(id delegate, bool shouldUseCredentialStorage, bool shouldContentSniff, SchedulingBehavior);
    283 #endif
    284289#endif
    285290
     
    289294#if USE(QUICK_LOOK)
    290295    OwnPtr<QuickLookHandle> m_quickLook;
    291 #endif // USE(QUICK_LOOK)
     296#endif
    292297};
    293298
  • trunk/Source/WebCore/platform/network/ResourceHandleInternal.h

    r165676 r167183  
    5353#include <libsoup/soup.h>
    5454#include <wtf/gobject/GRefPtr.h>
    55 class Frame;
    5655#endif
    5756
     
    7069
    7170namespace WebCore {
     71
    7272    class ResourceHandleClient;
    7373
     
    8484            , m_shouldContentSniff(shouldContentSniff)
    8585#if USE(CFNETWORK)
    86             , m_connection(0)
    8786            , m_currentRequest(request)
    8887#endif
     
    217216        NSURLAuthenticationChallenge *m_currentMacChallenge;
    218217#endif
     218
    219219        AuthenticationChallenge m_currentWebChallenge;
    220220        ResourceHandle::FailureType m_scheduledFailureType;
  • trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm

    r166791 r167183  
    298298}
    299299
    300 void ResourceHandle::schedule(SchedulePair* pair)
    301 {
    302 #if !PLATFORM(IOS)
    303     NSRunLoop *runLoop = pair->nsRunLoop();
     300#if PLATFORM(MAC)
     301
     302void ResourceHandle::schedule(SchedulePair& pair)
     303{
     304    NSRunLoop *runLoop = pair.nsRunLoop();
    304305    if (!runLoop)
    305306        return;
    306     [d->m_connection.get() scheduleInRunLoop:runLoop forMode:(NSString *)pair->mode()];
     307    [d->m_connection.get() scheduleInRunLoop:runLoop forMode:(NSString *)pair.mode()];
    307308    if (d->m_startWhenScheduled) {
    308309        [d->m_connection.get() start];
    309310        d->m_startWhenScheduled = false;
    310311    }
    311 #else
    312     UNUSED_PARAM(pair);
    313 #endif
    314 }
    315 
    316 void ResourceHandle::unschedule(SchedulePair* pair)
    317 {
    318 #if !PLATFORM(IOS)
    319     if (NSRunLoop *runLoop = pair->nsRunLoop())
    320         [d->m_connection.get() unscheduleFromRunLoop:runLoop forMode:(NSString *)pair->mode()];
    321 #else
    322     UNUSED_PARAM(pair);
    323 #endif
    324 }
     312}
     313
     314void ResourceHandle::unschedule(SchedulePair& pair)
     315{
     316    if (NSRunLoop *runLoop = pair.nsRunLoop())
     317        [d->m_connection.get() unscheduleFromRunLoop:runLoop forMode:(NSString *)pair.mode()];
     318}
     319
     320#endif
    325321
    326322id ResourceHandle::delegate()
Note: See TracChangeset for help on using the changeset viewer.