| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file replaces WebCore/platform/network/win/ResourceHandleWin.cpp with a | 5 // This file replaces WebCore/platform/network/win/ResourceHandleWin.cpp with a |
| 6 // platform-neutral implementation that simply defers almost entirely to | 6 // platform-neutral implementation that simply defers almost entirely to |
| 7 // ResouceLoaderBridge. | 7 // ResouceLoaderBridge. |
| 8 // | 8 // |
| 9 // This uses the same ResourceHandle.h header file that the rest of WebKit | 9 // This uses the same ResourceHandle.h header file that the rest of WebKit |
| 10 // uses, allowing us to avoid complicated changes. Our specific things are | 10 // uses, allowing us to avoid complicated changes. Our specific things are |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 // as long as it doesn't care about canceling the request. Although this is | 21 // as long as it doesn't care about canceling the request. Although this is |
| 22 // dumb, we support it. We use pending_ to indicate this extra AddRef, which | 22 // dumb, we support it. We use pending_ to indicate this extra AddRef, which |
| 23 // is done in start() and released in OnCompletedRequest. | 23 // is done in start() and released in OnCompletedRequest. |
| 24 | 24 |
| 25 #include "config.h" | 25 #include "config.h" |
| 26 | 26 |
| 27 #include "base/compiler_specific.h" | 27 #include "base/compiler_specific.h" |
| 28 | 28 |
| 29 MSVC_PUSH_WARNING_LEVEL(0); | 29 MSVC_PUSH_WARNING_LEVEL(0); |
| 30 #include "CString.h" | 30 #include "CString.h" |
| 31 #include "Console.h" | |
| 32 #include "DocLoader.h" | 31 #include "DocLoader.h" |
| 33 #include "DOMWindow.h" | |
| 34 #include "FormData.h" | 32 #include "FormData.h" |
| 35 #include "FrameLoader.h" | 33 #include "FrameLoader.h" |
| 36 #include "Page.h" | 34 #include "Page.h" |
| 37 #include "ResourceError.h" | 35 #include "ResourceError.h" |
| 38 #include "ResourceHandle.h" | 36 #include "ResourceHandle.h" |
| 39 #include "ResourceHandleClient.h" | 37 #include "ResourceHandleClient.h" |
| 40 #include "ResourceRequest.h" | 38 #include "ResourceRequest.h" |
| 41 #include "ResourceResponse.h" | 39 #include "ResourceResponse.h" |
| 42 MSVC_POP_WARNING(); | 40 MSVC_POP_WARNING(); |
| 43 | 41 |
| 44 #undef LOG | 42 #undef LOG |
| 45 #include "base/logging.h" | 43 #include "base/logging.h" |
| 46 #include "base/message_loop.h" | 44 #include "base/message_loop.h" |
| 47 #include "base/process_util.h" | 45 #include "base/process_util.h" |
| 48 #include "base/time.h" | 46 #include "base/time.h" |
| 49 #include "base/string_util.h" | 47 #include "base/string_util.h" |
| 50 #include "base/string_tokenizer.h" | 48 #include "base/string_tokenizer.h" |
| 51 #include "webkit/glue/feed_preview.h" | 49 #include "webkit/glue/feed_preview.h" |
| 52 #include "webkit/glue/glue_util.h" | 50 #include "webkit/glue/glue_util.h" |
| 53 #include "webkit/glue/multipart_response_delegate.h" | 51 #include "webkit/glue/multipart_response_delegate.h" |
| 54 #include "webkit/glue/resource_loader_bridge.h" | 52 #include "webkit/glue/resource_loader_bridge.h" |
| 55 #include "webkit/glue/webframe_impl.h" | |
| 56 #include "net/base/data_url.h" | 53 #include "net/base/data_url.h" |
| 57 #include "net/base/net_errors.h" | 54 #include "net/base/net_errors.h" |
| 58 #include "net/base/net_util.h" | 55 #include "net/base/net_util.h" |
| 59 #include "net/base/load_flags.h" | 56 #include "net/base/load_flags.h" |
| 60 #include "net/http/http_response_headers.h" | 57 #include "net/http/http_response_headers.h" |
| 61 | 58 |
| 62 using webkit_glue::ResourceLoaderBridge; | 59 using webkit_glue::ResourceLoaderBridge; |
| 63 using base::Time; | 60 using base::Time; |
| 64 using base::TimeDelta; | 61 using base::TimeDelta; |
| 65 using net::HttpResponseHeaders; | 62 using net::HttpResponseHeaders; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 305 | 302 |
| 306 // We are done using the object. ResourceHandle and ResourceHandleInternal | 303 // We are done using the object. ResourceHandle and ResourceHandleInternal |
| 307 // might be destroyed now. | 304 // might be destroyed now. |
| 308 job_->deref(); | 305 job_->deref(); |
| 309 } | 306 } |
| 310 | 307 |
| 311 bool ResourceHandleInternal::Start( | 308 bool ResourceHandleInternal::Start( |
| 312 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { | 309 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { |
| 313 DCHECK(!bridge_.get()); | 310 DCHECK(!bridge_.get()); |
| 314 | 311 |
| 315 // The WebFrame is the Frame's FrameWinClient | |
| 316 WebFrameImpl* webframe = | |
| 317 request_.frame() ? WebFrameImpl::FromFrame(request_.frame()) : NULL; | |
| 318 | |
| 319 CString method = request_.httpMethod().latin1(); | 312 CString method = request_.httpMethod().latin1(); |
| 320 GURL referrer(webkit_glue::StringToStdString(request_.httpReferrer())); | 313 GURL referrer(webkit_glue::StringToStdString(request_.httpReferrer())); |
| 321 | 314 |
| 322 // Compute the URL of the load. | 315 // Compute the URL of the load. |
| 323 GURL url = webkit_glue::KURLToGURL(request_.url()); | 316 GURL url = webkit_glue::KURLToGURL(request_.url()); |
| 324 if (url.SchemeIs("feed:")) { | 317 if (url.SchemeIs("feed:")) { |
| 325 // Feed URLs are special, they actually mean "http". | 318 // Feed URLs are special, they actually mean "http". |
| 326 url_canon::Replacements<char> replacements; | 319 url_canon::Replacements<char> replacements; |
| 327 replacements.SetScheme("http", url_parse::Component(0, 4)); | 320 replacements.SetScheme("http", url_parse::Component(0, 4)); |
| 328 url = url.ReplaceComponents(replacements); | 321 url = url.ReplaceComponents(replacements); |
| 329 | 322 |
| 330 // Replace our client with a client that understands previewing feeds | 323 // Replace our client with a client that understands previewing feeds |
| 331 // and forwards the feeds along to the original client. | 324 // and forwards the feeds along to the original client. |
| 332 feed_client_proxy_.reset(new FeedClientProxy(client_)); | 325 feed_client_proxy_.reset(new FeedClientProxy(client_)); |
| 333 client_ = feed_client_proxy_.get(); | 326 client_ = feed_client_proxy_.get(); |
| 334 } | 327 } |
| 335 | 328 |
| 336 // Inherit the policy URL from the request's frame. However, if the request | |
| 337 // is for a main frame, the current document's policyBaseURL is the old | |
| 338 // document, so we leave policyURL empty to indicate that the request is a | |
| 339 // first-party request. | |
| 340 GURL policy_url; | |
| 341 if (request_.targetType() != ResourceRequest::TargetIsMainFrame && | |
| 342 request_.frame() && request_.frame()->document()) { | |
| 343 policy_url = GURL(webkit_glue::StringToStdString( | |
| 344 request_.frame()->document()->policyBaseURL())); | |
| 345 } | |
| 346 | |
| 347 switch (request_.cachePolicy()) { | 329 switch (request_.cachePolicy()) { |
| 348 case ReloadIgnoringCacheData: | 330 case ReloadIgnoringCacheData: |
| 349 // Required by LayoutTests/http/tests/misc/refresh-headers.php | 331 // Required by LayoutTests/http/tests/misc/refresh-headers.php |
| 350 load_flags_ |= net::LOAD_VALIDATE_CACHE; | 332 load_flags_ |= net::LOAD_VALIDATE_CACHE; |
| 351 break; | 333 break; |
| 352 case ReturnCacheDataElseLoad: | 334 case ReturnCacheDataElseLoad: |
| 353 load_flags_ |= net::LOAD_PREFERRING_CACHE; | 335 load_flags_ |= net::LOAD_PREFERRING_CACHE; |
| 354 break; | 336 break; |
| 355 case ReturnCacheDataDontLoad: | 337 case ReturnCacheDataDontLoad: |
| 356 load_flags_ |= net::LOAD_ONLY_FROM_CACHE; | 338 load_flags_ |= net::LOAD_ONLY_FROM_CACHE; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 387 // Skip over "Cache-Control: max-age=0" header if the corresponding | 369 // Skip over "Cache-Control: max-age=0" header if the corresponding |
| 388 // load flag is already specified. FrameLoader sets both the flag and | 370 // load flag is already specified. FrameLoader sets both the flag and |
| 389 // the extra header -- the extra header is redundant since our network | 371 // the extra header -- the extra header is redundant since our network |
| 390 // implementation will add the necessary headers based on load flags. | 372 // implementation will add the necessary headers based on load flags. |
| 391 // See http://code.google.com/p/chromium/issues/detail?id=3434. | 373 // See http://code.google.com/p/chromium/issues/detail?id=3434. |
| 392 if ((load_flags_ & net::LOAD_VALIDATE_CACHE) && | 374 if ((load_flags_ & net::LOAD_VALIDATE_CACHE) && |
| 393 equalIgnoringCase((*it).first, "cache-control") && | 375 equalIgnoringCase((*it).first, "cache-control") && |
| 394 (*it).second == "max-age=0") | 376 (*it).second == "max-age=0") |
| 395 continue; | 377 continue; |
| 396 | 378 |
| 397 // WinInet dies if blank headers are set. TODO(darin): Is this still an | |
| 398 // issue now that we are using WinHTTP? | |
| 399 if ((*it).first.isEmpty()) { | |
| 400 webframe->frame()->domWindow()->console()->addMessage( | |
| 401 JSMessageSource, | |
| 402 ErrorMessageLevel, | |
| 403 "Refused to set blank header", | |
| 404 1, | |
| 405 String()); | |
| 406 continue; | |
| 407 } | |
| 408 if (!headerBuf.isEmpty()) | 379 if (!headerBuf.isEmpty()) |
| 409 headerBuf.append(crlf); | 380 headerBuf.append(crlf); |
| 410 headerBuf.append((*it).first + sep + (*it).second); | 381 headerBuf.append((*it).first + sep + (*it).second); |
| 411 } | 382 } |
| 412 | 383 |
| 413 // TODO(jcampan): in the non out-of-process plugin case the request does not | 384 // TODO(jcampan): in the non out-of-process plugin case the request does not |
| 414 // have a origin_pid. Find a better place to set this. | 385 // have a requestor_pid. Find a better place to set this. |
| 415 int origin_pid = request_.originPid(); | 386 int requestor_pid = request_.requestorProcessID(); |
| 416 if (origin_pid == 0) | 387 if (requestor_pid == 0) |
| 417 origin_pid = base::GetCurrentProcId(); | 388 requestor_pid = base::GetCurrentProcId(); |
| 418 | 389 |
| 419 bool mixed_content = | 390 bool mixed_content = |
| 420 webkit_glue::KURLToGURL(request_.mainDocumentURL()).SchemeIsSecure() && | 391 webkit_glue::KURLToGURL(request_.mainDocumentURL()).SchemeIsSecure() && |
| 421 !url.SchemeIsSecure(); | 392 !url.SchemeIsSecure(); |
| 422 | 393 |
| 423 if (url.SchemeIs("data")) { | 394 if (url.SchemeIs("data")) { |
| 424 if (sync_load_response) { | 395 if (sync_load_response) { |
| 425 // This is a sync load. Do the work now. | 396 // This is a sync load. Do the work now. |
| 426 sync_load_response->url = url; | 397 sync_load_response->url = url; |
| 427 std::string data; | 398 std::string data; |
| 428 GetInfoFromDataUrl(sync_load_response->url, sync_load_response, | 399 GetInfoFromDataUrl(sync_load_response->url, sync_load_response, |
| 429 &sync_load_response->data, | 400 &sync_load_response->data, |
| 430 &sync_load_response->status); | 401 &sync_load_response->status); |
| 431 } else { | 402 } else { |
| 432 pending_ = true; | 403 pending_ = true; |
| 433 job_->ref(); // to be released when we get a OnCompletedRequest. | 404 job_->ref(); // to be released when we get a OnCompletedRequest. |
| 434 job_->ref(); // to be released when HandleDataUrl is completed. | 405 job_->ref(); // to be released when HandleDataUrl is completed. |
| 435 MessageLoop::current()->PostTask(FROM_HERE, | 406 MessageLoop::current()->PostTask(FROM_HERE, |
| 436 data_url_factory_.NewRunnableMethod( | 407 data_url_factory_.NewRunnableMethod( |
| 437 &ResourceHandleInternal::HandleDataUrl)); | 408 &ResourceHandleInternal::HandleDataUrl)); |
| 438 } | 409 } |
| 439 return true; | 410 return true; |
| 440 } | 411 } |
| 441 | 412 |
| 442 // TODO(darin): is latin1 really correct here? It is if the strings are | 413 // TODO(darin): is latin1 really correct here? It is if the strings are |
| 443 // already ASCII (i.e., if they are already escaped properly). | 414 // already ASCII (i.e., if they are already escaped properly). |
| 444 // TODO(brettw) this should take parameter encoding into account when | 415 // TODO(brettw) this should take parameter encoding into account when |
| 445 // creating the GURLs. | 416 // creating the GURLs. |
| 446 bridge_.reset(ResourceLoaderBridge::Create( | 417 bridge_.reset(ResourceLoaderBridge::Create( |
| 447 webframe, | |
| 448 webkit_glue::CStringToStdString(method), | 418 webkit_glue::CStringToStdString(method), |
| 449 url, | 419 url, |
| 450 policy_url, | 420 webkit_glue::KURLToGURL(request_.policyURL()), |
| 451 referrer, | 421 referrer, |
| 452 webkit_glue::CStringToStdString(headerBuf.latin1()), | 422 webkit_glue::CStringToStdString(headerBuf.latin1()), |
| 453 load_flags_, | 423 load_flags_, |
| 454 origin_pid, | 424 requestor_pid, |
| 455 FromTargetType(request_.targetType()), | 425 FromTargetType(request_.targetType()), |
| 456 mixed_content)); | 426 mixed_content, |
| 427 request_.requestorID())); |
| 457 if (!bridge_.get()) | 428 if (!bridge_.get()) |
| 458 return false; | 429 return false; |
| 459 | 430 |
| 460 if (request_.httpBody()) { | 431 if (request_.httpBody()) { |
| 461 // GET and HEAD requests shouldn't have http bodies. | 432 // GET and HEAD requests shouldn't have http bodies. |
| 462 DCHECK(method != "GET" && method != "HEAD"); | 433 DCHECK(method != "GET" && method != "HEAD"); |
| 463 const Vector<FormDataElement>& elements = request_.httpBody()->elements(); | 434 const Vector<FormDataElement>& elements = request_.httpBody()->elements(); |
| 464 size_t n = elements.size(); | 435 size_t n = elements.size(); |
| 465 for (size_t i = 0; i < n; ++i) { | 436 for (size_t i = 0; i < n; ++i) { |
| 466 const FormDataElement& e = elements[static_cast<unsigned>(i)]; | 437 const FormDataElement& e = elements[static_cast<unsigned>(i)]; |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 // if the request cannot be serviced from cache. We force the 'DontLoad' | 747 // if the request cannot be serviced from cache. We force the 'DontLoad' |
| 777 // cache policy at this point to ensure that we never hit the network for | 748 // cache policy at this point to ensure that we never hit the network for |
| 778 // this request. | 749 // this request. |
| 779 // | 750 // |
| 780 DCHECK(request.httpMethod() == "POST"); | 751 DCHECK(request.httpMethod() == "POST"); |
| 781 request.setCachePolicy(ReturnCacheDataDontLoad); | 752 request.setCachePolicy(ReturnCacheDataDontLoad); |
| 782 return true; | 753 return true; |
| 783 } | 754 } |
| 784 | 755 |
| 785 } // namespace WebCore | 756 } // namespace WebCore |
| OLD | NEW |