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

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

Issue 5187613258416128: Issue #1234 - Rewrite internals of debug facility (Closed)
Left Patch Set: small fixes from comment #7 Created May 19, 2015, 3:13 p.m.
Right Patch Set: rebase only Created Nov. 26, 2015, 1:02 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
LEFTRIGHT
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 <Wbemidl.h>
21 #include <time.h>
22 #include "PluginSettings.h" 20 #include "PluginSettings.h"
23 #include "PluginClient.h" 21 #include "AdblockPlusClient.h"
24 #include "PluginSystem.h" 22 #include "PluginSystem.h"
25 #include "PluginFilter.h"
26 #include "PluginMutex.h" 23 #include "PluginMutex.h"
27 #include "../shared/Utils.h" 24 #include "../shared/Utils.h"
28 #include <memory>
29
30
31 // IE functions
32 #pragma comment(lib, "iepmapi.lib")
33
34 #include <knownfolders.h>
35 25
36 namespace 26 namespace
37 { 27 {
38 std::wstring CreateDomainWhitelistingFilter(const CString& domain) 28 std::wstring CreateDomainWhitelistingFilter(const std::wstring& domain)
39 { 29 {
40 return L"@@||" + ToWstring(domain) + L"^$document"; 30 return L"@@||" + domain + L"^$document";
41 } 31 }
42 } 32 }
43
44 class TSettings
45 {
46 DWORD processorId;
47
48 char sPluginId[44];
49 };
50 33
51 class CPluginSettingsWhitelistLock : public CPluginMutex 34 class CPluginSettingsWhitelistLock : public CPluginMutex
52 { 35 {
53 public: 36 public:
54 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN _ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} 37 CPluginSettingsWhitelistLock() : CPluginMutex(L"SettingsFileWhitelist", PLUGIN _ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {}
55 ~CPluginSettingsWhitelistLock() {} 38 ~CPluginSettingsWhitelistLock() {}
56 }; 39 };
57 40
58 CPluginSettings* CPluginSettings::s_instance = NULL; 41 CPluginSettings* CPluginSettings::s_instance = NULL;
59 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal; 42 CComAutoCriticalSection CPluginSettings::s_criticalSectionLocal;
60 43
61 CPluginSettings::CPluginSettings() 44 CPluginSettings::CPluginSettings()
62 { 45 {
63 s_instance = NULL; 46 s_instance = NULL;
64 m_WindowsBuildNumber = 0;
65 ClearWhitelist(); 47 ClearWhitelist();
66 } 48 }
67 49
68 CPluginSettings::~CPluginSettings() 50 CPluginSettings::~CPluginSettings()
69 { 51 {
70 s_instance = NULL; 52 s_instance = NULL;
71 } 53 }
72 54
73 CPluginSettings* CPluginSettings::GetInstance() 55 CPluginSettings* CPluginSettings::GetInstance()
74 { 56 {
(...skipping 25 matching lines...) Expand all
100 s_criticalSectionLocal.Unlock(); 82 s_criticalSectionLocal.Unlock();
101 83
102 return hasInstance; 84 return hasInstance;
103 } 85 }
104 86
105 bool CPluginSettings::IsPluginEnabled() const 87 bool CPluginSettings::IsPluginEnabled() const
106 { 88 {
107 return GetPluginEnabled(); 89 return GetPluginEnabled();
108 } 90 }
109 91
110 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const 92 std::map<std::wstring, std::wstring> CPluginSettings::GetFilterLanguageTitleList () const
111 { 93 {
112 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->FetchAvailableSubscriptions(); 94 auto subscriptions = CPluginClient::GetInstance()->FetchAvailableSubscriptions ();
113 95
114 std::map<CString, CString> filterList; 96 std::map<std::wstring, std::wstring> filterList;
115 for (size_t i = 0; i < subscriptions.size(); i ++) 97 for (size_t i = 0; i < subscriptions.size(); i ++)
116 { 98 {
117 SubscriptionDescription it = subscriptions[i]; 99 auto it = subscriptions[i];
118 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));
119 } 101 }
120 return filterList; 102 return filterList;
121 } 103 }
122 104
123 void CPluginSettings::TogglePluginEnabled() 105 void CPluginSettings::TogglePluginEnabled()
124 { 106 {
125 CPluginClient::GetInstance()->TogglePluginEnabled(); 107 CPluginClient::GetInstance()->TogglePluginEnabled();
126 } 108 }
127 bool CPluginSettings::GetPluginEnabled() const 109 bool CPluginSettings::GetPluginEnabled() const
128 { 110 {
129 return CPluginClient::GetInstance()->GetPref(L"enabled", true); 111 return CPluginClient::GetInstance()->GetPref(L"enabled", true);
130 } 112 }
131 113
132
133 void CPluginSettings::AddError(const CString& error, const CString& errorCode) 114 void CPluginSettings::AddError(const CString& error, const CString& errorCode)
134 { 115 {
135 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) 116 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode)
136 } 117 }
137
138 118
139 // ============================================================================ 119 // ============================================================================
140 // Whitelist settings 120 // Whitelist settings
141 // ============================================================================ 121 // ============================================================================
142 122
143 void CPluginSettings::ClearWhitelist() 123 void CPluginSettings::ClearWhitelist()
144 { 124 {
145 s_criticalSectionLocal.Lock(); 125 s_criticalSectionLocal.Lock();
146 { 126 {
147 m_whitelistedDomains.clear(); 127 m_whitelistedDomains.clear();
(...skipping 22 matching lines...) Expand all
170 s_criticalSectionLocal.Unlock(); 150 s_criticalSectionLocal.Unlock();
171 } 151 }
172 else 152 else
173 { 153 {
174 isRead = false; 154 isRead = false;
175 } 155 }
176 156
177 return isRead; 157 return isRead;
178 } 158 }
179 159
180 void CPluginSettings::AddWhiteListedDomain(const CString& domain) 160 void CPluginSettings::AddWhiteListedDomain(const std::wstring& domain)
181 { 161 {
182 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) 162 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
183 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) ); 163 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) );
184 } 164 }
185 165
186 void CPluginSettings::RemoveWhiteListedDomain(const CString& domain) 166 void CPluginSettings::RemoveWhiteListedDomain(const std::wstring& domain)
187 { 167 {
188 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain) 168 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain)
189 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in)); 169 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in));
190 } 170 }
191 171
192 int CPluginSettings::GetWhiteListedDomainCount() const 172 int CPluginSettings::GetWhiteListedDomainCount() const
193 { 173 {
194 int count = 0; 174 int count = 0;
195 175
196 s_criticalSectionLocal.Lock(); 176 s_criticalSectionLocal.Lock();
(...skipping 16 matching lines...) Expand all
213 { 193 {
214 CPluginSettingsWhitelistLock lock; 194 CPluginSettingsWhitelistLock lock;
215 if (lock.IsLocked()) 195 if (lock.IsLocked())
216 { 196 {
217 ReadWhitelist(true); 197 ReadWhitelist(true);
218 } 198 }
219 199
220 return true; 200 return true;
221 } 201 }
222 202
223 DWORD CPluginSettings::GetWindowsBuildNumber()
224 {
225 if (m_WindowsBuildNumber == 0)
226 {
227 OSVERSIONINFOEX osvi = {};
228 osvi.dwOSVersionInfoSize = sizeof(osvi);
229 if (GetVersionExW(reinterpret_cast<OSVERSIONINFO*>(&osvi)) != 0)
230 {
231 m_WindowsBuildNumber = osvi.dwBuildNumber;
232 }
233 }
234
235 return m_WindowsBuildNumber;
236 }
237
238 void CPluginSettings::SetSubscription(const std::wstring& url) 203 void CPluginSettings::SetSubscription(const std::wstring& url)
239 { 204 {
240 CPluginClient::GetInstance()->SetSubscription(url); 205 CPluginClient::GetInstance()->SetSubscription(url);
241 RefreshWhitelist(); 206 RefreshWhitelist();
242 } 207 }
243 208
244 CString CPluginSettings::GetSubscription() 209 std::wstring CPluginSettings::GetSubscription()
245 { 210 {
246 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions(); 211 auto subscriptions = CPluginClient::GetInstance()->GetListedSubscriptions();
247 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc eptionsurl", L""); 212 std::wstring aaUrl = CPluginClient::GetInstance()->GetPref(L"subscriptions_exc eptionsurl", L"");
248 213
249 for (std::vector<SubscriptionDescription>::iterator subscription = subscriptio ns.begin(); subscription != subscriptions.end(); subscription++) 214 for (auto subscription = subscriptions.begin(); subscription != subscriptions. end(); subscription++)
250 { 215 {
251 if (subscription->url != aaUrl) 216 if (subscription->url != aaUrl)
252 { 217 {
253 return CString(subscription->url.c_str()); 218 return subscription->url;
254 } 219 }
255 } 220 }
256 return CString(L""); 221 return std::wstring();
257 } 222 }
258
259 CString CPluginSettings::GetAppLocale()
260 {
261 return ToCString(GetBrowserLanguage());
262 }
263
264 CString CPluginSettings::GetDocumentationLink()
265 {
266 return CString(CPluginClient::GetInstance()->GetDocumentationLink().c_str());
267 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld