LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include "PluginStdAfx.h" | 18 #include "PluginStdAfx.h" |
19 | 19 |
20 #include "PluginSettings.h" | 20 #include "PluginSettings.h" |
21 #include "AdblockPlusClient.h" | 21 #include "AdblockPlusClient.h" |
22 #include "PluginSystem.h" | 22 #include "PluginSystem.h" |
23 #include "PluginMutex.h" | 23 #include "PluginMutex.h" |
24 #include "../shared/Utils.h" | 24 #include "../shared/Utils.h" |
25 | 25 |
26 namespace | 26 namespace |
27 { | 27 { |
28 std::wstring CreateDomainWhitelistingFilter(const CString& domain) | 28 std::wstring CreateDomainWhitelistingFilter(const std::wstring& domain) |
29 { | 29 { |
30 return L"@@||" + ToWstring(domain) + L"^$document"; | 30 return L"@@||" + domain + L"^$document"; |
31 } | 31 } |
32 } | 32 } |
33 | 33 |
34 class CPluginSettingsWhitelistLock : public CPluginMutex | 34 class CPluginSettingsWhitelistLock : public CPluginMutex |
35 { | 35 { |
36 public: | 36 public: |
37 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN
_ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} | 37 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN
_ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} |
38 ~CPluginSettingsWhitelistLock() {} | 38 ~CPluginSettingsWhitelistLock() {} |
39 }; | 39 }; |
40 | 40 |
41 CPluginSettings* CPluginSettings::s_instance = NULL; | 41 CPluginSettings* CPluginSettings::s_instance = NULL; |
42 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; | 42 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; |
43 | 43 |
44 CPluginSettings::CPluginSettings() | 44 CPluginSettings::CPluginSettings() |
45 { | 45 { |
46 s_instance = NULL; | 46 s_instance = NULL; |
47 m_WindowsBuildNumber = 0; | |
48 ClearWhitelist(); | 47 ClearWhitelist(); |
49 } | 48 } |
50 | 49 |
51 CPluginSettings::~CPluginSettings() | 50 CPluginSettings::~CPluginSettings() |
52 { | 51 { |
53 s_instance = NULL; | 52 s_instance = NULL; |
54 } | 53 } |
55 | 54 |
56 CPluginSettings* CPluginSettings::GetInstance() | 55 CPluginSettings* CPluginSettings::GetInstance() |
57 { | 56 { |
(...skipping 25 matching lines...) Expand all Loading... |
83 s_criticalSectionLocal.Unlock(); | 82 s_criticalSectionLocal.Unlock(); |
84 | 83 |
85 return hasInstance; | 84 return hasInstance; |
86 } | 85 } |
87 | 86 |
88 bool CPluginSettings::IsPluginEnabled() const | 87 bool CPluginSettings::IsPluginEnabled() const |
89 { | 88 { |
90 return GetPluginEnabled(); | 89 return GetPluginEnabled(); |
91 } | 90 } |
92 | 91 |
93 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const | 92 std::map<std::wstring, std::wstring> CPluginSettings::GetFilterLanguageTitleList
() const |
94 { | 93 { |
95 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc
e()->FetchAvailableSubscriptions(); | 94 auto subscriptions = CPluginClient::GetInstance()->FetchAvailableSubscriptions
(); |
96 | 95 |
97 std::map<CString, CString> filterList; | 96 std::map<std::wstring, std::wstring> filterList; |
98 for (size_t i = 0; i < subscriptions.size(); i ++) | 97 for (size_t i = 0; i < subscriptions.size(); i ++) |
99 { | 98 { |
100 SubscriptionDescription it = subscriptions[i]; | 99 auto it = subscriptions[i]; |
101 filterList.insert(std::make_pair(CString(it.url.c_str()), CString(it.title.c
_str()))); | 100 filterList.insert(std::make_pair(it.url, it.title)); |
102 } | 101 } |
103 return filterList; | 102 return filterList; |
104 } | 103 } |
105 | 104 |
106 void CPluginSettings::TogglePluginEnabled() | 105 void CPluginSettings::TogglePluginEnabled() |
107 { | 106 { |
108 CPluginClient::GetInstance()->TogglePluginEnabled(); | 107 CPluginClient::GetInstance()->TogglePluginEnabled(); |
109 } | 108 } |
110 bool CPluginSettings::GetPluginEnabled() const | 109 bool CPluginSettings::GetPluginEnabled() const |
111 { | 110 { |
112 return CPluginClient::GetInstance()->GetPref(L"enabled", true); | 111 return CPluginClient::GetInstance()->GetPref(L"enabled", true); |
113 } | 112 } |
114 | 113 |
115 | |
116 void CPluginSettings::AddError(const CString& error, const CString& errorCode) | 114 void CPluginSettings::AddError(const CString& error, const CString& errorCode) |
117 { | 115 { |
118 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) | 116 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) |
119 } | 117 } |
120 | |
121 | 118 |
122 // ============================================================================ | 119 // ============================================================================ |
123 // Whitelist settings | 120 // Whitelist settings |
124 // ============================================================================ | 121 // ============================================================================ |
125 | 122 |
126 void CPluginSettings::ClearWhitelist() | 123 void CPluginSettings::ClearWhitelist() |
127 { | 124 { |
128 s_criticalSectionLocal.Lock(); | 125 s_criticalSectionLocal.Lock(); |
129 { | 126 { |
130 m_whitelistedDomains.clear(); | 127 m_whitelistedDomains.clear(); |
(...skipping 22 matching lines...) Expand all Loading... |
153 s_criticalSectionLocal.Unlock(); | 150 s_criticalSectionLocal.Unlock(); |
154 } | 151 } |
155 else | 152 else |
156 { | 153 { |
157 isRead = false; | 154 isRead = false; |
158 } | 155 } |
159 | 156 |
160 return isRead; | 157 return isRead; |
161 } | 158 } |
162 | 159 |
163 void CPluginSettings::AddWhiteListedDomain(const CString& domain) | 160 void CPluginSettings::AddWhiteListedDomain(const std::wstring& domain) |
164 { | 161 { |
165 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) | 162 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) |
166 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain)
); | 163 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain)
); |
167 } | 164 } |
168 | 165 |
169 void CPluginSettings::RemoveWhiteListedDomain(const CString& domain) | 166 void CPluginSettings::RemoveWhiteListedDomain(const std::wstring& domain) |
170 { | 167 { |
171 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain) | 168 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain) |
172 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma
in)); | 169 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma
in)); |
173 } | 170 } |
174 | 171 |
175 int CPluginSettings::GetWhiteListedDomainCount() const | 172 int CPluginSettings::GetWhiteListedDomainCount() const |
176 { | 173 { |
177 int count = 0; | 174 int count = 0; |
178 | 175 |
179 s_criticalSectionLocal.Lock(); | 176 s_criticalSectionLocal.Lock(); |
(...skipping 16 matching lines...) Expand all Loading... |
196 { | 193 { |
197 CPluginSettingsWhitelistLock lock; | 194 CPluginSettingsWhitelistLock lock; |
198 if (lock.IsLocked()) | 195 if (lock.IsLocked()) |
199 { | 196 { |
200 ReadWhitelist(true); | 197 ReadWhitelist(true); |
201 } | 198 } |
202 | 199 |
203 return true; | 200 return true; |
204 } | 201 } |
205 | 202 |
206 DWORD CPluginSettings::GetWindowsBuildNumber() | |
207 { | |
208 if (m_WindowsBuildNumber == 0) | |
209 { | |
210 OSVERSIONINFOEX osvi = {}; | |
211 osvi.dwOSVersionInfoSize = sizeof(osvi); | |
212 if (GetVersionExW(reinterpret_cast<OSVERSIONINFO*>(&osvi)) != 0) | |
213 { | |
214 m_WindowsBuildNumber = osvi.dwBuildNumber; | |
215 } | |
216 } | |
217 | |
218 return m_WindowsBuildNumber; | |
219 } | |
220 | |
221 void CPluginSettings::SetSubscription(const std::wstring& url) | 203 void CPluginSettings::SetSubscription(const std::wstring& url) |
222 { | 204 { |
223 CPluginClient::GetInstance()->SetSubscription(url); | 205 CPluginClient::GetInstance()->SetSubscription(url); |
224 RefreshWhitelist(); | 206 RefreshWhitelist(); |
225 } | 207 } |
226 | 208 |
227 CString CPluginSettings::GetSubscription() | 209 std::wstring CPluginSettings::GetSubscription() |
228 { | 210 { |
229 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc
e()->GetListedSubscriptions(); | 211 auto subscriptions = CPluginClient::GetInstance()->GetListedSubscriptions(); |
230 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc
eptionsurl", L""); | 212 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc
eptionsurl", L""); |
231 | 213 |
232 for (std::vector<SubscriptionDescription>::iterator subscription = subscriptio
ns.begin(); subscription != subscriptions.end(); subscription++) | 214 for (auto subscription = subscriptions.begin(); subscription != subscriptions.
end(); subscription++) |
233 { | 215 { |
234 if (subscription->url != aaUrl) | 216 if (subscription->url != aaUrl) |
235 { | 217 { |
236 return CString(subscription->url.c_str()); | 218 return subscription->url; |
237 } | 219 } |
238 } | 220 } |
239 return CString(L""); | 221 return std::wstring(); |
240 } | 222 } |
241 | |
242 CString CPluginSettings::GetAppLocale() | |
243 { | |
244 return ToCString(GetBrowserLanguage()); | |
245 } | |
246 | |
247 CString CPluginSettings::GetDocumentationLink() | |
248 { | |
249 return CString(CPluginClient::GetInstance()->GetDocumentationLink().c_str()); | |
250 } | |
LEFT | RIGHT |