1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

RecoveryJsObject: Use safer method to get BrowserWindow from WebPage

This commit is contained in:
David Rosca 2015-09-24 23:08:55 +02:00
parent fc85caff57
commit a9d0e79eeb
2 changed files with 21 additions and 3 deletions

View File

@ -38,14 +38,29 @@ void RecoveryJsObject::setPage(WebPage *page)
void RecoveryJsObject::startNewSession() void RecoveryJsObject::startNewSession()
{ {
m_page->load(static_cast<TabbedWebView*>(m_page->view())->browserWindow()->homepageUrl()); BrowserWindow *window = getBrowserWindow();
if (!window)
return;
m_page->load(window->homepageUrl());
mApp->destroyRestoreManager(); mApp->destroyRestoreManager();
} }
void RecoveryJsObject::restoreSession() void RecoveryJsObject::restoreSession()
{ {
if (!mApp->restoreSession(static_cast<TabbedWebView*>(m_page->view())->browserWindow() , m_manager->restoreData())) { BrowserWindow *window = getBrowserWindow();
if (!window)
return;
bool ok = mApp->restoreSession(window , m_manager->restoreData());
if (!ok)
startNewSession(); startNewSession();
} }
BrowserWindow *RecoveryJsObject::getBrowserWindow() const
{
TabbedWebView *view = qobject_cast<TabbedWebView*>(m_page->view());
return view ? view->browserWindow() : Q_NULLPTR;
} }

View File

@ -22,6 +22,7 @@
#include <QObject> #include <QObject>
class WebPage; class WebPage;
class BrowserWindow;
class RestoreManager; class RestoreManager;
class RecoveryJsObject : public QObject class RecoveryJsObject : public QObject
@ -37,6 +38,8 @@ public slots:
void restoreSession(); void restoreSession();
private: private:
BrowserWindow *getBrowserWindow() const;
RestoreManager *m_manager; RestoreManager *m_manager;
WebPage *m_page; WebPage *m_page;
}; };