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 "PluginDomTraverser.h" | 6 #include "PluginDomTraverser.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 29 matching lines...) Expand all Loading... |
220 | 221 |
221 m_criticalSection.Lock(); | 222 m_criticalSection.Lock(); |
222 { | 223 { |
223 domain = m_documentDomain; | 224 domain = m_documentDomain; |
224 } | 225 } |
225 m_criticalSection.Unlock(); | 226 m_criticalSection.Unlock(); |
226 | 227 |
227 return domain; | 228 return domain; |
228 } | 229 } |
229 | 230 |
230 void CPluginTabBase::SetDocumentUrl(const CString& url) | 231 void CPluginTabBase::SetDocumentUrl(const std::wstring& url) |
231 { | 232 { |
232 m_criticalSection.Lock(); | 233 m_criticalSection.Lock(); |
233 { | 234 { |
234 m_documentUrl = url; | 235 m_documentUrl = url; |
235 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(to_wstr
ing(url)); | 236 m_documentDomain = CAdblockPlusClient::GetInstance()->GetHostFromUrl(url); |
236 } | 237 } |
237 m_criticalSection.Unlock(); | 238 m_criticalSection.Unlock(); |
238 } | 239 } |
239 | 240 |
240 CString CPluginTabBase::GetDocumentUrl() | 241 std::wstring CPluginTabBase::GetDocumentUrl() |
241 { | 242 { |
242 CString url; | 243 std::wstring url; |
243 | 244 |
244 m_criticalSection.Lock(); | 245 m_criticalSection.Lock(); |
245 { | 246 { |
246 url = m_documentUrl; | 247 url = m_documentUrl; |
247 } | 248 } |
248 m_criticalSection.Unlock(); | 249 m_criticalSection.Unlock(); |
249 | 250 |
250 return url; | 251 return url; |
251 } | 252 } |
252 | 253 |
253 | 254 |
254 // ============================================================================ | 255 // ============================================================================ |
255 // Frame caching | 256 // Frame caching |
256 // ============================================================================ | 257 // ============================================================================ |
257 bool CPluginTabBase::IsFrameCached(const CString& url) | 258 bool CPluginTabBase::IsFrameCached(const std::wstring& url) |
258 { | 259 { |
259 bool isFrame; | 260 bool isFrame; |
260 | 261 |
261 m_criticalSectionCache.Lock(); | 262 m_criticalSectionCache.Lock(); |
262 { | 263 { |
263 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); | 264 isFrame = m_cacheFrames.find(url) != m_cacheFrames.end(); |
264 } | 265 } |
265 m_criticalSectionCache.Unlock(); | 266 m_criticalSectionCache.Unlock(); |
266 | 267 |
267 return isFrame; | 268 return isFrame; |
268 } | 269 } |
269 | 270 |
270 void CPluginTabBase::CacheFrame(const CString& url) | 271 void CPluginTabBase::CacheFrame(const std::wstring& url) |
271 { | 272 { |
272 m_criticalSectionCache.Lock(); | 273 m_criticalSectionCache.Lock(); |
273 { | 274 { |
274 m_cacheFrames.insert(url); | 275 m_cacheFrames.insert(url); |
275 } | 276 } |
276 m_criticalSectionCache.Unlock(); | 277 m_criticalSectionCache.Unlock(); |
277 } | 278 } |
278 | 279 |
279 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) | 280 void CPluginTabBase::ClearFrameCache(const std::wstring& domain) |
280 { | 281 { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError.
GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr
ue, pluginError.GetProcessId(), pluginError.GetThreadId()); | 351 CPluginClient::LogPluginError(pluginError.GetErrorCode(), pluginError.
GetErrorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), tr
ue, pluginError.GetProcessId(), pluginError.GetThreadId()); |
351 } | 352 } |
352 | 353 |
353 // Non-hanging sleep | 354 // Non-hanging sleep |
354 Sleep(50); | 355 Sleep(50); |
355 } | 356 } |
356 | 357 |
357 tabLoopIteration++; | 358 tabLoopIteration++; |
358 } | 359 } |
359 } | 360 } |
OLD | NEW |