summaryrefslogtreecommitdiffstats
path: root/WebKit/mac/Panels
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/mac/Panels')
-rw-r--r--WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/classes.nib38
-rw-r--r--WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/info.nib16
-rw-r--r--WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/objects.nibbin0 -> 2931 bytes
-rw-r--r--WebKit/mac/Panels/WebAuthenticationPanel.h68
-rw-r--r--WebKit/mac/Panels/WebAuthenticationPanel.m244
-rw-r--r--WebKit/mac/Panels/WebPanelAuthenticationHandler.h45
-rw-r--r--WebKit/mac/Panels/WebPanelAuthenticationHandler.m164
7 files changed, 575 insertions, 0 deletions
diff --git a/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/classes.nib b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/classes.nib
new file mode 100644
index 0000000..87a7210
--- /dev/null
+++ b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/classes.nib
@@ -0,0 +1,38 @@
+{
+ IBClasses = (
+ {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
+ {
+ ACTIONS = {cancel = id; logIn = id; };
+ CLASS = IFAuthenticationPanel;
+ LANGUAGE = ObjC;
+ OUTLETS = {
+ imageView = id;
+ mainLabel = id;
+ panel = id;
+ password = id;
+ remember = id;
+ smallLabel = id;
+ username = id;
+ };
+ SUPERCLASS = NSObject;
+ },
+ {CLASS = NonBlockingPanel; LANGUAGE = ObjC; SUPERCLASS = NSPanel; },
+ {
+ ACTIONS = {cancel = id; logIn = id; };
+ CLASS = WebAuthenticationPanel;
+ LANGUAGE = ObjC;
+ OUTLETS = {
+ callback = id;
+ imageView = id;
+ mainLabel = id;
+ panel = id;
+ password = id;
+ remember = id;
+ smallLabel = id;
+ username = id;
+ };
+ SUPERCLASS = NSObject;
+ }
+ );
+ IBVersion = 1;
+} \ No newline at end of file
diff --git a/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/info.nib b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/info.nib
new file mode 100644
index 0000000..eb229b0
--- /dev/null
+++ b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/info.nib
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IBDocumentLocation</key>
+ <string>773 144 356 240 0 0 1280 778 </string>
+ <key>IBFramework Version</key>
+ <string>446.1</string>
+ <key>IBOpenObjects</key>
+ <array>
+ <integer>5</integer>
+ </array>
+ <key>IBSystem Version</key>
+ <string>8N1106</string>
+</dict>
+</plist>
diff --git a/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/objects.nib b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/objects.nib
new file mode 100644
index 0000000..59196ff
--- /dev/null
+++ b/WebKit/mac/Panels/English.lproj/WebAuthenticationPanel.nib/objects.nib
Binary files differ
diff --git a/WebKit/mac/Panels/WebAuthenticationPanel.h b/WebKit/mac/Panels/WebAuthenticationPanel.h
new file mode 100644
index 0000000..3e08857
--- /dev/null
+++ b/WebKit/mac/Panels/WebAuthenticationPanel.h
@@ -0,0 +1,68 @@
+/*
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Foundation/NSURLCredentialStorage.h>
+
+@class NSURLAuthenticationChallenge;
+
+@interface WebAuthenticationPanel : NSObject
+{
+ IBOutlet id mainLabel;
+ IBOutlet id panel;
+ IBOutlet id password;
+ IBOutlet id smallLabel;
+ IBOutlet id username;
+ IBOutlet id imageView;
+ IBOutlet id remember;
+ BOOL nibLoaded;
+ BOOL usingSheet;
+ id callback;
+ SEL selector;
+ NSURLAuthenticationChallenge *challenge;
+}
+
+-(id)initWithCallback:(id)cb selector:(SEL)sel;
+
+// Interface-related methods
+- (IBAction)cancel:(id)sender;
+- (IBAction)logIn:(id)sender;
+
+- (BOOL)loadNib;
+
+- (void)runAsModalDialogWithChallenge:(NSURLAuthenticationChallenge *)chall;
+- (void)runAsSheetOnWindow:(NSWindow *)window withChallenge:(NSURLAuthenticationChallenge *)chall;
+
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;
+
+@end
+
+// This is in the header so it can be used from the nib file
+@interface NonBlockingPanel : NSPanel
+@end
+
diff --git a/WebKit/mac/Panels/WebAuthenticationPanel.m b/WebKit/mac/Panels/WebAuthenticationPanel.m
new file mode 100644
index 0000000..4e17536
--- /dev/null
+++ b/WebKit/mac/Panels/WebAuthenticationPanel.m
@@ -0,0 +1,244 @@
+/*
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WebAuthenticationPanel.h>
+
+#import <Foundation/NSURLAuthenticationChallenge.h>
+#import <Foundation/NSURLProtectionSpace.h>
+#import <Foundation/NSURLCredential.h>
+#import <WebKit/WebLocalizableStrings.h>
+#import <WebKit/WebNSURLExtras.h>
+#import <wtf/Assertions.h>
+
+#import <WebKit/WebNSControlExtras.h>
+
+#define WebAuthenticationPanelNibName @"WebAuthenticationPanel"
+
+@implementation WebAuthenticationPanel
+
+-(id)initWithCallback:(id)cb selector:(SEL)sel
+{
+ self = [self init];
+ if (self != nil) {
+ callback = [cb retain];
+ selector = sel;
+ }
+ return self;
+}
+
+
+- (void)dealloc
+{
+ [panel release];
+
+ [callback release];
+
+ [super dealloc];
+}
+
+// IB actions
+
+- (IBAction)cancel:(id)sender
+{
+ // This is required because the body of this method is going to
+ // remove all of the panel's remaining refs, which can cause a
+ // crash later when finishing button hit tracking. So we make
+ // sure it lives on a bit longer.
+ [[panel retain] autorelease];
+
+ // This is required as a workaround for AppKit issue 4118422
+ [[self retain] autorelease];
+
+ [panel close];
+ if (usingSheet) {
+ [[NSApplication sharedApplication] endSheet:panel returnCode:1];
+ } else {
+ [[NSApplication sharedApplication] stopModalWithCode:1];
+ }
+}
+
+- (IBAction)logIn:(id)sender
+{
+ // This is required because the body of this method is going to
+ // remove all of the panel's remaining refs, which can cause a
+ // crash later when finishing button hit tracking. So we make
+ // sure it lives on a bit longer.
+ [[panel retain] autorelease];
+
+ [panel close];
+ if (usingSheet) {
+ [[NSApplication sharedApplication] endSheet:panel returnCode:0];
+ } else {
+ [[NSApplication sharedApplication] stopModalWithCode:0];
+ }
+}
+
+- (BOOL)loadNib
+{
+ if (!nibLoaded) {
+ if ([NSBundle loadNibNamed:WebAuthenticationPanelNibName owner:self]) {
+ nibLoaded = YES;
+ [imageView setImage:[NSImage imageNamed:@"NSApplicationIcon"]];
+ } else {
+ LOG_ERROR("couldn't load nib named '%@'", WebAuthenticationPanelNibName);
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+// Methods related to displaying the panel
+
+-(void)setUpForChallenge:(NSURLAuthenticationChallenge *)chall
+{
+ [self loadNib];
+
+ NSURLProtectionSpace *space = [chall protectionSpace];
+
+ NSString *host;
+ if ([space port] == 0) {
+ host = [[space host] _web_decodeHostName];
+ } else {
+ host = [NSString stringWithFormat:@"%@:%u", [[space host] _web_decodeHostName], [space port]];
+ }
+
+ NSString *realm = [space realm];
+ NSString *message;
+
+ if ([chall previousFailureCount] == 0) {
+ if ([space isProxy]) {
+ message = [NSString stringWithFormat:UI_STRING("To view this page, you need to log in to the %@ proxy server %@.",
+ "prompt string in authentication panel"),
+ [space proxyType], host];
+ } else {
+ message = [NSString stringWithFormat:UI_STRING("To view this page, you need to log in to area “%@” on %@.",
+ "prompt string in authentication panel"),
+ realm, host];
+ }
+ } else {
+ if ([space isProxy]) {
+ message = [NSString stringWithFormat:UI_STRING("The name or password entered for the %@ proxy server %@ was incorrect. Please try again.",
+ "prompt string in authentication panel"),
+ [space proxyType], host];
+ } else {
+ message = [NSString stringWithFormat:UI_STRING("The name or password entered for area “%@” on %@ was incorrect. Please try again.",
+ "prompt string in authentication panel"),
+ realm, host];
+ }
+ }
+
+ [mainLabel setStringValue:message];
+ [mainLabel sizeToFitAndAdjustWindowHeight];
+
+ if ([space receivesCredentialSecurely]) {
+ [smallLabel setStringValue:
+ UI_STRING("Your log-in information will be sent securely.",
+ "message in authentication panel")];
+ } else {
+ [smallLabel setStringValue:
+ UI_STRING("Your password will be sent in the clear.",
+ "message in authentication panel")];
+ }
+
+ if ([[chall proposedCredential] user] != nil) {
+ [username setStringValue:[[chall proposedCredential] user]];
+ [panel setInitialFirstResponder:password];
+ } else {
+ [username setStringValue:@""];
+ [password setStringValue:@""];
+ [panel setInitialFirstResponder:username];
+ }
+}
+
+- (void)runAsModalDialogWithChallenge:(NSURLAuthenticationChallenge *)chall
+{
+ [self setUpForChallenge:chall];
+ usingSheet = FALSE;
+ NSURLCredential *credential = nil;
+
+ if ([[NSApplication sharedApplication] runModalForWindow:panel] == 0) {
+ credential = [[NSURLCredential alloc] initWithUser:[username stringValue] password:[password stringValue] persistence:([remember state] == NSOnState) ? NSURLCredentialPersistencePermanent : NSURLCredentialPersistenceForSession];
+ }
+
+ [callback performSelector:selector withObject:chall withObject:credential];
+ [credential release];
+}
+
+- (void)runAsSheetOnWindow:(NSWindow *)window withChallenge:(NSURLAuthenticationChallenge *)chall
+{
+ ASSERT(!usingSheet);
+
+ [self setUpForChallenge:chall];
+
+ usingSheet = TRUE;
+ challenge = [chall retain];
+
+ [[NSApplication sharedApplication] beginSheet:panel modalForWindow:window modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:NULL];
+}
+
+- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo
+{
+ NSURLCredential *credential = nil;
+ NSURLAuthenticationChallenge *chall;
+
+ ASSERT(usingSheet);
+ ASSERT(challenge != nil);
+
+ if (returnCode == 0) {
+ credential = [[NSURLCredential alloc] initWithUser:[username stringValue] password:[password stringValue] persistence:([remember state] == NSOnState) ? NSURLCredentialPersistencePermanent : NSURLCredentialPersistenceForSession];
+ }
+
+ // We take this tricky approach to nilling out and releasing the challenge
+ // because the callback below might remove our last ref.
+ chall = challenge;
+ challenge = nil;
+ [callback performSelector:selector withObject:chall withObject:credential];
+ [credential release];
+ [chall release];
+}
+
+@end
+
+@implementation NonBlockingPanel
+
+- (BOOL)_blocksActionWhenModal:(SEL)theAction
+{
+ // This override of a private AppKit method allows the user to quit when a login dialog
+ // is onscreen, which is nice in general but in particular prevents pathological cases
+ // like 3744583 from requiring a Force Quit.
+ //
+ // It would be nice to allow closing the individual window as well as quitting the app when
+ // a login sheet is up, but this _blocksActionWhenModal: mechanism doesn't support that.
+ // This override matches those in NSOpenPanel and NSToolbarConfigPanel.
+ if (theAction == @selector(terminate:)) {
+ return NO;
+ }
+ return YES;
+}
+
+@end
diff --git a/WebKit/mac/Panels/WebPanelAuthenticationHandler.h b/WebKit/mac/Panels/WebPanelAuthenticationHandler.h
new file mode 100644
index 0000000..ac5f449
--- /dev/null
+++ b/WebKit/mac/Panels/WebPanelAuthenticationHandler.h
@@ -0,0 +1,45 @@
+/*
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Foundation/Foundation.h>
+#import <Foundation/NSURLCredentialStorage.h>
+
+@class NSURLAuthenticationChallenge;
+
+@interface WebPanelAuthenticationHandler : NSObject
+{
+ NSMutableDictionary *windowToPanel;
+ NSMutableDictionary *challengeToWindow;
+ NSMutableDictionary *windowToChallengeQueue;
+}
+
++ (id)sharedHandler;
+- (void)startAuthentication:(NSURLAuthenticationChallenge *)challenge window:(NSWindow *)w;
+- (void)cancelAuthentication:(NSURLAuthenticationChallenge *)challenge;
+
+@end
diff --git a/WebKit/mac/Panels/WebPanelAuthenticationHandler.m b/WebKit/mac/Panels/WebPanelAuthenticationHandler.m
new file mode 100644
index 0000000..c4c6e5b
--- /dev/null
+++ b/WebKit/mac/Panels/WebPanelAuthenticationHandler.m
@@ -0,0 +1,164 @@
+/*
+ * 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
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <WebKit/WebPanelAuthenticationHandler.h>
+
+#import <Foundation/NSURLAuthenticationChallenge.h>
+#import <WebKit/WebAuthenticationPanel.h>
+#import <WebKit/WebNSDictionaryExtras.h>
+#import <wtf/Assertions.h>
+
+static NSString *WebModalDialogPretendWindow = @"WebModalDialogPretendWindow";
+
+@implementation WebPanelAuthenticationHandler
+
+WebPanelAuthenticationHandler *sharedHandler;
+
++ (id)sharedHandler
+{
+ if (sharedHandler == nil)
+ sharedHandler = [[self alloc] init];
+ return sharedHandler;
+}
+
+-(id)init
+{
+ self = [super init];
+ if (self != nil) {
+ windowToPanel = [[NSMutableDictionary alloc] init];
+ challengeToWindow = [[NSMutableDictionary alloc] init];
+ windowToChallengeQueue = [[NSMutableDictionary alloc] init];
+ }
+ return self;
+}
+
+-(void)dealloc
+{
+ [windowToPanel release];
+ [challengeToWindow release];
+ [windowToChallengeQueue release];
+ [super dealloc];
+}
+
+-(void)enqueueChallenge:(NSURLAuthenticationChallenge *)challenge forWindow:(id)window
+{
+ NSMutableArray *queue = [windowToChallengeQueue objectForKey:window];
+ if (queue == nil) {
+ queue = [[NSMutableArray alloc] init];
+ [windowToChallengeQueue _webkit_setObject:queue forUncopiedKey:window];
+ [queue release];
+ }
+ [queue addObject:challenge];
+}
+
+-(void)tryNextChallengeForWindow:(id)window
+{
+ NSMutableArray *queue = [windowToChallengeQueue objectForKey:window];
+ if (queue == nil) {
+ return;
+ }
+
+ NSURLAuthenticationChallenge *challenge = [[queue objectAtIndex:0] retain];
+ [queue removeObjectAtIndex:0];
+ if ([queue count] == 0) {
+ [windowToChallengeQueue removeObjectForKey:window];
+ }
+
+ NSURLCredential *latestCredential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
+
+ if ([latestCredential hasPassword]) {
+ [[challenge sender] useCredential:latestCredential forAuthenticationChallenge:challenge];
+ [challenge release];
+ return;
+ }
+
+ [self startAuthentication:challenge window:(window == WebModalDialogPretendWindow ? nil : window)];
+ [challenge release];
+}
+
+
+-(void)startAuthentication:(NSURLAuthenticationChallenge *)challenge window:(NSWindow *)w
+{
+ id window = w ? (id)w : (id)WebModalDialogPretendWindow;
+
+ if ([windowToPanel objectForKey:window] != nil) {
+ [self enqueueChallenge:challenge forWindow:window];
+ return;
+ }
+
+ // In this case, we have an attached sheet that's not one of our
+ // authentication panels, so enqueing is not an option. Just
+ // cancel authentication instead, since this case is fairly
+ // unlikely (how would you be loading a page if you had an error
+ // sheet up?)
+ if ([w attachedSheet] != nil) {
+ [[challenge sender] cancelAuthenticationChallenge:challenge];
+ return;
+ }
+
+ WebAuthenticationPanel *panel = [[WebAuthenticationPanel alloc] initWithCallback:self selector:@selector(_authenticationDoneWithChallenge:result:)];
+ [challengeToWindow _webkit_setObject:window forUncopiedKey:challenge];
+ [windowToPanel _webkit_setObject:panel forUncopiedKey:window];
+ [panel release];
+
+ if (window == WebModalDialogPretendWindow) {
+ [panel runAsModalDialogWithChallenge:challenge];
+ } else {
+ [panel runAsSheetOnWindow:window withChallenge:challenge];
+ }
+}
+
+-(void)cancelAuthentication:(NSURLAuthenticationChallenge *)challenge
+{
+ id window = [challengeToWindow objectForKey:challenge];
+ if (window != nil) {
+ WebAuthenticationPanel *panel = [windowToPanel objectForKey:window];
+ [panel cancel:self];
+ }
+}
+
+-(void)_authenticationDoneWithChallenge:(NSURLAuthenticationChallenge *)challenge result:(NSURLCredential *)credential
+{
+ id window = [challengeToWindow objectForKey:challenge];
+ [window retain];
+ if (window != nil) {
+ [windowToPanel removeObjectForKey:window];
+ [challengeToWindow removeObjectForKey:challenge];
+ }
+
+ if (credential == nil) {
+ [[challenge sender] cancelAuthenticationChallenge:challenge];
+ } else {
+ [[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
+ }
+
+ [self tryNextChallengeForWindow:window];
+ [window release];
+}
+
+@end