mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 01:22:10 +01:00
AdBlockPlugin: Support unloading plugin
This commit is contained in:
parent
3984beda67
commit
b86b385d98
|
@ -42,16 +42,27 @@ DesktopFile AdBlockPlugin::metaData() const
|
|||
void AdBlockPlugin::init(InitState state, const QString &settingsPath)
|
||||
{
|
||||
Q_UNUSED(settingsPath)
|
||||
Q_ASSERT(state == StartupInitState);
|
||||
|
||||
connect(mApp, &MainApplication::aboutToQuit, AdBlockManager::instance(), &AdBlockManager::save);
|
||||
connect(mApp->plugins(), &PluginProxy::webPageCreated, this, &AdBlockPlugin::webPageCreated);
|
||||
connect(mApp->plugins(), &PluginProxy::webPageDeleted, this, &AdBlockPlugin::webPageDeleted);
|
||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, &AdBlockPlugin::mainWindowCreated);
|
||||
connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, &AdBlockPlugin::mainWindowDeleted);
|
||||
|
||||
if (state == LateInitState) {
|
||||
const auto windows = mApp->windows();
|
||||
for (BrowserWindow *window : windows) {
|
||||
mainWindowCreated(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockPlugin::unload()
|
||||
{
|
||||
const auto windows = mApp->windows();
|
||||
for (BrowserWindow *window : windows) {
|
||||
mainWindowDeleted(window);
|
||||
}
|
||||
}
|
||||
|
||||
bool AdBlockPlugin::testPlugin()
|
||||
|
@ -87,10 +98,19 @@ void AdBlockPlugin::webPageDeleted(WebPage *page)
|
|||
void AdBlockPlugin::mainWindowCreated(BrowserWindow *window)
|
||||
{
|
||||
AdBlockIcon *icon = new AdBlockIcon(window);
|
||||
m_icons[window] = icon;
|
||||
window->statusBar()->addButton(icon);
|
||||
window->navigationBar()->addToolButton(icon);
|
||||
}
|
||||
|
||||
void AdBlockPlugin::mainWindowDeleted(BrowserWindow *window)
|
||||
{
|
||||
AdBlockIcon *icon = m_icons.take(window);
|
||||
window->statusBar()->removeButton(icon);
|
||||
window->navigationBar()->removeToolButton(icon);
|
||||
delete icon;
|
||||
}
|
||||
|
||||
bool AdBlockPlugin::acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame)
|
||||
{
|
||||
Q_UNUSED(type)
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
class WebPage;
|
||||
class BrowserWindow;
|
||||
|
||||
class AdBlockIcon;
|
||||
|
||||
class AdBlockPlugin : public QObject, public PluginInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -39,6 +41,8 @@ private:
|
|||
void webPageCreated(WebPage *page);
|
||||
void webPageDeleted(WebPage *page);
|
||||
void mainWindowCreated(BrowserWindow *window);
|
||||
void mainWindowDeleted(BrowserWindow *window);
|
||||
bool acceptNavigationRequest(WebPage *page, const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override;
|
||||
|
||||
QHash<BrowserWindow*, AdBlockIcon*> m_icons;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user