Commit 479c06e2 authored by hausmann@webkit.org's avatar hausmann@webkit.org

2008-10-23 Yael Aharon <yael.aharon@nokia.com>

        Reviewed by Simon Hausmann.

        Invalid history entries could cause a crash in QT Webkit

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37843 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 4f3c9aa4
......@@ -85,7 +85,9 @@ QWebHistoryItem::~QWebHistoryItem()
*/
QUrl QWebHistoryItem::originalUrl() const
{
return QUrl(d->item->originalURL().string());
if (d->item)
return QUrl(d->item->originalURL().string());
return QUrl();
}
......@@ -96,7 +98,9 @@ QUrl QWebHistoryItem::originalUrl() const
*/
QUrl QWebHistoryItem::url() const
{
return QUrl(d->item->url().string());
if (d->item)
return QUrl(d->item->url().string());
return QUrl();
}
......@@ -107,7 +111,9 @@ QUrl QWebHistoryItem::url() const
*/
QString QWebHistoryItem::title() const
{
return d->item->title();
if (d->item)
return d->item->title();
return QString();
}
......@@ -119,7 +125,9 @@ QString QWebHistoryItem::title() const
QDateTime QWebHistoryItem::lastVisited() const
{
//FIXME : this will be wrong unless we correctly set lastVisitedTime ourselves
return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
if (d->item)
return QDateTime::fromTime_t((uint)d->item->lastVisitedTime());
return QDateTime();
}
......@@ -130,7 +138,9 @@ QDateTime QWebHistoryItem::lastVisited() const
*/
QIcon QWebHistoryItem::icon() const
{
return *d->item->icon()->nativeImageForCurrentFrame();
if (d->item)
return *d->item->icon()->nativeImageForCurrentFrame();
return QIcon();
}
/*!
......@@ -141,6 +151,15 @@ QWebHistoryItem::QWebHistoryItem(QWebHistoryItemPrivate *priv)
d = priv;
}
/*!
\since 4.5
Returns whether this is a valid history item.
*/
bool QWebHistoryItem::isValid() const
{
return d->item;
}
/*!
\class QWebHistory
\since 4.4
......
......@@ -46,6 +46,8 @@ public:
QIcon icon() const;
bool isValid() const;
private:
QWebHistoryItem(QWebHistoryItemPrivate *priv);
friend class QWebHistory;
......
......@@ -28,14 +28,15 @@ class QWebHistoryItemPrivate : public QSharedData
public:
QWebHistoryItemPrivate(WebCore::HistoryItem *i)
{
i->ref();
if (i)
i->ref();
item = i;
}
~QWebHistoryItemPrivate()
{
item->deref();
if (item)
item->deref();
}
WebCore::HistoryItem *item;
};
......
2008-10-23 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Simon Hausmann.
Invalid history entries could cause a crash in QT Webkit
* Api/qwebhistory.cpp:
(QWebHistoryItem::originalUrl):
(QWebHistoryItem::url):
(QWebHistoryItem::title):
(QWebHistoryItem::lastVisited):
(QWebHistoryItem::icon):
(QWebHistoryItem::isValid):
* Api/qwebhistory.h:
* Api/qwebhistory_p.h:
(QWebHistoryItemPrivate::QWebHistoryItemPrivate):
(QWebHistoryItemPrivate::~QWebHistoryItemPrivate):
* tests/qwebpage/tst_qwebpage.cpp:
(tst_QWebPage::modified):
2008-10-22 Yael Aharon <yael.aharon@nokia.com>
Reviewed by Simon Hausmann.
......
......@@ -294,6 +294,9 @@ void tst_QWebPage::modified()
QVERIFY(m_page->history()->canGoBack());
QVERIFY(!m_page->history()->canGoForward());
QCOMPARE(m_page->history()->count(), 2);
QVERIFY(m_page->history()->backItem().isValid());
QVERIFY(!m_page->history()->forwardItem().isValid());
m_page->history()->back();
QVERIFY(::waitForSignal(m_view, SIGNAL(loadFinished(bool))));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment