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

📄 frameloaderclientqt.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 3 页
字号:
void FrameLoaderClientQt::dispatchWillSendRequest(WebCore::DocumentLoader*, unsigned long identifier, WebCore::ResourceRequest& newRequest, const WebCore::ResourceResponse& redirectResponse){    if (dumpResourceLoadCallbacks)        printf("%s - willSendRequest %s redirectResponse %s\n",               qPrintable(dumpAssignedUrls[identifier]),               qPrintable(drtDescriptionSuitableForTestResult(newRequest)),               qPrintable(drtDescriptionSuitableForTestResult(redirectResponse)));    // seems like the Mac code doesn't do anything here by default neither    //qDebug() << "FrameLoaderClientQt::dispatchWillSendRequest" << request.isNull() << request.url().string`();}boolFrameLoaderClientQt::shouldUseCredentialStorage(DocumentLoader*, unsigned long){    notImplemented();    return false;}void FrameLoaderClientQt::dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&){    notImplemented();}void FrameLoaderClientQt::dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long, const AuthenticationChallenge&){    notImplemented();}void FrameLoaderClientQt::dispatchDidReceiveResponse(WebCore::DocumentLoader*, unsigned long, const WebCore::ResourceResponse& response){    m_response = response;    m_firstData = true;    //qDebug() << "    got response from" << response.url().string();}void FrameLoaderClientQt::dispatchDidReceiveContentLength(WebCore::DocumentLoader*, unsigned long, int){}void FrameLoaderClientQt::dispatchDidFinishLoading(WebCore::DocumentLoader* loader, unsigned long){}void FrameLoaderClientQt::dispatchDidFailLoading(WebCore::DocumentLoader* loader, unsigned long identifier, const WebCore::ResourceError& error){    if (dumpResourceLoadCallbacks)        printf("%s - didFailLoadingWithError: %s\n", qPrintable(dumpAssignedUrls[identifier]), qPrintable(drtDescriptionSuitableForTestResult(error)));    if (m_firstData) {        FrameLoader *fl = loader->frameLoader();        fl->setEncoding(m_response.textEncodingName(), false);        m_firstData = false;    }}bool FrameLoaderClientQt::dispatchDidLoadResourceFromMemoryCache(WebCore::DocumentLoader*, const WebCore::ResourceRequest&, const WebCore::ResourceResponse&, int){    notImplemented();    return false;}void FrameLoaderClientQt::dispatchDidFailProvisionalLoad(const WebCore::ResourceError&){    if (dumpFrameLoaderCallbacks)        printf("%s - didFailProvisionalLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));    m_loadSucceeded = false;}void FrameLoaderClientQt::dispatchDidFailLoad(const WebCore::ResourceError&){    if (dumpFrameLoaderCallbacks)        printf("%s - didFailLoadWithError\n", qPrintable(drtDescriptionSuitableForTestResult(m_frame)));    m_loadSucceeded = false;}WebCore::Frame* FrameLoaderClientQt::dispatchCreatePage(){    if (!m_webFrame)        return 0;    QWebPage *newPage = m_webFrame->page()->createWindow(QWebPage::WebBrowserWindow);    if (!newPage)        return 0;    return newPage->mainFrame()->d->frame;}void FrameLoaderClientQt::dispatchDecidePolicyForMIMEType(FramePolicyFunction function, const WebCore::String& MIMEType, const WebCore::ResourceRequest&){    // we need to call directly here    Q_ASSERT(!m_policyFunction);    m_policyFunction = function;    if (canShowMIMEType(MIMEType))        slotCallPolicyFunction(PolicyUse);    else        slotCallPolicyFunction(PolicyDownload);}void FrameLoaderClientQt::dispatchDecidePolicyForNewWindowAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>, const WebCore::String&){    Q_ASSERT(!m_policyFunction);    Q_ASSERT(m_webFrame);    m_policyFunction = function;#if QT_VERSION < 0x040400    QWebNetworkRequest r(request);#else    QNetworkRequest r(request.toNetworkRequest());#endif    QWebPage* page = m_webFrame->page();    if (!page->d->acceptNavigationRequest(0, r, QWebPage::NavigationType(action.type()))) {        if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)            m_frame->loader()->resetMultipleFormSubmissionProtection();        if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {            ResourceRequest emptyRequest;            m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);        }        slotCallPolicyFunction(PolicyIgnore);        return;    }    slotCallPolicyFunction(PolicyUse);}void FrameLoaderClientQt::dispatchDecidePolicyForNavigationAction(FramePolicyFunction function, const WebCore::NavigationAction& action, const WebCore::ResourceRequest& request, PassRefPtr<WebCore::FormState>){    Q_ASSERT(!m_policyFunction);    Q_ASSERT(m_webFrame);    m_policyFunction = function;#if QT_VERSION < 0x040400    QWebNetworkRequest r(request);#else    QNetworkRequest r(request.toNetworkRequest());#endif    QWebPage*page = m_webFrame->page();    if (!page->d->acceptNavigationRequest(m_webFrame, r, QWebPage::NavigationType(action.type()))) {        if (action.type() == NavigationTypeFormSubmitted || action.type() == NavigationTypeFormResubmitted)            m_frame->loader()->resetMultipleFormSubmissionProtection();        if (action.type() == NavigationTypeLinkClicked && r.url().hasFragment()) {            ResourceRequest emptyRequest;            m_frame->loader()->activeDocumentLoader()->setLastCheckedRequest(emptyRequest);        }        slotCallPolicyFunction(PolicyIgnore);        return;    }    slotCallPolicyFunction(PolicyUse);}void FrameLoaderClientQt::dispatchUnableToImplementPolicy(const WebCore::ResourceError&){    notImplemented();}void FrameLoaderClientQt::startDownload(const WebCore::ResourceRequest& request){#if QT_VERSION >= 0x040400    if (!m_webFrame)        return;    QWebPage *page = m_webFrame->page();    emit m_webFrame->page()->downloadRequested(request.toNetworkRequest());#endif}PassRefPtr<Frame> FrameLoaderClientQt::createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement,                                        const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight){    if (!m_webFrame)        return 0;    QWebFrameData frameData;    frameData.url = url;    frameData.name = name;    frameData.ownerElement = ownerElement;    frameData.referrer = referrer;    frameData.allowsScrolling = allowsScrolling;    frameData.marginWidth = marginWidth;    frameData.marginHeight = marginHeight;    QWebFrame* webFrame = new QWebFrame(m_webFrame, &frameData);    emit m_webFrame->page()->frameCreated(webFrame);    RefPtr<Frame> childFrame = adoptRef(webFrame->d->frame);    // ### set override encoding if we have one    FrameLoadType loadType = m_frame->loader()->loadType();    FrameLoadType childLoadType = FrameLoadTypeRedirectWithLockedBackForwardList;    childFrame->loader()->loadURL(frameData.url, frameData.referrer, String(), false, childLoadType, 0, 0);    // The frame's onload handler may have removed it from the document.    if (!childFrame->tree()->parent())        return 0;    return childFrame.release();}ObjectContentType FrameLoaderClientQt::objectContentType(const KURL& url, const String& _mimeType){//    qDebug()<<" ++++++++++++++++ url is "<<url.prettyURL()<<", mime = "<<_mimeType;    if (_mimeType == "application/x-qt-plugin" || _mimeType == "application/x-qt-styled-widget")        return ObjectContentOtherPlugin;    if (url.isEmpty() && !_mimeType.length())        return ObjectContentNone;    String mimeType = _mimeType;    if (!mimeType.length()) {        QFileInfo fi(url.path());        mimeType = MIMETypeRegistry::getMIMETypeForExtension(fi.suffix());    }    if (!mimeType.length())        return ObjectContentFrame;    if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType))        return ObjectContentImage;    if (PluginDatabase::installedPlugins()->isMIMETypeRegistered(mimeType))        return ObjectContentNetscapePlugin;    if (m_frame->page() && m_frame->page()->pluginData() && m_frame->page()->pluginData()->supportsMimeType(mimeType))        return ObjectContentOtherPlugin;    if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType))        return ObjectContentFrame;    if (url.protocol() == "about")        return ObjectContentFrame;    return ObjectContentNone;}static const CSSPropertyID qstyleSheetProperties[] = {    CSSPropertyColor,    CSSPropertyFontFamily,    CSSPropertyFontSize,    CSSPropertyFontStyle,    CSSPropertyFontWeight};const unsigned numqStyleSheetProperties = sizeof(qstyleSheetProperties) / sizeof(qstyleSheetProperties[0]);class QtPluginWidget: public Widget{public:    QtPluginWidget(QWidget* w = 0): Widget(w) {}    ~QtPluginWidget()    {        if (platformWidget())            platformWidget()->deleteLater();    }    virtual void invalidateRect(const IntRect& r)    {         if (platformWidget())            platformWidget()->update(r);    }    virtual void frameRectsChanged()    {        if (!platformWidget())            return;        IntRect windowRect = convertToContainingWindow(IntRect(0, 0, frameRect().width(), frameRect().height()));        platformWidget()->setGeometry(windowRect);        ScrollView* parentScrollView = parent();        if (!parentScrollView)            return;        ASSERT(parentScrollView->isFrameView());        IntRect clipRect(static_cast<FrameView*>(parentScrollView)->windowClipRect());        clipRect.move(-windowRect.x(), -windowRect.y());        clipRect.intersect(platformWidget()->rect());        platformWidget()->setMask(QRegion(clipRect.x(), clipRect.y(), clipRect.width(), clipRect.height()));    }};Widget* FrameLoaderClientQt::createPlugin(const IntSize& pluginSize, HTMLPlugInElement* element, const KURL& url, const Vector<String>& paramNames,                                          const Vector<String>& paramValues, const String& mimeType, bool loadManually){//     qDebug()<<"------ Creating plugin in FrameLoaderClientQt::createPlugin for "<<url.prettyURL() << mimeType;//     qDebug()<<"------\t url = "<<url.prettyURL();    if (!m_webFrame)        return 0;    QStringList params;    QStringList values;    QString classid(element->getAttribute("classid"));    for (int i = 0; i < paramNames.size(); ++i) {        params.append(paramNames[i]);        if (paramNames[i] == "classid")            classid = paramValues[i];    }    for (int i = 0; i < paramValues.size(); ++i)        values.append(paramValues[i]);    QString urlStr(url.string());    QUrl qurl = urlStr;    QObject* object = 0;    if (mimeType == "application/x-qt-plugin" || mimeType == "application/x-qt-styled-widget") {        object = m_webFrame->page()->createPlugin(classid, qurl, params, values);#ifndef QT_NO_STYLE_STYLESHEET        QWidget* widget = qobject_cast<QWidget*>(object);        if (widget && mimeType == "application/x-qt-styled-widget") {            QString styleSheet = element->getAttribute("style");            if (!styleSheet.isEmpty())                styleSheet += QLatin1Char(';');            for (int i = 0; i < numqStyleSheetProperties; ++i) {                CSSPropertyID property = qstyleSheetProperties[i];                styleSheet += QString::fromLatin1(::getPropertyName(property));                styleSheet += QLatin1Char(':');                styleSheet += computedStyle(element)->getPropertyValue(property);                styleSheet += QLatin1Char(';');            }            widget->setStyleSheet(styleSheet);        }#endif // QT_NO_STYLE_STYLESHEET    }#if QT_VERSION >= 0x040400        if (!object) {            QWebPluginFactory* factory = m_webFrame->page()->pluginFactory();            if (factory)                object = factory->create(mimeType, qurl, params, values);        }#endif        if (object) {            QWidget* widget = qobject_cast<QWidget*>(object);            if (widget) {                QWidget* view = m_webFrame->page()->view();                if (view)                    widget->setParent(view);                QtPluginWidget* w = new QtPluginWidget();                w->setPlatformWidget(widget);                // Make sure it's invisible until properly placed into the layout                w->setFrameRect(IntRect(0, 0, 0, 0));                return w;            }            // FIXME: make things work for widgetless plugins as well            delete object;    } else { // NPAPI Plugins        PluginView* pluginView = PluginView::create(m_frame, pluginSize, element, url,            paramNames, paramValues, mimeType, loadManually);        return pluginView;    }    return 0;}void FrameLoaderClientQt::redirectDataToPlugin(Widget* pluginWidget){    ASSERT(!m_pluginView);    m_pluginView = static_cast<PluginView*>(pluginWidget);    m_hasSentResponseToPlugin = false;}Widget* FrameLoaderClientQt::createJavaAppletWidget(const IntSize&, HTMLAppletElement*, const KURL& baseURL,                                                    const Vector<String>& paramNames, const Vector<String>& paramValues){    notImplemented();    return 0;}String FrameLoaderClientQt::overrideMediaType() const{    return String();}QString FrameLoaderClientQt::chooseFile(const QString& oldFile){    return webFrame()->page()->chooseFile(webFrame(), oldFile);}}#include "moc_FrameLoaderClientQt.cpp"

⌨️ 快捷键说明

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