| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 261 |
| 262 // Build up the header map. | 262 // Build up the header map. |
| 263 void* iter = NULL; | 263 void* iter = NULL; |
| 264 std::string name; | 264 std::string name; |
| 265 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 265 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 266 response->addHTTPHeaderField(WebString::fromUTF8(name), | 266 response->addHTTPHeaderField(WebString::fromUTF8(name), |
| 267 WebString::fromUTF8(value)); | 267 WebString::fromUTF8(value)); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 | 270 |
| 271 net::RequestPriority ConvertWebKitPriorityToNetPriority( | |
| 272 const WebURLRequest::Priority& priority) { | |
| 273 switch (priority) { | |
| 274 case WebURLRequest::PriorityVeryHigh: | |
| 275 return net::HIGHEST; | |
| 276 | |
| 277 case WebURLRequest::PriorityHigh: | |
| 278 return net::MEDIUM; | |
| 279 | |
| 280 case WebURLRequest::PriorityMedium: | |
| 281 return net::LOW; | |
| 282 | |
| 283 case WebURLRequest::PriorityLow: | |
| 284 return net::LOWEST; | |
| 285 | |
| 286 case WebURLRequest::PriorityVeryLow: | |
| 287 return net::IDLE; | |
| 288 | |
| 289 case WebURLRequest::PriorityUnresolved: | |
| 290 default: | |
| 291 NOTREACHED(); | |
| 292 return net::LOW; | |
| 293 } | |
| 294 } | |
| 295 | |
| 296 } // namespace | 271 } // namespace |
| 297 | 272 |
| 298 // WebURLLoaderImpl::Context -------------------------------------------------- | 273 // WebURLLoaderImpl::Context -------------------------------------------------- |
| 299 | 274 |
| 300 // This inner class exists since the WebURLLoader may be deleted while inside a | 275 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 301 // call to WebURLLoaderClient. The bridge requires its Peer to stay alive | 276 // call to WebURLLoaderClient. The bridge requires its Peer to stay alive |
| 302 // until it receives OnCompletedRequest. | 277 // until it receives OnCompletedRequest. |
| 303 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, | 278 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, |
| 304 public ResourceLoaderBridge::Peer { | 279 public ResourceLoaderBridge::Peer { |
| 305 public: | 280 public: |
| 306 explicit Context(WebURLLoaderImpl* loader); | 281 explicit Context(WebURLLoaderImpl* loader); |
| 307 | 282 |
| 308 WebURLLoaderClient* client() const { return client_; } | 283 WebURLLoaderClient* client() const { return client_; } |
| 309 void set_client(WebURLLoaderClient* client) { client_ = client; } | 284 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 310 | 285 |
| 311 void Cancel(); | 286 void Cancel(); |
| 312 void SetDefersLoading(bool value); | 287 void SetDefersLoading(bool value); |
| 313 void DidChangePriority(WebURLRequest::Priority new_priority); | |
| 314 void Start( | 288 void Start( |
| 315 const WebURLRequest& request, | 289 const WebURLRequest& request, |
| 316 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 290 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 317 WebKitPlatformSupportImpl* platform); | 291 WebKitPlatformSupportImpl* platform); |
| 318 | 292 |
| 319 // ResourceLoaderBridge::Peer methods: | 293 // ResourceLoaderBridge::Peer methods: |
| 320 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 294 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
| 321 virtual bool OnReceivedRedirect( | 295 virtual bool OnReceivedRedirect( |
| 322 const GURL& new_url, | 296 const GURL& new_url, |
| 323 const ResourceResponseInfo& info, | 297 const ResourceResponseInfo& info, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 // Do not make any further calls to the client. | 347 // Do not make any further calls to the client. |
| 374 client_ = NULL; | 348 client_ = NULL; |
| 375 loader_ = NULL; | 349 loader_ = NULL; |
| 376 } | 350 } |
| 377 | 351 |
| 378 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { | 352 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { |
| 379 if (bridge_.get()) | 353 if (bridge_.get()) |
| 380 bridge_->SetDefersLoading(value); | 354 bridge_->SetDefersLoading(value); |
| 381 } | 355 } |
| 382 | 356 |
| 383 void WebURLLoaderImpl::Context::DidChangePriority( | |
| 384 WebURLRequest::Priority new_priority) { | |
| 385 if (bridge_.get()) | |
| 386 bridge_->DidChangePriority( | |
| 387 ConvertWebKitPriorityToNetPriority(new_priority)); | |
| 388 } | |
| 389 | |
| 390 void WebURLLoaderImpl::Context::Start( | 357 void WebURLLoaderImpl::Context::Start( |
| 391 const WebURLRequest& request, | 358 const WebURLRequest& request, |
| 392 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 359 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 393 WebKitPlatformSupportImpl* platform) { | 360 WebKitPlatformSupportImpl* platform) { |
| 394 DCHECK(!bridge_.get()); | 361 DCHECK(!bridge_.get()); |
| 395 | 362 |
| 396 request_ = request; // Save the request. | 363 request_ = request; // Save the request. |
| 397 | 364 |
| 398 GURL url = request.url(); | 365 GURL url = request.url(); |
| 399 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 366 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 request_info.first_party_for_cookies = request.firstPartyForCookies(); | 426 request_info.first_party_for_cookies = request.firstPartyForCookies(); |
| 460 request_info.referrer = referrer_url; | 427 request_info.referrer = referrer_url; |
| 461 request_info.headers = flattener.GetBuffer(); | 428 request_info.headers = flattener.GetBuffer(); |
| 462 request_info.load_flags = load_flags; | 429 request_info.load_flags = load_flags; |
| 463 // requestor_pid only needs to be non-zero if the request originates outside | 430 // requestor_pid only needs to be non-zero if the request originates outside |
| 464 // the render process, so we can use requestorProcessID even for requests | 431 // the render process, so we can use requestorProcessID even for requests |
| 465 // from in-process plugins. | 432 // from in-process plugins. |
| 466 request_info.requestor_pid = request.requestorProcessID(); | 433 request_info.requestor_pid = request.requestorProcessID(); |
| 467 request_info.request_type = | 434 request_info.request_type = |
| 468 ResourceType::FromTargetType(request.targetType()); | 435 ResourceType::FromTargetType(request.targetType()); |
| 469 request_info.priority = | 436 request_info.priority = request.priority(); |
| 470 ConvertWebKitPriorityToNetPriority(request.priority()); | |
| 471 request_info.appcache_host_id = request.appCacheHostID(); | 437 request_info.appcache_host_id = request.appCacheHostID(); |
| 472 request_info.routing_id = request.requestorID(); | 438 request_info.routing_id = request.requestorID(); |
| 473 request_info.download_to_file = request.downloadToFile(); | 439 request_info.download_to_file = request.downloadToFile(); |
| 474 request_info.has_user_gesture = request.hasUserGesture(); | 440 request_info.has_user_gesture = request.hasUserGesture(); |
| 475 request_info.extra_data = request.extraData(); | 441 request_info.extra_data = request.extraData(); |
| 476 if (request.extraData()) { | 442 if (request.extraData()) { |
| 477 referrer_policy_ = static_cast<WebURLRequestExtraDataImpl*>( | 443 referrer_policy_ = static_cast<WebURLRequestExtraDataImpl*>( |
| 478 request.extraData())->referrer_policy(); | 444 request.extraData())->referrer_policy(); |
| 479 request_info.referrer_policy = referrer_policy_; | 445 request_info.referrer_policy = referrer_policy_; |
| 480 } | 446 } |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 } | 777 } |
| 812 | 778 |
| 813 void WebURLLoaderImpl::cancel() { | 779 void WebURLLoaderImpl::cancel() { |
| 814 context_->Cancel(); | 780 context_->Cancel(); |
| 815 } | 781 } |
| 816 | 782 |
| 817 void WebURLLoaderImpl::setDefersLoading(bool value) { | 783 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 818 context_->SetDefersLoading(value); | 784 context_->SetDefersLoading(value); |
| 819 } | 785 } |
| 820 | 786 |
| 821 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | |
| 822 context_->DidChangePriority(new_priority); | |
| 823 } | |
| 824 | |
| 825 } // namespace webkit_glue | 787 } // namespace webkit_glue |
| OLD | NEW |