Changeset 17365 in webkit


Ignore:
Timestamp:
Oct 27, 2006 12:09:47 AM (17 years ago)
Author:
darin
Message:

Reviewed by Maciej.

  • moved methods that are there just to be called by the frame loader client into the client in an attempt to get back some of the speed we lost yesterday
  • DefaultDelegates/WebDefaultResourceLoadDelegate.m: (-[WebDefaultResourceLoadDelegate webView:resource:didReceiveAuthenticationChallenge:fromDataSource:]): (-[WebDefaultResourceLoadDelegate webView:resource:didCancelAuthenticationChallenge:fromDataSource:]):
  • WebCoreSupport/WebFrameLoaderClient.h:
  • WebCoreSupport/WebFrameLoaderClient.mm: (dataSource): (decisionListener): (WebFrameLoaderClient::WebFrameLoaderClient): (WebFrameLoaderClient::hasWebView): (WebFrameLoaderClient::hasFrameView): (WebFrameLoaderClient::hasBackForwardList): (WebFrameLoaderClient::resetBackForwardList): (WebFrameLoaderClient::provisionalItemIsTarget): (WebFrameLoaderClient::loadProvisionalItemFromPageCache): (WebFrameLoaderClient::invalidateCurrentItemPageCache): (WebFrameLoaderClient::privateBrowsingEnabled): (WebFrameLoaderClient::makeDocumentView): (WebFrameLoaderClient::makeRepresentation): (WebFrameLoaderClient::setDocumentViewFromPageCache): (WebFrameLoaderClient::forceLayout): (WebFrameLoaderClient::forceLayoutForNonHTML): (WebFrameLoaderClient::updateHistoryForCommit): (WebFrameLoaderClient::updateHistoryForBackForwardNavigation): (WebFrameLoaderClient::updateHistoryForReload): (WebFrameLoaderClient::updateHistoryForStandardLoad): (WebFrameLoaderClient::updateHistoryForInternalLoad): (WebFrameLoaderClient::updateHistoryAfterClientRedirect): (WebFrameLoaderClient::setCopiesOnScroll): (WebFrameLoaderClient::tokenForLoadErrorReset): (WebFrameLoaderClient::resetAfterLoadError): (WebFrameLoaderClient::doNotResetAfterLoadError): (WebFrameLoaderClient::detachedFromParent1): (WebFrameLoaderClient::detachedFromParent2): (WebFrameLoaderClient::detachedFromParent3): (WebFrameLoaderClient::detachedFromParent4): (WebFrameLoaderClient::loadedFromPageCache): (WebFrameLoaderClient::download): (WebFrameLoaderClient::dispatchIdentifierForInitialRequest): (WebFrameLoaderClient::dispatchWillSendRequest): (WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge): (WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge): (WebFrameLoaderClient::dispatchDidReceiveResponse): (WebFrameLoaderClient::dispatchDidReceiveContentLength): (WebFrameLoaderClient::dispatchDidFinishLoading): (WebFrameLoaderClient::dispatchDidFailLoading): (WebFrameLoaderClient::dispatchDidHandleOnloadEvents): (WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad): (WebFrameLoaderClient::dispatchDidCancelClientRedirect): (WebFrameLoaderClient::dispatchWillPerformClientRedirect): (WebFrameLoaderClient::dispatchDidChangeLocationWithinPage): (WebFrameLoaderClient::dispatchWillClose): (WebFrameLoaderClient::dispatchDidReceiveIcon): (WebFrameLoaderClient::dispatchDidStartProvisionalLoad): (WebFrameLoaderClient::dispatchDidReceiveTitle): (WebFrameLoaderClient::dispatchDidCommitLoad): (WebFrameLoaderClient::dispatchDidFailProvisionalLoad): (WebFrameLoaderClient::dispatchDidFailLoad): (WebFrameLoaderClient::dispatchDidFinishLoad): (WebFrameLoaderClient::dispatchDidFirstLayout): (WebFrameLoaderClient::dispatchCreatePage): (WebFrameLoaderClient::dispatchShow): (WebFrameLoaderClient::dispatchDecidePolicyForMIMEType): (WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction): (WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction): (WebFrameLoaderClient::dispatchUnableToImplementPolicy): (WebFrameLoaderClient::dispatchWillSubmitForm): (WebFrameLoaderClient::dispatchDidLoadMainResource): (WebFrameLoaderClient::clearLoadingFromPageCache): (WebFrameLoaderClient::isLoadingFromPageCache): (WebFrameLoaderClient::revertToProvisionalState): (WebFrameLoaderClient::setMainDocumentError): (WebFrameLoaderClient::clearUnarchivingState): (WebFrameLoaderClient::progressStarted): (WebFrameLoaderClient::progressCompleted): (WebFrameLoaderClient::incrementProgress): (WebFrameLoaderClient::completeProgress): (WebFrameLoaderClient::setMainFrameDocumentReady): (WebFrameLoaderClient::startDownload): (WebFrameLoaderClient::willChangeTitle): (WebFrameLoaderClient::didChangeTitle): (WebFrameLoaderClient::committedLoad): (WebFrameLoaderClient::finishedLoading): (WebFrameLoaderClient::finalSetupForReplace): (WebFrameLoaderClient::cancelledError): (WebFrameLoaderClient::cannotShowURLError): (WebFrameLoaderClient::interruptForPolicyChangeError): (WebFrameLoaderClient::cannotShowMIMETypeError): (WebFrameLoaderClient::fileDoesNotExistError): (WebFrameLoaderClient::shouldFallBack): (WebFrameLoaderClient::mainFrameURL): (WebFrameLoaderClient::setDefersCallbacks): (WebFrameLoaderClient::willUseArchive): (WebFrameLoaderClient::isArchiveLoadPending): (WebFrameLoaderClient::cancelPendingArchiveLoad): (WebFrameLoaderClient::clearArchivedResources): (WebFrameLoaderClient::canHandleRequest): (WebFrameLoaderClient::canShowMIMEType): (WebFrameLoaderClient::representationExistsForURLScheme): (WebFrameLoaderClient::generatedMIMETypeForURLScheme): (WebFrameLoaderClient::elementForEvent): (WebFrameLoaderClient::createPolicyDecider): (WebFrameLoaderClient::frameLoadCompleted): (WebFrameLoaderClient::restoreScrollPositionAndViewState): (WebFrameLoaderClient::provisionalLoadStarted): (WebFrameLoaderClient::shouldTreatURLAsSameAsCurrent): (WebFrameLoaderClient::addHistoryItemForFragmentScroll): (WebFrameLoaderClient::didFinishLoad): (WebFrameLoaderClient::prepareForDataSourceReplacement): (WebFrameLoaderClient::createDocumentLoader): (WebFrameLoaderClient::setTitle): (WebFrameLoaderClient::canUseArchivedResource): (WebFrameLoaderClient::deliverArchivedResourcesAfterDelay): (WebFrameLoaderClient::deliverArchivedResources): (WebFrameLoaderClient::createPageCache):
  • WebView/WebFrame.mm: (-[NSView setWebFrame:]): (-[WebFrame _createItem:]): (-[WebFrame _loadItem:withLoadType:]): (-[WebFrame _recursiveGoToItem:fromItem:withLoadType:]): (-[WebFrame _loadURL:referrer:intoChild:]): (-[WebFrame _saveScrollPositionAndViewStateToItem:]): (-[WebFrame _hasSelection]): (-[WebFrame _clearSelection]): (-[WebFrame _setProvisionalItem:]): (-[WebFrame _setPreviousItem:]): (-[WebFrame _setCurrentItem:]): (-[WebFrame loadArchive:]):
  • WebView/WebFrameInternal.h:
  • WebView/WebHTMLView.m: (-[WebHTMLView _topHTMLView]):
  • WebView/WebHTMLViewPrivate.h:
Location:
trunk/WebKit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebKit/ChangeLog

    r17352 r17365  
     12006-10-27  Darin Adler  <darin@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        - moved methods that are there just to be called by the frame loader client into the client
     6          in an attempt to get back some of the speed we lost yesterday
     7
     8        * DefaultDelegates/WebDefaultResourceLoadDelegate.m:
     9        (-[WebDefaultResourceLoadDelegate webView:resource:didReceiveAuthenticationChallenge:fromDataSource:]):
     10        (-[WebDefaultResourceLoadDelegate webView:resource:didCancelAuthenticationChallenge:fromDataSource:]):
     11        * WebCoreSupport/WebFrameLoaderClient.h:
     12        * WebCoreSupport/WebFrameLoaderClient.mm:
     13        (dataSource):
     14        (decisionListener):
     15        (WebFrameLoaderClient::WebFrameLoaderClient):
     16        (WebFrameLoaderClient::hasWebView):
     17        (WebFrameLoaderClient::hasFrameView):
     18        (WebFrameLoaderClient::hasBackForwardList):
     19        (WebFrameLoaderClient::resetBackForwardList):
     20        (WebFrameLoaderClient::provisionalItemIsTarget):
     21        (WebFrameLoaderClient::loadProvisionalItemFromPageCache):
     22        (WebFrameLoaderClient::invalidateCurrentItemPageCache):
     23        (WebFrameLoaderClient::privateBrowsingEnabled):
     24        (WebFrameLoaderClient::makeDocumentView):
     25        (WebFrameLoaderClient::makeRepresentation):
     26        (WebFrameLoaderClient::setDocumentViewFromPageCache):
     27        (WebFrameLoaderClient::forceLayout):
     28        (WebFrameLoaderClient::forceLayoutForNonHTML):
     29        (WebFrameLoaderClient::updateHistoryForCommit):
     30        (WebFrameLoaderClient::updateHistoryForBackForwardNavigation):
     31        (WebFrameLoaderClient::updateHistoryForReload):
     32        (WebFrameLoaderClient::updateHistoryForStandardLoad):
     33        (WebFrameLoaderClient::updateHistoryForInternalLoad):
     34        (WebFrameLoaderClient::updateHistoryAfterClientRedirect):
     35        (WebFrameLoaderClient::setCopiesOnScroll):
     36        (WebFrameLoaderClient::tokenForLoadErrorReset):
     37        (WebFrameLoaderClient::resetAfterLoadError):
     38        (WebFrameLoaderClient::doNotResetAfterLoadError):
     39        (WebFrameLoaderClient::detachedFromParent1):
     40        (WebFrameLoaderClient::detachedFromParent2):
     41        (WebFrameLoaderClient::detachedFromParent3):
     42        (WebFrameLoaderClient::detachedFromParent4):
     43        (WebFrameLoaderClient::loadedFromPageCache):
     44        (WebFrameLoaderClient::download):
     45        (WebFrameLoaderClient::dispatchIdentifierForInitialRequest):
     46        (WebFrameLoaderClient::dispatchWillSendRequest):
     47        (WebFrameLoaderClient::dispatchDidReceiveAuthenticationChallenge):
     48        (WebFrameLoaderClient::dispatchDidCancelAuthenticationChallenge):
     49        (WebFrameLoaderClient::dispatchDidReceiveResponse):
     50        (WebFrameLoaderClient::dispatchDidReceiveContentLength):
     51        (WebFrameLoaderClient::dispatchDidFinishLoading):
     52        (WebFrameLoaderClient::dispatchDidFailLoading):
     53        (WebFrameLoaderClient::dispatchDidHandleOnloadEvents):
     54        (WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad):
     55        (WebFrameLoaderClient::dispatchDidCancelClientRedirect):
     56        (WebFrameLoaderClient::dispatchWillPerformClientRedirect):
     57        (WebFrameLoaderClient::dispatchDidChangeLocationWithinPage):
     58        (WebFrameLoaderClient::dispatchWillClose):
     59        (WebFrameLoaderClient::dispatchDidReceiveIcon):
     60        (WebFrameLoaderClient::dispatchDidStartProvisionalLoad):
     61        (WebFrameLoaderClient::dispatchDidReceiveTitle):
     62        (WebFrameLoaderClient::dispatchDidCommitLoad):
     63        (WebFrameLoaderClient::dispatchDidFailProvisionalLoad):
     64        (WebFrameLoaderClient::dispatchDidFailLoad):
     65        (WebFrameLoaderClient::dispatchDidFinishLoad):
     66        (WebFrameLoaderClient::dispatchDidFirstLayout):
     67        (WebFrameLoaderClient::dispatchCreatePage):
     68        (WebFrameLoaderClient::dispatchShow):
     69        (WebFrameLoaderClient::dispatchDecidePolicyForMIMEType):
     70        (WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction):
     71        (WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction):
     72        (WebFrameLoaderClient::dispatchUnableToImplementPolicy):
     73        (WebFrameLoaderClient::dispatchWillSubmitForm):
     74        (WebFrameLoaderClient::dispatchDidLoadMainResource):
     75        (WebFrameLoaderClient::clearLoadingFromPageCache):
     76        (WebFrameLoaderClient::isLoadingFromPageCache):
     77        (WebFrameLoaderClient::revertToProvisionalState):
     78        (WebFrameLoaderClient::setMainDocumentError):
     79        (WebFrameLoaderClient::clearUnarchivingState):
     80        (WebFrameLoaderClient::progressStarted):
     81        (WebFrameLoaderClient::progressCompleted):
     82        (WebFrameLoaderClient::incrementProgress):
     83        (WebFrameLoaderClient::completeProgress):
     84        (WebFrameLoaderClient::setMainFrameDocumentReady):
     85        (WebFrameLoaderClient::startDownload):
     86        (WebFrameLoaderClient::willChangeTitle):
     87        (WebFrameLoaderClient::didChangeTitle):
     88        (WebFrameLoaderClient::committedLoad):
     89        (WebFrameLoaderClient::finishedLoading):
     90        (WebFrameLoaderClient::finalSetupForReplace):
     91        (WebFrameLoaderClient::cancelledError):
     92        (WebFrameLoaderClient::cannotShowURLError):
     93        (WebFrameLoaderClient::interruptForPolicyChangeError):
     94        (WebFrameLoaderClient::cannotShowMIMETypeError):
     95        (WebFrameLoaderClient::fileDoesNotExistError):
     96        (WebFrameLoaderClient::shouldFallBack):
     97        (WebFrameLoaderClient::mainFrameURL):
     98        (WebFrameLoaderClient::setDefersCallbacks):
     99        (WebFrameLoaderClient::willUseArchive):
     100        (WebFrameLoaderClient::isArchiveLoadPending):
     101        (WebFrameLoaderClient::cancelPendingArchiveLoad):
     102        (WebFrameLoaderClient::clearArchivedResources):
     103        (WebFrameLoaderClient::canHandleRequest):
     104        (WebFrameLoaderClient::canShowMIMEType):
     105        (WebFrameLoaderClient::representationExistsForURLScheme):
     106        (WebFrameLoaderClient::generatedMIMETypeForURLScheme):
     107        (WebFrameLoaderClient::elementForEvent):
     108        (WebFrameLoaderClient::createPolicyDecider):
     109        (WebFrameLoaderClient::frameLoadCompleted):
     110        (WebFrameLoaderClient::restoreScrollPositionAndViewState):
     111        (WebFrameLoaderClient::provisionalLoadStarted):
     112        (WebFrameLoaderClient::shouldTreatURLAsSameAsCurrent):
     113        (WebFrameLoaderClient::addHistoryItemForFragmentScroll):
     114        (WebFrameLoaderClient::didFinishLoad):
     115        (WebFrameLoaderClient::prepareForDataSourceReplacement):
     116        (WebFrameLoaderClient::createDocumentLoader):
     117        (WebFrameLoaderClient::setTitle):
     118        (WebFrameLoaderClient::canUseArchivedResource):
     119        (WebFrameLoaderClient::deliverArchivedResourcesAfterDelay):
     120        (WebFrameLoaderClient::deliverArchivedResources):
     121        (WebFrameLoaderClient::createPageCache):
     122        * WebView/WebFrame.mm:
     123        (-[NSView setWebFrame:]):
     124        (-[WebFrame _createItem:]):
     125        (-[WebFrame _loadItem:withLoadType:]):
     126        (-[WebFrame _recursiveGoToItem:fromItem:withLoadType:]):
     127        (-[WebFrame _loadURL:referrer:intoChild:]):
     128        (-[WebFrame _saveScrollPositionAndViewStateToItem:]):
     129        (-[WebFrame _hasSelection]):
     130        (-[WebFrame _clearSelection]):
     131        (-[WebFrame _setProvisionalItem:]):
     132        (-[WebFrame _setPreviousItem:]):
     133        (-[WebFrame _setCurrentItem:]):
     134        (-[WebFrame loadArchive:]):
     135        * WebView/WebFrameInternal.h:
     136        * WebView/WebHTMLView.m:
     137        (-[WebHTMLView _topHTMLView]):
     138        * WebView/WebHTMLViewPrivate.h:
     139
    11402006-10-26  Geoffrey Garen  <ggaren@apple.com>
    2141
  • trunk/WebKit/DefaultDelegates/WebDefaultResourceLoadDelegate.m

    r14586 r17365  
    6666- (void)webView:(WebView *)wv resource:(id)identifier didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource
    6767{
    68     NSWindow *window = [wv hostWindow] ? [wv hostWindow] : [wv window];
    69     [[WebPanelAuthenticationHandler sharedHandler] startAuthentication:challenge window:window];
    7068}
    7169
    7270- (void)webView:(WebView *)wv resource:(id)identifier didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge fromDataSource:(WebDataSource *)dataSource
    7371{
    74     [(WebPanelAuthenticationHandler *)[WebPanelAuthenticationHandler sharedHandler] cancelAuthentication:challenge];
    7572}
    7673
  • trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.h

    r17352 r17365  
    2828
    2929#import <WebCore/RetainPtr.h>
     30#import <WebCore/Timer.h>
    3031#import <WebCore/WebFrameLoaderClient.h>
     32#import <wtf/HashMap.h>
    3133
    3234@class WebFrame;
     35@class WebHistoryItem;
     36@class WebResource;
    3337
    3438namespace WebCore {
    3539    class String;
     40    class WebResourceLoader;
    3641}
     42
     43typedef HashMap<RefPtr<WebCore::WebResourceLoader>, WebCore::RetainPtr<WebResource> > ResourceMap;
    3744
    3845class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
     
    4148    WebFrame* webFrame() const { return m_webFrame.get(); }
    4249
     50private:
    4351    virtual void detachFrameLoader();
    4452
     
    181189    virtual void setTitle(NSString *title, NSURL *);
    182190
    183 private:
     191    void deliverArchivedResourcesAfterDelay() const;
     192    bool canUseArchivedResource(NSURLRequest *) const;
     193    bool canUseArchivedResource(NSURLResponse *) const;
     194    void deliverArchivedResources(WebCore::Timer<WebFrameLoaderClient>*);
     195
     196    bool createPageCache(WebHistoryItem *);
     197
    184198    WebCore::RetainPtr<WebFrame> m_webFrame;
     199    mutable ResourceMap m_pendingArchivedResources;
     200    mutable WebCore::Timer<WebFrameLoaderClient> m_archivedResourcesDeliveryTimer;
    185201};
  • trunk/WebKit/WebCoreSupport/WebFrameLoaderClient.mm

    r17352 r17365  
    2929#import "WebFrameLoaderClient.h"
    3030
     31// Terrible hack, but needed so we can get right at the private structure.
     32#define private public
     33#import "WebFrame.h"
     34#undef private
     35
     36#import "WebBackForwardList.h"
     37#import "WebDataSourceInternal.h"
     38#import "WebDocumentInternal.h"
     39#import "WebDocumentLoaderMac.h"
     40#import "WebDownloadInternal.h"
    3141#import "WebFrameInternal.h"
     42#import "WebFrameLoadDelegate.h"
     43#import "WebFrameViewInternal.h"
     44#import "WebHTMLRepresentation.h"
     45#import "WebHTMLView.h"
     46#import "WebHistoryItemPrivate.h"
     47#import "WebHistoryPrivate.h"
     48#import "WebKitErrorsPrivate.h"
     49#import "WebKitNSStringExtras.h"
     50#import "WebNSURLExtras.h"
     51#import "WebPanelAuthenticationHandler.h"
     52#import "WebPolicyDeciderMac.h"
     53#import "WebPolicyDelegatePrivate.h"
     54#import "WebPreferences.h"
     55#import "WebResourcePrivate.h"
     56#import "WebResourceLoadDelegate.h"
     57#import "WebScriptDebugServerPrivate.h"
     58#import "WebUIDelegate.h"
     59#import "WebViewInternal.h"
    3260#import <WebCore/FrameMac.h>
     61#import <WebCore/FrameTree.h>
    3362#import <WebCore/PlatformString.h>
    3463#import <WebCore/WebCoreFrameBridge.h>
     64#import <WebCore/WebDataProtocol.h>
    3565#import <WebCore/WebDocumentLoader.h>
    36 #import <WebKit/DOMElement.h>
     66#import <WebCore/WebFrameLoader.h>
     67#import <WebCore/WebLoader.h>
     68#import <WebKitSystemInterface.h>
    3769#import <wtf/PassRefPtr.h>
    3870
    3971using namespace WebCore;
     72
     73static inline WebDataSource *dataSource(DocumentLoader* loader)
     74{
     75    return loader ? static_cast<WebDocumentLoaderMac*>(loader)->dataSource() : nil;
     76}
     77
     78static inline WebPolicyDecisionListener *decisionListener(WebPolicyDecider *decider)
     79{
     80    return [(WebPolicyDeciderMac *)decider decisionListener];
     81}
    4082
    4183WebFrameLoaderClient::WebFrameLoaderClient(WebFrame *webFrame)
    4284    : m_webFrame(webFrame)
     85    , m_archivedResourcesDeliveryTimer(this, &WebFrameLoaderClient::deliverArchivedResources)
    4386{
    4487}
     
    5194bool WebFrameLoaderClient::hasWebView() const
    5295{
    53     return [m_webFrame.get() _hasWebView];
     96    return [m_webFrame.get() webView] != nil;
    5497}
    5598
    5699bool WebFrameLoaderClient::hasFrameView() const
    57100{
    58     return [m_webFrame.get() _hasFrameView];
     101    return m_webFrame->_private->webFrameView != nil;
    59102}
    60103
    61104bool WebFrameLoaderClient::hasBackForwardList() const
    62105{
    63     return [m_webFrame.get() _hasBackForwardList];
     106    return [[m_webFrame.get() webView] backForwardList] != nil;
    64107}
    65108
    66109void WebFrameLoaderClient::resetBackForwardList()
    67110{
    68     [m_webFrame.get() _resetBackForwardList];
     111    // Note this doesn't verify the current load type as a b/f operation because it is called from
     112    // a subframe in the case of a delegate bailing out of the nav before it even gets to provisional state.
     113    WebFrame *mainFrame = [[m_webFrame.get() webView] mainFrame];
     114    WebHistoryItem *resetItem = mainFrame->_private->currentItem;
     115    if (resetItem)
     116        [[[m_webFrame.get() webView] backForwardList] goToItem:resetItem];
    69117}
    70118
    71119bool WebFrameLoaderClient::provisionalItemIsTarget() const
    72120{
    73     return [m_webFrame.get() _provisionalItemIsTarget];
     121    return [m_webFrame->_private->provisionalItem isTargetItem];
    74122}
    75123
    76124bool WebFrameLoaderClient::loadProvisionalItemFromPageCache()
    77125{
    78     return [m_webFrame.get() _loadProvisionalItemFromPageCache];
     126    WebHistoryItem *item = m_webFrame->_private->provisionalItem;
     127    if (![item hasPageCache])
     128        return false;
     129    NSDictionary *pageCache = [item pageCache];
     130    if (![pageCache objectForKey:WebCorePageCacheStateKey])
     131        return false;
     132    [[m_webFrame.get() provisionalDataSource] _loadFromPageCache:pageCache];
     133    return true;
    79134}
    80135
    81136void WebFrameLoaderClient::invalidateCurrentItemPageCache()
    82137{
    83     [m_webFrame.get() _invalidateCurrentItemPageCache];
     138    // When we are pre-commit, the currentItem is where the pageCache data resides
     139    WebHistoryItem *currentItem = m_webFrame->_private->currentItem;
     140    NSDictionary *pageCache = [currentItem pageCache];
     141    [m_webFrame->_private->bridge invalidatePageCache:pageCache];
     142    // We're assuming that WebCore invalidates its pageCache state in didNotOpen:pageCache:
     143    [currentItem setHasPageCache:NO];
    84144}
    85145
    86146bool WebFrameLoaderClient::privateBrowsingEnabled() const
    87147{
    88     return [m_webFrame.get() _privateBrowsingEnabled];
     148    return [[[m_webFrame.get() webView] preferences] privateBrowsingEnabled];
    89149}
    90150
    91151void WebFrameLoaderClient::makeDocumentView()
    92152{
    93     [m_webFrame.get() _makeDocumentView];
     153    WebFrameView *v = m_webFrame->_private->webFrameView;
     154    WebDataSource *ds = [m_webFrame.get() dataSource];
     155
     156    NSView <WebDocumentView> *documentView = [v _makeDocumentViewForDataSource:ds];
     157    if (!documentView)
     158        return;
     159
     160    WebFrameBridge *bridge = m_webFrame->_private->bridge;
     161
     162    // FIXME: We could save work and not do this for a top-level view that is not a WebHTMLView.
     163    [bridge createFrameViewWithNSView:documentView marginWidth:[v _marginWidth] marginHeight:[v _marginHeight]];
     164    [m_webFrame.get() _updateBackground];
     165    [bridge installInFrame:[v _scrollView]];
     166
     167    // Call setDataSource on the document view after it has been placed in the view hierarchy.
     168    // This what we for the top-level view, so should do this for views in subframes as well.
     169    [documentView setDataSource:ds];
    94170}
    95171
    96172void WebFrameLoaderClient::makeRepresentation(DocumentLoader* loader)
    97173{
    98     [m_webFrame.get() _makeRepresentationForDocumentLoader:loader];
    99 }
    100 
    101 void WebFrameLoaderClient::setDocumentViewFromPageCache(NSDictionary *dictionary)
    102 {
    103     [m_webFrame.get() _setDocumentViewFromPageCache:dictionary];
     174    [dataSource(loader) _makeRepresentation];
     175}
     176
     177void WebFrameLoaderClient::setDocumentViewFromPageCache(NSDictionary *pageCache)
     178{
     179    NSView <WebDocumentView> *cachedView = [pageCache objectForKey:WebPageCacheDocumentViewKey];
     180    ASSERT(cachedView != nil);
     181    [m_webFrame->_private->webFrameView _setDocumentView:cachedView];
    104182}
    105183
    106184void WebFrameLoaderClient::forceLayout()
    107185{
    108     [m_webFrame.get() _forceLayout];
     186    NSView <WebDocumentView> *view = [m_webFrame->_private->webFrameView documentView];
     187    if ([view isKindOfClass:[WebHTMLView class]])
     188        [(WebHTMLView *)view setNeedsToApplyStyles:YES];
     189    [view setNeedsLayout:YES];
     190    [view layout];
    109191}
    110192
    111193void WebFrameLoaderClient::forceLayoutForNonHTML()
    112194{
    113     [m_webFrame.get() _forceLayoutForNonHTML];
     195    WebFrameView *thisView = m_webFrame->_private->webFrameView;
     196    NSView <WebDocumentView> *thisDocumentView = [thisView documentView];
     197    ASSERT(thisDocumentView != nil);
     198   
     199    // Tell the just loaded document to layout.  This may be necessary
     200    // for non-html content that needs a layout message.
     201    if (!([[m_webFrame.get() dataSource] _isDocumentHTML])) {
     202        [thisDocumentView setNeedsLayout:YES];
     203        [thisDocumentView layout];
     204        [thisDocumentView setNeedsDisplay:YES];
     205    }
    114206}
    115207
    116208void WebFrameLoaderClient::updateHistoryForCommit()
    117209{
    118     [m_webFrame.get() _updateHistoryForCommit];
     210    FrameLoadType type = core(m_webFrame.get())->loader()->loadType();
     211    if (isBackForwardLoadType(type) ||
     212        (type == FrameLoadTypeReload && [[m_webFrame.get() provisionalDataSource] unreachableURL] != nil)) {
     213        // Once committed, we want to use current item for saving DocState, and
     214        // the provisional item for restoring state.
     215        // Note previousItem must be set before we close the URL, which will
     216        // happen when the data source is made non-provisional below
     217        [m_webFrame.get() _setPreviousItem:m_webFrame->_private->currentItem];
     218        ASSERT(m_webFrame->_private->provisionalItem);
     219        [m_webFrame.get() _setCurrentItem:m_webFrame->_private->provisionalItem];
     220        [m_webFrame.get() _setProvisionalItem:nil];
     221    }
    119222}
    120223
    121224void WebFrameLoaderClient::updateHistoryForBackForwardNavigation()
    122225{
    123     [m_webFrame.get() _updateHistoryForBackForwardNavigation];
     226    // Must grab the current scroll position before disturbing it
     227    [m_webFrame.get() _saveScrollPositionAndViewStateToItem:m_webFrame->_private->previousItem];
    124228}
    125229
    126230void WebFrameLoaderClient::updateHistoryForReload()
    127231{
    128     [m_webFrame.get() _updateHistoryForReload];
     232    WebHistoryItem *currItem = m_webFrame->_private->previousItem;
     233    [currItem setHasPageCache:NO];
     234    if (core(m_webFrame.get())->loader()->loadType() == FrameLoadTypeReload)
     235        [m_webFrame.get() _saveScrollPositionAndViewStateToItem:currItem];
     236    WebDataSource *dataSource = [m_webFrame.get() dataSource];
     237    NSURLRequest *request = [dataSource request];
     238    // Sometimes loading a page again leads to a different result because of cookies. Bugzilla 4072
     239    if ([request _webDataRequestUnreachableURL] == nil)
     240        [currItem setURL:[request URL]];
     241    // Update the last visited time. Mostly interesting for URL autocompletion statistics.
     242    NSURL *URL = [[[dataSource _documentLoader]->originalRequestCopy() URL] _webkit_canonicalize];
     243    WebHistory *sharedHistory = [WebHistory optionalSharedHistory];
     244    WebHistoryItem *oldItem = [sharedHistory itemForURL:URL];
     245    if (oldItem)
     246        [sharedHistory setLastVisitedTimeInterval:[NSDate timeIntervalSinceReferenceDate] forItem:oldItem];
    129247}
    130248
    131249void WebFrameLoaderClient::updateHistoryForStandardLoad()
    132250{
    133     [m_webFrame.get() _updateHistoryForStandardLoad];
     251    WebDataSource *dataSource = [m_webFrame.get() dataSource];
     252    if (![dataSource _documentLoader]->isClientRedirect()) {
     253        NSURL *URL = [dataSource _URLForHistory];
     254        if (URL && ![URL _web_isEmpty]) {
     255            ASSERT([m_webFrame.get() webView]);
     256            if (![[[m_webFrame.get() webView] preferences] privateBrowsingEnabled]) {
     257                WebHistoryItem *entry = [[WebHistory optionalSharedHistory] addItemForURL:URL];
     258                if ([dataSource pageTitle])
     259                    [entry setTitle:[dataSource pageTitle]];                           
     260            }
     261            [m_webFrame.get() _addBackForwardItemClippedAtTarget:YES];
     262        }
     263    } else {
     264        NSURLRequest *request = [dataSource request];
     265       
     266        // Update the URL in the BF list that we made before the redirect, unless
     267        // this is alternate content for an unreachable URL (we want the BF list
     268        // item to remember the unreachable URL in case it becomes reachable later).
     269        if ([request _webDataRequestUnreachableURL] == nil) {
     270            [m_webFrame->_private->currentItem setURL:[request URL]];
     271
     272            // clear out the form data so we don't repost it to the wrong place if we
     273            // ever go back/forward to this item
     274            [m_webFrame->_private->currentItem _setFormInfoFromRequest:request];
     275
     276            // We must also clear out form data so we don't try to restore it into the incoming page,
     277            // see -_opened
     278        }
     279    }
    134280}
    135281
    136282void WebFrameLoaderClient::updateHistoryForInternalLoad()
    137283{
    138     [m_webFrame.get() _updateHistoryForInternalLoad];
    139 }
    140 
     284    // Add an item to the item tree for this frame
     285    ASSERT(!core(m_webFrame.get())->loader()->documentLoader()->isClientRedirect());
     286    WebFrame *parentFrame = [m_webFrame.get() parentFrame];
     287    if (parentFrame) {
     288        WebHistoryItem *parentItem = parentFrame->_private->currentItem;
     289        // The only case where parentItem==nil should be when a parent frame loaded an
     290        // empty URL, which doesn't set up a current item in that parent.
     291        if (parentItem)
     292            [parentItem addChildItem:[m_webFrame.get() _createItem:YES]];
     293    } else {
     294        // See 3556159. It's not clear if it's valid to be in WebFrameLoadTypeOnLoadEvent
     295        // for a top-level frame, but that was a likely explanation for those crashes,
     296        // so let's guard against it.
     297        // ...and all WebFrameLoadTypeOnLoadEvent uses were folded to WebFrameLoadTypeInternal
     298        LOG_ERROR("no parent frame in transitionToCommitted:, WebFrameLoadTypeInternal");
     299    }
     300}
    141301
    142302void WebFrameLoaderClient::updateHistoryAfterClientRedirect()
    143303{
    144     [m_webFrame.get() _updateHistoryAfterClientRedirect];
     304    // Clear out form data so we don't try to restore it into the incoming page.  Must happen after
     305    // khtml has closed the URL and saved away the form state.
     306    WebHistoryItem *item = m_webFrame->_private->currentItem;
     307    [item setDocumentState:nil];
     308    [item setScrollPoint:NSZeroPoint];
    145309}
    146310
    147311void WebFrameLoaderClient::setCopiesOnScroll()
    148312{
    149     [m_webFrame.get() _setCopiesOnScroll];
     313    [[[m_webFrame->_private->webFrameView _scrollView] contentView] setCopiesOnScroll:YES];
    150314}
    151315
    152316LoadErrorResetToken* WebFrameLoaderClient::tokenForLoadErrorReset()
    153317{
    154     return [m_webFrame.get() _tokenForLoadErrorReset];
     318    if (isBackForwardLoadType(core(m_webFrame.get())->loader()->loadType()) && [m_webFrame.get() _isMainFrame])
     319        return (LoadErrorResetToken*)[m_webFrame->_private->currentItem retain];
     320    return 0;
    155321}
    156322
    157323void WebFrameLoaderClient::resetAfterLoadError(LoadErrorResetToken* token)
    158324{
    159     [m_webFrame.get() _resetAfterLoadError:token];
     325    WebHistoryItem *item = (WebHistoryItem *)token;
     326    if (!item)
     327        return;
     328    [[[m_webFrame.get() webView] backForwardList] goToItem:item];
     329    [item release];
    160330}
    161331
    162332void WebFrameLoaderClient::doNotResetAfterLoadError(LoadErrorResetToken* token)
    163333{
    164     [m_webFrame.get() _doNotResetAfterLoadError:token];
     334    WebHistoryItem *item = (WebHistoryItem *)token;
     335    [item release];
    165336}
    166337
    167338void WebFrameLoaderClient::detachedFromParent1()
    168339{
    169     [m_webFrame.get() _detachedFromParent1];
     340    [m_webFrame.get() _saveScrollPositionAndViewStateToItem:m_webFrame->_private->currentItem];
    170341}
    171342
    172343void WebFrameLoaderClient::detachedFromParent2()
    173344{
    174     [m_webFrame.get() _detachedFromParent2];
     345    [m_webFrame->_private->inspectors makeObjectsPerformSelector:@selector(_webFrameDetached:) withObject:m_webFrame.get()];
     346    [m_webFrame->_private->webFrameView _setWebFrame:nil]; // needed for now to be compatible w/ old behavior
    175347}
    176348
    177349void WebFrameLoaderClient::detachedFromParent3()
    178350{
    179     [m_webFrame.get() _detachedFromParent3];
     351    [m_webFrame->_private->webFrameView release];
     352    m_webFrame->_private->webFrameView = nil;
    180353}
    181354
    182355void WebFrameLoaderClient::detachedFromParent4()
    183356{
    184     [m_webFrame.get() _detachedFromParent4];
     357    m_webFrame->_private->bridge = nil;
    185358}
    186359
    187360void WebFrameLoaderClient::loadedFromPageCache()
    188361{
    189     [m_webFrame.get() _loadedFromPageCache];
     362    // Release the resources kept in the page cache.
     363    // They will be reset when we leave this page.
     364    // The WebCore side of the page cache will have already been invalidated by
     365    // the bridge to prevent premature release.
     366    [m_webFrame->_private->currentItem setHasPageCache:NO];
    190367}
    191368
     
    193370    NSURLResponse *response, id proxy)
    194371{
    195     [m_webFrame.get() _downloadWithLoadingConnection:connection request:request response:response proxy:proxy];
     372    [WebDownload _downloadWithLoadingConnection:connection
     373                                        request:request
     374                                       response:response
     375                                       delegate:[[m_webFrame.get() webView] downloadDelegate]
     376                                          proxy:proxy];
    196377}
    197378
    198379id WebFrameLoaderClient::dispatchIdentifierForInitialRequest(DocumentLoader* loader, NSURLRequest *request)
    199380{
    200     return [m_webFrame.get() _dispatchIdentifierForInitialRequest:request fromDocumentLoader:loader];
     381    WebView *webView = [m_webFrame.get() webView];
     382    id resourceLoadDelegate = [webView resourceLoadDelegate];
     383   
     384    if ([webView _resourceLoadDelegateImplementations].delegateImplementsIdentifierForRequest)
     385        return [resourceLoadDelegate webView:webView identifierForInitialRequest:request fromDataSource:dataSource(loader)];
     386    return [[[NSObject alloc] init] autorelease];
    201387}
    202388
     
    204390    NSURLRequest *request, NSURLResponse *redirectResponse)
    205391{
    206     return [m_webFrame.get() _dispatchResource:identifier willSendRequest:request
    207         redirectResponse:redirectResponse fromDocumentLoader:loader];
     392    WebView *webView = [m_webFrame.get() webView];
     393    id resourceLoadDelegate = [webView resourceLoadDelegate];
     394
     395    if ([webView _resourceLoadDelegateImplementations].delegateImplementsWillSendRequest)
     396        return [resourceLoadDelegate webView:webView resource:identifier willSendRequest:request redirectResponse:redirectResponse fromDataSource:dataSource(loader)];
     397
     398    return request;
    208399}
    209400
     
    211402    NSURLAuthenticationChallenge *challenge)
    212403{
    213     [m_webFrame.get() _dispatchDidReceiveAuthenticationChallenge:challenge forResource:identifier
    214         fromDocumentLoader:loader];
     404    WebView *webView = [m_webFrame.get() webView];
     405    id resourceLoadDelegate = [webView resourceLoadDelegate];
     406
     407    if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveAuthenticationChallenge) {
     408        [resourceLoadDelegate webView:webView resource:identifier didReceiveAuthenticationChallenge:challenge fromDataSource:dataSource(loader)];
     409        return;
     410    }
     411
     412    NSWindow *window = [webView hostWindow] ? [webView hostWindow] : [webView window];
     413    [[WebPanelAuthenticationHandler sharedHandler] startAuthentication:challenge window:window];
    215414}
    216415
     
    218417    NSURLAuthenticationChallenge *challenge)
    219418{
    220     [m_webFrame.get() _dispatchDidCancelAuthenticationChallenge:challenge forResource:identifier
    221         fromDocumentLoader:loader];
     419    WebView *webView = [m_webFrame.get() webView];
     420    id resourceLoadDelegate = [webView resourceLoadDelegate];
     421
     422    if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidCancelAuthenticationChallenge) {
     423        [resourceLoadDelegate webView:webView resource:identifier didCancelAuthenticationChallenge:challenge fromDataSource:dataSource(loader)];
     424        return;
     425    }
     426
     427    [(WebPanelAuthenticationHandler *)[WebPanelAuthenticationHandler sharedHandler] cancelAuthentication:challenge];
    222428}
    223429
    224430void WebFrameLoaderClient::dispatchDidReceiveResponse(DocumentLoader* loader, id identifier, NSURLResponse *response)
    225431{
    226     [m_webFrame.get() _dispatchResource:identifier didReceiveResponse:response fromDocumentLoader:loader];
     432    WebView *webView = [m_webFrame.get() webView];
     433
     434    if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveResponse)
     435        [[webView resourceLoadDelegate] webView:webView resource:identifier didReceiveResponse:response fromDataSource:dataSource(loader)];
    227436}
    228437
    229438void WebFrameLoaderClient::dispatchDidReceiveContentLength(DocumentLoader* loader, id identifier, int lengthReceived)
    230439{
    231     [m_webFrame.get() _dispatchResource:identifier didReceiveContentLength:lengthReceived fromDocumentLoader:loader];
     440    WebView *webView = [m_webFrame.get() webView];
     441
     442    if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveContentLength)
     443        [[webView resourceLoadDelegate] webView:webView resource:identifier didReceiveContentLength:(WebNSUInteger)lengthReceived fromDataSource:dataSource(loader)];
    232444}
    233445
    234446void WebFrameLoaderClient::dispatchDidFinishLoading(DocumentLoader* loader, id identifier)
    235447{
    236     [m_webFrame.get() _dispatchResource:identifier didFinishLoadingFromDocumentLoader:loader];
     448    WebView *webView = [m_webFrame.get() webView];
     449   
     450    if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidFinishLoadingFromDataSource)
     451        [[webView resourceLoadDelegate] webView:webView resource:identifier didFinishLoadingFromDataSource:dataSource(loader)];
    237452}
    238453
    239454void WebFrameLoaderClient::dispatchDidFailLoading(DocumentLoader* loader, id identifier, NSError *error)
    240455{
    241     [m_webFrame.get() _dispatchResource:identifier didFailLoadingWithError:error fromDocumentLoader:loader];
     456    WebView *webView = [m_webFrame.get() webView];
     457    [[webView _resourceLoadDelegateForwarder] webView:webView resource:identifier didFailLoadingWithError:error fromDataSource:dataSource(loader)];
    242458}
    243459
    244460void WebFrameLoaderClient::dispatchDidHandleOnloadEvents()
    245461{
    246     [m_webFrame.get() _dispatchDidHandleOnloadEventsForFrame];
     462    WebView *webView = [m_webFrame.get() webView];
     463    [[webView _frameLoadDelegateForwarder] webView:webView didHandleOnloadEventsForFrame:m_webFrame.get()];
    247464}
    248465
    249466void WebFrameLoaderClient::dispatchDidReceiveServerRedirectForProvisionalLoad()
    250467{
    251     [m_webFrame.get() _dispatchDidReceiveServerRedirectForProvisionalLoadForFrame];
     468    WebView *webView = [m_webFrame.get() webView];
     469    [[webView _frameLoadDelegateForwarder] webView:webView
     470       didReceiveServerRedirectForProvisionalLoadForFrame:m_webFrame.get()];
    252471}
    253472
    254473void WebFrameLoaderClient::dispatchDidCancelClientRedirect()
    255474{
    256     [m_webFrame.get() _dispatchDidCancelClientRedirectForFrame];
     475    WebView *webView = [m_webFrame.get() webView];
     476    [[webView _frameLoadDelegateForwarder] webView:webView didCancelClientRedirectForFrame:m_webFrame.get()];
    257477}
    258478
    259479void WebFrameLoaderClient::dispatchWillPerformClientRedirect(NSURL *URL, NSTimeInterval delay, NSDate *fireDate)
    260480{
    261     [m_webFrame.get() _dispatchWillPerformClientRedirectToURL:URL delay:delay fireDate:fireDate];
     481    WebView *webView = [m_webFrame.get() webView];   
     482    [[webView _frameLoadDelegateForwarder] webView:webView
     483                         willPerformClientRedirectToURL:URL
     484                                                  delay:delay
     485                                               fireDate:fireDate
     486                                               forFrame:m_webFrame.get()];
    262487}
    263488
    264489void WebFrameLoaderClient::dispatchDidChangeLocationWithinPage()
    265490{
    266     [m_webFrame.get() _dispatchDidChangeLocationWithinPageForFrame];
     491    WebView *webView = [m_webFrame.get() webView];   
     492    [[webView _frameLoadDelegateForwarder] webView:webView didChangeLocationWithinPageForFrame:m_webFrame.get()];
    267493}
    268494
    269495void WebFrameLoaderClient::dispatchWillClose()
    270496{
    271     [m_webFrame.get() _dispatchWillCloseFrame];
     497    WebView *webView = [m_webFrame.get() webView];   
     498    [[webView _frameLoadDelegateForwarder] webView:webView willCloseFrame:m_webFrame.get()];
    272499}
    273500
    274501void WebFrameLoaderClient::dispatchDidReceiveIcon(NSImage *icon)
    275502{
    276     [m_webFrame.get() _dispatchDidReceiveIcon:icon];
     503    WebView *webView = [m_webFrame.get() webView];   
     504    ASSERT([m_webFrame.get() _isMainFrame]);
     505    [webView _willChangeValueForKey:_WebMainFrameIconKey];
     506    [[webView _frameLoadDelegateForwarder] webView:webView didReceiveIcon:icon forFrame:m_webFrame.get()];
     507    [webView _didChangeValueForKey:_WebMainFrameIconKey];
    277508}
    278509
    279510void WebFrameLoaderClient::dispatchDidStartProvisionalLoad()
    280511{
    281     [m_webFrame.get() _dispatchDidStartProvisionalLoadForFrame];
     512    WebView *webView = [m_webFrame.get() webView];   
     513    [webView _didStartProvisionalLoadForFrame:m_webFrame.get()];
     514    [[webView _frameLoadDelegateForwarder] webView:webView didStartProvisionalLoadForFrame:m_webFrame.get()];   
    282515}
    283516
    284517void WebFrameLoaderClient::dispatchDidReceiveTitle(const String& title)
    285518{
    286     [m_webFrame.get() _dispatchDidReceiveTitle:title];
     519    WebView *webView = [m_webFrame.get() webView];   
     520    [[webView _frameLoadDelegateForwarder] webView:webView didReceiveTitle:title forFrame:m_webFrame.get()];
    287521}
    288522
    289523void WebFrameLoaderClient::dispatchDidCommitLoad()
    290524{
    291     [m_webFrame.get() _dispatchDidCommitLoadForFrame];
     525    // Tell the client we've committed this URL.
     526    ASSERT([m_webFrame->_private->webFrameView documentView] != nil);
     527
     528    WebView *webView = [m_webFrame.get() webView];   
     529    [webView _didCommitLoadForFrame:m_webFrame.get()];
     530    [[webView _frameLoadDelegateForwarder] webView:webView didCommitLoadForFrame:m_webFrame.get()];
    292531}
    293532
    294533void WebFrameLoaderClient::dispatchDidFailProvisionalLoad(NSError *error)
    295534{
    296     [m_webFrame.get() _dispatchDidFailProvisionalLoadWithError:error];
     535    WebView *webView = [m_webFrame.get() webView];   
     536    [webView _didFailProvisionalLoadWithError:error forFrame:m_webFrame.get()];
     537    [[webView _frameLoadDelegateForwarder] webView:webView didFailProvisionalLoadWithError:error forFrame:m_webFrame.get()];
     538    [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:error];
    297539}
    298540
    299541void WebFrameLoaderClient::dispatchDidFailLoad(NSError *error)
    300542{
    301     [m_webFrame.get() _dispatchDidFailLoadWithError:error];
     543    WebView *webView = [m_webFrame.get() webView];   
     544    [webView _didFailLoadWithError:error forFrame:m_webFrame.get()];
     545    [[webView _frameLoadDelegateForwarder] webView:webView didFailLoadWithError:error forFrame:m_webFrame.get()];
     546    [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:error];
    302547}
    303548
    304549void WebFrameLoaderClient::dispatchDidFinishLoad()
    305550{
    306     [m_webFrame.get() _dispatchDidFinishLoadForFrame];
     551    WebView *webView = [m_webFrame.get() webView];   
     552    [webView _didFinishLoadForFrame:m_webFrame.get()];
     553    [[webView _frameLoadDelegateForwarder] webView:webView didFinishLoadForFrame:m_webFrame.get()];
     554    [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:nil];
    307555}
    308556
    309557void WebFrameLoaderClient::dispatchDidFirstLayout()
    310558{
    311     [m_webFrame.get() _dispatchDidFirstLayoutInFrame];
     559    WebView *webView = [m_webFrame.get() webView];
     560    [[webView _frameLoadDelegateForwarder] webView:webView didFirstLayoutInFrame:m_webFrame.get()];
    312561}
    313562
    314563Frame* WebFrameLoaderClient::dispatchCreatePage(NSURLRequest *request)
    315564{
    316     return [m_webFrame.get() _dispatchCreateWebViewWithRequest:request];
     565    WebView *currentWebView = [m_webFrame.get() webView];
     566    id wd = [currentWebView UIDelegate];
     567    if ([wd respondsToSelector:@selector(webView:createWebViewWithRequest:)])
     568        return core([[wd webView:currentWebView createWebViewWithRequest:request] mainFrame]);
     569    return 0;
    317570}
    318571
    319572void WebFrameLoaderClient::dispatchShow()
    320573{
    321     [m_webFrame.get() _dispatchShow];
     574    WebView *webView = [m_webFrame.get() webView];
     575    [[webView _UIDelegateForwarder] webViewShow:webView];
    322576}
    323577
    324578void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(WebPolicyDecider *decider, const String& MIMEType, NSURLRequest *request)
    325579{
    326     [m_webFrame.get() _dispatchDecidePolicyForMIMEType:MIMEType request:request decider:decider];
     580    WebView *webView = [m_webFrame.get() webView];
     581
     582    [[webView _policyDelegateForwarder] webView:webView decidePolicyForMIMEType:MIMEType request:request frame:m_webFrame.get() decisionListener:decisionListener(decider)];
    327583}
    328584
    329585void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(WebPolicyDecider *decider, NSDictionary *action, NSURLRequest *request, const String& frameName)
    330586{
    331     [m_webFrame.get() _dispatchDecidePolicyForNewWindowAction:action request:request newFrameName:frameName
    332         decider:decider];
     587    WebView *webView = [m_webFrame.get() webView];
     588    [[webView _policyDelegateForwarder] webView:webView
     589            decidePolicyForNewWindowAction:action
     590                                   request:request
     591                              newFrameName:frameName
     592                          decisionListener:decisionListener(decider)];
    333593}
    334594
     
    336596    NSURLRequest *request)
    337597{
    338     [m_webFrame.get() _dispatchDecidePolicyForNavigationAction:action request:request decider:decider];
     598    WebView *webView = [m_webFrame.get() webView];
     599    [[webView _policyDelegateForwarder] webView:webView
     600                decidePolicyForNavigationAction:action
     601                                        request:request
     602                                          frame:m_webFrame.get()
     603                               decisionListener:decisionListener(decider)];
    339604}
    340605
    341606void WebFrameLoaderClient::dispatchUnableToImplementPolicy(NSError *error)
    342607{
    343     [m_webFrame.get() _dispatchUnableToImplementPolicyWithError:error];
     608    WebView *webView = [m_webFrame.get() webView];
     609    [[webView _policyDelegateForwarder] webView:webView unableToImplementPolicyWithError:error frame:m_webFrame.get()];   
    344610}
    345611
     
    347613    Element* form, NSDictionary *values)
    348614{
    349     [m_webFrame.get() _dispatchSourceFrame:sourceFrame
    350         willSubmitForm:form withValues:values submissionDecider:decider];
     615    [[[m_webFrame.get() webView] _formDelegate] frame:m_webFrame.get() sourceFrame:kit(sourceFrame) willSubmitForm:kit(form) withValues:values submissionListener:decisionListener(decider)];
    351616}
    352617
    353618void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader* loader)
    354619{
    355     [m_webFrame.get() _dispatchDidLoadMainResourceForDocumentLoader:loader];
     620    if ([WebScriptDebugServer listenerCount])
     621        [[WebScriptDebugServer sharedScriptDebugServer] webView:[m_webFrame.get() webView]
     622            didLoadMainResourceForDataSource:dataSource(loader)];
    356623}
    357624
    358625void WebFrameLoaderClient::clearLoadingFromPageCache(DocumentLoader* loader)
    359626{
    360     [m_webFrame.get() _clearLoadingFromPageCacheForDocumentLoader:loader];
     627    [dataSource(loader) _setLoadingFromPageCache:NO];
    361628}
    362629
    363630bool WebFrameLoaderClient::isLoadingFromPageCache(DocumentLoader* loader)
    364631{
    365     return [m_webFrame.get() _isDocumentLoaderLoadingFromPageCache:loader];
     632    return [dataSource(loader) _loadingFromPageCache];
    366633}
    367634
    368635void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader* loader)
    369636{
    370     [m_webFrame.get() _revertToProvisionalStateForDocumentLoader:loader];
     637    [dataSource(loader) _revertToProvisionalState];
    371638}
    372639
    373640void WebFrameLoaderClient::setMainDocumentError(DocumentLoader* loader, NSError *error)
    374641{
    375     [m_webFrame.get() _setMainDocumentError:error forDocumentLoader:loader];
     642    [dataSource(loader) _setMainDocumentError:error];
    376643}
    377644
    378645void WebFrameLoaderClient::clearUnarchivingState(DocumentLoader* loader)
    379646{
    380     [m_webFrame.get() _clearUnarchivingStateForLoader:loader];
     647    [dataSource(loader) _clearUnarchivingState];
    381648}
    382649
    383650void WebFrameLoaderClient::progressStarted()
    384651{
    385     [m_webFrame.get() _progressStarted];
     652    [[m_webFrame.get() webView] _progressStarted:m_webFrame.get()];
    386653}
    387654
    388655void WebFrameLoaderClient::progressCompleted()
    389656{
    390     [m_webFrame.get() _progressCompleted];
     657    [[m_webFrame.get() webView] _progressCompleted:m_webFrame.get()];
    391658}
    392659
    393660void WebFrameLoaderClient::incrementProgress(id identifier, NSURLResponse *response)
    394661{
    395     [m_webFrame.get() _incrementProgressForIdentifier:identifier response:response];
     662    [[m_webFrame.get() webView] _incrementProgressForIdentifier:identifier response:response];
    396663}
    397664
    398665void WebFrameLoaderClient::incrementProgress(id identifier, NSData *data)
    399666{
    400     [m_webFrame.get() _incrementProgressForIdentifier:identifier data:data];
     667    [[m_webFrame.get() webView] _incrementProgressForIdentifier:identifier data:data];
    401668}
    402669
    403670void WebFrameLoaderClient::completeProgress(id identifier)
    404671{
    405     [m_webFrame.get() _completeProgressForIdentifier:identifier];
     672    [[m_webFrame.get() webView] _completeProgressForIdentifier:identifier];
    406673}
    407674
    408675void WebFrameLoaderClient::setMainFrameDocumentReady(bool ready)
    409676{
    410     [m_webFrame.get() _setMainFrameDocumentReady:ready];
     677    [[m_webFrame.get() webView] setMainFrameDocumentReady:ready];
    411678}
    412679
    413680void WebFrameLoaderClient::startDownload(NSURLRequest *request)
    414681{
    415     [m_webFrame.get() _startDownloadWithRequest:request];
     682    // FIXME: Should download full request.
     683    [[m_webFrame.get() webView] _downloadURL:[request URL]];
    416684}
    417685
    418686void WebFrameLoaderClient::willChangeTitle(DocumentLoader* loader)
    419687{
    420     [m_webFrame.get() _willChangeTitleForDocument:loader];
     688    // FIXME: Should do this only in main frame case, right?
     689    [[m_webFrame.get() webView] _willChangeValueForKey:_WebMainFrameTitleKey];
    421690}
    422691
    423692void WebFrameLoaderClient::didChangeTitle(DocumentLoader* loader)
    424693{
    425     [m_webFrame.get() _didChangeTitleForDocument:loader];
     694    // FIXME: Should do this only in main frame case, right?
     695    [[m_webFrame.get() webView] _didChangeValueForKey:_WebMainFrameTitleKey];
    426696}
    427697
    428698void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, NSData *data)
    429699{
    430     [m_webFrame.get() _committedLoadWithDocumentLoader:loader data:data];
     700    [dataSource(loader) _receivedData:data];
    431701}
    432702
    433703void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader)
    434704{
    435     [m_webFrame.get() _finishedLoadingDocument:loader];
     705    [dataSource(loader) _finishedLoading];
    436706}
    437707
    438708void WebFrameLoaderClient::finalSetupForReplace(DocumentLoader* loader)
    439709{
    440     [m_webFrame.get() _finalSetupForReplaceWithDocumentLoader:loader];
     710    [dataSource(loader) _clearUnarchivingState];
    441711}
    442712
    443713NSError *WebFrameLoaderClient::cancelledError(NSURLRequest *request)
    444714{
    445     return [m_webFrame.get() _cancelledErrorWithRequest:request];
     715    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled URL:[request URL]];
    446716}
    447717
    448718NSError *WebFrameLoaderClient::cannotShowURLError(NSURLRequest *request)
    449719{
    450     return [m_webFrame.get() _cannotShowURLErrorWithRequest:request];
     720    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotShowURL URL:[request URL]];
    451721}
    452722
    453723NSError *WebFrameLoaderClient::interruptForPolicyChangeError(NSURLRequest *request)
    454724{
    455     return [m_webFrame.get() _interruptForPolicyChangeErrorWithRequest:request];
     725    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:[request URL]];
    456726}
    457727
    458728NSError *WebFrameLoaderClient::cannotShowMIMETypeError(NSURLResponse *response)
    459729{
    460     return [m_webFrame.get() _cannotShowMIMETypeErrorWithResponse:response];
     730    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:WebKitErrorCannotShowMIMEType URL:[response URL]];   
    461731}
    462732
    463733NSError *WebFrameLoaderClient::fileDoesNotExistError(NSURLResponse *response)
    464734{
    465     return [m_webFrame.get() _fileDoesNotExistErrorWithResponse:response];
     735    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist URL:[response URL]];   
    466736}
    467737
    468738bool WebFrameLoaderClient::shouldFallBack(NSError *error)
    469739{
    470     return [m_webFrame.get() _shouldFallBackForError:error];
     740    // FIXME: Needs to check domain.
     741    // FIXME: WebKitErrorPlugInWillHandleLoad is a workaround for the cancel we do to prevent
     742    // loading plugin content twice.  See <rdar://problem/4258008>
     743    return [error code] != NSURLErrorCancelled && [error code] != WebKitErrorPlugInWillHandleLoad;
    471744}
    472745
    473746NSURL *WebFrameLoaderClient::mainFrameURL()
    474747{
    475     return [m_webFrame.get() _mainFrameURL];
     748    return [[[[m_webFrame.get() webView] mainFrame] dataSource] _URL];
    476749}
    477750
    478751void WebFrameLoaderClient::setDefersCallbacks(bool defers)
    479752{
    480     [m_webFrame.get() _setDefersCallbacks:defers];
     753    if (!defers)
     754        deliverArchivedResourcesAfterDelay();
    481755}
    482756
    483757bool WebFrameLoaderClient::willUseArchive(WebResourceLoader* loader, NSURLRequest *request, NSURL *originalURL) const
    484758{
    485     return [m_webFrame.get() _willUseArchiveForRequest:request originalURL:originalURL loader:loader];
     759    if (![[request URL] isEqual:originalURL])
     760        return false;
     761    if (!canUseArchivedResource(request))
     762        return false;
     763    WebResource *resource = [dataSource(core(m_webFrame.get())->loader()->activeDocumentLoader()) _archivedSubresourceForURL:originalURL];
     764    if (!resource)
     765        return false;
     766    if (!canUseArchivedResource([resource _response]))
     767        return false;
     768    m_pendingArchivedResources.set(loader, resource);
     769    // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
     770    deliverArchivedResourcesAfterDelay();
     771    return true;
    486772}
    487773
    488774bool WebFrameLoaderClient::isArchiveLoadPending(WebResourceLoader* loader) const
    489775{
    490     return [m_webFrame.get() _archiveLoadPendingForLoader:loader];
     776    return m_pendingArchivedResources.contains(loader);
    491777}
    492778
    493779void WebFrameLoaderClient::cancelPendingArchiveLoad(WebResourceLoader* loader)
    494780{
    495     [m_webFrame.get() _cancelPendingArchiveLoadForLoader:loader];
     781    if (m_pendingArchivedResources.isEmpty())
     782        return;
     783    m_pendingArchivedResources.remove(loader);
     784    if (m_pendingArchivedResources.isEmpty())
     785        m_archivedResourcesDeliveryTimer.stop();
    496786}
    497787
    498788void WebFrameLoaderClient::clearArchivedResources()
    499789{
    500     [m_webFrame.get() _clearArchivedResources];
     790    m_pendingArchivedResources.clear();
     791    m_archivedResourcesDeliveryTimer.stop();
    501792}
    502793
    503794bool WebFrameLoaderClient::canHandleRequest(NSURLRequest *request) const
    504795{
    505     return [m_webFrame.get() _canHandleRequest:request];
     796    return [WebView _canHandleRequest:request];
    506797}
    507798
    508799bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const
    509800{
    510     return [m_webFrame.get() _canShowMIMEType:MIMEType];
     801    return [WebView canShowMIMEType:MIMEType];
    511802}
    512803
    513804bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const
    514805{
    515     return [m_webFrame.get() _representationExistsForURLScheme:URLScheme];
     806    return [WebView _representationExistsForURLScheme:URLScheme];
    516807}
    517808
    518809String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const
    519810{
    520     return [m_webFrame.get() _generatedMIMETypeForURLScheme:URLScheme];
     811    return [WebView _generatedMIMETypeForURLScheme:URLScheme];
    521812}
    522813
    523814NSDictionary *WebFrameLoaderClient::elementForEvent(NSEvent *event) const
    524815{
    525     return [m_webFrame.get() _elementForEvent:event];
     816    switch ([event type]) {
     817        case NSLeftMouseDown:
     818        case NSRightMouseDown:
     819        case NSOtherMouseDown:
     820        case NSLeftMouseUp:
     821        case NSRightMouseUp:
     822        case NSOtherMouseUp:
     823            break;
     824        default:
     825            return nil;
     826    }
     827
     828    NSView *topViewInEventWindow = [[event window] contentView];
     829    NSView *viewContainingPoint = [topViewInEventWindow hitTest:
     830        [topViewInEventWindow convertPoint:[event locationInWindow] fromView:nil]];
     831    while (viewContainingPoint) {
     832        if ([viewContainingPoint isKindOfClass:[WebView class]])
     833            return [(WebView *)viewContainingPoint elementAtPoint:
     834                [viewContainingPoint convertPoint:[event locationInWindow] fromView:nil]];
     835        viewContainingPoint = [viewContainingPoint superview];
     836    }
     837    return nil;
    526838}
    527839
    528840WebPolicyDecider *WebFrameLoaderClient::createPolicyDecider(id object, SEL selector)
    529841{
    530     return [m_webFrame.get() _createPolicyDeciderWithTarget:object action:selector];
     842    return [[WebPolicyDeciderMac alloc] initWithTarget:object action:selector];
    531843}
    532844
    533845void WebFrameLoaderClient::frameLoadCompleted()
    534846{
    535     [m_webFrame.get() _frameLoadCompleted];
    536 }
    537 
     847    // Note: Can be called multiple times.
     848    // Even if already complete, we might have set a previous item on a frame that
     849    // didn't do any data loading on the past transaction. Make sure to clear these out.
     850    NSScrollView *sv = [m_webFrame->_private->webFrameView _scrollView];
     851    if ([[m_webFrame.get() webView] drawsBackground])
     852        [sv setDrawsBackground:YES];
     853    [m_webFrame.get() _setPreviousItem:nil];
     854}
     855
     856/*
     857 There is a race condition between the layout and load completion that affects restoring the scroll position.
     858 We try to restore the scroll position at both the first layout and upon load completion.
     859 
     860 1) If first layout happens before the load completes, we want to restore the scroll position then so that the
     861 first time we draw the page is already scrolled to the right place, instead of starting at the top and later
     862 jumping down.  It is possible that the old scroll position is past the part of the doc laid out so far, in
     863 which case the restore silent fails and we will fix it in when we try to restore on doc completion.
     864 2) If the layout happens after the load completes, the attempt to restore at load completion time silently
     865 fails.  We then successfully restore it when the layout happens.
     866*/
    538867void WebFrameLoaderClient::restoreScrollPositionAndViewState()
    539868{
    540     [m_webFrame.get() _restoreScrollPositionAndViewState];
     869    ASSERT(m_webFrame->_private->currentItem);
     870    NSView <WebDocumentView> *docView = [m_webFrame->_private->webFrameView documentView];
     871    NSPoint point = [m_webFrame->_private->currentItem scrollPoint];
     872    if ([docView conformsToProtocol:@protocol(_WebDocumentViewState)]) {       
     873        id state = [m_webFrame->_private->currentItem viewState];
     874        if (state) {
     875            [(id <_WebDocumentViewState>)docView setViewState:state];
     876        }
     877       
     878        [(id <_WebDocumentViewState>)docView setScrollPoint:point];
     879    } else {
     880        [docView scrollPoint:point];
     881    }
    541882}
    542883
    543884void WebFrameLoaderClient::provisionalLoadStarted()
    544885{
    545     [m_webFrame.get() _provisionalLoadStarted];
     886    FrameLoadType loadType = core(m_webFrame.get())->loader()->loadType();
     887   
     888    // FIXME: This is OK as long as no one resizes the window,
     889    // but in the case where someone does, it means garbage outside
     890    // the occupied part of the scroll view.
     891    [[m_webFrame->_private->webFrameView _scrollView] setDrawsBackground:NO];
     892   
     893    // Cache the page, if possible.
     894    // Don't write to the cache if in the middle of a redirect, since we will want to
     895    // store the final page we end up on.
     896    // No point writing to the cache on a reload or loadSame, since we will just write
     897    // over it again when we leave that page.
     898    WebHistoryItem *item = m_webFrame->_private->currentItem;
     899    if ([m_webFrame.get() _canCachePage]
     900        && item
     901        && !core(m_webFrame.get())->loader()->isQuickRedirectComing()
     902        && loadType != FrameLoadTypeReload
     903        && loadType != FrameLoadTypeReloadAllowingStaleData
     904        && loadType != FrameLoadTypeSame
     905        && ![[m_webFrame.get() dataSource] isLoading]
     906        && !core(m_webFrame.get())->loader()->documentLoader()->isStopping()) {
     907        if ([[[m_webFrame.get() dataSource] representation] isKindOfClass:[WebHTMLRepresentation class]]) {
     908            if (![item pageCache]) {
     909                // Add the items to this page's cache.
     910                if (createPageCache(item))
     911                    // See if any page caches need to be purged after the addition of this new page cache.
     912                    [m_webFrame.get() _purgePageCache];
     913            }
     914        } else
     915            // Put the document into a null state, so it can be restored correctly.
     916            core(m_webFrame.get())->clear();
     917    }
    546918}
    547919
    548920bool WebFrameLoaderClient::shouldTreatURLAsSameAsCurrent(NSURL *URL) const
    549921{
    550     return [m_webFrame.get() _shouldTreatURLAsSameAsCurrent:URL];
     922    WebHistoryItem *item = m_webFrame->_private->currentItem;
     923    NSString* URLString = [URL _web_originalDataAsString];
     924    return [URLString isEqual:[item URLString]] || [URLString isEqual:[item originalURLString]];
    551925}
    552926
    553927void WebFrameLoaderClient::addHistoryItemForFragmentScroll()
    554928{
    555     [m_webFrame.get() _addHistoryItemForFragmentScroll];
     929    [m_webFrame.get() _addBackForwardItemClippedAtTarget:NO];
    556930}
    557931
    558932void WebFrameLoaderClient::didFinishLoad()
    559933{
    560     [m_webFrame.get() _didFinishLoad];
     934    [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:nil];   
    561935}
    562936
    563937void WebFrameLoaderClient::prepareForDataSourceReplacement()
    564938{
    565     [m_webFrame.get() _prepareForDataSourceReplacement];
     939    if (![m_webFrame.get() dataSource]) {
     940        ASSERT(!core(m_webFrame.get())->tree()->childCount());
     941        return;
     942    }
     943   
     944    // Make sure that any work that is triggered by resigning first reponder can get done.
     945    // The main example where this came up is the textDidEndEditing that is sent to the
     946    // FormsDelegate (3223413).  We need to do this before _detachChildren, since that will
     947    // remove the views as a side-effect of freeing the bridge, at which point we can't
     948    // post the FormDelegate messages.
     949    //
     950    // Note that this can also take FirstResponder away from a child of our frameView that
     951    // is not in a child frame's view.  This is OK because we are in the process
     952    // of loading new content, which will blow away all editors in this top frame, and if
     953    // a non-editor is firstReponder it will not be affected by endEditingFor:.
     954    // Potentially one day someone could write a DocView whose editors were not all
     955    // replaced by loading new content, but that does not apply currently.
     956    NSView *frameView = m_webFrame->_private->webFrameView;
     957    NSWindow *window = [frameView window];
     958    NSResponder *firstResp = [window firstResponder];
     959    if ([firstResp isKindOfClass:[NSView class]] && [(NSView *)firstResp isDescendantOf:frameView])
     960        [window endEditingFor:firstResp];
     961   
     962    core(m_webFrame.get())->loader()->detachChildren();
    566963}
    567964
    568965PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(NSURLRequest *request)
    569966{
    570     return [m_webFrame.get() _createDocumentLoaderWithRequest:request];
     967    RefPtr<WebDocumentLoaderMac> loader = new WebDocumentLoaderMac(request);
     968
     969    WebDataSource *dataSource = [[WebDataSource alloc] _initWithDocumentLoader:loader.get()];
     970    loader->setDataSource(dataSource);
     971    [dataSource release];
     972
     973    return loader.release();
    571974}
    572975
    573976void WebFrameLoaderClient::setTitle(NSString *title, NSURL *URL)
    574977{
    575     [m_webFrame.get() _setTitle:title forURL:URL];
    576 }
     978    [[[WebHistory optionalSharedHistory] itemForURL:URL] setTitle:title];
     979    [m_webFrame->_private->currentItem setTitle:title];
     980}
     981
     982// The following 2 functions are copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
     983// FIXME: It would be nice to eventually to share this logic somehow.
     984bool WebFrameLoaderClient::canUseArchivedResource(NSURLRequest *request) const
     985{
     986    NSURLRequestCachePolicy policy = [request cachePolicy];
     987    if (policy == NSURLRequestReturnCacheDataElseLoad)
     988        return true;
     989    if (policy == NSURLRequestReturnCacheDataDontLoad)
     990        return true;
     991    if (policy == NSURLRequestReloadIgnoringCacheData)
     992        return false;
     993    if ([request valueForHTTPHeaderField:@"must-revalidate"] != nil)
     994        return false;
     995    if ([request valueForHTTPHeaderField:@"proxy-revalidate"] != nil)
     996        return false;
     997    if ([request valueForHTTPHeaderField:@"If-Modified-Since"] != nil)
     998        return false;
     999    if ([request valueForHTTPHeaderField:@"Cache-Control"] != nil)
     1000        return false;
     1001    if ([@"POST" _webkit_isCaseInsensitiveEqualToString:[request HTTPMethod]])
     1002        return false;
     1003    return true;
     1004}
     1005
     1006bool WebFrameLoaderClient::canUseArchivedResource(NSURLResponse *response) const
     1007{
     1008    if (WKGetNSURLResponseMustRevalidate(response))
     1009        return false;
     1010    if (WKGetNSURLResponseCalculatedExpiration(response) - CFAbsoluteTimeGetCurrent() < 1)
     1011        return false;
     1012    return true;
     1013}
     1014
     1015void WebFrameLoaderClient::deliverArchivedResourcesAfterDelay() const
     1016{
     1017    if (m_pendingArchivedResources.isEmpty())
     1018        return;
     1019    if (core(m_webFrame.get())->loader()->defersCallbacks())
     1020        return;
     1021    if (!m_archivedResourcesDeliveryTimer.isActive())
     1022        m_archivedResourcesDeliveryTimer.startOneShot(0);
     1023}
     1024
     1025void WebFrameLoaderClient::deliverArchivedResources(Timer<WebFrameLoaderClient>*)
     1026{
     1027    if (m_pendingArchivedResources.isEmpty())
     1028        return;
     1029    if (core(m_webFrame.get())->loader()->defersCallbacks())
     1030        return;
     1031
     1032    const ResourceMap copy = m_pendingArchivedResources;
     1033    m_pendingArchivedResources.clear();
     1034
     1035    ResourceMap::const_iterator end = copy.end();
     1036    for (ResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
     1037        RefPtr<WebResourceLoader> loader = it->first;
     1038        WebResource *resource = it->second.get();
     1039        NSData *data = [[resource data] retain];
     1040        loader->didReceiveResponse([resource _response]);
     1041        loader->didReceiveData(data, [data length], true);
     1042        [data release];
     1043        loader->didFinishLoading();
     1044    }
     1045}
     1046
     1047bool WebFrameLoaderClient::createPageCache(WebHistoryItem *item)
     1048{
     1049    [item setHasPageCache:YES];
     1050    if (![m_webFrame->_private->bridge saveDocumentToPageCache]) {
     1051        [item setHasPageCache:NO];
     1052        return NO;
     1053    }
     1054    NSMutableDictionary *pageCache = [item pageCache];
     1055    [pageCache setObject:[NSDate date] forKey: WebPageCacheEntryDateKey];
     1056    [pageCache setObject:[m_webFrame.get() dataSource] forKey: WebPageCacheDataSourceKey];
     1057    [pageCache setObject:[m_webFrame->_private->webFrameView documentView] forKey: WebPageCacheDocumentViewKey];
     1058    return YES;
     1059}
  • trunk/WebKit/WebView/WebFrame.mm

    r17352 r17365  
    2929#import "WebFrameInternal.h"
    3030
    31 #import "WebArchive.h"
    3231#import "WebBackForwardList.h"
    3332#import "WebDataSourceInternal.h"
    34 #import "WebDefaultResourceLoadDelegate.h"
    35 #import "WebDefaultUIDelegate.h"
    3633#import "WebDocumentInternal.h"
    3734#import "WebDocumentLoaderMac.h"
    38 #import "WebDownloadInternal.h"
    3935#import "WebFrameBridge.h"
    4036#import "WebFrameLoadDelegate.h"
    4137#import "WebFrameLoaderClient.h"
    4238#import "WebFrameViewInternal.h"
    43 #import "WebHTMLRepresentationPrivate.h"
    4439#import "WebHTMLViewInternal.h"
    45 #import "WebHTMLViewPrivate.h"
     40#import "WebHistoryItem.h"
    4641#import "WebHistoryItemPrivate.h"
    47 #import "WebHistoryPrivate.h"
    48 #import "WebKitErrorsPrivate.h"
    4942#import "WebKitLogging.h"
    50 #import "WebKitNSStringExtras.h"
    5143#import "WebKitStatisticsPrivate.h"
    52 #import "WebNSDictionaryExtras.h"
    53 #import "WebNSObjectExtras.h"
    5444#import "WebNSURLExtras.h"
    5545#import "WebNSURLRequestExtras.h"
    56 #import "WebNetscapePluginEmbeddedView.h"
    57 #import "WebNullPluginView.h"
    58 #import "WebPlugin.h"
    59 #import "WebPluginController.h"
    60 #import "WebPolicyDeciderMac.h"
     46#import "WebPolicyDelegatePrivate.h"
    6147#import "WebPreferencesPrivate.h"
    62 #import "WebResourceLoadDelegate.h"
    63 #import "WebResourcePrivate.h"
    6448#import "WebScriptDebugDelegatePrivate.h"
    65 #import "WebScriptDebugServerPrivate.h"
    66 #import "WebUIDelegate.h"
    6749#import "WebViewInternal.h"
    6850#import <WebCore/Document.h>
    69 #import <WebCore/DocumentMarker.h>
    7051#import <WebCore/FrameLoader.h>
    7152#import <WebCore/FrameMac.h>
     
    7758#import <WebCore/WebFormDataStream.h>
    7859#import <WebCore/WebFormState.h>
    79 #import <WebCore/WebLoader.h>
    80 #import <WebKit/DOM.h>
    81 #import <WebKitSystemInterface.h>
    82 #import <objc/objc-runtime.h>
    83 #import <wtf/HashMap.h>
     60#import <WebKit/DOMDocument.h>
     61#import <WebKit/DOMElement.h>
     62#import <WebKit/DOMHTMLElement.h>
     63#import <WebKit/DOMRange.h>
    8464
    8565// FIXME: We should have a way to get the following DOM interface from the WebCore internal headers, but we
     
    140120using namespace WebCore;
    141121
    142 typedef HashMap<RefPtr<WebResourceLoader>, RetainPtr<WebResource> > ResourceMap;
    143 
    144122NSString *WebPageCacheEntryDateKey = @"WebPageCacheEntryDateKey";
    145123NSString *WebPageCacheDataSourceKey = @"WebPageCacheDataSourceKey";
     
    148126@interface WebFrame (ForwardDecls)
    149127- (void)_loadHTMLString:(NSString *)string baseURL:(NSURL *)URL unreachableURL:(NSURL *)unreachableURL;
    150 - (void)_saveScrollPositionAndViewStateToItem:(WebHistoryItem *)item;
    151128- (WebHistoryItem *)_createItem:(BOOL)useOriginal;
    152129- (WebHistoryItem *)_createItemTreeWithTargetFrame:(WebFrame *)targetFrame clippedAtTarget:(BOOL)doClip;
     
    156133@interface NSView (WebFramePluginHosting)
    157134- (void)setWebFrame:(WebFrame *)webFrame;
    158 @end
    159 
    160 @interface WebFramePrivate : NSObject
    161 {
    162 @public
    163     WebFrameView *webFrameView;
    164 
    165     WebFrameBridge *bridge;
    166     WebHistoryItem *currentItem;        // BF item for our current content
    167     WebHistoryItem *provisionalItem;    // BF item for where we're trying to go
    168                                         // (only known when navigating to a pre-existing BF item)
    169     WebHistoryItem *previousItem;       // BF item for previous content, see _itemForSavingDocState
    170 
    171     WebScriptDebugger *scriptDebugger;
    172     id internalLoadDelegate;
    173    
    174     NSMutableSet *plugInViews;
    175     NSMutableSet *inspectors;
    176 
    177     ResourceMap* pendingArchivedResources;
    178 }
    179 
    180 - (void)setWebFrameView:(WebFrameView *)v;
    181 
    182 - (void)setProvisionalItem:(WebHistoryItem *)item;
    183 - (void)setPreviousItem:(WebHistoryItem *)item;
    184 - (void)setCurrentItem:(WebHistoryItem *)item;
    185 
    186135@end
    187136
     
    201150    [inspectors release];
    202151
    203     delete pendingArchivedResources;
    204 
    205152    [super dealloc];
    206 }
    207 
    208 - (void)finalize
    209 {
    210     delete pendingArchivedResources;
    211 
    212     [super finalize];
    213153}
    214154
     
    218158    [webFrameView release];
    219159    webFrameView = v;
    220 }
    221 
    222 - (void)setProvisionalItem:(WebHistoryItem *)item
    223 {
    224     [item retain];
    225     [provisionalItem release];
    226     provisionalItem = item;
    227 }
    228 
    229 - (void)setPreviousItem:(WebHistoryItem *)item
    230 {
    231     [item retain];
    232     [previousItem release];
    233     previousItem = item;
    234 }
    235 
    236 - (void)setCurrentItem:(WebHistoryItem *)item
    237 {
    238     [item retain];
    239     [currentItem release];
    240     currentItem = item;
    241160}
    242161
     
    365284
    366285    // Set the item for which we will save document state
    367     [_private setPreviousItem:_private->currentItem];
    368     [_private setCurrentItem:bfItem];
     286    [self _setPreviousItem:_private->currentItem];
     287    [self _setCurrentItem:bfItem];
    369288
    370289    return bfItem;
     
    429348{
    430349    return FrameLoader::timeOfLastCompletedLoad();
    431 }
    432 
    433 - (BOOL)_createPageCacheForItem:(WebHistoryItem *)item
    434 {
    435     NSMutableDictionary *pageCache;
    436 
    437     [item setHasPageCache: YES];
    438 
    439     if (![_private->bridge saveDocumentToPageCache]){
    440         [item setHasPageCache: NO];
    441         return NO;
    442     }
    443     else {
    444         pageCache = [item pageCache];
    445         [pageCache setObject:[NSDate date]  forKey: WebPageCacheEntryDateKey];
    446         [pageCache setObject:[self dataSource] forKey: WebPageCacheDataSourceKey];
    447         [pageCache setObject:[[self frameView] documentView] forKey: WebPageCacheDocumentViewKey];
    448     }
    449     return YES;
    450350}
    451351
     
    531431   
    532432        // must do this maintenance here, since we don't go through a real page reload
    533         [_private setCurrentItem:item];
    534         [self _restoreScrollPositionAndViewState];
     433        [self _setCurrentItem:item];
     434        core(self)->loader()->client()->restoreScrollPositionAndViewState();
    535435
    536436        // Fake the URL change by updating the data source's request.  This will no longer
     
    543443    } else {
    544444        // Remember this item so we can traverse any child items as child frames load
    545         [_private setProvisionalItem:item];
     445        [self _setProvisionalItem:item];
    546446
    547447        WebDataSource *newDataSource;
     
    652552        [self _saveScrollPositionAndViewStateToItem:_private->currentItem];
    653553       
    654         [_private setCurrentItem:item];
     554        [self _setCurrentItem:item];
    655555
    656556        // Restore form state (works from currentItem)
    657557        [_private->bridge restoreDocumentState];
    658558        // Restore the scroll position (taken in favor of going back to the anchor)
    659         [self _restoreScrollPositionAndViewState];
     559        core(self)->loader()->client()->restoreScrollPositionAndViewState();
    660560       
    661561        NSArray *childItems = [item children];
     
    724624            if (isBackForwardLoadType(loadType))
    725625                // For back/forward, remember this item so we can traverse any child items as child frames load
    726                 [childFrame->_private setProvisionalItem:childItem];
     626                [childFrame _setProvisionalItem:childItem];
    727627            else
    728628                // For reload, just reinstall the current item, since a new child frame was created but we won't be creating a new BF item
    729                 [childFrame->_private setCurrentItem:childItem];
     629                [childFrame _setCurrentItem:childItem];
    730630        }
    731631    }
     
    741641{
    742642    if (item) {
    743         NSView <WebDocumentView> *docView = [[self frameView] documentView];
     643        NSView <WebDocumentView> *docView = [_private->webFrameView documentView];
    744644        NSView *parent = [docView superview];
    745645        // we might already be detached when this is called from detachFromParent, in which
     
    995895- (BOOL)_hasSelection
    996896{
    997     id documentView = [[self frameView] documentView];   
     897    id documentView = [_private->webFrameView documentView];   
    998898
    999899    // optimization for common case to avoid creating potentially large selection string
     
    1010910- (void)_clearSelection
    1011911{
    1012     id documentView = [[self frameView] documentView];   
     912    id documentView = [_private->webFrameView documentView];   
    1013913    if ([documentView conformsToProtocol:@protocol(WebDocumentText)])
    1014914        [documentView deselectAll];
     
    11221022}
    11231023
    1124 - (id <WebFormDelegate>)_formDelegate
    1125 {
    1126     return [[self webView] _formDelegate];
     1024- (void)_setProvisionalItem:(WebHistoryItem *)item
     1025{
     1026    [item retain];
     1027    [_private->provisionalItem release];
     1028    _private->provisionalItem = item;
     1029}
     1030
     1031- (void)_setPreviousItem:(WebHistoryItem *)item
     1032{
     1033    [item retain];
     1034    [_private->previousItem release];
     1035    _private->previousItem = item;
     1036}
     1037
     1038- (void)_setCurrentItem:(WebHistoryItem *)item
     1039{
     1040    [item retain];
     1041    [_private->currentItem release];
     1042    _private->currentItem = item;
    11271043}
    11281044
     
    12921208                                                     baseURL:[mainResource URL]
    12931209                                              unreachableURL:nil];
    1294         RefPtr<DocumentLoader> documentLoader = [self _createDocumentLoaderWithRequest:request];
     1210        RefPtr<DocumentLoader> documentLoader = core(self)->loader()->client()->createDocumentLoader(request);
    12951211        [dataSource(documentLoader.get()) _addToUnarchiveState:archive];
    12961212        [self _frameLoader]->load(documentLoader.get());
     
    13361252
    13371253@end
    1338 
    1339 @implementation WebFrame (WebFrameLoaderClient)
    1340 
    1341 - (BOOL)_hasBackForwardList
    1342 {
    1343     return [[self webView] backForwardList] != nil;
    1344 }
    1345 
    1346 - (void)_resetBackForwardList
    1347 {
    1348     // Note this doesn't verify the current load type as a b/f operation because it is called from
    1349     // a subframe in the case of a delegate bailing out of the nav before it even gets to provisional state.
    1350     WebFrame *mainFrame = [[self webView] mainFrame];
    1351     WebHistoryItem *resetItem = mainFrame->_private->currentItem;
    1352     if (resetItem)
    1353         [[[self webView] backForwardList] goToItem:resetItem];
    1354 }
    1355 
    1356 - (void)_invalidateCurrentItemPageCache
    1357 {
    1358     // When we are pre-commit, the currentItem is where the pageCache data resides
    1359     NSDictionary *pageCache = [_private->currentItem pageCache];
    1360 
    1361     [_private->bridge invalidatePageCache:pageCache];
    1362    
    1363     // We're assuming that WebCore invalidates its pageCache state in didNotOpen:pageCache:
    1364     [_private->currentItem setHasPageCache:NO];
    1365 }
    1366 
    1367 - (BOOL)_provisionalItemIsTarget
    1368 {
    1369     return [_private->provisionalItem isTargetItem];
    1370 }
    1371 
    1372 - (BOOL)_loadProvisionalItemFromPageCache
    1373 {
    1374     WebHistoryItem *item = _private->provisionalItem;
    1375     if (![item hasPageCache])
    1376         return NO;
    1377     NSDictionary *pageCache = [item pageCache];
    1378     if (![pageCache objectForKey:WebCorePageCacheStateKey])
    1379         return NO;
    1380     LOG(PageCache, "Restoring page from back/forward cache, %@", [item URL]);
    1381     [[self provisionalDataSource] _loadFromPageCache:pageCache];
    1382     return YES;
    1383 }
    1384 
    1385 - (BOOL)_privateBrowsingEnabled
    1386 {
    1387     return [[[self webView] preferences] privateBrowsingEnabled];
    1388 }
    1389 
    1390 - (void)_makeDocumentView
    1391 {
    1392     NSView <WebDocumentView> *documentView = [_private->webFrameView _makeDocumentViewForDataSource:[self dataSource]];
    1393     if (!documentView)
    1394         return;
    1395 
    1396     // FIXME: We could save work and not do this for a top-level view that is not a WebHTMLView.
    1397     WebFrameView *v = _private->webFrameView;
    1398     [_private->bridge createFrameViewWithNSView:documentView marginWidth:[v _marginWidth] marginHeight:[v _marginHeight]];
    1399     [self _updateBackground];
    1400     [_private->bridge installInFrame:[v _scrollView]];
    1401 
    1402     // Call setDataSource on the document view after it has been placed in the view hierarchy.
    1403     // This what we for the top-level view, so should do this for views in subframes as well.
    1404     [documentView setDataSource:[self dataSource]];
    1405 }
    1406 
    1407 - (void)_forceLayout
    1408 {
    1409     NSView <WebDocumentView> *view = [[self frameView] documentView];
    1410     if ([view isKindOfClass:[WebHTMLView class]])
    1411         [(WebHTMLView *)view setNeedsToApplyStyles:YES];
    1412     [view setNeedsLayout:YES];
    1413     [view layout];
    1414 }
    1415 
    1416 - (void)_updateHistoryForCommit
    1417 {
    1418     FrameLoadType type = [self _frameLoader]->loadType();
    1419     if (isBackForwardLoadType(type) ||
    1420         (type == FrameLoadTypeReload && [[self provisionalDataSource] unreachableURL] != nil)) {
    1421         // Once committed, we want to use current item for saving DocState, and
    1422         // the provisional item for restoring state.
    1423         // Note previousItem must be set before we close the URL, which will
    1424         // happen when the data source is made non-provisional below
    1425         [_private setPreviousItem:_private->currentItem];
    1426         ASSERT(_private->provisionalItem);
    1427         [_private setCurrentItem:_private->provisionalItem];
    1428         [_private setProvisionalItem:nil];
    1429     }
    1430 }
    1431 
    1432 - (void)_updateHistoryForReload
    1433 {
    1434     WebHistoryItem *currItem = _private->currentItem;
    1435     LOG(PageCache, "Clearing back/forward cache, %@\n", [currItem URL]);
    1436     [currItem setHasPageCache:NO];
    1437     if ([self _frameLoader]->loadType() == FrameLoadTypeReload)
    1438         [self _saveScrollPositionAndViewStateToItem:currItem];
    1439     WebDataSource *dataSource = [self dataSource];
    1440     NSURLRequest *request = [dataSource request];
    1441     // Sometimes loading a page again leads to a different result because of cookies. Bugzilla 4072
    1442     if ([request _webDataRequestUnreachableURL] == nil)
    1443         [currItem setURL:[request URL]];
    1444     // Update the last visited time. Mostly interesting for URL autocompletion statistics.
    1445     NSURL *URL = [[[dataSource _documentLoader]->originalRequestCopy() URL] _webkit_canonicalize];
    1446     WebHistory *sharedHistory = [WebHistory optionalSharedHistory];
    1447     WebHistoryItem *oldItem = [sharedHistory itemForURL:URL];
    1448     if (oldItem)
    1449         [sharedHistory setLastVisitedTimeInterval:[NSDate timeIntervalSinceReferenceDate] forItem:oldItem];
    1450 }
    1451 
    1452 - (void)_updateHistoryForStandardLoad
    1453 {
    1454     WebDataSource *dataSource = [self dataSource];
    1455     if (![dataSource _documentLoader]->isClientRedirect()) {
    1456         NSURL *URL = [dataSource _URLForHistory];
    1457         if (URL && ![URL _web_isEmpty]) {
    1458             ASSERT([self webView]);
    1459             if (![[[self webView] preferences] privateBrowsingEnabled]) {
    1460                 WebHistoryItem *entry = [[WebHistory optionalSharedHistory] addItemForURL:URL];
    1461                 if ([dataSource pageTitle])
    1462                     [entry setTitle:[dataSource pageTitle]];                           
    1463             }
    1464             [self _addBackForwardItemClippedAtTarget:YES];
    1465         }
    1466     } else {
    1467         NSURLRequest *request = [dataSource request];
    1468        
    1469         // Update the URL in the BF list that we made before the redirect, unless
    1470         // this is alternate content for an unreachable URL (we want the BF list
    1471         // item to remember the unreachable URL in case it becomes reachable later).
    1472         if ([request _webDataRequestUnreachableURL] == nil) {
    1473             [_private->currentItem setURL:[request URL]];
    1474 
    1475             // clear out the form data so we don't repost it to the wrong place if we
    1476             // ever go back/forward to this item
    1477             [_private->currentItem _setFormInfoFromRequest:request];
    1478 
    1479             // We must also clear out form data so we don't try to restore it into the incoming page,
    1480             // see -_opened
    1481         }
    1482     }
    1483 }
    1484 
    1485 - (void)_updateHistoryForBackForwardNavigation
    1486 {
    1487     // Must grab the current scroll position before disturbing it
    1488     [self _saveScrollPositionAndViewStateToItem:_private->previousItem];
    1489 }
    1490 
    1491 - (void)_updateHistoryForInternalLoad
    1492 {
    1493     // Add an item to the item tree for this frame
    1494     ASSERT(![self _frameLoader]->documentLoader()->isClientRedirect());
    1495     WebFrame *parentFrame = [self parentFrame];
    1496     if (parentFrame) {
    1497         WebHistoryItem *parentItem = parentFrame->_private->currentItem;
    1498         // The only case where parentItem==nil should be when a parent frame loaded an
    1499         // empty URL, which doesn't set up a current item in that parent.
    1500         if (parentItem)
    1501             [parentItem addChildItem:[self _createItem:YES]];
    1502     } else {
    1503         // See 3556159. It's not clear if it's valid to be in WebFrameLoadTypeOnLoadEvent
    1504         // for a top-level frame, but that was a likely explanation for those crashes,
    1505         // so let's guard against it.
    1506         // ...and all WebFrameLoadTypeOnLoadEvent uses were folded to WebFrameLoadTypeInternal
    1507         LOG_ERROR("no parent frame in transitionToCommitted:, WebFrameLoadTypeInternal");
    1508     }
    1509 }
    1510 
    1511 - (LoadErrorResetToken *)_tokenForLoadErrorReset
    1512 {
    1513     return (LoadErrorResetToken*)[[self _currentBackForwardListItemToResetTo] retain];
    1514 }
    1515 
    1516 - (void)_resetAfterLoadError:(LoadErrorResetToken *)token
    1517 {
    1518     WebHistoryItem *item = (WebHistoryItem *)token;
    1519     if (item)
    1520         [[[self webView] backForwardList] goToItem:item];
    1521     [item release];
    1522 }
    1523 
    1524 - (void)_doNotResetAfterLoadError:(LoadErrorResetToken *)token
    1525 {
    1526     WebHistoryItem *item = (WebHistoryItem *)token;
    1527     [item release];
    1528 }
    1529 
    1530 - (void)_dispatchDidHandleOnloadEventsForFrame
    1531 {
    1532     WebView *webView = [self webView];
    1533     [[webView _frameLoadDelegateForwarder] webView:webView didHandleOnloadEventsForFrame:self];
    1534 }
    1535 
    1536 - (void)_dispatchDidReceiveServerRedirectForProvisionalLoadForFrame
    1537 {
    1538     WebView *webView = [self webView];
    1539     [[webView _frameLoadDelegateForwarder] webView:webView
    1540        didReceiveServerRedirectForProvisionalLoadForFrame:self];
    1541 }
    1542 
    1543 - (id)_dispatchIdentifierForInitialRequest:(NSURLRequest *)clientRequest fromDocumentLoader:(DocumentLoader*)loader
    1544 {
    1545     WebView *webView = [self webView];
    1546     id resourceLoadDelegate = [webView resourceLoadDelegate];
    1547    
    1548     if ([webView _resourceLoadDelegateImplementations].delegateImplementsIdentifierForRequest)
    1549         return [resourceLoadDelegate webView:webView identifierForInitialRequest:clientRequest fromDataSource:dataSource(loader)];
    1550 
    1551     return [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView identifierForInitialRequest:clientRequest fromDataSource:dataSource(loader)];
    1552 }
    1553 
    1554 - (NSURLRequest *)_dispatchResource:(id)identifier willSendRequest:(NSURLRequest *)clientRequest redirectResponse:(NSURLResponse *)redirectResponse fromDocumentLoader:(DocumentLoader*)loader
    1555 {
    1556     WebView *webView = [self webView];
    1557     id resourceLoadDelegate = [webView resourceLoadDelegate];
    1558 
    1559     if ([webView _resourceLoadDelegateImplementations].delegateImplementsWillSendRequest)
    1560         return [resourceLoadDelegate webView:webView resource:identifier willSendRequest:clientRequest redirectResponse:redirectResponse fromDataSource:dataSource(loader)];
    1561     else
    1562         return [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier willSendRequest:clientRequest redirectResponse:redirectResponse fromDataSource:dataSource(loader)];
    1563 }
    1564 
    1565 - (void)_dispatchDidReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier fromDocumentLoader:(DocumentLoader*)loader
    1566 {
    1567     WebView *webView = [self webView];
    1568     id resourceLoadDelegate = [webView resourceLoadDelegate];
    1569 
    1570     if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveAuthenticationChallenge)
    1571         [resourceLoadDelegate webView:webView resource:identifier didReceiveAuthenticationChallenge:currentWebChallenge fromDataSource:dataSource(loader)];
    1572     else
    1573         [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier didReceiveAuthenticationChallenge:currentWebChallenge fromDataSource:dataSource(loader)];
    1574 }
    1575 
    1576 - (void)_dispatchDidCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier fromDocumentLoader:(DocumentLoader*)loader
    1577 {
    1578     WebView *webView = [self webView];
    1579     id resourceLoadDelegate = [webView resourceLoadDelegate];
    1580 
    1581     if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidCancelAuthenticationChallenge)
    1582         [resourceLoadDelegate webView:webView resource:identifier didCancelAuthenticationChallenge:currentWebChallenge fromDataSource:dataSource(loader)];
    1583     else
    1584         [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier didCancelAuthenticationChallenge:currentWebChallenge fromDataSource:dataSource(loader)];
    1585 }
    1586 
    1587 - (void)_dispatchResource:(id)identifier didReceiveResponse:(NSURLResponse *)r fromDocumentLoader:(DocumentLoader*)loader
    1588 {
    1589     WebView *webView = [self webView];
    1590 
    1591     if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveResponse)
    1592         [[webView resourceLoadDelegate] webView:webView resource:identifier didReceiveResponse:r fromDataSource:dataSource(loader)];
    1593     else
    1594         [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier didReceiveResponse:r fromDataSource:dataSource(loader)];
    1595 }
    1596 
    1597 - (void)_dispatchResource:(id)identifier didReceiveContentLength:(int)lengthReceived fromDocumentLoader:(DocumentLoader*)loader
    1598 {
    1599     WebView *webView = [self webView];
    1600 
    1601     if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidReceiveContentLength)
    1602         [[webView resourceLoadDelegate] webView:webView resource:identifier didReceiveContentLength:(WebNSUInteger)lengthReceived fromDataSource:dataSource(loader)];
    1603     else
    1604         [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier didReceiveContentLength:(WebNSUInteger)lengthReceived fromDataSource:dataSource(loader)];
    1605 }
    1606 
    1607 - (void)_dispatchResource:(id)identifier didFinishLoadingFromDocumentLoader:(DocumentLoader*)loader
    1608 {
    1609     WebView *webView = [self webView];
    1610    
    1611     if ([webView _resourceLoadDelegateImplementations].delegateImplementsDidFinishLoadingFromDataSource)
    1612         [[webView resourceLoadDelegate] webView:webView resource:identifier didFinishLoadingFromDataSource:dataSource(loader)];
    1613     else
    1614         [[WebDefaultResourceLoadDelegate sharedResourceLoadDelegate] webView:webView resource:identifier didFinishLoadingFromDataSource:dataSource(loader)];
    1615 }
    1616 
    1617 
    1618 - (void)_dispatchResource:(id)identifier didFailLoadingWithError:error fromDocumentLoader:(DocumentLoader*)loader
    1619 {
    1620     WebView *webView = [self webView];
    1621     [[webView _resourceLoadDelegateForwarder] webView:webView resource:identifier didFailLoadingWithError:error fromDataSource:dataSource(loader)];
    1622 }
    1623 
    1624 - (void)_dispatchDidCancelClientRedirectForFrame
    1625 {
    1626     WebView *webView = [self webView];
    1627     [[webView _frameLoadDelegateForwarder] webView:webView didCancelClientRedirectForFrame:self];
    1628 }
    1629 
    1630 - (void)_dispatchWillPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date
    1631 {
    1632     WebView *webView = [self webView];   
    1633     [[webView _frameLoadDelegateForwarder] webView:webView
    1634                          willPerformClientRedirectToURL:URL
    1635                                                   delay:seconds
    1636                                                fireDate:date
    1637                                                forFrame:self];
    1638 }
    1639 
    1640 - (void)_dispatchDidChangeLocationWithinPageForFrame
    1641 {
    1642     WebView *webView = [self webView];   
    1643     [[webView _frameLoadDelegateForwarder] webView:webView didChangeLocationWithinPageForFrame:self];
    1644 }
    1645 
    1646 - (void)_dispatchWillCloseFrame
    1647 {
    1648     WebView *webView = [self webView];   
    1649     [[webView _frameLoadDelegateForwarder] webView:webView willCloseFrame:self];
    1650 }
    1651 
    1652 - (void)_dispatchDidReceiveIcon:(NSImage *)icon
    1653 {
    1654     WebView *webView = [self webView];   
    1655     ASSERT([self _isMainFrame]);
    1656     [webView _willChangeValueForKey:_WebMainFrameIconKey];
    1657     [[webView _frameLoadDelegateForwarder] webView:webView didReceiveIcon:icon forFrame:self];
    1658     [webView _didChangeValueForKey:_WebMainFrameIconKey];
    1659 }
    1660 
    1661 - (void)_dispatchDidStartProvisionalLoadForFrame
    1662 {
    1663     WebView *webView = [self webView];   
    1664     [webView _didStartProvisionalLoadForFrame:self];
    1665     [[webView _frameLoadDelegateForwarder] webView:webView didStartProvisionalLoadForFrame:self];   
    1666 }
    1667 
    1668 - (void)_dispatchDidReceiveTitle:(NSString *)title
    1669 {
    1670     WebView *webView = [self webView];   
    1671     [[webView _frameLoadDelegateForwarder] webView:webView didReceiveTitle:title forFrame:self];
    1672 }
    1673 
    1674 - (void)_dispatchDidCommitLoadForFrame
    1675 {
    1676     // Tell the client we've committed this URL.
    1677     ASSERT([[self frameView] documentView] != nil);
    1678 
    1679     WebView *webView = [self webView];   
    1680     [webView _didCommitLoadForFrame:self];
    1681     [[webView _frameLoadDelegateForwarder] webView:webView didCommitLoadForFrame:self];
    1682 }
    1683 
    1684 - (void)_dispatchDidFailProvisionalLoadWithError:(NSError *)error
    1685 {
    1686     WebView *webView = [self webView];   
    1687     [webView _didFailProvisionalLoadWithError:error forFrame:self];
    1688     [[webView _frameLoadDelegateForwarder] webView:webView didFailProvisionalLoadWithError:error forFrame:self];
    1689     [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:error];
    1690 }
    1691 
    1692 - (void)_dispatchDidFailLoadWithError:(NSError *)error
    1693 {
    1694     WebView *webView = [self webView];   
    1695     [webView _didFailLoadWithError:error forFrame:self];
    1696     [[webView _frameLoadDelegateForwarder] webView:webView didFailLoadWithError:error forFrame:self];
    1697     [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:error];
    1698 }
    1699 
    1700 - (void)_dispatchDidFinishLoadForFrame
    1701 {
    1702     WebView *webView = [self webView];   
    1703     [webView _didFinishLoadForFrame:self];
    1704     [[webView _frameLoadDelegateForwarder] webView:webView didFinishLoadForFrame:self];
    1705     [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:nil];
    1706 }
    1707 
    1708 - (void)_dispatchDidFirstLayoutInFrame
    1709 {
    1710     WebView *webView = [self webView];
    1711     [[webView _frameLoadDelegateForwarder] webView:webView didFirstLayoutInFrame:self];
    1712 }
    1713 
    1714 - (Frame*)_dispatchCreateWebViewWithRequest:(NSURLRequest *)request
    1715 {
    1716     WebView *currentWebView = [self webView];
    1717     id wd = [currentWebView UIDelegate];
    1718     if ([wd respondsToSelector:@selector(webView:createWebViewWithRequest:)])
    1719         return core([[wd webView:currentWebView createWebViewWithRequest:request] mainFrame]);
    1720     return core([[[WebDefaultUIDelegate sharedUIDelegate] webView:currentWebView createWebViewWithRequest:request] mainFrame]);
    1721 }
    1722 
    1723 - (void)_dispatchShow
    1724 {
    1725     WebView *webView = [self webView];
    1726     [[webView _UIDelegateForwarder] webViewShow:webView];
    1727 }
    1728 
    1729 - (WebPolicyDecider *)_createPolicyDeciderWithTarget:(id)target action:(SEL)action
    1730 {
    1731     return [[WebPolicyDeciderMac alloc] initWithTarget:target action:action];
    1732 }
    1733 
    1734 static inline WebPolicyDecisionListener *decisionListener(WebPolicyDecider *decider)
    1735 {
    1736     return [(WebPolicyDeciderMac *)decider decisionListener];
    1737 }
    1738 
    1739 - (void)_dispatchDecidePolicyForMIMEType:(NSString *)MIMEType request:(NSURLRequest *)request decider:(WebPolicyDecider *)decider
    1740 {
    1741     WebView *webView = [self webView];
    1742 
    1743     [[webView _policyDelegateForwarder] webView:webView decidePolicyForMIMEType:MIMEType request:request frame:self decisionListener:decisionListener(decider)];
    1744 }
    1745 
    1746 - (void)_dispatchDecidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frameName decider:(WebPolicyDecider *)decider
    1747 {
    1748     WebView *webView = [self webView];
    1749     [[webView _policyDelegateForwarder] webView:webView
    1750             decidePolicyForNewWindowAction:action
    1751                                    request:request
    1752                               newFrameName:frameName
    1753                           decisionListener:decisionListener(decider)];
    1754 }
    1755 
    1756 - (void)_dispatchDecidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request decider:(WebPolicyDecider *)decider
    1757 {
    1758     WebView *webView = [self webView];
    1759     [[webView _policyDelegateForwarder] webView:webView
    1760                 decidePolicyForNavigationAction:action
    1761                                         request:request
    1762                                           frame:self
    1763                                decisionListener:decisionListener(decider)];
    1764 }
    1765 
    1766 - (void)_dispatchUnableToImplementPolicyWithError:(NSError *)error
    1767 {
    1768     WebView *webView = [self webView];
    1769     [[webView _policyDelegateForwarder] webView:webView unableToImplementPolicyWithError:error frame:self];   
    1770 }
    1771 
    1772 - (void)_dispatchSourceFrame:(Frame*)sourceFrame willSubmitForm:(Element*)form withValues:(NSDictionary *)values submissionDecider:(WebPolicyDecider *)decider
    1773 {
    1774     [[self _formDelegate] frame:self sourceFrame:kit(sourceFrame) willSubmitForm:kit(form) withValues:values submissionListener:decisionListener(decider)];
    1775 }
    1776 
    1777 - (void)_detachedFromParent1
    1778 {
    1779     [self _saveScrollPositionAndViewStateToItem:_private->currentItem];
    1780 }
    1781 
    1782 - (void)_detachedFromParent2
    1783 {
    1784     [_private->inspectors makeObjectsPerformSelector:@selector(_webFrameDetached:) withObject:self];
    1785     [_private->webFrameView _setWebFrame:nil]; // needed for now to be compatible w/ old behavior
    1786 }
    1787 
    1788 - (void)_detachedFromParent3
    1789 {
    1790     [_private setWebFrameView:nil];
    1791 }
    1792 
    1793 - (void)_detachedFromParent4
    1794 {
    1795     _private->bridge = nil;
    1796 }
    1797 
    1798 - (void)_updateHistoryAfterClientRedirect
    1799 {
    1800     // Clear out form data so we don't try to restore it into the incoming page.  Must happen after
    1801     // khtml has closed the URL and saved away the form state.
    1802     WebHistoryItem *item = _private->currentItem;
    1803     [item setDocumentState:nil];
    1804     [item setScrollPoint:NSZeroPoint];
    1805 }
    1806 
    1807 - (void)_loadedFromPageCache
    1808 {
    1809     // Release the resources kept in the page cache.
    1810     // They will be reset when we leave this page.
    1811     // The WebCore side of the page cache will have already been invalidated by
    1812     // the bridge to prevent premature release.
    1813     [_private->currentItem setHasPageCache:NO];
    1814 }
    1815 
    1816 - (void)_downloadWithLoadingConnection:(NSURLConnection *)connection request:(NSURLRequest *)request response:(NSURLResponse *)response proxy:(id)proxy
    1817 {
    1818     [WebDownload _downloadWithLoadingConnection:connection
    1819                                         request:request
    1820                                        response:response
    1821                                        delegate:[[self webView] downloadDelegate]
    1822                                           proxy:proxy];
    1823 }
    1824 
    1825 - (void)_setDocumentViewFromPageCache:(NSDictionary *)pageCache
    1826 {
    1827     NSView <WebDocumentView> *cachedView = [pageCache objectForKey:WebPageCacheDocumentViewKey];
    1828     ASSERT(cachedView != nil);
    1829     [[self frameView] _setDocumentView:cachedView];
    1830 }
    1831 
    1832 - (void)_setCopiesOnScroll
    1833 {
    1834     [[[[self frameView] _scrollView] contentView] setCopiesOnScroll:YES];
    1835 }
    1836 
    1837 - (void)_dispatchDidLoadMainResourceForDocumentLoader:(DocumentLoader*)loader
    1838 {
    1839     if ([WebScriptDebugServer listenerCount])
    1840         [[WebScriptDebugServer sharedScriptDebugServer] webView:[self webView]
    1841             didLoadMainResourceForDataSource:dataSource(loader)];
    1842 }
    1843 
    1844 - (void)_forceLayoutForNonHTML
    1845 {
    1846     WebFrameView *thisView = [self frameView];
    1847     NSView <WebDocumentView> *thisDocumentView = [thisView documentView];
    1848     ASSERT(thisDocumentView != nil);
    1849    
    1850     // Tell the just loaded document to layout.  This may be necessary
    1851     // for non-html content that needs a layout message.
    1852     if (!([[self dataSource] _isDocumentHTML])) {
    1853         [thisDocumentView setNeedsLayout:YES];
    1854         [thisDocumentView layout];
    1855         [thisDocumentView setNeedsDisplay:YES];
    1856     }
    1857 }
    1858 
    1859 - (void)_clearLoadingFromPageCacheForDocumentLoader:(DocumentLoader*)loader
    1860 {
    1861     [dataSource(loader) _setLoadingFromPageCache:NO];
    1862 }
    1863 
    1864 - (BOOL)_isDocumentLoaderLoadingFromPageCache:(DocumentLoader*)loader
    1865 {
    1866     return [dataSource(loader) _loadingFromPageCache];
    1867 }
    1868 
    1869 - (void)_makeRepresentationForDocumentLoader:(DocumentLoader*)loader
    1870 {
    1871     [dataSource(loader) _makeRepresentation];
    1872 }
    1873 
    1874 - (void)_revertToProvisionalStateForDocumentLoader:(DocumentLoader*)loader
    1875 {
    1876     [dataSource(loader) _revertToProvisionalState];
    1877 }
    1878 
    1879 - (void)_setMainDocumentError:(NSError *)error forDocumentLoader:(DocumentLoader*)loader
    1880 {
    1881     [dataSource(loader) _setMainDocumentError:error];
    1882 }
    1883 
    1884 - (void)_clearUnarchivingStateForLoader:(DocumentLoader*)loader
    1885 {
    1886     [dataSource(loader) _clearUnarchivingState];
    1887 }
    1888 
    1889 - (void)_progressStarted
    1890 {
    1891     [[self webView] _progressStarted:self];
    1892 }
    1893 
    1894 - (void)_progressCompleted
    1895 {
    1896     [[self webView] _progressCompleted:self];
    1897 }
    1898 
    1899 - (void)_incrementProgressForIdentifier:(id)identifier response:(NSURLResponse *)response
    1900 {
    1901     [[self webView] _incrementProgressForIdentifier:identifier response:response];
    1902 }
    1903 
    1904 - (void)_incrementProgressForIdentifier:(id)identifier data:(NSData *)data
    1905 {
    1906     [[self webView] _incrementProgressForIdentifier:identifier data:data];
    1907 }
    1908 
    1909 - (void)_completeProgressForIdentifier:(id)identifier
    1910 {
    1911     [[self webView] _completeProgressForIdentifier:identifier];
    1912 }
    1913 
    1914 - (void)_setMainFrameDocumentReady:(BOOL)ready
    1915 {
    1916     [[self webView] setMainFrameDocumentReady:ready];
    1917 }
    1918 
    1919 - (void)_willChangeTitleForDocument:(DocumentLoader*)loader
    1920 {
    1921     // FIXME: Should do this only in main frame case, right?
    1922     [[self webView] _willChangeValueForKey:_WebMainFrameTitleKey];
    1923 }
    1924 
    1925 - (void)_didChangeTitleForDocument:(DocumentLoader*)loader
    1926 {
    1927     // FIXME: Should do this only in main frame case, right?
    1928     [[self webView] _didChangeValueForKey:_WebMainFrameTitleKey];
    1929 }
    1930 
    1931 - (void)_startDownloadWithRequest:(NSURLRequest *)request
    1932 {
    1933     // FIXME: Should download full request.
    1934     [[self webView] _downloadURL:[request URL]];
    1935 }
    1936 
    1937 - (void)_finishedLoadingDocument:(DocumentLoader*)loader
    1938 {
    1939     [dataSource(loader) _finishedLoading];
    1940 }
    1941 
    1942 - (void)_committedLoadWithDocumentLoader:(DocumentLoader*)loader data:(NSData *)data
    1943 {
    1944     [dataSource(loader) _receivedData:data];
    1945 }
    1946 
    1947 - (void)_documentLoader:(DocumentLoader*)loader setMainDocumentError:(NSError *)error
    1948 {
    1949     [dataSource(loader) _setMainDocumentError:error];
    1950 }
    1951 
    1952 - (void)_finalSetupForReplaceWithDocumentLoader:(DocumentLoader*)loader
    1953 {
    1954     [dataSource(loader) _clearUnarchivingState];
    1955 }
    1956 
    1957 - (NSError *)_cancelledErrorWithRequest:(NSURLRequest *)request
    1958 {
    1959     return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled URL:[request URL]];
    1960 }
    1961 
    1962 - (NSError *)_cannotShowURLErrorWithRequest:(NSURLRequest *)request
    1963 {
    1964     return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotShowURL URL:[request URL]];
    1965 }
    1966 
    1967 - (NSError *)_interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request
    1968 {
    1969     return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:[request URL]];
    1970 }
    1971 
    1972 - (NSError *)_cannotShowMIMETypeErrorWithResponse:(NSURLResponse *)response
    1973 {
    1974     return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:WebKitErrorCannotShowMIMEType URL:[response URL]];   
    1975 }
    1976 
    1977 - (NSError *)_fileDoesNotExistErrorWithResponse:(NSURLResponse *)response
    1978 {
    1979     return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist URL:[response URL]];   
    1980 }
    1981 
    1982 - (BOOL)_shouldFallBackForError:(NSError *)error
    1983 {
    1984     // FIXME: Needs to check domain.
    1985     // FIXME: WebKitErrorPlugInWillHandleLoad is a workaround for the cancel we do to prevent
    1986     // loading plugin content twice.  See <rdar://problem/4258008>
    1987     return [error code] != NSURLErrorCancelled && [error code] != WebKitErrorPlugInWillHandleLoad;
    1988 }
    1989 
    1990 - (BOOL)_hasWebView
    1991 {
    1992     return [self webView] != nil;
    1993 }
    1994 
    1995 - (BOOL)_hasFrameView
    1996 {
    1997     return [self frameView] != nil;
    1998 }
    1999 
    2000 - (NSURL *)_mainFrameURL
    2001 {
    2002     return [[[[self webView] mainFrame] dataSource] _URL];
    2003 }
    2004 
    2005 // The following 2 methods are copied from [NSHTTPURLProtocol _cachedResponsePassesValidityChecks] and modified for our needs.
    2006 // FIXME: It would be nice to eventually to share this code somehow.
    2007 - (BOOL)_canUseResourceForRequest:(NSURLRequest *)request
    2008 {
    2009     NSURLRequestCachePolicy policy = [request cachePolicy];
    2010     if (policy == NSURLRequestReturnCacheDataElseLoad)
    2011         return YES;
    2012     if (policy == NSURLRequestReturnCacheDataDontLoad)
    2013         return YES;
    2014     if (policy == NSURLRequestReloadIgnoringCacheData)
    2015         return NO;
    2016     if ([request valueForHTTPHeaderField:@"must-revalidate"] != nil)
    2017         return NO;
    2018     if ([request valueForHTTPHeaderField:@"proxy-revalidate"] != nil)
    2019         return NO;
    2020     if ([request valueForHTTPHeaderField:@"If-Modified-Since"] != nil)
    2021         return NO;
    2022     if ([request valueForHTTPHeaderField:@"Cache-Control"] != nil)
    2023         return NO;
    2024     if ([@"POST" _webkit_isCaseInsensitiveEqualToString:[request HTTPMethod]])
    2025         return NO;
    2026     return YES;
    2027 }
    2028 
    2029 - (BOOL)_canUseResourceWithResponse:(NSURLResponse *)response
    2030 {
    2031     if (WKGetNSURLResponseMustRevalidate(response))
    2032         return NO;
    2033     if (WKGetNSURLResponseCalculatedExpiration(response) - CFAbsoluteTimeGetCurrent() < 1)
    2034         return NO;
    2035     return YES;
    2036 }
    2037 
    2038 - (void)_deliverArchivedResourcesAfterDelay
    2039 {
    2040     if (!_private->pendingArchivedResources)
    2041         return;
    2042     if (_private->pendingArchivedResources->isEmpty())
    2043         return;
    2044     if ([self _frameLoader]->defersCallbacks())
    2045         return;
    2046    
    2047     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
    2048     [self performSelector:@selector(_deliverArchivedResources) withObject:nil afterDelay:0];
    2049 }
    2050 
    2051 - (BOOL)_willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebResourceLoader*)loader
    2052 {
    2053     if (![[r URL] isEqual:originalURL])
    2054         return NO;
    2055     if (![self _canUseResourceForRequest:r])
    2056         return NO;
    2057     WebResource *resource = [dataSource([self _frameLoader]->activeDocumentLoader()) _archivedSubresourceForURL:originalURL];
    2058     if (!resource)
    2059         return NO;
    2060     if (![self _canUseResourceWithResponse:[resource _response]])
    2061         return NO;
    2062     if (!_private->pendingArchivedResources)
    2063         _private->pendingArchivedResources = new ResourceMap;
    2064     _private->pendingArchivedResources->set(loader, resource);
    2065     // Deliver the resource after a delay because callers don't expect to receive callbacks while calling this method.
    2066     [self _deliverArchivedResourcesAfterDelay];
    2067     return YES;
    2068 }
    2069 
    2070 - (BOOL)_archiveLoadPendingForLoader:(WebResourceLoader*)loader
    2071 {
    2072     if (!_private->pendingArchivedResources)
    2073         return false;
    2074     return _private->pendingArchivedResources->contains(loader);
    2075 }
    2076 
    2077 - (void)_cancelPendingArchiveLoadForLoader:(WebResourceLoader*)loader
    2078 {
    2079     if (!_private->pendingArchivedResources)
    2080         return;
    2081     if (_private->pendingArchivedResources->isEmpty())
    2082         return;
    2083     _private->pendingArchivedResources->remove(loader);
    2084     if (_private->pendingArchivedResources->isEmpty())
    2085         [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
    2086 }
    2087 
    2088 - (void)_clearArchivedResources
    2089 {
    2090     if (_private->pendingArchivedResources)
    2091         _private->pendingArchivedResources->clear();
    2092     [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_deliverArchivedResources) object:nil];
    2093 }
    2094 
    2095 - (void)_deliverArchivedResources
    2096 {
    2097     if (!_private->pendingArchivedResources)
    2098         return;
    2099     if (_private->pendingArchivedResources->isEmpty())
    2100         return;
    2101     if ([self _frameLoader]->defersCallbacks())
    2102         return;
    2103 
    2104     const ResourceMap copy = *_private->pendingArchivedResources;
    2105     _private->pendingArchivedResources->clear();
    2106 
    2107     ResourceMap::const_iterator end = copy.end();
    2108     for (ResourceMap::const_iterator it = copy.begin(); it != end; ++it) {
    2109         RefPtr<WebResourceLoader> loader = it->first;
    2110         WebResource *resource = it->second.get();
    2111         NSData *data = [[resource data] retain];
    2112         loader->didReceiveResponse([resource _response]);
    2113         loader->didReceiveData(data, [data length], true);
    2114         [data release];
    2115         loader->didFinishLoading();
    2116     }
    2117 }
    2118 
    2119 - (void)_setDefersCallbacks:(BOOL)defers
    2120 {
    2121     if (!defers)
    2122         [self _deliverArchivedResourcesAfterDelay];
    2123 }
    2124 
    2125 - (BOOL)_canHandleRequest:(NSURLRequest *)request
    2126 {
    2127     return [WebView _canHandleRequest:request];
    2128 }
    2129 
    2130 - (BOOL)_canShowMIMEType:(NSString *)MIMEType
    2131 {
    2132     return [WebView canShowMIMEType:MIMEType];
    2133 }
    2134 
    2135 - (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme
    2136 {
    2137     return [WebView _representationExistsForURLScheme:URLScheme];
    2138 }
    2139 
    2140 - (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme
    2141 {
    2142     return [WebView _generatedMIMETypeForURLScheme:URLScheme];
    2143 }
    2144 
    2145 - (NSDictionary *)_elementForEvent:(NSEvent *)event
    2146 {
    2147     switch ([event type]) {
    2148         case NSLeftMouseDown:
    2149         case NSRightMouseDown:
    2150         case NSOtherMouseDown:
    2151         case NSLeftMouseUp:
    2152         case NSRightMouseUp:
    2153         case NSOtherMouseUp:
    2154             break;
    2155         default:
    2156             return nil;
    2157     }
    2158 
    2159     NSView *topViewInEventWindow = [[event window] contentView];
    2160     NSView *viewContainingPoint = [topViewInEventWindow hitTest:
    2161         [topViewInEventWindow convertPoint:[event locationInWindow] fromView:nil]];
    2162     while (viewContainingPoint) {
    2163         if ([viewContainingPoint isKindOfClass:[WebView class]])
    2164             return [(WebView *)viewContainingPoint elementAtPoint:
    2165                 [viewContainingPoint convertPoint:[event locationInWindow] fromView:nil]];
    2166         viewContainingPoint = [viewContainingPoint superview];
    2167     }
    2168     return nil;
    2169 }
    2170 
    2171 - (void)_frameLoadCompleted
    2172 {
    2173     // Note: Can be called multiple times.
    2174     // Even if already complete, we might have set a previous item on a frame that
    2175     // didn't do any data loading on the past transaction. Make sure to clear these out.
    2176     NSScrollView *sv = [[self frameView] _scrollView];
    2177     if ([[self webView] drawsBackground])
    2178         [sv setDrawsBackground:YES];
    2179     [_private setPreviousItem:nil];
    2180 }
    2181 
    2182 /*
    2183  There is a race condition between the layout and load completion that affects restoring the scroll position.
    2184  We try to restore the scroll position at both the first layout and upon load completion.
    2185  
    2186  1) If first layout happens before the load completes, we want to restore the scroll position then so that the
    2187  first time we draw the page is already scrolled to the right place, instead of starting at the top and later
    2188  jumping down.  It is possible that the old scroll position is past the part of the doc laid out so far, in
    2189  which case the restore silent fails and we will fix it in when we try to restore on doc completion.
    2190  2) If the layout happens after the load completes, the attempt to restore at load completion time silently
    2191  fails.  We then successfully restore it when the layout happens.
    2192  */
    2193 
    2194 - (void)_restoreScrollPositionAndViewState
    2195 {
    2196     ASSERT(_private->currentItem);
    2197     NSView <WebDocumentView> *docView = [[self frameView] documentView];
    2198     NSPoint point = [_private->currentItem scrollPoint];
    2199     if ([docView conformsToProtocol:@protocol(_WebDocumentViewState)]) {       
    2200         id state = [_private->currentItem viewState];
    2201         if (state) {
    2202             [(id <_WebDocumentViewState>)docView setViewState:state];
    2203         }
    2204        
    2205         [(id <_WebDocumentViewState>)docView setScrollPoint:point];
    2206     } else {
    2207         [docView scrollPoint:point];
    2208     }
    2209 }
    2210 
    2211 - (void)_setTitle:(NSString *)title forURL:(NSURL *)URL
    2212 {
    2213     [[[WebHistory optionalSharedHistory] itemForURL:URL] setTitle:title];
    2214     [_private->currentItem setTitle:title];
    2215 }
    2216 
    2217 - (PassRefPtr<DocumentLoader>)_createDocumentLoaderWithRequest:(NSURLRequest *)request
    2218 {
    2219     RefPtr<WebDocumentLoaderMac> loader = new WebDocumentLoaderMac(request);
    2220 
    2221     WebDataSource *dataSource = [[WebDataSource alloc] _initWithDocumentLoader:loader.get()];
    2222     loader->setDataSource(dataSource);
    2223     [dataSource release];
    2224 
    2225     return loader.release();
    2226 }
    2227 
    2228 - (void)_prepareForDataSourceReplacement
    2229 {
    2230     if (![self dataSource]) {
    2231         ASSERT(!core(self)->tree()->childCount());
    2232         return;
    2233     }
    2234    
    2235     // Make sure that any work that is triggered by resigning first reponder can get done.
    2236     // The main example where this came up is the textDidEndEditing that is sent to the
    2237     // FormsDelegate (3223413).  We need to do this before _detachChildren, since that will
    2238     // remove the views as a side-effect of freeing the bridge, at which point we can't
    2239     // post the FormDelegate messages.
    2240     //
    2241     // Note that this can also take FirstResponder away from a child of our frameView that
    2242     // is not in a child frame's view.  This is OK because we are in the process
    2243     // of loading new content, which will blow away all editors in this top frame, and if
    2244     // a non-editor is firstReponder it will not be affected by endEditingFor:.
    2245     // Potentially one day someone could write a DocView whose editors were not all
    2246     // replaced by loading new content, but that does not apply currently.
    2247     NSView *frameView = [self frameView];
    2248     NSWindow *window = [frameView window];
    2249     NSResponder *firstResp = [window firstResponder];
    2250     if ([firstResp isKindOfClass:[NSView class]] && [(NSView *)firstResp isDescendantOf:frameView])
    2251         [window endEditingFor:firstResp];
    2252    
    2253     [self _frameLoader]->detachChildren();
    2254 }
    2255 
    2256 - (void)_didFinishLoad
    2257 {
    2258     [_private->internalLoadDelegate webFrame:self didFinishLoadWithError:nil];   
    2259 }
    2260 
    2261 - (void)_addHistoryItemForFragmentScroll
    2262 {
    2263     [self _addBackForwardItemClippedAtTarget:NO];
    2264 }
    2265 
    2266 - (BOOL)_shouldTreatURLAsSameAsCurrent:(NSURL *)URL
    2267 {
    2268     WebHistoryItem *item = _private->currentItem;
    2269     NSString* URLString = [URL _web_originalDataAsString];
    2270     return [URLString isEqual:[item URLString]] || [URLString isEqual:[item originalURLString]];
    2271 }   
    2272 
    2273 - (void)_provisionalLoadStarted
    2274 {
    2275     FrameLoadType loadType = [self _frameLoader]->loadType();
    2276    
    2277     // FIXME: This is OK as long as no one resizes the window,
    2278     // but in the case where someone does, it means garbage outside
    2279     // the occupied part of the scroll view.
    2280     [[[self frameView] _scrollView] setDrawsBackground:NO];
    2281    
    2282     // Cache the page, if possible.
    2283     // Don't write to the cache if in the middle of a redirect, since we will want to
    2284     // store the final page we end up on.
    2285     // No point writing to the cache on a reload or loadSame, since we will just write
    2286     // over it again when we leave that page.
    2287     WebHistoryItem *item = _private->currentItem;
    2288     if ([self _canCachePage]
    2289         && item
    2290         && ![self _frameLoader]->isQuickRedirectComing()
    2291         && loadType != FrameLoadTypeReload
    2292         && loadType != FrameLoadTypeReloadAllowingStaleData
    2293         && loadType != FrameLoadTypeSame
    2294         && ![[self dataSource] isLoading]
    2295         && ![self _frameLoader]->documentLoader()->isStopping()) {
    2296         if ([[[self dataSource] representation] isKindOfClass:[WebHTMLRepresentation class]]) {
    2297             if (![item pageCache]){
    2298                 // Add the items to this page's cache.
    2299                 if ([self _createPageCacheForItem:item]) {
    2300                     LOG(PageCache, "Saving page to back/forward cache, %@\n", [[self dataSource] _URL]);
    2301                    
    2302                     // See if any page caches need to be purged after the addition of this
    2303                     // new page cache.
    2304                     [self _purgePageCache];
    2305                 }
    2306                 else
    2307                     LOG(PageCache, "NOT saving page to back/forward cache, unable to create items, %@\n", [[self dataSource] _URL]);
    2308             }
    2309         } else
    2310             // Put the document into a null state, so it can be restored correctly.
    2311             core(self)->clear();
    2312     } else
    2313         LOG(PageCache, "NOT saving page to back/forward cache, %@\n", [[self dataSource] _URL]);
    2314 }
    2315 
    2316 @end
  • trunk/WebKit/WebView/WebFrameInternal.h

    r17299 r17365  
    3030
    3131#import "WebFramePrivate.h"
    32 #import "WebPolicyDelegatePrivate.h"
    3332
    3433#ifdef __cplusplus
    3534#import <WebCore/FrameLoaderTypes.h>
    36 #import <wtf/Forward.h>
    3735#endif
    3836
     37@class DOMElement;
    3938@class DOMRange;
    4039@class WebInspector;
    4140@class WebFrameView;
    4241@class WebFrameBridge;
    43 @class WebPolicyDecider;
     42@class WebHistoryItem;
     43@class WebScriptDebugger;
    4444
    4545#ifdef __cplusplus
     
    5454    class HTMLElement;
    5555    class Range;
    56     class WebResourceLoader;
    57     struct LoadErrorResetToken;
    5856}
    5957
     
    7270WebCore::Range* core(DOMRange *);
    7371DOMRange *kit(WebCore::Range*);
     72
     73@interface WebFramePrivate : NSObject
     74{
     75@public
     76    WebFrameView *webFrameView;
     77
     78    WebFrameBridge *bridge;
     79    WebHistoryItem *currentItem;        // BF item for our current content
     80    WebHistoryItem *provisionalItem;    // BF item for where we're trying to go
     81                                        // (only known when navigating to a pre-existing BF item)
     82    WebHistoryItem *previousItem;       // BF item for previous content, see _itemForSavingDocState
     83
     84    WebScriptDebugger *scriptDebugger;
     85    id internalLoadDelegate;
     86   
     87    NSMutableSet *plugInViews;
     88    NSMutableSet *inspectors;
     89}
     90@end
    7491
    7592#endif
     
    148165- (void)_recursive_resumeNullEventsForAllNetscapePlugins;
    149166
    150 @end
     167- (void)_setProvisionalItem:(WebHistoryItem *)item;
     168- (void)_setPreviousItem:(WebHistoryItem *)item;
     169- (void)_setCurrentItem:(WebHistoryItem *)item;
    151170
    152 #ifdef __cplusplus
     171- (void)_saveScrollPositionAndViewStateToItem:(WebHistoryItem *)item;
    153172
    154 @interface WebFrame (WebFrameLoaderClient)
     173- (void)_addBackForwardItemClippedAtTarget:(BOOL)doClip;
    155174
    156 - (BOOL)_hasBackForwardList;
    157 - (void)_resetBackForwardList;
    158 - (void)_invalidateCurrentItemPageCache;
    159 - (BOOL)_provisionalItemIsTarget;
    160 - (BOOL)_loadProvisionalItemFromPageCache;
    161 - (BOOL)_privateBrowsingEnabled;
    162 - (void)_makeDocumentView;
    163 - (void)_forceLayout;
    164 - (void)_updateHistoryForCommit;
    165 - (void)_updateHistoryForReload;
    166 - (void)_updateHistoryForStandardLoad;
    167 - (void)_updateHistoryForBackForwardNavigation;
    168 - (void)_updateHistoryForInternalLoad;
    169 - (WebCore::LoadErrorResetToken*)_tokenForLoadErrorReset;
    170 - (void)_resetAfterLoadError:(WebCore::LoadErrorResetToken*)token;
    171 - (void)_doNotResetAfterLoadError:(WebCore::LoadErrorResetToken*)token;
    172 - (void)_dispatchDidHandleOnloadEventsForFrame;
    173 - (void)_dispatchDidReceiveServerRedirectForProvisionalLoadForFrame;
    174 - (id)_dispatchIdentifierForInitialRequest:(NSURLRequest *)clientRequest fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    175 - (NSURLRequest *)_dispatchResource:(id)identifier willSendRequest:(NSURLRequest *)clientRequest redirectResponse:(NSURLResponse *)redirectResponse fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    176 - (void)_dispatchDidReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    177 - (void)_dispatchDidCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)currentWebChallenge forResource:(id)identifier fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    178 - (void)_dispatchResource:(id)identifier didReceiveResponse:(NSURLResponse *)r fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    179 - (void)_dispatchResource:(id)identifier didReceiveContentLength:(int)lengthReceived fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    180 - (void)_dispatchResource:(id)identifier didFinishLoadingFromDocumentLoader:(WebCore::DocumentLoader*)loader;
    181 - (void)_dispatchResource:(id)identifier didFailLoadingWithError:error fromDocumentLoader:(WebCore::DocumentLoader*)loader;
    182 - (void)_dispatchDidCancelClientRedirectForFrame;
    183 - (void)_dispatchWillPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date;
    184 - (void)_dispatchDidChangeLocationWithinPageForFrame;
    185 - (void)_dispatchWillCloseFrame;
    186 - (void)_dispatchDidReceiveIcon:(NSImage *)icon;
    187 - (void)_dispatchDidStartProvisionalLoadForFrame;
    188 - (void)_dispatchDidReceiveTitle:(NSString *)title;
    189 - (void)_dispatchDidCommitLoadForFrame;
    190 - (void)_dispatchDidFailProvisionalLoadWithError:(NSError *)error;
    191 - (void)_dispatchDidFailLoadWithError:(NSError *)error;
    192 - (void)_dispatchDidFinishLoadForFrame;
    193 - (void)_dispatchDidFirstLayoutInFrame;
    194 - (WebCore::Frame*)_dispatchCreateWebViewWithRequest:(NSURLRequest *)request;
    195 - (void)_dispatchShow;
    196 - (WebPolicyDecider *)_createPolicyDeciderWithTarget:(id)target action:(SEL)action;
    197 - (void)_dispatchDecidePolicyForMIMEType:(NSString *)MIMEType request:(NSURLRequest *)request decider:(WebPolicyDecider *)decider;
    198 - (void)_dispatchDecidePolicyForNewWindowAction:(NSDictionary *)action request:(NSURLRequest *)request newFrameName:(NSString *)frameName decider:(WebPolicyDecider *)decider;
    199 - (void)_dispatchDecidePolicyForNavigationAction:(NSDictionary *)action request:(NSURLRequest *)request decider:(WebPolicyDecider *)decider;
    200 - (void)_dispatchUnableToImplementPolicyWithError:(NSError *)error;
    201 - (void)_dispatchSourceFrame:(WebCore::Frame*)sourceFrame willSubmitForm:(WebCore::Element*)form withValues:(NSDictionary *)values submissionDecider:(WebPolicyDecider *)decider;
    202 - (void)_detachedFromParent1;
    203 - (void)_detachedFromParent2;
    204 - (void)_detachedFromParent3;
    205 - (void)_detachedFromParent4;
    206 - (void)_updateHistoryAfterClientRedirect;
    207 - (void)_loadedFromPageCache;
    208 - (void)_downloadWithLoadingConnection:(NSURLConnection *)connection request:(NSURLRequest *)request response:(NSURLResponse *)response proxy:(id)proxy;
    209 - (void)_setDocumentViewFromPageCache:(NSDictionary *)pageCache;
    210 - (void)_setCopiesOnScroll;
    211 - (void)_dispatchDidLoadMainResourceForDocumentLoader:(WebCore::DocumentLoader*)loader;
    212 - (void)_forceLayoutForNonHTML;
    213 - (void)_clearLoadingFromPageCacheForDocumentLoader:(WebCore::DocumentLoader*)loader;
    214 - (BOOL)_isDocumentLoaderLoadingFromPageCache:(WebCore::DocumentLoader*)loader;
    215 - (void)_makeRepresentationForDocumentLoader:(WebCore::DocumentLoader*)loader;
    216 - (void)_revertToProvisionalStateForDocumentLoader:(WebCore::DocumentLoader*)loader;
    217 - (void)_setMainDocumentError:(NSError *)error forDocumentLoader:(WebCore::DocumentLoader*)loader;
    218 - (void)_clearUnarchivingStateForLoader:(WebCore::DocumentLoader*)loader;
    219 - (void)_progressStarted;
    220 - (void)_progressCompleted;
    221 - (void)_incrementProgressForIdentifier:(id)identifier response:(NSURLResponse *)response;
    222 - (void)_incrementProgressForIdentifier:(id)identifier data:(NSData *)data;
    223 - (void)_completeProgressForIdentifier:(id)identifier;
    224 - (void)_setMainFrameDocumentReady:(BOOL)ready;
    225 - (void)_willChangeTitleForDocument:(WebCore::DocumentLoader*)loader;
    226 - (void)_didChangeTitleForDocument:(WebCore::DocumentLoader*)loader;
    227 - (void)_startDownloadWithRequest:(NSURLRequest *)request;
    228 - (void)_finishedLoadingDocument:(WebCore::DocumentLoader*)loader;
    229 - (void)_committedLoadWithDocumentLoader:(WebCore::DocumentLoader*)loader data:(NSData *)data;
    230 - (void)_documentLoader:(WebCore::DocumentLoader*)loader setMainDocumentError:(NSError *)error;
    231 - (void)_finalSetupForReplaceWithDocumentLoader:(WebCore::DocumentLoader*)loader;
    232 - (NSError *)_cancelledErrorWithRequest:(NSURLRequest *)request;
    233 - (NSError *)_cannotShowURLErrorWithRequest:(NSURLRequest *)request;
    234 - (NSError *)_interruptForPolicyChangeErrorWithRequest:(NSURLRequest *)request;
    235 - (NSError *)_cannotShowMIMETypeErrorWithResponse:(NSURLResponse *)response;
    236 - (NSError *)_fileDoesNotExistErrorWithResponse:(NSURLResponse *)response;
    237 - (BOOL)_shouldFallBackForError:(NSError *)error;
    238 - (BOOL)_hasWebView;
    239 - (BOOL)_hasFrameView;
    240 - (NSURL *)_mainFrameURL;
    241 - (BOOL)_canUseResourceForRequest:(NSURLRequest *)request;
    242 - (BOOL)_canUseResourceWithResponse:(NSURLResponse *)response;
    243 - (void)_deliverArchivedResourcesAfterDelay;
    244 - (BOOL)_willUseArchiveForRequest:(NSURLRequest *)r originalURL:(NSURL *)originalURL loader:(WebCore::WebResourceLoader*)loader;
    245 - (BOOL)_archiveLoadPendingForLoader:(WebCore::WebResourceLoader*)loader;
    246 - (void)_cancelPendingArchiveLoadForLoader:(WebCore::WebResourceLoader*)loader;
    247 - (void)_clearArchivedResources;
    248 - (void)_deliverArchivedResources;
    249 - (void)_setDefersCallbacks:(BOOL)defers;
    250 - (BOOL)_canHandleRequest:(NSURLRequest *)request;
    251 - (BOOL)_canShowMIMEType:(NSString *)MIMEType;
    252 - (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme;
    253 - (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme;
    254 - (NSDictionary *)_elementForEvent:(NSEvent *)event;
    255 - (void)_frameLoadCompleted;
    256 - (void)_restoreScrollPositionAndViewState;
    257 - (void)_setTitle:(NSString *)title forURL:(NSURL *)URL;
    258 - (PassRefPtr<WebCore::DocumentLoader>)_createDocumentLoaderWithRequest:(NSURLRequest *)request;
    259 - (void)_prepareForDataSourceReplacement;
    260 - (void)_didFinishLoad;
    261 - (void)_addHistoryItemForFragmentScroll;
    262 - (BOOL)_shouldTreatURLAsSameAsCurrent:(NSURL *)URL;
    263 - (void)_provisionalLoadStarted;
     175- (WebHistoryItem *)_createItem:(BOOL)useOriginal;
    264176
    265177@end
    266 
    267 #endif
    268178
    269179@interface NSObject (WebInternalFrameLoadDelegate)
  • trunk/WebKit/WebView/WebHTMLView.m

    r17303 r17365  
    944944{
    945945    WebHTMLView *view = (WebHTMLView *)[[[[_private->dataSource _webView] mainFrame] frameView] documentView];
     946    ASSERT(view);
    946947    ASSERT([view isKindOfClass:[WebHTMLView class]]);
    947948    return view;
  • trunk/WebKit/WebView/WebHTMLViewPrivate.h

    r16975 r17365  
    3030
    3131@class DOMDocumentFragment;
     32@class DOMNode;
    3233@class DOMRange;
    3334@class WebArchive;
Note: See TracChangeset for help on using the changeset viewer.