Skip to content

Commit

Permalink
Fixed a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Suter committed Jul 15, 2009
1 parent 97ec6c1 commit 3b7739e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 26 deletions.
2 changes: 2 additions & 0 deletions ClickToFlash.xcodeproj/project.pbxproj
Expand Up @@ -232,8 +232,10 @@
A494CC2B0F9F2446007D5EEB /* ctf.icns */,
D9566C2B0F37EA0800358646 /* deSIFR Resources */,
);
indentWidth = 4;
name = Plugin;
sourceTree = "<group>";
tabWidth = 4;
};
55EB70550E04A8A40016593D /* Frameworks */ = {
isa = PBXGroup;
Expand Down
26 changes: 15 additions & 11 deletions Plugin/CTFURLConnection.m
Expand Up @@ -36,7 +36,9 @@ - (NSHTTPURLResponse *)getURLResponseHeaders:(NSURL *)URL
[request release];

[theLock lockWhenCondition:1];
[theLock unlock];
if (error) (*error) = errorToReturn;


return [responseToReturn autorelease];
}
Expand All @@ -53,34 +55,37 @@ + (NSHTTPURLResponse *)getURLResponseHeaders:(NSURL *)URL

- (void)startRequest:(NSURLRequest *)request;
{

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[request retain];

NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:YES];
[[NSRunLoop currentRunLoop] run];

NSRunLoop *rl = [NSRunLoop currentRunLoop];

while ([rl runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) {
if ([theLock tryLockWhenCondition:1]) {
[theLock unlock];
break;
}
}

[connection release];

[request release];
[pool drain];

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;
{

[theLock tryLock];
[theLock lock];

errorToReturn = error;
[theLock unlockWithCondition:1];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse *)theResponse;
{

[theLock tryLock];
[theLock lock];

// we cancel here, because otherwise NSURLConnection will continue to download
// data due to a bug; even though we made a HEAD request, it still downloads
Expand All @@ -93,8 +98,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLRe

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{

[theLock tryLock];
[theLock lock];

[theLock unlockWithCondition:1];
}
Expand Down
39 changes: 24 additions & 15 deletions Plugin/Plugin.m
Expand Up @@ -381,26 +381,35 @@ - (id) initWithArguments:(NSDictionary *)arguments
return self;
}

- (void) dealloc
- (void)webPlugInDestroy
{
[self _removeTrackingAreaForCTF];
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self _removeTrackingAreaForCTF];
[NSObject cancelPreviousPerformRequestsWithTarget:self];

[self _abortAlert]; // to be on the safe side

// notify that this ClickToFlash plugin is going away
[[CTFMenubarMenuController sharedController] unregisterView: self];

[self setContainer:nil];
[self setHost:nil];
[self setWebView:nil];
[self setBaseURL:nil];
[self setAttributes:nil];

[_flashVars release];
[_badgeText release];

[[NSNotificationCenter defaultCenter] removeObserver: self];
[[CTFMenubarMenuController sharedController] unregisterView:self];

[self setContainer:nil];
[self setHost:nil];
[self setWebView:nil];
[self setBaseURL:nil];
[self setAttributes:nil];

[_flashVars release];
_flashVars = nil;
[_badgeText release];
_badgeText = nil;

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void) dealloc
{
// Just in case...
[self webPlugInDestroy];

#if LOGGING_ENABLED
NSLog(@"ClickToFlash:\tdealloc");
#endif
Expand Down

0 comments on commit 3b7739e

Please sign in to comment.