Home | History | Annotate | Download | only in loader
      1 /*
      2     Copyright (C) 1998 Lars Knoll (knoll (at) mpi-hd.mpg.de)
      3     Copyright (C) 2001 Dirk Mueller <mueller (at) kde.org>
      4     Copyright (C) 2004, 2006, 2007, 2008 Apple Inc. All rights reserved.
      5 
      6     This library is free software; you can redistribute it and/or
      7     modify it under the terms of the GNU Library General Public
      8     License as published by the Free Software Foundation; either
      9     version 2 of the License, or (at your option) any later version.
     10 
     11     This library is distributed in the hope that it will be useful,
     12     but WITHOUT ANY WARRANTY; without even the implied warranty of
     13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     14     Library General Public License for more details.
     15 
     16     You should have received a copy of the GNU Library General Public License
     17     along with this library; see the file COPYING.LIB.  If not, write to
     18     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     19     Boston, MA 02110-1301, USA.
     20 */
     21 
     22 #ifndef loader_h
     23 #define loader_h
     24 
     25 #include "AtomicString.h"
     26 #include "AtomicStringImpl.h"
     27 #include "FrameLoaderTypes.h"
     28 #include "PlatformString.h"
     29 #include "SubresourceLoaderClient.h"
     30 #include "Timer.h"
     31 #include <wtf/Deque.h>
     32 #include <wtf/HashMap.h>
     33 #include <wtf/Noncopyable.h>
     34 
     35 namespace WebCore {
     36 
     37     class CachedResource;
     38     class DocLoader;
     39     class KURL;
     40     class Request;
     41 
     42     class Loader : public Noncopyable {
     43     public:
     44         Loader();
     45         ~Loader();
     46 
     47         void load(DocLoader*, CachedResource*, bool incremental = true, SecurityCheckPolicy = DoSecurityCheck, bool sendResourceLoadCallbacks = true);
     48 
     49         void cancelRequests(DocLoader*);
     50 
     51         enum Priority { Low, Medium, High };
     52         void servePendingRequests(Priority minimumPriority = Low);
     53 
     54         bool isSuspendingPendingRequests() { return m_isSuspendingPendingRequests; }
     55         void suspendPendingRequests();
     56         void resumePendingRequests();
     57 
     58         void nonCacheRequestInFlight(const KURL&);
     59         void nonCacheRequestComplete(const KURL&);
     60 
     61     private:
     62         Priority determinePriority(const CachedResource*) const;
     63         void scheduleServePendingRequests();
     64 
     65         void requestTimerFired(Timer<Loader>*);
     66 
     67         class Host : public RefCounted<Host>, private SubresourceLoaderClient {
     68         public:
     69             static PassRefPtr<Host> create(const AtomicString& name, unsigned maxRequestsInFlight)
     70             {
     71                 return adoptRef(new Host(name, maxRequestsInFlight));
     72             }
     73             ~Host();
     74 
     75             const AtomicString& name() const { return m_name; }
     76             void addRequest(Request*, Priority);
     77             void nonCacheRequestInFlight();
     78             void nonCacheRequestComplete();
     79             void servePendingRequests(Priority minimumPriority = Low);
     80             void cancelRequests(DocLoader*);
     81             bool hasRequests() const;
     82 
     83             bool processingResource() const { return m_numResourcesProcessing != 0 || m_nonCachedRequestsInFlight !=0; }
     84 
     85         private:
     86             Host(const AtomicString&, unsigned);
     87 
     88             virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
     89             virtual void didReceiveData(SubresourceLoader*, const char*, int);
     90             virtual void didFinishLoading(SubresourceLoader*);
     91             virtual void didFail(SubresourceLoader*, const ResourceError&);
     92 
     93             typedef Deque<Request*> RequestQueue;
     94             void servePendingRequests(RequestQueue& requestsPending, bool& serveLowerPriority);
     95             void didFail(SubresourceLoader*, bool cancelled = false);
     96             void cancelPendingRequests(RequestQueue& requestsPending, DocLoader*);
     97 
     98             RequestQueue m_requestsPending[High + 1];
     99             typedef HashMap<RefPtr<SubresourceLoader>, Request*> RequestMap;
    100             RequestMap m_requestsLoading;
    101             const AtomicString m_name;
    102             const int m_maxRequestsInFlight;
    103             int m_numResourcesProcessing;
    104             int m_nonCachedRequestsInFlight;
    105         };
    106         typedef HashMap<AtomicStringImpl*, RefPtr<Host> > HostMap;
    107         HostMap m_hosts;
    108         RefPtr<Host> m_nonHTTPProtocolHost;
    109 
    110         Timer<Loader> m_requestTimer;
    111 
    112         bool m_isSuspendingPendingRequests;
    113     };
    114 
    115 }
    116 
    117 #endif
    118