| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
| 6 | 6 |
| 7 #include "webkit/glue/weburlloader_impl.h" | 7 #include "webkit/glue/weburlloader_impl.h" |
| 8 | 8 |
| 9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 | 178 |
| 179 // Build up the header map. | 179 // Build up the header map. |
| 180 void* iter = NULL; | 180 void* iter = NULL; |
| 181 std::string name; | 181 std::string name; |
| 182 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 182 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 183 response->addHTTPHeaderField(StdStringToWebString(name), | 183 response->addHTTPHeaderField(StdStringToWebString(name), |
| 184 StdStringToWebString(value)); | 184 StdStringToWebString(value)); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // namespace | 188 } // namespace |
| 189 | 189 |
| 190 // WebURLLoaderImpl::Context -------------------------------------------------- | 190 // WebURLLoaderImpl::Context -------------------------------------------------- |
| 191 | 191 |
| 192 // This inner class exists since the WebURLLoader may be deleted while inside a | 192 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 193 // call to WebURLLoaderClient. The bridge requires its Peer to stay alive | 193 // call to WebURLLoaderClient. The bridge requires its Peer to stay alive |
| 194 // until it receives OnCompletedRequest. | 194 // until it receives OnCompletedRequest. |
| 195 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, | 195 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, |
| 196 public ResourceLoaderBridge::Peer { | 196 public ResourceLoaderBridge::Peer { |
| 197 public: | 197 public: |
| 198 explicit Context(WebURLLoaderImpl* loader); | 198 explicit Context(WebURLLoaderImpl* loader); |
| 199 | 199 |
| 200 WebURLLoaderClient* client() const { return client_; } | 200 WebURLLoaderClient* client() const { return client_; } |
| 201 void set_client(WebURLLoaderClient* client) { client_ = client; } | 201 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 202 | 202 |
| 203 void Cancel(); | 203 void Cancel(); |
| 204 void SetDefersLoading(bool value); | 204 void SetDefersLoading(bool value); |
| 205 void Start( | 205 void Start( |
| 206 const WebURLRequest& request, | 206 const WebURLRequest& request, |
| 207 ResourceLoaderBridge::SyncLoadResponse* sync_load_response); | 207 ResourceLoaderBridge::SyncLoadResponse* sync_load_response); |
| 208 | 208 |
| 209 // ResourceLoaderBridge::Peer methods: | 209 // ResourceLoaderBridge::Peer methods: |
| 210 virtual void OnUploadProgress(uint64 position, uint64 size); | 210 virtual void OnUploadProgress(uint64 position, uint64 size); |
| 211 virtual bool OnReceivedRedirect( | 211 virtual bool OnReceivedRedirect( |
| 212 const GURL& new_url, const ResourceLoaderBridge::ResponseInfo& info); | 212 const GURL& new_url, |
| 213 const ResourceLoaderBridge::ResponseInfo& info, |
| 214 GURL* new_first_party_for_cookies); |
| 213 virtual void OnReceivedResponse( | 215 virtual void OnReceivedResponse( |
| 214 const ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); | 216 const ResourceLoaderBridge::ResponseInfo& info, bool content_filtered); |
| 215 virtual void OnReceivedData(const char* data, int len); | 217 virtual void OnReceivedData(const char* data, int len); |
| 216 virtual void OnCompletedRequest( | 218 virtual void OnCompletedRequest( |
| 217 const URLRequestStatus& status, const std::string& security_info); | 219 const URLRequestStatus& status, const std::string& security_info); |
| 218 virtual GURL GetURLForDebugging() const; | 220 virtual GURL GetURLForDebugging() const; |
| 219 | 221 |
| 220 private: | 222 private: |
| 221 friend class base::RefCounted<Context>; | 223 friend class base::RefCounted<Context>; |
| 222 ~Context() {} | 224 ~Context() {} |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { | 386 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { |
| 385 if (client_) | 387 if (client_) |
| 386 client_->didSendData(loader_, position, size); | 388 client_->didSendData(loader_, position, size); |
| 387 } | 389 } |
| 388 | 390 |
| 389 bool WebURLLoaderImpl::Context::OnReceivedRedirect( | 391 bool WebURLLoaderImpl::Context::OnReceivedRedirect( |
| 390 const GURL& new_url, | 392 const GURL& new_url, |
| 391 const ResourceLoaderBridge::ResponseInfo& info) { | 393 const ResourceLoaderBridge::ResponseInfo& info, |
| 394 GURL* new_first_party_for_cookies) { |
| 392 if (!client_) | 395 if (!client_) |
| 393 return false; | 396 return false; |
| 394 | 397 |
| 395 WebURLResponse response; | 398 WebURLResponse response; |
| 396 response.initialize(); | 399 response.initialize(); |
| 397 PopulateURLResponse(request_.url(), info, &response); | 400 PopulateURLResponse(request_.url(), info, &response); |
| 398 | 401 |
| 399 // TODO(darin): We lack sufficient information to construct the actual | 402 // TODO(darin): We lack sufficient information to construct the actual |
| 400 // request that resulted from the redirect. | 403 // request that resulted from the redirect. |
| 401 WebURLRequest new_request(new_url); | 404 WebURLRequest new_request(new_url); |
| 402 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); | 405 new_request.setFirstPartyForCookies(request_.firstPartyForCookies()); |
| 403 if (response.httpStatusCode() == 307) | 406 if (response.httpStatusCode() == 307) |
| 404 new_request.setHTTPMethod(request_.httpMethod()); | 407 new_request.setHTTPMethod(request_.httpMethod()); |
| 405 | 408 |
| 409 client_->willSendRequest(loader_, new_request, response); |
| 406 request_ = new_request; | 410 request_ = new_request; |
| 407 client_->willSendRequest(loader_, new_request, response); | 411 *new_first_party_for_cookies = request_.firstPartyForCookies(); |
| 408 | 412 |
| 409 // Only follow the redirect if WebKit left the URL unmodified. | 413 // Only follow the redirect if WebKit left the URL unmodified. |
| 410 if (new_url == GURL(new_request.url())) | 414 if (new_url == GURL(new_request.url())) |
| 411 return true; | 415 return true; |
| 412 | 416 |
| 413 // We assume that WebKit only changes the URL to suppress a redirect, and we | 417 // We assume that WebKit only changes the URL to suppress a redirect, and we |
| 414 // assume that it does so by setting it to be invalid. | 418 // assume that it does so by setting it to be invalid. |
| 415 DCHECK(!new_request.url().isValid()); | 419 DCHECK(!new_request.url().isValid()); |
| 416 return false; | 420 return false; |
| 417 } | 421 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 | 584 |
| 581 void WebURLLoaderImpl::cancel() { | 585 void WebURLLoaderImpl::cancel() { |
| 582 context_->Cancel(); | 586 context_->Cancel(); |
| 583 } | 587 } |
| 584 | 588 |
| 585 void WebURLLoaderImpl::setDefersLoading(bool value) { | 589 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 586 context_->SetDefersLoading(value); | 590 context_->SetDefersLoading(value); |
| 587 } | 591 } |
| 588 | 592 |
| 589 } // namespace webkit_glue | 593 } // namespace webkit_glue |
| OLD | NEW |