]> git.saurik.com Git - iphone-api.git/blob - WebCore/loader.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / loader.h
1 /*
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de)
3 Copyright (C) 2001 Dirk Mueller <mueller@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 "PlatformString.h"
28 #include "SubresourceLoaderClient.h"
29 #include "Timer.h"
30 #include <wtf/Deque.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/Noncopyable.h>
33
34 namespace WebCore {
35
36 class CachedResource;
37 class DocLoader;
38 class Request;
39
40 class Loader : Noncopyable {
41 public:
42 Loader();
43 ~Loader();
44
45 void load(DocLoader*, CachedResource*, bool incremental = true, bool skipCanLoadCheck = false, bool sendResourceLoadCallbacks = true);
46
47 void cancelRequests(DocLoader*);
48
49 enum Priority { Low, Medium, High };
50 void servePendingRequests(Priority minimumPriority = Low);
51
52 bool isSuspendingPendingRequests() { return m_isSuspendingPendingRequests; }
53 void suspendPendingRequests();
54 void resumePendingRequests();
55
56 private:
57 Priority determinePriority(const CachedResource*) const;
58 void scheduleServePendingRequests();
59
60 void requestTimerFired(Timer<Loader>*);
61
62 class Host : private SubresourceLoaderClient {
63 public:
64 Host(const AtomicString& name, unsigned maxRequestsInFlight);
65 ~Host();
66
67 const AtomicString& name() const { return m_name; }
68 void addRequest(Request*, Priority);
69 void servePendingRequests(Priority minimumPriority = Low);
70 void cancelRequests(DocLoader*);
71 bool hasRequests() const;
72
73 bool processingResource() const { return m_numResourcesProcessing != 0; }
74
75 private:
76 class ProcessingResource {
77 public:
78 ProcessingResource(Host* host)
79 : m_host(host)
80 {
81 m_host->m_numResourcesProcessing++;
82 }
83
84 ~ProcessingResource()
85 {
86 m_host->m_numResourcesProcessing--;
87 }
88
89 private:
90 Host* m_host;
91 };
92
93 virtual void didReceiveResponse(SubresourceLoader*, const ResourceResponse&);
94 virtual void didReceiveData(SubresourceLoader*, const char*, int);
95 virtual void didFinishLoading(SubresourceLoader*);
96 virtual void didFail(SubresourceLoader*, const ResourceError&);
97
98 typedef Deque<Request*> RequestQueue;
99 void servePendingRequests(RequestQueue& requestsPending, bool& serveLowerPriority);
100 void didFail(SubresourceLoader*, bool cancelled = false);
101 void cancelPendingRequests(RequestQueue& requestsPending, DocLoader*);
102
103 RequestQueue m_requestsPending[High + 1];
104 typedef HashMap<RefPtr<SubresourceLoader>, Request*> RequestMap;
105 RequestMap m_requestsLoading;
106 const AtomicString m_name;
107 const int m_maxRequestsInFlight;
108 int m_numResourcesProcessing;
109 };
110 typedef HashMap<AtomicStringImpl*, Host*> HostMap;
111 HostMap m_hosts;
112 Host m_nonHTTPProtocolHost;
113
114 Timer<Loader> m_requestTimer;
115
116 bool m_isSuspendingPendingRequests;
117 };
118
119 }
120
121 #endif