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

📄 frameloader.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1.  Redistributions of source code must retain the above copyright *     notice, this list of conditions and the following disclaimer.  * 2.  Redistributions in binary form must reproduce the above copyright *     notice, this list of conditions and the following disclaimer in the *     documentation and/or other materials provided with the distribution.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of *     its contributors may be used to endorse or promote products derived *     from this software without specific prior written permission.  * * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#include "FrameLoader.h"#include "Archive.h"#include "ArchiveFactory.h"#include "CString.h"#include "Cache.h"#include "CachedPage.h"#include "Chrome.h"#include "DOMImplementation.h"#include "DOMWindow.h"#include "DocLoader.h"#include "Document.h"#include "DocumentLoader.h"#include "Editor.h"#include "EditorClient.h"#include "Element.h"#include "Event.h"#include "EventNames.h"#include "FloatRect.h"#include "FormState.h"#include "Frame.h"#include "FrameLoadRequest.h"#include "FrameLoaderClient.h"#include "FrameTree.h"#include "FrameView.h"#include "HTMLAnchorElement.h"#include "HTMLFormElement.h"#include "HTMLFrameElement.h"#include "HTMLNames.h"#include "HTMLObjectElement.h"#include "HTTPParsers.h"#include "HistoryItem.h"#include "IconDatabase.h"#include "IconLoader.h"#include "InspectorController.h"#include "Logging.h"#include "MIMETypeRegistry.h"#include "MainResourceLoader.h"#include "Page.h"#include "PageCache.h"#include "PageGroup.h"#include "PluginData.h"#include "PluginDocument.h"#include "ProgressTracker.h"#include "RenderPart.h"#include "RenderView.h"#include "RenderWidget.h"#include "ResourceHandle.h"#include "ResourceRequest.h"#include "ScriptController.h"#include "ScriptSourceCode.h"#include "ScriptValue.h"#include "SecurityOrigin.h"#include "SegmentedString.h"#include "Settings.h"#include "TextResourceDecoder.h"#include "WindowFeatures.h"#include "XMLHttpRequest.h"#include "XMLTokenizer.h"#include <wtf/CurrentTime.h>#include <wtf/StdLibExtras.h>#if ENABLE(OFFLINE_WEB_APPLICATIONS)#include "ApplicationCache.h"#include "ApplicationCacheResource.h"#endif#if ENABLE(SVG)#include "SVGDocument.h"#include "SVGLocatable.h"#include "SVGNames.h"#include "SVGPreserveAspectRatio.h"#include "SVGSVGElement.h"#include "SVGViewElement.h"#include "SVGViewSpec.h"#endifnamespace WebCore {#if ENABLE(SVG)using namespace SVGNames;#endifusing namespace HTMLNames;typedef HashSet<String, CaseFoldingHash> LocalSchemesMap;struct FormSubmission {    FormSubmission(const char* action, const String& url, PassRefPtr<FormData> formData,                   const String& target, const String& contentType, const String& boundary,                   PassRefPtr<Event> event, bool lockHistory, bool lockBackForwardList)        : action(action)        , url(url)        , formData(formData)        , target(target)        , contentType(contentType)        , boundary(boundary)        , event(event)        , lockHistory(lockHistory)        , lockBackForwardList(lockBackForwardList)    {    }    const char* action;    String url;    RefPtr<FormData> formData;    String target;    String contentType;    String boundary;    RefPtr<Event> event;    bool lockHistory;    bool lockBackForwardList;};struct ScheduledRedirection {    enum Type { redirection, locationChange, historyNavigation, locationChangeDuringLoad };    const Type type;    const double delay;    const String url;    const String referrer;    const int historySteps;    const bool lockHistory;    const bool lockBackForwardList;    const bool wasUserGesture;    const bool wasRefresh;    ScheduledRedirection(double delay, const String& url, bool lockHistory, bool lockBackForwardList, bool wasUserGesture, bool refresh)        : type(redirection)        , delay(delay)        , url(url)        , historySteps(0)        , lockHistory(lockHistory)        , lockBackForwardList(lockBackForwardList)        , wasUserGesture(wasUserGesture)        , wasRefresh(refresh)    {        ASSERT(!url.isEmpty());    }    ScheduledRedirection(Type locationChangeType, const String& url, const String& referrer, bool lockHistory, bool lockBackForwardList, bool wasUserGesture, bool refresh)        : type(locationChangeType)        , delay(0)        , url(url)        , referrer(referrer)        , historySteps(0)        , lockHistory(lockHistory)        , lockBackForwardList(lockBackForwardList)        , wasUserGesture(wasUserGesture)        , wasRefresh(refresh)    {        ASSERT(locationChangeType == locationChange || locationChangeType == locationChangeDuringLoad);        ASSERT(!url.isEmpty());    }    explicit ScheduledRedirection(int historyNavigationSteps)        : type(historyNavigation)        , delay(0)        , historySteps(historyNavigationSteps)        , lockHistory(false)        , lockBackForwardList(false)        , wasUserGesture(false)        , wasRefresh(false)    {    }};static double storedTimeOfLastCompletedLoad;static FrameLoader::LocalLoadPolicy localLoadPolicy = FrameLoader::AllowLocalLoadsForLocalOnly;bool isBackForwardLoadType(FrameLoadType type){    switch (type) {        case FrameLoadTypeStandard:        case FrameLoadTypeReload:        case FrameLoadTypeReloadFromOrigin:        case FrameLoadTypeSame:        case FrameLoadTypeRedirectWithLockedBackForwardList:        case FrameLoadTypeReplace:            return false;        case FrameLoadTypeBack:        case FrameLoadTypeForward:        case FrameLoadTypeIndexedBackForward:            return true;    }    ASSERT_NOT_REACHED();    return false;}static int numRequests(Document* document){    if (!document)        return 0;        return document->docLoader()->requestCount();}FrameLoader::FrameLoader(Frame* frame, FrameLoaderClient* client)    : m_frame(frame)    , m_client(client)    , m_state(FrameStateCommittedPage)    , m_loadType(FrameLoadTypeStandard)    , m_policyLoadType(FrameLoadTypeStandard)    , m_delegateIsHandlingProvisionalLoadError(false)    , m_delegateIsDecidingNavigationPolicy(false)    , m_delegateIsHandlingUnimplementablePolicy(false)    , m_firstLayoutDone(false)    , m_quickRedirectComing(false)    , m_sentRedirectNotification(false)    , m_inStopAllLoaders(false)    , m_navigationDuringLoad(false)    , m_isExecutingJavaScriptFormAction(false)    , m_isRunningScript(false)    , m_didCallImplicitClose(false)    , m_wasUnloadEventEmitted(false)    , m_isComplete(false)    , m_isLoadingMainResource(false)    , m_cancellingWithLoadInProgress(false)    , m_needsClear(false)    , m_receivedData(false)    , m_encodingWasChosenByUser(false)    , m_containsPlugIns(false)    , m_redirectionTimer(this, &FrameLoader::redirectionTimerFired)    , m_checkCompletedTimer(this, &FrameLoader::checkCompletedTimerFired)    , m_checkLoadCompleteTimer(this, &FrameLoader::checkLoadCompleteTimerFired)    , m_opener(0)    , m_openedByDOM(false)    , m_creatingInitialEmptyDocument(false)    , m_isDisplayingInitialEmptyDocument(false)    , m_committedFirstRealDocumentLoad(false)    , m_didPerformFirstNavigation(false)#ifndef NDEBUG    , m_didDispatchDidCommitLoad(false)#endif#if ENABLE(WML)    , m_forceReloadWmlDeck(false)#endif{}FrameLoader::~FrameLoader(){    setOpener(0);    HashSet<Frame*>::iterator end = m_openedFrames.end();    for (HashSet<Frame*>::iterator it = m_openedFrames.begin(); it != end; ++it)        (*it)->loader()->m_opener = 0;            m_client->frameLoaderDestroyed();}void FrameLoader::init(){    // this somewhat odd set of steps is needed to give the frame an initial empty document    m_isDisplayingInitialEmptyDocument = false;    m_creatingInitialEmptyDocument = true;    setPolicyDocumentLoader(m_client->createDocumentLoader(ResourceRequest(KURL("")), SubstituteData()).get());    setProvisionalDocumentLoader(m_policyDocumentLoader.get());    setState(FrameStateProvisional);    m_provisionalDocumentLoader->setResponse(ResourceResponse(KURL(), "text/html", 0, String(), String()));    m_provisionalDocumentLoader->finishedLoading();    begin(KURL(), false);    end();    m_frame->document()->cancelParsing();    m_creatingInitialEmptyDocument = false;    m_didCallImplicitClose = true;}void FrameLoader::setDefersLoading(bool defers){    if (m_documentLoader)        m_documentLoader->setDefersLoading(defers);    if (m_provisionalDocumentLoader)        m_provisionalDocumentLoader->setDefersLoading(defers);    if (m_policyDocumentLoader)        m_policyDocumentLoader->setDefersLoading(defers);}Frame* FrameLoader::createWindow(FrameLoader* frameLoaderForFrameLookup, const FrameLoadRequest& request, const WindowFeatures& features, bool& created){     ASSERT(!features.dialog || request.frameName().isEmpty());    if (!request.frameName().isEmpty() && request.frameName() != "_blank") {        Frame* frame = frameLoaderForFrameLookup->frame()->tree()->find(request.frameName());        if (frame && shouldAllowNavigation(frame)) {            if (!request.resourceRequest().url().isEmpty())                frame->loader()->loadFrameRequestWithFormAndValues(request, false, false, 0, 0, HashMap<String, String>());            if (Page* page = frame->page())                page->chrome()->focus();            created = false;            return frame;        }    }        // FIXME: Setting the referrer should be the caller's responsibility.    FrameLoadRequest requestWithReferrer = request;    requestWithReferrer.resourceRequest().setHTTPReferrer(m_outgoingReferrer);    addHTTPOriginIfNeeded(requestWithReferrer.resourceRequest(), outgoingOrigin());    Page* oldPage = m_frame->page();    if (!oldPage)        return 0;            Page* page = oldPage->chrome()->createWindow(m_frame, requestWithReferrer, features);    if (!page)        return 0;    Frame* frame = page->mainFrame();    if (request.frameName() != "_blank")        frame->tree()->setName(request.frameName());    page->chrome()->setToolbarsVisible(features.toolBarVisible || features.locationBarVisible);    page->chrome()->setStatusbarVisible(features.statusBarVisible);    page->chrome()->setScrollbarsVisible(features.scrollbarsVisible);    page->chrome()->setMenubarVisible(features.menuBarVisible);    page->chrome()->setResizable(features.resizable);    // 'x' and 'y' specify the location of the window, while 'width' and 'height'     // specify the size of the page. We can only resize the window, so     // adjust for the difference between the window size and the page size.    FloatRect windowRect = page->chrome()->windowRect();    FloatSize pageSize = page->chrome()->pageRect().size();    if (features.xSet)        windowRect.setX(features.x);    if (features.ySet)        windowRect.setY(features.y);    if (features.widthSet)        windowRect.setWidth(features.width + (windowRect.width() - pageSize.width()));    if (features.heightSet)        windowRect.setHeight(features.height + (windowRect.height() - pageSize.height()));    page->chrome()->setWindowRect(windowRect);    page->chrome()->show();    created = true;    return frame;}bool FrameLoader::canHandleRequest(const ResourceRequest& request){    return m_client->canHandleRequest(request);}void FrameLoader::changeLocation(const String& url, const String& referrer, bool lockHistory, bool lockBackForwardList, bool userGesture, bool refresh){    changeLocation(completeURL(url), referrer, lockHistory, lockBackForwardList, userGesture, refresh);}void FrameLoader::changeLocation(const KURL& url, const String& referrer, bool lockHistory, bool lockBackForwardList, bool userGesture, bool refresh){    RefPtr<Frame> protect(m_frame);

⌨️ 快捷键说明

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