Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/plugin/PluginClass.cpp

Issue 6567422169448448: Issue 119 - Switch to injecting CSS for element hiding (Closed)
Patch Set: rebase and address comments Created April 13, 2015, 8:04 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/plugin/PluginClass.cpp
diff --git a/src/plugin/PluginClass.cpp b/src/plugin/PluginClass.cpp
index 57a8b346d4122e7af9effea02c1bb673e4fca623..139488b8f0a6091140a43aa568b519603eebc69a 100644
--- a/src/plugin/PluginClass.cpp
+++ b/src/plugin/PluginClass.cpp
@@ -30,6 +30,7 @@
#include "PluginUserSettings.h"
#include "../shared/Utils.h"
#include "../shared/Dictionary.h"
+#include "WebBrowserEventsListener.h"
#include "../shared/IE_version.h"
#include <thread>
#include <array>
@@ -90,6 +91,7 @@ namespace AdblockPlus
}
CPluginClass::CPluginClass()
+ : m_data(std::make_shared<Data>())
{
//Use this line to debug memory leaks
// _CrtDumpMemoryLeaks();
@@ -104,17 +106,14 @@ CPluginClass::CPluginClass()
m_isInitializedOk = false;
- m_tab = new CPluginTab(this);
-
+ m_data->tab.reset(new CPluginTab(this));
Dictionary::Create(GetBrowserLanguage());
}
CPluginClass::~CPluginClass()
{
- delete m_tab;
}
-
/////////////////////////////////////////////////////////////////////////////
// Initialization
@@ -127,7 +126,7 @@ void CPluginClass::FinalRelease()
{
s_criticalSectionBrowser.Lock();
{
- m_webBrowser2.Release();
+ m_data.reset();
}
s_criticalSectionBrowser.Unlock();
}
@@ -156,7 +155,7 @@ CComQIPtr<IWebBrowser2> CPluginClass::GetBrowser() const
s_criticalSectionBrowser.Lock();
{
- browser = m_webBrowser2;
+ browser = m_data->webBrowser2;
}
s_criticalSectionBrowser.Unlock();
@@ -192,7 +191,7 @@ std::wstring CPluginClass::GetBrowserUrl() const
}
else
{
- url = m_tab->GetDocumentUrl();
+ url = m_data->tab->GetDocumentUrl();
}
return url;
}
@@ -236,7 +235,7 @@ STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
s_criticalSectionBrowser.Lock();
{
- m_webBrowser2 = unknownSite;
+ m_data->webBrowser2 = ATL::CComQIPtr<IWebBrowser2>(unknownSite);
}
s_criticalSectionBrowser.Unlock();
@@ -331,7 +330,7 @@ STDMETHODIMP CPluginClass::SetSite(IUnknown* unknownSite)
// Release browser interface
s_criticalSectionBrowser.Lock();
{
- m_webBrowser2.Release();
+ m_data->webBrowser2.Release();
}
s_criticalSectionBrowser.Unlock();
@@ -484,7 +483,7 @@ void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
}
std::wstring url(urlVariant->bstrVal, SysStringLen(urlVariant->bstrVal));
UnescapeUrl(url);
-
+ EnsureWebBrowserConnected(webBrowser);
//Register a mime filter if it's not registered yet
if (s_mimeFilter == nullptr)
{
@@ -498,7 +497,7 @@ void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
}
else if (GetBrowser().IsEqualObject(webBrowser))
{
- m_tab->OnNavigate(url);
+ m_data->tab->OnNavigate(url);
DEBUG_GENERAL(
L"================================================================================\n"
L"Begin main navigation url:" + url + L"\n"
@@ -512,7 +511,7 @@ void STDMETHODCALLTYPE CPluginClass::OnBeforeNavigate2(
else
{
DEBUG_NAVI(L"Navi::Begin navigation url:" + url)
- m_tab->CacheFrame(url);
+ m_data->tab->CacheFrame(url);
}
}
catch (...)
@@ -529,29 +528,8 @@ void STDMETHODCALLTYPE CPluginClass::OnDownloadComplete()
ATL::CComPtr<IWebBrowser2> browser = GetBrowser();
if (browser)
{
- m_tab->OnDownloadComplete(browser);
- }
- }
- catch (...)
- {
- }
-}
-
-// Entry point
-void STDMETHODCALLTYPE CPluginClass::OnDocumentComplete(IDispatch* frameBrowserDisp, VARIANT* /*urlOrPidl*/)
-{
- try
- {
- DEBUG_NAVI(L"Navi::Document Complete");
- ATL::CComQIPtr<IWebBrowser2> webBrowser2 = frameBrowserDisp;
- if (!webBrowser2)
- {
- return;
+ m_data->tab->OnDownloadComplete(browser);
}
- std::wstring frameSrc = GetLocationUrl(*webBrowser2);
- UnescapeUrl(frameSrc);
- bool isRootPageBrowser = GetBrowser().IsEqualObject(webBrowser2);
- m_tab->OnDocumentComplete(webBrowser2, frameSrc, isRootPageBrowser);
}
catch (...)
{
@@ -987,7 +965,7 @@ CPluginClass* CPluginClass::FindInstance(HWND hStatusBarWnd)
CPluginTab* CPluginClass::GetTab()
{
- return m_tab;
+ return m_data->tab.get();
}
CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
@@ -999,7 +977,7 @@ CPluginTab* CPluginClass::GetTab(DWORD dwThreadId)
std::map<DWORD,CPluginClass*>::const_iterator it = s_threadInstances.find(dwThreadId);
if (it != s_threadInstances.end())
{
- tab = it->second->m_tab;
+ tab = it->second->m_data->tab.get();
}
}
s_criticalSectionLocal.Unlock();
@@ -1228,7 +1206,7 @@ STDMETHODIMP CPluginClass::Exec(const GUID*, DWORD nCmdID, DWORD, VARIANTARG*, V
}
// Create menu
- HMENU hMenu = CreatePluginMenu(m_tab->GetDocumentUrl());
+ HMENU hMenu = CreatePluginMenu(m_data->tab->GetDocumentUrl());
if (!hMenu)
{
return E_FAIL;
@@ -1626,7 +1604,6 @@ void CPluginClass::UpdateStatusBar()
}
}
-
void CPluginClass::Unadvise()
{
s_criticalSectionLocal.Lock();
@@ -1644,6 +1621,43 @@ void CPluginClass::Unadvise()
s_criticalSectionLocal.Unlock();
}
+void CPluginClass::EnsureWebBrowserConnected(const ATL::CComPtr<IWebBrowser2>& webBrowser)
+{
+ auto it = m_data->connectedWebBrowsersCache.find(webBrowser);
+ if (it != m_data->connectedWebBrowsersCache.end())
+ {
+ return;
+ }
+ ATL::CComObject<WebBrowserEventsListener>* listenerImpl = nullptr;
+ if (FAILED(ATL::CComObject<WebBrowserEventsListener>::CreateInstance(&listenerImpl)))
+ {
+ return;
+ }
+ ATL::CComPtr<IUnknown> listenerRefCounterGuard(listenerImpl->GetUnknown());
+ std::weak_ptr<Data> dataForCapturing = m_data;
+ auto onListenerDestroy = [webBrowser, dataForCapturing]
+ {
+ if (auto data = dataForCapturing.lock())
+ {
+ data->connectedWebBrowsersCache.erase(webBrowser);
+ }
+ };
+ if (FAILED(listenerImpl->Init(webBrowser, onListenerDestroy)))
+ {
+ return;
+ }
+ listenerImpl->reloaded = [webBrowser, dataForCapturing]
+ {
+ if (auto data = dataForCapturing.lock())
+ {
+ auto frameSrc = GetLocationUrl(*webBrowser);
+ UnescapeUrl(frameSrc);
+ data->tab->OnDocumentComplete(webBrowser, frameSrc, data->webBrowser2.IsEqualObject(webBrowser));
+ }
+ };
+ m_data->connectedWebBrowsersCache.emplace(webBrowser, listenerImpl);
+}
+
HICON CPluginClass::GetIcon(int type)
{
HICON icon = NULL;
« no previous file with comments | « src/plugin/PluginClass.h ('k') | src/plugin/PluginFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld