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

Side by Side Diff: src/plugin/PluginTabBase.cpp

Issue 5948518908821504: Issue #1158 - removed unnecessary definitions and #ifdef/#else/#endif sections (Closed)
Patch Set: Created Aug. 6, 2014, 7:38 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 #include "PluginStdAfx.h" 1 #include "PluginStdAfx.h"
2 2
3 #include "PluginClient.h" 3 #include "PluginClient.h"
4 #include "PluginSettings.h" 4 #include "PluginSettings.h"
5 #ifdef SUPPORT_CONFIG
6 #include "PluginConfig.h"
7 #endif
8 #include "PluginTab.h" 5 #include "PluginTab.h"
9 #include "PluginDomTraverser.h" 6 #include "PluginDomTraverser.h"
10 #include "PluginClass.h" 7 #include "PluginClass.h"
11
12 #include "PluginTabBase.h" 8 #include "PluginTabBase.h"
13 #include "PluginUtil.h" 9 #include "PluginUtil.h"
14 #include <dispex.h> 10 #include <dispex.h>
15 #include <Mshtmhst.h> 11 #include <Mshtmhst.h>
16 12
17 int CPluginTabBase::s_dictionaryVersion = 0; 13 int CPluginTabBase::s_dictionaryVersion = 0;
18 int CPluginTabBase::s_settingsVersion = 1; 14 int CPluginTabBase::s_settingsVersion = 1;
19 #ifdef SUPPORT_FILTER
20 int CPluginTabBase::s_filterVersion = 0; 15 int CPluginTabBase::s_filterVersion = 0;
21 #endif
22 #ifdef SUPPORT_WHITELIST
23 int CPluginTabBase::s_whitelistVersion = 0; 16 int CPluginTabBase::s_whitelistVersion = 0;
24 #endif
25 #ifdef SUPPORT_CONFIG
26 int CPluginTabBase::s_configVersion = 0;
27 #endif
28
29 17
30 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 18 CPluginTabBase::CPluginTabBase(CPluginClass* plugin)
31 : m_plugin(plugin) 19 : m_plugin(plugin)
32 , m_isActivated(false) 20 , m_isActivated(false)
33 , m_continueThreadRunning(true) 21 , m_continueThreadRunning(true)
34 { 22 {
35 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 23 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
36 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 24 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
37 25
38 CPluginClient* client = CPluginClient::GetInstance(); 26 CPluginClient* client = CPluginClient::GetInstance();
39 if (client->GetIEVersion() < 10) 27 if (client->GetIEVersion() < 10)
40 { 28 {
41 m_isActivated = true; 29 m_isActivated = true;
42 } 30 }
43 31
44 try 32 try
45 { 33 {
46 m_thread = std::thread(&CPluginTabBase::ThreadProc, this); 34 m_thread = std::thread(&CPluginTabBase::ThreadProc, this);
47 } 35 }
48 catch (const std::system_error& ex) 36 catch (const std::system_error& ex)
49 { 37 {
50 auto errDescription = std::string("Tab::Thread - Failed to create tab thread ") + 38 auto errDescription = std::string("Tab::Thread - Failed to create tab thread ") +
51 ex.code().message() + ex.what(); 39 ex.code().message() + ex.what();
52 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THR EAD_CREATE_PROCESS, errDescription.c_str()); 40 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THR EAD_CREATE_PROCESS, errDescription.c_str());
53 } 41 }
54
55 #ifdef SUPPORT_DOM_TRAVERSER
Oleksandr 2014/08/18 20:46:04 I would leave this ifdef and others concerning the
Felix Dahlke 2014/09/30 09:33:29 IMHO the traverser code is pretty well isolated fr
Oleksandr 2014/10/02 21:24:02 Good point. Agreed. On 2014/09/30 09:33:29, Felix
56 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); 42 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this));
57 #endif // SUPPORT_DOM_TRAVERSER
58 } 43 }
59 44
60 45
61 CPluginTabBase::~CPluginTabBase() 46 CPluginTabBase::~CPluginTabBase()
62 { 47 {
63 #ifdef SUPPORT_DOM_TRAVERSER
64 delete m_traverser; 48 delete m_traverser;
65 m_traverser = NULL; 49 m_traverser = NULL;
66 #endif // SUPPORT_DOM_TRAVERSER
67
68 m_continueThreadRunning = false; 50 m_continueThreadRunning = false;
69 if (m_thread.joinable()) { 51 if (m_thread.joinable()) {
70 m_thread.join(); 52 m_thread.join();
71 } 53 }
72 } 54 }
73 55
74 void CPluginTabBase::OnActivate() 56 void CPluginTabBase::OnActivate()
75 { 57 {
76 m_isActivated = true; 58 m_isActivated = true;
77 } 59 }
78 60
79 61
80 void CPluginTabBase::OnUpdate() 62 void CPluginTabBase::OnUpdate()
81 { 63 {
82 m_isActivated = true; 64 m_isActivated = true;
83 } 65 }
84 66
85 namespace 67 namespace
86 { 68 {
87 void FilterLoader(CPluginTabBase* tabBase) 69 void FilterLoader(CPluginTabBase* tabBase)
88 { 70 {
89 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH idingSelectors(tabBase->GetDocumentDomain().GetString())); 71 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH idingSelectors(tabBase->GetDocumentDomain().GetString()));
90 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); 72 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent);
91 } 73 }
92 } 74 }
93 75
94 void CPluginTabBase::OnNavigate(const CString& url) 76 void CPluginTabBase::OnNavigate(const CString& url)
95 { 77 {
96 SetDocumentUrl(url); 78 SetDocumentUrl(url);
97
98
99 #ifdef SUPPORT_FRAME_CACHING
100 ClearFrameCache(GetDocumentDomain()); 79 ClearFrameCache(GetDocumentDomain());
101 #endif
102
103 std::wstring domainString = GetDocumentDomain(); 80 std::wstring domainString = GetDocumentDomain();
104 ResetEvent(m_filter->hideFiltersLoadedEvent); 81 ResetEvent(m_filter->hideFiltersLoadedEvent);
105 try 82 try
106 { 83 {
107 std::thread filterLoaderThread(&FilterLoader, this); 84 std::thread filterLoaderThread(&FilterLoader, this);
108 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. 85 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
109 } 86 }
110 catch (const std::system_error& ex) 87 catch (const std::system_error& ex)
111 { 88 {
112 auto errDescription = std::string("Class::Thread - Failed to start filter lo ader thread, ") + 89 auto errDescription = std::string("Class::Thread - Failed to start filter lo ader thread, ") +
113 ex.code().message() + ex.what(); 90 ex.code().message() + ex.what();
114 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, errDescription.c_str()); 91 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, errDescription.c_str());
115 } 92 }
116
117 #ifdef SUPPORT_DOM_TRAVERSER
118 m_traverser->ClearCache(); 93 m_traverser->ClearCache();
119 #endif
120 } 94 }
121 95
122 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 96 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
123 { 97 {
124 CriticalSection::Lock lock(m_csInject); 98 CriticalSection::Lock lock(m_csInject);
125 CString url = GetDocumentUrl(); 99 CString url = GetDocumentUrl();
126 CString log; 100 CString log;
127 log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsF ileUrl().c_str()); 101 log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsF ileUrl().c_str());
128 DEBUG_GENERAL(log); 102 DEBUG_GENERAL(log);
129 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) || 103 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0); 149 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
176 DEBUG_GENERAL("Invoke"); 150 DEBUG_GENERAL("Invoke");
177 if (FAILED(hr)) 151 if (FAILED(hr))
178 { 152 {
179 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to create S ettings in JavaScript"); 153 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_CREATE_SETTINGS_JAVASCRIPT, PLUGIN_ERROR_CR EATE_SETTINGS_JAVASCRIPT_INVOKE, "CPluginTabBase::InjectABP - Failed to create S ettings in JavaScript");
180 } 154 }
181 } 155 }
182 156
183 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) 157 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
184 { 158 {
185 #ifdef SUPPORT_DOM_TRAVERSER
186 if (!CPluginClient::GetInstance()->IsWhitelistedUrl(std::wstring(GetDocumentUr l()))) 159 if (!CPluginClient::GetInstance()->IsWhitelistedUrl(std::wstring(GetDocumentUr l())))
187 { 160 {
188 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); 161 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() );
189 } 162 }
190 #endif // SUPPORT_DOM_TRAVERSER
191
192 InjectABP(browser); 163 InjectABP(browser);
193 } 164 }
194 165
195 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser) 166 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser)
196 { 167 {
197 CString documentUrl = GetDocumentUrl(); 168 CString documentUrl = GetDocumentUrl();
198 169
199 if (isDocumentBrowser) 170 if (isDocumentBrowser)
200 { 171 {
201 if (url != documentUrl) 172 if (url != documentUrl)
202 { 173 {
203 SetDocumentUrl(url); 174 SetDocumentUrl(url);
204 } 175 }
205 InjectABP(browser); 176 InjectABP(browser);
206 } 177 }
207
208 #ifdef SUPPORT_DOM_TRAVERSER
209 if (url.Left(6) != "res://") 178 if (url.Left(6) != "res://")
210 { 179 {
211 // Get document 180 // Get document
212 CComPtr<IDispatch> pDocDispatch; 181 CComPtr<IDispatch> pDocDispatch;
213 HRESULT hr = browser->get_Document(&pDocDispatch); 182 HRESULT hr = browser->get_Document(&pDocDispatch);
214 if (FAILED(hr) || !pDocDispatch) 183 if (FAILED(hr) || !pDocDispatch)
215 { 184 {
216 return; 185 return;
217 } 186 }
218 187
(...skipping 15 matching lines...) Expand all
234 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er); 203 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er);
235 if (docHostUIHandler != NULL) 204 if (docHostUIHandler != NULL)
236 { 205 {
237 docHostUIHandler->UpdateUI(); 206 docHostUIHandler->UpdateUI();
238 } 207 }
239 } 208 }
240 209
241 pDoc.Release(); 210 pDoc.Release();
242 pDocDispatch.Release(); 211 pDocDispatch.Release();
243 } 212 }
244 #endif
245 } 213 }
246 214
247 CString CPluginTabBase::GetDocumentDomain() 215 CString CPluginTabBase::GetDocumentDomain()
248 { 216 {
249 CString domain; 217 CString domain;
250 218
251 m_criticalSection.Lock(); 219 m_criticalSection.Lock();
252 { 220 {
253 domain = m_documentDomain; 221 domain = m_documentDomain;
254 } 222 }
(...skipping 22 matching lines...) Expand all
277 } 245 }
278 m_criticalSection.Unlock(); 246 m_criticalSection.Unlock();
279 247
280 return url; 248 return url;
281 } 249 }
282 250
283 251
284 // ============================================================================ 252 // ============================================================================
285 // Frame caching 253 // Frame caching
286 // ============================================================================ 254 // ============================================================================
287
288 #ifdef SUPPORT_FRAME_CACHING
289
290 bool CPluginTabBase::IsFrameCached(const CString& url) 255 bool CPluginTabBase::IsFrameCached(const CString& url)
291 { 256 {
292 bool isFrame; 257 bool isFrame;
293 258
294 m_criticalSectionCache.Lock(); 259 m_criticalSectionCache.Lock();
295 { 260 {
296 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); 261 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end();
297 } 262 }
298 m_criticalSectionCache.Unlock(); 263 m_criticalSectionCache.Unlock();
299 264
(...skipping 15 matching lines...) Expand all
315 { 280 {
316 if (domain.IsEmpty() || domain != m_cacheDomain) 281 if (domain.IsEmpty() || domain != m_cacheDomain)
317 { 282 {
318 m_cacheFrames.clear(); 283 m_cacheFrames.clear();
319 m_cacheDomain = domain; 284 m_cacheDomain = domain;
320 } 285 }
321 } 286 }
322 m_criticalSectionCache.Unlock(); 287 m_criticalSectionCache.Unlock();
323 } 288 }
324 289
325 #endif // SUPPORT_FRAME_CACHING
326
327
328 void CPluginTabBase::ThreadProc() 290 void CPluginTabBase::ThreadProc()
329 { 291 {
330 // Force loading/creation of settings 292 // Force loading/creation of settings
331 CPluginSettings* settings = CPluginSettings::GetInstance(); 293 CPluginSettings* settings = CPluginSettings::GetInstance();
332 294
333 settings->SetWorkingThreadId(); 295 settings->SetWorkingThreadId();
334 296
335 CString threadInfo; 297 CString threadInfo;
336 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId()); 298 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
337 299
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError. GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr ue, pluginError.GetProcessId(), pluginError.GetThreadId()); 348 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError. GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr ue, pluginError.GetProcessId(), pluginError.GetThreadId());
387 } 349 }
388 350
389 // Non-hanging sleep 351 // Non-hanging sleep
390 Sleep(50); 352 Sleep(50);
391 } 353 }
392 354
393 tabLoopIteration++; 355 tabLoopIteration++;
394 } 356 }
395 } 357 }
OLDNEW

Powered by Google App Engine
This is Rietveld