OLD | NEW |
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 #include "PluginTab.h" | 5 #include "PluginTab.h" |
6 #include "AdblockPlusDomTraverser.h" | 6 #include "AdblockPlusDomTraverser.h" |
7 #include "PluginClass.h" | 7 #include "PluginClass.h" |
8 #include "PluginTabBase.h" | 8 #include "PluginTabBase.h" |
9 #include "PluginUtil.h" | 9 #include "PluginUtil.h" |
10 #include <dispex.h> | 10 #include <dispex.h> |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 66 |
67 namespace | 67 namespace |
68 { | 68 { |
69 void FilterLoader(CPluginTabBase* tabBase) | 69 void FilterLoader(CPluginTabBase* tabBase) |
70 { | 70 { |
71 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH
idingSelectors(tabBase->GetDocumentDomain())); | 71 tabBase->m_filter->LoadHideFilters(CPluginClient::GetInstance()->GetElementH
idingSelectors(tabBase->GetDocumentDomain())); |
72 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); | 72 SetEvent(tabBase->m_filter->hideFiltersLoadedEvent); |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
76 void CPluginTabBase::OnNavigate(const CString& url) | 76 void CPluginTabBase::OnNavigate(const std::wstring& url) |
77 { | 77 { |
78 SetDocumentUrl(url); | 78 SetDocumentUrl(url); |
79 ClearFrameCache(GetDocumentDomain()); | 79 ClearFrameCache(GetDocumentDomain()); |
80 std::wstring domainString = GetDocumentDomain(); | 80 std::wstring domainString = GetDocumentDomain(); |
81 ResetEvent(m_filter->hideFiltersLoadedEvent); | 81 ResetEvent(m_filter->hideFiltersLoadedEvent); |
82 try | 82 try |
83 { | 83 { |
84 std::thread filterLoaderThread(&FilterLoader, this); | 84 std::thread filterLoaderThread(&FilterLoader, this); |
85 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. |
86 } | 86 } |
87 catch (const std::system_error& ex) | 87 catch (const std::system_error& ex) |
88 { | 88 { |
89 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, ") + |
90 ex.code().message() + ex.what(); | 90 ex.code().message() + ex.what(); |
91 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()); |
92 } | 92 } |
93 m_traverser->ClearCache(); | 93 m_traverser->ClearCache(); |
94 } | 94 } |
95 | 95 |
96 void CPluginTabBase::InjectABP(IWebBrowser2* browser) | 96 void CPluginTabBase::InjectABP(IWebBrowser2* browser) |
97 { | 97 { |
98 CriticalSection::Lock lock(m_csInject); | 98 CriticalSection::Lock lock(m_csInject); |
99 CString url = GetDocumentUrl(); | 99 CString url = ToCString(GetDocumentUrl()); |
100 CString log; | 100 CString log; |
101 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()); |
102 DEBUG_GENERAL(log); | 102 DEBUG_GENERAL(log); |
103 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) || | 103 if (!(0 == url.CompareNoCase(CString(UserSettingsFileUrl().c_str())) || |
104 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str())))) | 104 0 == url.CompareNoCase(CString(FirstRunPageFileUrl().c_str())))) |
105 { | 105 { |
106 DEBUG_GENERAL(L"Not injecting"); | 106 DEBUG_GENERAL(L"Not injecting"); |
107 return; | 107 return; |
108 } | 108 } |
109 DEBUG_GENERAL(L"Going to inject"); | 109 DEBUG_GENERAL(L"Going to inject"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 DEBUG_GENERAL("Invoke"); | 150 DEBUG_GENERAL("Invoke"); |
151 if (FAILED(hr)) | 151 if (FAILED(hr)) |
152 { | 152 { |
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"); | 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"); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) | 157 void CPluginTabBase::OnDownloadComplete(IWebBrowser2* browser) |
158 { | 158 { |
159 CPluginClient* client = CPluginClient::GetInstance(); | 159 CPluginClient* client = CPluginClient::GetInstance(); |
160 std::wstring url = to_wstring(GetDocumentUrl()); | 160 std::wstring url = GetDocumentUrl(); |
161 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u
rl)) | 161 if (!client->IsWhitelistedUrl(url) && !client->IsElemhideWhitelistedOnDomain(u
rl)) |
162 { | 162 { |
163 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl()
); | 163 m_traverser->TraverseDocument(browser, GetDocumentDomain(), GetDocumentUrl()
); |
164 } | 164 } |
165 InjectABP(browser); | 165 InjectABP(browser); |
166 } | 166 } |
167 | 167 |
168 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const CString& ur
l, bool isDocumentBrowser) | 168 void CPluginTabBase::OnDocumentComplete(IWebBrowser2* browser, const std::wstrin
g& url, bool isDocumentBrowser) |
169 { | 169 { |
170 CString documentUrl = GetDocumentUrl(); | 170 std::wstring documentUrl = GetDocumentUrl(); |
171 | 171 |
172 if (isDocumentBrowser) | 172 if (isDocumentBrowser) |
173 { | 173 { |
174 if (url != documentUrl) | 174 if (url != documentUrl) |
175 { | 175 { |
176 SetDocumentUrl(url); | 176 SetDocumentUrl(url); |
177 } | 177 } |
178 InjectABP(browser); | 178 InjectABP(browser); |
179 } | 179 } |
180 if (url.Left(6) != "res://") | 180 CString urlLegacy = ToCString(url); |
| 181 if (urlLegacy.Left(6) != "res://") |
181 { | 182 { |
182 // Get document | 183 // Get document |
183 CComPtr<IDispatch> pDocDispatch; | 184 CComPtr<IDispatch> pDocDispatch; |
184 HRESULT hr = browser->get_Document(&pDocDispatch); | 185 HRESULT hr = browser->get_Document(&pDocDispatch); |
185 if (FAILED(hr) || !pDocDispatch) | 186 if (FAILED(hr) || !pDocDispatch) |
186 { | 187 { |
187 return; | 188 return; |
188 } | 189 } |
189 | 190 |
190 CComQIPtr<IHTMLDocument2> pDoc = pDocDispatch; | 191 CComQIPtr<IHTMLDocument2> pDoc = pDocDispatch; |
(...skipping 26 matching lines...) Expand all Loading... |
217 | 218 |
218 m_criticalSection.Lock(); | 219 m_criticalSection.Lock(); |
219 { | 220 { |
220 domain = m_documentDomain; | 221 domain = m_documentDomain; |
221 } | 222 } |
222 m_criticalSection.Unlock(); | 223 m_criticalSection.Unlock(); |
223 | 224 |
224 return domain; | 225 return domain; |
225 } | 226 } |
226 | 227 |
227 void CPluginTabBase::SetDocumentUrl(const CString& url) | 228 void CPluginTabBase::SetDocumentUrl(const std::wstring& url) |
228 { | 229 { |
229 m_criticalSection.Lock(); | 230 m_criticalSection.Lock(); |
230 { | 231 { |
231 m_documentUrl = url; | 232 m_documentUrl = url; |
232 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(to_wstr
ing(url)); | 233 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url); |
233 } | 234 } |
234 m_criticalSection.Unlock(); | 235 m_criticalSection.Unlock(); |
235 } | 236 } |
236 | 237 |
237 CString CPluginTabBase::GetDocumentUrl() | 238 std::wstring CPluginTabBase::GetDocumentUrl() |
238 { | 239 { |
239 CString url; | 240 std::wstring url; |
240 | 241 |
241 m_criticalSection.Lock(); | 242 m_criticalSection.Lock(); |
242 { | 243 { |
243 url = m_documentUrl; | 244 url = m_documentUrl; |
244 } | 245 } |
245 m_criticalSection.Unlock(); | 246 m_criticalSection.Unlock(); |
246 | 247 |
247 return url; | 248 return url; |
248 } | 249 } |
249 | 250 |
250 | 251 |
251 // ============================================================================ | 252 // ============================================================================ |
252 // Frame caching | 253 // Frame caching |
253 // ============================================================================ | 254 // ============================================================================ |
254 bool CPluginTabBase::IsFrameCached(const CString& url) | 255 bool CPluginTabBase::IsFrameCached(const std::wstring& url) |
255 { | 256 { |
256 bool isFrame; | 257 bool isFrame; |
257 | 258 |
258 m_criticalSectionCache.Lock(); | 259 m_criticalSectionCache.Lock(); |
259 { | 260 { |
260 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); | 261 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); |
261 } | 262 } |
262 m_criticalSectionCache.Unlock(); | 263 m_criticalSectionCache.Unlock(); |
263 | 264 |
264 return isFrame; | 265 return isFrame; |
265 } | 266 } |
266 | 267 |
267 void CPluginTabBase::CacheFrame(const CString& url) | 268 void CPluginTabBase::CacheFrame(const std::wstring& url) |
268 { | 269 { |
269 m_criticalSectionCache.Lock(); | 270 m_criticalSectionCache.Lock(); |
270 { | 271 { |
271 m_cacheFrames.insert(url); | 272 m_cacheFrames.insert(url); |
272 } | 273 } |
273 m_criticalSectionCache.Unlock(); | 274 m_criticalSectionCache.Unlock(); |
274 } | 275 } |
275 | 276 |
276 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) | 277 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) |
277 { | 278 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 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()); |
348 } | 349 } |
349 | 350 |
350 // Non-hanging sleep | 351 // Non-hanging sleep |
351 Sleep(50); | 352 Sleep(50); |
352 } | 353 } |
353 | 354 |
354 tabLoopIteration++; | 355 tabLoopIteration++; |
355 } | 356 } |
356 } | 357 } |
OLD | NEW |