1 /* 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> 4 * Copyright (C) 2009 Google Inc. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 16 * its contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 #ifndef InspectorResource_h 32 #define InspectorResource_h 33 34 #include "HTTPHeaderMap.h" 35 #include "KURL.h" 36 #include "ScriptObject.h" 37 #include "ScriptState.h" 38 #include "ScriptString.h" 39 40 #include <wtf/CurrentTime.h> 41 #include <wtf/OwnPtr.h> 42 #include <wtf/PassRefPtr.h> 43 #include <wtf/RefCounted.h> 44 #include <wtf/RefPtr.h> 45 46 namespace WebCore { 47 48 class CachedResource; 49 class DocumentLoader; 50 class InspectorFrontend; 51 class Frame; 52 class ResourceResponse; 53 54 struct ResourceRequest; 55 56 class InspectorResource : public RefCounted<InspectorResource> { 57 public: 58 59 // Keep these in sync with WebInspector.Resource.Type 60 enum Type { 61 Doc, 62 Stylesheet, 63 Image, 64 Font, 65 Script, 66 XHR, 67 Media, 68 Other 69 }; 70 create(long long identifier,DocumentLoader * loader)71 static PassRefPtr<InspectorResource> create(long long identifier, DocumentLoader* loader) 72 { 73 return adoptRef(new InspectorResource(identifier, loader)); 74 } 75 76 static PassRefPtr<InspectorResource> createCached(long long identifier, DocumentLoader*, const CachedResource*); 77 78 ~InspectorResource(); 79 80 void createScriptObject(InspectorFrontend* frontend); 81 void updateScriptObject(InspectorFrontend* frontend); 82 void releaseScriptObject(InspectorFrontend* frontend, bool callRemoveResource); 83 84 void updateRequest(const ResourceRequest&); 85 void updateResponse(const ResourceResponse&); 86 87 void setXMLHttpResponseText(const ScriptString& data); 88 89 String sourceString() const; isSameLoader(DocumentLoader * loader)90 bool isSameLoader(DocumentLoader* loader) const { return loader == m_loader; } markMainResource()91 void markMainResource() { m_isMainResource = true; } identifier()92 long long identifier() const { return m_identifier; } requestURL()93 String requestURL() const { return m_requestURL.string(); } frame()94 Frame* frame() const { return m_frame.get(); } mimeType()95 const String& mimeType() const { return m_mimeType; } 96 void startTiming(); 97 void markResponseReceivedTime(); 98 void endTiming(); 99 100 void markFailed(); 101 void addLength(int lengthReceived); 102 103 private: 104 enum ChangeType { 105 NoChange = 0, 106 RequestChange = 1, 107 ResponseChange = 2, 108 TypeChange = 4, 109 LengthChange = 8, 110 CompletionChange = 16, 111 TimingChange = 32 112 }; 113 114 class Changes { 115 public: Changes()116 Changes() : m_change(NoChange) {} 117 hasChange(ChangeType change)118 inline bool hasChange(ChangeType change) { return (m_change & change) || !(m_change + change); } set(ChangeType change)119 inline void set(ChangeType change) 120 { 121 m_change = static_cast<ChangeType>(static_cast<unsigned>(m_change) | static_cast<unsigned>(change)); 122 } clear(ChangeType change)123 inline void clear(ChangeType change) 124 { 125 m_change = static_cast<ChangeType>(static_cast<unsigned>(m_change) & ~static_cast<unsigned>(change)); 126 } 127 setAll()128 inline void setAll() { m_change = static_cast<ChangeType>(63); } clearAll()129 inline void clearAll() { m_change = NoChange; } 130 131 private: 132 ChangeType m_change; 133 }; 134 135 InspectorResource(long long identifier, DocumentLoader*); 136 Type type() const; 137 138 long long m_identifier; 139 RefPtr<DocumentLoader> m_loader; 140 RefPtr<Frame> m_frame; 141 KURL m_requestURL; 142 HTTPHeaderMap m_requestHeaderFields; 143 HTTPHeaderMap m_responseHeaderFields; 144 String m_mimeType; 145 String m_suggestedFilename; 146 bool m_scriptObjectCreated; 147 long long m_expectedContentLength; 148 bool m_cached; 149 bool m_finished; 150 bool m_failed; 151 int m_length; 152 int m_responseStatusCode; 153 double m_startTime; 154 double m_responseReceivedTime; 155 double m_endTime; 156 ScriptString m_xmlHttpResponseText; 157 Changes m_changes; 158 bool m_isMainResource; 159 }; 160 161 } // namespace WebCore 162 163 #endif // InspectorResource_h 164