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

Delta Between Two Patch Sets: src/plugin/PluginTabBase.cpp

Issue 5171515343503360: Issue #41 - Bring method of determining IE version up to date (Closed)
Left Patch Set: reformatted Created July 26, 2014, 3:52 p.m.
Right Patch Set: Final (?) 2 Created Jan. 5, 2015, 1:02 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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 "AdblockPlusDomTraverser.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 "../shared/IE_version.h" 10 #include "../shared/IE_version.h"
15 #include <dispex.h> 11 #include <dispex.h>
16 #include <Mshtmhst.h> 12 #include <Mshtmhst.h>
17 13
18 int CPluginTabBase::s_dictionaryVersion = 0; 14 int CPluginTabBase::s_dictionaryVersion = 0;
19 int CPluginTabBase::s_settingsVersion = 1; 15 int CPluginTabBase::s_settingsVersion = 1;
20 #ifdef SUPPORT_FILTER
21 int CPluginTabBase::s_filterVersion = 0; 16 int CPluginTabBase::s_filterVersion = 0;
22 #endif
23 #ifdef SUPPORT_WHITELIST
24 int CPluginTabBase::s_whitelistVersion = 0; 17 int CPluginTabBase::s_whitelistVersion = 0;
25 #endif
26 #ifdef SUPPORT_CONFIG
27 int CPluginTabBase::s_configVersion = 0;
28 #endif
29
30 18
31 CPluginTabBase::CPluginTabBase(CPluginClass* plugin) 19 CPluginTabBase::CPluginTabBase(CPluginClass* plugin)
32 : m_plugin(plugin) 20 : m_plugin(plugin)
33 , m_isActivated(false) 21 , m_isActivated(false)
34 , m_continueThreadRunning(true) 22 , m_continueThreadRunning(true)
35 { 23 {
36 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); 24 m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter());
37 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL); 25 m_filter->hideFiltersLoadedEvent = CreateEvent(NULL, true, false, NULL);
38 26
39 CPluginClient* client = CPluginClient::GetInstance(); 27 CPluginClient* client = CPluginClient::GetInstance();
40 if (AdblockPlus::IE::installed_major_version() < 10) 28 if (AdblockPlus::IE::InstalledMajorVersion() < 10)
41 { 29 {
42 m_isActivated = true; 30 m_isActivated = true;
43 } 31 }
44 32
45 try 33 try
46 { 34 {
47 m_thread = std::thread(&CPluginTabBase::ThreadProc, this); 35 m_thread = std::thread(&CPluginTabBase::ThreadProc, this);
48 } 36 }
49 catch (const std::system_error& ex) 37 catch (const std::system_error& ex)
50 { 38 {
51 auto errDescription = std::string("Tab::Thread - Failed to create tab thread ") + 39 auto errDescription = std::string("Tab::Thread - Failed to create tab thread ") +
52 ex.code().message() + ex.what(); 40 ex.code().message() + ex.what();
53 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THR EAD_CREATE_PROCESS, errDescription.c_str()); 41 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_TAB_THR EAD_CREATE_PROCESS, errDescription.c_str());
54 } 42 }
55
56 #ifdef SUPPORT_DOM_TRAVERSER
57 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this)); 43 m_traverser = new CPluginDomTraverser(static_cast<CPluginTab*>(this));
58 #endif // SUPPORT_DOM_TRAVERSER
59 } 44 }
60 45
61 46
62 CPluginTabBase::~CPluginTabBase() 47 CPluginTabBase::~CPluginTabBase()
63 { 48 {
64 #ifdef SUPPORT_DOM_TRAVERSER
65 delete m_traverser; 49 delete m_traverser;
66 m_traverser = NULL; 50 m_traverser = NULL;
67 #endif // SUPPORT_DOM_TRAVERSER
68
69 m_continueThreadRunning = false; 51 m_continueThreadRunning = false;
70 if (m_thread.joinable()) { 52 if (m_thread.joinable()) {
71 m_thread.join(); 53 m_thread.join();
72 } 54 }
73 } 55 }
74 56
75 void CPluginTabBase::OnActivate() 57 void CPluginTabBase::OnActivate()
76 { 58 {
77 m_isActivated = true; 59 m_isActivated = true;
78 } 60 }
79 61
80 62
81 void CPluginTabBase::OnUpdate() 63 void CPluginTabBase::OnUpdate()
82 { 64 {
83 m_isActivated = true; 65 m_isActivated = true;
84 } 66 }
85 67
86 namespace 68 namespace
87 { 69 {
88 void FilterLoader(CPluginTabBase* tabBase) 70 void FilterLoader(CPluginTabBase* tabBase)
89 { 71 {
90 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH idingSelectors(tabBase->GetDocumentDomain().GetString())); 72 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH idingSelectors(tabBase->GetDocumentDomain()));
91 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); 73 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent);
92 } 74 }
93 } 75 }
94 76
95 void CPluginTabBase::OnNavigate(const CString& url) 77 void CPluginTabBase::OnNavigate(const CString& url)
96 { 78 {
97 SetDocumentUrl(url); 79 SetDocumentUrl(url);
98
99
100 #ifdef SUPPORT_FRAME_CACHING
101 ClearFrameCache(GetDocumentDomain()); 80 ClearFrameCache(GetDocumentDomain());
102 #endif
103
104 std::wstring domainString = GetDocumentDomain(); 81 std::wstring domainString = GetDocumentDomain();
105 ResetEvent(m_filter->hideFiltersLoadedEvent); 82 ResetEvent(m_filter->hideFiltersLoadedEvent);
106 try 83 try
107 { 84 {
108 std::thread filterLoaderThread(&FilterLoader, this); 85 std::thread filterLoaderThread(&FilterLoader, this);
109 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr. 86 filterLoaderThread.detach(); // TODO: but actually we should wait for the th read in the dtr.
110 } 87 }
111 catch (const std::system_error& ex) 88 catch (const std::system_error& ex)
112 { 89 {
113 auto errDescription = std::string("Class::Thread - Failed to start filter lo ader thread, ") + 90 auto errDescription = std::string("Class::Thread - Failed to start filter lo ader thread, ") +
114 ex.code().message() + ex.what(); 91 ex.code().message() + ex.what();
115 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, errDescription.c_str()); 92 DEBUG_ERROR_LOG(ex.code().value(), PLUGIN_ERROR_THREAD, PLUGIN_ERROR_MAIN_TH READ_CREATE_PROCESS, errDescription.c_str());
116 } 93 }
117
118 #ifdef SUPPORT_DOM_TRAVERSER
119 m_traverser->ClearCache(); 94 m_traverser->ClearCache();
120 #endif
121 } 95 }
122 96
123 void CPluginTabBase::InjectABP(IWebBrowser2* browser) 97 void CPluginTabBase::InjectABP(IWebBrowser2* browser)
124 { 98 {
125 CriticalSection::Lock lock(m_csInject); 99 CriticalSection::Lock lock(m_csInject);
126 CString url = GetDocumentUrl(); 100 CString url = GetDocumentUrl();
127 CString log; 101 CString log;
128 log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsF ileUrl().c_str()); 102 log.Format(L"InjectABP. Current URL: %s, settings URL: %s", url, UserSettingsF ileUrl().c_str());
129 DEBUG_GENERAL(log); 103 DEBUG_GENERAL(log);
130 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) || 104 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) ||
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0); 150 hr = pWndEx->Invoke(dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPU T | DISPATCH_PROPERTYPUTREF, &params, 0, 0, 0);
177 DEBUG_GENERAL("Invoke"); 151 DEBUG_GENERAL("Invoke");
178 if (FAILED(hr)) 152 if (FAILED(hr))
179 { 153 {
180 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"); 154 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");
181 } 155 }
182 } 156 }
183 157
184 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) 158 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser)
185 { 159 {
186 #ifdef SUPPORT_DOM_TRAVERSER 160 CPluginClient* client = CPluginClient::GetInstance();
187 if (!CPluginClient::GetInstance()->IsWhitelistedUrl(std::wstring(GetDocumentUr l()))) 161 std::wstring url = to_wstring(GetDocumentUrl());
162 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl))
188 { 163 {
189 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); 164 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() );
190 } 165 }
191 #endif // SUPPORT_DOM_TRAVERSER
192
193 InjectABP(browser); 166 InjectABP(browser);
194 } 167 }
195 168
196 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser) 169 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser)
197 { 170 {
198 CString documentUrl = GetDocumentUrl(); 171 CString documentUrl = GetDocumentUrl();
199 172
200 if (isDocumentBrowser) 173 if (isDocumentBrowser)
201 { 174 {
202 if (url != documentUrl) 175 if (url != documentUrl)
203 { 176 {
204 SetDocumentUrl(url); 177 SetDocumentUrl(url);
205 } 178 }
206 InjectABP(browser); 179 InjectABP(browser);
207 } 180 }
208
209 #ifdef SUPPORT_DOM_TRAVERSER
210 if (url.Left(6) != "res://") 181 if (url.Left(6) != "res://")
211 { 182 {
212 // Get document 183 // Get document
213 CComPtr<IDispatch> pDocDispatch; 184 CComPtr<IDispatch> pDocDispatch;
214 HRESULT hr = browser->get_Document(&pDocDispatch); 185 HRESULT hr = browser->get_Document(&pDocDispatch);
215 if (FAILED(hr) || !pDocDispatch) 186 if (FAILED(hr) || !pDocDispatch)
216 { 187 {
217 return; 188 return;
218 } 189 }
219 190
(...skipping 11 matching lines...) Expand all
231 pOleObj->GetClientSite(&pClientSite); 202 pOleObj->GetClientSite(&pClientSite);
232 if (pClientSite != NULL) 203 if (pClientSite != NULL)
233 { 204 {
234 CComPtr<IDocHostUIHandler> docHostUIHandler; 205 CComPtr<IDocHostUIHandler> docHostUIHandler;
235 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er); 206 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er);
236 if (docHostUIHandler != NULL) 207 if (docHostUIHandler != NULL)
237 { 208 {
238 docHostUIHandler->UpdateUI(); 209 docHostUIHandler->UpdateUI();
239 } 210 }
240 } 211 }
241 212 }
242 pDoc.Release(); 213 }
243 pDocDispatch.Release(); 214
244 } 215 std::wstring CPluginTabBase::GetDocumentDomain()
245 #endif 216 {
246 } 217 std::wstring domain;
247
248 CString CPluginTabBase::GetDocumentDomain()
249 {
250 CString domain;
251 218
252 m_criticalSection.Lock(); 219 m_criticalSection.Lock();
253 { 220 {
254 domain = m_documentDomain; 221 domain = m_documentDomain;
255 } 222 }
256 m_criticalSection.Unlock(); 223 m_criticalSection.Unlock();
257 224
258 return domain; 225 return domain;
259 } 226 }
260 227
261 void CPluginTabBase::SetDocumentUrl(const CString& url) 228 void CPluginTabBase::SetDocumentUrl(const CString& url)
262 { 229 {
263 m_criticalSection.Lock(); 230 m_criticalSection.Lock();
264 { 231 {
265 m_documentUrl = url; 232 m_documentUrl = url;
266 m_documentDomain = CString(CAdblockPlusClient::GetInstance()->GetHostFromUrl (url.GetString()).c_str()); 233 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(to_wstr ing(url));
267 } 234 }
268 m_criticalSection.Unlock(); 235 m_criticalSection.Unlock();
269 } 236 }
270 237
271 CString CPluginTabBase::GetDocumentUrl() 238 CString CPluginTabBase::GetDocumentUrl()
272 { 239 {
273 CString url; 240 CString url;
274 241
275 m_criticalSection.Lock(); 242 m_criticalSection.Lock();
276 { 243 {
277 url = m_documentUrl; 244 url = m_documentUrl;
278 } 245 }
279 m_criticalSection.Unlock(); 246 m_criticalSection.Unlock();
280 247
281 return url; 248 return url;
282 } 249 }
283 250
284 251
285 // ============================================================================ 252 // ============================================================================
286 // Frame caching 253 // Frame caching
287 // ============================================================================ 254 // ============================================================================
288
289 #ifdef SUPPORT_FRAME_CACHING
290
291 bool CPluginTabBase::IsFrameCached(const CString& url) 255 bool CPluginTabBase::IsFrameCached(const CString& url)
292 { 256 {
293 bool isFrame; 257 bool isFrame;
294 258
295 m_criticalSectionCache.Lock(); 259 m_criticalSectionCache.Lock();
296 { 260 {
297 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); 261 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end();
298 } 262 }
299 m_criticalSectionCache.Unlock(); 263 m_criticalSectionCache.Unlock();
300 264
301 return isFrame; 265 return isFrame;
302 } 266 }
303 267
304 void CPluginTabBase::CacheFrame(const CString& url) 268 void CPluginTabBase::CacheFrame(const CString& url)
305 { 269 {
306 m_criticalSectionCache.Lock(); 270 m_criticalSectionCache.Lock();
307 { 271 {
308 m_cacheFrames.insert(url); 272 m_cacheFrames.insert(url);
309 } 273 }
310 m_criticalSectionCache.Unlock(); 274 m_criticalSectionCache.Unlock();
311 } 275 }
312 276
313 void CPluginTabBase::ClearFrameCache(const CString& domain) 277 void CPluginTabBase::ClearFrameCache(const std::wstring& domain)
314 { 278 {
315 m_criticalSectionCache.Lock(); 279 m_criticalSectionCache.Lock();
316 { 280 {
317 if (domain.IsEmpty() || domain != m_cacheDomain) 281 if (domain.empty() || domain != m_cacheDomain)
318 { 282 {
319 m_cacheFrames.clear(); 283 m_cacheFrames.clear();
320 m_cacheDomain = domain; 284 m_cacheDomain = domain;
321 } 285 }
322 } 286 }
323 m_criticalSectionCache.Unlock(); 287 m_criticalSectionCache.Unlock();
324 } 288 }
325
326 #endif // SUPPORT_FRAME_CACHING
327
328 289
329 void CPluginTabBase::ThreadProc() 290 void CPluginTabBase::ThreadProc()
330 { 291 {
331 // Force loading/creation of settings 292 // Force loading/creation of settings
332 CPluginSettings* settings = CPluginSettings::GetInstance(); 293 CPluginSettings* settings = CPluginSettings::GetInstance();
333 294
334 settings->SetWorkingThreadId(); 295 settings->SetWorkingThreadId();
335 296
336 CString threadInfo; 297 CString threadInfo;
337 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId()); 298 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 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());
388 } 349 }
389 350
390 // Non-hanging sleep 351 // Non-hanging sleep
391 Sleep(50); 352 Sleep(50);
392 } 353 }
393 354
394 tabLoopIteration++; 355 tabLoopIteration++;
395 } 356 }
396 } 357 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld