| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CachedCSSStyleSheet.h" | 7 #include "CachedCSSStyleSheet.h" |
| 8 #include "CachedResource.h" | 8 #include "CachedResource.h" |
| 9 #include "CachedScript.h" | 9 #include "CachedScript.h" |
| 10 #include "CachedXSLStyleSheet.h" | 10 #include "CachedXSLStyleSheet.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using namespace WebCore; | 31 using namespace WebCore; |
| 32 | 32 |
| 33 NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate) | 33 NetAgentImpl::NetAgentImpl(NetAgentDelegate* delegate) |
| 34 : delegate_(delegate), | 34 : delegate_(delegate), |
| 35 document_(NULL), | 35 document_(NULL), |
| 36 last_cached_identifier_(-2) { | 36 last_cached_identifier_(-2) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 NetAgentImpl::~NetAgentImpl() { | 39 NetAgentImpl::~NetAgentImpl() { |
| 40 SetDocument(NULL); | 40 SetDocument(NULL); |
| 41 for (CachedResources::iterator it = pending_resources_.begin(); |
| 42 it != pending_resources_.end(); ++it) { |
| 43 delete it->second; |
| 44 } |
| 45 pending_resources_.clear(); |
| 41 } | 46 } |
| 42 | 47 |
| 43 void NetAgentImpl::SetDocument(Document* doc) { | 48 void NetAgentImpl::SetDocument(Document* doc) { |
| 44 // loaders_.clear(); | 49 // loaders_.clear(); |
| 45 document_ = doc; | 50 document_ = doc; |
| 46 } | 51 } |
| 47 | 52 |
| 48 void NetAgentImpl::AssignIdentifierToRequest( | 53 void NetAgentImpl::AssignIdentifierToRequest( |
| 49 DocumentLoader* loader, | 54 DocumentLoader* loader, |
| 50 int identifier, | 55 int identifier, |
| 51 const ResourceRequest& request) { | 56 const ResourceRequest& request) { |
| 52 loaders_.set(identifier, loader); | 57 loaders_.set(identifier, loader); |
| 53 } | 58 } |
| 54 | 59 |
| 55 void NetAgentImpl::WillSendRequest( | 60 void NetAgentImpl::WillSendRequest( |
| 56 DocumentLoader* loader, | 61 DocumentLoader* loader, |
| 57 int identifier, | 62 int identifier, |
| 58 const ResourceRequest& request) { | 63 const ResourceRequest& request) { |
| 59 KURL url = request.url(); | 64 KURL url = request.url(); |
| 60 DictionaryValue value; | 65 DictionaryValue* resource = new DictionaryValue(); |
| 61 value.SetReal(L"startTime", WTF::currentTime()); | 66 |
| 62 value.SetString(L"url", webkit_glue::StringToStdString(url.string())); | 67 resource->SetReal(L"startTime", WTF::currentTime()); |
| 63 value.SetString(L"domain", webkit_glue::StringToStdString(url.host())); | 68 resource->SetString(L"url", webkit_glue::StringToStdString(url.string())); |
| 64 value.SetString(L"path", webkit_glue::StringToStdString(url.path())); | 69 resource->SetString(L"domain", webkit_glue::StringToStdString(url.host())); |
| 65 value.SetString(L"lastPathComponent", | 70 resource->SetString(L"path", webkit_glue::StringToStdString(url.path())); |
| 71 resource->SetString(L"lastPathComponent", |
| 66 webkit_glue::StringToStdString(url.lastPathComponent())); | 72 webkit_glue::StringToStdString(url.lastPathComponent())); |
| 67 value.Set(L"requestHeaders", | 73 resource->Set(L"requestHeaders", |
| 68 BuildValueForHeaders(request.httpHeaderFields())); | 74 BuildValueForHeaders(request.httpHeaderFields())); |
| 69 delegate_->WillSendRequest(identifier, value); | 75 delegate_->WillSendRequest(identifier, *resource); |
| 76 pending_resources_.set(identifier, resource); |
| 70 } | 77 } |
| 71 | 78 |
| 72 void NetAgentImpl::DidReceiveResponse( | 79 void NetAgentImpl::DidReceiveResponse( |
| 73 DocumentLoader* loader, | 80 DocumentLoader* loader, |
| 74 int identifier, | 81 int identifier, |
| 75 const ResourceResponse &response) { | 82 const ResourceResponse &response) { |
| 76 if (!document_) { | 83 KURL url = response.url(); |
| 84 if (!pending_resources_.contains(identifier)) { |
| 77 return; | 85 return; |
| 78 } | 86 } |
| 79 KURL url = response.url(); | 87 DictionaryValue* resource = pending_resources_.get(identifier); |
| 80 | 88 resource->SetReal(L"responseReceivedTime", WTF::currentTime()); |
| 81 DictionaryValue value; | 89 resource->SetString(L"url", |
| 82 value.SetReal(L"responseReceivedTime", WTF::currentTime()); | |
| 83 value.SetString(L"url", | |
| 84 webkit_glue::StringToStdWString(url.string())); | 90 webkit_glue::StringToStdWString(url.string())); |
| 85 value.SetInteger(L"expectedContentLength", | 91 resource->SetInteger(L"expectedContentLength", |
| 86 static_cast<int>(response.expectedContentLength())); | 92 static_cast<int>(response.expectedContentLength())); |
| 87 value.SetInteger(L"responseStatusCode", response.httpStatusCode()); | 93 resource->SetInteger(L"responseStatusCode", response.httpStatusCode()); |
| 88 value.SetString(L"mimeType", | 94 resource->SetString(L"mimeType", |
| 89 webkit_glue::StringToStdWString(response.mimeType())); | 95 webkit_glue::StringToStdWString(response.mimeType())); |
| 90 value.SetString(L"suggestedFilename", | 96 resource->SetString(L"suggestedFilename", |
| 91 webkit_glue::StringToStdWString(response.suggestedFilename())); | 97 webkit_glue::StringToStdWString(response.suggestedFilename())); |
| 92 value.Set(L"responseHeaders", | 98 resource->Set(L"responseHeaders", |
| 93 BuildValueForHeaders(response.httpHeaderFields())); | 99 BuildValueForHeaders(response.httpHeaderFields())); |
| 94 | 100 |
| 95 delegate_->DidReceiveResponse(identifier, value); | 101 delegate_->DidReceiveResponse(identifier, *resource); |
| 96 } | 102 } |
| 97 | 103 |
| 98 void NetAgentImpl::DidReceiveContentLength( | 104 void NetAgentImpl::DidReceiveContentLength( |
| 99 DocumentLoader* loader, | 105 DocumentLoader* loader, |
| 100 int identifier, | 106 int identifier, |
| 101 int length) { | 107 int length) { |
| 102 } | 108 } |
| 103 | 109 |
| 104 void NetAgentImpl::DidFinishLoading( | 110 void NetAgentImpl::DidFinishLoading( |
| 105 DocumentLoader* loader, | 111 DocumentLoader* loader, |
| 106 int identifier) { | 112 int identifier) { |
| 107 DictionaryValue value; | 113 if (!pending_resources_.contains(identifier)) { |
| 108 value.SetReal(L"endTime", WTF::currentTime()); | 114 return; |
| 109 delegate_->DidFinishLoading(identifier, value); | 115 } |
| 116 DictionaryValue* resource = pending_resources_.get(identifier); |
| 117 resource->SetReal(L"endTime", WTF::currentTime()); |
| 118 delegate_->DidFinishLoading(identifier, *resource); |
| 119 pending_resources_.remove(identifier); |
| 120 delete resource; |
| 110 } | 121 } |
| 111 | 122 |
| 112 void NetAgentImpl::DidFailLoading( | 123 void NetAgentImpl::DidFailLoading( |
| 113 DocumentLoader* loader, | 124 DocumentLoader* loader, |
| 114 int identifier, | 125 int identifier, |
| 115 const ResourceError& error) { | 126 const ResourceError& error) { |
| 116 DictionaryValue value; | 127 if (!pending_resources_.contains(identifier)) { |
| 117 value.SetReal(L"endTime", WTF::currentTime()); | 128 return; |
| 118 value.SetInteger(L"errorCode", error.errorCode()); | 129 } |
| 119 value.SetString(L"localizedDescription", | 130 DictionaryValue* resource = pending_resources_.get(identifier); |
| 131 resource->SetReal(L"endTime", WTF::currentTime()); |
| 132 resource->SetInteger(L"errorCode", error.errorCode()); |
| 133 resource->SetString(L"localizedDescription", |
| 120 webkit_glue::StringToStdString(error.localizedDescription())); | 134 webkit_glue::StringToStdString(error.localizedDescription())); |
| 121 delegate_->DidFailLoading(identifier, value); | 135 delegate_->DidFailLoading(identifier, *resource); |
| 136 pending_resources_.remove(identifier); |
| 137 delete resource; |
| 122 } | 138 } |
| 123 | 139 |
| 124 void NetAgentImpl::DidLoadResourceFromMemoryCache( | 140 void NetAgentImpl::DidLoadResourceFromMemoryCache( |
| 125 DocumentLoader* loader, | 141 DocumentLoader* loader, |
| 126 const ResourceRequest& request, | 142 const ResourceRequest& request, |
| 127 const ResourceResponse& response, | 143 const ResourceResponse& response, |
| 128 int length) { | 144 int length) { |
| 129 int identifier = last_cached_identifier_--; | 145 int identifier = last_cached_identifier_--; |
| 130 loaders_.set(identifier, loader); | 146 loaders_.set(identifier, loader); |
| 131 } | 147 } |
| 132 | 148 |
| 133 void NetAgentImpl::GetResourceContent( | 149 void NetAgentImpl::GetResourceContent( |
| 134 int call_id, | 150 int call_id, |
| 135 int identifier, | 151 int identifier, |
| 136 const String& url) { | 152 const String& url) { |
| 137 if (!document_) { | 153 if (!document_) { |
| 138 return; | 154 return; |
| 139 } | 155 } |
| 140 HashMap<int, RefPtr<DocumentLoader> >::iterator it = | 156 CachedLoaders::iterator it = loaders_.find(identifier); |
| 141 loaders_.find(identifier); | |
| 142 if (it == loaders_.end() || !it->second) { | 157 if (it == loaders_.end() || !it->second) { |
| 143 return; | 158 return; |
| 144 } | 159 } |
| 145 | 160 |
| 146 RefPtr<DocumentLoader> loader = it->second; | 161 RefPtr<DocumentLoader> loader = it->second; |
| 147 String source; | 162 String source; |
| 148 | 163 |
| 149 if (url == loader->requestURL()) { | 164 if (url == loader->requestURL()) { |
| 150 RefPtr<SharedBuffer> buffer = loader->mainResourceData(); | 165 RefPtr<SharedBuffer> buffer = loader->mainResourceData(); |
| 151 String text_encoding_name = document_->inputEncoding(); | 166 String text_encoding_name = document_->inputEncoding(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 211 |
| 197 Value* NetAgentImpl::BuildValueForHeaders(const HTTPHeaderMap& headers) { | 212 Value* NetAgentImpl::BuildValueForHeaders(const HTTPHeaderMap& headers) { |
| 198 OwnPtr<DictionaryValue> value(new DictionaryValue()); | 213 OwnPtr<DictionaryValue> value(new DictionaryValue()); |
| 199 HTTPHeaderMap::const_iterator end = headers.end(); | 214 HTTPHeaderMap::const_iterator end = headers.end(); |
| 200 for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) { | 215 for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) { |
| 201 value->SetString(webkit_glue::StringToStdWString(it->first), | 216 value->SetString(webkit_glue::StringToStdWString(it->first), |
| 202 webkit_glue::StringToStdString(it->second)); | 217 webkit_glue::StringToStdString(it->second)); |
| 203 } | 218 } |
| 204 return value.release(); | 219 return value.release(); |
| 205 } | 220 } |
| OLD | NEW |