WebCore:
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 22:21:29 +0000 (22:21 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Oct 2006 22:21:29 +0000 (22:21 +0000)
        - rolled out my loader change; caused world leak and possibly a plug-in crash

WebKit:

        - rolled out my loader change; caused world leak and possibly a plug-in crash

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17175 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
WebCore/ChangeLog
WebCore/WebCore.exp
WebCore/WebCore.xcodeproj/project.pbxproj
WebCore/bridge/mac/WebCoreFrameBridge.mm
WebCore/loader/mac/WebFrameLoader.h
WebCore/loader/mac/WebFrameLoader.mm
WebCore/loader/mac/WebFrameLoaderClient.h
WebCore/loader/mac/WebLoader.h
WebCore/loader/mac/WebLoader.mm
WebCore/loader/mac/WebMainResourceLoader.h
WebCore/loader/mac/WebMainResourceLoader.mm
WebCore/loader/mac/WebNetscapePlugInStreamLoader.h
WebCore/loader/mac/WebNetscapePlugInStreamLoader.mm
WebCore/loader/mac/WebSubresourceLoader.h
WebCore/loader/mac/WebSubresourceLoader.mm
WebCore/platform/cf/RetainPtr.h
WebKit/ChangeLog
WebKit/Plugins/WebNetscapePluginStream.h
WebKit/Plugins/WebNetscapePluginStream.m
WebKit/WebCoreSupport/WebFrameBridge.m
WebKit/WebView/WebFrame.m

index be014ae17fa5284acdf2a0ce5bfa23a196c3e223..acbfdd2f83c7741cf172ee4e9bb6e5631e8feee7 100644 (file)
@@ -1,3 +1,7 @@
+2006-10-20  Darin Adler  <darin@apple.com>
+
+        - rolled out my loader change; caused world leak and possibly a plug-in crash
+
 2006-10-20  Anders Carlsson  <acarlsson@apple.com>
 
         Reviewed by Tim H
index 7a862987b44b6ff6793d4750f4d46188bbc172e3..020b07df90d7cda24f6ab81ff0b32381c56fa430 100644 (file)
 .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
@@ -133,11 +136,6 @@ _WebCoreShouldUseFontSmoothing
 _WebCoreTextFloatWidth
 __Z21isBackForwardLoadType13FrameLoadType
 __ZN7WebCore10StringImplD1Ev
-__ZN7WebCore17WebResourceLoader14cancelledErrorEv
-__ZN7WebCore17WebResourceLoader20inConnectionCallbackEv
-__ZN7WebCore26NetscapePlugInStreamLoader6createEP14WebFrameLoaderP11objc_object
-__ZNK7WebCore17WebResourceLoader11frameLoaderEv
-__ZNK7WebCore26NetscapePlugInStreamLoader6isDoneEv
 _canonicalURL
 _stringIsFileURL
 _urlByRemovingComponent
index 5975d26f0af2c2c45d8b85ec566be8daf56023f6..ffcb161abda47278cbcb97dc2e7a97e27003faf2 100644 (file)
                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 */; settings = {ATTRIBUTES = (Private, ); }; };
+               65BAAABE0ADCA015005BB5A4 /* RetainPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 65BAAABD0ADCA015005BB5A4 /* RetainPtr.h */; };
                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 */,
index 8df99056447b71cf647894fd7c58bc7b1d584964..0238748d44625b1faf94b36c6a185c1e6802683b 100644 (file)
@@ -2731,8 +2731,12 @@ static NSString *stringByCollapsingNonPrintingCharacters(NSString *string)
     BOOL hideReferrer;
     [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
     
-    return SubresourceLoader::create([self frameLoader], resourceLoader,
-        method, URL, customHeaders, hideReferrer ? nil : [self referrer]);
+    return [WebSubresourceLoader startLoadingResource:resourceLoader
+                                           withMethod:method
+                                                  URL:URL
+                                        customHeaders:customHeaders
+                                             referrer:(hideReferrer ? nil : [self referrer])
+                                       forFrameLoader:[self frameLoader]];
 }
 
 - (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data
@@ -2746,8 +2750,7 @@ static NSString *stringByCollapsingNonPrintingCharacters(NSString *string)
     [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.
@@ -2759,8 +2762,13 @@ static NSString *stringByCollapsingNonPrintingCharacters(NSString *string)
     BOOL hideReferrer;
     [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
     
-    return SubresourceLoader::create([self frameLoader], resourceLoader,
-        method, URL, customHeaders, postData, hideReferrer ? nil : [self referrer]);
+    return [WebSubresourceLoader startLoadingResource:resourceLoader
+                                           withMethod:method 
+                                                  URL:URL
+                                        customHeaders:customHeaders
+                                             postData:postData
+                                             referrer:(hideReferrer ? nil : [self referrer])
+                                       forFrameLoader:[self frameLoader]];
 }
 
 - (void)reportClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date lockHistory:(BOOL)lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction
index 6a765df582b101ef26a9428dde62f70495dba85c..cf78d9cef2553d8747b0b1eb448a773849eb04e7 100644 (file)
 #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);
+BOOL isBackForwardLoadType(FrameLoadType type);
 
 @interface WebFrameLoader : NSObject 
 {
     WebCoreFrameBridge *frameBridge;
     
-    WebCore::MainResourceLoader *m_mainResourceLoader;
+    WebMainResourceLoader *mainResourceLoader;
     
-    HashSet<RefPtr<WebCore::WebResourceLoader> >* m_subresourceLoaders;
-    HashSet<RefPtr<WebCore::WebResourceLoader> >* m_plugInStreamLoaders;
+    NSMutableArray *subresourceLoaders;
+    NSMutableArray *plugInStreamLoaders;
     
-    id <WebFrameLoaderClient> client;
+    id<WebFrameLoaderClient> client;
     WebDocumentLoader *documentLoader;
     WebDocumentLoader *provisionalDocumentLoader;
     WebDocumentLoader *policyDocumentLoader;
@@ -86,16 +83,16 @@ bool isBackForwardLoadType(FrameLoadType);
 }
 
 - (id)initWithFrameBridge:(WebCoreFrameBridge *)bridge;
-- (void)addPlugInStreamLoader:(WebCore::WebResourceLoader *)loader;
-- (void)removePlugInStreamLoader:(WebCore::WebResourceLoader *)loader;
+- (void)addPlugInStreamLoader:(WebLoader *)loader;
+- (void)removePlugInStreamLoader:(WebLoader *)loader;
 - (void)setDefersCallbacks:(BOOL)defers;
 - (void)stopLoadingPlugIns;
 - (BOOL)isLoadingMainResource;
 - (BOOL)isLoadingSubresources;
 - (BOOL)isLoading;
 - (void)stopLoadingSubresources;
-- (void)addSubresourceLoader:(WebCore::WebResourceLoader *)loader;
-- (void)removeSubresourceLoader:(WebCore::WebResourceLoader *)loader;
+- (void)addSubresourceLoader:(WebLoader *)loader;
+- (void)removeSubresourceLoader:(WebLoader *)loader;
 - (NSData *)mainResourceData;
 - (void)releaseMainResourceLoader;
 - (void)cancelMainResourceLoad;
@@ -147,9 +144,9 @@ bool isBackForwardLoadType(FrameLoadType);
 
 - (NSError *)cancelledErrorWithRequest:(NSURLRequest *)request;
 - (NSError *)fileDoesNotExistErrorWithResponse:(NSURLResponse *)response;
-- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebCore::WebResourceLoader *)loader;
-- (BOOL)archiveLoadPendingForLoader:(WebCore::WebResourceLoader *)loader;
-- (void)cancelPendingArchiveLoadForLoader:(WebCore::WebResourceLoader *)loader;
+- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader;
+- (BOOL)archiveLoadPendingForLoader:(WebLoader *)loader;
+- (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
 - (void)cannotShowMIMETypeWithResponse:(NSURLResponse *)response;
 - (NSError *)interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request;
 - (BOOL)isHostedByObjectElement;
index 4f077a48e011e5fbbee3b154526ae16d3de90a62..e4335a69dc95fbc08611ad8404cdd054850a4271 100644 (file)
 
 using namespace WebCore;
 
-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)
+static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
 {
     return [a caseInsensitiveCompare:b] == NSOrderedSame;
 }
 
-bool isBackForwardLoadType(FrameLoadType type)
+BOOL isBackForwardLoadType(FrameLoadType type)
 {
     switch (type) {
         case FrameLoadTypeStandard:
@@ -114,11 +88,10 @@ bool isBackForwardLoadType(FrameLoadType type)
 
 - (void)dealloc
 {
-    // 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;
+    // FIXME: should these even exist?
+    [mainResourceLoader release];
+    [subresourceLoaders release];
+    [plugInStreamLoaders release];
     [documentLoader release];
     [provisionalDocumentLoader release];
  
@@ -128,13 +101,6 @@ bool isBackForwardLoadType(FrameLoadType type)
     [super dealloc];
 }
 
-- (void)finalize
-{
-    if (m_mainResourceLoader)
-        m_mainResourceLoader->deref();
-    [super finalize];
-}
-
 - (WebDocumentLoader *)activeDocumentLoader
 {
     if (state == WebFrameStateProvisional)
@@ -143,18 +109,17 @@ bool isBackForwardLoadType(FrameLoadType type)
     return documentLoader;    
 }
 
-- (void)addPlugInStreamLoader:(WebResourceLoader *)loader
+- (void)addPlugInStreamLoader:(WebLoader *)loader
 {
-    if (!m_plugInStreamLoaders)
-        m_plugInStreamLoaders = new ResourceLoaderSet;
-    m_plugInStreamLoaders->add(loader);
+    if (!plugInStreamLoaders)
+        plugInStreamLoaders = [[NSMutableArray alloc] init];
+    [plugInStreamLoaders addObject:loader];
     [[self activeDocumentLoader] setLoading:YES];
 }
 
-- (void)removePlugInStreamLoader:(WebResourceLoader *)loader
+- (void)removePlugInStreamLoader:(WebLoader *)loader
 {
-    ASSERT(m_plugInStreamLoaders);
-    m_plugInStreamLoaders->remove(loader);
+    [plugInStreamLoaders removeObject:loader];
     [[self activeDocumentLoader] updateLoading];
 }
 
@@ -172,31 +137,39 @@ bool isBackForwardLoadType(FrameLoadType type)
 
 - (void)setDefersCallbacks:(BOOL)defers
 {
-    if (m_mainResourceLoader)
-        m_mainResourceLoader->setDefersCallbacks(defers);
-    setDefersCallbacks(m_subresourceLoaders, defers);
-    setDefersCallbacks(m_plugInStreamLoaders, 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];
+
     [client _setDefersCallbacks:defers];
 }
 
 - (void)stopLoadingPlugIns
 {
-    cancelAll(m_plugInStreamLoaders);
+    [plugInStreamLoaders makeObjectsPerformSelector:@selector(cancel)];
+    [plugInStreamLoaders removeAllObjects];   
 }
 
 - (BOOL)isLoadingMainResource
 {
-    return m_mainResourceLoader != 0;
+    return mainResourceLoader != nil;
 }
 
 - (BOOL)isLoadingSubresources
 {
-    return m_subresourceLoaders && !m_subresourceLoaders->isEmpty();
+    return [subresourceLoaders count];
 }
 
 - (BOOL)isLoadingPlugIns
 {
-    return m_plugInStreamLoaders && !m_plugInStreamLoaders->isEmpty();
+    return [plugInStreamLoaders count];
 }
 
 - (BOOL)isLoading
@@ -206,59 +179,55 @@ bool isBackForwardLoadType(FrameLoadType type)
 
 - (void)stopLoadingSubresources
 {
-    cancelAll(m_subresourceLoaders);
+    NSArray *loaders = [subresourceLoaders copy];
+    [loaders makeObjectsPerformSelector:@selector(cancel)];
+    [loaders release];
+    [subresourceLoaders removeAllObjects];
 }
 
-- (void)addSubresourceLoader:(WebResourceLoader *)loader
+- (void)addSubresourceLoader:(WebLoader *)loader
 {
     ASSERT(!provisionalDocumentLoader);
-    if (!m_subresourceLoaders)
-        m_subresourceLoaders = new ResourceLoaderSet;
-    m_subresourceLoaders->add(loader);
+    if (subresourceLoaders == nil)
+        subresourceLoaders = [[NSMutableArray alloc] init];
+    [subresourceLoaders addObject:loader];
     [[self activeDocumentLoader] setLoading:YES];
 }
 
-- (void)removeSubresourceLoader:(WebResourceLoader *)loader
+- (void)removeSubresourceLoader:(WebLoader *)loader
 {
-    ASSERT(m_subresourceLoaders);
-    m_subresourceLoaders->remove(loader);
+    [subresourceLoaders removeObject:loader];
     [[self activeDocumentLoader] updateLoading];
 }
 
 - (NSData *)mainResourceData
 {
-    if (!m_mainResourceLoader)
-        return nil;
-    return m_mainResourceLoader->resourceData();
+    return [mainResourceLoader resourceData];
 }
 
 - (void)releaseMainResourceLoader
 {
-    if (!m_mainResourceLoader)
-        return;
-    m_mainResourceLoader->deref();
-    m_mainResourceLoader = 0;
+    [mainResourceLoader release];
+    mainResourceLoader = nil;
 }
 
 - (void)cancelMainResourceLoad
 {
-    if (m_mainResourceLoader)
-        m_mainResourceLoader->cancel();
+    [mainResourceLoader cancel];
 }
 
 - (BOOL)startLoadingMainResourceWithRequest:(NSMutableURLRequest *)request identifier:(id)identifier
 {
-    ASSERT(!m_mainResourceLoader);
-    m_mainResourceLoader = MainResourceLoader::create(self).release();
+    mainResourceLoader = [[WebMainResourceLoader alloc] initWithFrameLoader:self];
     
-    m_mainResourceLoader->setIdentifier(identifier);
+    [mainResourceLoader setIdentifier:identifier];
     [self addExtraFieldsToRequest:request mainResource:YES alwaysFromRequest:NO];
-    if (!m_mainResourceLoader->load(request)) {
+    if (![mainResourceLoader loadWithRequest: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]);
-        m_mainResourceLoader->deref();
-        m_mainResourceLoader = 0;
+        [mainResourceLoader release];
+        mainResourceLoader = nil;
         return NO;
     }
     
@@ -267,7 +236,7 @@ bool isBackForwardLoadType(FrameLoadType type)
 
 - (void)stopLoadingWithError:(NSError *)error
 {
-    m_mainResourceLoader->cancel(error);
+    [mainResourceLoader cancelWithError:error];
 }
 
 - (void)setDocumentLoader:(WebDocumentLoader *)loader
@@ -904,17 +873,17 @@ static CFAbsoluteTime _timeOfLastCompletedLoad;
     return [client _fileDoesNotExistErrorWithResponse:response];    
 }
 
-- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebResourceLoader *)loader
+- (BOOL)willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader
 {
     return [client _willUseArchiveForRequest:request originalURL:originalURL loader:loader];
 }
 
-- (BOOL)archiveLoadPendingForLoader:(WebResourceLoader *)loader
+- (BOOL)archiveLoadPendingForLoader:(WebLoader *)loader
 {
     return [client _archiveLoadPendingForLoader:loader];
 }
 
-- (void)cancelPendingArchiveLoadForLoader:(WebResourceLoader *)loader
+- (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader
 {
     [client _cancelPendingArchiveLoadForLoader:loader];
 }
index c866c0956a6146e7224a1e8a59e97f2f9e55edae..4af330ccf3060b612409bd8515be2b606141d412 100644 (file)
 
 #import <Cocoa/Cocoa.h>
 
-namespace WebCore {
-    class WebResourceLoader;
-}
-
 typedef struct LoadErrorResetToken LoadErrorResetToken;
 
 @class DOMElement;
 @class WebCoreFrameBridge;
 @class WebDocumentLoader;
+@class WebLoader;
 @class WebPolicyDecider;
 @class WebResource;
 
@@ -157,9 +154,9 @@ typedef struct LoadErrorResetToken LoadErrorResetToken;
 
 - (void)_setDefersCallbacks:(BOOL)defers;
 
-- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebCore::WebResourceLoader *)loader;
-- (BOOL)_archiveLoadPendingForLoader:(WebCore::WebResourceLoader *)loader;
-- (void)_cancelPendingArchiveLoadForLoader:(WebCore::WebResourceLoader *)loader;
+- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)request originalURL:(NSURL *)originalURL loader:(WebLoader *)loader;
+- (BOOL)_archiveLoadPendingForLoader:(WebLoader *)loader;
+- (void)_cancelPendingArchiveLoadForLoader:(WebLoader *)loader;
 - (void)_clearArchivedResources;
 
 - (BOOL)_canHandleRequest:(NSURLRequest *)request;
index 3b732f5de98e7df82d8907c9c75a9af518f5ec4b..923ef3cd1c9ed0a5df66a6bb19340d486fa2055f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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.
  */
 
-#include "RetainPtr.h"
-#include "Shared.h"
+#import <Foundation/Foundation.h>
 
 @class NSError;
 @class NSURLAuthenticationChallenge;
 @class NSURLConnection;
+@class NSURLConnectionAuthenticationChallenge;
+@class NSURLCredential;
 @class NSURLRequest;
 @class NSURLResponse;
 @class WebFrameLoader;
-@class WebCoreResourceLoaderDelegate;
 
-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();
-
-        void setFrameLoader(WebFrameLoader *);
-        WebFrameLoader *frameLoader() const;
-
-        virtual void cancel();
-        virtual void cancel(NSError *);
-        NSError *cancelledError();
-
-        virtual void setDefersCallbacks(bool);
-        bool defersCallbacks() const;
+@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;
 
-        void setIdentifier(id);
+- (BOOL)loadWithRequest:(NSURLRequest *)request;
 
-        virtual void releaseResources();
-        NSURLResponse *response() const;
+- (void)setFrameLoader:(WebFrameLoader *)fl;
+- (WebFrameLoader *)frameLoader;
 
-        virtual void addData(NSData *, bool allAtOnce);
-        NSData *resourceData();
-        void clearResourceData();
+- (void)cancel;
+- (void)cancelWithError:(NSError *)error;
+- (NSError *)cancelledError;
 
-        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 *);
+- (void)setDefersCallbacks:(BOOL)defers;
+- (BOOL)defersCallbacks;
 
-        void receivedCredential(NSURLAuthenticationChallenge *, NSURLCredential *);
-        void receivedRequestToContinueWithoutCredential(NSURLAuthenticationChallenge *);
-        void receivedCancellation(NSURLAuthenticationChallenge *);
+- (void)setIdentifier:(id)ident;
 
-        // 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();
+- (void)releaseResources;
+- (NSURLResponse *)response;
 
-    protected:
-        WebResourceLoader(WebFrameLoader *);
-        WebCoreResourceLoaderDelegate *delegate();
-        virtual void releaseDelegate();
+- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce;
+- (NSData *)resourceData;
+- (void)clearResourceData;
 
-        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(); }
+// 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;
 
-        RetainPtr<NSURLConnection> m_connection;
 
-    private:
-        RetainPtr<NSURLRequest> m_request;
-        bool m_reachedTerminalState;
-        bool m_signalledFinish;
-        bool m_cancelled;
+// Used to work around the fact that you don't get any more NSURLConnection callbacks until you return from the first one.
++ (BOOL)inConnectionCallback;
 
-        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;
-    };
+@end
 
-}
+// 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
index eb9ab20bc611daeab2bde9b2429da9163495e045..95c6ed95ffb32569998a1e39885f6f245ebf96cd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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
@@ -29,7 +29,6 @@
 #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 <wtf/RefPtr.h>
-
-using namespace WebCore;
+#import "WebCoreSystemInterface.h"
 
-@interface WebCoreResourceLoaderDelegate : NSObject <NSURLAuthenticationChallengeSender>
-{
-    WebResourceLoader* m_loader;
-}
-- (id)initWithLoader:(WebResourceLoader*)loader;
-- (void)detachLoader;
-@end
+static unsigned inNSURLConnectionCallback;
+static BOOL NSURLConnectionSupportsBufferedData;
 
 @interface NSURLConnection (NSURLConnectionTigerPrivate)
 - (NSData *)_bufferedData;
 @end
 
-@interface NSURLProtocol (WebFoundationSecret) 
-+ (void)_removePropertyForKey:(NSString *)key inRequest:(NSMutableURLRequest *)request;
+@interface WebLoader (WebNSURLAuthenticationChallengeSender) <NSURLAuthenticationChallengeSender>
 @end
 
-namespace WebCore {
+@implementation WebLoader (WebNSURLAuthenticationChallengeSender) 
 
-static unsigned inNSURLConnectionCallback;
-static bool NSURLConnectionSupportsBufferedData;
+- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+{
+    if (challenge == nil || challenge != currentWebChallenge) {
+        return;
+    }
 
-#ifndef NDEBUG
-static bool isInitializingConnection;
-#endif
+    [[currentConnectionChallenge sender] useCredential:credential forAuthenticationChallenge:currentConnectionChallenge];
 
-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;
+    [currentConnectionChallenge release];
+    currentConnectionChallenge = nil;
+    
+    [currentWebChallenge release];
+    currentWebChallenge = nil;
+}
+
+- (void)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+{
+    if (challenge == nil || challenge != currentWebChallenge) {
+        return;
+    }
+
+    [[currentConnectionChallenge sender] continueWithoutCredentialForAuthenticationChallenge:currentConnectionChallenge];
+
+    [currentConnectionChallenge release];
+    currentConnectionChallenge = nil;
+    
+    [currentWebChallenge release];
+    currentWebChallenge = nil;
+}
+
+- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+{
+    if (challenge == nil || challenge != currentWebChallenge) {
+        return;
     }
+
+    [self cancel];
 }
 
-WebResourceLoader::~WebResourceLoader()
+@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
 {
-    ASSERT(m_reachedTerminalState);
-    releaseDelegate();
+    NSURLConnectionSupportsBufferedData = [NSURLConnection instancesRespondToSelector:@selector(_bufferedData)];
 }
 
-void WebResourceLoader::releaseResources()
+- (void)releaseResources
 {
-    ASSERT(!m_reachedTerminalState);
+    ASSERT(!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.
-    RefPtr<WebResourceLoader> protector(this);
+    
+    [self retain];
 
-    // We need to set reachedTerminalState to true before we release
+    // We need to set reachedTerminalState to YES before we release
     // the resources to prevent a double dealloc of WebView <rdar://problem/4372628>
-    m_reachedTerminalState = true;
 
-    m_identifier = nil;
-    m_connection = nil;
-    m_frameLoader = nil;
-    m_resourceData = nil;
+    reachedTerminalState = YES;
+
+    [identifier release];
+    identifier = nil;
 
-    releaseDelegate();
+    [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];
 }
 
-bool WebResourceLoader::load(NSURLRequest *r)
+- (BOOL)loadWithRequest:(NSURLRequest *)r
 {
-    ASSERT(m_connection == nil);
-    ASSERT(![m_frameLoader.get() archiveLoadPendingForLoader:this]);
+    ASSERT(connection == nil);
+    ASSERT(![frameLoader archiveLoadPendingForLoader:self]);
     
-    m_originalURL = [r URL];
+    NSURL *URL = [[r URL] retain];
+    [originalURL release];
+    originalURL = URL;
     
-    NSURLRequest *clientRequest = willSendRequest(r, nil);
+    NSURLRequest *clientRequest = [self willSendRequest:r redirectResponse:nil];
     if (clientRequest == nil) {
-        didFail([m_frameLoader.get() cancelledErrorWithRequest:r]);
-        return false;
+        NSError *cancelledError = [frameLoader cancelledErrorWithRequest:r];
+        [self didFailWithError:cancelledError];
+        return NO;
     }
     r = clientRequest;
     
-    if ([m_frameLoader.get() willUseArchiveForRequest:r originalURL:m_originalURL.get() loader:this])
-        return true;
+    if ([frameLoader willUseArchiveForRequest:r originalURL:originalURL loader:self])
+        return YES;
     
 #ifndef NDEBUG
     isInitializingConnection = YES;
 #endif
-    NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:r delegate:delegate()];
+    connection = [[NSURLConnection alloc] initWithRequest:r delegate:self];
 #ifndef NDEBUG
     isInitializingConnection = NO;
 #endif
-    m_connection = connection;
-    [connection release];
-    if (defersCallbacks())
-        wkSetNSURLConnectionDefersCallbacks(m_connection.get(), YES);
+    if (defersCallbacks)
+        wkSetNSURLConnectionDefersCallbacks(connection, YES);
 
-    return true;
+    return YES;
 }
 
-void WebResourceLoader::setDefersCallbacks(bool defers)
+- (void)setDefersCallbacks:(BOOL)defers
 {
-    m_defersCallbacks = defers;
-    wkSetNSURLConnectionDefersCallbacks(m_connection.get(), defers);
+    defersCallbacks = defers;
+    wkSetNSURLConnectionDefersCallbacks(connection, defers);
+    // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
 }
 
-bool WebResourceLoader::defersCallbacks() const
+- (BOOL)defersCallbacks
 {
-    return m_defersCallbacks;
+    return defersCallbacks;
 }
 
-void WebResourceLoader::setFrameLoader(WebFrameLoader *fl)
+- (void)setFrameLoader:(WebFrameLoader *)fl
 {
     ASSERT(fl);
-    m_frameLoader = fl;
-    setDefersCallbacks([fl defersCallbacks]);
+    
+    [fl retain];
+    [frameLoader release];
+    frameLoader = fl;
+
+    [self setDefersCallbacks:[frameLoader defersCallbacks]];
 }
 
-WebFrameLoader *WebResourceLoader::frameLoader() const
+- (WebFrameLoader *)frameLoader
 {
-    return m_frameLoader.get();
+    return frameLoader;
 }
 
-void WebResourceLoader::addData(NSData *data, bool allAtOnce)
+- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce
 {
     if (allAtOnce) {
-        NSMutableData *dataCopy = [data mutableCopy];
-        m_resourceData = dataCopy;
-        [dataCopy release];
+        resourceData = [data copy];
         return;
     }
         
     if (NSURLConnectionSupportsBufferedData) {
         // Buffer data only if the connection has handed us the data because is has stopped buffering it.
-        if (m_resourceData)
-            [m_resourceData.get() appendData:data];
+        if (resourceData != nil)
+            [resourceData appendData:data];
     } else {
-        if (!m_resourceData) {
-            NSMutableData *newData = [[NSMutableData alloc] init];
-            m_resourceData = newData;
-            [newData release];
-        }
-        [m_resourceData.get() appendData:data];
+        if (resourceData == nil)
+            resourceData = [[NSMutableData alloc] init];
+        [resourceData appendData:data];
     }
 }
 
-NSData *WebResourceLoader::resourceData()
+- (NSData *)resourceData
 {
-    if (m_resourceData)
+    if (resourceData)
         // Retain and autorelease resourceData since releaseResources (which releases resourceData) may be called 
-        // before the caller of this method has an opportunity to retain the returned data (4070729).
-        return [[m_resourceData.get() retain] autorelease];
+        // before the caller of this method has an opporuntity to retain the returned data (4070729).
+        return [[resourceData retain] autorelease];
 
     if (NSURLConnectionSupportsBufferedData)
-        return [m_connection.get() _bufferedData];
+        return [connection _bufferedData];
 
     return nil;
 }
 
-void WebResourceLoader::clearResourceData()
+- (void)clearResourceData
 {
-    [m_resourceData.get() setLength:0];
+    [resourceData setLength:0];
 }
 
-NSURLRequest *WebResourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
+- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
 {
-    // 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);
+    ASSERT(!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.
-    bool haveDataSchemeRequest = false;
-    NSMutableURLRequest *clientRequest = [mutableRequest _webDataRequestExternalRequest];
+    clientRequest = [mutableRequest _webDataRequestExternalRequest];
     if (!clientRequest)
         clientRequest = mutableRequest;
     else
-        haveDataSchemeRequest = true;
+        haveDataSchemeRequest = YES;
     
-    if (!m_identifier) {
-        id identifier = [m_frameLoader.get() _identifierForInitialRequest:clientRequest];
-        m_identifier = identifier;
-        [identifier release];
-    }
+    if (identifier == nil)
+        identifier = [frameLoader _identifierForInitialRequest:clientRequest];
 
-    NSURLRequest *updatedRequest = [m_frameLoader.get() _willSendRequest:clientRequest
-        forResource:m_identifier.get() redirectResponse:redirectResponse];
+    updatedRequest = [frameLoader _willSendRequest:clientRequest forResource:identifier redirectResponse:redirectResponse];
 
     if (!haveDataSchemeRequest)
         newRequest = updatedRequest;
@@ -252,137 +286,136 @@ NSURLRequest *WebResourceLoader::willSendRequest(NSURLRequest *newRequest, NSURL
         }
     }
 
-    // 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];
-
     // Store a copy of the request.
-    NSURLRequest *copy = [newRequest copy];
-    m_request = copy;
-    [copy release];
+    [request autorelease];
+
+    request = [newRequest copy];
 
-    return copy;
+    [self release];
+    return request;
 }
 
-void WebResourceLoader::didReceiveAuthenticationChallenge(NSURLAuthenticationChallenge *challenge)
+- (void)didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
 {
-    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);
+    ASSERT(!reachedTerminalState);
+    ASSERT(!currentConnectionChallenge);
+    ASSERT(!currentWebChallenge);
 
-    m_currentConnectionChallenge = challenge;
-    NSURLAuthenticationChallenge *webChallenge = [[NSURLAuthenticationChallenge alloc] initWithAuthenticationChallenge:challenge sender:delegate()];
-    m_currentWebChallenge = webChallenge;
+    // 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_frameLoader.get() _didReceiveAuthenticationChallenge:webChallenge forResource:m_identifier.get()];
+    [frameLoader _didReceiveAuthenticationChallenge:currentWebChallenge forResource:identifier];
 
-    [webChallenge release];
+    [self release];
 }
 
-void WebResourceLoader::didCancelAuthenticationChallenge(NSURLAuthenticationChallenge *challenge)
+- (void)didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
 {
-    ASSERT(!m_reachedTerminalState);
-    ASSERT(m_currentConnectionChallenge);
-    ASSERT(m_currentWebChallenge);
-    ASSERT(m_currentConnectionChallenge == challenge);
+    ASSERT(!reachedTerminalState);
+    ASSERT(currentConnectionChallenge);
+    ASSERT(currentWebChallenge);
+    ASSERT(currentConnectionChallenge = challenge);
 
-    // 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()];
+    // 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];
 }
 
-void WebResourceLoader::didReceiveResponse(NSURLResponse *r)
+- (void)didReceiveResponse:(NSURLResponse *)r
 {
-    ASSERT(!m_reachedTerminalState);
+    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);
+    // 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]; 
 
     // 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:[m_request.get() _webDataRequestExternalURL] MIMEType:[r MIMEType]
-                expectedContentLength:[r expectedContentLength] textEncodingName:[r textEncodingName]] autorelease];
+    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;
 
-    m_response = r;
+    [frameLoader _didReceiveResponse:r forResource:identifier];
 
-    [m_frameLoader.get() _didReceiveResponse:r forResource:m_identifier.get()];
+    [self release];
 }
 
-void WebResourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
+- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(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(!m_reachedTerminalState);
+    // 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);
+    // 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];
     
-    addData(data, allAtOnce);
+    [self addData:data allAtOnce:allAtOnce];
     
-    [m_frameLoader.get() _didReceiveData:data contentLength:(int)lengthReceived forResource:m_identifier.get()];
+    [frameLoader _didReceiveData:data contentLength:(int)lengthReceived forResource:identifier];
+
+    [self release];
 }
 
-void WebResourceLoader::willStopBufferingData(NSData *data)
+- (void)willStopBufferingData:(NSData *)data
 {
-    ASSERT(!m_resourceData);
-    NSMutableData *copy = [data mutableCopy];
-    m_resourceData = copy;
-    [copy release];
+    ASSERT(resourceData == nil);
+    resourceData = [data mutableCopy];
 }
 
-void WebResourceLoader::signalFinish()
+- (void)signalFinish
 {
-    m_signalledFinish = true;
-    [m_frameLoader.get() _didFinishLoadingForResource:m_identifier.get()];
+    signalledFinish = YES;
+    [frameLoader _didFinishLoadingForResource:identifier];
 }
 
-void WebResourceLoader::didFinishLoading()
+- (void)didFinishLoading
 {
     // If load has been cancelled after finishing (which could happen with a 
     // javascript that changes the window location), do nothing.
-    if (m_cancelled)
+    if (cancelledFlag)
         return;
     
-    ASSERT(!m_reachedTerminalState);
+    ASSERT(!reachedTerminalState);
 
-    if (!m_signalledFinish)
-        signalFinish();
+    if (!signalledFinish)
+        [self signalFinish];
 
-    releaseResources();
+    [self releaseResources];
 }
 
-void WebResourceLoader::didFail(NSError *error)
+- (void)didFailWithError:(NSError *)error
 {
-    if (m_cancelled)
+    if (cancelledFlag) {
         return;
+    }
     
-    ASSERT(!m_reachedTerminalState);
+    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);
+    // 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];
 
-    [m_frameLoader.get() _didFailLoadingWithError:error forResource:m_identifier.get()];
+    [frameLoader _didFailLoadingWithError:error forResource:identifier];
 
-    releaseResources();
+    [self releaseResources];
+    [self release];
 }
 
-NSCachedURLResponse *WebResourceLoader::willCacheResponse(NSCachedURLResponse *cachedResponse)
+- (NSCachedURLResponse *)willCacheResponse:(NSCachedURLResponse *)cachedResponse
 {
     // When in private browsing mode, prevent caching to disk
-    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [m_frameLoader.get() _privateBrowsingEnabled]) {
+    if ([cachedResponse storagePolicy] == NSURLCacheStorageAllowed && [frameLoader _privateBrowsingEnabled]) {
         cachedResponse = [[[NSCachedURLResponse alloc] initWithResponse:[cachedResponse response]
                                                                    data:[cachedResponse data]
                                                                userInfo:[cachedResponse userInfo]
@@ -391,228 +424,139 @@ NSCachedURLResponse *WebResourceLoader::willCacheResponse(NSCachedURLResponse *c
     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
 {
-    if (!m_loader)
-        return nil;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    NSURLRequest *result = m_loader->willSendRequest(newRequest, redirectResponse);
+    NSURLRequest *result = [self willSendRequest:newRequest redirectResponse:redirectResponse];
     --inNSURLConnectionCallback;
     return result;
 }
 
 - (void)connection:(NSURLConnection *)con didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didReceiveAuthenticationChallenge(challenge);
+    [self didReceiveAuthenticationChallenge:challenge];
     --inNSURLConnectionCallback;
 }
 
 - (void)connection:(NSURLConnection *)con didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didCancelAuthenticationChallenge(challenge);
+    [self didCancelAuthenticationChallenge:challenge];
     --inNSURLConnectionCallback;
 }
 
 - (void)connection:(NSURLConnection *)con didReceiveResponse:(NSURLResponse *)r
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didReceiveResponse(r);
+    [self didReceiveResponse:r];
     --inNSURLConnectionCallback;
 }
 
 - (void)connection:(NSURLConnection *)con didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didReceiveData(data, lengthReceived, false);
+    [self didReceiveData:data lengthReceived:lengthReceived allAtOnce:NO];
     --inNSURLConnectionCallback;
 }
 
 - (void)connection:(NSURLConnection *)con willStopBufferingData:(NSData *)data
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->willStopBufferingData(data);
+    [self willStopBufferingData:data];
     --inNSURLConnectionCallback;
 }
 
 - (void)connectionDidFinishLoading:(NSURLConnection *)con
 {
-    if (!m_loader)
-        return;
+    // don't worry about checking connection consistency if this load
+    // got cancelled while finishing.
+    ASSERT(cancelledFlag || con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didFinishLoading();
+    [self didFinishLoading];
     --inNSURLConnectionCallback;
 }
 
 - (void)connection:(NSURLConnection *)con didFailWithError:(NSError *)error
 {
-    if (!m_loader)
-        return;
+    ASSERT(con == connection);
     ++inNSURLConnectionCallback;
-    m_loader->didFail(error);
+    [self didFailWithError:error];
     --inNSURLConnectionCallback;
 }
 
-- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse
+- (NSCachedURLResponse *)connection:(NSURLConnection *)con willCacheResponse:(NSCachedURLResponse *)cachedResponse
 {
 #ifndef NDEBUG
-    if (isInitializingConnection)
+    if (connection == nil && isInitializingConnection) {
         LOG_ERROR("connection:willCacheResponse: was called inside of [NSURLConnection initWithRequest:delegate:] (40676250)");
+    }
 #endif
-    if (!m_loader)
-        return nil;
     ++inNSURLConnectionCallback;
-    NSCachedURLResponse *result = m_loader->willCacheResponse(cachedResponse);
+    NSCachedURLResponse *result = [self willCacheResponse:cachedResponse];
     --inNSURLConnectionCallback;
     return result;
 }
 
-- (void)useCredential:(NSURLCredential *)credential forAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+- (void)cancelWithError:(NSError *)error
 {
-    if (!m_loader)
-        return;
-    m_loader->receivedCredential(challenge, credential);
+    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)continueWithoutCredentialForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+- (void)cancel
 {
-    if (!m_loader)
-        return;
-    m_loader->receivedRequestToContinueWithoutCredential(challenge);
+    if (!reachedTerminalState) {
+        [self cancelWithError:[self cancelledError]];
+    }
 }
 
-- (void)cancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
+- (void)setIdentifier: ident
 {
-    if (!m_loader)
-        return;
-    m_loader->receivedCancellation(challenge);
+    if (identifier != ident){
+        [identifier release];
+        identifier = [ident retain];
+    }
+}
+
+- (NSURLResponse *)response
+{
+    return response;
+}
+
++ (BOOL)inConnectionCallback
+{
+    return inNSURLConnectionCallback != 0;
+}
+
+- (NSError *)cancelledError
+{
+    return [frameLoader cancelledErrorWithRequest:request];
 }
 
 @end
index 029d907fe781fcbd4a630691bd0bfdff9b7b9e13..c466cf00065d32129ccb8b742c4be1146fac1ac6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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 "FrameLoaderTypes.h"
+#import <Foundation/Foundation.h>
 #import "WebLoader.h"
-#import <wtf/Forward.h>
 
-@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 *);
-
-        void continueAfterNavigationPolicy(NSURLRequest *);
-        void continueAfterContentPolicy(WebPolicyAction);
-
-    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 *);
+@interface WebMainResourceLoader : WebLoader
+{
+    int _contentLength; // for logging only
+    int _bytesReceived; // for logging only
+    NSURLResponse *_response;
+    id proxy;
+    NSURLRequest *_initialRequest;
+}
 
-        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;
-    };
+- (id)initWithFrameLoader:(WebFrameLoader *)frameLoader;
 
-}
+@end
index b79b4cf081d8078dc65905395a8db02444f36a6e..f5ff08d3f23c5490badbfc53244115a4f6758cfa 100644 (file)
@@ -29,7 +29,6 @@
 #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 <wtf/PassRefPtr.h>
+#import "WebCoreSystemInterface.h"
 
-// FIXME: More that is in common with SubresourceLoader should move up into WebResourceLoader.
+// FIXME: More that is in common with WebSubresourceLoader should move up into WebLoader.
 
-using namespace WebCore;
+@implementation WebMainResourceLoader
 
-@interface WebCoreMainResourceLoaderPolicyDelegate : NSObject
+- (id)initWithFrameLoader:(WebFrameLoader *)fl
 {
-    MainResourceLoader* m_loader;
-}
-- (id)initWithLoader:(MainResourceLoader *)loader;
-- (void)detachLoader;
-@end
-
-namespace WebCore {
-
-const size_t URLBufferLength = 2048;
+    self = [super init];
+    
+    if (self) {
+        [self setFrameLoader:fl];
+        proxy = wkCreateNSURLConnectionDelegateProxy();
+        [proxy setDelegate:self];
+    }
 
-MainResourceLoader::MainResourceLoader(WebFrameLoader *fl)
-    : WebResourceLoader(fl)
-    , m_contentLength(0)
-    , m_bytesReceived(0)
-    , m_proxy(wkCreateNSURLConnectionDelegateProxy())
-    , m_loadingMultipartContent(false)
-{
-    [m_proxy.get() setDelegate:delegate()];
+    return self;
 }
 
-MainResourceLoader::~MainResourceLoader()
+- (void)dealloc
 {
-}
+    [_initialRequest release];
 
-void MainResourceLoader::releaseDelegate()
-{
-    releasePolicyDelegate();
-    [m_proxy.get() setDelegate:nil];
-    WebResourceLoader::releaseDelegate();
+    [_response release];
+    [proxy setDelegate:nil];
+    [proxy release];
+    
+    [super dealloc];
 }
 
-PassRefPtr<MainResourceLoader> MainResourceLoader::create(WebFrameLoader *fl)
+- (void)finalize
 {
-    return new MainResourceLoader(fl);
+    [proxy setDelegate:nil];
+    [super finalize];
 }
 
-void MainResourceLoader::receivedError(NSError *error)
+- (void)receivedError:(NSError *)error
 {
-    // Calling _receivedMainResourceError will likely result in the last reference to this object to go away.
-    RefPtr<MainResourceLoader> protect(this);
+    // 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
 
-    WebFrameLoader *fl = [frameLoader() retain]; // WebResourceLoader::didFailWithError will release the frameLoader
-
-    if (!cancelled()) {
-        ASSERT(!reachedTerminalState());
-        [fl _didFailLoadingWithError:error forResource:identifier()];
+    if (!cancelledFlag) {
+        ASSERT(!reachedTerminalState);
+        [frameLoader _didFailLoadingWithError:error forResource:identifier];
     }
 
     [fl _receivedMainResourceError:error complete:YES];
 
-    if (!cancelled())
-        releaseResources();
+    if (!cancelledFlag)
+        [self releaseResources];
 
-    ASSERT(reachedTerminalState());
+    ASSERT(reachedTerminalState);
 
     [fl release];
+    [self release];
 }
 
-void MainResourceLoader::cancel(NSError *error)
+-(void)cancelWithError:(NSError *)error
 {
-    // Calling _receivedMainResourceError will likely result in the last reference to this class to go away.
-    RefPtr<MainResourceLoader> protect(this);
+    // Calling _receivedMainResourceError will likely result in a call to release, so we must retain.
+    [self retain];
 
-    [frameLoader() cancelContentPolicy];
-    [frameLoader() retain];
-    [frameLoader() _receivedMainResourceError:error complete:YES];
-    [frameLoader() release];
+    [frameLoader cancelContentPolicy];
+    [frameLoader retain];
+    [frameLoader _receivedMainResourceError:error complete:YES];
+    [frameLoader release];
+    [super cancelWithError:error];
 
-    WebResourceLoader::cancel(error);
+    [self release];
 }
 
-NSError *MainResourceLoader::interruptionForPolicyChangeError() const
+- (NSError *)interruptForPolicyChangeError
 {
-    return [frameLoader() interruptForPolicyChangeErrorWithRequest:request()];
+    return [frameLoader interruptForPolicyChangeErrorWithRequest:request];
 }
 
-void MainResourceLoader::stopLoadingForPolicyChange()
+-(void)stopLoadingForPolicyChange
 {
-    cancel(interruptionForPolicyChangeError());
+    [self retain];
+    [self cancelWithError:[self interruptForPolicyChangeError]];
+    [self release];
 }
 
-void MainResourceLoader::continueAfterNavigationPolicy(NSURLRequest *r)
+-(void)continueAfterNavigationPolicy:(NSURLRequest *)_request formState:(id)state
 {
-    if (!r)
-        stopLoadingForPolicyChange();
+    if (!_request)
+        [self stopLoadingForPolicyChange];
 }
 
-bool MainResourceLoader::isPostOrRedirectAfterPost(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
+- (BOOL)_isPostOrRedirectAfterPost:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse
 {
-    if ([[newRequest HTTPMethod] isEqualToString:@"POST"])
-        return true;
-
-    if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
+    BOOL result = NO;
+    
+    if ([[newRequest HTTPMethod] isEqualToString:@"POST"]) {
+        result = YES;
+    }
+    else if (redirectResponse && [redirectResponse isKindOfClass:[NSHTTPURLResponse class]]) {
         int status = [(NSHTTPURLResponse *)redirectResponse statusCode];
         if (((status >= 301 && status <= 303) || status == 307)
-                && [[[frameLoader() initialRequest] HTTPMethod] isEqualToString:@"POST"])
-            return true;
+            && [[[frameLoader initialRequest] HTTPMethod] isEqualToString:@"POST"]) {
+            result = YES;
+        }
     }
     
-    return false;
+    return result;
 }
 
-void MainResourceLoader::addData(NSData *data, bool allAtOnce)
+- (void)addData:(NSData *)data allAtOnce:(BOOL)allAtOnce
 {
-    WebResourceLoader::addData(data, allAtOnce);
-    [frameLoader() _receivedData:data];
+    [super addData:data allAtOnce:allAtOnce];
+    [frameLoader _receivedData:data];
 }
 
-NSURLRequest *MainResourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
+- (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
 {
     // 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
@@ -161,16 +163,16 @@ NSURLRequest *MainResourceLoader::willSendRequest(NSURLRequest *newRequest, NSUR
     // callbacks is meant to prevent.
     ASSERT(newRequest != nil);
 
-    // 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);
+    // 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];
 
     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];
     }
@@ -179,299 +181,277 @@ NSURLRequest *MainResourceLoader::willSendRequest(NSURLRequest *newRequest, NSUR
     // 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 && isPostOrRedirectAfterPost(newRequest, redirectResponse)) {
-        if (!mutableRequest)
+    if ([newRequest cachePolicy] == NSURLRequestUseProtocolCachePolicy && 
+        [self _isPostOrRedirectAfterPost:newRequest redirectResponse: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 = [[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];
+    newRequest = [[[super willSendRequest:newRequest redirectResponse:redirectResponse] retain] autorelease];
 
-    [frameLoader() _checkNavigationPolicyForRequest:newRequest
-        andCall:policyDelegate() 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:self 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;
 }
 
-static bool shouldLoadAsEmptyDocument(NSURL *url)
+#define URL_BYTES_BUFFER_LENGTH 2048
+
+static BOOL shouldLoadAsEmptyDocument(NSURL *url)
 {
-    Vector<UInt8, URLBufferLength> buffer(URLBufferLength);
-    CFIndex bytesFilled = CFURLGetBytes((CFURLRef)url, buffer.data(), URLBufferLength);
+    UInt8 *buffer = (UInt8 *)malloc(URL_BYTES_BUFFER_LENGTH);
+    CFIndex bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, URL_BYTES_BUFFER_LENGTH);
     if (bytesFilled == -1) {
         CFIndex bytesToAllocate = CFURLGetBytes((CFURLRef)url, NULL, 0);
-        buffer.resize(bytesToAllocate);
-        bytesFilled = CFURLGetBytes((CFURLRef)url, buffer.data(), bytesToAllocate);
+        buffer = (UInt8 *)realloc(buffer, bytesToAllocate);
+        bytesFilled = CFURLGetBytes((CFURLRef)url, buffer, bytesToAllocate);
         ASSERT(bytesFilled == bytesToAllocate);
     }
     
-    return (bytesFilled == 0) || (bytesFilled > 5 && strncmp((char *)buffer.data(), "about:", 6) == 0);
+    BOOL result = (bytesFilled == 0) || (bytesFilled > 5 && strncmp((char *)buffer, "about:", 6) == 0);
+    free(buffer);
+
+    return result;
 }
 
-void MainResourceLoader::continueAfterContentPolicy(WebPolicyAction contentPolicy, NSURLResponse *r)
+-(void)continueAfterContentPolicy:(WebPolicyAction)contentPolicy response:(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())
-                stopLoadingForPolicyChange();
+            if (!reachedTerminalState) {
+                [self stopLoadingForPolicyChange];
+            }
             return;
         }
         break;
     }
     case WebPolicyDownload:
-        [m_proxy.get() setDelegate:nil];
-        [frameLoader() _downloadWithLoadingConnection:connection() request:request() response:r proxy:m_proxy.get()];
-        m_proxy = nil;
-        receivedError(interruptionForPolicyChangeError());
+        [proxy setDelegate:nil];
+        [frameLoader _downloadWithLoadingConnection:connection request:request response:r proxy:proxy];
+        [proxy release];
+        proxy = nil;
+
+        [self receivedError:[self interruptForPolicyChangeError]];
         return;
 
     case WebPolicyIgnore:
-        stopLoadingForPolicyChange();
+        [self stopLoadingForPolicyChange];
         return;
     
     default:
         ASSERT_NOT_REACHED();
     }
 
-    RefPtr<MainResourceLoader> protect(this);
+    [self retain];
 
     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)
-                cancel();
+                [self cancel];
         }
     }
 
     // we may have cancelled this load as part of switching to fallback content
-    if (!reachedTerminalState())
-        WebResourceLoader::didReceiveResponse(r);
+    if (!reachedTerminalState) {
+        [super didReceiveResponse:r];
+    }
 
-    if (![frameLoader() _isStopping] && (shouldLoadAsEmptyDocument(URL) || [frameLoader() _representationExistsForURLScheme:[URL scheme]]))
-        didFinishLoading();
+    if (![frameLoader _isStopping] && (shouldLoadAsEmptyDocument(URL) || [frameLoader _representationExistsForURLScheme:[URL scheme]])) {
+        [self didFinishLoading];
+    }
+    
+    [self release];
 }
 
-void MainResourceLoader::continueAfterContentPolicy(WebPolicyAction policy)
+-(void)continueAfterContentPolicy:(WebPolicyAction)policy
 {
-    bool isStopping = [frameLoader() _isStopping];
-    [frameLoader() cancelContentPolicy];
+    BOOL isStopping = [frameLoader _isStopping];
+
+    [frameLoader cancelContentPolicy];
     if (!isStopping)
-        continueAfterContentPolicy(policy, m_response.get());
+        [self continueAfterContentPolicy:policy response:_response];
+}
+
+-(void)checkContentPolicy
+{
+    [frameLoader _checkContentPolicyForMIMEType:[_response MIMEType] andCall:self withSelector:@selector(continueAfterContentPolicy:)];
 }
 
-void MainResourceLoader::didReceiveResponse(NSURLResponse *r)
+- (void)didReceiveResponse:(NSURLResponse *)r
 {
-    ASSERT(shouldLoadAsEmptyDocument([r URL]) || !defersCallbacks());
-    ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![frameLoader() defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![self defersCallbacks]);
+    ASSERT(shouldLoadAsEmptyDocument([r URL]) || ![frameLoader defersCallbacks]);
 
-    if (m_loadingMultipartContent) {
-        [frameLoader() _setupForReplaceByMIMEType:[r MIMEType]];
-        clearResourceData();
+    if (loadingMultipartContent) {
+        [frameLoader _setupForReplaceByMIMEType:[r MIMEType]];
+        [self clearResourceData];
     }
     
     if ([[r MIMEType] isEqualToString:@"multipart/x-mixed-replace"])
-        m_loadingMultipartContent = true;
+        loadingMultipartContent = YES;
         
-    // 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:)];
+    // 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];
 }
 
-void MainResourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
+- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
 {
     ASSERT(data);
     ASSERT([data length] != 0);
-    ASSERT(!defersCallbacks());
-    ASSERT(![frameLoader() defersCallbacks]);
+    ASSERT(![self defersCallbacks]);
+    ASSERT(![frameLoader defersCallbacks]);
  
-    // 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);
+    // 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];
 
-    WebResourceLoader::didReceiveData(data, lengthReceived, allAtOnce);
-    m_bytesReceived += [data length];
+    [self release];
 }
 
-void MainResourceLoader::didFinishLoading()
+- (void)didFinishLoading
 {
-    ASSERT(shouldLoadAsEmptyDocument([frameLoader() _URL]) || !defersCallbacks());
-    ASSERT(shouldLoadAsEmptyDocument([frameLoader() _URL]) || ![frameLoader() defersCallbacks]);
+    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];
 
-    // The additional processing can do anything including possibly removing the last
-    // reference to this object.
-    RefPtr<MainResourceLoader> protect(this);
+    [frameLoader _finishedLoading];
+    [super didFinishLoading];
 
-    [frameLoader() _finishedLoading];
-    WebResourceLoader::didFinishLoading();
+    [self release];
 }
 
-void MainResourceLoader::didFail(NSError *error)
+- (void)didFailWithError:(NSError *)error
 {
-    ASSERT(!defersCallbacks());
-    ASSERT(![frameLoader() defersCallbacks]);
+    ASSERT(![self defersCallbacks]);
+    ASSERT(![frameLoader defersCallbacks]);
 
-    receivedError(error);
+    [self receivedError:error];
 }
 
-NSURLRequest *MainResourceLoader::loadNow(NSURLRequest *r)
+- (NSURLRequest *)loadWithRequestNow:(NSURLRequest *)r
 {
-    bool shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument([r URL]);
+    BOOL shouldLoadEmptyBeforeRedirect = shouldLoadAsEmptyDocument([r URL]);
 
-    ASSERT(!connection());
-    ASSERT(shouldLoadEmptyBeforeRedirect || !defersCallbacks());
-    ASSERT(shouldLoadEmptyBeforeRedirect || ![frameLoader() defersCallbacks]);
+    ASSERT(connection == nil);
+    ASSERT(shouldLoadEmptyBeforeRedirect || ![self 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 = willSendRequest(r, nil);
+    r = [self willSendRequest:r redirectResponse:nil];
     NSURL *URL = [r URL];
-    bool shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
+    BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
 
-    if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && defersCallbacks())
+    if (shouldLoadEmptyBeforeRedirect && !shouldLoadEmpty && [self 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];
-        didReceiveResponse(resp);
+        [self didReceiveResponse:resp];
         [resp release];
     } else {
-        NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:r delegate:m_proxy.get()];
-        m_connection = conn;
-        [conn release];
+        connection = [[NSURLConnection alloc] initWithRequest:r delegate:proxy];
     }
 
     return nil;
 }
 
-bool MainResourceLoader::load(NSURLRequest *r)
+- (BOOL)loadWithRequest:(NSURLRequest *)r
 {
-    ASSERT(!connection());
+    ASSERT(connection == nil);
 
-    bool defer = defersCallbacks();
+    BOOL defer = [self defersCallbacks];
     if (defer) {
-        bool shouldLoadEmpty = shouldLoadAsEmptyDocument([r URL]);
-        if (shouldLoadEmpty)
-            defer = false;
+        NSURL *URL = [r URL];
+        BOOL shouldLoadEmpty = shouldLoadAsEmptyDocument(URL);
+        if (shouldLoadEmpty) {
+            defer = NO;
+        }
     }
     if (!defer) {
-        r = loadNow(r);
-        if (r) {
+        r = [self loadWithRequestNow:r];
+        if (r != nil) {
             // Started as an empty document, but was redirected to something non-empty.
-            ASSERT(defersCallbacks());
-            defer = true;
+            ASSERT([self defersCallbacks]);
+            defer = YES;
         }
     }
     if (defer) {
         NSURLRequest *copy = [r copy];
-        m_initialRequest = copy;
-        [copy release];
+        [_initialRequest release];
+        _initialRequest = copy;
     }
 
-    return true;
+    return YES;
 }
 
-void MainResourceLoader::setDefersCallbacks(bool defers)
+- (void)setDefersCallbacks:(BOOL)defers
 {
-    WebResourceLoader::setDefersCallbacks(defers);
+    [super setDefersCallbacks:defers];
     if (!defers) {
-        RetainPtr<NSURLRequest> r = m_initialRequest;
-        if (r) {
-            m_initialRequest = nil;
-            loadNow(r.get());
+        NSURLRequest *r = _initialRequest;
+        if (r != nil) {
+            _initialRequest = nil;
+            [self loadWithRequestNow:r];
+            [r release];
         }
     }
 }
 
-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
index f5b79cb370603917e2b342bbbe48cb0bd887c865..279abb07beeee6a184cada62c701435f9dc3bffe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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>
 
-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;
-    };
+@class WebNetscapePluginStream;
 
+@interface WebNetscapePlugInStreamLoader : WebLoader
+{
+    NSObject<WebPlugInStreamLoaderDelegate> *stream;
 }
+- (id)initWithDelegate:(NSObject <WebPlugInStreamLoaderDelegate> *)theStream frameLoader:(WebFrameLoader *)fl;
+- (BOOL)isDone;
+@end
index bc8163f04a60a88d72d64c61bee4c522ac41daf1..b0ab095d9307b74638c98f714de4f9618ac4cafe 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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>
 
-namespace WebCore {
+@implementation WebNetscapePlugInStreamLoader
 
-NetscapePlugInStreamLoader::NetscapePlugInStreamLoader(WebFrameLoader *fl, id <WebPlugInStreamLoaderDelegate> stream)
-    : WebResourceLoader(fl)
-    , m_stream(stream)
+- (id)initWithDelegate:(NSObject<WebPlugInStreamLoaderDelegate> *)theStream frameLoader:(WebFrameLoader *)fl;
 {
+    [super init];
+    stream = [theStream retain];
+    [self setFrameLoader:fl];
+    return self;
 }
 
-NetscapePlugInStreamLoader::~NetscapePlugInStreamLoader()
+- (BOOL)isDone
 {
+    return stream == nil;
 }
 
-PassRefPtr<NetscapePlugInStreamLoader> NetscapePlugInStreamLoader::create(WebFrameLoader* fl, id <WebPlugInStreamLoaderDelegate> d)
+- (void)releaseResources
 {
-    return new NetscapePlugInStreamLoader(fl, d);
+    [stream release];
+    stream = nil;
+    [super releaseResources];
 }
 
-bool NetscapePlugInStreamLoader::isDone() const
+- (void)didReceiveResponse:(NSURLResponse *)theResponse
 {
-    return !m_stream;
-}
-
-void NetscapePlugInStreamLoader::releaseResources()
-{
-    m_stream = nil;
-    WebResourceLoader::releaseResources();
-}
-
-void NetscapePlugInStreamLoader::didReceiveResponse(NSURLResponse *theResponse)
-{
-    // 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);
-
-    [m_stream.get() startStreamWithResponse:theResponse];
+    // 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 (!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];
+    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];
 }
 
-void NetscapePlugInStreamLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
+- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
 {
-    // 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);
-
-    [m_stream.get() receivedData:data];
-    WebResourceLoader::didReceiveData(data, lengthReceived, 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];
+    [stream receivedData:data];
+    [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:(BOOL)allAtOnce];
+    [self release];
 }
 
-void NetscapePlugInStreamLoader::didFinishLoading()
+- (void)didFinishLoading
 {
-    // Calling removePlugInStreamLoader will likely result in a call to deref, so we must protect.
-    RefPtr<NetscapePlugInStreamLoader> protect(this);
+    // 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];
 
-    [frameLoader() removePlugInStreamLoader:this];
-    [frameLoader() _finishedLoadingResource];
-    [m_stream.get() finishedLoadingWithData:resourceData()];
-    WebResourceLoader::didFinishLoading();
+    [self release];
 }
 
-void NetscapePlugInStreamLoader::didFail(NSError *error)
+- (void)didFailWithError:(NSError *)error
 {
-    // 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);
+    // 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];
+
+    [[self frameLoader] removePlugInStreamLoader:self];
+    [[self frameLoader] _receivedError:error];
+    [stream destroyStreamWithError:error];
+    [super didFailWithError:error];
+
+    [self release];
 }
 
-void NetscapePlugInStreamLoader::cancel(NSError *error)
+- (void)cancelWithError:(NSError *)error
 {
-    // Calling removePlugInStreamLoader will likely result in a call to deref, so we must protect.
-    RefPtr<NetscapePlugInStreamLoader> protect(this);
+    // Calling _removePlugInStreamLoader will likely result in a call to release, so we must retain.
+    [self retain];
 
-    [frameLoader() removePlugInStreamLoader:this];
-    [m_stream.get() destroyStreamWithError:error];
-    WebResourceLoader::cancel(error);
-}
+    [[self frameLoader] removePlugInStreamLoader:self];
+    [stream destroyStreamWithError:error];
+    [super cancelWithError:error];
 
+    [self release];
 }
+
+@end
index 812b6e267232dd1b425a72ccded54c87a5401950..51f797d6baad9a7d2b4bc5f5c009d625419d775b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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"
-
-namespace WebCore {
-
-    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);
 
-        virtual ~SubresourceLoader();
+#import "WebCoreResourceLoader.h"
 
-        virtual void signalFinish();
-        virtual void cancel();
+@class WebFrameLoader;
 
-        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 *);
+@protocol WebCoreResourceHandle;
+@protocol WebCoreResourceLoader;
 
-    private:
-        static id <WebCoreResourceHandle> create(WebFrameLoader *, id <WebCoreResourceLoader>,
-            NSMutableURLRequest *, NSString *method, NSDictionary *customHeaders, NSString *referrer);
+@interface WebSubresourceLoader : WebLoader <WebCoreResourceHandle>
+{
+    id <WebCoreResourceLoader> coreLoader;
+}
 
-        SubresourceLoader(WebFrameLoader *, id <WebCoreResourceLoader>);
-        id <WebCoreResourceHandle> handle();
+- (void)signalFinish;
 
-        void receivedError(NSError *error);
++ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
+                                    withMethod:(NSString *)method
+                                           URL:(NSURL *)URL 
+                                 customHeaders:(NSDictionary *)customHeaders
+                                      referrer:(NSString *)referrer 
+                                forFrameLoader:(WebFrameLoader *)loader;
 
-        RetainPtr<id <WebCoreResourceLoader> > m_coreLoader;
-        bool m_loadingMultipartContent;
-    };
++ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
+                                    withMethod:(NSString *)method
+                                           URL:(NSURL *)URL 
+                                 customHeaders:(NSDictionary *)customHeaders
+                                      postData:(NSArray *)postData 
+                                      referrer:(NSString *)referrer 
+                                forFrameLoader:(WebFrameLoader *)loader;
 
-}
+@end
index f30f42f4a564e69e18b2bba1f41185739e613e4d..9d843199641e82f4bf90ddebf34a9ee51fdaaa73 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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"
 
-using namespace WebCore;
+@implementation WebSubresourceLoader
 
-@interface WebCoreSubresourceHandle : NSObject <WebCoreResourceHandle>
+- initWithLoader:(id <WebCoreResourceLoader>)l frameLoader:(WebFrameLoader *)fl
 {
-    SubresourceLoader* m_loader;
-}
-- (id)initWithLoader:(SubresourceLoader*)loader;
-@end
-
-namespace WebCore {
+    [super init];
+    
+    coreLoader = [l retain];
 
-SubresourceLoader::SubresourceLoader(WebFrameLoader *fl, id <WebCoreResourceLoader> l)
-    : WebResourceLoader(fl)
-    , m_coreLoader(l)
-    , m_loadingMultipartContent(false)
-{
-    [fl addSubresourceLoader:this];
+    [self setFrameLoader:fl];
+    
+    return self;
 }
 
-SubresourceLoader::~SubresourceLoader()
+- (void)dealloc
 {
+    [coreLoader release];
+    [super dealloc];
 }
 
-id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
-    NSMutableURLRequest *newRequest, NSString *method, NSDictionary *customHeaders, NSString *referrer)
++ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
+                                   withRequest:(NSMutableURLRequest *)newRequest
+                                 customHeaders:(NSDictionary *)customHeaders
+                                      referrer:(NSString *)referrer 
+                                forFrameLoader:(WebFrameLoader *)fl
 {
     if ([fl state] == WebFrameStateProvisional)
         return nil;
-
-    // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
-    if (![method isEqualToString:@"GET"])
-        [newRequest setHTTPMethod:method];
-
+        
     wkSupportsMultipartXMixedReplace(newRequest);
 
+    WebSubresourceLoader *loader = [[[self alloc] initWithLoader:rLoader frameLoader:fl] autorelease];
+    
+    [fl addSubresourceLoader:loader];
+
     NSEnumerator *e = [customHeaders keyEnumerator];
     NSString *key;
     while ((key = [e nextObject]))
@@ -91,164 +90,160 @@ id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <Web
     setHTTPReferrer(newRequest, referrer);
     
     [fl addExtraFieldsToRequest:newRequest mainResource:NO alwaysFromRequest:NO];
-
-    RefPtr<SubresourceLoader> loader(new SubresourceLoader(fl, rLoader));
-    if (!loader->load(newRequest))
-        return nil;
-    return loader->handle();
+            
+    if (![loader loadWithRequest:newRequest])
+        loader = nil;
+    
+    return loader;
 }
 
-id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
-    NSString *method, NSURL *URL, NSDictionary *customHeaders, NSString *referrer)
++ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
+                                    withMethod:(NSString *)method 
+                                           URL:(NSURL *)URL
+                                 customHeaders:(NSDictionary *)customHeaders
+                                      referrer:(NSString *)referrer
+                                 forFrameLoader:(WebFrameLoader *)fl
 {
     NSMutableURLRequest *newRequest = [[NSMutableURLRequest alloc] initWithURL:URL];
-    id <WebCoreResourceHandle> handle = create(fl, rLoader, newRequest, method, customHeaders, referrer);
+
+    // 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];
     [newRequest release];
-    return handle;
+
+    return loader;
 }
 
-id <WebCoreResourceHandle> SubresourceLoader::create(WebFrameLoader *fl, id <WebCoreResourceLoader> rLoader,
-    NSString *method, NSURL *URL, NSDictionary *customHeaders, NSArray *postData, NSString *referrer)
++ (WebSubresourceLoader *)startLoadingResource:(id <WebCoreResourceLoader>)rLoader
+                                    withMethod:(NSString *)method 
+                                           URL:(NSURL *)URL
+                                 customHeaders:(NSDictionary *)customHeaders
+                                      postData:(NSArray *)postData
+                                      referrer:(NSString *)referrer
+                                forFrameLoader:(WebFrameLoader *)fl
 {
     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);
-    id <WebCoreResourceHandle> handle = create(fl, rLoader, newRequest, method, customHeaders, referrer);
+
+    WebSubresourceLoader *loader = [self startLoadingResource:rLoader withRequest:newRequest customHeaders:customHeaders referrer:referrer forFrameLoader:fl];
     [newRequest release];
-    return handle;
+
+    return loader;
+
 }
 
-void SubresourceLoader::receivedError(NSError *error)
+- (void)receivedError:(NSError *)error
 {
-    [frameLoader() _receivedError:error];
+    [frameLoader _receivedError:error];
 }
 
-NSURLRequest *SubresourceLoader::willSendRequest(NSURLRequest *newRequest, NSURLResponse *redirectResponse)
+- (NSURLRequest *)willSendRequest:(NSURLRequest *)newRequest redirectResponse:(NSURLResponse *)redirectResponse;
 {
-    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]];
+    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]];
+
     return clientRequest;
 }
 
-void SubresourceLoader::didReceiveResponse(NSURLResponse *r)
+- (void)didReceiveResponse:(NSURLResponse *)r
 {
     ASSERT(r);
 
     if ([[r MIMEType] isEqualToString:@"multipart/x-mixed-replace"])
-        m_loadingMultipartContent = true;
+        loadingMultipartContent = YES;
 
-    // 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];
+    // 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];
     // The coreLoader can cancel a load if it receives a multipart response for a non-image
-    if (reachedTerminalState())
+    if (reachedTerminalState) {
+        [self release];
         return;
-    WebResourceLoader::didReceiveResponse(r);
+    }
+    [super didReceiveResponse:r];
+    [self release];
     
-    if (m_loadingMultipartContent && [resourceData() length]) {
+    if (loadingMultipartContent && [[self resourceData] length]) {
         // A subresource loader does not load multipart sections progressively, deliver the previously received data to the coreLoader all at once
-        [m_coreLoader.get() addData:resourceData()];
-
+        [coreLoader addData:[self resourceData]];
         // Clears the data to make way for the next multipart section
-        clearResourceData();
+        [self clearResourceData];
         
         // After the first multipart section is complete, signal to delegates that this load is "finished" 
-        if (!signalledFinish())
-            signalFinish();
+        if (!signalledFinish)
+            [self signalFinish];
     }
 }
 
-void SubresourceLoader::didReceiveData(NSData *data, long long lengthReceived, bool allAtOnce)
+- (void)didReceiveData:(NSData *)data lengthReceived:(long long)lengthReceived allAtOnce:(BOOL)allAtOnce
 {
-    // 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);
-
+    // 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];
     // A subresource loader does not load multipart sections progressively, don't deliver any data to the coreLoader yet
-    if (!m_loadingMultipartContent)
-        [m_coreLoader.get() addData:data];
-    WebResourceLoader::didReceiveData(data, lengthReceived, allAtOnce);
+    if (!loadingMultipartContent)
+        [coreLoader addData:data];
+    [super didReceiveData:data lengthReceived:lengthReceived allAtOnce:allAtOnce];
+    [self release];
 }
 
-void SubresourceLoader::signalFinish()
+- (void)signalFinish
 {
-    [frameLoader() removeSubresourceLoader:this];
-    [frameLoader() _finishedLoadingResource];
-    WebResourceLoader::signalFinish();
+    [frameLoader removeSubresourceLoader:self];
+    [frameLoader _finishedLoadingResource];
+    [super signalFinish];
 }
 
-void SubresourceLoader::didFinishLoading()
+- (void)didFinishLoading
 {
-    // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
-    RefPtr<SubresourceLoader> protect(this);
+    // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
+    [self retain];
     
-    [m_coreLoader.get() finishWithData:resourceData()];
+    [coreLoader finishWithData:[self resourceData]];
     
-    if (!signalledFinish())
-        signalFinish();
-        
-    WebResourceLoader::didFinishLoading();
-}
-
-void SubresourceLoader::didFail(NSError *error)
-{
-    // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
-    RefPtr<SubresourceLoader> protect(this);
-    
-    [m_coreLoader.get() reportError];
-    [frameLoader() removeSubresourceLoader:this];
-    receivedError(error);
-    WebResourceLoader::didFail(error);
-}
-
-void SubresourceLoader::cancel()
-{
-    // Calling removeSubresourceLoader will likely result in a call to deref, so we must protect ourselves.
-    RefPtr<SubresourceLoader> protect(this);
+    if (!signalledFinish)
+        [self signalFinish];
         
-    [m_coreLoader.get() cancel];
-    [frameLoader() removeSubresourceLoader:this];
-    receivedError(cancelledError());
-    WebResourceLoader::cancel();
-}
+    [super didFinishLoading];
 
-id <WebCoreResourceHandle> SubresourceLoader::handle()
-{
-    return [[[WebCoreSubresourceHandle alloc] initWithLoader:this] autorelease];
+    [self release];    
 }
 
-}
-
-@implementation WebCoreSubresourceHandle
-
-- (id)initWithLoader:(SubresourceLoader*)loader
+- (void)didFailWithError:(NSError *)error
 {
-    self = [self init];
-    if (!self)
-        return nil;
-    loader->ref();
-    m_loader = loader;
-    return self;
-}
-
-- (void)dealloc
-{
-    m_loader->deref();
-    [super dealloc];
-}
+    // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
+    [self retain];
+    
+    [coreLoader reportError];
+    [frameLoader removeSubresourceLoader:self];
+    [self receivedError:error];
+    [super didFailWithError:error];
 
-- (void)finalize
-{
-    m_loader->deref();
-    [super finalize];
+    [self release];
 }
 
 - (void)cancel
 {
-    m_loader->cancel();
+    // Calling _removeSubresourceLoader will likely result in a call to release, so we must retain.
+    [self retain];
+        
+    [coreLoader cancel];
+    [frameLoader removeSubresourceLoader:self];
+    [self receivedError:[self cancelledError]];
+    [super cancel];
+
+    [self release];
 }
 
 @end
index b9153c7e005852f9315ab9e10cab60e49090294e..ef6613dde41a44d02064a39dc62deb31b3eca088 100644 (file)
@@ -26,7 +26,7 @@
 #include <algorithm>
 #include <CoreFoundation/CoreFoundation.h>
 
-namespace WebCore {
+namespace WTF {
 
     template <typename T> struct RemovePointer {
         typedef T type;
@@ -177,6 +177,10 @@ namespace WebCore {
         return p.get();
     }
 
-}
+} // namespace WTF
+
+using WTF::RetainPtr;
+using WTF::static_pointer_cast;
+using WTF::const_pointer_cast;
 
 #endif // RETAINPTR_H_
index 3f3ab03eba76958c028e551f0bb63719ece788a0..1ed68ae5b7d3c5d75be360d9032cf7bb1df79a12 100644 (file)
@@ -1,3 +1,7 @@
+2006-10-20  Darin Adler  <darin@apple.com>
+
+        - rolled out my loader change; caused world leak and possibly a plug-in crash
+
 2006-10-20  Darin Adler  <darin@apple.com>
 
         Reviewed by Adele.
index d2e2190f8fa6c87fb9210e788caa80f6aeba45b2..8b318b971302d5e3b8bb7e1cf536a3e5ea0fc5d9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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/WebBaseNetscapePluginStream.h>
-#import <WebKit/npapi.h>
 
-#if __cplusplus
-namespace WebCore {
-    class NetscapePlugInStreamLoader;
-}
-typedef WebCore::NetscapePlugInStreamLoader WebCoreNetscapePlugInStreamLoader;
-#else
-@class WebCoreNetscapePlugInStreamLoader;
-#endif
+#import <WebKit/npapi.h>
+#import <WebKit/WebBaseNetscapePluginStream.h>
 
 @class NSURLRequest;
 @class NSURLConnection;
+@class WebNetscapePlugInStreamLoader;
+
 
 @interface WebNetscapePluginStream : WebBaseNetscapePluginStream 
 {    
-    WebCoreNetscapePlugInStreamLoader *_loader;
+    WebNetscapePlugInStreamLoader *_loader;
     NSURLRequest *request;
 }
 
index 0d9d16aca57cf285ae8cc1a28e5f9a9701811693..b53018641bc8cf0b9376d922dc8aa65eb938159c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005, 2006 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2005 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 <Foundation/NSURLConnection.h>
-#import <WebCore/WebFrameLoader.h>
-#import <WebCore/WebNetscapePlugInStreamLoader.h>
-#import <WebKit/WebDataSourceInternal.h>
 #import <WebKit/WebFrameBridge.h>
+#import <WebKit/WebDataSourceInternal.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 <wtf/PassRefPtr.h>
+#import <WebCore/WebFrameLoader.h>
 
-using namespace WebCore;
+#import <Foundation/NSURLConnection.h>
 
 @implementation WebNetscapePluginStream
 
@@ -69,10 +67,11 @@ using namespace WebCore;
     isTerminated = YES;
     
     request = [theRequest mutableCopy];
-    if (hideReferrer)
+    if (hideReferrer) {
         [(NSMutableURLRequest *)request _web_setHTTPReferrer:nil];
+    }
 
-    _loader = NetscapePlugInStreamLoader::create([[view webFrame] _frameLoader], self).release();
+    _loader = [[WebNetscapePlugInStreamLoader alloc] initWithDelegate:self frameLoader:[[view webFrame] _frameLoader]]; 
     
     isTerminated = NO;
 
@@ -81,38 +80,33 @@ using namespace WebCore;
 
 - (void)dealloc
 {
-    if (_loader)
-        _loader->deref();
+    [_loader release];
     [request release];
     [super dealloc];
 }
 
-- (void)finalize
-{
-    if (_loader)
-        _loader->deref();
-    [super finalize];
-}
-
 - (void)start
 {
     ASSERT(request);
 
-    [_loader->frameLoader() addPlugInStreamLoader:_loader];
+    [[_loader frameLoader] addPlugInStreamLoader:_loader];
 
-    if (!_loader->load(request))
-        [_loader->frameLoader() removePlugInStreamLoader:_loader];
+    BOOL succeeded = [_loader loadWithRequest:request];
+    if (!succeeded) {
+        [[_loader frameLoader] removePlugInStreamLoader:_loader];
+    }
 }
 
 - (void)cancelLoadWithError:(NSError *)error
 {
-    if (!_loader->isDone())
-        _loader->cancel(error);
+    if (![_loader isDone]) {
+        [_loader cancelWithError:error];
+    }
 }
 
 - (void)stop
 {
-    [self cancelLoadAndDestroyStreamWithError:_loader->cancelledError()];
+    [self cancelLoadAndDestroyStreamWithError:[_loader cancelledError]];
 }
 
 @end
index 3b8d1ea3884fac932c970703c7feeae47373664d..17387e8f00503871ed37289cf10a1d200a38c6b8 100644 (file)
 - (jobject)pollForAppletInWindow:(NSWindow *)window;
 @end
 
-using namespace WebCore;
-
 NSString *WebPluginBaseURLKey =     @"WebPluginBaseURL";
 NSString *WebPluginAttributesKey =  @"WebPluginAttributes";
 NSString *WebPluginContainerKey =   @"WebPluginContainer";
@@ -1417,7 +1415,7 @@ static id <WebFormDelegate> formDelegate(WebFrameBridge *self)
 
 - (BOOL)canRunModalNow
 {
-    return [self canRunModal] && !WebResourceLoader::inConnectionCallback();
+    return [self canRunModal] && ![WebLoader inConnectionCallback];
 }
 
 - (void)runModal
index 00f08a10f35c17b4371cd09bf23e7ad7eade6e12..d74e57384bc2c774a4f40bf08297ad4091aaa3df 100644 (file)
@@ -75,7 +75,6 @@
 #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:
@@ -109,10 +108,6 @@ Repeat load of the same URL (by any other means of navigation other than the rel
  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";
@@ -149,7 +144,7 @@ NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
     NSMutableSet *plugInViews;
     NSMutableSet *inspectors;
 
-    ResourceMap* pendingArchivedResources;
+    NSMutableDictionary *pendingArchivedResources;
 }
 
 - (void)setWebFrameView:(WebFrameView *)v;
@@ -175,18 +170,11 @@ NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
     ASSERT(plugInViews == nil);
     [inspectors release];
 
-    delete pendingArchivedResources;
+    [pendingArchivedResources release];
 
     [super dealloc];
 }
 
-- (void)finalize
-{
-    delete pendingArchivedResources;
-
-    [super finalize];
-}
-
 - (void)setWebFrameView:(WebFrameView *)v 
 { 
     [v retain];
@@ -217,7 +205,7 @@ NSString *WebPageCacheDocumentViewKey = @"WebPageCacheDocumentViewKey";
 
 @end
 
-static inline WebFrame *frame(WebCoreFrameBridge *bridge)
+static inline WebFrame *Frame(WebCoreFrameBridge *bridge)
 {
     return [(WebFrameBridge *)bridge webFrame];
 }
@@ -226,12 +214,12 @@ static inline WebFrame *frame(WebCoreFrameBridge *bridge)
 
 - (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
@@ -241,17 +229,17 @@ static inline WebFrame *frame(WebCoreFrameBridge *bridge)
 
 - (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
@@ -355,7 +343,7 @@ static inline WebFrame *frame(WebCoreFrameBridge *bridge)
 
 - (WebFrame *)_immediateChildFrameNamed:(NSString *)name
 {
-    return frame([[self _bridge] childFrameNamed:name]);
+    return Frame([[self _bridge] childFrameNamed:name]);
 }
 
 - (BOOL)_canCachePage
@@ -805,13 +793,13 @@ static inline WebFrame *frame(WebCoreFrameBridge *bridge)
 // 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
@@ -1241,12 +1229,12 @@ static inline WebDataSource *dataSource(WebDocumentLoader *loader)
 
 - (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
@@ -1696,7 +1684,7 @@ static inline WebPolicyDecisionListener *decisionListener(WebPolicyDecider *deci
 
 - (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
@@ -1962,18 +1950,14 @@ static inline WebPolicyDecisionListener *decisionListener(WebPolicyDecider *deci
 
 - (void)_deliverArchivedResourcesAfterDelay
 {
-    if (!_private->pendingArchivedResources)
-        return;
-    if (_private->pendingArchivedResources->isEmpty())
-        return;
-    if ([[self _frameLoader] defersCallbacks])
+    if (![_private->pendingArchivedResources count] || [[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:(WebResourceLoader*)loader
+- (BOOL)_willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebLoader *)loader
 {
     if (![[r URL] isEqual:originalURL])
         return NO;
@@ -1985,60 +1969,48 @@ static inline WebPolicyDecisionListener *decisionListener(WebPolicyDecider *deci
     if (![self _canUseResourceWithResponse:[resource _response]])
         return NO;
     if (!_private->pendingArchivedResources)
-        _private->pendingArchivedResources = new ResourceMap;
-    _private->pendingArchivedResources->set(loader, resource);
+        _private->pendingArchivedResources = [[NSMutableDictionary alloc] init];
+    [_private->pendingArchivedResources _webkit_setObject:resource forUncopiedKey:loader];
     // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
     [self _deliverArchivedResourcesAfterDelay];
     return YES;
 }
 
-- (BOOL)_archiveLoadPendingForLoader:(WebResourceLoader*)loader
+- (BOOL)_archiveLoadPendingForLoader:(WebLoader *)loader
 {
-    if (!_private->pendingArchivedResources)
-        return false;
-    return _private->pendingArchivedResources->contains(loader);
+    return [_private->pendingArchivedResources objectForKey:loader] != nil;
 }
 
-- (void)_cancelPendingArchiveLoadForLoader:(WebResourceLoader*)loader
+- (void)_cancelPendingArchiveLoadForLoader:(WebLoader *)loader
 {
-    if (!_private->pendingArchivedResources)
-        return;
-    if (_private->pendingArchivedResources->isEmpty())
-        return;
-    _private->pendingArchivedResources->remove(loader);
-    if (_private->pendingArchivedResources->isEmpty())
+    [_private->pendingArchivedResources removeObjectForKey:loader];
+    
+    if (![_private->pendingArchivedResources count])
         [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
 }
 
 - (void)_clearArchivedResources
 {
-    if (_private->pendingArchivedResources)
-        _private->pendingArchivedResources->clear();
+    [_private->pendingArchivedResources removeAllObjects];
     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
 }
 
 - (void)_deliverArchivedResources
 {
-    if (!_private->pendingArchivedResources)
+    if (![_private->pendingArchivedResources count] || [[self _frameLoader] defersCallbacks])
         return;
-    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();
+        
+    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];
     }
+    
+    [_private->pendingArchivedResources removeAllObjects];
 }
 
 - (void)_setDefersCallbacks:(BOOL)defers