#import <WebKit/WebIconDatabasePrivate.h>
#import <WebKit/WebNSURLExtras.h>
#import <WebKit/WebFrameLoadDelegate.h>
-
+#import <WebKit/WebDataProtocol.h>
+#import <WebKit/WebKitNSStringExtras.h>
@implementation WebFrameLoader
listener = nil;
}
+- (void)_loadRequest:(NSURLRequest *)request archive:(WebArchive *)archive
+{
+ WebFrameLoadType loadType;
+
+ // note this copies request
+ WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
+ NSMutableURLRequest *r = [newDataSource request];
+ [webFrame _addExtraFieldsToRequest:r mainResource:YES alwaysFromRequest:NO];
+ if ([webFrame _shouldTreatURLAsSameAsCurrent:[request URL]]) {
+ [r setCachePolicy:NSURLRequestReloadIgnoringCacheData];
+ loadType = WebFrameLoadTypeSame;
+ } else
+ loadType = WebFrameLoadTypeStandard;
+
+ [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
+ [newDataSource _addToUnarchiveState:archive];
+
+ // When we loading alternate content for an unreachable URL that we're
+ // visiting in the b/f list, we treat it as a reload so the b/f list
+ // is appropriately maintained.
+ if ([webFrame _shouldReloadToHandleUnreachableURLFromRequest:request]) {
+ ASSERT(loadType == WebFrameLoadTypeStandard);
+ loadType = WebFrameLoadTypeReload;
+ }
+
+ [webFrame _loadDataSource:newDataSource withLoadType:loadType formState:nil];
+ [newDataSource release];
+}
+
+- (void)_loadRequest:(NSURLRequest *)request triggeringAction:(NSDictionary *)action loadType:(WebFrameLoadType)loadType formState:(WebFormState *)formState
+{
+ WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
+ [newDataSource _setTriggeringAction:action];
+
+ [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
+
+ [webFrame _loadDataSource:newDataSource withLoadType:loadType formState:formState];
+
+ [newDataSource release];
+}
+
+- (void)_reloadAllowingStaleDataWithOverrideEncoding:(NSString *)encoding
+{
+ WebDataSource *ds = [self dataSource];
+ if (ds == nil)
+ return;
+
+ NSMutableURLRequest *request = [[ds request] mutableCopy];
+ NSURL *unreachableURL = [ds unreachableURL];
+ if (unreachableURL != nil)
+ [request setURL:unreachableURL];
+
+ [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
+ WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
+ [request release];
+
+ [newDataSource _setOverrideEncoding:encoding];
+
+ [webFrame _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReloadAllowingStaleData formState:nil];
+
+ [newDataSource release];
+}
+
+- (void)reload
+{
+ WebDataSource *ds = [self dataSource];
+ if (ds == nil)
+ return;
+
+ NSMutableURLRequest *initialRequest = [ds request];
+
+ // If a window is created by javascript, its main frame can have an empty but non-nil URL.
+ // Reloading in this case will lose the current contents (see 4151001).
+ if ([[[[ds request] URL] absoluteString] length] == 0)
+ return;
+
+ // Replace error-page URL with the URL we were trying to reach.
+ NSURL *unreachableURL = [initialRequest _webDataRequestUnreachableURL];
+ if (unreachableURL != nil)
+ initialRequest = [NSURLRequest requestWithURL:unreachableURL];
+
+ // initWithRequest copies the request
+ WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:initialRequest];
+ NSMutableURLRequest *request = [newDataSource request];
+
+ [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
+
+ // If we're about to rePOST, set up action so the app can warn the user
+ if ([[request HTTPMethod] _webkit_isCaseInsensitiveEqualToString:@"POST"]) {
+ NSDictionary *action = [webFrame _actionInformationForNavigationType:WebNavigationTypeFormResubmitted event:nil originalURL:[request URL]];
+ [newDataSource _setTriggeringAction:action];
+ }
+
+ [newDataSource _setOverrideEncoding:[ds _overrideEncoding]];
+
+ [webFrame _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReload formState:nil];
+
+ [newDataSource release];
+}
+
@end
@end
@interface WebFrame (ForwardDecls)
-- (void)_loadRequest:(NSURLRequest *)request triggeringAction:(NSDictionary *)action loadType:(WebFrameLoadType)loadType formState:(WebFormState *)formState;
- (void)_loadHTMLString:(NSString *)string baseURL:(NSURL *)URL unreachableURL:(NSURL *)unreachableURL;
- (NSDictionary *)_actionInformationForLoadType:(WebFrameLoadType)loadType isFormSubmission:(BOOL)isFormSubmission event:(NSEvent *)event originalURL:(NSURL *)URL;
return request;
}
-- (BOOL)_shouldReloadToHandleUnreachableURLFromRequest:(NSURLRequest *)request
-{
- NSURL *unreachableURL = [request _webDataRequestUnreachableURL];
- if (unreachableURL == nil) {
- return NO;
- }
-
- if (_private->policyLoadType != WebFrameLoadTypeForward
- && _private->policyLoadType != WebFrameLoadTypeBack
- && _private->policyLoadType != WebFrameLoadTypeIndexedBackForward) {
- return NO;
- }
-
- // We only treat unreachableURLs specially during the delegate callbacks
- // for provisional load errors and navigation policy decisions. The former
- // case handles well-formed URLs that can't be loaded, and the latter
- // case handles malformed URLs and unknown schemes. Loading alternate content
- // at other times behaves like a standard load.
- WebDataSource *compareDataSource = nil;
- if (_private->delegateIsDecidingNavigationPolicy || _private->delegateIsHandlingUnimplementablePolicy) {
- compareDataSource = _private->policyDataSource;
- } else if (_private->delegateIsHandlingProvisionalLoadError) {
- compareDataSource = [self provisionalDataSource];
- }
-
- return compareDataSource != nil && [unreachableURL isEqual:[[compareDataSource request] URL]];
-}
-
-- (void)_loadRequest:(NSURLRequest *)request archive:(WebArchive *)archive
-{
- WebFrameLoadType loadType;
-
- // note this copies request
- WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
- NSMutableURLRequest *r = [newDataSource request];
- [self _addExtraFieldsToRequest:r mainResource:YES alwaysFromRequest:NO];
- if ([self _shouldTreatURLAsSameAsCurrent:[request URL]]) {
- [r setCachePolicy:NSURLRequestReloadIgnoringCacheData];
- loadType = WebFrameLoadTypeSame;
- } else {
- loadType = WebFrameLoadTypeStandard;
- }
-
- [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
- [newDataSource _addToUnarchiveState:archive];
-
- // When we loading alternate content for an unreachable URL that we're
- // visiting in the b/f list, we treat it as a reload so the b/f list
- // is appropriately maintained.
- if ([self _shouldReloadToHandleUnreachableURLFromRequest:request]) {
- ASSERT(loadType == WebFrameLoadTypeStandard);
- loadType = WebFrameLoadTypeReload;
- }
-
- [self _loadDataSource:newDataSource withLoadType:loadType formState:nil];
- [newDataSource release];
-}
-
// helper method used in various nav cases below
- (void)_addBackForwardItemClippedAtTarget:(BOOL)doClip
{
action = [self _actionInformationForLoadType:loadType isFormSubmission:NO event:nil originalURL:itemOriginalURL];
}
- [self _loadRequest:request triggeringAction:action loadType:loadType formState:nil];
+ [_private->frameLoader _loadRequest:request triggeringAction:action loadType:loadType formState:nil];
[request release];
}
}
}
}
-- (void)_loadRequest:(NSURLRequest *)request triggeringAction:(NSDictionary *)action loadType:(WebFrameLoadType)loadType formState:(WebFormState *)formState
-{
- WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
- [newDataSource _setTriggeringAction:action];
-
- [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
-
- [self _loadDataSource:newDataSource withLoadType:loadType formState:formState];
-
- [newDataSource release];
-}
-
-(NSDictionary *)_actionInformationForNavigationType:(WebNavigationType)navigationType event:(NSEvent *)event originalURL:(NSURL *)URL
{
switch ([event type]) {
[[webView _UIDelegateForwarder] webViewShow:webView];
[[self _bridge] setOpener:[frame _bridge]];
- [frame _loadRequest:request triggeringAction:nil loadType:WebFrameLoadTypeStandard formState:formState];
+ [_private->frameLoader _loadRequest:request triggeringAction:nil loadType:WebFrameLoadTypeStandard formState:formState];
}
} else {
// must grab this now, since this load may stop the previous load and clear this flag
BOOL isRedirect = _private->quickRedirectComing;
- [self _loadRequest:request triggeringAction:action loadType:loadType formState:formState];
+ [_private->frameLoader _loadRequest:request triggeringAction:action loadType:loadType formState:formState];
if (isRedirect) {
LOG(Redirect, "%@(%p) _private->quickRedirectComing was %d", [self name], self, (int)isRedirect);
_private->quickRedirectComing = NO;
WebFrame *targetFrame = [self findFrameNamed:target];
if (targetFrame != nil) {
- [targetFrame _loadRequest:request triggeringAction:action loadType:WebFrameLoadTypeStandard formState:formState];
+ [[targetFrame _frameLoader] _loadRequest:request triggeringAction:action loadType:WebFrameLoadTypeStandard formState:formState];
} else {
[self _checkNewWindowPolicyForRequest:request action:action frameName:target formState:formState andCall:self withSelector:@selector(_continueLoadRequestAfterNewWindowPolicy:frameName:formState:)];
}
return;
}
- [self _loadRequest:request triggeringAction:action loadType:WebFrameLoadTypeStandard formState:formState];
+ [_private->frameLoader _loadRequest:request triggeringAction:action loadType:WebFrameLoadTypeStandard formState:formState];
[request release];
[formState release];
[[[frame frameView] documentView] viewDidMoveToHostWindow];
}
-- (void)_reloadAllowingStaleDataWithOverrideEncoding:(NSString *)encoding
-{
- WebDataSource *dataSource = [self dataSource];
- if (dataSource == nil) {
- return;
- }
-
- NSMutableURLRequest *request = [[dataSource request] mutableCopy];
- NSURL *unreachableURL = [dataSource unreachableURL];
- if (unreachableURL != nil) {
- [request setURL:unreachableURL];
- }
- [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
- WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:request];
- [request release];
-
- [newDataSource _setOverrideEncoding:encoding];
-
- [self _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReloadAllowingStaleData formState:nil];
-
- [newDataSource release];
-}
-
- (void)_addChild:(WebFrame *)child
{
[[self _bridge] appendChild:[child _bridge]];
_private->firstLayoutDone = YES;
}
+- (BOOL)_shouldReloadToHandleUnreachableURLFromRequest:(NSURLRequest *)request
+{
+ NSURL *unreachableURL = [request _webDataRequestUnreachableURL];
+ if (unreachableURL == nil) {
+ return NO;
+ }
+
+ if (_private->policyLoadType != WebFrameLoadTypeForward
+ && _private->policyLoadType != WebFrameLoadTypeBack
+ && _private->policyLoadType != WebFrameLoadTypeIndexedBackForward) {
+ return NO;
+ }
+
+ // We only treat unreachableURLs specially during the delegate callbacks
+ // for provisional load errors and navigation policy decisions. The former
+ // case handles well-formed URLs that can't be loaded, and the latter
+ // case handles malformed URLs and unknown schemes. Loading alternate content
+ // at other times behaves like a standard load.
+ WebDataSource *compareDataSource = nil;
+ if (_private->delegateIsDecidingNavigationPolicy || _private->delegateIsHandlingUnimplementablePolicy) {
+ compareDataSource = _private->policyDataSource;
+ } else if (_private->delegateIsHandlingProvisionalLoadError) {
+ compareDataSource = [self provisionalDataSource];
+ }
+
+ return compareDataSource != nil && [unreachableURL isEqual:[[compareDataSource request] URL]];
+}
+
@end
@implementation WebFormState : NSObject
// after loading is finished or aborted.
_private->loadType = WebFrameLoadTypeStandard;
- [self _loadRequest:request archive:nil];
+ [_private->frameLoader _loadRequest:request archive:nil];
}
- (void)_loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)encodingName baseURL:(NSURL *)URL unreachableURL:(NSURL *)unreachableURL
textEncodingName:[mainResource textEncodingName]
baseURL:[mainResource URL]
unreachableURL:nil];
- [self _loadRequest:request archive:archive];
+ [_private->frameLoader _loadRequest:request archive:archive];
}
}
- (void)reload
{
- WebDataSource *dataSource = [self dataSource];
- if (dataSource == nil)
- return;
-
- NSMutableURLRequest *initialRequest = [dataSource request];
-
- // If a window is created by javascript, its main frame can have an empty but non-nil URL.
- // Reloading in this case will lose the current contents (see 4151001).
- if ([[[[dataSource request] URL] absoluteString] length] == 0) {
- return;
- }
-
- // Replace error-page URL with the URL we were trying to reach.
- NSURL *unreachableURL = [initialRequest _webDataRequestUnreachableURL];
- if (unreachableURL != nil) {
- initialRequest = [NSURLRequest requestWithURL:unreachableURL];
- }
-
- // initWithRequest copies the request
- WebDataSource *newDataSource = [[WebDataSource alloc] initWithRequest:initialRequest];
- NSMutableURLRequest *request = [newDataSource request];
-
- [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
-
- // If we're about to rePOST, set up action so the app can warn the user
- if ([[request HTTPMethod] _webkit_isCaseInsensitiveEqualToString:@"POST"]) {
- NSDictionary *action = [self _actionInformationForNavigationType:WebNavigationTypeFormResubmitted event:nil originalURL:[request URL]];
- [newDataSource _setTriggeringAction:action];
- }
-
- [newDataSource _setOverrideEncoding:[dataSource _overrideEncoding]];
-
- [self _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReload formState:nil];
-
- [newDataSource release];
+ [_private->frameLoader reload];
}
- (WebFrame *)findFrameNamed:(NSString *)name