NetworkResourcesData.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (C) 2011 Google Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. *
  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
  14. * distribution.
  15. *
  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.
  27. */
  28. #ifndef NetworkResourcesData_h
  29. #define NetworkResourcesData_h
  30. #include "HTTPHeaderMap.h"
  31. #include "InspectorPageAgent.h"
  32. #include "TextResourceDecoder.h"
  33. #include <wtf/Deque.h>
  34. #include <wtf/HashMap.h>
  35. #include <wtf/RefCounted.h>
  36. #include <wtf/text/StringBuilder.h>
  37. #include <wtf/text/WTFString.h>
  38. #if ENABLE(INSPECTOR)
  39. namespace WebCore {
  40. class CachedResource;
  41. class FormData;
  42. class SharedBuffer;
  43. class TextResourceDecoder;
  44. class XHRReplayData : public RefCounted<XHRReplayData> {
  45. public:
  46. static PassRefPtr<XHRReplayData> create(const String &method, const KURL&, bool async, PassRefPtr<FormData>, bool includeCredentials);
  47. void addHeader(const AtomicString& key, const String& value);
  48. const String& method() const { return m_method; }
  49. const KURL& url() const { return m_url; }
  50. bool async() const { return m_async; }
  51. PassRefPtr<FormData> formData() const { return m_formData; }
  52. const HTTPHeaderMap& headers() const { return m_headers; }
  53. bool includeCredentials() const { return m_includeCredentials; }
  54. private:
  55. XHRReplayData(const String &method, const KURL&, bool async, PassRefPtr<FormData>, bool includeCredentials);
  56. String m_method;
  57. KURL m_url;
  58. bool m_async;
  59. RefPtr<FormData> m_formData;
  60. HTTPHeaderMap m_headers;
  61. bool m_includeCredentials;
  62. };
  63. class NetworkResourcesData {
  64. WTF_MAKE_FAST_ALLOCATED;
  65. public:
  66. class ResourceData {
  67. WTF_MAKE_FAST_ALLOCATED;
  68. friend class NetworkResourcesData;
  69. public:
  70. ResourceData(const String& requestId, const String& loaderId);
  71. String requestId() const { return m_requestId; }
  72. String loaderId() const { return m_loaderId; }
  73. String frameId() const { return m_frameId; }
  74. void setFrameId(const String& frameId) { m_frameId = frameId; }
  75. String url() const { return m_url; }
  76. void setUrl(const String& url) { m_url = url; }
  77. bool hasContent() const { return !m_content.isNull(); }
  78. String content() const { return m_content; }
  79. void setContent(const String&, bool base64Encoded);
  80. bool base64Encoded() const { return m_base64Encoded; }
  81. unsigned removeContent();
  82. bool isContentEvicted() const { return m_isContentEvicted; }
  83. unsigned evictContent();
  84. InspectorPageAgent::ResourceType type() const { return m_type; }
  85. void setType(InspectorPageAgent::ResourceType type) { m_type = type; }
  86. int httpStatusCode() const { return m_httpStatusCode; }
  87. void setHTTPStatusCode(int httpStatusCode) { m_httpStatusCode = httpStatusCode; }
  88. String textEncodingName() const { return m_textEncodingName; }
  89. void setTextEncodingName(const String& textEncodingName) { m_textEncodingName = textEncodingName; }
  90. PassRefPtr<TextResourceDecoder> decoder() const { return m_decoder; }
  91. void setDecoder(PassRefPtr<TextResourceDecoder> decoder) { m_decoder = decoder; }
  92. PassRefPtr<SharedBuffer> buffer() const { return m_buffer; }
  93. void setBuffer(PassRefPtr<SharedBuffer> buffer) { m_buffer = buffer; }
  94. CachedResource* cachedResource() const { return m_cachedResource; }
  95. void setCachedResource(CachedResource* cachedResource) { m_cachedResource = cachedResource; }
  96. XHRReplayData* xhrReplayData() const { return m_xhrReplayData.get(); }
  97. void setXHRReplayData(XHRReplayData* xhrReplayData) { m_xhrReplayData = xhrReplayData; }
  98. private:
  99. bool hasData() const { return m_dataBuffer; }
  100. size_t dataLength() const;
  101. void appendData(const char* data, size_t dataLength);
  102. size_t decodeDataToContent();
  103. String m_requestId;
  104. String m_loaderId;
  105. String m_frameId;
  106. String m_url;
  107. String m_content;
  108. RefPtr<XHRReplayData> m_xhrReplayData;
  109. bool m_base64Encoded;
  110. RefPtr<SharedBuffer> m_dataBuffer;
  111. bool m_isContentEvicted;
  112. InspectorPageAgent::ResourceType m_type;
  113. int m_httpStatusCode;
  114. String m_textEncodingName;
  115. RefPtr<TextResourceDecoder> m_decoder;
  116. RefPtr<SharedBuffer> m_buffer;
  117. CachedResource* m_cachedResource;
  118. };
  119. NetworkResourcesData();
  120. ~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());
  133. void setResourcesDataSizeLimits(size_t maximumResourcesContentSize, size_t maximumSingleResourceContentSize);
  134. void setXHRReplayData(const String& requestId, XHRReplayData*);
  135. void reuseXHRReplayData(const String& requestId, const String& reusedRequestId);
  136. XHRReplayData* xhrReplayData(const String& requestId);
  137. private:
  138. ResourceData* resourceDataForRequestId(const String& requestId);
  139. void ensureNoDataForRequestId(const String& requestId);
  140. bool ensureFreeSpace(size_t);
  141. Deque<String> m_requestIdsDeque;
  142. typedef HashMap<String, String> ReusedRequestIds;
  143. ReusedRequestIds m_reusedXHRReplayDataRequestIds;
  144. typedef HashMap<String, ResourceData*> ResourceDataMap;
  145. ResourceDataMap m_requestIdToResourceDataMap;
  146. size_t m_contentSize;
  147. size_t m_maximumResourcesContentSize;
  148. size_t m_maximumSingleResourceContentSize;
  149. };
  150. } // namespace WebCore
  151. #endif // ENABLE(INSPECTOR)
  152. #endif // !defined(NetworkResourcesData_h)