Changeset 146667 in webkit
- Timestamp:
- Mar 22, 2013, 3:44:07 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r146664 r146667 1 2013-03-22 Alexey Proskuryakov <ap@apple.com> 2 3 Split ResourceHandleMac into multiple files 4 https://bugs.webkit.org/show_bug.cgi?id=113100 5 6 Reviewed by Geoff Garen. 7 8 It's grown too big to navigate, and I'm going to make WebCoreResourceHandleAsDelegate 9 substantially more complicated yet. 10 11 1. Mechanically moved WebCoreResourceHandleAsDelegate into separate files. 12 2. Refactored WebCoreSynchronousLoaderClient to be cross-platform, and moved it into 13 separate files. 14 15 * WebCore.vcproj/WebCore.vcproj: 16 * WebCore.vcxproj/WebCore.vcxproj: 17 * WebCore.vcxproj/WebCore.vcxproj.filters: 18 * WebCore.xcodeproj/project.pbxproj: 19 * platform/network/SynchronousLoaderClient.cpp: Added. 20 * platform/network/SynchronousLoaderClient.h: Added. 21 * platform/network/cf/ResourceHandleCFNet.cpp: 22 * platform/network/mac/SynchronousLoaderClient.mm: Added. 23 * platform/network/mac/WebCoreResourceHandleAsDelegate.h: Added. 24 * platform/network/mac/WebCoreResourceHandleAsDelegate.mm: Added. 25 1 26 2013-03-21 Geoffrey Garen <ggaren@apple.com> 2 27 -
trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj
r146585 r146667 33286 33286 > 33287 33287 </File> 33288 <File 33289 RelativePath="..\platform\network\SynchronousLoaderClient.cpp" 33290 > 33291 </File> 33292 <File 33293 RelativePath="..\platform\network\SynchronousLoaderClient.h" 33294 > 33295 </File> 33288 33296 <Filter 33289 33297 Name="cf" -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
r146585 r146667 4651 4651 <ClCompile Include="..\platform\network\SocketStreamErrorBase.cpp" /> 4652 4652 <ClCompile Include="..\platform\network\SocketStreamHandleBase.cpp" /> 4653 <ClCompile Include="..\platform\network\SynchronousLoaderClient.cpp" /> 4653 4654 <ClCompile Include="..\platform\network\cf\AuthenticationCF.cpp"> 4654 4655 <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild> … … 11934 11935 <ClInclude Include="..\platform\network\SocketStreamHandleBase.h" /> 11935 11936 <ClInclude Include="..\platform\network\SocketStreamHandleClient.h" /> 11937 <ClInclude Include="..\platform\network\SynchronousLoaderClient.h" /> 11936 11938 <CustomBuildStep Include="..\platform\network\cf\AuthenticationCF.h" /> 11937 11939 <CustomBuildStep Include="..\platform\network\cf\AuthenticationChallenge.h" /> -
trunk/Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
r146585 r146667 3322 3322 <Filter>platform\network</Filter> 3323 3323 </ClCompile> 3324 <ClCompile Include="..\platform\network\SynchronousLoaderClient.cpp"> 3325 <Filter>platform\network</Filter> 3326 </ClCompile> 3324 3327 <ClCompile Include="..\platform\network\cf\AuthenticationCF.cpp"> 3325 3328 <Filter>platform\network\cf</Filter> … … 10151 10154 </ClInclude> 10152 10155 <ClInclude Include="..\platform\network\SocketStreamHandleClient.h"> 10156 <Filter>platform\network</Filter> 10157 </ClInclude> 10158 <ClInclude Include="..\platform\network\SynchronousLoaderClient.h"> 10153 10159 <Filter>platform\network</Filter> 10154 10160 </ClInclude> -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r146585 r146667 6235 6235 E17B492116A9B8FF001C8839 /* JSTransitionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E17B491F16A9B8FF001C8839 /* JSTransitionEvent.h */; }; 6236 6236 E17B492216A9B8FF001C8839 /* JSTransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E17B492016A9B8FF001C8839 /* JSTransitionEvent.cpp */; }; 6237 E180810E16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = E180810C16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm */; }; 6238 E180810F16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E180810D16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.h */; }; 6239 E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E180811016FCF42E00B80D07 /* SynchronousLoaderClient.cpp */; }; 6240 E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */ = {isa = PBXBuildFile; fileRef = E180811416FCF9CB00B80D07 /* SynchronousLoaderClient.mm */; }; 6241 E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E180811516FCF9CB00B80D07 /* SynchronousLoaderClient.h */; }; 6237 6242 E182568F0EF2B02D00933242 /* JSWorkerContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E182568D0EF2B02D00933242 /* JSWorkerContext.cpp */; }; 6238 6243 E18256900EF2B02D00933242 /* JSWorkerContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E182568E0EF2B02D00933242 /* JSWorkerContext.h */; }; … … 13948 13953 E17B491F16A9B8FF001C8839 /* JSTransitionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTransitionEvent.h; sourceTree = "<group>"; }; 13949 13954 E17B492016A9B8FF001C8839 /* JSTransitionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTransitionEvent.cpp; sourceTree = "<group>"; }; 13955 E180810C16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreResourceHandleAsDelegate.mm; sourceTree = "<group>"; }; 13956 E180810D16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreResourceHandleAsDelegate.h; sourceTree = "<group>"; }; 13957 E180811016FCF42E00B80D07 /* SynchronousLoaderClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SynchronousLoaderClient.cpp; sourceTree = "<group>"; }; 13958 E180811416FCF9CB00B80D07 /* SynchronousLoaderClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SynchronousLoaderClient.mm; sourceTree = "<group>"; }; 13959 E180811516FCF9CB00B80D07 /* SynchronousLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SynchronousLoaderClient.h; sourceTree = "<group>"; }; 13950 13960 E182568D0EF2B02D00933242 /* JSWorkerContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWorkerContext.cpp; sourceTree = "<group>"; }; 13951 13961 E182568E0EF2B02D00933242 /* JSWorkerContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWorkerContext.h; sourceTree = "<group>"; }; … … 16317 16327 510D4A31103165EE0049EA54 /* SocketStreamHandleBase.h */, 16318 16328 510D4A32103165EE0049EA54 /* SocketStreamHandleClient.h */, 16329 E180811016FCF42E00B80D07 /* SynchronousLoaderClient.cpp */, 16330 E180811516FCF9CB00B80D07 /* SynchronousLoaderClient.h */, 16319 16331 ); 16320 16332 path = network; … … 16338 16350 1FAFBF1615A5FA5200083A20 /* UTIUtilities.h */, 16339 16351 1FAFBF1715A5FA5200083A20 /* UTIUtilities.mm */, 16352 E180810C16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm */, 16353 E180810D16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.h */, 16354 E180811416FCF9CB00B80D07 /* SynchronousLoaderClient.mm */, 16340 16355 37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */, 16341 16356 37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */, … … 26768 26783 2D5BC42716F882EE007048D0 /* SecurityPolicyViolationEvent.h in Headers */, 26769 26784 50E18CDA16F9285800C65486 /* StyleCustomFilterProgramCache.h in Headers */, 26785 E180810F16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.h in Headers */, 26786 E180811716FCF9CB00B80D07 /* SynchronousLoaderClient.h in Headers */, 26770 26787 ); 26771 26788 runOnlyForDeploymentPostprocessing = 0; … … 29976 29993 50E18CD816F9285800C65486 /* StyleCustomFilterProgram.cpp in Sources */, 29977 29994 50E18CD916F9285800C65486 /* StyleCustomFilterProgramCache.cpp in Sources */, 29995 E180810E16FCECDF00B80D07 /* WebCoreResourceHandleAsDelegate.mm in Sources */, 29996 E180811216FCF42F00B80D07 /* SynchronousLoaderClient.cpp in Sources */, 29997 E180811616FCF9CB00B80D07 /* SynchronousLoaderClient.mm in Sources */, 29978 29998 ); 29979 29999 runOnlyForDeploymentPostprocessing = 0; -
trunk/Source/WebCore/platform/network/cf/ResourceHandleCFNet.cpp
r144503 r146667 43 43 #include "ResourceResponse.h" 44 44 #include "SharedBuffer.h" 45 #include "SynchronousLoaderClient.h" 45 46 #include <CFNetwork/CFNetwork.h> 46 47 #include <sys/stat.h> … … 77 78 78 79 #if USE(CFNETWORK) 79 80 class WebCoreSynchronousLoaderClient : public ResourceHandleClient {81 public:82 static PassOwnPtr<WebCoreSynchronousLoaderClient> create(ResourceResponse& response, ResourceError& error)83 {84 return adoptPtr(new WebCoreSynchronousLoaderClient(response, error));85 }86 87 void setAllowStoredCredentials(bool allow) { m_allowStoredCredentials = allow; }88 bool isDone() { return m_isDone; }89 90 CFMutableDataRef data() { return m_data.get(); }91 92 private:93 WebCoreSynchronousLoaderClient(ResourceResponse& response, ResourceError& error)94 : m_allowStoredCredentials(false)95 , m_response(response)96 , m_error(error)97 , m_isDone(false)98 {99 }100 101 virtual void willSendRequest(ResourceHandle*, ResourceRequest&, const ResourceResponse& /*redirectResponse*/);102 virtual bool shouldUseCredentialStorage(ResourceHandle*);103 virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&);104 virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);105 virtual void didReceiveData(ResourceHandle*, const char*, int, int /*encodedDataLength*/);106 virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/);107 virtual void didFail(ResourceHandle*, const ResourceError&);108 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)109 virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace&);110 #endif111 112 bool m_allowStoredCredentials;113 ResourceResponse& m_response;114 RetainPtr<CFMutableDataRef> m_data;115 ResourceError& m_error;116 bool m_isDone;117 };118 80 119 81 static HashSet<String>& allowsAnyHTTPSCertificateHosts() … … 707 669 } 708 670 709 void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& vector)671 void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentials storedCredentials, ResourceError& error, ResourceResponse& response, Vector<char>& data) 710 672 { 711 673 LOG(Network, "ResourceHandle::platformLoadResourceSynchronously:%s allowStoredCredentials:%u", request.url().string().utf8().data(), storedCredentials); … … 716 678 ASSERT(error.isNull()); 717 679 718 OwnPtr< WebCoreSynchronousLoaderClient> client = WebCoreSynchronousLoaderClient::create(response, error);680 OwnPtr<SynchronousLoaderClient> client = SynchronousLoaderClient::create(); 719 681 client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); 720 682 … … 737 699 CFRunLoopRunInMode(synchronousLoadRunLoopMode(), UINT_MAX, true); 738 700 701 error = client->error(); 702 739 703 CFURLConnectionCancel(handle->connection()); 740 704 741 705 if (error.isNull() && response.mimeType().isNull()) 742 706 setDefaultMIMEType(response.cfURLResponse()); 743 744 RetainPtr<CFDataRef> data = client->data();745 707 746 if (!error.isNull()) { 708 if (error.isNull()) 709 response = client->response(); 710 else { 747 711 response = ResourceResponse(request.url(), String(), 0, String(), String()); 748 749 CFErrorRef cfError = error; 750 CFStringRef domain = CFErrorGetDomain(cfError); 751 // FIXME: Return the actual response for failed authentication. 752 if (domain == kCFErrorDomainCFNetwork) 753 response.setHTTPStatusCode(CFErrorGetCode(cfError)); 712 // FIXME: ResourceHandleMac also handles authentication errors by setting code to 401. CFNet version should probably do the same. 713 if (error.domain() == String(kCFErrorDomainCFNetwork)) 714 response.setHTTPStatusCode(error.errorCode()); 754 715 else 755 716 response.setHTTPStatusCode(404); 756 717 } 757 718 758 if (data) { 759 ASSERT(vector.isEmpty()); 760 vector.append(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get())); 761 } 719 data.swap(client->mutableData()); 762 720 } 763 721 … … 809 767 810 768 CFURLConnectionUnscheduleFromRunLoop(d->m_connection.get(), runLoop, pair->mode()); 811 }812 #endif813 814 void WebCoreSynchronousLoaderClient::willSendRequest(ResourceHandle* handle, ResourceRequest& request, const ResourceResponse& /*redirectResponse*/)815 {816 // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.817 if (!protocolHostAndPortAreEqual(handle->firstRequest().url(), request.url())) {818 ASSERT(!m_error.cfError());819 RetainPtr<CFErrorRef> cfError(AdoptCF, CFErrorCreate(kCFAllocatorDefault, kCFErrorDomainCFNetwork, kCFURLErrorBadServerResponse, 0));820 m_error = cfError.get();821 m_isDone = true;822 CFURLRequestRef nullRequest = 0;823 request = nullRequest;824 return;825 }826 }827 void WebCoreSynchronousLoaderClient::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)828 {829 m_response = response;830 }831 832 void WebCoreSynchronousLoaderClient::didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/)833 {834 if (!m_data)835 m_data.adoptCF(CFDataCreateMutable(kCFAllocatorDefault, 0));836 CFDataAppendBytes(m_data.get(), reinterpret_cast<const UInt8*>(data), length);837 }838 839 void WebCoreSynchronousLoaderClient::didFinishLoading(ResourceHandle*, double)840 {841 m_isDone = true;842 }843 844 void WebCoreSynchronousLoaderClient::didFail(ResourceHandle*, const ResourceError& error)845 {846 m_error = error;847 m_isDone = true;848 }849 850 void WebCoreSynchronousLoaderClient::didReceiveAuthenticationChallenge(ResourceHandle* handle, const AuthenticationChallenge& challenge)851 {852 // FIXME: The user should be asked for credentials, as in async case.853 CFURLConnectionUseCredential(handle->connection(), 0, challenge.cfURLAuthChallengeRef());854 }855 856 bool WebCoreSynchronousLoaderClient::shouldUseCredentialStorage(ResourceHandle*)857 {858 // FIXME: We should ask FrameLoaderClient whether using credential storage is globally forbidden.859 return m_allowStoredCredentials;860 }861 862 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)863 bool WebCoreSynchronousLoaderClient::canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace&)864 {865 // FIXME: We should ask FrameLoaderClient. <http://webkit.org/b/65196>866 return true;867 769 } 868 770 #endif -
trunk/Source/WebCore/platform/network/mac/ResourceHandleMac.mm
r146536 r146667 48 48 #import "SharedBuffer.h" 49 49 #import "SubresourceLoader.h" 50 #import "WebCoreResourceHandleAsDelegate.h" 51 #import "SynchronousLoaderClient.h" 50 52 #import "WebCoreSystemInterface.h" 51 53 #import "WebCoreURLResponse.h" … … 57 59 using namespace WebCore; 58 60 59 @interface WebCoreResourceHandleAsDelegate : NSObject <NSURLConnectionDelegate> {60 ResourceHandle* m_handle;61 }62 - (id)initWithHandle:(ResourceHandle*)handle;63 - (void)detachHandle;64 @end65 66 61 // WebCoreNSURLConnectionDelegateProxy exists so that we can cast m_proxy to it in order 67 62 // to disambiguate the argument type in the -setDelegate: call. This avoids a spurious … … 74 69 -(id)_initWithRequest:(NSURLRequest *)request delegate:(id)delegate usesCache:(BOOL)usesCacheFlag maxContentLength:(long long)maxContentLength startImmediately:(BOOL)startImmediately connectionProperties:(NSDictionary *)connectionProperties; 75 70 @end 76 77 @interface NSURLRequest (Details)78 - (id)_propertyForKey:(NSString *)key;79 @end80 81 class WebCoreSynchronousLoaderClient : public ResourceHandleClient {82 public:83 static PassOwnPtr<WebCoreSynchronousLoaderClient> create()84 {85 return adoptPtr(new WebCoreSynchronousLoaderClient);86 }87 88 virtual ~WebCoreSynchronousLoaderClient();89 90 void setAllowStoredCredentials(bool allow) { m_allowStoredCredentials = allow; }91 NSURLResponse *response() { return m_response; }92 NSMutableData *data() { return m_data; }93 NSError *error() { return m_error; }94 bool isDone() { return m_isDone; }95 96 private:97 WebCoreSynchronousLoaderClient()98 : m_allowStoredCredentials(false)99 , m_response(0)100 , m_data(0)101 , m_error(0)102 , m_isDone(false)103 {104 }105 106 virtual void willSendRequest(ResourceHandle*, ResourceRequest&, const ResourceResponse& /*redirectResponse*/);107 virtual bool shouldUseCredentialStorage(ResourceHandle*);108 virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&);109 virtual void didReceiveResponse(ResourceHandle*, const ResourceResponse&);110 virtual void didReceiveData(ResourceHandle*, const char*, int, int /*encodedDataLength*/);111 virtual void didFinishLoading(ResourceHandle*, double /*finishTime*/);112 virtual void didFail(ResourceHandle*, const ResourceError&);113 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)114 virtual bool canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace&);115 #endif116 117 bool m_allowStoredCredentials;118 NSURLResponse *m_response;119 NSMutableData *m_data;120 NSError *m_error;121 bool m_isDone;122 };123 71 124 72 namespace WebCore { … … 356 304 LOG(Network, "ResourceHandle::platformLoadResourceSynchronously:%@ allowStoredCredentials:%u", request.nsURLRequest(DoNotUpdateHTTPBody), storedCredentials); 357 305 358 NSError *nsError = nil;359 NSURLResponse *nsURLResponse = nil;360 NSData *result = nil;361 362 306 ASSERT(!request.isEmpty()); 363 307 364 OwnPtr< WebCoreSynchronousLoaderClient> client = WebCoreSynchronousLoaderClient::create();308 OwnPtr<SynchronousLoaderClient> client = SynchronousLoaderClient::create(); 365 309 client->setAllowStoredCredentials(storedCredentials == AllowStoredCredentials); 366 310 … … 385 329 [[NSRunLoop currentRunLoop] runMode:(NSString *)synchronousLoadRunLoopMode() beforeDate:[NSDate distantFuture]]; 386 330 387 result = client->data(); 388 nsURLResponse = client->response(); 389 nsError = client->error(); 331 error = client->error(); 390 332 391 333 [handle->connection() cancel]; 392 334 393 394 if (!nsError) 395 response = nsURLResponse; 335 if (error.isNull()) 336 response = client->response(); 396 337 else { 397 338 response = ResourceResponse(request.url(), String(), 0, String(), String()); 398 if ( [nsError domain] == NSURLErrorDomain)399 switch ( [nsError code]) {400 401 402 403 404 405 response.setHTTPStatusCode([nsError code]);339 if (error.domain() == String(NSURLErrorDomain)) 340 switch (error.errorCode()) { 341 case NSURLErrorUserCancelledAuthentication: 342 // FIXME: we should really return the actual HTTP response, but sendSynchronousRequest doesn't provide us with one. 343 response.setHTTPStatusCode(401); 344 break; 345 default: 346 response.setHTTPStatusCode(error.errorCode()); 406 347 } 407 348 else 408 349 response.setHTTPStatusCode(404); 409 350 } 410 411 data.resize([result length]); 412 memcpy(data.data(), [result bytes], [result length]); 413 414 error = nsError; 351 352 data.swap(client->mutableData()); 415 353 } 416 354 … … 618 556 } // namespace WebCore 619 557 620 @implementation WebCoreResourceHandleAsDelegate621 622 - (id)initWithHandle:(ResourceHandle*)handle623 {624 self = [self init];625 if (!self)626 return nil;627 m_handle = handle;628 return self;629 }630 631 - (void)detachHandle632 {633 m_handle = 0;634 }635 636 - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse637 {638 UNUSED_PARAM(connection);639 640 if (!m_handle || !m_handle->client())641 return nil;642 643 // See <rdar://problem/5380697>. This is a workaround for a behavior change in CFNetwork where willSendRequest gets called more often.644 if (!redirectResponse)645 return newRequest;646 647 #if !LOG_DISABLED648 if ([redirectResponse isKindOfClass:[NSHTTPURLResponse class]])649 LOG(Network, "Handle %p delegate connection:%p willSendRequest:%@ redirectResponse:%d, Location:<%@>", m_handle, connection, [newRequest description], static_cast<int>([(id)redirectResponse statusCode]), [[(id)redirectResponse allHeaderFields] objectForKey:@"Location"]);650 else651 LOG(Network, "Handle %p delegate connection:%p willSendRequest:%@ redirectResponse:non-HTTP", m_handle, connection, [newRequest description]);652 #endif653 654 ResourceRequest request = newRequest;655 656 m_handle->willSendRequest(request, redirectResponse);657 658 return request.nsURLRequest(UpdateHTTPBody);659 }660 661 - (BOOL)connectionShouldUseCredentialStorage:(NSURLConnection *)connection662 {663 UNUSED_PARAM(connection);664 665 LOG(Network, "Handle %p delegate connectionShouldUseCredentialStorage:%p", m_handle, connection);666 667 if (!m_handle)668 return NO;669 670 return m_handle->shouldUseCredentialStorage();671 }672 673 - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge674 {675 UNUSED_PARAM(connection);676 677 LOG(Network, "Handle %p delegate connection:%p didReceiveAuthenticationChallenge:%p", m_handle, connection, challenge);678 679 if (!m_handle) {680 [[challenge sender] cancelAuthenticationChallenge:challenge];681 return;682 }683 m_handle->didReceiveAuthenticationChallenge(core(challenge));684 }685 686 - (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge687 {688 // FIXME: We probably don't need to implement this (see <rdar://problem/8960124>).689 690 UNUSED_PARAM(connection);691 692 LOG(Network, "Handle %p delegate connection:%p didCancelAuthenticationChallenge:%p", m_handle, connection, challenge);693 694 if (!m_handle)695 return;696 m_handle->didCancelAuthenticationChallenge(core(challenge));697 }698 699 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)700 - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace701 {702 UNUSED_PARAM(connection);703 704 LOG(Network, "Handle %p delegate connection:%p canAuthenticateAgainstProtectionSpace:%@://%@:%u realm:%@ method:%@ %@%@", m_handle, connection, [protectionSpace protocol], [protectionSpace host], [protectionSpace port], [protectionSpace realm], [protectionSpace authenticationMethod], [protectionSpace isProxy] ? @"proxy:" : @"", [protectionSpace isProxy] ? [protectionSpace proxyType] : @"");705 706 if (!m_handle)707 return NO;708 709 return m_handle->canAuthenticateAgainstProtectionSpace(core(protectionSpace));710 }711 #endif712 713 - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)r714 {715 UNUSED_PARAM(connection);716 717 LOG(Network, "Handle %p delegate connection:%p didReceiveResponse:%p (HTTP status %d, reported MIMEType '%s')", m_handle, connection, r, [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0, [[r MIMEType] UTF8String]);718 719 if (!m_handle || !m_handle->client())720 return;721 722 // Avoid MIME type sniffing if the response comes back as 304 Not Modified.723 int statusCode = [r respondsToSelector:@selector(statusCode)] ? [(id)r statusCode] : 0;724 if (statusCode != 304)725 adjustMIMETypeIfNecessary([r _CFURLResponse]);726 727 if ([m_handle->firstRequest().nsURLRequest(DoNotUpdateHTTPBody) _propertyForKey:@"ForceHTMLMIMEType"])728 [r _setMIMEType:@"text/html"];729 730 m_handle->client()->didReceiveResponse(m_handle, r);731 }732 733 #if USE(NETWORK_CFDATA_ARRAY_CALLBACK)734 - (void)connection:(NSURLConnection *)connection didReceiveDataArray:(NSArray *)dataArray735 {736 UNUSED_PARAM(connection);737 LOG(Network, "Handle %p delegate connection:%p didReceiveDataArray:%p arraySize:%d", m_handle, connection, dataArray, [dataArray count]);738 739 if (!dataArray)740 return;741 742 if (!m_handle || !m_handle->client())743 return;744 745 m_handle->handleDataArray(reinterpret_cast<CFArrayRef>(dataArray));746 // The call to didReceiveData above can cancel a load, and if so, the delegate (self) could have been deallocated by this point.747 }748 #endif749 750 - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived751 {752 UNUSED_PARAM(connection);753 UNUSED_PARAM(lengthReceived);754 755 LOG(Network, "Handle %p delegate connection:%p didReceiveData:%p lengthReceived:%lld", m_handle, connection, data, lengthReceived);756 757 if (!m_handle || !m_handle->client())758 return;759 // FIXME: If we get more than 2B bytes in a single chunk, this code won't do the right thing.760 // However, with today's computers and networking speeds, this won't happen in practice.761 // Could be an issue with a giant local file.762 763 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=19793764 // -1 means we do not provide any data about transfer size to inspector so it would use765 // Content-Length headers or content size to show transfer size.766 m_handle->client()->didReceiveBuffer(m_handle, SharedBuffer::wrapNSData(data), -1);767 }768 769 - (void)connection:(NSURLConnection *)connection willStopBufferingData:(NSData *)data770 {771 UNUSED_PARAM(connection);772 773 LOG(Network, "Handle %p delegate connection:%p willStopBufferingData:%p", m_handle, connection, data);774 775 if (!m_handle || !m_handle->client())776 return;777 // FIXME: If we get a resource with more than 2B bytes, this code won't do the right thing.778 // However, with today's computers and networking speeds, this won't happen in practice.779 // Could be an issue with a giant local file.780 m_handle->client()->willStopBufferingData(m_handle, (const char*)[data bytes], static_cast<int>([data length]));781 }782 783 - (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite784 {785 UNUSED_PARAM(connection);786 UNUSED_PARAM(bytesWritten);787 788 LOG(Network, "Handle %p delegate connection:%p didSendBodyData:%d totalBytesWritten:%d totalBytesExpectedToWrite:%d", m_handle, connection, bytesWritten, totalBytesWritten, totalBytesExpectedToWrite);789 790 if (!m_handle || !m_handle->client())791 return;792 m_handle->client()->didSendData(m_handle, totalBytesWritten, totalBytesExpectedToWrite);793 }794 795 - (void)connectionDidFinishLoading:(NSURLConnection *)connection796 {797 UNUSED_PARAM(connection);798 799 LOG(Network, "Handle %p delegate connectionDidFinishLoading:%p", m_handle, connection);800 801 if (!m_handle || !m_handle->client())802 return;803 804 m_handle->client()->didFinishLoading(m_handle, 0);805 }806 807 - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error808 {809 UNUSED_PARAM(connection);810 811 LOG(Network, "Handle %p delegate connection:%p didFailWithError:%@", m_handle, connection, error);812 813 if (!m_handle || !m_handle->client())814 return;815 816 m_handle->client()->didFail(m_handle, error);817 }818 819 820 - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse821 {822 LOG(Network, "Handle %p delegate connection:%p willCacheResponse:%p", m_handle, connection, cachedResponse);823 824 UNUSED_PARAM(connection);825 826 if (!m_handle || !m_handle->client())827 return nil;828 829 // Workaround for <rdar://problem/6300990> Caching does not respect Vary HTTP header.830 // FIXME: WebCore cache has issues with Vary, too (bug 58797, bug 71509).831 if ([[cachedResponse response] isKindOfClass:[NSHTTPURLResponse class]]832 && [[(NSHTTPURLResponse *)[cachedResponse response] allHeaderFields] objectForKey:@"Vary"])833 return nil;834 835 NSCachedURLResponse *newResponse = m_handle->client()->willCacheResponse(m_handle, cachedResponse);836 if (newResponse != cachedResponse)837 return newResponse;838 839 return newResponse;840 }841 842 @end843 844 845 WebCoreSynchronousLoaderClient::~WebCoreSynchronousLoaderClient()846 {847 [m_response release];848 [m_data release];849 [m_error release];850 }851 852 void WebCoreSynchronousLoaderClient::willSendRequest(ResourceHandle* handle, ResourceRequest& request, const ResourceResponse& /*redirectResponse*/)853 {854 // FIXME: This needs to be fixed to follow the redirect correctly even for cross-domain requests.855 if (!protocolHostAndPortAreEqual(handle->firstRequest().url(), request.url())) {856 ASSERT(!m_error);857 m_error = [[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadServerResponse userInfo:nil];858 m_isDone = true;859 request = 0;860 return;861 }862 }863 864 bool WebCoreSynchronousLoaderClient::shouldUseCredentialStorage(ResourceHandle*)865 {866 // FIXME: We should ask FrameLoaderClient whether using credential storage is globally forbidden.867 return m_allowStoredCredentials;868 }869 870 #if USE(PROTECTION_SPACE_AUTH_CALLBACK)871 bool WebCoreSynchronousLoaderClient::canAuthenticateAgainstProtectionSpace(ResourceHandle*, const ProtectionSpace&)872 {873 // FIXME: We should ask FrameLoaderClient. <http://webkit.org/b/65196>874 return true;875 }876 #endif877 878 void WebCoreSynchronousLoaderClient::didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge& challenge)879 {880 // FIXME: The user should be asked for credentials, as in async case.881 [challenge.sender() continueWithoutCredentialForAuthenticationChallenge:challenge.nsURLAuthenticationChallenge()];882 }883 884 void WebCoreSynchronousLoaderClient::didReceiveResponse(ResourceHandle*, const ResourceResponse& response)885 {886 [m_response release];887 m_response = [response.nsURLResponse() copy];888 }889 890 void WebCoreSynchronousLoaderClient::didReceiveData(ResourceHandle*, const char* data, int length, int /*encodedDataLength*/)891 {892 if (!m_data)893 m_data = [[NSMutableData alloc] init];894 [m_data appendBytes:data length:length];895 }896 897 void WebCoreSynchronousLoaderClient::didFinishLoading(ResourceHandle*, double)898 {899 m_isDone = true;900 }901 902 void WebCoreSynchronousLoaderClient::didFail(ResourceHandle*, const ResourceError& error)903 {904 ASSERT(!m_error);905 906 m_error = [error copy];907 m_isDone = true;908 }909 910 911 558 #endif // !USE(CFNETWORK)
Note:
See TracChangeset
for help on using the changeset viewer.