Exemplo n.º 1
0
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
    // ctrl open in new tab
    // ctrl-shift open in new tab and select
    // ctrl-alt open in new window
    if (type == QWebPage::NavigationTypeLinkClicked
        && (m_keyboardModifiers & Qt::ControlModifier
            || m_pressedButtons == Qt::MidButton)) {
        bool newWindow = (m_keyboardModifiers & Qt::AltModifier);
        WebView *webView;
        if (newWindow) {
            BrowserApplication::instance()->newMainWindow();
            BrowserMainWindow *newMainWindow = BrowserApplication::instance()->mainWindow();
            webView = newMainWindow->currentTab();
            newMainWindow->raise();
            newMainWindow->activateWindow();
            webView->setFocus();
        } else {
            bool selectNewTab = (m_keyboardModifiers & Qt::ShiftModifier);
            webView = mainWindow()->tabWidget()->newTab(selectNewTab);
        }
        webView->load(request);
        m_keyboardModifiers = Qt::NoModifier;
        m_pressedButtons = Qt::NoButton;
        return false;
    }
    if (frame == mainFrame()) {
        m_loadingUrl = request.url();
        emit loadingUrl(m_loadingUrl);
    }
    return QWebPage::acceptNavigationRequest(frame, request, type);
}
Exemplo n.º 2
0
bool WBWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type)
{
    // ctrl open in new tab
    // ctrl-shift open in new tab and select
    // ctrl-alt open in new window
    if (type == QWebPage::NavigationTypeLinkClicked
        && (mKeyboardModifiers & Qt::ControlModifier
            || mPressedButtons == Qt::MidButton))
    {
        WBWebView *webView;

        bool selectNewTab = (mKeyboardModifiers & Qt::ShiftModifier);
        webView = mainWindow()->tabWidget()->newTab(selectNewTab);

        webView->load(request);
        mKeyboardModifiers = Qt::NoModifier;
        mPressedButtons = Qt::NoButton;

        return false;
    }

    if (frame == mainFrame())
    {
        mLoadingUrl = request.url();
        emit loadingUrl(mLoadingUrl);
    }

    return QWebPage::acceptNavigationRequest(frame, request, type);
}
Exemplo n.º 3
0
WebView::WebView(QWidget* parent)
    : QWebView(parent)
    , m_progress(0)
    , m_page(new WebPage(this))
{
    setPage(m_page);
    connect(page(), SIGNAL(statusBarMessage(QString)),
            SLOT(setStatusBarText(QString)));
    connect(this, SIGNAL(loadProgress(int)),
            this, SLOT(setProgress(int)));
    connect(this, SIGNAL(loadFinished(bool)),
            this, SLOT(loadFinished()));
    connect(page(), SIGNAL(loadingUrl(QUrl)),
            this, SIGNAL(urlChanged(QUrl)));
    connect(page(), SIGNAL(downloadRequested(QNetworkRequest)),
            this, SLOT(downloadRequested(QNetworkRequest)));
    page()->setForwardUnsupportedContent(true);

}
Exemplo n.º 4
0
bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type, const QByteArray& postData)
{
    QString scheme = request.url().scheme();
    if (scheme == QLatin1String("mailto")
        || scheme == QLatin1String("ftp")) {
//        QDesktopServices::openUrl(request.url());
        return false;
    }

    if (IS_CRAWLER) // when crawler, we run the webapplication is the same process
        // make it easier for replay
        return QWebPage::acceptNavigationRequest(frame, request, type, postData);
    
    WebView::OpenType t = WebView::NewWebApp;
    WebView* view = qobject_cast<WebView*>(parent());
    Q_ASSERT(view != 0);

    // little trick to avoid double post
    if (m_posted) {
        m_posted = false;
    } else if (postData.size() > 0) {
        m_posted = true;
    }
    // ctrl open in new tab
    // ctrl-shift open in new tab and select
    // ctrl-alt open in new window
    if (type == QWebPage::NavigationTypeLinkClicked
        && (m_keyboardModifiers & Qt::ControlModifier
            || m_pressedButtons == Qt::MidButton)) {
        bool newWindow = (m_keyboardModifiers & Qt::AltModifier);
        if (newWindow) {
            t = WebView::NewWindow;            
        } else {
            bool selectNewTab = (m_keyboardModifiers & Qt::ShiftModifier);
            if (selectNewTab)
                t = WebView::NewTabSelect;
            else
                t = WebView::NewTabNoSelect;
        }

        // check and load
        view->loadPolicy(request, postData, t);
        
        m_keyboardModifiers = Qt::NoModifier;
        m_pressedButtons = Qt::NoButton;
        return false;
    }
    
    //qDebug() << "navigation request url: " << request.url();
    QUrl::FormattingOptions format = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
    if (frame == mainFrame()) {
        //qDebug() << "mainFrame navigation request to " << request.url();
        m_loadingUrl = request.url();
        
        QUrl current = view->url();
        bool sop = (m_loadingUrl.scheme().toLower() == current.scheme().toLower())
            && (m_loadingUrl.host().toLower() == current.host().toLower())
            && (m_loadingUrl.port() == current.port());
        //QUrl::FormattingOptions format = QUrl::RemoveQuery | QUrl::RemoveFragment | QUrl::StripTrailingSlash;
        if (!sop //(view->loaded() || type == QWebPage::NavigationTypeLinkClicked) && !sop
            /*(m_loadingUrl.toString(format) != current.toString(format)) */) {
            t = WebView::NewWebApp;
            
            // check and load
            if (m_posted)
                view->loadPolicy(request, postData, t);
            else
                view->loadPolicy(request, QByteArray(), t);

            return false;
        } else {
            emit loadingUrl(m_loadingUrl);
            
            
            if ((type != NavigationTypeOther) && (type != NavigationTypeReload) && (type != NavigationTypeBackOrForward)
                || (view->m_userAction)) {
                QVariant var(m_loadingUrl.toString());
                OPNET::OpNetwork::instance()->sendUIMsg(MSG_addHistoryItem, getByteArray(var));
                view->m_userAction = false;
            }
            if (type == NavigationTypeBackOrForward) {
                //QVariant var(m_back);
                //OPNET::OpNetwork::instance()->sendUIMsg(MSG_navBackOrForward, getByteArray(var));
                m_back = false;
            }
        }
    }
    else if(frame == 0)
    {
        t = WebView::NewTabNoSelect;

        // check and load
        view->loadPolicy(request, postData, t);

        return false;
    }
    // same-origin and "about:blank" navigation requests fall-through to acceptNavigationRequest
    else if( m_iframeHandled &&
             (request.url().toString(format | QUrl::RemovePath) != view->url().toString(format | QUrl::RemovePath) 
              && request.url().toString() != "about:blank")) {
        //qDebug() << "navigation request for sub-frame \"" << frame->frameName() << "\" to " << request.url() << " type: " << type;
        t = WebView::NewSubFrame;
        OPNET::OpNetwork::instance()->sendSysCall(MSG_EMBED_FRAME, 0, frame->frameName().toAscii());
        view->loadPolicy(request, postData, t);
        return false;
    }

    return QWebPage::acceptNavigationRequest(frame, request, type, postData);
}