void QtStageWebView::registerEventbus()
{
    QWebFrame* frame = page()->mainFrame();
    frame->addToJavaScriptWindowObject(QString("eventbus2"), new BlackBerryBus(this, frame));
    frame->evaluateJavaScript(BlackBerry::Ripple::eventbusSource);

    // check for iframes, if found add to window object
    for(int i = 0; i < frame->childFrames().length(); i++)
    {
        frame->childFrames()[i]->addToJavaScriptWindowObject(QString("eventbus2"), new BlackBerryBus(this, frame->childFrames()[i]));
        frame->childFrames()[i]->evaluateJavaScript(BlackBerry::Ripple::eventbusSource);
  }
}
Esempio n. 2
0
QList<QWebFrame *> QWebFrameProto::childFrames() const
{
  QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject());
  scriptDeprecated("QWebFrame will not be available in future versions");
  if (item)
    return item->childFrames();
  return QList<QWebFrame *>();
}
void FakePluginWidget::load (bool loadAll)
{
    QWebView *view = webViewFrom(parentWidget());
    if (!view)
        return;

    // WORKAROUND: For some reason, when we load on demand plugins the scroll
    // position gets utterly screwed up and reset to the beginning of the
    // document. This is an effort to workaround that issue.
    connect(view->page(), SIGNAL(scrollRequested(int,int,QRect)),
            this, SLOT(updateScrollPoisition(int,int,QRect)), Qt::QueuedConnection);

    hide();
    m_swapping = true;

    QList<QWebFrame*> frames;
    frames.append(view->page()->mainFrame());

    QString selector (QLatin1String("applet:not([type]),embed:not([type]),object:not([type]),applet[type=\""));
    selector += m_mimeType;
    selector += QLatin1String("\"],embed[type=\"");
    selector += m_mimeType;
    selector += QLatin1String("\"],object[type=\"");
    selector += m_mimeType;
    selector += QLatin1String("\"]");

    while (!frames.isEmpty()) {
        bool loaded = false;
        QWebFrame *frame = frames.takeFirst();
        QWebElement docElement = frame->documentElement();
        QWebElementCollection elements = docElement.findAll(selector);

        Q_FOREACH (QWebElement element, elements) {
            if (loadAll || element.evaluateJavaScript(QLatin1String("this.swapping")).toBool()) {
                QWebElement substitute = element.clone();
                emit pluginLoaded(m_id);
                m_updateScrollPosition = true;
                element.replace(substitute);
                deleteLater();
                if (!loadAll) {
                    loaded = true;
                    break;  // Found the one plugin we wanted to start so exit loop.
                }
            }
        }
        if (loaded && !loadAll) {
            break;      // Loading only one item, exit the outer loop as well...
        }
        frames += frame->childFrames();
    }

    m_swapping = false;
}
Esempio n. 4
0
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
    if (reply->error() == QNetworkReply::ProtocolUnknownError) {
        QSettings settings;
        settings.beginGroup(QLatin1String("WebView"));
        QStringList externalSchemes;
        externalSchemes = settings.value(QLatin1String("externalSchemes")).toStringList();
        if (externalSchemes.contains(reply->url().scheme()))
            QDesktopServices::openUrl(reply->url());
        return;
    }

    if (reply->error() == QNetworkReply::NoError) {
        if (reply->header(QNetworkRequest::ContentTypeHeader).isValid())
            BrowserApplication::downloadManager()->handleUnsupportedContent(reply);
        return;
    }

    QFile file(QLatin1String(":/notfound.html"));
    bool isOpened = file.open(QIODevice::ReadOnly);
    Q_ASSERT(isOpened);
    QString title = tr("Error loading page: %1").arg(reply->url().toString());
    QString html = QString(QLatin1String(file.readAll()))
                        .arg(title)
                        .arg(reply->errorString())
                        .arg(reply->url().toString());

    QBuffer imageBuffer;
    imageBuffer.open(QBuffer::ReadWrite);
    QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view());
    QPixmap pixmap = icon.pixmap(QSize(32, 32));
    if (pixmap.save(&imageBuffer, "PNG")) {
        html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
                     QString(QLatin1String(imageBuffer.buffer().toBase64())));
    }

    QList<QWebFrame*> frames;
    frames.append(mainFrame());
    while (!frames.isEmpty()) {
        QWebFrame *frame = frames.takeFirst();
        if (frame->url() == reply->url()) {
            frame->setHtml(html, reply->url());
            return;
        }
        QList<QWebFrame *> children = frame->childFrames();
        foreach (QWebFrame *frame, children)
            frames.append(frame);
    }
    if (m_loadingUrl == reply->url()) {
        mainFrame()->setHtml(html, reply->url());
    }
}
Esempio n. 5
0
	QWebFrame* CustomWebPage::FindFrame (const QUrl& url)
	{
		QList<QWebFrame*> frames;
		frames.append (mainFrame ());
		while (!frames.isEmpty ())
		{
			QWebFrame *frame = frames.takeFirst ();
			if (frame->url () == url)
				return frame;
			frames << frame->childFrames ();
		}
		return 0;
	}
Esempio n. 6
0
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
    QString errorString = reply->errorString();

    if (m_loadingUrl != reply->url()) {
        // sub resource of this page
        qWarning() << "Resource" << reply->url().toEncoded() << "has unknown Content-Type, will be ignored.";
        reply->deleteLater();
        return;
    }

    if (reply->error() == QNetworkReply::NoError && !reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
        errorString = "Unknown Content-Type";
    }

    QFile file(QLatin1String(":/notfound.html"));
    bool isOpened = file.open(QIODevice::ReadOnly);
    Q_ASSERT(isOpened);
    Q_UNUSED(isOpened)

    QString title = tr("Error loading page: %1").arg(reply->url().toString());
    QString html = QString(QLatin1String(file.readAll()))
                        .arg(title)
                        .arg(errorString)
                        .arg(reply->url().toString());

    QBuffer imageBuffer;
    imageBuffer.open(QBuffer::ReadWrite);
    QIcon icon = view()->style()->standardIcon(QStyle::SP_MessageBoxWarning, 0, view());
    QPixmap pixmap = icon.pixmap(QSize(32,32));
    if (pixmap.save(&imageBuffer, "PNG")) {
        html.replace(QLatin1String("IMAGE_BINARY_DATA_HERE"),
                     QString(QLatin1String(imageBuffer.buffer().toBase64())));
    }

    QList<QWebFrame*> frames;
    frames.append(mainFrame());
    while (!frames.isEmpty()) {
        QWebFrame *frame = frames.takeFirst();
        if (frame->url() == reply->url()) {
            frame->setHtml(html, reply->url());
            return;
        }
        QList<QWebFrame *> children = frame->childFrames();
        foreach(QWebFrame *frame, children)
            frames.append(frame);
    }
    if (m_loadingUrl == reply->url()) {
        mainFrame()->setHtml(html, reply->url());
    }
}
Esempio n. 7
0
void ClickToFlash::findElement()
{
  if (!loadButton_)
    return;

  QPoint objectPos = page_->view()->mapFromGlobal(loadButton_->mapToGlobal(loadButton_->pos()));
  QWebFrame* objectFrame = page_->frameAt(objectPos);
  QWebHitTestResult hitResult;
  QWebElement hitElement;

  if (objectFrame) {
    hitResult = objectFrame->hitTestContent(objectPos);
    hitElement = hitResult.element();
  }

  if (!hitElement.isNull() && (hitElement.tagName().compare("embed", Qt::CaseInsensitive) == 0 ||
                               hitElement.tagName().compare("object", Qt::CaseInsensitive) == 0)) {
    element_ = hitElement;
    return;
  }

  // HitTestResult failed, trying to find element by src
  // attribute in elements at all frames on page (less accurate)

  QList<QWebFrame*> frames;
  frames.append(objectFrame);
  frames.append(page_->mainFrame());

  while (!frames.isEmpty()) {
    QWebFrame* frame = frames.takeFirst();
    if (!frame) {
      continue;
    }
    QWebElement docElement = frame->documentElement();

    QWebElementCollection elements;
    elements.append(docElement.findAll(QLatin1String("embed")));
    elements.append(docElement.findAll(QLatin1String("object")));

    foreach (const QWebElement &element, elements) {
      if (!checkElement(element) && !checkUrlOnElement(element)) {
        continue;
      }
      element_ = element;
      return;
    }
    frames += frame->childFrames();
  }
}
Esempio n. 8
0
QWebFrame *EventSender::frameUnderMouse() const
{
    QWebFrame *frame = m_page->mainFrame();

redo:
    QList<QWebFrame*> children = frame->childFrames();
    for (int i = 0; i < children.size(); ++i) {
        if (children.at(i)->geometry().contains(m_mousePos)) {
            frame = children.at(i);
            goto redo;
        }
    }
    if (frame->geometry().contains(m_mousePos))
        return frame;
    return 0;
}
Esempio n. 9
0
void HelpPage::onHandleUnsupportedContent(QNetworkReply *reply)
{
    // sub resource of this page
    if (m_loadingUrl != reply->url()) {
        qWarning() << "Resource" << reply->url().toEncoded() << "has unknown Content-Type, will be ignored.";
        reply->deleteLater();
        return;
    }

    // set a default error string we are going to display
    QString errorString = HelpViewer::tr("Unknown or unsupported Content!");
    if (reply->error() == QNetworkReply::NoError) {
        // try to open the url using using the desktop service
        if (QDesktopServices::openUrl(reply->url())) {
            reply->deleteLater();
            return;
        }
        // seems we failed, now we show the error page inside creator
    } else {
        errorString = reply->errorString();
    }

    // setup html
    const QString html = QString::fromLatin1(g_htmlPage).arg(g_percent1, errorString,
        HelpViewer::tr("Error loading: %1").arg(reply->url().toString()), g_percent4, g_percent5, g_percent6,
        g_percent7);

    // update the current layout
    QList<QWebFrame*> frames;
    frames.append(mainFrame());
    while (!frames.isEmpty()) {
        QWebFrame *frame = frames.takeFirst();
        if (frame->url() == reply->url()) {
            frame->setHtml(html, reply->url());
            return;
        }

        QList<QWebFrame *> children = frame->childFrames();
        foreach (QWebFrame *frame, children)
            frames.append(frame);
    }

    if (m_loadingUrl == reply->url())
        mainFrame()->setHtml(html, reply->url());
}
Esempio n. 10
0
void WebView::applyEncoding()
{
	if (m_encoding_in_progress)
		return;

	if (webPage() && webPage()->mainWindow())
	{
		QString enc = webPage()->mainWindow()->m_currentEncoding;
		if (enc.isEmpty())
			return;

		if (enc == m_current_encoding && m_current_encoding_url == url() )
			return;

		QWebPage *page = webPage();
		if (!page)
			return;

		QWebFrame *mainframe = page->mainFrame();
		if (!mainframe)
			return;

		QString html = mainframe->toHtml();

		QTextCodec *codec = QTextCodec::codecForName( enc.toAscii() );
		if (!codec)
			return;

		QTextDecoder *decoder = codec->makeDecoder();
		if (!decoder)
			return;

		m_encoding_in_progress = true;
		m_current_encoding = enc;
		m_current_encoding_url = url();
		QString output = decoder->toUnicode(html.toAscii());
		mainframe->setHtml(output, mainframe->url());

		QList<QWebFrame *> children = mainframe->childFrames();
		foreach(QWebFrame *frame, children)
		{
			html = frame->toHtml();
			output = decoder->toUnicode(html.toAscii());
			frame->setHtml(output, frame->url());
		}
Esempio n. 11
0
QString NoteItem::getTitle()
{
    if(m_readOnly)
        return m_title->text();
    else {
        QString title = m_titleEdit->text();
        if(title == "" || title == tr("Untitled")) {
            if(m_rich) {
                QWebFrame* mainFrame = m_webView->page()->mainFrame();
                QWebFrame* iframe = mainFrame->childFrames()[0];
                title = MainWindow::getTitleFromContent(iframe->toPlainText());
            }
            else
                title = MainWindow::getTitleFromContent(m_textEdit->toPlainText());
        }
        return title;
    }
}
Esempio n. 12
0
void WebPage::handleUnsupportedContent(QNetworkReply *reply)
{
    if (reply->error() == QNetworkReply::NoError) {
        if (reply->header(QNetworkRequest::ContentTypeHeader).isValid())
            qDebug() << "download it";
            new OpDownloader(reply);
        return;
    }

    if (reply->error() == QNetworkReply::ProtocolUnknownError) {
        // we currently don't support protocol other than http(s):// and file://
        // return;
    }

    //display notfound
    if (reply->url().isEmpty())
        return;
    QFile file(QLatin1String(":/notfound.html"));
    bool isOpened = file.open(QIODevice::ReadOnly);
    Q_ASSERT(isOpened);
    QString title = ("HTTP 404 Not Found");
    QString html = QString(QLatin1String(file.readAll()));
    
    QList<QWebFrame*> frames;
    frames.append(mainFrame());
    while (!frames.isEmpty()) {
        QWebFrame *frame = frames.takeFirst();
        if (frame->url() == reply->url()) {
            frame->setHtml(html, reply->url());
            return;
        }
        QList<QWebFrame *> children = frame->childFrames();
        foreach (QWebFrame *frame, children)
            frames.append(frame);
    }
    if (m_loadingUrl == reply->url()) {
        mainFrame()->setHtml(html, reply->url());
    }
}
Esempio n. 13
0
void AutoFillModel::post(const QNetworkRequest &request, const QByteArray &outgoingData)
{
    //Dont save in private browsing
    if (mApp->webSettings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
        return;
    }

    m_lastOutgoingData = outgoingData;

    QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
    WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
    if (!webPage) {
        return;
    }
    WebView* webView = qobject_cast<WebView*>(webPage->view());
    if (!webView) {
        return;
    }

    v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 101));
    QWebPage::NavigationType type = (QWebPage::NavigationType)v.toInt();

    if (type != QWebPage::NavigationTypeFormSubmitted) {
        return;
    }

    QString usernameName;
    QString usernameValue;
    QString passwordName;
    QString passwordValue;
    QUrl siteUrl = webPage->url();

    if (!isStoringEnabled(siteUrl)) {
        return;
    }

    QWebElementCollection allForms; // All form elements on page
    QWebElement foundForm;          // Sent form element

    QList<QWebFrame*> frames;
    frames.append(webPage->mainFrame());  // Find all form elements
    while (!frames.isEmpty()) {
        QWebFrame* frame = frames.takeFirst();
        allForms.append(frame->findAllElements("form"));
        frames += frame->childFrames();
    }

    foreach(const QWebElement & formElement, allForms) {
        foreach(const QWebElement &inputElement, formElement.findAll("input[type=\"password\"]")) {
            passwordName = inputElement.attribute("name");
            passwordValue = getValueFromData(outgoingData, inputElement);

            if (!passwordValue.isEmpty() && dataContains(outgoingData, passwordName)) {
                foundForm = formElement;
                break;
            }
        }

        if (!foundForm.isNull()) {
            break;
        }
    }
Esempio n. 14
0
void AutoFillModel::completePage(WebPage* page)
{
    if (!page) {
        return;
    }

    QUrl pageUrl = page->url();
    if (!isStored(pageUrl)) {
        return;
    }

    QWebElementCollection inputs;
    QList<QWebFrame*> frames;
    frames.append(page->mainFrame());
    while (!frames.isEmpty()) {
        QWebFrame* frame = frames.takeFirst();
        inputs.append(frame->findAllElements("input"));
        frames += frame->childFrames();
    }

    QString server = pageUrl.host();
    if (server.isEmpty()) {
        server = pageUrl.toString();
    }

    QSqlQuery query;
    query.prepare("SELECT data FROM autofill WHERE server=?");
    query.addBindValue(server);
    query.exec();
    query.next();
    QByteArray data = query.value(0).toByteArray();
    if (data.isEmpty()) {
        return;
    }

    // Why not to use encodedQueryItems = QByteArrays ?
    // Because we need to filter "+" characters that must be spaces
    // (not real "+" characters "%2B")

    QueryItems arguments = QUrl::fromEncoded("http://bla.com/?" + data).queryItems();
    for (int i = 0; i < arguments.count(); i++) {
        QString key = arguments.at(i).first;
        QString value = arguments.at(i).second;
        key.replace("+", " ");
        value.replace("+", " ");

        key = QUrl::fromEncoded(key.toUtf8()).toString();
        value = QUrl::fromEncoded(value.toUtf8()).toString();

        for (int i = 0; i < inputs.count(); i++) {
            QWebElement element = inputs.at(i);

            if (element.attribute("type") != "text" && element.attribute("type") != "password" && element.attribute("type") != "") {
                continue;
            }
            if (key == element.attribute("name")) {
                element.setAttribute("value", value);
            }
        }
    }
}
Esempio n. 15
0
void ClickToFlash::findElement()
{
    if (!m_toolButton) {
        return;
    }

    QWidget* parent = parentWidget();
    QWebView* view = 0;
    while (parent) {
        if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
            view = aView;
            break;
        }
        parent = parent->parentWidget();
    }
    if (!view) {
        return;
    }

    QPoint objectPos = view->mapFromGlobal(m_toolButton->mapToGlobal(m_toolButton->pos()));
    QWebFrame* objectFrame = view->page()->frameAt(objectPos);
    QWebHitTestResult hitResult;
    QWebElement hitElement;

    if (objectFrame) {
        hitResult = objectFrame->hitTestContent(objectPos);
        hitElement = hitResult.element();
    }

    if (!hitElement.isNull() && (hitElement.tagName().compare("embed", Qt::CaseInsensitive) == 0 ||
                                 hitElement.tagName().compare("object", Qt::CaseInsensitive) == 0)) {
        m_element = hitElement;
        return;
    }

    // HitTestResult failed, trying to find element by src
    // attribute in elements at all frames on page (less accurate)

    QList<QWebFrame*> frames;
    frames.append(objectFrame);
    m_mainFrame = view->page()->mainFrame();
    frames.append(m_mainFrame);

    while (!frames.isEmpty()) {
        QWebFrame* frame = frames.takeFirst();
        if (!frame) {
            continue;
        }
        QWebElement docElement = frame->documentElement();

        QWebElementCollection elements;
        elements.append(docElement.findAll(QLatin1String("embed")));
        elements.append(docElement.findAll(QLatin1String("object")));

        foreach(const QWebElement & element, elements) {
            if (!checkElement(element) && !checkUrlOnElement(element)) {
                continue;
            }
            m_element = element;
            return;
        }
        frames += frame->childFrames();
    }
}
Esempio n. 16
0
void WBWebPage::handleUnsupportedContent(QNetworkReply *reply)
{
    if(reply->url().scheme() == "mailto")
    {
        bool result = QDesktopServices::openUrl(reply->url());
        if (result)
            return;
    }

    QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
    bool isPDF = (contentType == "application/pdf");

    // Delete this big "if (isPDF)" block to get the pdf directly inside the browser
    if (isPDF)
    {
        QMessageBox messageBox(mainWindow());
        messageBox.setText(tr("Download PDF Document: would you prefer to download the PDF file or add it to the current Sankore document?"));

        messageBox.addButton(tr("Download"), QMessageBox::AcceptRole);
        QAbstractButton *addButton =
            messageBox.addButton(tr("Add to Current Document"), QMessageBox::AcceptRole);

        messageBox.exec();
        if (messageBox.clickedButton() == addButton)
        {
            UBApplication::applicationController->showBoard();
            UBApplication::boardController->downloadURL(reply->request().url());
            return;
        }
        else
        {
            isPDF = false;
        }
    }

    if (!isPDF && reply->error() == QNetworkReply::NoError)
    {
        if(contentType == "application/widget")
            WBBrowserWindow::downloadManager()->handleUnsupportedContent(reply,false, UBSettings::settings()->uniboardGipLibraryDirectory());
        else
            WBBrowserWindow::downloadManager()->handleUnsupportedContent(reply);
        return;
    }

    QFile file;
    file.setFileName(isPDF ? QLatin1String(":/webbrowser/object-wrapper.html") : QLatin1String(":/webbrowser/notfound.html"));

    bool isOpened = file.open(QIODevice::ReadOnly);
    Q_ASSERT(isOpened);
    QString html;
    if (isPDF)
    {
        html = QString(QLatin1String(file.readAll()))
                        .arg(tr("PDF"))
                        .arg("application/x-ub-pdf")
                        .arg(reply->url().toString());
    }
    else
    {
        QString title = tr("Error loading page: %1").arg(reply->url().toString());
        html = QString(QLatin1String(file.readAll()))
                        .arg(title)
                        .arg(reply->errorString())
                        .arg(reply->url().toString());
    }

    QList<QWebFrame*> frames;
    frames.append(mainFrame());
    while (!frames.isEmpty())
    {
        QWebFrame *frame = frames.takeFirst();
        if (frame->url() == reply->url())
        {
            frame->setHtml(html, reply->url());
            return;
        }
        QList<QWebFrame *> children = frame->childFrames();
        foreach(QWebFrame *frame, children)
            frames.append(frame);
    }

    if (mLoadingUrl == reply->url())
    {
        mainFrame()->setHtml(html, reply->url());
    }
}