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

📄 frameloader.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    switch (loadType()) {        case FrameLoadTypeReload:        case FrameLoadTypeReloadFromOrigin:        case FrameLoadTypeSame:        case FrameLoadTypeReplace:            break;        case FrameLoadTypeBack:        case FrameLoadTypeForward:        case FrameLoadTypeIndexedBackForward:        case FrameLoadTypeRedirectWithLockedBackForwardList:        case FrameLoadTypeStandard:            itemToRestore = m_currentHistoryItem.get();     }        if (!itemToRestore)        return;    LOG(Loading, "WebCoreLoading %s: restoring form state from %p", m_frame->tree()->name().string().utf8().data(), itemToRestore);    doc->setStateForNewFormElements(itemToRestore->documentState());}void FrameLoader::gotoAnchor(){    // If our URL has no ref, then we have no place we need to jump to.    // OTOH If CSS target was set previously, we want to set it to 0, recalc    // and possibly repaint because :target pseudo class may have been    // set (see bug 11321).    if (!m_URL.hasRef() && !m_frame->document()->cssTarget())        return;    String ref = m_URL.ref();    if (gotoAnchor(ref))        return;    // Try again after decoding the ref, based on the document's encoding.    if (m_decoder)        gotoAnchor(decodeURLEscapeSequences(ref, m_decoder->encoding()));}void FrameLoader::finishedParsing(){    if (m_creatingInitialEmptyDocument)        return;    // This can be called from the Frame's destructor, in which case we shouldn't protect ourselves    // because doing so will cause us to re-enter the destructor when protector goes out of scope.    // Null-checking the FrameView indicates whether or not we're in the destructor.    RefPtr<Frame> protector = m_frame->view() ? m_frame : 0;    m_client->dispatchDidFinishDocumentLoad();    checkCompleted();    if (!m_frame->view())        return; // We are being destroyed by something checkCompleted called.    // Check if the scrollbars are really needed for the content.    // If not, remove them, relayout, and repaint.    m_frame->view()->restoreScrollbar();    gotoAnchor();}void FrameLoader::loadDone(){    checkCompleted();}void FrameLoader::checkCompleted(){    if (m_frame->view())        m_frame->view()->checkStopDelayingDeferredRepaints();    // Any frame that hasn't completed yet?    for (Frame* child = m_frame->tree()->firstChild(); child; child = child->tree()->nextSibling())        if (!child->loader()->m_isComplete)            return;    // Have we completed before?    if (m_isComplete)        return;    // Are we still parsing?    if (m_frame->document()->parsing())        return;    // Still waiting for images/scripts?    if (numRequests(m_frame->document()))        return;    // OK, completed.    m_isComplete = true;    RefPtr<Frame> protect(m_frame);    checkCallImplicitClose(); // if we didn't do it before    // Do not start a redirection timer for subframes here.    // That is deferred until the parent is completed.    if (m_scheduledRedirection && !m_frame->tree()->parent())        startRedirectionTimer();    completed();    if (m_frame->page())        checkLoadComplete();}void FrameLoader::checkCompletedTimerFired(Timer<FrameLoader>*){    checkCompleted();}void FrameLoader::scheduleCheckCompleted(){    if (!m_checkCompletedTimer.isActive())        m_checkCompletedTimer.startOneShot(0);}void FrameLoader::checkLoadCompleteTimerFired(Timer<FrameLoader>*){    if (!m_frame->page())        return;    checkLoadComplete();}void FrameLoader::scheduleCheckLoadComplete(){    if (!m_checkLoadCompleteTimer.isActive())        m_checkLoadCompleteTimer.startOneShot(0);}void FrameLoader::checkCallImplicitClose(){    if (m_didCallImplicitClose || m_frame->document()->parsing())        return;    for (Frame* child = m_frame->tree()->firstChild(); child; child = child->tree()->nextSibling())        if (!child->loader()->m_isComplete) // still got a frame running -> too early            return;    m_didCallImplicitClose = true;    m_wasUnloadEventEmitted = false;    m_frame->document()->implicitClose();}KURL FrameLoader::baseURL() const{    ASSERT(m_frame->document());    return m_frame->document()->baseURL();}String FrameLoader::baseTarget() const{    ASSERT(m_frame->document());    return m_frame->document()->baseTarget();}KURL FrameLoader::completeURL(const String& url){    ASSERT(m_frame->document());    return m_frame->document()->completeURL(url);}void FrameLoader::scheduleHTTPRedirection(double delay, const String& url){    if (delay < 0 || delay > INT_MAX / 1000)        return;            if (!m_frame->page())        return;    if (url.isEmpty())        return;    // We want a new history item if the refresh timeout is > 1 second.    if (!m_scheduledRedirection || delay <= m_scheduledRedirection->delay)        scheduleRedirection(new ScheduledRedirection(delay, url, true, delay <= 1, false, false));}void FrameLoader::scheduleLocationChange(const String& url, const String& referrer, bool lockHistory, bool lockBackForwardList, bool wasUserGesture){    if (!m_frame->page())        return;    if (url.isEmpty())        return;    // If the URL we're going to navigate to is the same as the current one, except for the    // fragment part, we don't need to schedule the location change.    KURL parsedURL(url);    if (parsedURL.hasRef() && equalIgnoringRef(m_URL, parsedURL)) {        changeLocation(url, referrer, lockHistory, lockBackForwardList, wasUserGesture);        return;    }    // Handle a location change of a page with no document as a special case.    // This may happen when a frame changes the location of another frame.    bool duringLoad = !m_committedFirstRealDocumentLoad;    // If a redirect was scheduled during a load, then stop the current load.    // Otherwise when the current load transitions from a provisional to a     // committed state, pending redirects may be cancelled.     if (duringLoad) {        if (m_provisionalDocumentLoader)            m_provisionalDocumentLoader->stopLoading();        stopLoading(true);       }    ScheduledRedirection::Type type = duringLoad        ? ScheduledRedirection::locationChangeDuringLoad : ScheduledRedirection::locationChange;    scheduleRedirection(new ScheduledRedirection(type, url, referrer, lockHistory, lockBackForwardList, wasUserGesture, false));}void FrameLoader::scheduleRefresh(bool wasUserGesture){    if (!m_frame->page())        return;    if (m_URL.isEmpty())        return;    ScheduledRedirection::Type type = ScheduledRedirection::locationChange;    scheduleRedirection(new ScheduledRedirection(type, m_URL.string(), m_outgoingReferrer, true, true, wasUserGesture, true));}bool FrameLoader::isLocationChange(const ScheduledRedirection& redirection){    switch (redirection.type) {        case ScheduledRedirection::redirection:            return false;        case ScheduledRedirection::historyNavigation:        case ScheduledRedirection::locationChange:        case ScheduledRedirection::locationChangeDuringLoad:            return true;    }    ASSERT_NOT_REACHED();    return false;}void FrameLoader::scheduleHistoryNavigation(int steps){    if (!m_frame->page())        return;    // navigation will always be allowed in the 0 steps case, which is OK because that's supposed to force a reload.    if (!canGoBackOrForward(steps)) {        cancelRedirection();        return;    }    // If the steps to navigate is not zero (which needs to force a reload), and if we think the navigation is going to be a fragment load    // (when the URL we're going to navigate to is the same as the current one, except for the fragment part - but not exactly the same because that's a reload),    // then we don't need to schedule the navigation.    if (steps != 0) {        KURL destination = historyURL(steps);        // FIXME: This doesn't seem like a reliable way to tell whether or not the load will be a fragment load.        if (equalIgnoringRef(m_URL, destination) && m_URL != destination) {            goBackOrForward(steps);            return;        }    }        scheduleRedirection(new ScheduledRedirection(steps));}void FrameLoader::goBackOrForward(int distance){    if (distance == 0)        return;            Page* page = m_frame->page();    if (!page)        return;    BackForwardList* list = page->backForwardList();    if (!list)        return;        HistoryItem* item = list->itemAtIndex(distance);    if (!item) {        if (distance > 0) {            int forwardListCount = list->forwardListCount();            if (forwardListCount > 0)                 item = list->itemAtIndex(forwardListCount);        } else {            int backListCount = list->backListCount();            if (backListCount > 0)                item = list->itemAtIndex(-backListCount);        }    }        ASSERT(item); // we should not reach this line with an empty back/forward list    if (item)        page->goToItem(item, FrameLoadTypeIndexedBackForward);}void FrameLoader::redirectionTimerFired(Timer<FrameLoader>*){    ASSERT(m_frame->page());    OwnPtr<ScheduledRedirection> redirection(m_scheduledRedirection.release());    switch (redirection->type) {        case ScheduledRedirection::redirection:        case ScheduledRedirection::locationChange:        case ScheduledRedirection::locationChangeDuringLoad:            changeLocation(redirection->url, redirection->referrer,                redirection->lockHistory, redirection->lockBackForwardList, redirection->wasUserGesture, redirection->wasRefresh);            return;        case ScheduledRedirection::historyNavigation:            if (redirection->historySteps == 0) {                // Special case for go(0) from a frame -> reload only the frame                urlSelected(m_URL, "", 0, redirection->lockHistory, redirection->lockBackForwardList, redirection->wasUserGesture);                return;            }            // go(i!=0) from a frame navigates into the history of the frame only,            // in both IE and NS (but not in Mozilla). We can't easily do that.            goBackOrForward(redirection->historySteps);            return;    }    ASSERT_NOT_REACHED();}/*    In the case of saving state about a page with frames, we store a tree of items that mirrors the frame tree.      The item that was the target of the user's navigation is designated as the "targetItem".      When this method is called with doClip=YES we're able to create the whole tree except for the target's children,     which will be loaded in the future.  That part of the tree will be filled out as the child loads are committed.*/void FrameLoader::loadURLIntoChildFrame(const KURL& url, const String& referer, Frame* childFrame){    ASSERT(childFrame);    HistoryItem* parentItem = currentHistoryItem();    FrameLoadType loadType = this->loadType();    FrameLoadType childLoadType = FrameLoadTypeRedirectWithLockedBackForwardList;    KURL workingURL = url;        // If we're moving in the back/forward list, we might want to replace the content    // of this child frame with whatever was there at that point.    if (parentItem && parentItem->children().size() && isBackForwardLoadType(loadType)) {        HistoryItem* childItem = parentItem->childItemWithName(childFrame->tree()->name());        if (childItem) {            // Use the original URL to ensure we get all the side-effects, such as            // onLoad handlers, of any redirects that happened. An example of where            // this is needed is Radar 3213556.            workingURL = KURL(childItem->originalURLString());            childLoadType = loadType;            childFrame->loader()->setProvisionalHistoryItem(childItem);        }    }    RefPtr<Archive> subframeArchive = activeDocumentLoader()->popArchiveForSubframe(childFrame->tree()->name());        if (subframeArchive)        childFrame->loader()->loadArchive(subframeArchive.release());    else        childFrame->loader()->loadURL(workingURL, referer, String(), false, childLoadType, 0, 0);}void FrameLoader::loadArchive(PassRefPtr<Archive> prpArchive){    RefPtr<Archive> archive = prpArchive;        ArchiveResource* mainResource = archive->mainResource();    ASSERT(mainResource);    if (!mainResource)        return;            SubstituteData substituteData(mainResource->data(), mainResource->mimeType(), mainResource->textEncoding(), KURL());        ResourceRequest request(mainResource->url());#if PLATFORM(MAC)    request.applyWebArchiveHackForMail();#endif    RefPtr<DocumentLoader> documentLoader = m_client->createDocumentLoader(request, substituteData);    documentLoader->addAllArchiveResources(archive.get());    load(documentLoader.get());}String FrameLoader::encoding() const{

⌨️ 快捷键说明

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