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

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

Issue 6299667012780032: Issues #696,1231,1264,1265 - Improve handling in PassthroughApp (Closed)
Left Patch Set: Created Sept. 19, 2014, 2:41 p.m.
Right Patch Set: rebase Created Oct. 17, 2014, 12:51 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
« no previous file with change/comment | « src/plugin/PluginFilter.cpp ('k') | src/plugin/PluginWbPassThrough.h » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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()));
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 CPluginClient* client = CPluginClient::GetInstance(); 159 CPluginClient* client = CPluginClient::GetInstance();
187 std::wstring url = std::wstring(GetDocumentUrl()); 160 std::wstring url = to_wstring(GetDocumentUrl());
188 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl)) 161 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u rl))
189 { 162 {
190 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() ); 163 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl() );
191 } 164 }
192 #endif // SUPPORT_DOM_TRAVERSER
193
194 InjectABP(browser); 165 InjectABP(browser);
195 } 166 }
196 167
197 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser) 168 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur l, bool isDocumentBrowser)
198 { 169 {
199 CString documentUrl = GetDocumentUrl(); 170 CString documentUrl = GetDocumentUrl();
200 171
201 if (isDocumentBrowser) 172 if (isDocumentBrowser)
202 { 173 {
203 if (url != documentUrl) 174 if (url != documentUrl)
204 { 175 {
205 SetDocumentUrl(url); 176 SetDocumentUrl(url);
206 } 177 }
207 InjectABP(browser); 178 InjectABP(browser);
208 } 179 }
209
210 #ifdef SUPPORT_DOM_TRAVERSER
211 if (url.Left(6) != "res://") 180 if (url.Left(6) != "res://")
212 { 181 {
213 // Get document 182 // Get document
214 CComPtr<IDispatch> pDocDispatch; 183 CComPtr<IDispatch> pDocDispatch;
215 HRESULT hr = browser->get_Document(&pDocDispatch); 184 HRESULT hr = browser->get_Document(&pDocDispatch);
216 if (FAILED(hr) || !pDocDispatch) 185 if (FAILED(hr) || !pDocDispatch)
217 { 186 {
218 return; 187 return;
219 } 188 }
220 189
(...skipping 12 matching lines...) Expand all
233 if (pClientSite != NULL) 202 if (pClientSite != NULL)
234 { 203 {
235 CComPtr<IDocHostUIHandler> docHostUIHandler; 204 CComPtr<IDocHostUIHandler> docHostUIHandler;
236 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er); 205 pClientSite->QueryInterface(IID_IDocHostUIHandler, (void**)&docHostUIHandl er);
237 if (docHostUIHandler != NULL) 206 if (docHostUIHandler != NULL)
238 { 207 {
239 docHostUIHandler->UpdateUI(); 208 docHostUIHandler->UpdateUI();
240 } 209 }
241 } 210 }
242 } 211 }
243 #endif 212 }
244 } 213
245 214 std::wstring CPluginTabBase::GetDocumentDomain()
246 CString CPluginTabBase::GetDocumentDomain() 215 {
247 { 216 std::wstring domain;
248 CString domain;
249 217
250 m_criticalSection.Lock(); 218 m_criticalSection.Lock();
251 { 219 {
252 domain = m_documentDomain; 220 domain = m_documentDomain;
253 } 221 }
254 m_criticalSection.Unlock(); 222 m_criticalSection.Unlock();
255 223
256 return domain; 224 return domain;
257 } 225 }
258 226
259 void CPluginTabBase::SetDocumentUrl(const CString& url) 227 void CPluginTabBase::SetDocumentUrl(const CString& url)
260 { 228 {
261 m_criticalSection.Lock(); 229 m_criticalSection.Lock();
262 { 230 {
263 m_documentUrl = url; 231 m_documentUrl = url;
264 m_documentDomain = CString(CAdblockPlusClient::GetInstance()->GetHostFromUrl (url.GetString()).c_str()); 232 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(to_wstr ing(url));
265 } 233 }
266 m_criticalSection.Unlock(); 234 m_criticalSection.Unlock();
267 } 235 }
268 236
269 CString CPluginTabBase::GetDocumentUrl() 237 CString CPluginTabBase::GetDocumentUrl()
270 { 238 {
271 CString url; 239 CString url;
272 240
273 m_criticalSection.Lock(); 241 m_criticalSection.Lock();
274 { 242 {
275 url = m_documentUrl; 243 url = m_documentUrl;
276 } 244 }
277 m_criticalSection.Unlock(); 245 m_criticalSection.Unlock();
278 246
279 return url; 247 return url;
280 } 248 }
281 249
282 250
283 // ============================================================================ 251 // ============================================================================
284 // Frame caching 252 // Frame caching
285 // ============================================================================ 253 // ============================================================================
286
287 #ifdef SUPPORT_FRAME_CACHING
288
289 bool CPluginTabBase::IsFrameCached(const CString& url) 254 bool CPluginTabBase::IsFrameCached(const CString& url)
290 { 255 {
291 bool isFrame; 256 bool isFrame;
292 257
293 m_criticalSectionCache.Lock(); 258 m_criticalSectionCache.Lock();
294 { 259 {
295 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); 260 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end();
296 } 261 }
297 m_criticalSectionCache.Unlock(); 262 m_criticalSectionCache.Unlock();
298 263
299 return isFrame; 264 return isFrame;
300 } 265 }
301 266
302 void CPluginTabBase::CacheFrame(const CString& url) 267 void CPluginTabBase::CacheFrame(const CString& url)
303 { 268 {
304 m_criticalSectionCache.Lock(); 269 m_criticalSectionCache.Lock();
305 { 270 {
306 m_cacheFrames.insert(url); 271 m_cacheFrames.insert(url);
307 } 272 }
308 m_criticalSectionCache.Unlock(); 273 m_criticalSectionCache.Unlock();
309 } 274 }
310 275
311 void CPluginTabBase::ClearFrameCache(const CString& domain) 276 void CPluginTabBase::ClearFrameCache(const std::wstring& domain)
312 { 277 {
313 m_criticalSectionCache.Lock(); 278 m_criticalSectionCache.Lock();
314 { 279 {
315 if (domain.IsEmpty() || domain != m_cacheDomain) 280 if (domain.empty() || domain != m_cacheDomain)
316 { 281 {
317 m_cacheFrames.clear(); 282 m_cacheFrames.clear();
318 m_cacheDomain = domain; 283 m_cacheDomain = domain;
319 } 284 }
320 } 285 }
321 m_criticalSectionCache.Unlock(); 286 m_criticalSectionCache.Unlock();
322 } 287 }
323
324 #endif // SUPPORT_FRAME_CACHING
325
326 288
327 void CPluginTabBase::ThreadProc() 289 void CPluginTabBase::ThreadProc()
328 { 290 {
329 // Force loading/creation of settings 291 // Force loading/creation of settings
330 CPluginSettings* settings = CPluginSettings::GetInstance(); 292 CPluginSettings* settings = CPluginSettings::GetInstance();
331 293
332 settings->SetWorkingThreadId(); 294 settings->SetWorkingThreadId();
333 295
334 CString threadInfo; 296 CString threadInfo;
335 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId()); 297 threadInfo.Format(L"%d.%d", ::GetCurrentProcessId(), ::GetCurrentThreadId());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError. GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr ue, pluginError.GetProcessId(), pluginError.GetThreadId()); 347 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError. GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr ue, pluginError.GetProcessId(), pluginError.GetThreadId());
386 } 348 }
387 349
388 // Non-hanging sleep 350 // Non-hanging sleep
389 Sleep(50); 351 Sleep(50);
390 } 352 }
391 353
392 tabLoopIteration++; 354 tabLoopIteration++;
393 } 355 }
394 } 356 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld