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

Side by Side Diff: src/plugin/PluginSettings.cpp

Issue 5750789393874944: [IE] First round of ATL removal (Closed)
Patch Set: Created June 20, 2014, 9:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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(const CString domain) 23 std::wstring CreateDomainWhitelistingFilter(const std::wstring domain)
24 { 24 {
25 return std::wstring(L"@@||") + domain.GetString() + std::wstring(L"^$documen t"); 25 return L"@@||" + domain + L"^$document";
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
36 36
37 class CPluginSettingsLock : public CPluginMutex 37 class CPluginSettingsLock : public CPluginMutex
38 { 38 {
39 public: 39 public:
40 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN GS_FILE) {} 40 CPluginSettingsLock() : CPluginMutex( L"SettingsFile", PLUGIN_ERROR_MUTEX_SETT INGS_FILE ) {}
41 ~CPluginSettingsLock() {} 41 ~CPluginSettingsLock() {}
42 42
43 }; 43 };
44 44
45 45
46 class CPluginSettingsTabLock : public CPluginMutex 46 class CPluginSettingsTabLock : public CPluginMutex
47 { 47 {
48 public: 48 public:
49 CPluginSettingsTabLock() : CPluginMutex("SettingsFileTab", PLUGIN_ERROR_MUTEX_ SETTINGS_FILE_TAB) {} 49 CPluginSettingsTabLock() : CPluginMutex( L"SettingsFileTab", PLUGIN_ERROR_MUTE X_SETTINGS_FILE_TAB ) {}
50 ~CPluginSettingsTabLock() {} 50 ~CPluginSettingsTabLock() {}
51 }; 51 };
52 52
53 #ifdef SUPPORT_WHITELIST 53 #ifdef SUPPORT_WHITELIST
54 54
55 class CPluginSettingsWhitelistLock : public CPluginMutex 55 class CPluginSettingsWhitelistLock : public CPluginMutex
56 { 56 {
57 public: 57 public:
58 CPluginSettingsWhitelistLock() : CPluginMutex("SettingsFileWhitelist", PLUGIN_ ERROR_MUTEX_SETTINGS_FILE_WHITELIST) {} 58 CPluginSettingsWhitelistLock() : CPluginMutex( L"SettingsFileWhitelist", PLUGI N_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 67
68 68
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 s_criticalSectionLocal.Lock(); 110 s_criticalSectionLocal.Lock();
111 { 111 {
112 hasInstance = s_instance != NULL; 112 hasInstance = s_instance != NULL;
113 } 113 }
114 s_criticalSectionLocal.Unlock(); 114 s_criticalSectionLocal.Unlock();
115 115
116 return hasInstance; 116 return hasInstance;
117 } 117 }
118 118
119 119 std::wstring CPluginSettings::GetDataPath(const std::wstring & filename)
120
121 CString CPluginSettings::GetDataPath(const CString& filename)
122 { 120 {
123 std::wstring path = ::GetAppDataPath() + L"\\" + static_cast<LPCWSTR>(filename ); 121 return ::GetAppDataPath() + L"\\" + filename;
124 return CString(path.c_str());
125 } 122 }
126 123
127 CString CPluginSettings::GetSystemLanguage() 124 std::wstring CPluginSettings::GetSystemLanguage()
128 { 125 {
129 CString language; 126 DWORD bufSize = 256;
130 CString country; 127 std::unique_ptr< wchar_t > buffer( new wchar_t[ bufSize ] );
128 int ccBuf = GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, buff er.get(), bufSize);
129 std::wstring language( buffer.get() );
130 ccBuf = GetLocaleInfoW(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, buffer. get(), bufSize);
131 std::wstring country( buffer.get() );
131 132
132 DWORD bufSize = 256; 133 if ((country.empty()) || (language.empty()))
133 int ccBuf = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, langu age.GetBufferSetLength(bufSize), bufSize);
134 ccBuf = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, country. GetBufferSetLength(bufSize), bufSize);
135
136 if ((country.IsEmpty()) || (language.IsEmpty()))
137 { 134 {
138 return CString(); 135 return L"";
139 } 136 }
140 CString lang; 137 return language + L"-" + country;
141 lang.Append(language);
142 lang.Append(L"-");
143 lang.Append(country);
144
145 return lang;
146
147 } 138 }
148 139
149 140
150 bool CPluginSettings::IsPluginEnabled() const 141 bool CPluginSettings::IsPluginEnabled() const
151 { 142 {
152 return GetPluginEnabled(); 143 return GetPluginEnabled();
153 } 144 }
154 145
155 146
156 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const 147 std::map< std::wstring, std::wstring > CPluginSettings::GetFilterLanguageTitleLi st() const
157 { 148 {
158 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->FetchAvailableSubscriptions(); 149 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->FetchAvailableSubscriptions();
159 150
160 std::map<CString, CString> filterList; 151 std::map< std::wstring, std::wstring > filterList;
161 for (size_t i = 0; i < subscriptions.size(); i ++) 152 for (size_t i = 0; i < subscriptions.size(); i ++)
162 { 153 {
163 SubscriptionDescription it = subscriptions[i]; 154 SubscriptionDescription it = subscriptions[i];
164 filterList.insert(std::make_pair(CString(it.url.c_str()), CString(it.title.c _str()))); 155 filterList.insert(std::make_pair(it.url, it.title));
165 } 156 }
166 return filterList; 157 return filterList;
167 } 158 }
168 159
169 bool CPluginSettings::IsWorkingThread(DWORD dwThreadId) const 160 bool CPluginSettings::IsWorkingThread(DWORD dwThreadId) const
170 { 161 {
171 if (dwThreadId == 0) 162 if (dwThreadId == 0)
172 { 163 {
173 dwThreadId = ::GetCurrentThreadId(); 164 dwThreadId = ::GetCurrentThreadId();
174 } 165 }
(...skipping 13 matching lines...) Expand all
188 void CPluginSettings::TogglePluginEnabled() 179 void CPluginSettings::TogglePluginEnabled()
189 { 180 {
190 CPluginClient::GetInstance()->TogglePluginEnabled(); 181 CPluginClient::GetInstance()->TogglePluginEnabled();
191 } 182 }
192 bool CPluginSettings::GetPluginEnabled() const 183 bool CPluginSettings::GetPluginEnabled() const
193 { 184 {
194 return CPluginClient::GetInstance()->GetPref(L"enabled", true); 185 return CPluginClient::GetInstance()->GetPref(L"enabled", true);
195 } 186 }
196 187
197 188
198 void CPluginSettings::AddError(const CString& error, const CString& errorCode) 189 void CPluginSettings::AddError(const std::wstring & error, const std::wstring & errorCode)
199 { 190 {
200 DEBUG_SETTINGS(L"SettingsTab::AddError error:" + error + " code:" + errorCode) 191 DEBUG_SETTINGS( L"SettingsTab::AddError error:" + error + L" code:" + errorCod e )
201 } 192 }
202 193
203 194
204 // ============================================================================ 195 // ============================================================================
205 // Whitelist settings 196 // Whitelist settings
206 // ============================================================================ 197 // ============================================================================
207 198
208 #ifdef SUPPORT_WHITELIST 199 #ifdef SUPPORT_WHITELIST
209 200
210 void CPluginSettings::ClearWhitelist() 201 void CPluginSettings::ClearWhitelist()
211 { 202 {
212 s_criticalSectionLocal.Lock(); 203 s_criticalSectionLocal.Lock();
213 { 204 {
214 m_whitelistedDomains.clear(); 205 m_whitelistedDomains.clear();
215 } 206 }
216 s_criticalSectionLocal.Unlock(); 207 s_criticalSectionLocal.Unlock();
217 } 208 }
218 209
219 210
220 bool CPluginSettings::ReadWhitelist(bool isDebug) 211 bool CPluginSettings::ReadWhitelist(bool isDebug)
221 { 212 {
222 bool isRead = true; 213 bool isRead = true;
223 214
224 DEBUG_SETTINGS("SettingsWhitelist::Read") 215 DEBUG_SETTINGS("SettingsWhitelist::Read")
225 216
226 if (isDebug) 217 if (isDebug)
227 { 218 {
228 DEBUG_GENERAL("*** Loading whitelist settings"); 219 DEBUG_GENERAL(L"*** Loading whitelist settings");
229 } 220 }
230 221
231 CPluginSettingsWhitelistLock lock; 222 CPluginSettingsWhitelistLock lock;
232 if (lock.IsLocked()) 223 if (lock.IsLocked())
233 { 224 {
234 ClearWhitelist(); 225 ClearWhitelist();
235 226
236 s_criticalSectionLocal.Lock(); 227 s_criticalSectionLocal.Lock();
237 m_whitelistedDomains = CPluginClient::GetInstance()->GetExceptionDomains() ; 228 m_whitelistedDomains = CPluginClient::GetInstance()->GetExceptionDomains() ;
238 s_criticalSectionLocal.Unlock(); 229 s_criticalSectionLocal.Unlock();
239 } 230 }
240 else 231 else
241 { 232 {
242 isRead = false; 233 isRead = false;
243 } 234 }
244 235
245 return isRead; 236 return isRead;
246 } 237 }
247 238
248 239
249 void CPluginSettings::AddWhiteListedDomain(const CString& domain) 240 void CPluginSettings::AddWhiteListedDomain(const std::wstring & domain)
250 { 241 {
251 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) 242 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
252 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) ); 243 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) );
253 } 244 }
254 245
255 void CPluginSettings::RemoveWhiteListedDomain(const CString& domain) 246 void CPluginSettings::RemoveWhiteListedDomain(const std::wstring & domain)
256 { 247 {
257 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain) 248 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain)
258 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in)); 249 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in));
259 } 250 }
260 251
261 int CPluginSettings::GetWhiteListedDomainCount() const 252 int CPluginSettings::GetWhiteListedDomainCount() const
262 { 253 {
263 int count = 0; 254 int count = 0;
264 255
265 s_criticalSectionLocal.Lock(); 256 s_criticalSectionLocal.Lock();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 300
310 return m_WindowsBuildNumber; 301 return m_WindowsBuildNumber;
311 } 302 }
312 303
313 void CPluginSettings::SetSubscription(const std::wstring& url) 304 void CPluginSettings::SetSubscription(const std::wstring& url)
314 { 305 {
315 CPluginClient::GetInstance()->SetSubscription(url); 306 CPluginClient::GetInstance()->SetSubscription(url);
316 RefreshWhitelist(); 307 RefreshWhitelist();
317 } 308 }
318 309
319 CString CPluginSettings::GetSubscription() 310 std::wstring CPluginSettings::GetSubscription()
320 { 311 {
321 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions(); 312 std::vector<SubscriptionDescription> subscriptions = CPluginClient::GetInstanc e()->GetListedSubscriptions();
322 if (subscriptions.size() > 0) 313 if (subscriptions.size() > 0)
323 return CString(subscriptions.front().url.c_str()); 314 return subscriptions.front().url;
324 else 315 else
325 return CString(L""); 316 return L"";
326 } 317 }
327 318
328 CString CPluginSettings::GetAppLocale() 319 std::wstring CPluginSettings::GetAppLocale()
329 { 320 {
330 return CPluginSystem::GetInstance()->GetBrowserLanguage(); 321 return CPluginSystem::GetInstance()->GetBrowserLanguage();
331 } 322 }
332 323
333 CString CPluginSettings::GetDocumentationLink() 324 std::wstring CPluginSettings::GetDocumentationLink()
334 { 325 {
335 return CString(CPluginClient::GetInstance()->GetDocumentationLink().c_str()); 326 return CPluginClient::GetInstance()->GetDocumentationLink();
336 } 327 }
337 328
338 329
339 330
340 #endif // SUPPORT_WHITELIST 331 #endif // SUPPORT_WHITELIST
OLDNEW

Powered by Google App Engine
This is Rietveld