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

Unified Diff: src/plugin/PluginTabBase.cpp

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 p.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
Index: src/plugin/PluginTabBase.cpp
===================================================================
--- a/src/plugin/PluginTabBase.cpp
+++ b/src/plugin/PluginTabBase.cpp
@@ -46,9 +46,9 @@
}
catch (const std::system_error& ex)
{
- auto errDescription = std::string("Tab::Thread - Failed to create tab thread") +
- ex.code().message() + ex.what();
- DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREATE_PROCESS, errDescription.c_str());
+ std::wstring errDescription( L"Tab::Thread - Failed to create tab thread" );
+ errDescription += ABP::debug::widen( ex.code().message() + ex.what() );
+ DEBUG_ERROR_LOG( ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THREAD_CREATE_PROCESS, errDescription );
}
#ifdef SUPPORT_DOM_TRAVERSER
@@ -85,16 +85,15 @@
{
void FilterLoader(CPluginTabBase* tabBase)
{
- tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSelectors(tabBase->GetDocumentDomain().GetString()));
+ tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementHidingSelectors(tabBase->GetDocumentDomain()));
SetEvent(tabBase->m_filter->hideFiltersLoadedEvent);
}
}
-void CPluginTabBase::OnNavigate(const CString& url)
+void CPluginTabBase::OnNavigate(const std::wstring & url)
{
SetDocumentUrl(url);
-
#ifdef SUPPORT_FRAME_CACHING
ClearFrameCache(GetDocumentDomain());
#endif
@@ -108,9 +107,9 @@
}
catch (const std::system_error& ex)
{
- auto errDescription = std::string("Class::Thread - Failed to start filter loader thread, ") +
- ex.code().message() + ex.what();
- DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CREATE_PROCESS, errDescription.c_str());
+ std::wstring errDescription( L"Class::Thread - Failed to start filter loader thread, ");
+ errDescription += ABP::debug::widen( ex.code().message() + ex.what() );
+ DEBUG_ERROR_LOG( ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_THREAD_CREATE_PROCESS, errDescription );
}
#ifdef SUPPORT_DOM_TRAVERSER
@@ -118,15 +117,20 @@
#endif
}
+namespace {
+}
+
void CPluginTabBase::InjectABP(IWebBrowser2* browser)
{
CriticalSection::Lock lock(m_csInject);
- CString url = GetDocumentUrl();
- CString log;
- log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsFileUrl().c_str());
- DEBUG_GENERAL(log);
- if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
- 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str()))))
+ std::wstring url = GetDocumentUrl();
+
+ std::wostringstream log;
+ log << L"InjectABP. Current URL: " << url << L", settings URL: " << UserSettingsFileUrl();
+ DEBUG_GENERAL( log.str() );
+
+ if( !ABP::util::wstring_equal_ci( url, UserSettingsFileUrl() )
+ && !ABP::util::wstring_equal_ci( url, FirstRunPageFileUrl() ) )
{
DEBUG_GENERAL(L"Not injecting");
return;
@@ -137,20 +141,20 @@
CComQIPtr<IHTMLDocument2> pDoc2 = pDocDispatch;
if (!pDoc2)
{
- DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI document");
+ DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, L"CPluginTabBase::InjectABP - Failed to QI document");
return;
}
CComPtr<IHTMLWindow2> pWnd2;
pDoc2->get_parentWindow(&pWnd2);
if (!pWnd2)
{
- DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get parent window");
+ DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, L"CPluginTabBase::InjectABP - Failed to get parent window");
return;
}
CComQIPtr<IDispatchEx> pWndEx = pWnd2;
if (!pWndEx)
{
- DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to QI dispatch");
+ DEBUG_ERROR_LOG(0, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, L"CPluginTabBase::InjectABP - Failed to QI dispatch");
return;
}
// Create "Settings" object in JavaScript.
@@ -159,12 +163,15 @@
HRESULT hr = pWndEx->GetDispID(L"Settings", fdexNameEnsure, &dispid);
if (FAILED(hr))
{
- DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to get dispatch");
+ DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, L"CPluginTabBase::InjectABP - Failed to get dispatch");
return;
}
- CComVariant var((IDispatch*)&m_pluginUserSettings);
- DEBUG_GENERAL("Injecting");
+ DEBUG_GENERAL(L"Injecting");
+
+ VARIANT var;
+ var.vt = VT_DISPATCH;
+ var.pdispVal = &m_pluginUserSettings;
DISPPARAMS params;
params.cArgs = 1;
@@ -172,40 +179,40 @@
params.rgvarg = &var;
params.rgdispidNamedArgs = 0;
hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
- DEBUG_GENERAL("Invoke");
+ DEBUG_GENERAL(L"Invoke");
if (FAILED(hr))
{
- DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to create Settings in JavaScript");
+ DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT_INVOKE, L"CPluginTabBase::InjectABP - Failed to create Settings in JavaScript");
}
}
void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
{
#ifdef SUPPORT_DOM_TRAVERSER
- if (!CPluginClient::GetInstance()->IsWhitelistedUrl(std::wstring(GetDocumentUrl())))
+ if (!CPluginClient::GetInstance()->IsWhitelistedUrl(GetDocumentUrl()))
{
- m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl());
+ m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl().c_str());
}
#endif // SUPPORT_DOM_TRAVERSER
InjectABP(browser);
}
-void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& url, bool isDocumentBrowser)
+void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const std::wstring url, bool isDocumentBrowser)
{
- CString documentUrl = GetDocumentUrl();
+ std::wstring documentUrl = GetDocumentUrl();
if (isDocumentBrowser)
{
if (url != documentUrl)
{
- SetDocumentUrl(url);
+ SetDocumentUrl( url );
}
InjectABP(browser);
}
#ifdef SUPPORT_DOM_TRAVERSER
- if (url.Left(6) != "res://")
+ if ( !ABP::util::begins_with( url, L"res://" ) )
{
// Get document
CComPtr<IDispatch> pDocDispatch;
@@ -243,9 +250,9 @@
#endif
}
-CString CPluginTabBase::GetDocumentDomain()
+std::wstring CPluginTabBase::GetDocumentDomain()
{
- CString domain;
+ std::wstring domain;
m_criticalSection.Lock();
{
@@ -256,19 +263,19 @@
return domain;
}
-void CPluginTabBase::SetDocumentUrl(const CString& url)
+void CPluginTabBase::SetDocumentUrl(const std::wstring & url)
{
m_criticalSection.Lock();
{
m_documentUrl = url;
- m_documentDomain = CString(CAdblockPlusClient::GetInstance()->GetHostFromUrl(url.GetString()).c_str());
+ m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url);
}
m_criticalSection.Unlock();
}
-CString CPluginTabBase::GetDocumentUrl()
+std::wstring CPluginTabBase::GetDocumentUrl()
{
- CString url;
+ std::wstring url;
m_criticalSection.Lock();
{
@@ -286,7 +293,7 @@
#ifdef SUPPORT_FRAME_CACHING
-bool CPluginTabBase::IsFrameCached(const CString& url)
+bool CPluginTabBase::IsFrameCached(const std::wstring & url)
{
bool isFrame;
@@ -299,7 +306,7 @@
return isFrame;
}
-void CPluginTabBase::CacheFrame(const CString& url)
+void CPluginTabBase::CacheFrame(const std::wstring & url)
{
m_criticalSectionCache.Lock();
{
@@ -308,11 +315,11 @@
m_criticalSectionCache.Unlock();
}
-void CPluginTabBase::ClearFrameCache(const CString& domain)
+void CPluginTabBase::ClearFrameCache(const std::wstring & domain)
{
m_criticalSectionCache.Lock();
{
- if (domain.IsEmpty() || domain != m_cacheDomain)
+ if (domain.empty() || domain != m_cacheDomain)
{
m_cacheFrames.clear();
m_cacheDomain = domain;
@@ -331,16 +338,15 @@
settings->SetWorkingThreadId();
- CString threadInfo;
- threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
+ std::wostringstream thread_info;
+ thread_info << ::GetCurrentProcessId() << L"." << ::GetCurrentThreadId();
- CString debugText;
-
- debugText += L"================================================================================";
- debugText += L"\nTAB THREAD " + threadInfo;
- debugText += L"\n================================================================================";
-
- DEBUG_GENERAL(debugText)
+ std::wstring t[] = {
+ L"================================================================================",
+ L"TAB THREAD " + thread_info.str(),
+ L"================================================================================",
+ };
+ DEBUG_GENERAL(t);
// --------------------------------------------------------------------
// Tab loop
@@ -352,12 +358,11 @@
while (this->m_continueThreadRunning)
{
#ifdef ENABLE_DEBUG_THREAD
- CStringA sTabLoopIteration;
- sTabLoopIteration.Format("%u", tabLoopIteration);
-
- DEBUG_THREAD("--------------------------------------------------------------------------------")
- DEBUG_THREAD("Loop iteration " + sTabLoopIteration);
- DEBUG_THREAD("--------------------------------------------------------------------------------")
+ std::wostringstream message;
+ message << L"Loop iteration " << tabLoopIteration;
+ DEBUG_THREAD( L"--------------------------------------------------------------------------------" );
+ DEBUG_THREAD( message.str() );
+ DEBUG_THREAD( L"--------------------------------------------------------------------------------" );
#endif
if (this->m_isActivated)
{

Powered by Google App Engine
This is Rietveld