Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 #include "PluginStdAfx.h" | 1 #include "PluginStdAfx.h" |
2 | 2 |
3 #include <Wbemidl.h> | 3 #include <Wbemidl.h> |
4 #include <time.h> | 4 #include <time.h> |
5 #include "PluginSettings.h" | 5 #include "PluginSettings.h" |
6 #include "PluginClient.h" | 6 #include "PluginClient.h" |
7 #include "PluginSystem.h" | 7 #include "PluginSystem.h" |
8 #ifdef SUPPORT_FILTER | 8 #ifdef SUPPORT_FILTER |
9 #include "PluginFilter.h" | 9 #include "PluginFilter.h" |
10 #endif | 10 #endif |
11 #include "PluginMutex.h" | 11 #include "PluginMutex.h" |
12 #include "../shared/Utils.h" | 12 #include "../shared/Utils.h" |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 | 15 |
16 // IE functions | 16 // IE functions |
17 #pragma comment(lib, "iepmapi.lib") | 17 #pragma comment(lib, "iepmapi.lib") |
18 | 18 |
19 #include <knownfolders.h> | 19 #include <knownfolders.h> |
20 | 20 |
21 namespace | 21 namespace |
22 { | 22 { |
23 std::wstring CreateDomainWhitelistingFilter(CString domain) | 23 std::wstring CreateDomainWhitelistingFilter(const CString domain) |
24 { | 24 { |
25 return L"@@||" + domain + L"^$document"; | 25 return std::wstring(L"@@||") + domain.GetString() + std::wstring(L"^$documen t"); |
26 } | 26 } |
27 } | 27 } |
28 | 28 |
29 class TSettings | 29 class TSettings |
30 { | 30 { |
31 DWORD processorId; | 31 DWORD processorId; |
32 | 32 |
33 char sPluginId[44]; | 33 char sPluginId[44]; |
34 }; | 34 }; |
35 | 35 |
(...skipping 21 matching lines...) Expand all Loading... | |
57 public: | 57 public: |
58 CPluginSettingsWhitelistLock() : CPluginMutex("SettingsFileWhitelist", PLUGIN_ ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} | 58 CPluginSettingsWhitelistLock() : CPluginMutex("SettingsFileWhitelist", PLUGIN_ ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} |
59 ~CPluginSettingsWhitelistLock() {} | 59 ~CPluginSettingsWhitelistLock() {} |
60 }; | 60 }; |
61 | 61 |
62 #endif | 62 #endif |
63 | 63 |
64 CPluginSettings* CPluginSettings::s_instance = NULL; | 64 CPluginSettings* CPluginSettings::s_instance = NULL; |
65 | 65 |
66 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 66 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; |
67 #ifdef SUPPORT_WHITELIST | 67 |
68 CComAutoCriticalSection CPluginSettings::s_criticalSectionDomainHistory; | 68 |
69 #endif | 69 CPluginSettings::CPluginSettings() : m_dwWorkingThreadId(0), m_isPluginEnabledTa b(true) |
70 | 70 { |
71 | |
72 CPluginSettings::CPluginSettings() : | |
73 m_settingsVersion("1"), m_isDirty(false), m_isFirstRun(false), m_isFirstRunUpd ate(false), m_dwMainProcessId(0), m_dwMainThreadId(0), m_dwWorkingThreadId(0), | |
74 m_isPluginEnabledTab(true), m_tabNumber("1") | |
75 { | |
76 | |
77 CPluginSettings *lightInstance = s_instance; | |
78 s_instance = NULL; | 71 s_instance = NULL; |
79 | 72 |
80 m_WindowsBuildNumber = 0; | 73 m_WindowsBuildNumber = 0; |
81 | 74 |
82 #ifdef SUPPORT_WHITELIST | 75 #ifdef SUPPORT_WHITELIST |
83 ClearWhitelist(); | 76 ClearWhitelist(); |
84 #endif | 77 #endif |
85 } | 78 } |
86 | 79 |
87 | 80 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 } | 143 } |
151 CString lang; | 144 CString lang; |
152 lang.Append(language); | 145 lang.Append(language); |
153 lang.Append(L"-"); | 146 lang.Append(L"-"); |
154 lang.Append(country); | 147 lang.Append(country); |
155 | 148 |
156 return lang; | 149 return lang; |
157 | 150 |
158 } | 151 } |
159 | 152 |
160 CString CPluginSettings::GetTempPath(const CString& filename) | |
161 { | |
162 CString tempPath; | |
163 | |
164 LPWSTR pwszCacheDir = NULL; | |
165 | |
166 HRESULT hr = ::IEGetWriteableFolderPath(FOLDERID_InternetCache, &pwszCacheDir) ; | |
167 if (SUCCEEDED(hr)) | |
168 { | |
169 tempPath = pwszCacheDir; | |
170 } | |
171 // Not implemented in IE6 | |
172 else if (hr == E_NOTIMPL) | |
173 { | |
174 TCHAR path[MAX_PATH] = _T(""); | |
175 | |
176 if (::SHGetSpecialFolderPath(NULL, path, CSIDL_INTERNET_CACHE, TRUE)) | |
177 { | |
178 tempPath = path; | |
179 } | |
180 else | |
181 { | |
182 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSIN FO_GET_SPECIAL_FOLDER_TEMP, "Settings::GetTempPath failed"); | |
183 } | |
184 } | |
185 // Other error | |
186 else | |
187 { | |
188 DEBUG_ERROR_LOG(hr, PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO_TEMP_PATH, "S ettings::GetTempPath failed"); | |
189 } | |
190 | |
191 ::CoTaskMemFree(pwszCacheDir); | |
192 | |
193 return tempPath + "\\" + filename; | |
194 } | |
195 | |
196 CString CPluginSettings::GetTempFile(const CString& prefix, const CString& exten sion) | |
197 { | |
198 TCHAR nameBuffer[MAX_PATH] = _T(""); | |
199 | |
200 CString tempPath; | |
201 | |
202 DWORD dwRetVal = ::GetTempFileName(GetTempPath(), prefix, 0, nameBuffer); | |
203 if (dwRetVal == 0) | |
204 { | |
205 DEBUG_ERROR_LOG(::GetLastError(), PLUGIN_ERROR_SYSINFO, PLUGIN_ERROR_SYSINFO _TEMP_FILE, "Settings::GetTempFileName failed"); | |
206 | |
207 tempPath = GetDataPath(); | |
208 } | |
209 else | |
210 { | |
211 tempPath = nameBuffer; | |
212 if (!extension.IsEmpty()) | |
213 { | |
214 int pos = tempPath.ReverseFind(_T('.')); | |
215 if (pos >= 0) | |
216 { | |
217 tempPath = tempPath.Left(pos+1) + extension; | |
218 } | |
219 } | |
220 } | |
221 | |
222 return tempPath; | |
223 } | |
224 | |
225 | 153 |
226 bool CPluginSettings::IsPluginEnabled() const | 154 bool CPluginSettings::IsPluginEnabled() const |
227 { | 155 { |
228 return m_isPluginEnabledTab; | 156 return m_isPluginEnabledTab; |
229 } | 157 } |
230 | 158 |
231 | 159 |
232 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 160 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const |
233 { | 161 { |
234 std::map<CString, CString> filterList; | 162 std::map<CString, CString> filterList; |
235 for (size_t i = 0; i < m_subscriptions.size(); i ++) | 163 for (size_t i = 0; i < m_subscriptions.size(); i ++) |
236 { | 164 { |
237 SubscriptionDescription it = m_subscriptions[i]; | 165 SubscriptionDescription it = m_subscriptions[i]; |
238 filterList.insert(std::make_pair(CString(it.url.c_str()), CString(it.title.c _str()))); | 166 filterList.insert(std::make_pair(CString(it.url.c_str()), CString(it.title.c _str()))); |
239 } | 167 } |
240 return filterList; | 168 return filterList; |
241 } | 169 } |
242 | 170 |
243 bool CPluginSettings::IsMainProcess(DWORD dwProcessId) const | 171 bool CPluginSettings::IsWorkingThread(DWORD dwThreadId) const |
244 { | |
245 if (dwProcessId == 0) | |
246 { | |
247 dwProcessId = ::GetCurrentProcessId(); | |
248 } | |
249 return m_dwMainProcessId == dwProcessId; | |
250 } | |
251 | |
252 void CPluginSettings::SetMainProcessId() | |
253 { | |
254 m_dwMainProcessId = ::GetCurrentProcessId(); | |
255 } | |
256 | |
257 void CPluginSettings::SetMainProcessId(DWORD id) | |
258 { | |
259 m_dwMainProcessId = id; | |
260 } | |
261 | |
262 | |
263 bool CPluginSettings::IsMainUiThread(DWORD dwThreadId) const | |
264 { | 172 { |
265 if (dwThreadId == 0) | 173 if (dwThreadId == 0) |
266 { | 174 { |
267 dwThreadId = ::GetCurrentThreadId(); | 175 dwThreadId = ::GetCurrentThreadId(); |
268 } | 176 } |
269 return m_dwMainUiThreadId == dwThreadId; | |
270 } | |
271 | |
272 void CPluginSettings::SetMainUiThreadId() | |
273 { | |
274 m_dwMainUiThreadId = ::GetCurrentThreadId(); | |
275 } | |
276 | |
277 void CPluginSettings::SetMainUiThreadId(DWORD id) | |
278 { | |
279 m_dwMainUiThreadId = id; | |
280 } | |
281 bool CPluginSettings::IsMainThread(DWORD dwThreadId) const | |
282 { | |
283 if (dwThreadId == 0) | |
284 { | |
285 dwThreadId = ::GetCurrentThreadId(); | |
286 } | |
287 return m_dwMainThreadId == dwThreadId; | |
288 } | |
289 | |
290 void CPluginSettings::SetMainThreadId() | |
291 { | |
292 m_dwMainThreadId = ::GetCurrentThreadId(); | |
293 } | |
294 | |
295 void CPluginSettings::SetMainThreadId(DWORD id) | |
296 { | |
297 m_dwMainThreadId = id; | |
298 } | |
299 | |
300 bool CPluginSettings::IsWorkingThread(DWORD dwThreadId) const | |
301 { | |
302 if (dwThreadId == 0) | |
303 { | |
304 dwThreadId = ::GetCurrentThreadId(); | |
305 } | |
306 return m_dwWorkingThreadId == dwThreadId; | 177 return m_dwWorkingThreadId == dwThreadId; |
307 } | 178 } |
308 | 179 |
309 void CPluginSettings::SetWorkingThreadId() | 180 void CPluginSettings::SetWorkingThreadId() |
310 { | 181 { |
311 m_dwWorkingThreadId = ::GetCurrentThreadId(); | 182 m_dwWorkingThreadId = ::GetCurrentThreadId(); |
312 } | 183 } |
313 | 184 |
314 void CPluginSettings::SetWorkingThreadId(DWORD id) | 185 void CPluginSettings::SetWorkingThreadId(DWORD id) |
315 { | 186 { |
316 m_dwWorkingThreadId = id; | 187 m_dwWorkingThreadId = id; |
317 } | 188 } |
318 | 189 |
319 void CPluginSettings::SetFirstRun() | 190 void CPluginSettings::SetFirstRun() |
320 { | 191 { |
321 m_isFirstRun = true; | 192 m_isFirstRun = true; |
322 } | 193 } |
323 | 194 |
324 bool CPluginSettings::IsFirstRun() const | 195 bool CPluginSettings::IsFirstRun() const |
325 { | 196 { |
326 return m_isFirstRun; | 197 return m_isFirstRun; |
327 } | 198 } |
328 | |
329 void CPluginSettings::SetFirstRunUpdate() | |
330 { | |
331 m_isFirstRunUpdate = true; | |
332 } | |
333 | |
334 bool CPluginSettings::IsFirstRunUpdate() const | |
335 { | |
336 return m_isFirstRunUpdate; | |
337 } | |
338 | |
339 bool CPluginSettings::IsFirstRunAny() const | |
340 { | |
341 return m_isFirstRun || m_isFirstRunUpdate; | |
342 } | |
343 | |
344 | |
345 bool CPluginSettings::IncrementTabCount() | |
346 { | |
347 int tabCount = 1; | |
348 | |
349 CPluginSettingsTabLock lock; | |
350 if (lock.IsLocked()) | |
351 { | |
352 SYSTEMTIME systemTime; | |
353 ::GetSystemTime(&systemTime); | |
354 | |
355 CString today; | |
356 today.Format(L"%d-%d-%d", systemTime.wYear, systemTime.wMonth, systemTime.wD ay); | |
357 | |
358 s_criticalSectionLocal.Lock(); | |
359 { | |
360 //TODO: Increment tab count in the AdblockPlusEngine | |
361 | |
362 m_tabNumber.Format(L"%d", tabCount); | |
363 } | |
364 s_criticalSectionLocal.Unlock(); | |
365 } | |
366 | |
367 return tabCount == 1; | |
368 } | |
369 | |
370 | |
371 CString CPluginSettings::GetTabNumber() const | |
372 { | |
373 CString tabNumber; | |
374 | |
375 s_criticalSectionLocal.Lock(); | |
376 { | |
377 tabNumber = m_tabNumber; | |
378 } | |
379 s_criticalSectionLocal.Unlock(); | |
380 | |
381 return tabNumber; | |
382 } | |
383 | |
384 | |
385 bool CPluginSettings::DecrementTabCount() | |
386 { | |
387 int tabCount = 0; | |
388 | |
389 CPluginSettingsTabLock lock; | |
390 if (lock.IsLocked()) | |
391 { | |
392 | |
393 s_criticalSectionLocal.Lock(); | |
394 { | |
395 //TODO: Retrieve tab count from the AdblockPlusEngine | |
396 m_tabNumber.Format(L"%d", tabCount); | |
397 } | |
398 s_criticalSectionLocal.Unlock(); | |
399 } | |
400 | |
401 return tabCount == 0; | |
402 } | |
403 | |
404 | 199 |
405 void CPluginSettings::TogglePluginEnabled() | 200 void CPluginSettings::TogglePluginEnabled() |
406 { | 201 { |
407 CPluginSettingsTabLock lock; | 202 CPluginSettingsTabLock lock; |
408 if (lock.IsLocked()) | 203 if (lock.IsLocked()) |
409 { | 204 { |
410 s_criticalSectionLocal.Lock(); | 205 s_criticalSectionLocal.Lock(); |
411 { | 206 { |
412 //TODO: Query if plugin is enabled from the AdblockPlusEngine | 207 //TODO: Query if plugin is enabled from the AdblockPlusEngine |
413 m_isPluginEnabledTab = m_isPluginEnabledTab ? false : true; | 208 m_isPluginEnabledTab = m_isPluginEnabledTab ? false : true; |
(...skipping 29 matching lines...) Expand all Loading... | |
443 } | 238 } |
444 } | 239 } |
445 bool CPluginSettings::GetPluginEnabled() const | 240 bool CPluginSettings::GetPluginEnabled() const |
446 { | 241 { |
447 //TODO: Query AdblockPlusEngine | 242 //TODO: Query AdblockPlusEngine |
448 return m_isPluginEnabledTab; | 243 return m_isPluginEnabledTab; |
449 } | 244 } |
450 | 245 |
451 bool CPluginSettings::GetStatusBarAsked() | 246 bool CPluginSettings::GetStatusBarAsked() |
452 { | 247 { |
453 //TOTO: Get value from the registry; | 248 return CPluginClient::GetInstance()->GetPref(L"statusbarasked", false); |
Wladimir Palant
2013/07/05 09:26:45
TOTO => TODO and please fix indentation
| |
454 return false; | 249 } |
455 } | 250 |
456 | 251 void CPluginSettings::SetStatusBarAsked() |
457 void CPluginSettings::SetStatusBarAsked(bool asked) | 252 { |
Wladimir Palant
2013/07/05 09:26:45
The parameter can probably be removed here - we wo
| |
458 { | 253 CPluginClient::GetInstance()->SetPref(L"statusbarasked", true); |
459 //TODO: Set value in the registry | |
460 } | 254 } |
461 | 255 |
462 | 256 |
463 void CPluginSettings::AddError(const CString& error, const CString& errorCode) | 257 void CPluginSettings::AddError(const CString& error, const CString& errorCode) |
464 { | 258 { |
465 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) | 259 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) |
466 } | 260 } |
467 | 261 |
468 | 262 |
469 // ============================================================================ | 263 // ============================================================================ |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 365 |
572 m_WindowsBuildNumber = osvi.dwBuildNumber; | 366 m_WindowsBuildNumber = osvi.dwBuildNumber; |
573 } | 367 } |
574 | 368 |
575 return m_WindowsBuildNumber; | 369 return m_WindowsBuildNumber; |
576 } | 370 } |
577 | 371 |
578 void CPluginSettings::SetSubscription(const std::wstring& url) | 372 void CPluginSettings::SetSubscription(const std::wstring& url) |
579 { | 373 { |
580 CPluginClient::GetInstance()->SetSubscription(url); | 374 CPluginClient::GetInstance()->SetSubscription(url); |
581 RefreshFilterlist(); | |
582 RefreshWhitelist(); | 375 RefreshWhitelist(); |
583 } | 376 } |
584 | 377 |
585 CString CPluginSettings::GetSubscription() | 378 CString CPluginSettings::GetSubscription() |
586 { | 379 { |
587 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions(); | 380 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions(); |
588 if (subscriptions.size() > 0) | 381 if (subscriptions.size() > 0) |
589 return CString(subscriptions.front().url.c_str()); | 382 return CString(subscriptions.front().url.c_str()); |
590 else | 383 else |
591 return CString(L""); | 384 return CString(L""); |
592 } | 385 } |
593 | 386 |
594 | 387 |
595 void CPluginSettings::RefreshFilterlist() | |
596 { | |
597 CPluginClient::GetInstance()->UpdateAllSubscriptions(); | |
598 } | |
599 | 388 |
600 #endif // SUPPORT_WHITELIST | 389 #endif // SUPPORT_WHITELIST |
LEFT | RIGHT |