| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_ | |
| 6 #define WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_ | |
| 7 | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "HTTPHeaderMap.h" | |
| 11 #include "KURL.h" | |
| 12 #include <wtf/HashMap.h> | |
| 13 #include <wtf/RefCounted.h> | |
| 14 #include <wtf/RefPtr.h> | |
| 15 #include <wtf/Vector.h> | |
| 16 | |
| 17 #include "webkit/glue/devtools/net_agent.h" | |
| 18 | |
| 19 namespace WebCore { | |
| 20 class Document; | |
| 21 class DocumentLoader; | |
| 22 class HTTPHeaderMap; | |
| 23 class ResourceError; | |
| 24 class ResourceResponse; | |
| 25 class ScriptString; | |
| 26 class String; | |
| 27 struct ResourceRequest; | |
| 28 } | |
| 29 | |
| 30 class Value; | |
| 31 | |
| 32 // NetAgent is a utility object that covers network-related functionality of the | |
| 33 // WebDevToolsAgent. It is capable of sniffing network calls and passing the | |
| 34 // HttpRequest-related data to the client. | |
| 35 // NetAgent's environment is represented with the NetAgentDelegate interface. | |
| 36 class NetAgentImpl : public NetAgent { | |
| 37 public: | |
| 38 explicit NetAgentImpl(NetAgentDelegate* delegate); | |
| 39 virtual ~NetAgentImpl(); | |
| 40 | |
| 41 // Initializes net agent with the given document. | |
| 42 void SetDocument(WebCore::Document* document); | |
| 43 | |
| 44 // Tells agent it has attached client. | |
| 45 void Attach(); | |
| 46 | |
| 47 // Tells agent it has no attached client. | |
| 48 void Detach(); | |
| 49 | |
| 50 // Tells agent that new load has been committed. | |
| 51 void DidCommitMainResourceLoad(); | |
| 52 | |
| 53 // NetAgent implementation. | |
| 54 void GetResourceContent(int call_id, int identifier, | |
| 55 const WebCore::String& request_url); | |
| 56 void AssignIdentifierToRequest( | |
| 57 WebCore::DocumentLoader* loader, | |
| 58 int identifier, | |
| 59 const WebCore::ResourceRequest& request); | |
| 60 void WillSendRequest( | |
| 61 WebCore::DocumentLoader* loader, | |
| 62 int identifier, | |
| 63 const WebCore::ResourceRequest& request); | |
| 64 void DidReceiveResponse( | |
| 65 WebCore::DocumentLoader* loader, | |
| 66 int identifier, | |
| 67 const WebCore::ResourceResponse &response); | |
| 68 void DidReceiveContentLength( | |
| 69 WebCore::DocumentLoader* loader, | |
| 70 int identifier, | |
| 71 int length); | |
| 72 void DidFinishLoading( | |
| 73 WebCore::DocumentLoader* loader, | |
| 74 int identifier); | |
| 75 void DidFailLoading( | |
| 76 WebCore::DocumentLoader* loader, | |
| 77 int identifier, | |
| 78 const WebCore::ResourceError& error); | |
| 79 void DidLoadResourceFromMemoryCache( | |
| 80 WebCore::DocumentLoader* loader, | |
| 81 const WebCore::ResourceRequest& request, | |
| 82 const WebCore::ResourceResponse& response, | |
| 83 int length); | |
| 84 void DidLoadResourceByXMLHttpRequest( | |
| 85 int identifier, | |
| 86 const WebCore::ScriptString& source); | |
| 87 | |
| 88 private: | |
| 89 struct Resource { | |
| 90 Resource() | |
| 91 : main_resource(false), | |
| 92 start_time(0), | |
| 93 response_received_time(0), | |
| 94 end_time(0), | |
| 95 expected_content_length(0), | |
| 96 http_status_code(0), | |
| 97 error_code(0) { | |
| 98 } | |
| 99 bool main_resource; | |
| 100 | |
| 101 double start_time; | |
| 102 double response_received_time; | |
| 103 double end_time; | |
| 104 | |
| 105 WebCore::KURL url; | |
| 106 WebCore::String mime_type; | |
| 107 WebCore::String suggested_filename; | |
| 108 | |
| 109 int expected_content_length; | |
| 110 int http_status_code; | |
| 111 | |
| 112 WebCore::HTTPHeaderMap request_headers; | |
| 113 WebCore::HTTPHeaderMap response_headers; | |
| 114 | |
| 115 int error_code; | |
| 116 WebCore::String error_description; | |
| 117 }; | |
| 118 | |
| 119 static void Serialize(const Resource& resource, DictionaryValue* value); | |
| 120 | |
| 121 // Serializes headers map into a value. | |
| 122 static Value* BuildValueForHeaders(const WebCore::HTTPHeaderMap& headers); | |
| 123 | |
| 124 void ExpireFinishedResourcesCache(); | |
| 125 | |
| 126 NetAgentDelegate* delegate_; | |
| 127 WebCore::Document* document_; | |
| 128 RefPtr<WebCore::DocumentLoader> main_loader_; | |
| 129 typedef HashMap<int, Resource*, DefaultHash<int>::Hash, | |
| 130 WTF::UnsignedWithZeroKeyHashTraits<int> > ResourcesMap; | |
| 131 typedef Vector<std::pair<int, Resource*> > FinishedResources; | |
| 132 typedef HashMap<int, WebCore::ScriptString, DefaultHash<int>::Hash, | |
| 133 WTF::UnsignedWithZeroKeyHashTraits<int> > XmlHttpSources; | |
| 134 | |
| 135 ResourcesMap pending_resources_; | |
| 136 FinishedResources finished_resources_; | |
| 137 XmlHttpSources xml_http_sources_; | |
| 138 int last_cached_identifier_; | |
| 139 bool attached_; | |
| 140 DISALLOW_COPY_AND_ASSIGN(NetAgentImpl); | |
| 141 }; | |
| 142 | |
| 143 #endif // WEBKIT_GLUE_DEVTOOLS_NET_AGENT_IMPL_H_ | |
| OLD | NEW |