📄 frameloaderclientqt.cpp
字号:
/* * Copyright (C) 2006 Zack Rusin <zack@kde.org> * Copyright (C) 2006 Apple Computer, Inc. All rights reserved. * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) * Copyright (C) 2008 Collabora Ltd. All rights reserved. * Coypright (C) 2008 Holger Hans Peter Freyther * * All rights reserved. * * 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. * * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR * 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 "CSSComputedStyleDeclaration.h"#include "CSSPropertyNames.h"#include "FrameLoaderClientQt.h"#include "FrameTree.h"#include "FrameView.h"#include "DocumentLoader.h"#include "MIMETypeRegistry.h"#include "ResourceResponse.h"#include "Page.h"#include "PluginData.h"#include "PluginDatabase.h"#include "ProgressTracker.h"#include "RenderPart.h"#include "ResourceRequest.h"#include "HistoryItem.h"#include "HTMLAppletElement.h"#include "HTMLFormElement.h"#include "HTMLPlugInElement.h"#include "NotImplemented.h"#include "QNetworkReplyHandler.h"#include "ResourceHandleInternal.h"#include "ResourceHandle.h"#include "Settings.h"#include "qwebpage.h"#include "qwebframe.h"#include "qwebframe_p.h"#include "qwebhistoryinterface.h"#include "qwebpluginfactory.h"#include <qfileinfo.h>#include <QCoreApplication>#include <QDebug>#if QT_VERSION >= 0x040400#include <QNetworkRequest>#include <QNetworkReply>#else#include "qwebnetworkinterface_p.h"#endif#include "qwebhistory_p.h"static bool dumpFrameLoaderCallbacks = false;static bool dumpResourceLoadCallbacks = false;static QMap<unsigned long, QString> dumpAssignedUrls;void QWEBKIT_EXPORT qt_dump_frame_loader(bool b){ dumpFrameLoaderCallbacks = b;}void QWEBKIT_EXPORT qt_dump_resource_load_callbacks(bool b){ dumpResourceLoadCallbacks = b;}// Compare with WebKitTools/DumpRenderTree/mac/FrameLoadDelegate.mmstatic QString drtDescriptionSuitableForTestResult(WebCore::Frame* _frame){ QWebFrame* frame = QWebFramePrivate::kit(_frame); QString name = frame->frameName(); bool isMainFrame = frame == frame->page()->mainFrame(); if (isMainFrame) { if (!name.isEmpty()) return QString::fromLatin1("main frame \"%1\"").arg(name); return QLatin1String("main frame"); } else { if (!name.isEmpty()) return QString::fromLatin1("frame \"%1\"").arg(name); return QLatin1String("frame (anonymous)"); }}static QString drtDescriptionSuitableForTestResult(const WebCore::KURL& _url){ QUrl url = _url; return url.toString();}static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceError& error){ QString failingURL = error.failingURL(); return QString::fromLatin1("<NSError domain NSURLErrorDomain, code %1, failing URL \"%2\">").arg(error.errorCode()).arg(failingURL);}static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceRequest& request){ QString url = request.url().string(); return QString::fromLatin1("<NSURLRequest %1>").arg(url);}static QString drtDescriptionSuitableForTestResult(const WebCore::ResourceResponse& response){ QString text = response.httpStatusText(); if (text.isEmpty()) return QLatin1String("(null)"); return text;}namespace WebCore{FrameLoaderClientQt::FrameLoaderClientQt() : m_frame(0) , m_webFrame(0) , m_pluginView(0) , m_hasSentResponseToPlugin(false) , m_firstData(false) , m_policyFunction(0) , m_loadSucceeded(false){ connect(this, SIGNAL(sigCallPolicyFunction(int)), this, SLOT(slotCallPolicyFunction(int)), Qt::QueuedConnection);}FrameLoaderClientQt::~FrameLoaderClientQt(){}void FrameLoaderClientQt::setFrame(QWebFrame* webFrame, Frame* frame){ m_webFrame = webFrame; m_frame = frame; if (!m_webFrame || !m_webFrame->page()) { qWarning("FrameLoaderClientQt::setFrame frame without Page!"); return; } connect(this, SIGNAL(loadStarted()), m_webFrame->page(), SIGNAL(loadStarted())); connect(this, SIGNAL(loadProgress(int)), m_webFrame->page(), SIGNAL(loadProgress(int))); connect(this, SIGNAL(loadFinished(bool)), m_webFrame->page(), SIGNAL(loadFinished(bool))); connect(this, SIGNAL(titleChanged(const QString&)), m_webFrame, SIGNAL(titleChanged(const QString&)));}QWebFrame* FrameLoaderClientQt::webFrame() const{ return m_webFrame;}void FrameLoaderClientQt::callPolicyFunction(FramePolicyFunction function, PolicyAction action){ ASSERT(!m_policyFunction); ASSERT(function); m_policyFunction = function; emit sigCallPolicyFunction(action);}void FrameLoaderClientQt::slotCallPolicyFunction(int action){ if (!m_frame || !m_policyFunction) return; FramePolicyFunction function = m_policyFunction; m_policyFunction = 0; (m_frame->loader()->*function)(WebCore::PolicyAction(action));}bool FrameLoaderClientQt::hasWebView() const{ //notImplemented(); return true;}void FrameLoaderClientQt::savePlatformDataToCachedFrame(CachedFrame*) { notImplemented();}void FrameLoaderClientQt::transitionToCommittedFromCachedFrame(CachedFrame*){}void FrameLoaderClientQt::transitionToCommittedForNewPage(){ ASSERT(m_frame); ASSERT(m_webFrame); QBrush brush = m_webFrame->page()->palette().brush(QPalette::Base); QColor backgroundColor = brush.style() == Qt::SolidPattern ? brush.color() : QColor(); m_frame->createView(m_webFrame->page()->viewportSize(), backgroundColor, !backgroundColor.alpha(), m_webFrame->page()->fixedLayoutSize(), m_webFrame->page()->useFixedLayout(), (ScrollbarMode)m_webFrame->scrollBarPolicy(Qt::Horizontal), (ScrollbarMode)m_webFrame->scrollBarPolicy(Qt::Vertical));}void FrameLoaderClientQt::makeRepresentation(DocumentLoader*){ // don't need this for now I think.}void FrameLoaderClientQt::forceLayout(){ FrameView* view = m_frame->view(); if (view) view->forceLayout(true);}void FrameLoaderClientQt::forceLayoutForNonHTML(){}void FrameLoaderClientQt::setCopiesOnScroll(){ // apparently mac specific}void FrameLoaderClientQt::detachedFromParent2(){}void FrameLoaderClientQt::detachedFromParent3(){}void FrameLoaderClientQt::dispatchDidHandleOnloadEvents(){ // don't need this one if (dumpFrameLoaderCallbacks) printf("%s - didHandleOnloadEventsForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));}void FrameLoaderClientQt::dispatchDidReceiveServerRedirectForProvisionalLoad(){ if (dumpFrameLoaderCallbacks) printf("%s - didReceiveServerRedirectForProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); notImplemented();}void FrameLoaderClientQt::dispatchDidCancelClientRedirect(){ if (dumpFrameLoaderCallbacks) printf("%s - didCancelClientRedirectForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); notImplemented();}void FrameLoaderClientQt::dispatchWillPerformClientRedirect(const KURL& url, double interval, double fireDate){ if (dumpFrameLoaderCallbacks) printf("%s - willPerformClientRedirectToURL: %s \n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(drtDescriptionSuitableForTestResult(url))); notImplemented();}void FrameLoaderClientQt::dispatchDidChangeLocationWithinPage(){ if (dumpFrameLoaderCallbacks) printf("%s - didChangeLocationWithinPageForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); if (!m_webFrame) return; emit m_webFrame->urlChanged(m_webFrame->url()); m_webFrame->page()->d->updateNavigationActions();}void FrameLoaderClientQt::dispatchWillClose(){ if (dumpFrameLoaderCallbacks) printf("%s - willCloseFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));}void FrameLoaderClientQt::dispatchDidStartProvisionalLoad(){ if (dumpFrameLoaderCallbacks) printf("%s - didStartProvisionalLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); if (m_webFrame) emit m_webFrame->provisionalLoad();}void FrameLoaderClientQt::dispatchDidReceiveTitle(const String& title){ if (dumpFrameLoaderCallbacks) printf("%s - didReceiveTitle: %s\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), qPrintable(QString(title))); if (!m_webFrame) return; // ### hack emit m_webFrame->urlChanged(m_webFrame->url()); emit titleChanged(title);}void FrameLoaderClientQt::dispatchDidCommitLoad(){ if (dumpFrameLoaderCallbacks) printf("%s - didCommitLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); if (m_frame->tree()->parent() || !m_webFrame) return; m_webFrame->page()->d->updateNavigationActions(); // We should assume first the frame has no title. If it has, then the above dispatchDidReceiveTitle() // will be called very soon with the correct title. // This properly resets the title when we navigate to a URI without a title. emit titleChanged(String());}void FrameLoaderClientQt::dispatchDidFinishDocumentLoad(){ if (dumpFrameLoaderCallbacks) printf("%s - didFinishDocumentLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); if (QWebPagePrivate::drtRun) { int unloadEventCount = m_frame->eventHandler()->pendingFrameUnloadEventCount(); if (unloadEventCount) printf("%s - has %u onunload handler(s)\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)), unloadEventCount); } if (m_frame->tree()->parent() || !m_webFrame) return; m_webFrame->page()->d->updateNavigationActions();}void FrameLoaderClientQt::dispatchDidFinishLoad(){ if (dumpFrameLoaderCallbacks) printf("%s - didFinishLoadForFrame\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame))); m_loadSucceeded = true; if (m_frame->tree()->parent() || !m_webFrame) return; m_webFrame->page()->d->updateNavigationActions();}void FrameLoaderClientQt::dispatchDidFirstLayout()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -