diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/platform/network/cf | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/platform/network/cf')
-rw-r--r-- | WebCore/platform/network/cf/FormDataStreamCFNet.cpp | 88 | ||||
-rw-r--r-- | WebCore/platform/network/cf/ResourceHandleCFNet.cpp | 93 | ||||
-rw-r--r-- | WebCore/platform/network/cf/ResourceRequestCFNet.h | 2 | ||||
-rw-r--r-- | WebCore/platform/network/cf/ResourceResponse.h | 12 |
4 files changed, 61 insertions, 134 deletions
diff --git a/WebCore/platform/network/cf/FormDataStreamCFNet.cpp b/WebCore/platform/network/cf/FormDataStreamCFNet.cpp index 71fbfe7..3414d90 100644 --- a/WebCore/platform/network/cf/FormDataStreamCFNet.cpp +++ b/WebCore/platform/network/cf/FormDataStreamCFNet.cpp @@ -317,8 +317,7 @@ static void formEventCallback(CFReadStreamRef stream, CFStreamEventType type, vo void setHTTPBody(CFMutableURLRequestRef request, PassRefPtr<FormData> formData) { if (!formData) { - if (wkCanAccessCFURLRequestHTTPBodyParts()) - wkCFURLRequestSetHTTPRequestBodyParts(request, 0); + wkCFURLRequestSetHTTPRequestBodyParts(request, 0); return; } @@ -338,52 +337,20 @@ void setHTTPBody(CFMutableURLRequestRef request, PassRefPtr<FormData> formData) } } - if (wkCanAccessCFURLRequestHTTPBodyParts()) { - RetainPtr<CFMutableArrayRef> array(AdoptCF, CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks)); - - for (size_t i = 0; i < count; ++i) { - const FormDataElement& element = formData->elements()[i]; - if (element.m_type == FormDataElement::data) { - RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(0, reinterpret_cast<const UInt8*>(element.m_data.data()), element.m_data.size())); - CFArrayAppendValue(array.get(), data.get()); - } else { - RetainPtr<CFStringRef> filename(AdoptCF, element.m_filename.createCFString()); - CFArrayAppendValue(array.get(), filename.get()); - } - } + RetainPtr<CFMutableArrayRef> array(AdoptCF, CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks)); - wkCFURLRequestSetHTTPRequestBodyParts(request, array.get()); - return; - } - - // Precompute the content length so CFURLConnection doesn't use chunked mode. - bool haveLength = true; - long long length = 0; for (size_t i = 0; i < count; ++i) { const FormDataElement& element = formData->elements()[i]; - if (element.m_type == FormDataElement::data) - length += element.m_data.size(); - else { - long long size; - if (getFileSize(element.m_filename, size)) - length += size; - else - haveLength = false; + if (element.m_type == FormDataElement::data) { + RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(0, reinterpret_cast<const UInt8*>(element.m_data.data()), element.m_data.size())); + CFArrayAppendValue(array.get(), data.get()); + } else { + RetainPtr<CFStringRef> filename(AdoptCF, element.m_filename.createCFString()); + CFArrayAppendValue(array.get(), filename.get()); } } - if (haveLength) { - CFStringRef lengthStr = CFStringCreateWithFormat(0, 0, CFSTR("%lld"), length); - CFURLRequestSetHTTPHeaderFieldValue(request, CFSTR("Content-Length"), lengthStr); - CFRelease(lengthStr); - } - - static WCReadStreamCallBacks formDataStreamCallbacks = - { 1, formCreate, formFinalize, 0, formOpen, 0, formRead, 0, formCanRead, formClose, 0, 0, 0, formSchedule, formUnschedule }; - - CFReadStreamRef stream = CFReadStreamCreate(0, (CFReadStreamCallBacks *)&formDataStreamCallbacks, formData.releaseRef()); - CFURLRequestSetHTTPRequestBodyStream(request, stream); - CFRelease(stream); + wkCFURLRequestSetHTTPRequestBodyParts(request, array.get()); } PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request) @@ -391,28 +358,23 @@ PassRefPtr<FormData> httpBodyFromRequest(CFURLRequestRef request) if (RetainPtr<CFDataRef> bodyData = CFURLRequestCopyHTTPRequestBody(request)) return FormData::create(CFDataGetBytePtr(bodyData.get()), CFDataGetLength(bodyData.get())); - if (wkCanAccessCFURLRequestHTTPBodyParts()) { - if (RetainPtr<CFArrayRef> bodyParts = wkCFURLRequestCopyHTTPRequestBodyParts(request)) { - RefPtr<FormData> formData = FormData::create(); - - CFIndex count = CFArrayGetCount(bodyParts.get()); - for (CFIndex i = 0; i < count; i++) { - CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i); - CFTypeID typeID = CFGetTypeID(bodyPart); - if (typeID == CFStringGetTypeID()) { - String filename = (CFStringRef)bodyPart; - formData->appendFile(filename); - } else if (typeID == CFDataGetTypeID()) { - CFDataRef data = (CFDataRef)bodyPart; - formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data)); - } else - ASSERT_NOT_REACHED(); - } - return formData.release(); + if (RetainPtr<CFArrayRef> bodyParts = wkCFURLRequestCopyHTTPRequestBodyParts(request)) { + RefPtr<FormData> formData = FormData::create(); + + CFIndex count = CFArrayGetCount(bodyParts.get()); + for (CFIndex i = 0; i < count; i++) { + CFTypeRef bodyPart = CFArrayGetValueAtIndex(bodyParts.get(), i); + CFTypeID typeID = CFGetTypeID(bodyPart); + if (typeID == CFStringGetTypeID()) { + String filename = (CFStringRef)bodyPart; + formData->appendFile(filename); + } else if (typeID == CFDataGetTypeID()) { + CFDataRef data = (CFDataRef)bodyPart; + formData->appendData(CFDataGetBytePtr(data), CFDataGetLength(data)); + } else + ASSERT_NOT_REACHED(); } - } else { - if (RetainPtr<CFReadStreamRef> bodyStream = CFURLRequestCopyHTTPRequestBodyStream(request)) - return getStreamFormDatas().get(bodyStream.get()); + return formData.release(); } // FIXME: what to do about arbitrary body streams? diff --git a/WebCore/platform/network/cf/ResourceHandleCFNet.cpp b/WebCore/platform/network/cf/ResourceHandleCFNet.cpp index a4000a3..2dcbbed 100644 --- a/WebCore/platform/network/cf/ResourceHandleCFNet.cpp +++ b/WebCore/platform/network/cf/ResourceHandleCFNet.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,51 +53,6 @@ namespace WebCore { -static HMODULE findCFNetworkModule() -{ - if (HMODULE module = GetModuleHandleA("CFNetwork")) - return module; - return GetModuleHandleA("CFNetwork_debug"); -} - -static DWORD cfNetworkVersion() -{ - HMODULE cfNetworkModule = findCFNetworkModule(); - WCHAR filename[MAX_PATH]; - GetModuleFileName(cfNetworkModule, filename, MAX_PATH); - DWORD handle; - DWORD versionInfoSize = GetFileVersionInfoSize(filename, &handle); - Vector<BYTE> versionInfo(versionInfoSize); - GetFileVersionInfo(filename, handle, versionInfoSize, versionInfo.data()); - VS_FIXEDFILEINFO* fixedFileInfo; - UINT fixedFileInfoLength; - VerQueryValue(versionInfo.data(), TEXT("\\"), reinterpret_cast<LPVOID*>(&fixedFileInfo), &fixedFileInfoLength); - return fixedFileInfo->dwProductVersionMS; -} - -static CFIndex highestSupportedCFURLConnectionClientVersion() -{ - const DWORD firstCFNetworkVersionWithConnectionClientV2 = 0x000101a8; // 1.424 - const DWORD firstCFNetworkVersionWithConnectionClientV3 = 0x000101ad; // 1.429 - -#ifndef _CFURLConnectionClientV2Present - return 1; -#else - - DWORD version = cfNetworkVersion(); - if (version < firstCFNetworkVersionWithConnectionClientV2) - return 1; -#ifndef _CFURLConnectionClientV3Present - return 2; -#else - - if (version < firstCFNetworkVersionWithConnectionClientV3) - return 2; - return 3; -#endif // _CFURLConnectionClientV3Present -#endif // _CFURLConnectionClientV2Present -} - static HashSet<String>& allowsAnyHTTPSCertificateHosts() { static HashSet<String> hosts; @@ -154,7 +109,6 @@ void didReceiveData(CFURLConnectionRef conn, CFDataRef data, CFIndex originalLen handle->client()->didReceiveData(handle, (const char*)bytes, length, originalLength); } -#ifdef _CFURLConnectionClientV2Present static void didSendBodyData(CFURLConnectionRef conn, CFIndex bytesWritten, CFIndex totalBytesWritten, CFIndex totalBytesExpectedToWrite, const void *clientInfo) { ResourceHandle* handle = (ResourceHandle*)clientInfo; @@ -162,9 +116,7 @@ static void didSendBodyData(CFURLConnectionRef conn, CFIndex bytesWritten, CFInd return; handle->client()->didSendData(handle, totalBytesWritten, totalBytesExpectedToWrite); } -#endif -#ifdef _CFURLConnectionClientV3Present static Boolean shouldUseCredentialStorageCallback(CFURLConnectionRef conn, const void* clientInfo) { ResourceHandle* handle = const_cast<ResourceHandle*>(static_cast<const ResourceHandle*>(clientInfo)); @@ -176,7 +128,6 @@ static Boolean shouldUseCredentialStorageCallback(CFURLConnectionRef conn, const return handle->shouldUseCredentialStorage(); } -#endif void didFinishLoading(CFURLConnectionRef conn, const void* clientInfo) { @@ -202,6 +153,9 @@ CFCachedURLResponseRef willCacheResponse(CFURLConnectionRef conn, CFCachedURLRes { ResourceHandle* handle = (ResourceHandle*)clientInfo; + if (handle->client() && !handle->client()->shouldCacheResponse(handle, cachedResponse)) + return 0; + CacheStoragePolicy policy = static_cast<CacheStoragePolicy>(CFCachedURLResponseGetStoragePolicy(cachedResponse)); if (handle->client()) @@ -297,7 +251,7 @@ void* runLoaderThread(void *unused) CFRunLoopRef ResourceHandle::loaderRunLoop() { if (!loaderRL) { - createThread(runLoaderThread, 0, "CFNetwork::Loader"); + createThread(runLoaderThread, 0, "WebCore: CFNetwork Loader"); while (loaderRL == 0) { // FIXME: sleep 10? that can't be right... Sleep(10); @@ -348,20 +302,9 @@ bool ResourceHandle::start(Frame* frame) RetainPtr<CFURLRequestRef> request(AdoptCF, makeFinalRequest(d->m_request, d->m_shouldContentSniff)); - static CFIndex clientVersion = highestSupportedCFURLConnectionClientVersion(); - CFURLConnectionClient* client; -#if defined(_CFURLConnectionClientV3Present) - CFURLConnectionClient_V3 client_V3 = {clientVersion, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData, shouldUseCredentialStorageCallback, 0}; - client = reinterpret_cast<CFURLConnectionClient*>(&client_V3); -#elif defined(_CFURLConnectionClientV2Present) - CFURLConnectionClient_V2 client_V2 = {clientVersion, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData}; - client = reinterpret_cast<CFURLConnectionClient*>(&client_V2); -#else - CFURLConnectionClient client_V1 = {1, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge}; - client = &client_V1; -#endif - - d->m_connection.adoptCF(CFURLConnectionCreate(0, request.get(), client)); + CFURLConnectionClient_V3 client = { 3, this, 0, 0, 0, willSendRequest, didReceiveResponse, didReceiveData, NULL, didFinishLoading, didFail, willCacheResponse, didReceiveChallenge, didSendBodyData, shouldUseCredentialStorageCallback, 0}; + + d->m_connection.adoptCF(CFURLConnectionCreate(0, request.get(), reinterpret_cast<CFURLConnectionClient*>(&client))); CFURLConnectionScheduleWithCurrentMessageQueue(d->m_connection.get()); CFURLConnectionScheduleDownloadWithRunLoop(d->m_connection.get(), loaderRunLoop(), kCFRunLoopDefaultMode); @@ -519,12 +462,22 @@ bool ResourceHandle::loadsBlocked() return false; } -bool ResourceHandle::willLoadFromCache(ResourceRequest&) +bool ResourceHandle::willLoadFromCache(ResourceRequest& request) { - // Not having this function means that we'll ask the user about re-posting a form - // even when we go back to a page that's still in the cache. - notImplemented(); - return false; + request.setCachePolicy(ReturnCacheDataDontLoad); + + CFURLResponseRef cfResponse = 0; + CFErrorRef cfError = 0; + RetainPtr<CFURLRequestRef> cfRequest(AdoptCF, makeFinalRequest(request, true)); + RetainPtr<CFDataRef> data(AdoptCF, CFURLConnectionSendSynchronousRequest(cfRequest.get(), &cfResponse, &cfError, request.timeoutInterval())); + bool cached = cfResponse && !cfError; + + if (cfError) + CFRelease(cfError); + if (cfResponse) + CFRelease(cfResponse); + + return cached; } } // namespace WebCore diff --git a/WebCore/platform/network/cf/ResourceRequestCFNet.h b/WebCore/platform/network/cf/ResourceRequestCFNet.h index e9ebe76..d26072d 100644 --- a/WebCore/platform/network/cf/ResourceRequestCFNet.h +++ b/WebCore/platform/network/cf/ResourceRequestCFNet.h @@ -30,7 +30,7 @@ typedef const struct _CFURLRequest* CFURLRequestRef; namespace WebCore { - class ResourceRequest; + struct ResourceRequest; void getResourceRequest(ResourceRequest&, CFURLRequestRef); CFURLRequestRef cfURLRequest(const ResourceRequest&); diff --git a/WebCore/platform/network/cf/ResourceResponse.h b/WebCore/platform/network/cf/ResourceResponse.h index e14c79e..04cc82c 100644 --- a/WebCore/platform/network/cf/ResourceResponse.h +++ b/WebCore/platform/network/cf/ResourceResponse.h @@ -52,6 +52,18 @@ public: { } + unsigned memoryUsage() const + { + // FIXME: Find some programmatic lighweight way to calculate ResourceResponse and associated classes. + // This is a rough estimate of resource overhead based on stats collected from the stress test. + return 3072; + /* 1280 * 2 + // average size of ResourceResponse. Doubled to account for the WebCore copy and the CF copy. + // Mostly due to the size of the hash maps, the Header Map strings and the URL. + 256 * 2 // Overhead from ResourceRequest, doubled to account for WebCore copy and CF copy. + // Mostly due to the URL and Header Map. + */ + } + CFURLResponseRef cfURLResponse() const; private: |