+2006-10-20 Darin Adler <darin@apple.com>
+
+ Reviewed by Adele.
+
+ - convert WebLoader and its 3 subclasses to C++
+
+ Renamed WebLoader to WebCore::WebResourceLoader (should be ResourceLoader, but
+ there's currently another class with that name).
+ Renamed WebMainResourceLoader to WebCore::MainResourceLoader.
+ Renamed WebSubresourceLoader to WebCore::SubresourceLoader.
+ Renamed WebNetscapePlugInStreamLoader to WebCore::NetscapePlugInStreamLoader.
+
+ Converted the classes to C++ and added Objective-C delegates to forward from
+ API that still requires Objective-C.
+
+ Did not yet rename the source files.
+
+ * WebCore.exp: Removed WebLoader, WebNetscapePlugInStreamLoader, and WebSubresourceLoader
+ classes. Added 5 functions from the WebResourceLoader and NetscapePlugInStreamLoader
+ classes.
+
+ * WebCore.xcodeproj/project.pbxproj: Made RetainPtr.h a private header instead of project.
+
+ * platform/cf/RetainPtr.h: Put into the WebCore namespace rather than the WTF namespace.
+
+ * loader/mac/WebLoader.h:
+ * loader/mac/WebLoader.mm:
+ * loader/mac/WebMainResourceLoader.h:
+ * loader/mac/WebMainResourceLoader.mm:
+ * loader/mac/WebNetscapePlugInStreamLoader.h:
+ * loader/mac/WebNetscapePlugInStreamLoader.mm:
+ * loader/mac/WebSubresourceLoader.h:
+ * loader/mac/WebSubresourceLoader.mm:
+ Translate to C++.
+
+ * bridge/mac/WebCoreFrameBridge.mm:
+ (-[WebCoreFrameBridge startLoadingResource:withMethod:URL:customHeaders:]):
+ (-[WebCoreFrameBridge startLoadingResource:withMethod:URL:customHeaders:postData:]):
+ * loader/mac/WebFrameLoader.h:
+ * loader/mac/WebFrameLoader.mm:
+ (isCaseInsensitiveEqual):
+ (isBackForwardLoadType):
+ (-[WebFrameLoader dealloc]):
+ (-[WebFrameLoader addPlugInStreamLoader:]):
+ (-[WebFrameLoader removePlugInStreamLoader:]):
+ (-[WebFrameLoader setDefersCallbacks:]):
+ (-[WebFrameLoader stopLoadingPlugIns]):
+ (-[WebFrameLoader isLoadingMainResource]):
+ (-[WebFrameLoader isLoadingSubresources]):
+ (-[WebFrameLoader isLoadingPlugIns]):
+ (-[WebFrameLoader stopLoadingSubresources]):
+ (-[WebFrameLoader addSubresourceLoader:]):
+ (-[WebFrameLoader removeSubresourceLoader:]):
+ (-[WebFrameLoader mainResourceData]):
+ (-[WebFrameLoader releaseMainResourceLoader]):
+ (-[WebFrameLoader cancelMainResourceLoad]):
+ (-[WebFrameLoader startLoadingMainResourceWithRequest:identifier:]):
+ (-[WebFrameLoader stopLoadingWithError:]):
+ (-[WebFrameLoader willUseArchiveForRequest:originalURL:loader:]):
+ (-[WebFrameLoader archiveLoadPendingForLoader:]):
+ (-[WebFrameLoader cancelPendingArchiveLoadForLoader:]):
+ * loader/mac/WebFrameLoaderClient.h:
+ Call the new C++ API.
+
2006-10-20 Nikolas Zimmermann <zimmermann@kde.org>
Reviewed and landed by Anders.
.objc_class_name_WebDashboardRegion
.objc_class_name_WebDocumentLoader
.objc_class_name_WebFrameLoader
-.objc_class_name_WebLoader
-.objc_class_name_WebNetscapePlugInStreamLoader
.objc_class_name_WebPolicyDecider
.objc_class_name_WebScriptObject
.objc_class_name_WebScriptObjectPrivate
-.objc_class_name_WebSubresourceLoader
.objc_class_name_WebUndefined
_WebCoreDrawTextAtPoint
_WebCoreFindFont
_WebCoreTextFloatWidth
__Z21isBackForwardLoadType13FrameLoadType
__ZN7WebCore10StringImplD1Ev
+__ZN7WebCore17WebResourceLoader14cancelledErrorEv
+__ZN7WebCore17WebResourceLoader20inConnectionCallbackEv
+__ZN7WebCore26NetscapePlugInStreamLoader6createEP14WebFrameLoaderP11objc_object
+__ZNK7WebCore17WebResourceLoader11frameLoaderEv
+__ZNK7WebCore26NetscapePlugInStreamLoader6isDoneEv
_canonicalURL
_stringIsFileURL
_urlByRemovingComponent
65A21468097A329100B9050A /* Page.h in Headers */ = {isa = PBXBuildFile; fileRef = 65A21467097A329100B9050A /* Page.h */; };
65A21484097A3F5300B9050A /* FrameTree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65A21482097A3F5300B9050A /* FrameTree.cpp */; };
65A21485097A3F5300B9050A /* FrameTree.h in Headers */ = {isa = PBXBuildFile; fileRef = 65A21483097A3F5300B9050A /* FrameTree.h */; };
- 65BAAABE0ADCA015005BB5A4 /* RetainPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BAAABD0ADCA015005BB5A4 /* RetainPtr.h */; };
+ 65BAAABE0ADCA015005BB5A4 /* RetainPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BAAABD0ADCA015005BB5A4 /* RetainPtr.h */; settings = {ATTRIBUTES = (Private, ); }; };
65BF022E0974816300C43196 /* Frame.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 65BF02290974816300C43196 /* Frame.cpp */; };
65BF022F0974816300C43196 /* Frame.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BF022A0974816300C43196 /* Frame.h */; settings = {ATTRIBUTES = (Private, ); }; };
65BF02300974816300C43196 /* FramePrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BF022B0974816300C43196 /* FramePrivate.h */; };
mainGroup = 0867D691FE84028FC02AAC07 /* WebKit */;
productRefGroup = 034768DFFF38A50411DB9C8B /* Products */;
projectDirPath = "";
- projectRoot = "";
targets = (
93F198A508245E59001E9ABC /* WebCore */,
DD041FBE09D9DDBE0010AF2A /* Derived Sources */,
BOOL hideReferrer;
[self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
- return [WebSubresourceLoader startLoadingResource:resourceLoader
- withMethod:method
- URL:URL
- customHeaders:customHeaders
- referrer:(hideReferrer ? nil : [self referrer])
- forFrameLoader:[self frameLoader]];
+ return SubresourceLoader::create([self frameLoader], resourceLoader,
+ method, URL, customHeaders, hideReferrer ? nil : [self referrer]);
}
- (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data
[request release];
}
-- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)postData
+- (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL
+ customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)postData
{
// If we are no longer attached to a Page, this must be an attempted load from an
// onUnload handler, so let's just block it.
BOOL hideReferrer;
[self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
- return [WebSubresourceLoader startLoadingResource:resourceLoader
- withMethod:method
- URL:URL
- customHeaders:customHeaders
- postData:postData
- referrer:(hideReferrer ? nil : [self referrer])
- forFrameLoader:[self frameLoader]];
+ return SubresourceLoader::create([self frameLoader], resourceLoader,
+ method, URL, customHeaders, postData, hideReferrer ? nil : [self referrer]);
}
- (void)reportClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date lockHistory:(BOOL)lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction
#import "FrameLoaderTypes.h"
#import <Cocoa/Cocoa.h>
#import <wtf/Forward.h>
+#import <wtf/HashSet.h>
+#import <wtf/RefPtr.h>
+#import <wtf/Vector.h>
namespace WebCore {
class FormState;
+ class MainResourceLoader;
+ class WebResourceLoader;
}
@class DOMElement;
@class WebDocumentLoader;
@class WebCoreFrameBridge;
-@class WebLoader;
-@class WebMainResourceLoader;
@class WebPolicyDecider;
@protocol WebFrameLoaderClient;
-BOOL isBackForwardLoadType(FrameLoadType type);
+bool isBackForwardLoadType(FrameLoadType);
@interface WebFrameLoader : NSObject
{
WebCoreFrameBridge *frameBridge;
- WebMainResourceLoader *mainResourceLoader;
+ WebCore::MainResourceLoader *m_mainResourceLoader;
- NSMutableArray *subresourceLoaders;
- NSMutableArray *plugInStreamLoaders;
+ HashSet<RefPtr<WebCore::WebResourceLoader> >* m_subresourceLoaders;
+ HashSet<RefPtr<WebCore::WebResourceLoader> >* m_plugInStreamLoaders;
- id<WebFrameLoaderClient> client;
+ id <WebFrameLoaderClient> client;
WebDocumentLoader *documentLoader;
WebDocumentLoader *provisionalDocumentLoader;
WebDocumentLoader *policyDocumentLoader;
}
- (id)initWithFrameBridge:(WebCoreFrameBridge *)bridge;
-- (void)addPlugInStreamLoader:(WebLoader *)loader;
-- (void)removePlugInStreamLoader:(WebLoader *)loader;
+- (void)addPlugInStreamLoader:(WebCore::WebResourceLoader *)loader;
+- (void)removePlugInStreamLoader:(WebCore::WebResourceLoader *)loader;
- (void)setDefersCallbacks:(BOOL)defers;
- (void)stopLoadingPlugIns;
- (BOOL)isLoadingMainResource;
- (BOOL)isLoadingSubresources;
- (BOOL)isLoading;
- (void)stopLoadingSubresources;
-- (void)addSubresourceLoader:(WebLoader *)loader;
-- (void)removeSubresourceLoader:(WebLoader *)loader;
+- (void)addSubresourceLoader:(WebCore::WebResourceLoader *)loader;
+- (void)removeSubresourceLoader:(WebCore::WebResourceLoader *)loader;
- (NSData *)mainResourceData;
- (void)releaseMainResourceLoader;
- (void)cancelMainResourceLoad;
- (NSError *)cancelledErrorWithRequest:(NSURLRequest *)request;
- (NSError *)fileDoesNotExistErrorWithResponse:(NSURLResponse *)response;
-- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader;
-- (BOOL)archiveLoadPendingForLoader:(WebLoader *)loader;
-- (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
+- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebCore::WebResourceLoader *)loader;
+- (BOOL)archiveLoadPendingForLoader:(WebCore::WebResourceLoader *)loader;
+- (void)cancelPendingArchiveLoadForLoader:(WebCore::WebResourceLoader *)loader;
- (void)cannotShowMIMETypeWithResponse:(NSURLResponse *)response;
- (NSError *)interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request;
- (BOOL)isHostedByObjectElement;
using namespace WebCore;
-static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
+namespace WebCore {
+
+typedef HashSet<RefPtr<WebCore::WebResourceLoader> > ResourceLoaderSet;
+
+static void setDefersCallbacks(const ResourceLoaderSet* set, bool defers)
+{
+ if (!set)
+ return;
+ const ResourceLoaderSet copy = *set;
+ ResourceLoaderSet::const_iterator end = copy.end();
+ for (ResourceLoaderSet::const_iterator it = copy.begin(); it != end; ++it)
+ (*it)->setDefersCallbacks(defers);
+}
+
+static void cancelAll(const ResourceLoaderSet* set)
+{
+ if (!set)
+ return;
+ const ResourceLoaderSet copy = *set;
+ ResourceLoaderSet::const_iterator end = copy.end();
+ for (ResourceLoaderSet::const_iterator it = copy.begin(); it != end; ++it)
+ (*it)->cancel();
+}
+
+}
+
+static bool isCaseInsensitiveEqual(NSString *a, NSString *b)
{
return [a caseInsensitiveCompare:b] == NSOrderedSame;
}
-BOOL isBackForwardLoadType(FrameLoadType type)
+bool isBackForwardLoadType(FrameLoadType type)
{
switch (type) {
case FrameLoadTypeStandard:
- (void)dealloc
{
- // FIXME: should these even exist?
- [mainResourceLoader release];
- [subresourceLoaders release];
- [plugInStreamLoaders release];
+ // FIXME: Is there really a possiblity that any of these could be non-null?
+ if (m_mainResourceLoader)
+ m_mainResourceLoader->deref();
+ delete m_subresourceLoaders;
+ delete m_plugInStreamLoaders;
[documentLoader release];
[provisionalDocumentLoader release];
[super dealloc];
}
+- (void)finalize
+{
+ if (m_mainResourceLoader)
+ m_mainResourceLoader->deref();
+ [super finalize];
+}
+
- (WebDocumentLoader *)activeDocumentLoader
{
if (state == WebFrameStateProvisional)
return documentLoader;
}
-- (void)addPlugInStreamLoader:(WebLoader *)loader
+- (void)addPlugInStreamLoader:(WebResourceLoader *)loader
{
- if (!plugInStreamLoaders)
- plugInStreamLoaders = [[NSMutableArray alloc] init];
- [plugInStreamLoaders addObject:loader];
+ if (!m_plugInStreamLoaders)
+ m_plugInStreamLoaders = new ResourceLoaderSet;
+ m_plugInStreamLoaders->add(loader);
[[self activeDocumentLoader] setLoading:YES];
}
-- (void)removePlugInStreamLoader:(WebLoader *)loader
+- (void)removePlugInStreamLoader:(WebResourceLoader *)loader
{
- [plugInStreamLoaders removeObject:loader];
+ ASSERT(m_plugInStreamLoaders);
+ m_plugInStreamLoaders->remove(loader);
[[self activeDocumentLoader] updateLoading];
}
- (void)setDefersCallbacks:(BOOL)defers
{
- [mainResourceLoader setDefersCallbacks:defers];
-
- NSEnumerator *e = [subresourceLoaders objectEnumerator];
- WebLoader *loader;
- while ((loader = [e nextObject]))
- [loader setDefersCallbacks:defers];
-
- e = [plugInStreamLoaders objectEnumerator];
- while ((loader = [e nextObject]))
- [loader setDefersCallbacks:defers];
-
+ if (m_mainResourceLoader)
+ m_mainResourceLoader->setDefersCallbacks(defers);
+ setDefersCallbacks(m_subresourceLoaders, defers);
+ setDefersCallbacks(m_plugInStreamLoaders, defers);
[client _setDefersCallbacks:defers];
}
- (void)stopLoadingPlugIns
{
- [plugInStreamLoaders makeObjectsPerformSelector:@selector(cancel)];
- [plugInStreamLoaders removeAllObjects];
+ cancelAll(m_plugInStreamLoaders);
}
- (BOOL)isLoadingMainResource
{
- return mainResourceLoader != nil;
+ return m_mainResourceLoader != 0;
}
- (BOOL)isLoadingSubresources
{
- return [subresourceLoaders count];
+ return m_subresourceLoaders && !m_subresourceLoaders->isEmpty();
}
- (BOOL)isLoadingPlugIns
{
- return [plugInStreamLoaders count];
+ return m_plugInStreamLoaders && !m_plugInStreamLoaders->isEmpty();
}
- (BOOL)isLoading
- (void)stopLoadingSubresources
{
- NSArray *loaders = [subresourceLoaders copy];
- [loaders makeObjectsPerformSelector:@selector(cancel)];
- [loaders release];
- [subresourceLoaders removeAllObjects];
+ cancelAll(m_subresourceLoaders);
}
-- (void)addSubresourceLoader:(WebLoader *)loader
+- (void)addSubresourceLoader:(WebResourceLoader *)loader
{
ASSERT(!provisionalDocumentLoader);
- if (subresourceLoaders == nil)
- subresourceLoaders = [[NSMutableArray alloc] init];
- [subresourceLoaders addObject:loader];
+ if (!m_subresourceLoaders)
+ m_subresourceLoaders = new ResourceLoaderSet;
+ m_subresourceLoaders->add(loader);
[[self activeDocumentLoader] setLoading:YES];
}
-- (void)removeSubresourceLoader:(WebLoader *)loader
+- (void)removeSubresourceLoader:(WebResourceLoader *)loader
{
- [subresourceLoaders removeObject:loader];
+ ASSERT(m_subresourceLoaders);
+ m_subresourceLoaders->remove(loader);
[[self activeDocumentLoader] updateLoading];
}
- (NSData *)mainResourceData
{
- return [mainResourceLoader resourceData];
+ if (!m_mainResourceLoader)
+ return nil;
+ return m_mainResourceLoader->resourceData();
}
- (void)releaseMainResourceLoader
{
- [mainResourceLoader release];
- mainResourceLoader = nil;
+ if (!m_mainResourceLoader)
+ return;
+ m_mainResourceLoader->deref();
+ m_mainResourceLoader = 0;
}
- (void)cancelMainResourceLoad
{
- [mainResourceLoader cancel];
+ if (m_mainResourceLoader)
+ m_mainResourceLoader->cancel();
}
- (BOOL)startLoadingMainResourceWithRequest:(NSMutableURLRequest *)request identifier:(id)identifier
{
- mainResourceLoader = [[WebMainResourceLoader alloc] initWithFrameLoader:self];
+ ASSERT(!m_mainResourceLoader);
+ m_mainResourceLoader = MainResourceLoader::create(self).release();
- [mainResourceLoader setIdentifier:identifier];
+ m_mainResourceLoader->setIdentifier(identifier);
[self addExtraFieldsToRequest:request mainResource:YES alwaysFromRequest:NO];
- if (![mainResourceLoader loadWithRequest:request]) {
+ if (!m_mainResourceLoader->load(request)) {
// FIXME: if this should really be caught, we should just ASSERT this doesn't happen;
// should it be caught by other parts of WebKit or other parts of the app?
LOG_ERROR("could not create WebResourceHandle for URL %@ -- should be caught by policy handler level", [request URL]);
- [mainResourceLoader release];
- mainResourceLoader = nil;
+ m_mainResourceLoader->deref();
+ m_mainResourceLoader = 0;
return NO;
}
- (void)stopLoadingWithError:(NSError *)error
{
- [mainResourceLoader cancelWithError:error];
+ m_mainResourceLoader->cancel(error);
}
- (void)setDocumentLoader:(WebDocumentLoader *)loader
return [client _fileDoesNotExistErrorWithResponse:response];
}
-- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader
+- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebResourceLoader *)loader
{
return [client _willUseArchiveForRequest:request originalURL:originalURL loader:loader];
}
-- (BOOL)archiveLoadPendingForLoader:(WebLoader *)loader
+- (BOOL)archiveLoadPendingForLoader:(WebResourceLoader *)loader
{
return [client _archiveLoadPendingForLoader:loader];
}
-- (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader
+- (void)cancelPendingArchiveLoadForLoader:(WebResourceLoader *)loader
{
[client _cancelPendingArchiveLoadForLoader:loader];
}
#import <Cocoa/Cocoa.h>
+namespace WebCore {
+ class WebResourceLoader;
+}
+
typedef struct LoadErrorResetToken LoadErrorResetToken;
@class DOMElement;
@class WebCoreFrameBridge;
@class WebDocumentLoader;
-@class WebLoader;
@class WebPolicyDecider;
@class WebResource;
- (void)_setDefersCallbacks:(BOOL)defers;
-- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader;
-- (BOOL)_archiveLoadPendingForLoader:(WebLoader *)loader;
-- (void)_cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
+- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebCore::WebResourceLoader *)loader;
+- (BOOL)_archiveLoadPendingForLoader:(WebCore::WebResourceLoader *)loader;
+- (void)_cancelPendingArchiveLoadForLoader:(WebCore::WebResourceLoader *)loader;
- (void)_clearArchivedResources;
- (BOOL)_canHandleRequest:(NSURLRequest *)request;
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import <Foundation/Foundation.h>
+#include "RetainPtr.h"
+#include "Shared.h"
@class NSError;
@class NSURLAuthenticationChallenge;
@class NSURLConnection;
-@class NSURLConnectionAuthenticationChallenge;
-@class NSURLCredential;
@class NSURLRequest;
@class NSURLResponse;
@class WebFrameLoader;
+@class WebCoreResourceLoaderDelegate;
-@interface WebLoader : NSObject
-{
-@protected
- WebFrameLoader *frameLoader;
- NSURLConnection *connection;
- NSURLRequest *request;
- BOOL reachedTerminalState;
- BOOL loadingMultipartContent;
- BOOL signalledFinish;
- BOOL cancelledFlag;
- id identifier;
-@private
- NSURLResponse *response;
- NSURLAuthenticationChallenge *currentConnectionChallenge;
- NSURLAuthenticationChallenge *currentWebChallenge;
- BOOL defersCallbacks;
- NSURL *originalURL;
- NSMutableData *resourceData;
-#ifndef NDEBUG
- BOOL isInitializingConnection;
-#endif
-}
-- (void)signalFinish;
+namespace WebCore {
+
+ // FIXME: Rename to ResourceLoader after resolving conflict with existing class of that name.
+ class WebResourceLoader : public Shared<WebResourceLoader> {
+ public:
+ virtual ~WebResourceLoader();
+
+ virtual bool load(NSURLRequest *);
+
+ virtual void signalFinish();
-- (BOOL)loadWithRequest:(NSURLRequest *)request;
+ void setFrameLoader(WebFrameLoader *);
+ WebFrameLoader *frameLoader() const;
-- (void)setFrameLoader:(WebFrameLoader *)fl;
-- (WebFrameLoader *)frameLoader;
+ virtual void cancel();
+ virtual void cancel(NSError *);
+ NSError *cancelledError();
-- (void)cancel;
-- (void)cancelWithError:(NSError *)error;
-- (NSError *)cancelledError;
+ virtual void setDefersCallbacks(bool);
+ bool defersCallbacks() const;
-- (void)setDefersCallbacks:(BOOL)defers;
-- (BOOL)defersCallbacks;
+ void setIdentifier(id);
-- (void)setIdentifier:(id)ident;
+ virtual void releaseResources();
+ NSURLResponse *response() const;
-- (void)releaseResources;
-- (NSURLResponse *)response;
+ virtual void addData(NSData *, bool allAtOnce);
+ NSData *resourceData();
+ void clearResourceData();
-- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce;
-- (NSData *)resourceData;
-- (void)clearResourceData;
+ virtual NSURLRequest *willSendRequest(NSURLRequest *, NSURLResponse *redirectResponse);
+ void didReceiveAuthenticationChallenge(NSURLAuthenticationChallenge *);
+ void didCancelAuthenticationChallenge(NSURLAuthenticationChallenge *);
+ virtual void didReceiveResponse(NSURLResponse *);
+ virtual void didReceiveData(NSData *, long long lengthReceived, bool allAtOnce);
+ void willStopBufferingData(NSData *data);
+ virtual void didFinishLoading();
+ virtual void didFail(NSError *);
+ NSCachedURLResponse *willCacheResponse(NSCachedURLResponse *);
-// Connection-less callbacks allow us to send callbacks using data attained from a WebResource instead of an NSURLConnection.
-- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse;
-- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
-- (void)didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge;
-- (void)didReceiveResponse:(NSURLResponse *)r;
-- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce;
-- (void)willStopBufferingData:(NSData *)data;
-- (void)didFinishLoading;
-- (void)didFailWithError:(NSError *)error;
-- (NSCachedURLResponse *)willCacheResponse:(NSCachedURLResponse *)cachedResponse;
+ void receivedCredential(NSURLAuthenticationChallenge *, NSURLCredential *);
+ void receivedRequestToContinueWithoutCredential(NSURLAuthenticationChallenge *);
+ void receivedCancellation(NSURLAuthenticationChallenge *);
+ // Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the first one.
+ static bool inConnectionCallback();
-// Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the first one.
-+ (BOOL)inConnectionCallback;
+ protected:
+ WebResourceLoader(WebFrameLoader *);
+ WebCoreResourceLoaderDelegate *delegate();
+ virtual void releaseDelegate();
-@end
+ NSURLConnection *connection() const { return m_connection.get(); }
+ NSURLRequest *request() const { return m_request.get(); }
+ bool reachedTerminalState() const { return m_reachedTerminalState; }
+ bool signalledFinish() const { return m_signalledFinish; }
+ bool cancelled() const { return m_cancelled; }
+ id identifier() const { return m_identifier.get(); }
-// Note: This interface can be removed once this method is declared
-// in Foundation (probably will be in Foundation-485).
-@interface NSObject (WebLoaderExtras)
-- (void)connection:(NSURLConnection *)con didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived;
-@end
+ RetainPtr<NSURLConnection> m_connection;
+
+ private:
+ RetainPtr<NSURLRequest> m_request;
+ bool m_reachedTerminalState;
+ bool m_signalledFinish;
+ bool m_cancelled;
+
+ RetainPtr<WebFrameLoader> m_frameLoader;
+ RetainPtr<id> m_identifier;
+ RetainPtr<NSURLResponse> m_response;
+ NSURLAuthenticationChallenge *m_currentConnectionChallenge;
+ RetainPtr<NSURLAuthenticationChallenge> m_currentWebChallenge;
+ bool m_defersCallbacks;
+ RetainPtr<NSURL> m_originalURL;
+ RetainPtr<NSMutableData> m_resourceData;
+ RetainPtr<WebCoreResourceLoaderDelegate> m_delegate;
+ };
+
+}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "config.h"
#import "WebLoader.h"
+#import "WebCoreSystemInterface.h"
#import "WebDataProtocol.h"
#import "WebFrameLoader.h"
#import <Foundation/NSURLAuthenticationChallenge.h>
#import <Foundation/NSURLRequest.h>
#import <Foundation/NSURLResponse.h>
#import <wtf/Assertions.h>
-#import "WebCoreSystemInterface.h"
+#import <wtf/RefPtr.h>
-static unsigned inNSURLConnectionCallback;
-static BOOL NSURLConnectionSupportsBufferedData;
+using namespace WebCore;
+
+@interface WebCoreResourceLoaderDelegate : NSObject <NSURLAuthenticationChallengeSender>
+{
+ WebResourceLoader* m_loader;
+}
+- (id)initWithLoader:(WebResourceLoader*)loader;
+- (void)detachLoader;
+@end
@interface NSURLConnection (NSURLConnectionTigerPrivate)
- (NSData *)_bufferedData;
@end
-@interface WebLoader (WebNSURLAuthenticationChallengeSender) <NSURLAuthenticationChallengeSender>
+@interface NSURLProtocol (WebFoundationSecret)
++ (void)_removePropertyForKey:(NSString *)key inRequest:(NSMutableURLRequest *)request;
@end
-@implementation WebLoader (WebNSURLAuthenticationChallengeSender)
+namespace WebCore {
-- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
-{
- if (challenge == nil || challenge != currentWebChallenge) {
- return;
- }
-
- [[currentConnectionChallenge sender] useCredential:credential forAuthenticationChallenge:currentConnectionChallenge];
-
- [currentConnectionChallenge release];
- currentConnectionChallenge = nil;
-
- [currentWebChallenge release];
- currentWebChallenge = nil;
-}
-
-- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
-{
- if (challenge == nil || challenge != currentWebChallenge) {
- return;
- }
-
- [[currentConnectionChallenge sender] continueWithoutCredentialForAuthenticationChallenge:currentConnectionChallenge];
+static unsigned inNSURLConnectionCallback;
+static bool NSURLConnectionSupportsBufferedData;
- [currentConnectionChallenge release];
- currentConnectionChallenge = nil;
-
- [currentWebChallenge release];
- currentWebChallenge = nil;
-}
+#ifndef NDEBUG
+static bool isInitializingConnection;
+#endif
-- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
-{
- if (challenge == nil || challenge != currentWebChallenge) {
- return;
+WebResourceLoader::WebResourceLoader(WebFrameLoader *frameLoader)
+ : m_reachedTerminalState(false)
+ , m_signalledFinish(false)
+ , m_cancelled(false)
+ , m_frameLoader(frameLoader)
+ , m_currentConnectionChallenge(nil)
+ , m_defersCallbacks([frameLoader defersCallbacks])
+{
+ static bool initialized = false;
+ if (!initialized) {
+ NSURLConnectionSupportsBufferedData = [NSURLConnection instancesRespondToSelector:@selector(_bufferedData)];
+ initialized = true;
}
-
- [self cancel];
}
-@end
-
-// This declaration is only needed to ease the transition to a new SPI. It can be removed
-// moving forward beyond Tiger 8A416.
-@interface NSURLProtocol (WebFoundationSecret)
-+ (void)_removePropertyForKey:(NSString *)key inRequest:(NSMutableURLRequest *)request;
-@end
-
-@implementation WebLoader
-
-+ (void)initialize
+WebResourceLoader::~WebResourceLoader()
{
- NSURLConnectionSupportsBufferedData = [NSURLConnection instancesRespondToSelector:@selector(_bufferedData)];
+ ASSERT(m_reachedTerminalState);
+ releaseDelegate();
}
-- (void)releaseResources
+void WebResourceLoader::releaseResources()
{
- ASSERT(!reachedTerminalState);
+ ASSERT(!m_reachedTerminalState);
// It's possible that when we release the handle, it will be
// deallocated and release the last reference to this object.
// We need to retain to avoid accessing the object after it
// has been deallocated and also to avoid reentering this method.
-
- [self retain];
+ RefPtr<WebResourceLoader> protector(this);
- // We need to set reachedTerminalState to YES before we release
+ // We need to set reachedTerminalState to true before we release
// the resources to prevent a double dealloc of WebView <rdar://problem/4372628>
+ m_reachedTerminalState = true;
- reachedTerminalState = YES;
-
- [identifier release];
- identifier = nil;
+ m_identifier = nil;
+ m_connection = nil;
+ m_frameLoader = nil;
+ m_resourceData = nil;
- [connection release];
- connection = nil;
-
- [frameLoader release];
- frameLoader = nil;
-
- [resourceData release];
- resourceData = nil;
-
- [self release];
-}
-
-- (void)dealloc
-{
- ASSERT(reachedTerminalState);
- [request release];
- [response release];
- [originalURL release];
- [super dealloc];
+ releaseDelegate();
}
-- (BOOL)loadWithRequest:(NSURLRequest *)r
+bool WebResourceLoader::load(NSURLRequest *r)
{
- ASSERT(connection == nil);
- ASSERT(![frameLoader archiveLoadPendingForLoader:self]);
+ ASSERT(m_connection == nil);
+ ASSERT(![m_frameLoader.get() archiveLoadPendingForLoader:this]);
- NSURL *URL = [[r URL] retain];
- [originalURL release];
- originalURL = URL;
+ m_originalURL = [r URL];
- NSURLRequest *clientRequest = [self willSendRequest:r redirectResponse:nil];
+ NSURLRequest *clientRequest = willSendRequest(r, nil);
if (clientRequest == nil) {
- NSError *cancelledError = [frameLoader cancelledErrorWithRequest:r];
- [self didFailWithError:cancelledError];
- return NO;
+ didFail([m_frameLoader.get() cancelledErrorWithRequest:r]);
+ return false;
}
r = clientRequest;
- if ([frameLoader willUseArchiveForRequest:r originalURL:originalURL loader:self])
- return YES;
+ if ([m_frameLoader.get() willUseArchiveForRequest:r originalURL:m_originalURL.get() loader:this])
+ return true;
#ifndef NDEBUG
isInitializingConnection = YES;
#endif
- connection = [[NSURLConnection alloc] initWithRequest:r delegate:self];
+ NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:r delegate:delegate()];
#ifndef NDEBUG
isInitializingConnection = NO;
#endif
- if (defersCallbacks)
- wkSetNSURLConnectionDefersCallbacks(connection, YES);
+ m_connection = connection;
+ [connection release];
+ if (defersCallbacks())
+ wkSetNSURLConnectionDefersCallbacks(m_connection.get(), YES);
- return YES;
+ return true;
}
-- (void)setDefersCallbacks:(BOOL)defers
+void WebResourceLoader::setDefersCallbacks(bool defers)
{
- defersCallbacks = defers;
- wkSetNSURLConnectionDefersCallbacks(connection, defers);
- // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
+ m_defersCallbacks = defers;
+ wkSetNSURLConnectionDefersCallbacks(m_connection.get(), defers);
}
-- (BOOL)defersCallbacks
+bool WebResourceLoader::defersCallbacks() const
{
- return defersCallbacks;
+ return m_defersCallbacks;
}
-- (void)setFrameLoader:(WebFrameLoader *)fl
+void WebResourceLoader::setFrameLoader(WebFrameLoader *fl)
{
ASSERT(fl);
-
- [fl retain];
- [frameLoader release];
- frameLoader = fl;
-
- [self setDefersCallbacks:[frameLoader defersCallbacks]];
+ m_frameLoader = fl;
+ setDefersCallbacks([fl defersCallbacks]);
}
-- (WebFrameLoader *)frameLoader
+WebFrameLoader *WebResourceLoader::frameLoader() const
{
- return frameLoader;
+ return m_frameLoader.get();
}
-- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce
+void WebResourceLoader::addData(NSData *data, bool allAtOnce)
{
if (allAtOnce) {
- resourceData = [data copy];
+ NSMutableData *dataCopy = [data mutableCopy];
+ m_resourceData = dataCopy;
+ [dataCopy release];
return;
}
if (NSURLConnectionSupportsBufferedData) {
// Buffer data only if the connection has handed us the data because is has stopped buffering it.
- if (resourceData != nil)
- [resourceData appendData:data];
+ if (m_resourceData)
+ [m_resourceData.get() appendData:data];
} else {
- if (resourceData == nil)
- resourceData = [[NSMutableData alloc] init];
- [resourceData appendData:data];
+ if (!m_resourceData) {
+ NSMutableData *newData = [[NSMutableData alloc] init];
+ m_resourceData = newData;
+ [newData release];
+ }
+ [m_resourceData.get() appendData:data];
}
}
-- (NSData *)resourceData
+NSData *WebResourceLoader::resourceData()
{
- if (resourceData)
+ if (m_resourceData)
// Retain and autorelease resourceData since releaseResources (which releases resourceData) may be called
- // before the caller of this method has an opporuntity to retain the returned data (4070729).
- return [[resourceData retain] autorelease];
+ // before the caller of this method has an opportunity to retain the returned data (4070729).
+ return [[m_resourceData.get() retain] autorelease];
if (NSURLConnectionSupportsBufferedData)
- return [connection _bufferedData];
+ return [m_connection.get() _bufferedData];
return nil;
}
-- (void)clearResourceData
+void WebResourceLoader::clearResourceData()
{
- [resourceData setLength:0];
+ [m_resourceData.get() setLength:0];
}
-- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
+NSURLRequest *WebResourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
{
- ASSERT(!reachedTerminalState);
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
+
+ ASSERT(!m_reachedTerminalState);
NSMutableURLRequest *mutableRequest = [[newRequest mutableCopy] autorelease];
- NSMutableURLRequest *clientRequest;
- NSURLRequest *updatedRequest;
- BOOL haveDataSchemeRequest = NO;
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
-
newRequest = mutableRequest;
// If we have a special "applewebdata" scheme URL we send a fake request to the delegate.
- clientRequest = [mutableRequest _webDataRequestExternalRequest];
+ bool haveDataSchemeRequest = false;
+ NSMutableURLRequest *clientRequest = [mutableRequest _webDataRequestExternalRequest];
if (!clientRequest)
clientRequest = mutableRequest;
else
- haveDataSchemeRequest = YES;
+ haveDataSchemeRequest = true;
- if (identifier == nil)
- identifier = [frameLoader _identifierForInitialRequest:clientRequest];
+ if (!m_identifier) {
+ id identifier = [m_frameLoader.get() _identifierForInitialRequest:clientRequest];
+ m_identifier = identifier;
+ [identifier release];
+ }
- updatedRequest = [frameLoader _willSendRequest:clientRequest forResource:identifier redirectResponse:redirectResponse];
+ NSURLRequest *updatedRequest = [m_frameLoader.get() _willSendRequest:clientRequest
+ forResource:m_identifier.get() redirectResponse:redirectResponse];
if (!haveDataSchemeRequest)
newRequest = updatedRequest;
}
}
- // Store a copy of the request.
- [request autorelease];
+ // Old code used to autorelease rather than release, so do an autorelease here for now.
+ // Eventually we should remove this.
+ [[m_request.get() retain] autorelease];
- request = [newRequest copy];
+ // Store a copy of the request.
+ NSURLRequest *copy = [newRequest copy];
+ m_request = copy;
+ [copy release];
- [self release];
- return request;
+ return copy;
}
-- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+void WebResourceLoader::didReceiveAuthenticationChallenge(NSURLAuthenticationChallenge *challenge)
{
- ASSERT(!reachedTerminalState);
- ASSERT(!currentConnectionChallenge);
- ASSERT(!currentWebChallenge);
+ ASSERT(!m_reachedTerminalState);
+ ASSERT(!m_currentConnectionChallenge);
+ ASSERT(!m_currentWebChallenge);
+
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- currentConnectionChallenge = [challenge retain];;
- currentWebChallenge = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:challenge sender:self];
+ m_currentConnectionChallenge = challenge;
+ NSURLAuthenticationChallenge *webChallenge = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:challenge sender:delegate()];
+ m_currentWebChallenge = webChallenge;
- [frameLoader _didReceiveAuthenticationChallenge:currentWebChallenge forResource:identifier];
+ [m_frameLoader.get() _didReceiveAuthenticationChallenge:webChallenge forResource:m_identifier.get()];
- [self release];
+ [webChallenge release];
}
-- (void)didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+void WebResourceLoader::didCancelAuthenticationChallenge(NSURLAuthenticationChallenge *challenge)
{
- ASSERT(!reachedTerminalState);
- ASSERT(currentConnectionChallenge);
- ASSERT(currentWebChallenge);
- ASSERT(currentConnectionChallenge = challenge);
+ ASSERT(!m_reachedTerminalState);
+ ASSERT(m_currentConnectionChallenge);
+ ASSERT(m_currentWebChallenge);
+ ASSERT(m_currentConnectionChallenge == challenge);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- [frameLoader _didCancelAuthenticationChallenge:currentWebChallenge forResource:identifier];
- [self release];
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
+
+ [m_frameLoader.get() _didCancelAuthenticationChallenge:m_currentWebChallenge.get()
+ forResource:m_identifier.get()];
}
-- (void)didReceiveResponse:(NSURLResponse *)r
+void WebResourceLoader::didReceiveResponse(NSURLResponse *r)
{
- ASSERT(!reachedTerminalState);
+ ASSERT(!m_reachedTerminalState);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
// If the URL is one of our whacky applewebdata URLs then
// fake up a substitute URL to present to the delegate.
- if([WebDataProtocol _webIsDataProtocolURL:[r URL]])
- r = [[[NSURLResponse alloc] initWithURL:[request _webDataRequestExternalURL] MIMEType:[r MIMEType] expectedContentLength:(int)[r expectedContentLength] textEncodingName:[r textEncodingName]] autorelease];
-
- [r retain];
- [response release];
- response = r;
+ if ([WebDataProtocol _webIsDataProtocolURL:[r URL]])
+ r = [[[NSURLResponse alloc] initWithURL:[m_request.get() _webDataRequestExternalURL] MIMEType:[r MIMEType]
+ expectedContentLength:[r expectedContentLength] textEncodingName:[r textEncodingName]] autorelease];
- [frameLoader _didReceiveResponse:r forResource:identifier];
+ m_response = r;
- [self release];
+ [m_frameLoader.get() _didReceiveResponse:r forResource:m_identifier.get()];
}
-- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
+void WebResourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
{
// The following assertions are not quite valid here, since a subclass
// might override didReceiveData: in a way that invalidates them. This
// happens with the steps listed in 3266216
// ASSERT(con == connection);
- // ASSERT(!reachedTerminalState);
+ // ASSERT(!m_reachedTerminalState);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
- [self addData:data allAtOnce:allAtOnce];
+ addData(data, allAtOnce);
- [frameLoader _didReceiveData:data contentLength:(int)lengthReceived forResource:identifier];
-
- [self release];
+ [m_frameLoader.get() _didReceiveData:data contentLength:(int)lengthReceived forResource:m_identifier.get()];
}
-- (void)willStopBufferingData:(NSData *)data
+void WebResourceLoader::willStopBufferingData(NSData *data)
{
- ASSERT(resourceData == nil);
- resourceData = [data mutableCopy];
+ ASSERT(!m_resourceData);
+ NSMutableData *copy = [data mutableCopy];
+ m_resourceData = copy;
+ [copy release];
}
-- (void)signalFinish
+void WebResourceLoader::signalFinish()
{
- signalledFinish = YES;
- [frameLoader _didFinishLoadingForResource:identifier];
+ m_signalledFinish = true;
+ [m_frameLoader.get() _didFinishLoadingForResource:m_identifier.get()];
}
-- (void)didFinishLoading
+void WebResourceLoader::didFinishLoading()
{
// If load has been cancelled after finishing (which could happen with a
// javascript that changes the window location), do nothing.
- if (cancelledFlag)
+ if (m_cancelled)
return;
- ASSERT(!reachedTerminalState);
+ ASSERT(!m_reachedTerminalState);
- if (!signalledFinish)
- [self signalFinish];
+ if (!m_signalledFinish)
+ signalFinish();
- [self releaseResources];
+ releaseResources();
}
-- (void)didFailWithError:(NSError *)error
+void WebResourceLoader::didFail(NSError *error)
{
- if (cancelledFlag) {
+ if (m_cancelled)
return;
- }
- ASSERT(!reachedTerminalState);
+ ASSERT(!m_reachedTerminalState);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
+ // Protect this in this delegate method since the additional processing can do
+ // anything including possibly derefing this; one example of this is Radar 3266216.
+ RefPtr<WebResourceLoader> protector(this);
- [frameLoader _didFailLoadingWithError:error forResource:identifier];
+ [m_frameLoader.get() _didFailLoadingWithError:error forResource:m_identifier.get()];
- [self releaseResources];
- [self release];
+ releaseResources();
}
-- (NSCachedURLResponse *)willCacheResponse:(NSCachedURLResponse *)cachedResponse
+NSCachedURLResponse *WebResourceLoader::willCacheResponse(NSCachedURLResponse *cachedResponse)
{
// When in private browsing mode, prevent caching to disk
- if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [frameLoader _privateBrowsingEnabled]) {
+ if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [m_frameLoader.get() _privateBrowsingEnabled]) {
cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
data:[cachedResponse data]
userInfo:[cachedResponse userInfo]
return cachedResponse;
}
+void WebResourceLoader::cancel(NSError *error)
+{
+ ASSERT(!m_reachedTerminalState);
+
+ // This flag prevents bad behavior when loads that finish cause the
+ // load itself to be cancelled (which could happen with a javascript that
+ // changes the window location). This is used to prevent both the body
+ // of this method and the body of connectionDidFinishLoading: running
+ // for a single delegate. Cancelling wins.
+ m_cancelled = true;
+
+ m_currentConnectionChallenge = nil;
+ m_currentWebChallenge = nil;
+
+ [m_frameLoader.get() cancelPendingArchiveLoadForLoader:this];
+ [m_connection.get() cancel];
+
+ [m_frameLoader.get() _didFailLoadingWithError:error forResource:m_identifier.get()];
+
+ releaseResources();
+}
+
+void WebResourceLoader::cancel()
+{
+ if (!m_reachedTerminalState)
+ cancel(cancelledError());
+}
+
+void WebResourceLoader::setIdentifier(id identifier)
+{
+ m_identifier = identifier;
+}
+
+NSURLResponse *WebResourceLoader::response() const
+{
+ return m_response.get();
+}
+
+bool WebResourceLoader::inConnectionCallback()
+{
+ return inNSURLConnectionCallback != 0;
+}
+
+NSError *WebResourceLoader::cancelledError()
+{
+ return [m_frameLoader.get() cancelledErrorWithRequest:m_request.get()];
+}
+
+void WebResourceLoader::receivedCredential(NSURLAuthenticationChallenge *challenge, NSURLCredential *credential)
+{
+ ASSERT(challenge);
+ if (challenge != m_currentWebChallenge)
+ return;
+
+ [[m_currentConnectionChallenge sender] useCredential:credential forAuthenticationChallenge:m_currentConnectionChallenge];
+
+ m_currentConnectionChallenge = nil;
+ m_currentWebChallenge = nil;
+}
+
+void WebResourceLoader::receivedRequestToContinueWithoutCredential(NSURLAuthenticationChallenge *challenge)
+{
+ ASSERT(challenge);
+ if (challenge != m_currentWebChallenge)
+ return;
+
+ [[m_currentConnectionChallenge sender] continueWithoutCredentialForAuthenticationChallenge:m_currentConnectionChallenge];
+
+ m_currentConnectionChallenge = nil;
+ m_currentWebChallenge = nil;
+}
+
+void WebResourceLoader::receivedCancellation(NSURLAuthenticationChallenge *challenge)
+{
+ if (challenge != m_currentWebChallenge)
+ return;
+
+ cancel();
+}
+
+WebCoreResourceLoaderDelegate *WebResourceLoader::delegate()
+{
+ if (!m_delegate) {
+ WebCoreResourceLoaderDelegate *d = [[WebCoreResourceLoaderDelegate alloc] initWithLoader:this];
+ m_delegate = d;
+ [d release];
+ }
+ return m_delegate.get();
+}
+
+void WebResourceLoader::releaseDelegate()
+{
+ if (!m_delegate)
+ return;
+ [m_delegate.get() detachLoader];
+ m_delegate = nil;
+}
+
+}
+
+@implementation WebCoreResourceLoaderDelegate
+
+- (id)initWithLoader:(WebResourceLoader*)loader
+{
+ self = [self init];
+ if (!self)
+ return nil;
+ m_loader = loader;
+ return self;
+}
+
+- (void)detachLoader
+{
+ m_loader = nil;
+}
+
- (NSURLRequest *)connection:(NSURLConnection *)con willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return nil;
++inNSURLConnectionCallback;
- NSURLRequest *result = [self willSendRequest:newRequest redirectResponse:redirectResponse];
+ NSURLRequest *result = m_loader->willSendRequest(newRequest, redirectResponse);
--inNSURLConnectionCallback;
return result;
}
- (void)connection:(NSURLConnection *)con didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didReceiveAuthenticationChallenge:challenge];
+ m_loader->didReceiveAuthenticationChallenge(challenge);
--inNSURLConnectionCallback;
}
- (void)connection:(NSURLConnection *)con didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didCancelAuthenticationChallenge:challenge];
+ m_loader->didCancelAuthenticationChallenge(challenge);
--inNSURLConnectionCallback;
}
- (void)connection:(NSURLConnection *)con didReceiveResponse:(NSURLResponse *)r
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didReceiveResponse:r];
+ m_loader->didReceiveResponse(r);
--inNSURLConnectionCallback;
}
- (void)connection:(NSURLConnection *)con didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didReceiveData:data lengthReceived:lengthReceived allAtOnce:NO];
+ m_loader->didReceiveData(data, lengthReceived, false);
--inNSURLConnectionCallback;
}
- (void)connection:(NSURLConnection *)con willStopBufferingData:(NSData *)data
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self willStopBufferingData:data];
+ m_loader->willStopBufferingData(data);
--inNSURLConnectionCallback;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)con
{
- // don't worry about checking connection consistency if this load
- // got cancelled while finishing.
- ASSERT(cancelledFlag || con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didFinishLoading];
+ m_loader->didFinishLoading();
--inNSURLConnectionCallback;
}
- (void)connection:(NSURLConnection *)con didFailWithError:(NSError *)error
{
- ASSERT(con == connection);
+ if (!m_loader)
+ return;
++inNSURLConnectionCallback;
- [self didFailWithError:error];
+ m_loader->didFail(error);
--inNSURLConnectionCallback;
}
-- (NSCachedURLResponse *)connection:(NSURLConnection *)con willCacheResponse:(NSCachedURLResponse *)cachedResponse
+- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
#ifndef NDEBUG
- if (connection == nil && isInitializingConnection) {
+ if (isInitializingConnection)
LOG_ERROR("connection:willCacheResponse: was called inside of [NSURLConnection initWithRequest:delegate:] (40676250)");
- }
#endif
+ if (!m_loader)
+ return nil;
++inNSURLConnectionCallback;
- NSCachedURLResponse *result = [self willCacheResponse:cachedResponse];
+ NSCachedURLResponse *result = m_loader->willCacheResponse(cachedResponse);
--inNSURLConnectionCallback;
return result;
}
-- (void)cancelWithError:(NSError *)error
-{
- ASSERT(!reachedTerminalState);
-
- // This flag prevents bad behvior when loads that finish cause the
- // load itself to be cancelled (which could happen with a javascript that
- // changes the window location). This is used to prevent both the body
- // of this method and the body of connectionDidFinishLoading: running
- // for a single delegate. Cancelling wins.
- cancelledFlag = YES;
-
- [currentConnectionChallenge release];
- currentConnectionChallenge = nil;
-
- [currentWebChallenge release];
- currentWebChallenge = nil;
-
- [frameLoader cancelPendingArchiveLoadForLoader:self];
- [connection cancel];
-
- [frameLoader _didFailLoadingWithError:error forResource:identifier];
-
- [self releaseResources];
-}
-
-- (void)cancel
-{
- if (!reachedTerminalState) {
- [self cancelWithError:[self cancelledError]];
- }
-}
-
-- (void)setIdentifier: ident
-{
- if (identifier != ident){
- [identifier release];
- identifier = [ident retain];
- }
-}
-
-- (NSURLResponse *)response
+- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
- return response;
+ if (!m_loader)
+ return;
+ m_loader->receivedCredential(challenge, credential);
}
-+ (BOOL)inConnectionCallback
+- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
- return inNSURLConnectionCallback != 0;
+ if (!m_loader)
+ return;
+ m_loader->receivedRequestToContinueWithoutCredential(challenge);
}
-- (NSError *)cancelledError
+- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
- return [frameLoader cancelledErrorWithRequest:request];
+ if (!m_loader)
+ return;
+ m_loader->receivedCancellation(challenge);
}
@end
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#import <Foundation/Foundation.h>
+#import "FrameLoaderTypes.h"
#import "WebLoader.h"
+#import <wtf/Forward.h>
-@interface WebMainResourceLoader : WebLoader
-{
- int _contentLength; // for logging only
- int _bytesReceived; // for logging only
- NSURLResponse *_response;
- id proxy;
- NSURLRequest *_initialRequest;
-}
+@class WebCoreMainResourceLoaderPolicyDelegate;
+
+namespace WebCore {
+
+ class MainResourceLoader : public WebResourceLoader {
+ public:
+ static PassRefPtr<MainResourceLoader> create(WebFrameLoader *);
+
+ virtual ~MainResourceLoader();
+
+ virtual bool load(NSURLRequest *);
+
+ using WebResourceLoader::cancel;
+ virtual void cancel(NSError *);
+
+ virtual void setDefersCallbacks(bool);
+
+ virtual void addData(NSData *, bool allAtOnce);
+
+ virtual NSURLRequest *willSendRequest(NSURLRequest *, NSURLResponse *redirectResponse);
+ virtual void didReceiveResponse(NSURLResponse *);
+ virtual void didReceiveData(NSData *, long long lengthReceived, bool allAtOnce);
+ virtual void didFinishLoading();
+ virtual void didFail(NSError *);
-- (id)initWithFrameLoader:(WebFrameLoader *)frameLoader;
+ void continueAfterNavigationPolicy(NSURLRequest *);
+ void continueAfterContentPolicy(WebPolicyAction);
-@end
+ private:
+ MainResourceLoader(WebFrameLoader *);
+
+ virtual void releaseDelegate();
+
+ WebCoreMainResourceLoaderPolicyDelegate *policyDelegate();
+ void releasePolicyDelegate();
+
+ NSURLRequest *loadNow(NSURLRequest *);
+
+ void receivedError(NSError *);
+ NSError *interruptionForPolicyChangeError() const;
+ void stopLoadingForPolicyChange();
+ bool isPostOrRedirectAfterPost(NSURLRequest *newRequest, NSURLResponse *redirectResponse);
+
+ void continueAfterContentPolicy(WebPolicyAction, NSURLResponse *);
+
+ int m_contentLength; // for logging only
+ int m_bytesReceived; // for logging only
+ RetainPtr<NSURLResponse> m_response;
+ RetainPtr<id> m_proxy;
+ RetainPtr<NSURLRequest> m_initialRequest;
+ RetainPtr<WebCoreMainResourceLoaderPolicyDelegate> m_policyDelegate;
+ bool m_loadingMultipartContent;
+ };
+
+}
#import "config.h"
#import "WebMainResourceLoader.h"
+#import "WebCoreSystemInterface.h"
#import "WebDataProtocol.h"
#import "WebFrameLoader.h"
#import <Foundation/NSHTTPCookie.h>
#import <Foundation/NSURLRequest.h>
#import <Foundation/NSURLResponse.h>
#import <wtf/Assertions.h>
-#import "WebCoreSystemInterface.h"
+#import <wtf/PassRefPtr.h>
-// FIXME: More that is in common with WebSubresourceLoader should move up into WebLoader.
+// FIXME: More that is in common with SubresourceLoader should move up into WebResourceLoader.
-@implementation WebMainResourceLoader
+using namespace WebCore;
-- (id)initWithFrameLoader:(WebFrameLoader *)fl
+@interface WebCoreMainResourceLoaderPolicyDelegate : NSObject
{
- self = [super init];
-
- if (self) {
- [self setFrameLoader:fl];
- proxy = wkCreateNSURLConnectionDelegateProxy();
- [proxy setDelegate:self];
- }
+ MainResourceLoader* m_loader;
+}
+- (id)initWithLoader:(MainResourceLoader *)loader;
+- (void)detachLoader;
+@end
- return self;
+namespace WebCore {
+
+const size_t URLBufferLength = 2048;
+
+MainResourceLoader::MainResourceLoader(WebFrameLoader *fl)
+ : WebResourceLoader(fl)
+ , m_contentLength(0)
+ , m_bytesReceived(0)
+ , m_proxy(wkCreateNSURLConnectionDelegateProxy())
+ , m_loadingMultipartContent(false)
+{
+ [m_proxy.get() setDelegate:delegate()];
}
-- (void)dealloc
+MainResourceLoader::~MainResourceLoader()
{
- [_initialRequest release];
+}
- [_response release];
- [proxy setDelegate:nil];
- [proxy release];
-
- [super dealloc];
+void MainResourceLoader::releaseDelegate()
+{
+ releasePolicyDelegate();
+ [m_proxy.get() setDelegate:nil];
+ WebResourceLoader::releaseDelegate();
}
-- (void)finalize
+PassRefPtr<MainResourceLoader> MainResourceLoader::create(WebFrameLoader *fl)
{
- [proxy setDelegate:nil];
- [super finalize];
+ return new MainResourceLoader(fl);
}
-- (void)receivedError:(NSError *)error
+void MainResourceLoader::receivedError(NSError *error)
{
- // Calling _receivedMainResourceError will likely result in a call to release, so we must retain.
- [self retain];
- WebFrameLoader *fl = [frameLoader retain]; // super's didFailWithError will release the frameLoader
+ // Calling _receivedMainResourceError will likely result in the last reference to this object to go away.
+ RefPtr<MainResourceLoader> protect(this);
- if (!cancelledFlag) {
- ASSERT(!reachedTerminalState);
- [frameLoader _didFailLoadingWithError:error forResource:identifier];
+ WebFrameLoader *fl = [frameLoader() retain]; // WebResourceLoader::didFailWithError will release the frameLoader
+
+ if (!cancelled()) {
+ ASSERT(!reachedTerminalState());
+ [fl _didFailLoadingWithError:error forResource:identifier()];
}
[fl _receivedMainResourceError:error complete:YES];
- if (!cancelledFlag)
- [self releaseResources];
+ if (!cancelled())
+ releaseResources();
- ASSERT(reachedTerminalState);
+ ASSERT(reachedTerminalState());
[fl release];
- [self release];
}
--(void)cancelWithError:(NSError *)error
+void MainResourceLoader::cancel(NSError *error)
{
- // Calling _receivedMainResourceError will likely result in a call to release, so we must retain.
- [self retain];
+ // Calling _receivedMainResourceError will likely result in the last reference to this class to go away.
+ RefPtr<MainResourceLoader> protect(this);
- [frameLoader cancelContentPolicy];
- [frameLoader retain];
- [frameLoader _receivedMainResourceError:error complete:YES];
- [frameLoader release];
- [super cancelWithError:error];
+ [frameLoader() cancelContentPolicy];
+ [frameLoader() retain];
+ [frameLoader() _receivedMainResourceError:error complete:YES];
+ [frameLoader() release];
- [self release];
+ WebResourceLoader::cancel(error);
}
-- (NSError *)interruptForPolicyChangeError
+NSError *MainResourceLoader::interruptionForPolicyChangeError() const
{
- return [frameLoader interruptForPolicyChangeErrorWithRequest:request];
+ return [frameLoader() interruptForPolicyChangeErrorWithRequest:request()];
}
--(void)stopLoadingForPolicyChange
+void MainResourceLoader::stopLoadingForPolicyChange()
{
- [self retain];
- [self cancelWithError:[self interruptForPolicyChangeError]];
- [self release];
+ cancel(interruptionForPolicyChangeError());
}
--(void)continueAfterNavigationPolicy:(NSURLRequest *)_request formState:(id)state
+void MainResourceLoader::continueAfterNavigationPolicy(NSURLRequest *r)
{
- if (!_request)
- [self stopLoadingForPolicyChange];
+ if (!r)
+ stopLoadingForPolicyChange();
}
-- (BOOL)_isPostOrRedirectAfterPost:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
+bool MainResourceLoader::isPostOrRedirectAfterPost(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
{
- BOOL result = NO;
-
- if ([[newRequest HTTPMethod] isEqualToString:@"POST"]) {
- result = YES;
- }
- else if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
+ if ([[newRequest HTTPMethod] isEqualToString:@"POST"])
+ return true;
+
+ if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
if (((status >= 301 && status <= 303) || status == 307)
- && [[[frameLoader initialRequest] HTTPMethod] isEqualToString:@"POST"]) {
- result = YES;
- }
+ && [[[frameLoader() initialRequest] HTTPMethod] isEqualToString:@"POST"])
+ return true;
}
- return result;
+ return false;
}
-- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce
+void MainResourceLoader::addData(NSData *data, bool allAtOnce)
{
- [super addData:data allAtOnce:allAtOnce];
- [frameLoader _receivedData:data];
+ WebResourceLoader::addData(data, allAtOnce);
+ [frameLoader() _receivedData:data];
}
-- (void)saveResource
-{
- // Override. We don't want to save the main resource as a subresource of the data source.
-}
-
-- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
+NSURLRequest *MainResourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
{
// Note that there are no asserts here as there are for the other callbacks. This is due to the
// fact that this "callback" is sent when starting every load, and the state of callback
// callbacks is meant to prevent.
ASSERT(newRequest != nil);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
+ // The additional processing can do anything including possibly removing the last
+ // reference to this object; one example of this is 3266216.
+ RefPtr<MainResourceLoader> protect(this);
NSURL *URL = [newRequest URL];
NSMutableURLRequest *mutableRequest = nil;
// Update cookie policy base URL as URL changes, except for subframes, which use the
// URL of the main frame which doesn't change when we redirect.
- if ([frameLoader isLoadingMainFrame]) {
+ if ([frameLoader() isLoadingMainFrame]) {
mutableRequest = [newRequest mutableCopy];
[mutableRequest setMainDocumentURL:URL];
}
// this is a common site technique to return to a page viewing some data that the POST
// just modified.
// Also, POST requests always load from origin, but this does not affect subresources.
- if ([newRequest cachePolicy] == NSURLRequestUseProtocolCachePolicy &&
- [self _isPostOrRedirectAfterPost:newRequest redirectResponse:redirectResponse]) {
- if (!mutableRequest) {
+ if ([newRequest cachePolicy] == NSURLRequestUseProtocolCachePolicy && isPostOrRedirectAfterPost(newRequest, redirectResponse)) {
+ if (!mutableRequest)
mutableRequest = [newRequest mutableCopy];
- }
[mutableRequest setCachePolicy:NSURLRequestReloadIgnoringCacheData];
}
- if (mutableRequest) {
+ if (mutableRequest)
newRequest = [mutableRequest autorelease];
- }
// Note super will make a copy for us, so reassigning newRequest is important. Since we are returning this value, but
// it's only guaranteed to be retained by self, and self might be dealloc'ed in this method, we have to autorelease.
// See 3777253 for an example.
- newRequest = [[[super willSendRequest:newRequest redirectResponse:redirectResponse] retain] autorelease];
+ newRequest = [[WebResourceLoader::willSendRequest(newRequest, redirectResponse) retain] autorelease];
- // Don't set this on the first request. It is set
- // when the main load was started.
- [frameLoader _setRequest:newRequest];
-
- [frameLoader _checkNavigationPolicyForRequest:newRequest andCall:self withSelector:@selector(continueAfterNavigationPolicy:formState:)];
+ // Don't set this on the first request. It is set when the main load was started.
+ [frameLoader() _setRequest:newRequest];
+
+ [frameLoader() _checkNavigationPolicyForRequest:newRequest
+ andCall:policyDelegate() withSelector:@selector(continueAfterNavigationPolicy:formState:)];
- [self release];
return newRequest;
}
-static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
+static bool isCaseInsensitiveEqual(NSString *a, NSString *b)
{
return [a caseInsensitiveCompare:b] == NSOrderedSame;
}
-#define URL_BYTES_BUFFER_LENGTH 2048
-
-static BOOL shouldLoadAsEmptyDocument(NSURL *url)
+static bool shouldLoadAsEmptyDocument(NSURL *url)
{
- UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH);
- CFIndex bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, URL_BYTES_BUFFER_LENGTH);
+ Vector<UInt8, URLBufferLength> buffer(URLBufferLength);
+ CFIndex bytesFilled = CFURLGetBytes((CFURLRef)url, buffer.data(), URLBufferLength);
if (bytesFilled == -1) {
CFIndex bytesToAllocate = CFURLGetBytes((CFURLRef)url, NULL, 0);
- buffer = (UInt8 *)realloc(buffer, bytesToAllocate);
- bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, bytesToAllocate);
+ buffer.resize(bytesToAllocate);
+ bytesFilled = CFURLGetBytes((CFURLRef)url, buffer.data(), bytesToAllocate);
ASSERT(bytesFilled == bytesToAllocate);
}
- BOOL result = (bytesFilled == 0) || (bytesFilled > 5 && strncmp((char *)buffer, "about:", 6) == 0);
- free(buffer);
-
- return result;
+ return (bytesFilled == 0) || (bytesFilled > 5 && strncmp((char *)buffer.data(), "about:", 6) == 0);
}
--(void)continueAfterContentPolicy:(WebPolicyAction)contentPolicy response:(NSURLResponse *)r
+void MainResourceLoader::continueAfterContentPolicy(WebPolicyAction contentPolicy, NSURLResponse *r)
{
- NSURL *URL = [request URL];
+ NSURL *URL = [request() URL];
NSString *MIMEType = [r MIMEType];
switch (contentPolicy) {
- case WebPolicyUse:
- {
+ case WebPolicyUse: {
// Prevent remote web archives from loading because they can claim to be from any domain and thus avoid cross-domain security checks (4120255).
- BOOL isRemote = ![URL isFileURL] && ![WebDataProtocol _webIsDataProtocolURL:URL];
- BOOL isRemoteWebArchive = isRemote && isCaseInsensitiveEqual(@"application/x-webarchive", MIMEType);
- if (![frameLoader _canShowMIMEType:MIMEType] || isRemoteWebArchive) {
- [frameLoader cannotShowMIMETypeWithResponse:r];
+ bool isRemote = ![URL isFileURL] && ![WebDataProtocol _webIsDataProtocolURL:URL];
+ bool isRemoteWebArchive = isRemote && isCaseInsensitiveEqual(@"application/x-webarchive", MIMEType);
+ if (![frameLoader() _canShowMIMEType:MIMEType] || isRemoteWebArchive) {
+ [frameLoader() cannotShowMIMETypeWithResponse:r];
// Check reachedTerminalState since the load may have already been cancelled inside of _handleUnimplementablePolicyWithErrorCode::.
- if (!reachedTerminalState) {
- [self stopLoadingForPolicyChange];
- }
+ if (!reachedTerminalState())
+ stopLoadingForPolicyChange();
return;
}
break;
}
case WebPolicyDownload:
- [proxy setDelegate:nil];
- [frameLoader _downloadWithLoadingConnection:connection request:request response:r proxy:proxy];
- [proxy release];
- proxy = nil;
-
- [self receivedError:[self interruptForPolicyChangeError]];
+ [m_proxy.get() setDelegate:nil];
+ [frameLoader() _downloadWithLoadingConnection:connection() request:request() response:r proxy:m_proxy.get()];
+ m_proxy = nil;
+ receivedError(interruptionForPolicyChangeError());
return;
case WebPolicyIgnore:
- [self stopLoadingForPolicyChange];
+ stopLoadingForPolicyChange();
return;
default:
ASSERT_NOT_REACHED();
}
- [self retain];
+ RefPtr<MainResourceLoader> protect(this);
if ([r isKindOfClass:[NSHTTPURLResponse class]]) {
int status = [(NSHTTPURLResponse *)r statusCode];
if (status < 200 || status >= 300) {
- BOOL hostedByObject = [frameLoader isHostedByObjectElement];
+ bool hostedByObject = [frameLoader() isHostedByObjectElement];
- [frameLoader _handleFallbackContent];
+ [frameLoader() _handleFallbackContent];
// object elements are no longer rendered after we fallback, so don't
// keep trying to process data from their load
if (hostedByObject)
- [self cancel];
+ cancel();
}
}
// we may have cancelled this load as part of switching to fallback content
- if (!reachedTerminalState) {
- [super didReceiveResponse:r];
- }
+ if (!reachedTerminalState())
+ WebResourceLoader::didReceiveResponse(r);
- if (![frameLoader _isStopping] && (shouldLoadAsEmptyDocument(URL) || [frameLoader _representationExistsForURLScheme:[URL scheme]])) {
- [self didFinishLoading];
- }
-
- [self release];
+ if (![frameLoader() _isStopping] && (shouldLoadAsEmptyDocument(URL) || [frameLoader() _representationExistsForURLScheme:[URL scheme]]))
+ didFinishLoading();
}
--(void)continueAfterContentPolicy:(WebPolicyAction)policy
+void MainResourceLoader::continueAfterContentPolicy(WebPolicyAction policy)
{
- BOOL isStopping = [frameLoader _isStopping];
-
- [frameLoader cancelContentPolicy];
+ bool isStopping = [frameLoader() _isStopping];
+ [frameLoader() cancelContentPolicy];
if (!isStopping)
- [self continueAfterContentPolicy:policy response:_response];
-}
-
--(void)checkContentPolicy
-{
- [frameLoader _checkContentPolicyForMIMEType:[_response MIMEType] andCall:self withSelector:@selector(continueAfterContentPolicy:)];
+ continueAfterContentPolicy(policy, m_response.get());
}
-- (void)didReceiveResponse:(NSURLResponse *)r
+void MainResourceLoader::didReceiveResponse(NSURLResponse *r)
{
- ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![self defersCallbacks]);
- ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![frameLoader defersCallbacks]);
+ ASSERT(shouldLoadAsEmptyDocument([r URL]) || !defersCallbacks());
+ ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![frameLoader() defersCallbacks]);
- if (loadingMultipartContent) {
- [frameLoader _setupForReplaceByMIMEType:[r MIMEType]];
- [self clearResourceData];
+ if (m_loadingMultipartContent) {
+ [frameLoader() _setupForReplaceByMIMEType:[r MIMEType]];
+ clearResourceData();
}
if ([[r MIMEType] isEqualToString:@"multipart/x-mixed-replace"])
- loadingMultipartContent = YES;
+ m_loadingMultipartContent = true;
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- [frameLoader _setResponse:r];
- _contentLength = (int)[r expectedContentLength];
-
- _response = [r retain];
- [self checkContentPolicy];
- [self release];
+ // The additional processing can do anything including possibly removing the last
+ // reference to this object; one example of this is 3266216.
+ RefPtr<MainResourceLoader> protect(this);
+
+ [frameLoader() _setResponse:r];
+ m_contentLength = (int)[r expectedContentLength];
+
+ m_response = r;
+ [frameLoader() _checkContentPolicyForMIMEType:[m_response.get() MIMEType]
+ andCall:policyDelegate() withSelector:@selector(continueAfterContentPolicy:)];
}
-- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
+void MainResourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
{
ASSERT(data);
ASSERT([data length] != 0);
- ASSERT(![self defersCallbacks]);
- ASSERT(![frameLoader defersCallbacks]);
+ ASSERT(!defersCallbacks());
+ ASSERT(![frameLoader() defersCallbacks]);
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
-
- [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:allAtOnce];
- _bytesReceived += [data length];
+ // The additional processing can do anything including possibly removing the last
+ // reference to this object; one example of this is 3266216.
+ RefPtr<MainResourceLoader> protect(this);
- [self release];
+ WebResourceLoader::didReceiveData(data, lengthReceived, allAtOnce);
+ m_bytesReceived += [data length];
}
-- (void)didFinishLoading
+void MainResourceLoader::didFinishLoading()
{
- ASSERT(shouldLoadAsEmptyDocument([frameLoader _URL]) || ![self defersCallbacks]);
- ASSERT(shouldLoadAsEmptyDocument([frameLoader _URL]) || ![frameLoader defersCallbacks]);
-
- // Calls in this method will most likely result in a call to release, so we must retain.
- [self retain];
+ ASSERT(shouldLoadAsEmptyDocument([frameLoader() _URL]) || !defersCallbacks());
+ ASSERT(shouldLoadAsEmptyDocument([frameLoader() _URL]) || ![frameLoader() defersCallbacks]);
- [frameLoader _finishedLoading];
- [super didFinishLoading];
+ // The additional processing can do anything including possibly removing the last
+ // reference to this object.
+ RefPtr<MainResourceLoader> protect(this);
- [self release];
+ [frameLoader() _finishedLoading];
+ WebResourceLoader::didFinishLoading();
}
-- (void)didFailWithError:(NSError *)error
+void MainResourceLoader::didFail(NSError *error)
{
- ASSERT(![self defersCallbacks]);
- ASSERT(![frameLoader defersCallbacks]);
+ ASSERT(!defersCallbacks());
+ ASSERT(![frameLoader() defersCallbacks]);
- [self receivedError:error];
+ receivedError(error);
}
-- (NSURLRequest *)loadWithRequestNow:(NSURLRequest *)r
+NSURLRequest *MainResourceLoader::loadNow(NSURLRequest *r)
{
- BOOL shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument([r URL]);
+ bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument([r URL]);
- ASSERT(connection == nil);
- ASSERT(shouldLoadEmptyBeforeRedirect || ![self defersCallbacks]);
- ASSERT(shouldLoadEmptyBeforeRedirect || ![frameLoader defersCallbacks]);
+ ASSERT(!connection());
+ ASSERT(shouldLoadEmptyBeforeRedirect || !defersCallbacks());
+ ASSERT(shouldLoadEmptyBeforeRedirect || ![frameLoader() defersCallbacks]);
// Send this synthetic delegate callback since clients expect it, and
// we no longer send the callback from within NSURLConnection for
// initial requests.
- r = [self willSendRequest:r redirectResponse:nil];
+ r = willSendRequest(r, nil);
NSURL *URL = [r URL];
- BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
+ bool shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
- if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && [self defersCallbacks]) {
+ if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersCallbacks())
return r;
- }
- if (shouldLoadEmpty || [frameLoader _representationExistsForURLScheme:[URL scheme]]) {
+ if (shouldLoadEmpty || [frameLoader() _representationExistsForURLScheme:[URL scheme]]) {
NSString *MIMEType;
- if (shouldLoadEmpty) {
+ if (shouldLoadEmpty)
MIMEType = @"text/html";
- } else {
- MIMEType = [frameLoader _generatedMIMETypeForURLScheme:[URL scheme]];
- }
+ else
+ MIMEType = [frameLoader() _generatedMIMETypeForURLScheme:[URL scheme]];
NSURLResponse *resp = [[NSURLResponse alloc] initWithURL:URL MIMEType:MIMEType
expectedContentLength:0 textEncodingName:nil];
- [self didReceiveResponse:resp];
+ didReceiveResponse(resp);
[resp release];
} else {
- connection = [[NSURLConnection alloc] initWithRequest:r delegate:proxy];
+ NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:r delegate:m_proxy.get()];
+ m_connection = conn;
+ [conn release];
}
return nil;
}
-- (BOOL)loadWithRequest:(NSURLRequest *)r
+bool MainResourceLoader::load(NSURLRequest *r)
{
- ASSERT(connection == nil);
+ ASSERT(!connection());
- BOOL defer = [self defersCallbacks];
+ bool defer = defersCallbacks();
if (defer) {
- NSURL *URL = [r URL];
- BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
- if (shouldLoadEmpty) {
- defer = NO;
- }
+ bool shouldLoadEmpty = shouldLoadAsEmptyDocument([r URL]);
+ if (shouldLoadEmpty)
+ defer = false;
}
if (!defer) {
- r = [self loadWithRequestNow:r];
- if (r != nil) {
+ r = loadNow(r);
+ if (r) {
// Started as an empty document, but was redirected to something non-empty.
- ASSERT([self defersCallbacks]);
- defer = YES;
+ ASSERT(defersCallbacks());
+ defer = true;
}
}
if (defer) {
NSURLRequest *copy = [r copy];
- [_initialRequest release];
- _initialRequest = copy;
+ m_initialRequest = copy;
+ [copy release];
}
- return YES;
+ return true;
}
-- (void)setDefersCallbacks:(BOOL)defers
+void MainResourceLoader::setDefersCallbacks(bool defers)
{
- [super setDefersCallbacks:defers];
+ WebResourceLoader::setDefersCallbacks(defers);
if (!defers) {
- NSURLRequest *r = _initialRequest;
- if (r != nil) {
- _initialRequest = nil;
- [self loadWithRequestNow:r];
- [r release];
+ RetainPtr<NSURLRequest> r = m_initialRequest;
+ if (r) {
+ m_initialRequest = nil;
+ loadNow(r.get());
}
}
}
+WebCoreMainResourceLoaderPolicyDelegate *MainResourceLoader::policyDelegate()
+{
+ if (!m_policyDelegate) {
+ WebCoreMainResourceLoaderPolicyDelegate *d = [[WebCoreMainResourceLoaderPolicyDelegate alloc] initWithLoader:this];
+ m_policyDelegate = d;
+ [d release];
+ }
+ return m_policyDelegate.get();
+}
+
+void MainResourceLoader::releasePolicyDelegate()
+{
+ if (!m_policyDelegate)
+ return;
+ [m_policyDelegate.get() detachLoader];
+ m_policyDelegate = nil;
+}
+
+}
+
+@implementation WebCoreMainResourceLoaderPolicyDelegate
+
+- (id)initWithLoader:(MainResourceLoader*)loader
+{
+ self = [self init];
+ if (!self)
+ return nil;
+ m_loader = loader;
+ return self;
+}
+
+- (void)detachLoader
+{
+ m_loader = nil;
+}
+
+- (void)continueAfterNavigationPolicy:(NSURLRequest *)request formState:(id)formState
+{
+ if (!m_loader)
+ return;
+ m_loader->continueAfterNavigationPolicy(request);
+}
+
+- (void)continueAfterContentPolicy:(WebPolicyAction)policy
+{
+ if (!m_loader)
+ return;
+ m_loader->continueAfterContentPolicy(policy);
+}
+
@end
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "WebLoader.h"
#import "WebPlugInStreamLoaderDelegate.h"
+#import <wtf/Forward.h>
-@class WebNetscapePluginStream;
+namespace WebCore {
+
+ class NetscapePlugInStreamLoader : public WebResourceLoader {
+ public:
+ static PassRefPtr<NetscapePlugInStreamLoader> create(WebFrameLoader*, id <WebPlugInStreamLoaderDelegate>);
+ virtual ~NetscapePlugInStreamLoader();
+
+ bool isDone() const;
+
+ virtual void didReceiveResponse(NSURLResponse *);
+ virtual void didReceiveData(NSData *, long long lengthReceived, bool allAtOnce);
+ virtual void didFinishLoading();
+ virtual void didFail(NSError *);
+ virtual void cancel(NSError *);
+
+ virtual void releaseResources();
+
+ private:
+ NetscapePlugInStreamLoader(WebFrameLoader*, id <WebPlugInStreamLoaderDelegate>);
+
+ RetainPtr<id <WebPlugInStreamLoaderDelegate> > m_stream;
+ };
-@interface WebNetscapePlugInStreamLoader : WebLoader
-{
- NSObject<WebPlugInStreamLoaderDelegate> *stream;
}
-- (id)initWithDelegate:(NSObject <WebPlugInStreamLoaderDelegate> *)theStream frameLoader:(WebFrameLoader *)fl;
-- (BOOL)isDone;
-@end
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "WebNetscapePlugInStreamLoader.h"
#import "WebFrameLoader.h"
+#import <wtf/PassRefPtr.h>
-@implementation WebNetscapePlugInStreamLoader
+namespace WebCore {
-- (id)initWithDelegate:(NSObject<WebPlugInStreamLoaderDelegate> *)theStream frameLoader:(WebFrameLoader *)fl;
+NetscapePlugInStreamLoader::NetscapePlugInStreamLoader(WebFrameLoader *fl, id <WebPlugInStreamLoaderDelegate> stream)
+ : WebResourceLoader(fl)
+ , m_stream(stream)
{
- [super init];
- stream = [theStream retain];
- [self setFrameLoader:fl];
- return self;
}
-- (BOOL)isDone
+NetscapePlugInStreamLoader::~NetscapePlugInStreamLoader()
{
- return stream == nil;
}
-- (void)releaseResources
+PassRefPtr<NetscapePlugInStreamLoader> NetscapePlugInStreamLoader::create(WebFrameLoader* fl, id <WebPlugInStreamLoaderDelegate> d)
{
- [stream release];
- stream = nil;
- [super releaseResources];
+ return new NetscapePlugInStreamLoader(fl, d);
}
-- (void)didReceiveResponse:(NSURLResponse *)theResponse
+bool NetscapePlugInStreamLoader::isDone() const
{
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- [stream startStreamWithResponse:theResponse];
-
- // Don't continue if the stream is cancelled in startStreamWithResponse or didReceiveResponse.
- if (stream) {
- [super didReceiveResponse:theResponse];
- if (stream) {
- if ([theResponse isKindOfClass:[NSHTTPURLResponse class]] &&
- ([(NSHTTPURLResponse *)theResponse statusCode] >= 400 || [(NSHTTPURLResponse *)theResponse statusCode] < 100)) {
- NSError *error = [frameLoader fileDoesNotExistErrorWithResponse:theResponse];
- [stream cancelLoadAndDestroyStreamWithError:error];
- }
- }
- }
- [self release];
+ return !m_stream;
}
-- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
+void NetscapePlugInStreamLoader::releaseResources()
{
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- [stream receivedData:data];
- [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:(BOOL)allAtOnce];
- [self release];
+ m_stream = nil;
+ WebResourceLoader::releaseResources();
}
-- (void)didFinishLoading
+void NetscapePlugInStreamLoader::didReceiveResponse(NSURLResponse *theResponse)
{
- // Calling _removePlugInStreamLoader will likely result in a call to release, so we must retain.
- [self retain];
-
- [frameLoader removePlugInStreamLoader:self];
- [frameLoader _finishedLoadingResource];
- [stream finishedLoadingWithData:[self resourceData]];
- [super didFinishLoading];
+ // Protect self in this delegate method since the additional processing can do
+ // anything including possibly getting rid of the last reference to this object.
+ // One example of this is Radar 3266216.
+ RefPtr<NetscapePlugInStreamLoader> protect(this);
- [self release];
+ [m_stream.get() startStreamWithResponse:theResponse];
+
+ // Don't continue if the stream is cancelled in startStreamWithResponse or didReceiveResponse.
+ if (!m_stream)
+ return;
+ WebResourceLoader::didReceiveResponse(theResponse);
+ if (!m_stream)
+ return;
+ if ([theResponse isKindOfClass:[NSHTTPURLResponse class]] &&
+ ([(NSHTTPURLResponse *)theResponse statusCode] >= 400 || [(NSHTTPURLResponse *)theResponse statusCode] < 100)) {
+ NSError *error = [frameLoader() fileDoesNotExistErrorWithResponse:theResponse];
+ [m_stream.get() cancelLoadAndDestroyStreamWithError:error];
+ }
}
-- (void)didFailWithError:(NSError *)error
+void NetscapePlugInStreamLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
{
- // Calling _removePlugInStreamLoader will likely result in a call to release, so we must retain.
- // The other additional processing can do anything including possibly releasing self;
- // one example of this is 3266216
- [self retain];
+ // Protect self in this delegate method since the additional processing can do
+ // anything including possibly getting rid of the last reference to this object.
+ // One example of this is Radar 3266216.
+ RefPtr<NetscapePlugInStreamLoader> protect(this);
- [[self frameLoader] removePlugInStreamLoader:self];
- [[self frameLoader] _receivedError:error];
- [stream destroyStreamWithError:error];
- [super didFailWithError:error];
+ [m_stream.get() receivedData:data];
+ WebResourceLoader::didReceiveData(data, lengthReceived, allAtOnce);
+}
+
+void NetscapePlugInStreamLoader::didFinishLoading()
+{
+ // Calling removePlugInStreamLoader will likely result in a call to deref, so we must protect.
+ RefPtr<NetscapePlugInStreamLoader> protect(this);
- [self release];
+ [frameLoader() removePlugInStreamLoader:this];
+ [frameLoader() _finishedLoadingResource];
+ [m_stream.get() finishedLoadingWithData:resourceData()];
+ WebResourceLoader::didFinishLoading();
}
-- (void)cancelWithError:(NSError *)error
+void NetscapePlugInStreamLoader::didFail(NSError *error)
{
- // Calling _removePlugInStreamLoader will likely result in a call to release, so we must retain.
- [self retain];
+ // Protect self in this delegate method since the additional processing can do
+ // anything including possibly getting rid of the last reference to this object.
+ // One example of this is Radar 3266216.
+
+ [frameLoader() removePlugInStreamLoader:this];
+ [frameLoader() _receivedError:error];
+ [m_stream.get() destroyStreamWithError:error];
+ WebResourceLoader::didFail(error);
+}
- [[self frameLoader] removePlugInStreamLoader:self];
- [stream destroyStreamWithError:error];
- [super cancelWithError:error];
+void NetscapePlugInStreamLoader::cancel(NSError *error)
+{
+ // Calling removePlugInStreamLoader will likely result in a call to deref, so we must protect.
+ RefPtr<NetscapePlugInStreamLoader> protect(this);
- [self release];
+ [frameLoader() removePlugInStreamLoader:this];
+ [m_stream.get() destroyStreamWithError:error];
+ WebResourceLoader::cancel(error);
}
-@end
+}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
*/
#import "WebLoader.h"
-
#import "WebCoreResourceLoader.h"
-@class WebFrameLoader;
+namespace WebCore {
-@protocol WebCoreResourceHandle;
-@protocol WebCoreResourceLoader;
+ class SubresourceLoader : public WebResourceLoader {
+ public:
+ static id <WebCoreResourceHandle> create(WebFrameLoader *, id <WebCoreResourceLoader>,
+ NSString *method, NSURL *URL, NSDictionary *customHeaders, NSString *referrer);
+ static id <WebCoreResourceHandle> create(WebFrameLoader *, id <WebCoreResourceLoader>,
+ NSString *method, NSURL *URL, NSDictionary *customHeaders, NSArray *postData, NSString *referrer);
-@interface WebSubresourceLoader : WebLoader <WebCoreResourceHandle>
-{
- id <WebCoreResourceLoader> coreLoader;
-}
+ virtual ~SubresourceLoader();
+
+ virtual void signalFinish();
+ virtual void cancel();
-- (void)signalFinish;
+ virtual NSURLRequest *willSendRequest(NSURLRequest *, NSURLResponse *redirectResponse);
+ virtual void didReceiveResponse(NSURLResponse *);
+ virtual void didReceiveData(NSData *, long long lengthReceived, bool allAtOnce);
+ virtual void didFinishLoading();
+ virtual void didFail(NSError *);
-+ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
- withMethod:(NSString *)method
- URL:(NSURL *)URL
- customHeaders:(NSDictionary *)customHeaders
- referrer:(NSString *)referrer
- forFrameLoader:(WebFrameLoader *)loader;
+ private:
+ static id <WebCoreResourceHandle> create(WebFrameLoader *, id <WebCoreResourceLoader>,
+ NSMutableURLRequest *, NSString *method, NSDictionary *customHeaders, NSString *referrer);
-+ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
- withMethod:(NSString *)method
- URL:(NSURL *)URL
- customHeaders:(NSDictionary *)customHeaders
- postData:(NSArray *)postData
- referrer:(NSString *)referrer
- forFrameLoader:(WebFrameLoader *)loader;
+ SubresourceLoader(WebFrameLoader *, id <WebCoreResourceLoader>);
+ id <WebCoreResourceHandle> handle();
-@end
+ void receivedError(NSError *error);
+
+ RetainPtr<id <WebCoreResourceLoader> > m_coreLoader;
+ bool m_loadingMultipartContent;
+ };
+
+}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import "LoaderNSURLExtras.h"
#import "LoaderNSURLRequestExtras.h"
+#import "WebCoreResourceLoader.h"
+#import "WebCoreSystemInterface.h"
#import "WebFormDataStream.h"
#import "WebFrameLoader.h"
#import <Foundation/NSURLResponse.h>
#import <wtf/Assertions.h>
-#import "WebCoreResourceLoader.h"
-#import "WebCoreSystemInterface.h"
-@implementation WebSubresourceLoader
+using namespace WebCore;
-- initWithLoader:(id <WebCoreResourceLoader>)l frameLoader:(WebFrameLoader *)fl
+@interface WebCoreSubresourceHandle : NSObject <WebCoreResourceHandle>
{
- [super init];
-
- coreLoader = [l retain];
+ SubresourceLoader* m_loader;
+}
+- (id)initWithLoader:(SubresourceLoader*)loader;
+@end
- [self setFrameLoader:fl];
-
- return self;
+namespace WebCore {
+
+SubresourceLoader::SubresourceLoader(WebFrameLoader *fl, id <WebCoreResourceLoader> l)
+ : WebResourceLoader(fl)
+ , m_coreLoader(l)
+ , m_loadingMultipartContent(false)
+{
+ [fl addSubresourceLoader:this];
}
-- (void)dealloc
+SubresourceLoader::~SubresourceLoader()
{
- [coreLoader release];
- [super dealloc];
}
-+ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
- withRequest:(NSMutableURLRequest *)newRequest
- customHeaders:(NSDictionary *)customHeaders
- referrer:(NSString *)referrer
- forFrameLoader:(WebFrameLoader *)fl
+id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
+ NSMutableURLRequest *newRequest, NSString *method, NSDictionary *customHeaders, NSString *referrer)
{
if ([fl state] == WebFrameStateProvisional)
return nil;
-
- wkSupportsMultipartXMixedReplace(newRequest);
- WebSubresourceLoader *loader = [[[self alloc] initWithLoader:rLoader frameLoader:fl] autorelease];
-
- [fl addSubresourceLoader:loader];
+ // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
+ if (![method isEqualToString:@"GET"])
+ [newRequest setHTTPMethod:method];
+
+ wkSupportsMultipartXMixedReplace(newRequest);
NSEnumerator *e = [customHeaders keyEnumerator];
NSString *key;
setHTTPReferrer(newRequest, referrer);
[fl addExtraFieldsToRequest:newRequest mainResource:NO alwaysFromRequest:NO];
-
- if (![loader loadWithRequest:newRequest])
- loader = nil;
-
- return loader;
+
+ RefPtr<SubresourceLoader> loader(new SubresourceLoader(fl, rLoader));
+ if (!loader->load(newRequest))
+ return nil;
+ return loader->handle();
}
-+ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
- withMethod:(NSString *)method
- URL:(NSURL *)URL
- customHeaders:(NSDictionary *)customHeaders
- referrer:(NSString *)referrer
- forFrameLoader:(WebFrameLoader *)fl
+id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
+ NSString *method, NSURL *URL, NSDictionary *customHeaders, NSString *referrer)
{
NSMutableURLRequest *newRequest = [[NSMutableURLRequest alloc] initWithURL:URL];
-
- // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
- if (![method isEqualToString:@"GET"])
- [newRequest setHTTPMethod:method];
-
- WebSubresourceLoader *loader = [self startLoadingResource:rLoader withRequest:newRequest customHeaders:customHeaders referrer:referrer forFrameLoader:fl];
+ id <WebCoreResourceHandle> handle = create(fl, rLoader, newRequest, method, customHeaders, referrer);
[newRequest release];
-
- return loader;
+ return handle;
}
-+ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
- withMethod:(NSString *)method
- URL:(NSURL *)URL
- customHeaders:(NSDictionary *)customHeaders
- postData:(NSArray *)postData
- referrer:(NSString *)referrer
- forFrameLoader:(WebFrameLoader *)fl
+id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
+ NSString *method, NSURL *URL, NSDictionary *customHeaders, NSArray *postData, NSString *referrer)
{
NSMutableURLRequest *newRequest = [[NSMutableURLRequest alloc] initWithURL:URL];
-
- // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
- if (![method isEqualToString:@"GET"])
- [newRequest setHTTPMethod:method];
-
webSetHTTPBody(newRequest, postData);
-
- WebSubresourceLoader *loader = [self startLoadingResource:rLoader withRequest:newRequest customHeaders:customHeaders referrer:referrer forFrameLoader:fl];
+ id <WebCoreResourceHandle> handle = create(fl, rLoader, newRequest, method, customHeaders, referrer);
[newRequest release];
-
- return loader;
-
+ return handle;
}
-- (void)receivedError:(NSError *)error
+void SubresourceLoader::receivedError(NSError *error)
{
- [frameLoader _receivedError:error];
+ [frameLoader() _receivedError:error];
}
-- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse;
+NSURLRequest *SubresourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
{
- NSURL *oldURL = [request URL];
- NSURLRequest *clientRequest = [super willSendRequest:newRequest redirectResponse:redirectResponse];
-
- if (clientRequest != nil && oldURL != [clientRequest URL] && ![oldURL isEqual:[clientRequest URL]])
- [coreLoader redirectedToURL:[clientRequest URL]];
-
+ NSURL *oldURL = [request() URL];
+ NSURLRequest *clientRequest = WebResourceLoader::willSendRequest(newRequest, redirectResponse);
+ if (clientRequest && oldURL != [clientRequest URL] && ![oldURL isEqual:[clientRequest URL]])
+ [m_coreLoader.get() redirectedToURL:[clientRequest URL]];
return clientRequest;
}
-- (void)didReceiveResponse:(NSURLResponse *)r
+void SubresourceLoader::didReceiveResponse(NSURLResponse *r)
{
ASSERT(r);
if ([[r MIMEType] isEqualToString:@"multipart/x-mixed-replace"])
- loadingMultipartContent = YES;
+ m_loadingMultipartContent = true;
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
- [coreLoader receivedResponse:r];
+ // Reference the object in this method since the additional processing can do
+ // anything including removing the last reference to this object; one example of this is 3266216.
+ RefPtr<SubresourceLoader> protect(this);
+
+ [m_coreLoader.get() receivedResponse:r];
// The coreLoader can cancel a load if it receives a multipart response for a non-image
- if (reachedTerminalState) {
- [self release];
+ if (reachedTerminalState())
return;
- }
- [super didReceiveResponse:r];
- [self release];
+ WebResourceLoader::didReceiveResponse(r);
- if (loadingMultipartContent && [[self resourceData] length]) {
+ if (m_loadingMultipartContent && [resourceData() length]) {
// A subresource loader does not load multipart sections progressively, deliver the previously received data to the coreLoader all at once
- [coreLoader addData:[self resourceData]];
+ [m_coreLoader.get() addData:resourceData()];
+
// Clears the data to make way for the next multipart section
- [self clearResourceData];
+ clearResourceData();
// After the first multipart section is complete, signal to delegates that this load is "finished"
- if (!signalledFinish)
- [self signalFinish];
+ if (!signalledFinish())
+ signalFinish();
}
}
-- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
+void SubresourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
{
- // retain/release self in this delegate method since the additional processing can do
- // anything including possibly releasing self; one example of this is 3266216
- [self retain];
+ // Reference the object in this method since the additional processing can do
+ // anything including removing the last reference to this object; one example of this is 3266216.
+ RefPtr<SubresourceLoader> protect(this);
+
// A subresource loader does not load multipart sections progressively, don't deliver any data to the coreLoader yet
- if (!loadingMultipartContent)
- [coreLoader addData:data];
- [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:allAtOnce];
- [self release];
+ if (!m_loadingMultipartContent)
+ [m_coreLoader.get() addData:data];
+ WebResourceLoader::didReceiveData(data, lengthReceived, allAtOnce);
}
-- (void)signalFinish
+void SubresourceLoader::signalFinish()
{
- [frameLoader removeSubresourceLoader:self];
- [frameLoader _finishedLoadingResource];
- [super signalFinish];
+ [frameLoader() removeSubresourceLoader:this];
+ [frameLoader() _finishedLoadingResource];
+ WebResourceLoader::signalFinish();
}
-- (void)didFinishLoading
+void SubresourceLoader::didFinishLoading()
{
- // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
- [self retain];
+ // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
+ RefPtr<SubresourceLoader> protect(this);
- [coreLoader finishWithData:[self resourceData]];
+ [m_coreLoader.get() finishWithData:resourceData()];
- if (!signalledFinish)
- [self signalFinish];
+ if (!signalledFinish())
+ signalFinish();
- [super didFinishLoading];
-
- [self release];
+ WebResourceLoader::didFinishLoading();
}
-- (void)didFailWithError:(NSError *)error
+void SubresourceLoader::didFail(NSError *error)
{
- // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
- [self retain];
+ // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
+ RefPtr<SubresourceLoader> protect(this);
- [coreLoader reportError];
- [frameLoader removeSubresourceLoader:self];
- [self receivedError:error];
- [super didFailWithError:error];
-
- [self release];
+ [m_coreLoader.get() reportError];
+ [frameLoader() removeSubresourceLoader:this];
+ receivedError(error);
+ WebResourceLoader::didFail(error);
}
-- (void)cancel
+void SubresourceLoader::cancel()
{
- // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
- [self retain];
+ // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
+ RefPtr<SubresourceLoader> protect(this);
- [coreLoader cancel];
- [frameLoader removeSubresourceLoader:self];
- [self receivedError:[self cancelledError]];
- [super cancel];
+ [m_coreLoader.get() cancel];
+ [frameLoader() removeSubresourceLoader:this];
+ receivedError(cancelledError());
+ WebResourceLoader::cancel();
+}
+
+id <WebCoreResourceHandle> SubresourceLoader::handle()
+{
+ return [[[WebCoreSubresourceHandle alloc] initWithLoader:this] autorelease];
+}
+
+}
+
+@implementation WebCoreSubresourceHandle
- [self release];
+- (id)initWithLoader:(SubresourceLoader*)loader
+{
+ self = [self init];
+ if (!self)
+ return nil;
+ loader->ref();
+ m_loader = loader;
+ return self;
+}
+
+- (void)dealloc
+{
+ m_loader->deref();
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ m_loader->deref();
+ [super finalize];
+}
+
+- (void)cancel
+{
+ m_loader->cancel();
}
@end
#include <algorithm>
#include <CoreFoundation/CoreFoundation.h>
-namespace WTF {
+namespace WebCore {
template <typename T> struct RemovePointer {
typedef T type;
return p.get();
}
-} // namespace WTF
-
-using WTF::RetainPtr;
-using WTF::static_pointer_cast;
-using WTF::const_pointer_cast;
+}
#endif // RETAINPTR_H_
+2006-10-20 Darin Adler <darin@apple.com>
+
+ Reviewed by Adele.
+
+ - convert WebLoader and its 3 subclasses to C++
+
+ * Plugins/WebNetscapePluginStream.h:
+ * Plugins/WebNetscapePluginStream.m:
+ (-[WebNetscapePluginStream dealloc]):
+ (-[WebNetscapePluginStream finalize]):
+ (-[WebNetscapePluginStream start]):
+ (-[WebNetscapePluginStream cancelLoadWithError:]):
+ (-[WebNetscapePluginStream stop]):
+ * WebCoreSupport/WebFrameBridge.m:
+ (-[WebFrameBridge canRunModalNow]):
+ * WebView/WebFrame.m:
+ (-[WebFramePrivate dealloc]):
+ (-[WebFramePrivate finalize]):
+ (frame): Changed from uppercase to lowercase so that it won't conflict
+ with the WebCore class named Frame.
+ (-[WebFrame _firstChildFrame]):
+ (-[WebFrame _lastChildFrame]):
+ (-[WebFrame _previousSiblingFrame]):
+ (-[WebFrame _nextSiblingFrame]):
+ (-[WebFrame _traverseNextFrameStayWithin:]):
+ (-[WebFrame _immediateChildFrameNamed:]):
+ (-[WebFrame _nextFrameWithWrap:]):
+ (-[WebFrame _previousFrameWithWrap:]):
+ (-[WebFrame findFrameNamed:]):
+ (-[WebFrame parentFrame]):
+ (-[WebFrame _dispatchSourceFrame:willSubmitForm:withValues:submissionDecider:]):
+ (-[WebFrame _deliverArchivedResourcesAfterDelay]):
+ (-[WebFrame _willUseArchiveForRequest:originalURL:loader:]):
+ (-[WebFrame _archiveLoadPendingForLoader:]):
+ (-[WebFrame _cancelPendingArchiveLoadForLoader:]):
+ (-[WebFrame _clearArchivedResources]):
+ (-[WebFrame _deliverArchivedResources]):
+
2006-10-20 John Sullivan <sullivan@apple.com>
Reviewed by Darin
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
*/
#import <Foundation/Foundation.h>
-
-#import <WebKit/npapi.h>
#import <WebKit/WebBaseNetscapePluginStream.h>
+#import <WebKit/npapi.h>
+
+#if __cplusplus
+namespace WebCore {
+ class NetscapePlugInStreamLoader;
+}
+typedef WebCore::NetscapePlugInStreamLoader WebCoreNetscapePlugInStreamLoader;
+#else
+@class WebCoreNetscapePlugInStreamLoader;
+#endif
@class NSURLRequest;
@class NSURLConnection;
-@class WebNetscapePlugInStreamLoader;
-
@interface WebNetscapePluginStream : WebBaseNetscapePluginStream
{
- WebNetscapePlugInStreamLoader *_loader;
+ WebCoreNetscapePlugInStreamLoader *_loader;
NSURLRequest *request;
}
/*
- * Copyright (C) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
#import <WebKit/WebNetscapePluginStream.h>
-#import <WebKit/WebFrameBridge.h>
+#import <Foundation/NSURLConnection.h>
+#import <WebCore/WebFrameLoader.h>
+#import <WebCore/WebNetscapePlugInStreamLoader.h>
#import <WebKit/WebDataSourceInternal.h>
+#import <WebKit/WebFrameBridge.h>
#import <WebKit/WebFrameInternal.h>
#import <WebKit/WebKitErrorsPrivate.h>
#import <WebKit/WebKitLogging.h>
+#import <WebKit/WebNSURLRequestExtras.h>
#import <WebKit/WebNetscapePluginEmbeddedView.h>
#import <WebKit/WebNetscapePluginPackage.h>
-#import <WebCore/WebNetscapePlugInStreamLoader.h>
-#import <WebKit/WebNSURLRequestExtras.h>
#import <WebKit/WebViewInternal.h>
-#import <WebCore/WebFrameLoader.h>
+#import <wtf/PassRefPtr.h>
-#import <Foundation/NSURLConnection.h>
+using namespace WebCore;
@implementation WebNetscapePluginStream
isTerminated = YES;
request = [theRequest mutableCopy];
- if (hideReferrer) {
+ if (hideReferrer)
[(NSMutableURLRequest *)request _web_setHTTPReferrer:nil];
- }
- _loader = [[WebNetscapePlugInStreamLoader alloc] initWithDelegate:self frameLoader:[[view webFrame] _frameLoader]];
+ _loader = NetscapePlugInStreamLoader::create([[view webFrame] _frameLoader], self).release();
isTerminated = NO;
- (void)dealloc
{
- [_loader release];
+ if (_loader)
+ _loader->deref();
[request release];
[super dealloc];
}
+- (void)finalize
+{
+ if (_loader)
+ _loader->deref();
+ [super finalize];
+}
+
- (void)start
{
ASSERT(request);
- [[_loader frameLoader] addPlugInStreamLoader:_loader];
+ [_loader->frameLoader() addPlugInStreamLoader:_loader];
- BOOL succeeded = [_loader loadWithRequest:request];
- if (!succeeded) {
- [[_loader frameLoader] removePlugInStreamLoader:_loader];
- }
+ if (!_loader->load(request))
+ [_loader->frameLoader() removePlugInStreamLoader:_loader];
}
- (void)cancelLoadWithError:(NSError *)error
{
- if (![_loader isDone]) {
- [_loader cancelWithError:error];
- }
+ if (!_loader->isDone())
+ _loader->cancel(error);
}
- (void)stop
{
- [self cancelLoadAndDestroyStreamWithError:[_loader cancelledError]];
+ [self cancelLoadAndDestroyStreamWithError:_loader->cancelledError()];
}
@end
- (jobject)pollForAppletInWindow:(NSWindow *)window;
@end
+using namespace WebCore;
+
NSString *WebPluginBaseURLKey = @"WebPluginBaseURL";
NSString *WebPluginAttributesKey = @"WebPluginAttributes";
NSString *WebPluginContainerKey = @"WebPluginContainer";
- (BOOL)canRunModalNow
{
- return [self canRunModal] && ![WebLoader inConnectionCallback];
+ return [self canRunModal] && !WebResourceLoader::inConnectionCallback();
}
- (void)runModal
#import <WebKit/DOM.h>
#import <WebKitSystemInterface.h>
#import <objc/objc-runtime.h>
+#import <wtf/HashMap.h>
/*
Here is the current behavior matrix for four types of navigations:
Add to back/forward list: NO
*/
+using namespace WebCore;
+
+typedef HashMap<RefPtr<WebResourceLoader>, RetainPtr<WebResource> > ResourceMap;
+
NSString *WebPageCacheEntryDateKey = @"WebPageCacheEntryDateKey";
NSString *WebPageCacheDataSourceKey = @"WebPageCacheDataSourceKey";
NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
NSMutableSet *plugInViews;
NSMutableSet *inspectors;
- NSMutableDictionary *pendingArchivedResources;
+ ResourceMap* pendingArchivedResources;
}
- (void)setWebFrameView:(WebFrameView *)v;
ASSERT(plugInViews == nil);
[inspectors release];
- [pendingArchivedResources release];
+ delete pendingArchivedResources;
[super dealloc];
}
+- (void)finalize
+{
+ delete pendingArchivedResources;
+
+ [super finalize];
+}
+
- (void)setWebFrameView:(WebFrameView *)v
{
[v retain];
@end
-static inline WebFrame *Frame(WebCoreFrameBridge *bridge)
+static inline WebFrame *frame(WebCoreFrameBridge *bridge)
{
return [(WebFrameBridge *)bridge webFrame];
}
- (WebFrame *)_firstChildFrame
{
- return Frame([[self _bridge] firstChild]);
+ return frame([[self _bridge] firstChild]);
}
- (WebFrame *)_lastChildFrame
{
- return Frame([[self _bridge] lastChild]);
+ return frame([[self _bridge] lastChild]);
}
- (unsigned)_childFrameCount
- (WebFrame *)_previousSiblingFrame;
{
- return Frame([[self _bridge] previousSibling]);
+ return frame([[self _bridge] previousSibling]);
}
- (WebFrame *)_nextSiblingFrame;
{
- return Frame([[self _bridge] nextSibling]);
+ return frame([[self _bridge] nextSibling]);
}
- (WebFrame *)_traverseNextFrameStayWithin:(WebFrame *)stayWithin
{
- return Frame([[self _bridge] traverseNextFrameStayWithin:[stayWithin _bridge]]);
+ return frame([[self _bridge] traverseNextFrameStayWithin:[stayWithin _bridge]]);
}
@end
- (WebFrame *)_immediateChildFrameNamed:(NSString *)name
{
- return Frame([[self _bridge] childFrameNamed:name]);
+ return frame([[self _bridge] childFrameNamed:name]);
}
- (BOOL)_canCachePage
// Return next frame to be traversed, visiting children after parent
- (WebFrame *)_nextFrameWithWrap:(BOOL)wrapFlag
{
- return Frame([[self _bridge] nextFrameWithWrap:wrapFlag]);
+ return frame([[self _bridge] nextFrameWithWrap:wrapFlag]);
}
// Return previous frame to be traversed, exact reverse order of _nextFrame
- (WebFrame *)_previousFrameWithWrap:(BOOL)wrapFlag
{
- return Frame([[self _bridge] previousFrameWithWrap:wrapFlag]);
+ return frame([[self _bridge] previousFrameWithWrap:wrapFlag]);
}
- (int)_numPendingOrLoadingRequests:(BOOL)recurse
- (WebFrame *)findFrameNamed:(NSString *)name
{
- return Frame([[self _bridge] findFrameNamed:name]);
+ return frame([[self _bridge] findFrameNamed:name]);
}
- (WebFrame *)parentFrame
{
- return [[Frame([[self _bridge] parent]) retain] autorelease];
+ return [[frame([[self _bridge] parent]) retain] autorelease];
}
- (NSArray *)childFrames
- (void)_dispatchSourceFrame:(WebCoreFrameBridge *)sourceFrame willSubmitForm:(DOMElement *)form withValues:(NSDictionary *)values submissionDecider:(WebPolicyDecider *)decider
{
- [[self _formDelegate] frame:self sourceFrame:Frame(sourceFrame) willSubmitForm:form withValues:values submissionListener:decisionListener(decider)];
+ [[self _formDelegate] frame:self sourceFrame:frame(sourceFrame) willSubmitForm:form withValues:values submissionListener:decisionListener(decider)];
}
- (void)_detachedFromParent1
- (void)_deliverArchivedResourcesAfterDelay
{
- if (![_private->pendingArchivedResources count] || [[self _frameLoader] defersCallbacks])
+ if (!_private->pendingArchivedResources)
+ return;
+ if (_private->pendingArchivedResources->isEmpty())
+ return;
+ if ([[self _frameLoader] defersCallbacks])
return;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
[self performSelector:@selector(_deliverArchivedResources) withObject:nil afterDelay:0];
}
-- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebLoader *)loader
+- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebResourceLoader*)loader
{
if (![[r URL] isEqual:originalURL])
return NO;
if (![self _canUseResourceWithResponse:[resource _response]])
return NO;
if (!_private->pendingArchivedResources)
- _private->pendingArchivedResources = [[NSMutableDictionary alloc] init];
- [_private->pendingArchivedResources _webkit_setObject:resource forUncopiedKey:loader];
+ _private->pendingArchivedResources = new ResourceMap;
+ _private->pendingArchivedResources->set(loader, resource);
// Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
[self _deliverArchivedResourcesAfterDelay];
return YES;
}
-- (BOOL)_archiveLoadPendingForLoader:(WebLoader *)loader
+- (BOOL)_archiveLoadPendingForLoader:(WebResourceLoader*)loader
{
- return [_private->pendingArchivedResources objectForKey:loader] != nil;
+ if (!_private->pendingArchivedResources)
+ return false;
+ return _private->pendingArchivedResources->contains(loader);
}
-- (void)_cancelPendingArchiveLoadForLoader:(WebLoader *)loader
+- (void)_cancelPendingArchiveLoadForLoader:(WebResourceLoader*)loader
{
- [_private->pendingArchivedResources removeObjectForKey:loader];
-
- if (![_private->pendingArchivedResources count])
+ if (!_private->pendingArchivedResources)
+ return;
+ if (_private->pendingArchivedResources->isEmpty())
+ return;
+ _private->pendingArchivedResources->remove(loader);
+ if (_private->pendingArchivedResources->isEmpty())
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
}
- (void)_clearArchivedResources
{
- [_private->pendingArchivedResources removeAllObjects];
+ if (_private->pendingArchivedResources)
+ _private->pendingArchivedResources->clear();
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
}
- (void)_deliverArchivedResources
{
- if (![_private->pendingArchivedResources count] || [[self _frameLoader] defersCallbacks])
+ if (!_private->pendingArchivedResources)
return;
-
- NSEnumerator *keyEnum = [_private->pendingArchivedResources keyEnumerator];
- WebLoader *loader;
- while ((loader = [keyEnum nextObject])) {
- WebResource *resource = [_private->pendingArchivedResources objectForKey:loader];
- [loader didReceiveResponse:[resource _response]];
- NSData *data = [resource data];
- [loader didReceiveData:data lengthReceived:[data length] allAtOnce:YES];
- [loader didFinishLoading];
+ if (_private->pendingArchivedResources->isEmpty())
+ return;
+ if ([[self _frameLoader] defersCallbacks])
+ return;
+
+ const ResourceMap copy = *_private->pendingArchivedResources;
+ _private->pendingArchivedResources->clear();
+
+ ResourceMap::const_iterator end = copy.end();
+ for (ResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
+ RefPtr<WebResourceLoader> loader = it->first;
+ WebResource *resource = it->second.get();
+ NSData *data = [[resource data] retain];
+ loader->didReceiveResponse([resource _response]);
+ loader->didReceiveData(data, [data length], true);
+ [data release];
+ loader->didFinishLoading();
}
-
- [_private->pendingArchivedResources removeAllObjects];
}
- (void)_setDefersCallbacks:(BOOL)defers