//void ArestShopPlugin::SinglePageFound()
//{
//#ifdef USE_WEBKIT
//	QWebFrame * ptrFrame = getWebPage()->mainFrame();
//	parseProductPage(m_stCompData);
//	m_stCompData.strCompURL = ptrFrame->url().toString();
//	emit priceSearchedFinished(m_stCompData);
//	productFoundFinish();
//#endif
//};
void ArestShopPlugin::parseSearchProductPage(SearchResult & stResult,bool & bNextPage)
{
	//run XML search page parse

	bNextPage=false;
#ifdef USE_WEBKIT
	QWebFrame * ptrFrame = getWebPage()->mainFrame();
	//////////////////////////////////////////////////////////////////////////
	QWebElementCollection tableProdRows = ptrFrame->findAllElements("table[class=pricelist]");
	
	for(int iIndex=0;iIndex<tableProdRows.count();++iIndex)
	{
		QWebElement prodNameHeader = tableProdRows.at(iIndex).findFirst("td[class=nazwa]");
		if (prodNameHeader.isNull())
			continue;
		QWebElement productLink = prodNameHeader.findFirst("a");
		QUrl stProductURL = productLink.attribute("href");
		//////////////////////////////////////////////////////////////////////////
		QString strName = productLink.toPlainText();
		stResult.insert(std::make_pair(strName,stProductURL));
	}
	//////////////////////////////////////////////////////////////////////////
	QWebElement tablePageNavi = ptrFrame->findFirstElement("li[class=next]");
	if (tablePageNavi.isNull())
	{
		bNextPage=false;
		return;
	}
	bNextPage=true;
#endif
	stResult.insert(Arest::mSearchResult.begin(),Arest::mSearchResult.end());
	bNextPage=m_bLoadNextPage;
}
示例#2
0
void AuthenticationDialog::loadFinished()
{
//     Q_D(AuthenticationDialog);
    QUrl url = d->webView->url();

    if (url.host() == "www.facebook.com" && url.path() == "/login.php") {
        if (d->username.isEmpty() && d->password.isEmpty()) {
            return;
        }

        QWebFrame *frame = d->webView->page()->mainFrame();
        if (!d->username.isEmpty()) {
            QWebElement email = frame->findFirstElement("input#email");
            if (!email.isNull()) {
                email.setAttribute("value", d->username);
            }
        }

        if (!d->password.isEmpty()) {
            QWebElement passd = frame->findFirstElement("input#pass");
            if (!passd.isNull()) {
                passd.setAttribute("value", d->password);
            }
        }
        return;
    }
}
示例#3
0
void WebPage::handleUnsupportedContent(QNetworkReply* reply)
{
    if (!reply) {
        return;
    }

    const QUrl url = reply->url();

    switch (reply->error()) {
    case QNetworkReply::NoError:
        if (reply->header(QNetworkRequest::ContentTypeHeader).isValid()) {
            QString requestUrl = reply->request().url().toString(QUrl::RemoveFragment | QUrl::RemoveQuery);
            if (requestUrl.endsWith(QLatin1String(".swf"))) {
                const QWebElement docElement = mainFrame()->documentElement();
                const QWebElement object = docElement.findFirst(QString("object[src=\"%1\"]").arg(requestUrl));
                const QWebElement embed = docElement.findFirst(QString("embed[src=\"%1\"]").arg(requestUrl));

                if (!object.isNull() || !embed.isNull()) {
                    qDebug() << "WebPage::UnsupportedContent" << url << "Attempt to download flash object on site!";
                    reply->deleteLater();
                    return;
                }
            }
            DownloadManager* dManager = mApp->downloadManager();
            dManager->handleUnsupportedContent(reply, this);
            return;
        }
        // Falling unsupported content with invalid ContentTypeHeader to be handled as UnknownProtocol

    case QNetworkReply::ProtocolUnknownError: {
        if (url.scheme() == QLatin1String("file")) {
            FileSchemeHandler::handleUrl(url);
            return;
        }

        qDebug() << "WebPage::UnsupportedContent" << url << "ProtocolUnknowError";
        desktopServicesOpen(url);

        reply->deleteLater();
        return;
    }
    default:
        break;
    }

    qDebug() << "WebPage::UnsupportedContent error" << url << reply->errorString();
    reply->deleteLater();
}
示例#4
0
void MainWindow::finished_loading(bool ok)
{
	if(!ok)
std::cout << "LOAD FINISH NOT OK!\n\n";
	QString output;
	QWebElement body;
	progress = 100;
	adjust_title();
	QWebFrame *frame = uimw->webView->page()->mainFrame();
	QWebElement document = frame->documentElement();
	QWebElement element = document.firstChild();
	while(!element.isNull())
	{
		if(element.tagName() == "BODY")
		{
			output = element.toInnerXml();
			if(output == "ok\n")
			{
				QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar();
				QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth);
				for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ )
				{
					std::cout << "Set-Cookie: ";
					QByteArray ba = i->toRawForm();
					std::cout.write(ba.data(), ba.count());
					std::cout << "\r\n";
				}
				exit(0);
			}
		}
		element = element.nextSibling();
	}
	this->show();
}
示例#5
0
			void KinotifyWidget::mousePressEvent (QMouseEvent *event)
			{
				const QWebHitTestResult& r = page ()->mainFrame ()->hitTestContent (event->pos ());
				if (!r.linkUrl ().isEmpty ())
				{
					QWebView::mousePressEvent (event);
					return;
				}

				QWebElement elem = r.element ();
				if (elem.isNull () || elem.attribute ("type") != "button")
				{
					disconnect (CheckTimer_,
							SIGNAL (timeout ()),
							this,
							SIGNAL (checkNotificationQueue ()));

					disconnect (&Machine_,
							SIGNAL (finished ()),
							this,
							SLOT (closeNotification ()));

					emit checkNotificationQueue ();
					closeNotification ();
				}
				else
					QWebView::mousePressEvent (event);
			}
示例#6
0
void QtWebKitWebPage::updateBlockedPageElements(const QStringList domainList, const bool isException)
{
	for (int i = 0; i < domainList.count(); ++i)
	{
		const QList<QString> exceptionList = isException ? ContentBlockingManager::getHidingRulesExceptions().values(domainList.at(i)) : ContentBlockingManager::getSpecificDomainHidingRules().values(domainList.at(i));

		for (int j = 0; j < exceptionList.count(); ++j)
		{
			const QWebElementCollection elements = mainFrame()->documentElement().findAll(exceptionList.at(j));

			for (int k = 0; k < elements.count(); ++k)
			{
				QWebElement element = elements.at(k);

				if (element.isNull())
				{
					continue;
				}

				if (isException)
				{
					element.setStyleProperty(QLatin1String("display"), QLatin1String("block"));
				}
				else
				{
					element.removeFromDocument();
				}
			}
		}
	}
}
示例#7
0
int PhpWebView::click2(QWebElement elem, bool samewnd)
{
	if (elem.isNull())
		return 0;

	if (samewnd)
		elem.removeAttribute("target");

	QEventLoop loop;
	isNewViewCreated = false;
	isNewViewBegin = false;
	
	QString js = "var e = document.createEvent('MouseEvents');";
	//js += "e.initEvent( 'click', true, true );";
    js += "e.initMouseEvent( 'click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);";
    js += "this.dispatchEvent(e);";
	elem.evaluateJavaScript(js);
	
	QTimer::singleShot(1000, &loop, SLOT(quit()));
	loop.exec();
	
	while (browser && isNewViewBegin && !isNewViewCreated)
		loop.processEvents();

	return 1;
}
void GoogleChat::loginPage(bool ok) {
    QString location = form.webView->url().toString();
    if (!ok) {
        if (location.indexOf("CheckCookie"))
            return;
        showError("Service unavailable");
    } else {
        // check for any error message

        QWebElement  e = document().findFirst(".errormsg");
        if (e.isNull()) {
            form.stackedWidget->setCurrentIndex(2);
            QTimer::singleShot(500, this, SLOT(hideElements()));
            return;
        }

       QString err = "Unknown login failure.";
       const QString errorMessage = e.toPlainText();
        if (!errorMessage.isEmpty()) {
            err = errorMessage;
            err = err.simplified();
        }
        showError(err);
    }
}
示例#9
0
/*!
    Encloses this element with \a element. This element becomes the child of
    the deepest descendant within \a element.

    \sa replace()
*/
void QWebElement::encloseWith(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    RefPtr<Node> insertionPoint = findInsertionPoint(element.m_element);

    if (!insertionPoint)
        return;

    // Keep reference to these two nodes before pulling out this element and
    // wrapping it in the fragment. The reason for doing it in this order is
    // that once the fragment has been added to the document it is empty, so
    // we no longer have access to the nodes it contained.
    Node* parentNode = m_element->parent();
    Node* siblingNode = m_element->nextSibling();

    ExceptionCode exception = 0;
    insertionPoint->appendChild(m_element, exception);

    if (!siblingNode)
        parentNode->appendChild(element.m_element, exception);
    else
        parentNode->insertBefore(element.m_element, siblingNode, exception);
}
示例#10
0
bool Page_Login::doLogin (
        int servNo,
        const QString& login,
        const QString& password,
        bool keep) {
    Q_ASSERT(!document.isNull());
    QWebElement form = document.findFirst("FORM[id=loginForm]");
    if (form.isNull()) {
        qCritical("login form not found");
        return false;
    }
    //QWebElement
    submit = form.findFirst("INPUT[type=submit]");
    if (submit.isNull()) {
        qCritical("submit button not found");
        return false;
    }

    js_setById("server", servNo);
    js_setByName("email", login);
    js_setByName("password", password);
    if (keep) {
        js("document.getElementsByName('remember')[0].checked=true;");
    }
    qDebug("press login button");
    pressSubmit();
    return true;
}
StationScheduleItem parseResult(const QWebElement &result)
{
    StationScheduleItem item;

    QWebElement current = result.findFirst("h2");
    if (!current.isNull()) {
        item.setTrain(current.toPlainText());
    }
    parseDetailsUrl(result, item);
    current = result.findFirst("div.bloccotreno");
    parseDelayClass(current, item);
    QString rawText = current.toPlainText();
    parseTrain(rawText, item);

    qDebug() << "train:" << item.train();
    qDebug() << "delayClass:" << item.delayClass();
    qDebug() << "detailsUrl:" << item.detailsUrl();
    qDebug() << "departureStation:" << item.departureStation();
    qDebug() << "departureTime:" << item.departureTime();
    qDebug() << "arrivalStation:" << item.arrivalStation();
    qDebug() << "arrivalTime:" << item.arrivalTime();
    qDebug() << "expectedPlatform:" << item.expectedPlatform();
    qDebug() << "actualPlatform:" << item.actualPlatform();
    qDebug() << "delay:" << item.delay();
    return item;
}
示例#12
0
bool MainWindow::disableSelection()
{
    if (mainSettings->value("view/disable_selection").toBool()) {
        qDebug("Try to disable text selection...");

        // Then webkit loads page and it's "empty" - empty html DOM loaded...
        // So we wait before real page DOM loaded...
        QWebElement bodyElem = view->page()->mainFrame()->findFirstElement("body");
        if (!bodyElem.isNull() && !bodyElem.toInnerXml().trimmed().isEmpty()) {
            QWebElement headElem = view->page()->mainFrame()->findFirstElement("head");
            if (headElem.isNull() || headElem.toInnerXml().trimmed().isEmpty()) {
                qDebug("... html head not loaded ... wait...");
                return false;
            }

            //qDebug() << "... head element content:\n" << headElem.toInnerXml();

            // http://stackoverflow.com/a/5313735
            QString content;
            content = "<style type=\"text/css\">\n";
            content += "body, div, p, span, h1, h2, h3, h4, h5, h6, caption, td, li, dt, dd {\n";
            content += " -moz-user-select: none;\n";
            content += " -khtml-user-select: none;\n";
            content += " -webkit-user-select: none;\n";
            content += " user-select: none;\n";
            content += " }\n";
            content += "</style>\n";

            // Ugly hack, but it's works...
            if (!headElem.toInnerXml().contains(content)) {
                headElem.setInnerXml(headElem.toInnerXml() + content);
                qDebug("... html head loaded ... hack inserted...");
            } else {
                qDebug("... html head loaded ... hack already inserted...");
            }

            //headElem = view->page()->mainFrame()->findFirstElement("head");
            //qDebug() << "... head element content after:\n" << headElem.toInnerXml() ;

        } else {
            qDebug("... html body not loaded ... wait...");
            return false;
        }
    }

    return true;
}
示例#13
0
void HtmlExtractor::move(QWebElement &element, const QString &file, bool outer)
{
    if(!element.isNull())
    {
        WriteFile(file, outer?element.toOuterXml():element.toInnerXml());
        element.removeFromDocument();
    }
}
示例#14
0
文件: Page.cpp 项目: stereos/Webocado
//#####################################################################
// Function setDOMNodes
//#####################################################################
void Page::setDOMNodes(const QWebElement& domNode) {
    QWebElement domChild = domNode.firstChild();
    while (!domChild.isNull()) {
        setDOMNodes(domChild);
        domChild = domChild.nextSibling();
    }
    mDOMNodes.append(domNode);
}
示例#15
0
/*!
    Appends the given \a element as the element's last child.

    If \a element is the child of another element, it is re-parented to this
    element. If \a element is a child of this element, then its position in
    the list of children is changed.

    Calling this function on a null element does nothing.

    \sa prependInside(), prependOutside(), appendOutside()
*/
void QWebElement::appendInside(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    ExceptionCode exception = 0;
    m_element->appendChild(element.m_element, exception);
}
示例#16
0
/*!
    Replaces this element with \a element.

    This method will not replace the <html>, <head> or <body> elements.

    \sa encloseWith()
*/
void QWebElement::replace(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    appendOutside(element);
    takeFromDocument();
}
示例#17
0
QTreeWidgetItem* XPathInspector::createTree(QWebElement root)
{
	QString js = "var arr = []; ";
    js +=        "for (var i=0; i<this.childNodes.length; i++) ";
    js +=        "   if (this.childNodes[i].nodeType == 3 && this.childNodes[i].nodeValue.replace(/^\\s+|\\s+$/g,'') != '') ";
    js +=        "      arr.push(this.childNodes[i].nodeValue); ";
	js +=        "   else if (this.childNodes[i].nodeType == 1)";
	js +=        "      arr.push(this.childNodes[i].tagName); ";
    js +=        "arr; ";
	QVariant v = root.evaluateJavaScript(js);
	QStringList nodes = v.toStringList();

	QWebElement child = root.firstChild();
	QList<QTreeWidgetItem*> list;
	int i = 0;
	while (!(i>=nodes.count() && child.isNull()))
	{
		while (i<nodes.count() && nodes.at(i) != child.tagName())
		{
			QTreeWidgetItem *item2 = new QTreeWidgetItem();
			item2->setText(0, nodes.at(i));
			list.append(item2);
			i++;
		}
		if (!child.isNull())
		{
			list.append(createTree(child));
			child = child.nextSibling();
			i++;
		}
	}

	QString text = "<"+root.tagName().toLower();
	QStringList attrs = root.attributeNames();
	for (int i=0; i<attrs.count(); i++)
		text += " "+attrs.at(i)+"=\""+root.attribute(attrs.at(i))+"\"";
	text += ">";
	
	QTreeWidgetItem *item = new QTreeWidgetItem();
	item->setText(0, text);
	QVariant v2(QVariant::UserType);
	v2.setValue<QWebElement>(root);
	item->setData(0, Qt::UserRole, v2);
	item->addChildren(list);
	return item;
}
static void parseDetailsUrl(const QWebElement &element, StationScheduleItem &item)
{
    if (!element.isNull()) {
        QWebElement link = element.findFirst("a");
        QString url = link.attribute("href");
        item.setDetailsUrl(url);
    } else {
        qDebug() << "link not found";
    }
}
示例#19
0
/*!
    Inserts the given \a element before this element.

    If \a element is the child of another element, it is re-parented to the
    parent of this element.

    Calling this function on a null element does nothing.

    \sa appendInside(), prependInside(), appendOutside()
*/
void QWebElement::prependOutside(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    if (!m_element->parent())
        return;

    ExceptionCode exception = 0;
    m_element->parent()->insertBefore(element.m_element, m_element, exception);
}
void GoogleChat::initialPage(bool ok) {
    if (!QSslSocket::supportsSsl()) {
        showError("This example requires SSL support.");
        return;
    }

    if (ok) {
        QWebElement email = document().findFirst("#Email");
        QWebElement passwd = document().findFirst("#Passwd");
        QWebElement loginForm = document().findFirst("#gaia_loginform");
        if (!email.isNull() && !passwd.isNull() && !loginForm.isNull()) {
            form.stackedWidget->setCurrentIndex(1);
            form.userNameEdit->setFocus();
            form.webView->disconnect();
            return;
        }
    }

    showError("SERVICE unavailable.");
}
示例#21
0
void MainWindow::attachStyles()
{
    if (!mainSettings->contains("attach/styles")) {
        return;
    }
    QStringList styles = mainSettings->value("attach/styles").toStringList();
    if (!styles.length()) {
        return;
    }

    QWebElement headElem = view->page()->mainFrame()->findFirstElement("head");
    QString content = "";
    if (headElem.isNull() || headElem.toInnerXml().trimmed().isEmpty()) {
        // Page without head... We need something in <head> to interact with?
        return;
    }

    QStringListIterator stylesIterator(styles);
    QString file_name;
    QFileInfo finfo = QFileInfo();
    quint32 countStyles = 0;

    while (stylesIterator.hasNext()) {
        file_name = stylesIterator.next();

        if (!file_name.trimmed().length()) continue;

        qDebug() << "-- attach " << file_name;
        countStyles++;

        finfo.setFile(file_name);

        if (finfo.isFile()) {
            qDebug("-- it's local file");
            QFile f(file_name);
            content += "\n<style type=\"text/css\">\n";
            content += QString(f.readAll());
            content += "</style>\n";
            f.close();
        } else {
            qDebug("-- it's remote file");
            content += "\n<link type=\"text/css\" rel=\"stylesheet\" href=\"";
            content += file_name;
            content += "\"/>\n";
        }
    }

    if (countStyles > 0 && content.trimmed().length() > 0) {
        headElem.setInnerXml(headElem.toInnerXml() + content);

        qDebug() << "Page loaded, found " << countStyles << " user style files...";
    }
}
示例#22
0
/*!
    Prepends \a element as the element's first child.

    If \a element is the child of another element, it is re-parented to this
    element. If \a element is a child of this element, then its position in
    the list of children is changed.

    Calling this function on a null element does nothing.

    \sa appendInside(), prependOutside(), appendOutside()
*/
void QWebElement::prependInside(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    ExceptionCode exception = 0;

    if (m_element->hasChildNodes())
        m_element->insertBefore(element.m_element, m_element->firstChild(), exception);
    else
        m_element->appendChild(element.m_element, exception);
}
static void parseDelayClass(const QWebElement &element, StationScheduleItem &item)
{
    if (!element.isNull()) {
        QWebElement image = element.findFirst("img");
        if (!image.isNull()) {
            int delayClass = 42;
            QString imageName = image.attribute("src");
            if (!imageName.isEmpty()) {
                QRegExp delayClassRegexp("pallinoRit([0-9])\\.png");
                int pos = delayClassRegexp.indexIn(imageName);
                qDebug() << "regexp matched at pos:" << pos << "match:" << delayClassRegexp.cap(0);
                delayClass =  (pos >= 0) ? delayClassRegexp.cap(1).toInt() : 0;
            }
            item.setDelayClass(delayClass);
        } else {
            qDebug() << "img not found";
        }
    } else {
        qDebug() << "div.bloccotreno not found";
    }
}
示例#24
0
void MainWindow::attachJavascripts()
{
    if (!mainSettings->contains("attach/javascripts")) {
        return;
    }
    QStringList scripts = mainSettings->value("attach/javascripts").toStringList();
    if (!scripts.length()) {
        return;
    }

    QWebElement bodyElem = view->page()->mainFrame()->findFirstElement("body");
    QString content = "";
    if (bodyElem.isNull() || bodyElem.toInnerXml().trimmed().isEmpty()) {
        // No body here... We need something in <body> to interact with?
        return;
    }

    QStringListIterator scriptsIterator(scripts);
    QFileInfo finfo = QFileInfo();
    QString file_name;
    quint32 countScripts = 0;

    while (scriptsIterator.hasNext()) {
        file_name = scriptsIterator.next();

        if (!file_name.trimmed().length()) continue;

        qDebug() << "-- attach " << file_name;

        countScripts++;

        finfo.setFile(file_name);
        if (finfo.isFile()) {
            qDebug("-- it's local file");
            QFile f(file_name);
            content += "\n<script type=\"text/javascript\">";
            content += QString(f.readAll());
            content += "</script>\n";
            f.close();
        } else {
            qDebug("-- it's remote file");
            content += "\n<script type=\"text/javascript\" src=\"";
            content += file_name;
            content += "\"></script>\n";
        }
    }
    if (countScripts > 0 && content.trimmed().length() > 0) {
        bodyElem.setInnerXml(bodyElem.toInnerXml() + content);

        qDebug() << "Page loaded, found " << countScripts << " user javascript files...";
    }
}
QRectF WebContentAnimationItem::findZoomableRectForPoint(const QPointF& point)
{
    QPointF zoomPoint = m_webView->mapFromParent(point);

    QWebHitTestResult hitResult = m_webView->page()->mainFrame()->hitTestContent(zoomPoint.toPoint());
    QWebElement targetElement = hitResult.enclosingBlockElement();

    while (!targetElement.isNull() && targetElement.geometry().width() < MinDoubleClickZoomTargetWidth)
        targetElement = targetElement.parent();

    if (!targetElement.isNull()) {
        QRectF elementRect = targetElement.geometry();
        qreal overMinWidth = elementRect.width() - ZoomableContentMinWidth;
        if (overMinWidth < 0)
            elementRect.adjust(overMinWidth / 2, 0, -overMinWidth / 2, 0);
        zoomPoint.setX(elementRect.x());
        QRectF resultRect(zoomPoint, elementRect.size());
        return QRectF(m_webView->mapToParent(resultRect.topLeft()),
                      m_webView->mapToParent(resultRect.bottomRight()));
    }
    return QRectF();
}
示例#26
0
void MyWebView::on_HighlightTreeSelectedElem(QString name)
{
	if (!m_boolEnableEvtProcess) { return; }
    QWebElement welemTemp = page()->mainFrame()->documentElement();
    QWebElement webelem = FindElementByName(welemTemp, name);
	
	if (webelem.isNull())
	{
		qDebug() << "[ERROR] Invalid QWebElement in MyWebView::on_HighlightTreeSelectedElem.";
		return;
	}
	ChangeClickedElemColor(webelem);
}
示例#27
0
QWebElement MyWebView::FindElementByName(QWebElement &elem, QString &name)
{
	if (elem.attribute("id").compare(name, Qt::CaseInsensitive) == 0)
	{
		return elem;
	}
	else
	{
		QWebElement childelem = elem.firstChild();
		QWebElement retelem;
		while (!childelem.isNull())
		{
			retelem = FindElementByName(childelem, name);
			if (!retelem.isNull())
			{
				return retelem;
			}
			childelem = childelem.nextSibling();
		}
	}
	return QWebElement();
}
void MarbleLegendBrowser::setCheckedProperty( const QString& name, bool checked )
{
#ifndef MARBLE_NO_WEBKIT
    QWebElement box = page()->mainFrame()->findFirstElement("input[name="+name+']');
    if (!box.isNull()) {
        if (checked != d->m_checkBoxMap[name]) {
            d->m_checkBoxMap[name] = checked;
            emit toggledShowProperty( name, checked );
        }
    }

    update();
#endif
}
示例#29
0
/*!
    Inserts the given \a element after this element.

    If \a element is the child of another element, it is re-parented to the
    parent of this element.

    Calling this function on a null element does nothing.

    \sa appendInside(), prependInside(), prependOutside()
*/
void QWebElement::appendOutside(const QWebElement &element)
{
    if (!m_element || element.isNull())
        return;

    if (!m_element->parent())
        return;

    ExceptionCode exception = 0;
    if (!m_element->nextSibling())
        m_element->parent()->appendChild(element.m_element, exception);
    else
        m_element->parent()->insertBefore(element.m_element, m_element->nextSibling(), exception);
}
示例#30
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();
  }
}