2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #import <WebKit/WebFrameLoader.h>
31 #import <JavaScriptCore/Assertions.h>
32 #import <WebKit/WebDataSourceInternal.h>
33 #import <WebKit/WebFrameInternal.h>
34 #import <WebKit/WebMainResourceLoader.h>
35 #import <WebKit/WebKitLogging.h>
36 #import <WebKit/WebViewInternal.h>
37 #import <WebKit/WebKitErrorsPrivate.h>
38 #import <WebKit/WebResourcePrivate.h>
39 #import <WebKit/DOMHTML.h>
40 #import <WebKit/WebFrameBridge.h>
41 #import <WebKit/WebPreferences.h>
42 #import <WebKit/WebIconDatabasePrivate.h>
43 #import <WebKit/WebNSURLExtras.h>
44 #import <WebKit/WebFrameLoadDelegate.h>
45 #import <WebKit/WebDataProtocol.h>
46 #import <WebKit/WebKitNSStringExtras.h>
47 #import "WebNSDictionaryExtras.h"
49 @implementation WebFrameLoader
51 - (id)initWithWebFrame:(WebFrame *)wf
56 state = WebFrameStateCommittedPage;
63 // FIXME: should these even exist?
64 [mainResourceLoader release];
65 [subresourceLoaders release];
66 [plugInStreamLoaders release];
67 [documentLoadState release];
68 [provisionalDocumentLoadState release];
70 ASSERT(!policyDocumentLoadState);
75 - (WebDocumentLoadState *)activeDocumentLoadState
77 if (state == WebFrameStateProvisional)
78 return provisionalDocumentLoadState;
80 return documentLoadState;
83 - (WebDataSource *)activeDataSource
85 return [webFrame _dataSourceForDocumentLoadState:[self activeDocumentLoadState]];
88 - (WebResource *)_archivedSubresourceForURL:(NSURL *)URL
90 return [[self activeDataSource] _archivedSubresourceForURL:URL];
93 - (void)addPlugInStreamLoader:(WebLoader *)loader
95 if (!plugInStreamLoaders)
96 plugInStreamLoaders = [[NSMutableArray alloc] init];
97 [plugInStreamLoaders addObject:loader];
98 [[self activeDocumentLoadState] setLoading:YES];
101 - (void)removePlugInStreamLoader:(WebLoader *)loader
103 [plugInStreamLoaders removeObject:loader];
104 [[self activeDocumentLoadState] updateLoading];
107 - (void)defersCallbacksChanged
109 [self setDefersCallbacks:[[webFrame webView] defersCallbacks]];
112 - (BOOL)defersCallbacks
114 return [[webFrame webView] defersCallbacks];
117 - (void)setDefersCallbacks:(BOOL)defers
119 [mainResourceLoader setDefersCallbacks:defers];
121 NSEnumerator *e = [subresourceLoaders objectEnumerator];
123 while ((loader = [e nextObject]))
124 [loader setDefersCallbacks:defers];
126 e = [plugInStreamLoaders objectEnumerator];
127 while ((loader = [e nextObject]))
128 [loader setDefersCallbacks:defers];
130 [self deliverArchivedResourcesAfterDelay];
133 - (void)stopLoadingPlugIns
135 [plugInStreamLoaders makeObjectsPerformSelector:@selector(cancel)];
136 [plugInStreamLoaders removeAllObjects];
139 - (BOOL)isLoadingMainResource
141 return mainResourceLoader != nil;
144 - (BOOL)isLoadingSubresources
146 return [subresourceLoaders count];
149 - (BOOL)isLoadingPlugIns
151 return [plugInStreamLoaders count];
156 return [self isLoadingMainResource] || [self isLoadingSubresources] || [self isLoadingPlugIns];
159 - (void)stopLoadingSubresources
161 NSArray *loaders = [subresourceLoaders copy];
162 [loaders makeObjectsPerformSelector:@selector(cancel)];
164 [subresourceLoaders removeAllObjects];
167 - (void)addSubresourceLoader:(WebLoader *)loader
169 ASSERT(!provisionalDocumentLoadState);
170 if (subresourceLoaders == nil)
171 subresourceLoaders = [[NSMutableArray alloc] init];
172 [subresourceLoaders addObject:loader];
173 [[self activeDocumentLoadState] setLoading:YES];
176 - (void)removeSubresourceLoader:(WebLoader *)loader
178 [subresourceLoaders removeObject:loader];
179 [[self activeDocumentLoadState] updateLoading];
182 - (NSData *)mainResourceData
184 return [mainResourceLoader resourceData];
187 - (void)releaseMainResourceLoader
189 [mainResourceLoader release];
190 mainResourceLoader = nil;
193 - (void)cancelMainResourceLoad
195 [mainResourceLoader cancel];
198 - (BOOL)startLoadingMainResourceWithRequest:(NSMutableURLRequest *)request identifier:(id)identifier
200 mainResourceLoader = [[WebMainResourceLoader alloc] initWithFrameLoader:self];
202 [mainResourceLoader setIdentifier:identifier];
203 [webFrame _addExtraFieldsToRequest:request mainResource:YES alwaysFromRequest:NO];
204 if (![mainResourceLoader loadWithRequest:request]) {
205 // FIXME: if this should really be caught, we should just ASSERT this doesn't happen;
206 // should it be caught by other parts of WebKit or other parts of the app?
207 LOG_ERROR("could not create WebResourceHandle for URL %@ -- should be caught by policy handler level", [request URL]);
208 [mainResourceLoader release];
209 mainResourceLoader = nil;
216 - (void)stopLoadingWithError:(NSError *)error
218 [mainResourceLoader cancelWithError:error];
221 - (WebDataSource *)dataSource
223 return [webFrame _dataSourceForDocumentLoadState:documentLoadState];
226 - (void)_setDocumentLoadState:(WebDocumentLoadState *)loadState
228 if (loadState == nil && documentLoadState == nil)
231 ASSERT(loadState != documentLoadState);
233 [webFrame _prepareForDataSourceReplacement];
234 [documentLoadState detachFromFrameLoader];
237 [documentLoadState release];
238 documentLoadState = loadState;
241 - (WebDocumentLoadState *)documentLoadState
243 return documentLoadState;
246 - (WebDataSource *)policyDataSource
248 return [webFrame _dataSourceForDocumentLoadState:policyDocumentLoadState];
251 - (void)_setPolicyDocumentLoadState:(WebDocumentLoadState *)loadState
254 [policyDocumentLoadState release];
255 policyDocumentLoadState = loadState;
258 - (void)clearDataSource
260 [self _setDocumentLoadState:nil];
263 - (WebDataSource *)provisionalDataSource
265 return [webFrame _dataSourceForDocumentLoadState:provisionalDocumentLoadState];
268 - (WebDocumentLoadState *)provisionalDocumentLoadState
270 return provisionalDocumentLoadState;
273 - (void)_setProvisionalDocumentLoadState:(WebDocumentLoadState *)loadState
275 ASSERT(!loadState || !provisionalDocumentLoadState);
277 if (provisionalDocumentLoadState != documentLoadState)
278 [provisionalDocumentLoadState detachFromFrameLoader];
281 [provisionalDocumentLoadState release];
282 provisionalDocumentLoadState = loadState;
285 - (void)_clearProvisionalDataSource
287 [self _setProvisionalDocumentLoadState:nil];
290 - (WebFrameState)state
296 static const char * const stateNames[] = {
297 "WebFrameStateProvisional",
298 "WebFrameStateCommittedPage",
299 "WebFrameStateComplete"
303 static CFAbsoluteTime _timeOfLastCompletedLoad;
305 + (CFAbsoluteTime)timeOfLastCompletedLoad
307 return _timeOfLastCompletedLoad;
310 - (void)_setState:(WebFrameState)newState
312 LOG(Loading, "%@: transition from %s to %s", [webFrame name], stateNames[state], stateNames[newState]);
313 if ([webFrame webView])
314 LOG(Timing, "%@: transition from %s to %s, %f seconds since start of document load", [webFrame name], stateNames[state], stateNames[newState], CFAbsoluteTimeGetCurrent() - [[[[webFrame webView] mainFrame] dataSource] _loadingStartedTime]);
316 if (newState == WebFrameStateComplete && webFrame == [[webFrame webView] mainFrame])
317 LOG(DocumentLoad, "completed %@ (%f seconds)", [[[self dataSource] request] URL], CFAbsoluteTimeGetCurrent() - [[self dataSource] _loadingStartedTime]);
321 if (state == WebFrameStateProvisional)
322 [webFrame _provisionalLoadStarted];
323 else if (state == WebFrameStateComplete) {
324 [webFrame _frameLoadCompleted];
325 _timeOfLastCompletedLoad = CFAbsoluteTimeGetCurrent();
326 [[self dataSource] _stopRecordingResponses];
330 - (void)clearProvisionalLoad
332 [self _setProvisionalDocumentLoadState:nil];
333 [[webFrame webView] _progressCompleted:webFrame];
334 [self _setState:WebFrameStateComplete];
337 - (void)markLoadComplete
339 [self _setState:WebFrameStateComplete];
342 - (void)commitProvisionalLoad
344 [self stopLoadingSubresources];
345 [self stopLoadingPlugIns];
347 [self _setDocumentLoadState:provisionalDocumentLoadState];
348 [self _setProvisionalDocumentLoadState:nil];
349 [self _setState:WebFrameStateCommittedPage];
354 [[self provisionalDocumentLoadState] stopLoading];
355 [[self documentLoadState] stopLoading];
356 [self _clearProvisionalDataSource];
357 [self clearArchivedResources];
360 // FIXME: poor method name; also why is this not part of startProvisionalLoad:?
363 [[self provisionalDataSource] _startLoading];
366 - (void)startProvisionalLoad:(WebDataSource *)ds
368 [self _setProvisionalDocumentLoadState:[ds _documentLoadState]];
369 [self _setState:WebFrameStateProvisional];
372 - (void)setupForReplace
374 [self _setState:WebFrameStateProvisional];
375 WebDocumentLoadState *old = provisionalDocumentLoadState;
376 provisionalDocumentLoadState = documentLoadState;
377 documentLoadState = nil;
380 [webFrame _detachChildren];
383 - (id)_identifierForInitialRequest:(NSURLRequest *)clientRequest
385 return [[self activeDataSource] _identifierForInitialRequest:clientRequest];
388 - (NSURLRequest *)_willSendRequest:(NSMutableURLRequest *)clientRequest forResource:(id)identifier redirectResponse:(NSURLResponse *)redirectResponse
390 return [[self activeDataSource] _willSendRequest:clientRequest forResource:identifier redirectResponse:redirectResponse];
393 - (void)_didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier
395 [[self activeDataSource] _didReceiveAuthenticationChallenge:currentWebChallenge forResource:identifier];
398 - (void)_didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier
400 [[self activeDataSource] _didCancelAuthenticationChallenge:currentWebChallenge forResource:identifier];
403 - (void)_didReceiveResponse:(NSURLResponse *)r forResource:(id)identifier
405 [[self activeDataSource] _didReceiveResponse:r forResource:identifier];
408 - (void)_didReceiveData:(NSData *)data contentLength:(int)lengthReceived forResource:(id)identifier
410 [[self activeDataSource] _didReceiveData:data contentLength:lengthReceived forResource:identifier];
413 - (void)_didFinishLoadingForResource:(id)identifier
415 [[self activeDataSource] _didFinishLoadingForResource:identifier];
418 - (void)_didFailLoadingWithError:(NSError *)error forResource:(id)identifier
420 [[self activeDataSource] _didFailLoadingWithError:error forResource:identifier];
423 - (BOOL)_privateBrowsingEnabled
425 return [[[webFrame webView] preferences] privateBrowsingEnabled];
428 - (void)_finishedLoadingResource
430 [webFrame _checkLoadComplete];
433 - (void)_receivedError:(NSError *)error
435 [webFrame _checkLoadComplete];
438 - (NSURLRequest *)_originalRequest
440 return [[self activeDocumentLoadState] originalRequestCopy];
443 - (WebFrame *)webFrame
448 - (void)_receivedMainResourceError:(NSError *)error complete:(BOOL)isComplete
450 WebDataSource *ds = [self activeDataSource];
452 [ds _receivedMainResourceError:error complete:isComplete];
456 - (NSURLRequest *)initialRequest
458 return [[self activeDataSource] initialRequest];
461 - (void)_receivedData:(NSData *)data
463 [[self activeDocumentLoadState] receivedData:data];
466 - (void)_setRequest:(NSURLRequest *)request
468 [[self activeDocumentLoadState] setRequest:request];
471 - (void)_downloadWithLoadingConnection:(NSURLConnection *)connection request:(NSURLRequest *)request response:(NSURLResponse *)r proxy:(id)proxy
473 [[self activeDataSource] _downloadWithLoadingConnection:connection request:request response:r proxy:proxy];
476 - (WebFrameBridge *)bridge
478 return [webFrame _bridge];
481 - (void)_handleFallbackContent
483 [[self bridge] handleFallbackContent];
488 return [[self activeDocumentLoadState] isStopping];
491 - (void)_setupForReplaceByMIMEType:(NSString *)newMIMEType
493 [[self activeDocumentLoadState] setupForReplaceByMIMEType:newMIMEType];
496 - (void)_setResponse:(NSURLResponse *)response
498 [[self activeDocumentLoadState] setResponse:response];
501 - (void)_mainReceivedError:(NSError *)error complete:(BOOL)isComplete
503 [[self activeDocumentLoadState] mainReceivedError:error complete:isComplete];
506 - (void)_finishedLoading
508 WebDataSource *ds = [self activeDataSource];
511 [[self activeDocumentLoadState] finishedLoading];
513 if ([ds _mainDocumentError] || ![ds webFrame]) {
518 [ds _setPrimaryLoadComplete:YES];
519 [webFrame _checkLoadComplete];
524 - (void)_notifyIconChanged:(NSURL *)iconURL
526 ASSERT([[WebIconDatabase sharedIconDatabase] _isEnabled]);
527 ASSERT(webFrame == [[webFrame webView] mainFrame]);
529 [[webFrame webView] _willChangeValueForKey:_WebMainFrameIconKey];
531 NSImage *icon = [[WebIconDatabase sharedIconDatabase] iconForURL:[[[self activeDataSource] _URL] _web_originalDataAsString] withSize:WebIconSmallSize];
533 [[[webFrame webView] _frameLoadDelegateForwarder] webView:[webFrame webView]
537 [[webFrame webView] _didChangeValueForKey:_WebMainFrameIconKey];
542 return [[self activeDataSource] _URL];
545 - (NSError *)cancelledErrorWithRequest:(NSURLRequest *)request
547 return [NSError _webKitErrorWithDomain:NSURLErrorDomain
548 code:NSURLErrorCancelled
552 - (NSError *)fileDoesNotExistErrorWithResponse:(NSURLResponse *)response
554 return [NSError _webKitErrorWithDomain:NSURLErrorDomain
555 code:NSURLErrorFileDoesNotExist
559 - (void)clearArchivedResources
561 [pendingArchivedResources removeAllObjects];
562 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(deliverArchivedResources) object:nil];
565 - (void)deliverArchivedResources
567 if (![pendingArchivedResources count] || [self defersCallbacks])
570 NSEnumerator *keyEnum = [pendingArchivedResources keyEnumerator];
572 while ((loader = [keyEnum nextObject])) {
573 WebResource *resource = [pendingArchivedResources objectForKey:loader];
574 [loader didReceiveResponse:[resource _response]];
575 NSData *data = [resource data];
576 [loader didReceiveData:data lengthReceived:[data length] allAtOnce:YES];
577 [loader didFinishLoading];
580 [pendingArchivedResources removeAllObjects];
583 - (void)deliverArchivedResourcesAfterDelay
585 if (![pendingArchivedResources count] || [self defersCallbacks])
588 [self performSelector:@selector(deliverArchivedResources) withObject:nil afterDelay:0];
591 static BOOL isCaseInsensitiveEqual(NSString *a, NSString *b)
593 return [a caseInsensitiveCompare:b] == NSOrderedSame;
596 // The following 2 methods are copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
597 // FIXME: It would be nice to eventually to share this code somehow.
598 - (BOOL)_canUseResourceForRequest:(NSURLRequest *)theRequest
600 NSURLRequestCachePolicy policy = [theRequest cachePolicy];
602 if (policy == NSURLRequestReturnCacheDataElseLoad) {
604 } else if (policy == NSURLRequestReturnCacheDataDontLoad) {
606 } else if (policy == NSURLRequestReloadIgnoringCacheData) {
608 } else if ([theRequest valueForHTTPHeaderField:@"must-revalidate"] != nil) {
610 } else if ([theRequest valueForHTTPHeaderField:@"proxy-revalidate"] != nil) {
612 } else if ([theRequest valueForHTTPHeaderField:@"If-Modified-Since"] != nil) {
614 } else if ([theRequest valueForHTTPHeaderField:@"Cache-Control"] != nil) {
616 } else if (isCaseInsensitiveEqual(@"POST", [theRequest HTTPMethod])) {
623 - (BOOL)_canUseResourceWithResponse:(NSURLResponse *)theResponse
625 if (WKGetNSURLResponseMustRevalidate(theResponse)) {
627 } else if (WKGetNSURLResponseCalculatedExpiration(theResponse) - CFAbsoluteTimeGetCurrent() < 1) {
634 - (NSMutableDictionary *)pendingArchivedResources
636 if (!pendingArchivedResources)
637 pendingArchivedResources = [[NSMutableDictionary alloc] init];
639 return pendingArchivedResources;
642 - (BOOL)willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebLoader *)loader
644 if ([[r URL] isEqual:originalURL] && [self _canUseResourceForRequest:r]) {
645 WebResource *resource = [self _archivedSubresourceForURL:originalURL];
646 if (resource && [self _canUseResourceWithResponse:[resource _response]]) {
647 [[self pendingArchivedResources] _webkit_setObject:resource forUncopiedKey:loader];
648 // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
649 [self deliverArchivedResourcesAfterDelay];
656 - (BOOL)archiveLoadPendingForLoader:(WebLoader *)loader
658 return [pendingArchivedResources objectForKey:loader] != nil;
661 - (void)cancelPendingArchiveLoadForLoader:(WebLoader *)loader
663 [pendingArchivedResources removeObjectForKey:loader];
665 if (![pendingArchivedResources count])
666 [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(deliverArchivedResources) object:nil];
669 - (void)_addExtraFieldsToRequest:(NSMutableURLRequest *)request mainResource:(BOOL)mainResource alwaysFromRequest:(BOOL)f
671 [webFrame _addExtraFieldsToRequest:request mainResource:mainResource alwaysFromRequest:f];
674 - (void)cannotShowMIMETypeForURL:(NSURL *)URL
676 [webFrame _handleUnimplementablePolicyWithErrorCode:WebKitErrorCannotShowMIMEType forURL:URL];
679 - (NSError *)interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request
681 return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:[request URL]];
684 - (BOOL)isHostedByObjectElement
686 // Handle <object> fallback for error cases.
687 DOMHTMLElement *hostElement = [webFrame frameElement];
688 return hostElement && [hostElement isKindOfClass:[DOMHTMLObjectElement class]];
691 - (BOOL)isLoadingMainFrame
693 return [webFrame _isMainFrame];
696 + (BOOL)_canShowMIMEType:(NSString *)MIMEType
698 return [WebView canShowMIMEType:MIMEType];
701 + (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme
703 return [WebView _representationExistsForURLScheme:URLScheme];
706 + (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme
708 return [WebView _generatedMIMETypeForURLScheme:URLScheme];
711 - (void)_checkNavigationPolicyForRequest:(NSURLRequest *)newRequest andCall:(id)obj withSelector:(SEL)sel
713 [webFrame _checkNavigationPolicyForRequest:newRequest
714 dataSource:[self activeDataSource]
720 - (void)_checkContentPolicyForMIMEType:(NSString *)MIMEType andCall:(id)obj withSelector:(SEL)sel
722 WebPolicyDecisionListener *l = [[WebPolicyDecisionListener alloc] _initWithTarget:obj action:sel];
726 [[self activeDataSource] _decidePolicyForMIMEType:MIMEType decisionListener:l];
730 - (void)cancelContentPolicy
732 [listener _invalidate];
737 - (void)_loadRequest:(NSURLRequest *)request archive:(WebArchive *)archive
739 WebFrameLoadType loadType;
741 policyDocumentLoadState = [webFrame _createDocumentLoadStateWithRequest:request];
742 WebDataSource *newDataSource = [webFrame _dataSourceForDocumentLoadState:policyDocumentLoadState];
744 NSMutableURLRequest *r = [newDataSource request];
745 [webFrame _addExtraFieldsToRequest:r mainResource:YES alwaysFromRequest:NO];
746 if ([webFrame _shouldTreatURLAsSameAsCurrent:[request URL]]) {
747 [r setCachePolicy:NSURLRequestReloadIgnoringCacheData];
748 loadType = WebFrameLoadTypeSame;
750 loadType = WebFrameLoadTypeStandard;
752 [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
753 [newDataSource _addToUnarchiveState:archive];
755 // When we loading alternate content for an unreachable URL that we're
756 // visiting in the b/f list, we treat it as a reload so the b/f list
757 // is appropriately maintained.
758 if ([webFrame _shouldReloadToHandleUnreachableURLFromRequest:request]) {
759 ASSERT(loadType == WebFrameLoadTypeStandard);
760 loadType = WebFrameLoadTypeReload;
763 [webFrame _loadDataSource:newDataSource withLoadType:loadType formState:nil];
766 - (void)_loadRequest:(NSURLRequest *)request triggeringAction:(NSDictionary *)action loadType:(WebFrameLoadType)loadType formState:(WebFormState *)formState
768 policyDocumentLoadState = [webFrame _createDocumentLoadStateWithRequest:request];
769 WebDataSource *newDataSource = [webFrame _dataSourceForDocumentLoadState:policyDocumentLoadState];
771 [newDataSource _setTriggeringAction:action];
773 [newDataSource _setOverrideEncoding:[[self dataSource] _overrideEncoding]];
775 [webFrame _loadDataSource:newDataSource withLoadType:loadType formState:formState];
778 - (void)_reloadAllowingStaleDataWithOverrideEncoding:(NSString *)encoding
780 WebDataSource *ds = [self dataSource];
784 NSMutableURLRequest *request = [[ds request] mutableCopy];
785 NSURL *unreachableURL = [ds unreachableURL];
786 if (unreachableURL != nil)
787 [request setURL:unreachableURL];
789 [request setCachePolicy:NSURLRequestReturnCacheDataElseLoad];
790 policyDocumentLoadState = [webFrame _createDocumentLoadStateWithRequest:request];
791 WebDataSource *newDataSource = [webFrame _dataSourceForDocumentLoadState:policyDocumentLoadState];
794 [newDataSource _setOverrideEncoding:encoding];
796 [webFrame _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReloadAllowingStaleData formState:nil];
801 WebDataSource *ds = [self dataSource];
805 NSMutableURLRequest *initialRequest = [ds request];
807 // If a window is created by javascript, its main frame can have an empty but non-nil URL.
808 // Reloading in this case will lose the current contents (see 4151001).
809 if ([[[[ds request] URL] absoluteString] length] == 0)
812 // Replace error-page URL with the URL we were trying to reach.
813 NSURL *unreachableURL = [initialRequest _webDataRequestUnreachableURL];
814 if (unreachableURL != nil)
815 initialRequest = [NSURLRequest requestWithURL:unreachableURL];
817 policyDocumentLoadState = [webFrame _createDocumentLoadStateWithRequest:initialRequest];
818 WebDataSource *newDataSource = [webFrame _dataSourceForDocumentLoadState:policyDocumentLoadState];
819 NSMutableURLRequest *request = [newDataSource request];
821 [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
823 // If we're about to rePOST, set up action so the app can warn the user
824 if ([[request HTTPMethod] _webkit_isCaseInsensitiveEqualToString:@"POST"]) {
825 NSDictionary *action = [webFrame _actionInformationForNavigationType:WebNavigationTypeFormResubmitted event:nil originalURL:[request URL]];
826 [newDataSource _setTriggeringAction:action];
829 [newDataSource _setOverrideEncoding:[ds _overrideEncoding]];
831 [webFrame _loadDataSource:newDataSource withLoadType:WebFrameLoadTypeReload formState:nil];
834 - (void)didReceiveServerRedirectForProvisionalLoadForFrame
836 [webFrame _didReceiveServerRedirectForProvisionalLoadForFrame];
839 - (void)finishedLoadingDocumentLoadState:(WebDocumentLoadState *)loadState
841 [[webFrame _dataSourceForDocumentLoadState:loadState] _finishedLoading];
844 - (void)commitProvisitionalLoad
846 [webFrame _commitProvisionalLoad:nil];
849 - (void)committedLoadWithDocumentLoadState:(WebDocumentLoadState *)loadState data:(NSData *)data
851 [[webFrame _dataSourceForDocumentLoadState:loadState] _receivedData:data];
856 return [webFrame _loadType] == WebFrameLoadTypeReplace;
861 [webFrame _setLoadType:WebFrameLoadTypeReplace];
864 - (void)revertToProvisionalWithDocumentLoadState:(WebDocumentLoadState *)loadState
866 [[webFrame _dataSourceForDocumentLoadState:loadState] _revertToProvisionalState];
869 - (void)documentLoadState:(WebDocumentLoadState *)loadState setMainDocumentError:(NSError *)error
871 [[webFrame _dataSourceForDocumentLoadState:loadState] _setMainDocumentError:error];
874 - (void)documentLoadState:(WebDocumentLoadState *)loadState mainReceivedCompleteError:(NSError *)error
876 [[webFrame _dataSourceForDocumentLoadState:loadState] _setPrimaryLoadComplete:YES];
877 [webFrame _checkLoadComplete];
880 - (void)finalSetupForReplaceWithDocumentLoadState:(WebDocumentLoadState *)loadState
882 [[webFrame _dataSourceForDocumentLoadState:loadState] _clearUnarchivingState];