if (challenge_ != nil)
[challenge_ release];
- if (request_ != nil)
- [request_ release];
-
if (closer_ != nil)
[closer_ release];
- (void) setURL:(NSURL *)url {
_assert(request_ == nil);
- request_ = [[NSURLRequest
+ request_ = [NSURLRequest
requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:DefaultTimeout_
- ] retain];
+ ];
}
- (void) loadURL:(NSURL *)url cachePolicy:(NSURLRequestCachePolicy)policy {
NSMutableURLRequest *request([request_ mutableCopy]);
[request setCachePolicy:(cache ? NSURLRequestUseProtocolCachePolicy : NSURLRequestReloadIgnoringLocalCacheData)];
- [request_ autorelease];
- request_ = [request retain];
+ request_ = request;
if ([request_ HTTPBody] == nil && [request_ HTTPBodyStream] == nil)
[self loadRequest:request_];
return true;
}
+- (bool) allowsNavigationAction {
+ return allowsNavigationAction_;
+}
+
+- (void) setAllowsNavigationAction:(bool)value {
+ allowsNavigationAction_ = value;
+}
+
+- (void) setAllowsNavigationActionByNumber:(NSNumber *)value {
+ [self setAllowsNavigationAction:[value boolValue]];
+}
+
- (void) _didFailWithError:(NSError *)error forFrame:(WebFrame *)frame {
[loading_ removeObject:[NSValue valueWithNonretainedObject:frame]];
[self _didFinishLoading];
}
}
-// CYWebViewDelegate {{{
-- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
-#if LogMessages
- NSLog(@"addMessageToConsole:%@", message);
-#endif
-}
-
-- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
-#if LogBrowser
- NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
-#endif
-
- if ([frame parentFrame] == nil) {
- if (!error_) {
- if (request_ != nil)
- [request_ autorelease];
- if (request == nil)
- request_ = nil;
- else
- request_ = [request retain];
- }
- }
-}
-
-- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
-#if LogBrowser
- NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
-#endif
-
+- (void) pushRequest:(NSURLRequest *)request asPop:(bool)pop {
NSURL *url([request URL]);
- if (url == nil)
- return;
-
- if ([frame isEqualToString:@"_open"])
- [delegate_ openURL:url];
-
- NSString *scheme([[url scheme] lowercaseString]);
- if ([scheme isEqualToString:@"mailto"])
- [self _openMailToURL:url];
// XXX: filter to internal usage?
CYViewController *page([delegate_ pageForURL:url forExternal:NO]);
[page setDelegate:delegate_];
- if (![frame isEqualToString:@"_popup"]) {
+ if (!pop) {
[[self navigationItem] setTitle:title_];
[[self navigationController] pushViewController:page animated:YES];
[[self navigationController] presentModalViewController:navigation animated:YES];
}
+}
+
+// CYWebViewDelegate {{{
+- (void) webView:(WebView *)view addMessageToConsole:(NSDictionary *)message {
+#if LogMessages
+ NSLog(@"addMessageToConsole:%@", message);
+#endif
+}
+
+- (void) webView:(WebView *)view decidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+#if LogBrowser
+ NSLog(@"decidePolicyForNavigationAction:%@ request:%@ frame:%@", action, request, frame);
+#endif
+
+ if ([frame parentFrame] == nil) {
+ if (!error_) {
+ NSURL *url(request == nil ? nil : [request URL]);
+
+ if (request_ == nil || [self allowsNavigationAction] || [[request_ URL] isEqual:url])
+ request_ = request;
+ else {
+ if (url != nil)
+ [self pushRequest:request asPop:NO];
+ [listener ignore];
+ }
+ }
+ }
+}
+
+- (void) webView:(WebView *)view decidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frame decisionListener:(id<WebPolicyDecisionListener>)listener {
+#if LogBrowser
+ NSLog(@"decidePolicyForNewWindowAction:%@ request:%@ newFrameName:%@", action, request, frame);
+#endif
+
+ NSURL *url([request URL]);
+ if (url == nil)
+ return;
+
+ if ([frame isEqualToString:@"_open"])
+ [delegate_ openURL:url];
+ else {
+ NSString *scheme([[url scheme] lowercaseString]);
+ if ([scheme isEqualToString:@"mailto"])
+ [self _openMailToURL:url];
+ else
+ [self pushRequest:request asPop:[frame isEqualToString:@"_popup"]];
+ }
[listener ignore];
}
- (id) initWithWidth:(float)width ofClass:(Class)_class {
if ((self = [super init]) != nil) {
+ allowsNavigationAction_ = true;
+
class_ = _class;
loading_ = [[NSMutableSet alloc] initWithCapacity:5];