2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef NetworkResourcesData_h
30 #define NetworkResourcesData_h
32 #include "InspectorPageAgent.h"
33 #include "TextResourceDecoder.h"
35 #include <wtf/Deque.h>
36 #include <wtf/HashMap.h>
37 #include <wtf/RefCounted.h>
38 #include <wtf/text/StringBuilder.h>
39 #include <wtf/text/WTFString.h>
47 class TextResourceDecoder;
49 class NetworkResourcesData {
52 friend class NetworkResourcesData;
54 ResourceData(const String& requestId, const String& loaderId);
56 String requestId() const { return m_requestId; }
57 String loaderId() const { return m_loaderId; }
59 String frameId() const { return m_frameId; }
60 void setFrameId(const String& frameId) { m_frameId = frameId; }
62 String url() const { return m_url; }
63 void setUrl(const String& url) { m_url = url; }
65 bool hasContent() const { return !m_content.isNull(); }
66 String content() const { return m_content; }
67 void setContent(const String&, bool base64Encoded);
69 bool base64Encoded() const { return m_base64Encoded; }
71 unsigned removeContent();
72 bool isContentPurged() const { return m_isContentPurged; }
73 unsigned purgeContent();
75 InspectorPageAgent::ResourceType type() const { return m_type; }
76 void setType(InspectorPageAgent::ResourceType type) { m_type = type; }
78 int httpStatusCode() const { return m_httpStatusCode; }
79 void setHTTPStatusCode(int httpStatusCode) { m_httpStatusCode = httpStatusCode; }
81 String textEncodingName() const { return m_textEncodingName; }
82 void setTextEncodingName(const String& textEncodingName) { m_textEncodingName = textEncodingName; }
84 PassRefPtr<TextResourceDecoder> decoder() const { return m_decoder; }
85 void setDecoder(PassRefPtr<TextResourceDecoder> decoder) { m_decoder = decoder; }
87 PassRefPtr<SharedBuffer> buffer() const { return m_buffer; }
88 void setBuffer(PassRefPtr<SharedBuffer> buffer) { m_buffer = buffer; }
90 CachedResource* cachedResource() const { return m_cachedResource; }
91 void setCachedResource(CachedResource* cachedResource) { m_cachedResource = cachedResource; }
94 bool hasData() const { return m_dataBuffer; }
95 size_t dataLength() const;
96 void appendData(const char* data, size_t dataLength);
97 size_t decodeDataToContent();
104 bool m_base64Encoded;
105 RefPtr<SharedBuffer> m_dataBuffer;
106 bool m_isContentPurged;
107 InspectorPageAgent::ResourceType m_type;
108 int m_httpStatusCode;
110 String m_textEncodingName;
111 RefPtr<TextResourceDecoder> m_decoder;
113 RefPtr<SharedBuffer> m_buffer;
114 CachedResource* m_cachedResource;
117 NetworkResourcesData();
119 ~NetworkResourcesData();
121 void resourceCreated(const String& requestId, const String& loaderId);
122 void responseReceived(const String& requestId, const String& frameId, const ResourceResponse&);
123 void setResourceType(const String& requestId, InspectorPageAgent::ResourceType);
124 InspectorPageAgent::ResourceType resourceType(const String& requestId);
125 void setResourceContent(const String& requestId, const String& content, bool base64Encoded = false);
126 void maybeAddResourceData(const String& requestId, const char* data, size_t dataLength);
127 void maybeDecodeDataToContent(const String& requestId);
128 void addCachedResource(const String& requestId, CachedResource*);
129 void addResourceSharedBuffer(const String& requestId, PassRefPtr<SharedBuffer>, const String& textEncodingName);
130 ResourceData const* data(const String& requestId);
131 Vector<String> removeCachedResource(CachedResource*);
132 void clear(const String& preservedLoaderId = String());
134 void setResourcesDataSizeLimits(size_t maximumResourcesContentSize, size_t maximumSingleResourceContentSize);
137 void ensureNoDataForRequestId(const String& requestId);
138 bool ensureFreeSpace(size_t size);
140 Deque<String> m_requestIdsDeque;
142 typedef HashMap<String, ResourceData*> ResourceDataMap;
143 ResourceDataMap m_requestIdToResourceDataMap;
144 size_t m_contentSize;
145 size_t m_maximumResourcesContentSize;
146 size_t m_maximumSingleResourceContentSize;
149 } // namespace WebCore
151 #endif // ENABLE(INSPECTOR)
153 #endif // !defined(NetworkResourcesData_h)