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

📄 webframeloaderclient.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 5 页
字号:
    //    1) The load gets far enough along: WebFrameLoader::frameLoadCompleted.    //    2) The window is resized: -[WebFrameView setFrameSize:].    // or 3) The view is moved out of the window: -[WebFrameView viewDidMoveToWindow].    // Please keep the comments in these four functions in agreement with each other.    [[m_webFrame->_private->webFrameView _scrollView] setDrawsBackground:NO];}void WebFrameLoaderClient::didFinishLoad(){    [m_webFrame->_private->internalLoadDelegate webFrame:m_webFrame.get() didFinishLoadWithError:nil];    }void WebFrameLoaderClient::prepareForDataSourceReplacement(){    if (![m_webFrame.get() _dataSource]) {        ASSERT(!core(m_webFrame.get())->tree()->childCount());        return;    }        // Make sure that any work that is triggered by resigning first reponder can get done.    // The main example where this came up is the textDidEndEditing that is sent to the    // FormsDelegate (3223413). We need to do this before _detachChildren, since that will    // remove the views as a side-effect of freeing the frame, at which point we can't    // post the FormDelegate messages.    //    // Note that this can also take FirstResponder away from a child of our frameView that    // is not in a child frame's view.  This is OK because we are in the process    // of loading new content, which will blow away all editors in this top frame, and if    // a non-editor is firstReponder it will not be affected by endEditingFor:.    // Potentially one day someone could write a DocView whose editors were not all    // replaced by loading new content, but that does not apply currently.    NSView *frameView = m_webFrame->_private->webFrameView;    NSWindow *window = [frameView window];    NSResponder *firstResp = [window firstResponder];    if ([firstResp isKindOfClass:[NSView class]] && [(NSView *)firstResp isDescendantOf:frameView])        [window endEditingFor:firstResp];}PassRefPtr<DocumentLoader> WebFrameLoaderClient::createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData){    RefPtr<WebDocumentLoaderMac> loader = WebDocumentLoaderMac::create(request, substituteData);    WebDataSource *dataSource = [[WebDataSource alloc] _initWithDocumentLoader:loader.get()];    loader->setDataSource(dataSource, getWebView(m_webFrame.get()));    [dataSource release];    return loader.release();}// FIXME: <rdar://problem/4880065> - Push Global History into WebCore// Once that task is complete, this will go awayvoid WebFrameLoaderClient::setTitle(const String& title, const KURL& URL){    NSURL* nsURL = URL;    nsURL = [nsURL _webkit_canonicalize];    if(!nsURL)        return;    NSString *titleNSString = title;    [[[WebHistory optionalSharedHistory] itemForURL:nsURL] setTitle:titleNSString];}void WebFrameLoaderClient::savePlatformDataToCachedFrame(CachedFrame* cachedFrame){    WebCachedFramePlatformData* webPlatformData = new WebCachedFramePlatformData([m_webFrame->_private->webFrameView documentView]);    cachedFrame->setCachedFramePlatformData(webPlatformData);}void WebFrameLoaderClient::transitionToCommittedFromCachedFrame(CachedFrame* cachedFrame){    WebCachedFramePlatformData* platformData = reinterpret_cast<WebCachedFramePlatformData*>(cachedFrame->cachedFramePlatformData());    NSView <WebDocumentView> *cachedView = platformData->webDocumentView();    ASSERT(cachedView != nil);    ASSERT(cachedFrame->documentLoader());    [cachedView setDataSource:dataSource(cachedFrame->documentLoader())];        // clean up webkit plugin instances before WebHTMLView gets freed.    WebView *webView = getWebView(m_webFrame.get());    [webView removePluginInstanceViewsFor:(m_webFrame.get())];        [m_webFrame->_private->webFrameView _setDocumentView:cachedView];}void WebFrameLoaderClient::transitionToCommittedForNewPage(){    WebFrameView *v = m_webFrame->_private->webFrameView;    WebDataSource *ds = [m_webFrame.get() _dataSource];    bool willProduceHTMLView = [[WebFrameView class] _viewClassForMIMEType:[ds _responseMIMEType]] == [WebHTMLView class];    bool canSkipCreation = core(m_webFrame.get())->loader()->committingFirstRealLoad() && willProduceHTMLView;    if (canSkipCreation) {        [[v documentView] setDataSource:ds];        return;    }    // Don't suppress scrollbars before the view creation if we're making the view for a non-HTML view.    if (!willProduceHTMLView)        [[v _scrollView] setScrollBarsSuppressed:NO repaintOnUnsuppress:NO];        // clean up webkit plugin instances before WebHTMLView gets freed.    WebView *webView = getWebView(m_webFrame.get());    [webView removePluginInstanceViewsFor:(m_webFrame.get())];        BOOL useDocumentViews = [webView _usesDocumentViews];    NSView <WebDocumentView> *documentView = nil;    if (useDocumentViews) {        documentView = [v _makeDocumentViewForDataSource:ds];        if (!documentView)            return;    }    // FIXME: Could we skip some of this work for a top-level view that is not a WebHTMLView?    // If we own the view, delete the old one - otherwise the render m_frame will take care of deleting the view.    Frame* coreFrame = core(m_webFrame.get());    Page* page = coreFrame->page();    bool isMainFrame = coreFrame == page->mainFrame();    if (isMainFrame && coreFrame->view())        coreFrame->view()->setParentVisible(false);    coreFrame->setView(0);    FrameView* coreView;    if (useDocumentViews)        coreView = new FrameView(coreFrame);    else        coreView = new FrameView(coreFrame, IntSize([webView bounds].size));    coreFrame->setView(coreView);    coreView->deref(); // FIXME: Eliminate this crazy refcounting!    [m_webFrame.get() _updateBackgroundAndUpdatesWhileOffscreen];    [v _install];    if (isMainFrame)        coreView->setParentVisible(true);    // Call setDataSource on the document view after it has been placed in the view hierarchy.    // This what we for the top-level view, so should do this for views in subframes as well.    [documentView setDataSource:ds];        if (HTMLFrameOwnerElement* owner = coreFrame->ownerElement())        coreFrame->view()->setCanHaveScrollbars(owner->scrollingMode() != ScrollbarAlwaysOff);    }RetainPtr<WebFramePolicyListener> WebFrameLoaderClient::setUpPolicyListener(FramePolicyFunction function){    // FIXME: <rdar://5634381> We need to support multiple active policy listeners.    [m_policyListener.get() invalidate];    WebFramePolicyListener *listener = [[WebFramePolicyListener alloc] initWithWebCoreFrame:core(m_webFrame.get())];    m_policyListener = listener;    [listener release];    m_policyFunction = function;    return listener;}void WebFrameLoaderClient::receivedPolicyDecison(PolicyAction action){    ASSERT(m_policyListener);    ASSERT(m_policyFunction);    FramePolicyFunction function = m_policyFunction;    m_policyListener = nil;    m_policyFunction = 0;    (core(m_webFrame.get())->loader()->*function)(action);}String WebFrameLoaderClient::userAgent(const KURL& url){    WebView *webView = getWebView(m_webFrame.get());    ASSERT(webView);    // We should never get here with nil for the WebView unless there is a bug somewhere else.    // But if we do, it's better to return the empty string than just crashing on the spot.    // Most other call sites are tolerant of nil because of Objective-C behavior, but this one    // is not because the return value of _userAgentForURL is a const KURL&.    if (!webView)        return String("");    return [webView _userAgentForURL:url];}static const MouseEvent* findMouseEvent(const Event* event){    for (const Event* e = event; e; e = e->underlyingEvent())        if (e->isMouseEvent())            return static_cast<const MouseEvent*>(e);    return 0;}NSDictionary *WebFrameLoaderClient::actionDictionary(const NavigationAction& action, PassRefPtr<FormState> formState) const{    unsigned modifierFlags = 0;    const Event* event = action.event();    if (const UIEventWithKeyState* keyStateEvent = findEventWithKeyState(const_cast<Event*>(event))) {        if (keyStateEvent->ctrlKey())            modifierFlags |= NSControlKeyMask;        if (keyStateEvent->altKey())            modifierFlags |= NSAlternateKeyMask;        if (keyStateEvent->shiftKey())            modifierFlags |= NSShiftKeyMask;        if (keyStateEvent->metaKey())            modifierFlags |= NSCommandKeyMask;    }    NSURL *originalURL = action.url();    NSMutableDictionary *result = [NSMutableDictionary dictionaryWithObjectsAndKeys:        [NSNumber numberWithInt:action.type()], WebActionNavigationTypeKey,        [NSNumber numberWithInt:modifierFlags], WebActionModifierFlagsKey,        originalURL, WebActionOriginalURLKey,        nil];    if (const MouseEvent* mouseEvent = findMouseEvent(event)) {        IntPoint point(mouseEvent->pageX(), mouseEvent->pageY());        WebElementDictionary *element = [[WebElementDictionary alloc]            initWithHitTestResult:core(m_webFrame.get())->eventHandler()->hitTestResultAtPoint(point, false)];        [result setObject:element forKey:WebActionElementKey];        [element release];        [result setObject:[NSNumber numberWithInt:mouseEvent->button()] forKey:WebActionButtonKey];    }    if (formState) {        ASSERT(formState->form());        [result setObject:kit(formState->form()) forKey:WebActionFormKey];    }    return result;}bool WebFrameLoaderClient::canCachePage() const{    // We can only cache HTML pages right now    return [[[m_webFrame.get() _dataSource] representation] isKindOfClass:[WebHTMLRepresentation class]];}PassRefPtr<Frame> WebFrameLoaderClient::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,    const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight){    BEGIN_BLOCK_OBJC_EXCEPTIONS;        ASSERT(m_webFrame);        WebFrameView *childView = [getWebView(m_webFrame.get()) _usesDocumentViews] ? [[WebFrameView alloc] init] : nil;        RefPtr<Frame> result = [WebFrame _createSubframeWithOwnerElement:ownerElement frameName:name frameView:childView];    [childView release];    WebFrame *newFrame = kit(result.get());    if ([newFrame _dataSource])        [[newFrame _dataSource] _documentLoader]->setOverrideEncoding([[m_webFrame.get() _dataSource] _documentLoader]->overrideEncoding());      // The creation of the frame may have run arbitrary JavaScript that removed it from the page already.    if (!result->page())        return 0;     core(m_webFrame.get())->loader()->loadURLIntoChildFrame(url, referrer, result.get());    // The frame's onload handler may have removed it from the document.    if (!result->tree()->parent())        return 0;    return result.release();    END_BLOCK_OBJC_EXCEPTIONS;    return 0;}ObjectContentType WebFrameLoaderClient::objectContentType(const KURL& url, const String& mimeType){    BEGIN_BLOCK_OBJC_EXCEPTIONS;    // This is a quirk that ensures Tiger Mail's WebKit plug-in will load during layout    // and not attach time. (5520541)    static BOOL isTigerMail = WKAppVersionCheckLessThan(@"com.apple.mail", -1, 3.0);    if (isTigerMail && mimeType == "application/x-apple-msg-attachment")        return ObjectContentNetscapePlugin;    String type = mimeType;    if (type.isEmpty()) {        // Try to guess the MIME type based off the extension.        NSURL *URL = url;        NSString *extension = [[URL path] pathExtension];        if ([extension length] > 0) {            type = WKGetMIMETypeForExtension(extension);            if (type.isEmpty()) {                // If no MIME type is specified, use a plug-in if we have one that can handle the extension.                if (WebBasePluginPackage *package = [getWebView(m_webFrame.get()) _pluginForExtension:extension]) {                    if ([package isKindOfClass:[WebPluginPackage class]])                         return ObjectContentOtherPlugin;#if ENABLE(NETSCAPE_PLUGIN_API)                    else {                        ASSERT([package isKindOfClass:[WebNetscapePluginPackage class]]);                        return ObjectContentNetscapePlugin;                    }#endif                }            }        }    }    if (type.isEmpty())        return ObjectContentFrame; // Go ahead and hope that we can display the content.    if (MIMETypeRegistry::isSupportedImageMIMEType(type))        return ObjectContentImage;

⌨️ 快捷键说明

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