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

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

Issue 10948032: Fix domain-based whitelisting (Closed)
Patch Set: Created June 14, 2013, 2:44 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 "PluginIniFileW.h" 5 #include "PluginIniFileW.h"
6 #include "PluginIniFile.h" 6 #include "PluginIniFile.h"
7 #include "PluginSettings.h" 7 #include "PluginSettings.h"
8 #include "PluginClient.h" 8 #include "PluginClient.h"
9 #include "PluginChecksum.h" 9 #include "PluginChecksum.h"
10 #include "PluginSystem.h" 10 #include "PluginSystem.h"
11 #ifdef SUPPORT_FILTER 11 #ifdef SUPPORT_FILTER
12 #include "PluginFilter.h" 12 #include "PluginFilter.h"
13 #endif 13 #endif
14 #include "PluginMutex.h" 14 #include "PluginMutex.h"
15 #include "PluginHttpRequest.h" 15 #include "PluginHttpRequest.h"
16 #include "../shared/Utils.h" 16 #include "../shared/Utils.h"
17 #include <memory> 17 #include <memory>
18 18
19 19
20 // IE functions 20 // IE functions
21 #pragma comment(lib, "iepmapi.lib") 21 #pragma comment(lib, "iepmapi.lib")
22 22
23 #include <knownfolders.h> 23 #include <knownfolders.h>
24 24
25 namespace
26 {
27 std::string CreateDomainWhitelistingFilter(CString domain)
28 {
29 return std::string("@@||").append(CW2A(domain)).append("^$document");
30 }
31 }
32
25 class TSettings 33 class TSettings
26 { 34 {
27 DWORD processorId; 35 DWORD processorId;
28 36
29 char sPluginId[44]; 37 char sPluginId[44];
30 }; 38 };
31 39
32 40
33 class CPluginSettingsLock : public CPluginMutex 41 class CPluginSettingsLock : public CPluginMutex
34 { 42 {
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 } 1271 }
1264 1272
1265 return isRead; 1273 return isRead;
1266 } 1274 }
1267 1275
1268 1276
1269 void CPluginSettings::AddWhiteListedDomain(const CString& domain) 1277 void CPluginSettings::AddWhiteListedDomain(const CString& domain)
1270 { 1278 {
1271 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain) 1279 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
1272 1280
1273 bool isNewVersion = false; 1281 RefreshWhitelist();
1274 bool isForcingUpdateOnStart = false; 1282 if (IsWhiteListedDomain(domain))
1283 return;
Wladimir Palant 2013/06/17 09:33:56 I think that this code block is unnecessary and me
Felix Dahlke 2013/06/17 11:19:01 Done.
1275 1284
1276 CPluginSettingsWhitelistLock lock; 1285 s_criticalSectionLocal.Lock();
Wladimir Palant 2013/06/17 09:33:56 Please remove the pointless critical section use h
Felix Dahlke 2013/06/17 11:19:01 Done.
1277 if (lock.IsLocked()) 1286 CPluginClient::GetInstance()->AddFilter(CreateDomainWhitelistingFilter(domain) );
1278 { 1287 s_criticalSectionLocal.Unlock();
1279 ReadWhitelist(false);
1280
1281 std::string newDomain = CW2A(domain, CP_UTF8);
1282
1283 //Domain already present?
1284 if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD omain) != m_whitelistedDomains.end())
1285 {
1286 return;
1287 }
1288 s_criticalSectionLocal.Lock();
1289 CPluginClient::GetInstance()->AddFilter(std::string("@@||").append(CW2A(doma in)).append("^$document"));
1290 s_criticalSectionLocal.Unlock();
1291
1292 }
1293
1294 if (isForcingUpdateOnStart)
1295 {
1296 ForceConfigurationUpdateOnStart();
1297 }
1298 } 1288 }
1299 1289
1290 void CPluginSettings::RemoveWhiteListedDomain(const CString& domain)
1291 {
1292 DEBUG_SETTINGS("SettingsWhitelist::RemoveWhiteListedDomain domain:" + domain)
1293
1294 RefreshWhitelist();
1295 if (!IsWhiteListedDomain(domain))
1296 return;
Wladimir Palant 2013/06/17 09:33:56 I think that this code block is unnecessary and me
Felix Dahlke 2013/06/17 11:19:01 Done.
1297
1298 s_criticalSectionLocal.Lock();
Wladimir Palant 2013/06/17 09:33:56 Please remove the pointless critical section use h
Felix Dahlke 2013/06/17 11:19:01 Done.
1299 CPluginClient::GetInstance()->RemoveFilter(CreateDomainWhitelistingFilter(doma in));
1300 s_criticalSectionLocal.Unlock();
1301 }
1300 1302
1301 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const 1303 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const
1302 { 1304 {
1303 bool bIsWhiteListed; 1305 bool bIsWhiteListed;
1304 1306
1305 s_criticalSectionLocal.Lock(); 1307 s_criticalSectionLocal.Lock();
1306 { 1308 {
1307 bIsWhiteListed = std::find(m_whitelistedDomains.begin(), m_whitelistedDomain s.end(), std::string(CW2A(domain, CP_UTF8))) != m_whitelistedDomains.end(); 1309 bIsWhiteListed = std::find(m_whitelistedDomains.begin(), m_whitelistedDomain s.end(), std::string(CW2A(domain, CP_UTF8))) != m_whitelistedDomains.end();
1308 } 1310 }
1309 s_criticalSectionLocal.Unlock(); 1311 s_criticalSectionLocal.Unlock();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 return CString(L""); 1398 return CString(L"");
1397 } 1399 }
1398 1400
1399 1401
1400 void CPluginSettings::RefreshFilterlist() 1402 void CPluginSettings::RefreshFilterlist()
1401 { 1403 {
1402 CPluginClient::GetInstance()->UpdateAllSubscriptions(); 1404 CPluginClient::GetInstance()->UpdateAllSubscriptions();
1403 } 1405 }
1404 1406
1405 #endif // SUPPORT_WHITELIST 1407 #endif // SUPPORT_WHITELIST
OLDNEW

Powered by Google App Engine
This is Rietveld