⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webframeloaderclient.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
Frame* WebFrameLoaderClient::dispatchCreatePage(){    WebView *currentWebView = getWebView(m_webFrame.get());    NSDictionary *features = [[NSDictionary alloc] init];    WebView *newWebView = [[currentWebView _UIDelegateForwarder] webView:currentWebView                                                 createWebViewWithRequest:nil                                                          windowFeatures:features];    [features release];    return core([newWebView mainFrame]);}void WebFrameLoaderClient::dispatchShow(){    WebView *webView = getWebView(m_webFrame.get());    [[webView _UIDelegateForwarder] webViewShow:webView];}void WebFrameLoaderClient::dispatchDecidePolicyForMIMEType(FramePolicyFunction function,    const String& MIMEType, const ResourceRequest& request){    WebView *webView = getWebView(m_webFrame.get());    [[webView _policyDelegateForwarder] webView:webView                        decidePolicyForMIMEType:MIMEType                                        request:request.nsURLRequest()                                          frame:m_webFrame.get()                               decisionListener:setUpPolicyListener(function).get()];}void WebFrameLoaderClient::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function,    const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState, const String& frameName){    WebView *webView = getWebView(m_webFrame.get());    [[webView _policyDelegateForwarder] webView:webView            decidePolicyForNewWindowAction:actionDictionary(action, formState)                                   request:request.nsURLRequest()                              newFrameName:frameName                          decisionListener:setUpPolicyListener(function).get()];}void WebFrameLoaderClient::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function,    const NavigationAction& action, const ResourceRequest& request, PassRefPtr<FormState> formState){    WebView *webView = getWebView(m_webFrame.get());    [[webView _policyDelegateForwarder] webView:webView                decidePolicyForNavigationAction:actionDictionary(action, formState)                                        request:request.nsURLRequest()                                          frame:m_webFrame.get()                               decisionListener:setUpPolicyListener(function).get()];}void WebFrameLoaderClient::cancelPolicyCheck(){    [m_policyListener.get() invalidate];    m_policyListener = nil;    m_policyFunction = 0;}void WebFrameLoaderClient::dispatchUnableToImplementPolicy(const ResourceError& error){    WebView *webView = getWebView(m_webFrame.get());    [[webView _policyDelegateForwarder] webView:webView unableToImplementPolicyWithError:error frame:m_webFrame.get()];    }void WebFrameLoaderClient::dispatchWillSubmitForm(FramePolicyFunction function, PassRefPtr<FormState> formState){    id <WebFormDelegate> formDelegate = [getWebView(m_webFrame.get()) _formDelegate];    if (!formDelegate) {        (core(m_webFrame.get())->loader()->*function)(PolicyUse);        return;    }    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:formState->values().size()];    HashMap<String, String>::const_iterator end = formState->values().end();    for (HashMap<String, String>::const_iterator it = formState->values().begin(); it != end; ++it)        [dictionary setObject:it->second forKey:it->first];    CallFormDelegate(getWebView(m_webFrame.get()), @selector(frame:sourceFrame:willSubmitForm:withValues:submissionListener:), m_webFrame.get(), kit(formState->sourceFrame()), kit(formState->form()), dictionary, setUpPolicyListener(function).get());    [dictionary release];}void WebFrameLoaderClient::dispatchDidLoadMainResource(DocumentLoader* loader){}void WebFrameLoaderClient::revertToProvisionalState(DocumentLoader* loader){    [dataSource(loader) _revertToProvisionalState];}void WebFrameLoaderClient::setMainDocumentError(DocumentLoader* loader, const ResourceError& error){    [dataSource(loader) _setMainDocumentError:error];}void WebFrameLoaderClient::willChangeEstimatedProgress(){    [getWebView(m_webFrame.get()) _willChangeValueForKey:_WebEstimatedProgressKey];}void WebFrameLoaderClient::didChangeEstimatedProgress(){    [getWebView(m_webFrame.get()) _didChangeValueForKey:_WebEstimatedProgressKey];}void WebFrameLoaderClient::postProgressStartedNotification(){    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressStartedNotification object:getWebView(m_webFrame.get())];}void WebFrameLoaderClient::postProgressEstimateChangedNotification(){    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressEstimateChangedNotification object:getWebView(m_webFrame.get())];}void WebFrameLoaderClient::postProgressFinishedNotification(){    [[NSNotificationCenter defaultCenter] postNotificationName:WebViewProgressFinishedNotification object:getWebView(m_webFrame.get())];}void WebFrameLoaderClient::setMainFrameDocumentReady(bool ready){    [getWebView(m_webFrame.get()) setMainFrameDocumentReady:ready];}void WebFrameLoaderClient::startDownload(const ResourceRequest& request){    // FIXME: Should download full request.    WebDownload *download = [getWebView(m_webFrame.get()) _downloadURL:request.url()];        setOriginalURLForDownload(download, request);}void WebFrameLoaderClient::willChangeTitle(DocumentLoader* loader){    // FIXME: Should do this only in main frame case, right?    [getWebView(m_webFrame.get()) _willChangeValueForKey:_WebMainFrameTitleKey];}void WebFrameLoaderClient::didChangeTitle(DocumentLoader* loader){    // FIXME: Should do this only in main frame case, right?    [getWebView(m_webFrame.get()) _didChangeValueForKey:_WebMainFrameTitleKey];}void WebFrameLoaderClient::committedLoad(DocumentLoader* loader, const char* data, int length){    NSData *nsData = [[NSData alloc] initWithBytesNoCopy:(void*)data length:length freeWhenDone:NO];    [dataSource(loader) _receivedData:nsData];    [nsData release];}void WebFrameLoaderClient::finishedLoading(DocumentLoader* loader){    [dataSource(loader) _finishedLoading];}void WebFrameLoaderClient::updateGlobalHistory(){    DocumentLoader* loader = core(m_webFrame.get())->loader()->documentLoader();    [[WebHistory optionalSharedHistory] _visitedURL:loader->urlForHistory()                                           withTitle:loader->title()                                             method:loader->originalRequestCopy().httpMethod()                                         wasFailure:loader->urlForHistoryReflectsFailure()];    updateGlobalHistoryRedirectLinks();}void WebFrameLoaderClient::updateGlobalHistoryRedirectLinks(){    DocumentLoader* loader = core(m_webFrame.get())->loader()->documentLoader();    if (!loader->clientRedirectSourceForHistory().isNull()) {        if (WebHistoryItem *item = [[WebHistory optionalSharedHistory] _itemForURLString:loader->clientRedirectSourceForHistory()])            core(item)->addRedirectURL(loader->clientRedirectDestinationForHistory());    }    if (!loader->serverRedirectSourceForHistory().isNull()) {        if (WebHistoryItem *item = [[WebHistory optionalSharedHistory] _itemForURLString:loader->serverRedirectSourceForHistory()])            core(item)->addRedirectURL(loader->serverRedirectDestinationForHistory());    }}bool WebFrameLoaderClient::shouldGoToHistoryItem(HistoryItem* item) const{    WebView* view = getWebView(m_webFrame.get());    WebHistoryItem *webItem = kit(item);        return [[view _policyDelegateForwarder] webView:view shouldGoToHistoryItem:webItem];}ResourceError WebFrameLoaderClient::cancelledError(const ResourceRequest& request){    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled URL:request.url()];}    ResourceError WebFrameLoaderClient::blockedError(const ResourceRequest& request){    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotUseRestrictedPort URL:request.url()];}ResourceError WebFrameLoaderClient::cannotShowURLError(const ResourceRequest& request){    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorCannotShowURL URL:request.url()];}ResourceError WebFrameLoaderClient::interruptForPolicyChangeError(const ResourceRequest& request){    return [NSError _webKitErrorWithDomain:WebKitErrorDomain code:WebKitErrorFrameLoadInterruptedByPolicyChange URL:request.url()];}ResourceError WebFrameLoaderClient::cannotShowMIMETypeError(const ResourceResponse& response){    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:WebKitErrorCannotShowMIMEType URL:response.url()];}ResourceError WebFrameLoaderClient::fileDoesNotExistError(const ResourceResponse& response){    return [NSError _webKitErrorWithDomain:NSURLErrorDomain code:NSURLErrorFileDoesNotExist URL:response.url()];    }ResourceError WebFrameLoaderClient::pluginWillHandleLoadError(const ResourceResponse& response){    NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorPlugInWillHandleLoad                                                    contentURL:response.url()                                                 pluginPageURL:nil                                                    pluginName:nil                                                      MIMEType:response.mimeType()];    return [error autorelease];}bool WebFrameLoaderClient::shouldFallBack(const ResourceError& error){    // FIXME: Needs to check domain.    // FIXME: WebKitErrorPlugInWillHandleLoad is a workaround for the cancel we do to prevent    // loading plugin content twice.  See <rdar://problem/4258008>    return error.errorCode() != NSURLErrorCancelled && error.errorCode() != WebKitErrorPlugInWillHandleLoad;}bool WebFrameLoaderClient::canHandleRequest(const ResourceRequest& request) const{    Frame* frame = core(m_webFrame.get());    Page* page = frame->page();    BOOL forMainFrame = page && page->mainFrame() == frame;    return [WebView _canHandleRequest:request.nsURLRequest() forMainFrame:forMainFrame];}bool WebFrameLoaderClient::canShowMIMEType(const String& MIMEType) const{    return [WebView canShowMIMEType:MIMEType];}bool WebFrameLoaderClient::representationExistsForURLScheme(const String& URLScheme) const{    return [WebView _representationExistsForURLScheme:URLScheme];}String WebFrameLoaderClient::generatedMIMETypeForURLScheme(const String& URLScheme) const{    return [WebView _generatedMIMETypeForURLScheme:URLScheme];}void WebFrameLoaderClient::frameLoadCompleted(){    // Note: Can be called multiple times.    // See WebFrameLoaderClient::provisionalLoadStarted.    if ([getWebView(m_webFrame.get()) drawsBackground])        [[m_webFrame->_private->webFrameView _scrollView] setDrawsBackground:YES];}void WebFrameLoaderClient::saveViewStateToItem(HistoryItem* item){    if (!item)        return;        NSView <WebDocumentView> *docView = [m_webFrame->_private->webFrameView documentView];    // we might already be detached when this is called from detachFromParent, in which    // case we don't want to override real data earlier gathered with (0,0)    if ([docView superview] && [docView conformsToProtocol:@protocol(_WebDocumentViewState)])        item->setViewState([(id <_WebDocumentViewState>)docView viewState]);}void WebFrameLoaderClient::restoreViewState(){    HistoryItem* currentItem = core(m_webFrame.get())->loader()->currentHistoryItem();    ASSERT(currentItem);    // FIXME: As the ASSERT attests, it seems we should always have a currentItem here.    // One counterexample is <rdar://problem/4917290>    // For now, to cover this issue in release builds, there is no technical harm to returning    // early and from a user standpoint - as in the above radar - the previous page load failed     // so there *is* no scroll state to restore!    if (!currentItem)        return;        NSView <WebDocumentView> *docView = [m_webFrame->_private->webFrameView documentView];    if ([docView conformsToProtocol:@protocol(_WebDocumentViewState)]) {                id state = currentItem->viewState();        if (state) {            [(id <_WebDocumentViewState>)docView setViewState:state];        }    }}void WebFrameLoaderClient::provisionalLoadStarted(){        // Tell the scroll view not to draw a background so we can leave the contents of    // the old page showing during the beginning of the loading process.    // This will stay set to NO until:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -