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

Delta Between Two Patch Sets: Shared/PluginSettings.cpp

Issue 9998007: Initial libadblockplus integration (Closed)
Left Patch Set: Subscription changes and filter management cleanup Created April 5, 2013, 1:56 a.m.
Right Patch Set: Whitelisting management Created April 11, 2013, 9:06 a.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
« no previous file with change/comment | « Shared/PluginSettings.h ('k') | Shared/PluginTabBase.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 "PluginDictionary.h" 8 #include "PluginDictionary.h"
9 #include "PluginClient.h" 9 #include "PluginClient.h"
10 #include "PluginChecksum.h" 10 #include "PluginChecksum.h"
11 #include "PluginSystem.h" 11 #include "PluginSystem.h"
12 #ifdef SUPPORT_FILTER 12 #ifdef SUPPORT_FILTER
13 #include "PluginFilter.h" 13 #include "PluginFilter.h"
14 #endif 14 #endif
15 #include "PluginMutex.h" 15 #include "PluginMutex.h"
16 #include "PluginHttpRequest.h" 16 #include "PluginHttpRequest.h"
17 #include <memory>
18
17 19
18 // IE functions 20 // IE functions
19 #pragma comment(lib, "iepmapi.lib") 21 #pragma comment(lib, "iepmapi.lib")
20 22
21 #include <knownfolders.h> 23 #include <knownfolders.h>
22 24
23 class TSettings 25 class TSettings
24 { 26 {
25 DWORD processorId; 27 DWORD processorId;
26 28
27 char sPluginId[44]; 29 char sPluginId[44];
28 }; 30 };
31
32 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription s);
29 33
30 34
31 class CPluginSettingsLock : public CPluginMutex 35 class CPluginSettingsLock : public CPluginMutex
32 { 36 {
33 public: 37 public:
34 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN GS_FILE) {} 38 CPluginSettingsLock() : CPluginMutex("SettingsFile", PLUGIN_ERROR_MUTEX_SETTIN GS_FILE) {}
35 ~CPluginSettingsLock() {} 39 ~CPluginSettingsLock() {}
36 40
37 }; 41 };
38 42
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 220
217 CPluginSettings* CPluginSettings::GetInstance() 221 CPluginSettings* CPluginSettings::GetInstance()
218 { 222 {
219 CPluginSettings* instance = NULL; 223 CPluginSettings* instance = NULL;
220 224
221 s_criticalSectionLocal.Lock(); 225 s_criticalSectionLocal.Lock();
222 { 226 {
223 if ((!s_instance) || (s_isLightOnly)) 227 if ((!s_instance) || (s_isLightOnly))
224 { 228 {
225 s_instance = new CPluginSettings(); 229 s_instance = new CPluginSettings();
230 CPluginClient::GetInstance()->GetFilterEngine()->FetchAvailableSubscriptio ns((AdblockPlus::SubscriptionsCallback)&SubsCallback);
226 s_isLightOnly = false; 231 s_isLightOnly = false;
227 } 232 }
228 233
229 instance = s_instance; 234 instance = s_instance;
230 } 235 }
231 s_criticalSectionLocal.Unlock(); 236 s_criticalSectionLocal.Unlock();
232 237
233 return instance; 238 return instance;
234 } 239 }
235 240
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 { 733 {
729 SetString(key, value ? "true":"false"); 734 SetString(key, value ? "true":"false");
730 } 735 }
731 736
732 737
733 bool CPluginSettings::IsPluginEnabled() const 738 bool CPluginSettings::IsPluginEnabled() const
734 { 739 {
735 return m_isPluginEnabledTab; 740 return m_isPluginEnabledTab;
736 } 741 }
737 742
743 static void SubsCallback(std::vector<AdblockPlus::SubscriptionPtr>& subscription s)
744 {
745 CPluginSettings::GetInstance()->m_subscriptions = subscriptions;
746 return;
747 }
738 748
739 749
740 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const 750 std::map<CString, CString> CPluginSettings::GetFilterLanguageTitleList() const
741 { 751 {
742 std::map<CString, CString> filterList; 752 std::map<CString, CString> filterList;
743 std::vector<Subscription> subs = CPluginClient::GetInstance()->GetFilterEngine ()->GetSubscriptions(); 753 for (int i = 0; i < m_subscriptions.size(); i ++)
744 for (std::vector<Subscription>::iterator it = subs.begin(); it != subs.end(); ++it)
745 { 754 {
746 CString title = CA2T((*it).title.c_str(), CP_UTF8); 755 AdblockPlus::SubscriptionPtr it = m_subscriptions[i];
747 CString url = CA2T((*it).url.c_str(), CP_UTF8); 756 std::string title = "";
748 filterList.insert(std::make_pair(title, url)); 757 std::string url = "";
758
759 //TODO: Property for language name?
760 title = it.get()->GetProperty("title", title);
761 url = it.get()->GetProperty("url", url);
762
763 filterList.insert(std::make_pair(CString(CA2T(url.c_str(), CP_UTF8)), CStrin g(CA2T(title.c_str(), CP_UTF8))));
749 } 764 }
750 return filterList; 765 return filterList;
751 } 766 }
752 767
753 768
754 bool CPluginSettings::Write(bool isDebug) 769 bool CPluginSettings::Write(bool isDebug)
755 { 770 {
756 bool isWritten = true; 771 bool isWritten = true;
757 772
758 if (!m_isDirty) 773 if (!m_isDirty)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 810
796 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION); 811 IncrementTabVersion(SETTING_TAB_SETTINGS_VERSION);
797 } 812 }
798 else 813 else
799 { 814 {
800 isWritten = false; 815 isWritten = false;
801 } 816 }
802 817
803 return isWritten; 818 return isWritten;
804 } 819 }
805
806 #ifdef SUPPORT_WHITELIST
807
808 void CPluginSettings::AddDomainToHistory(const CString& domain)
809 {
810 if (!CPluginClient::IsValidDomain(domain))
811 {
812 return;
813 }
814
815 // Delete domain
816 s_criticalSectionDomainHistory.Lock();
817 {
818 for (TDomainHistory::iterator it = m_domainHistory.begin(); it != m_domainHi story.end(); ++it)
819 {
820 if (it->first == domain)
821 {
822 m_domainHistory.erase(it);
823 break;
824 }
825 }
826
827 // Get whitelist reason
828 int reason = 0;
829
830 s_criticalSectionLocal.Lock();
831 {
832 TDomainList::iterator it = m_whitelist.find(domain);
833 if (it != m_whitelist.end())
834 {
835 reason = it->second;
836 }
837 else
838 {
839 reason = 3;
840 }
841 }
842 s_criticalSectionLocal.Unlock();
843
844 // Delete domain, if history is too long
845 if (m_domainHistory.size() >= DOMAIN_HISTORY_MAX_COUNT)
846 {
847 m_domainHistory.erase(m_domainHistory.begin());
848 }
849
850 m_domainHistory.push_back(std::make_pair(domain, reason));
851 }
852 s_criticalSectionDomainHistory.Unlock();
853 }
854
855
856 TDomainHistory CPluginSettings::GetDomainHistory() const
857 {
858 TDomainHistory domainHistory;
859
860 s_criticalSectionDomainHistory.Lock();
861 {
862 domainHistory = m_domainHistory;
863 }
864 s_criticalSectionDomainHistory.Unlock();
865
866 return domainHistory;
867 }
868
869 #endif // SUPPORT_WHITELIST
870 820
871 821
872 bool CPluginSettings::IsPluginUpdateAvailable() const 822 bool CPluginSettings::IsPluginUpdateAvailable() const
873 { 823 {
874 bool isAvailable = Has(SETTING_PLUGIN_UPDATE_VERSION); 824 bool isAvailable = Has(SETTING_PLUGIN_UPDATE_VERSION);
875 if (isAvailable) 825 if (isAvailable)
876 { 826 {
877 CString newVersion = GetString(SETTING_PLUGIN_UPDATE_VERSION); 827 CString newVersion = GetString(SETTING_PLUGIN_UPDATE_VERSION);
878 CString curVersion = IEPLUGIN_VERSION; 828 CString curVersion = IEPLUGIN_VERSION;
879 829
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1548 // ============================================================================ 1498 // ============================================================================
1549 // Whitelist settings 1499 // Whitelist settings
1550 // ============================================================================ 1500 // ============================================================================
1551 1501
1552 #ifdef SUPPORT_WHITELIST 1502 #ifdef SUPPORT_WHITELIST
1553 1503
1554 void CPluginSettings::ClearWhitelist() 1504 void CPluginSettings::ClearWhitelist()
1555 { 1505 {
1556 s_criticalSectionLocal.Lock(); 1506 s_criticalSectionLocal.Lock();
1557 { 1507 {
1558 m_whitelist.clear(); 1508 m_whitelistedDomains.clear();
1559 m_whitelistToGo.clear();
1560 } 1509 }
1561 s_criticalSectionLocal.Unlock(); 1510 s_criticalSectionLocal.Unlock();
1562 } 1511 }
1563 1512
1564 1513
1565 bool CPluginSettings::ReadWhitelist(bool isDebug) 1514 bool CPluginSettings::ReadWhitelist(bool isDebug)
1566 { 1515 {
1567 bool isRead = true; 1516 bool isRead = true;
1568 1517
1569 DEBUG_SETTINGS("SettingsWhitelist::Read") 1518 DEBUG_SETTINGS("SettingsWhitelist::Read")
1570 1519
1571 if (isDebug) 1520 if (isDebug)
1572 { 1521 {
1573 DEBUG_GENERAL("*** Loading whitelist settings:" + m_settingsFileWhitelist- >GetFilePath()); 1522 DEBUG_GENERAL("*** Loading whitelist settings");
1574 } 1523 }
1575 1524
1576 CPluginSettingsWhitelistLock lock; 1525 CPluginSettingsWhitelistLock lock;
1577 if (lock.IsLocked()) 1526 if (lock.IsLocked())
1578 { 1527 {
1579 isRead = m_settingsFileWhitelist->Read(); 1528 ClearWhitelist();
1580 if (isRead) 1529
1581 { 1530 s_criticalSectionLocal.Lock();
1582 if (m_settingsFileWhitelist->IsValidChecksum()) 1531 std::vector<AdblockPlus::FilterPtr> filters = CPluginClient::GetInstance() ->GetFilterEngine()->GetListedFilters();
1532 for (int i = 0; i < filters.size(); i ++)
1533 {
1534 if (filters[i]->GetProperty("type", AdblockPlus::Filter::Type::TYPE_INVA LID) == AdblockPlus::Filter::Type::TYPE_EXCEPTION)
1583 { 1535 {
1584 ClearWhitelist(); 1536 std::string text = filters[i]->GetProperty("text", "");
1585 1537 //@@||example.com^$document
1586 s_criticalSectionLocal.Lock(); 1538 size_t endPos = text.rfind("^$document");
1539 if (endPos != std::string::npos)
1587 { 1540 {
1588 // Unpack white list 1541 size_t startPos = text.find("@@||") + 4;
1589 CPluginIniFileW::TSectionData whitelist = m_settingsFileWhitelist->G etSectionData("Whitelist"); 1542 if (startPos != std::string::npos)
1590 int domainCount = 0;
1591 bool bContinue = true;
1592
1593 do
1594 { 1543 {
1595 CString domainCountStr; 1544 m_whitelistedDomains.push_back(text.substr(startPos, endPos - star tPos));
1596 domainCountStr.Format(L"%d", ++domainCount); 1545 }
1597
1598 CPluginIniFileW::TSectionData::iterator domainIt = whitelist.find( L"domain" + domainCountStr);
1599 CPluginIniFileW::TSectionData::iterator reasonIt = whitelist.find( L"domain" + domainCountStr + L"r");
1600
1601 if (bContinue = (domainIt != whitelist.end() && reasonIt != whitel ist.end()))
1602 {
1603 m_whitelist[domainIt->second] = _wtoi(reasonIt->second);
1604 }
1605
1606 } while (bContinue);
1607
1608 // Unpack white list
1609 whitelist = m_settingsFileWhitelist->GetSectionData("Whitelist togo" );
1610 domainCount = 0;
1611 bContinue = true;
1612
1613 do
1614 {
1615 CString domainCountStr;
1616 domainCountStr.Format(L"%d", ++domainCount);
1617
1618 CPluginIniFileW::TSectionData::iterator domainIt = whitelist.find( L"domain" + domainCountStr);
1619 CPluginIniFileW::TSectionData::iterator reasonIt = whitelist.find( L"domain" + domainCountStr + L"r");
1620
1621 if (bContinue = (domainIt != whitelist.end() && reasonIt != whitel ist.end()))
1622 {
1623 m_whitelistToGo[domainIt->second] = _wtoi(reasonIt->second);
1624 }
1625
1626 } while (bContinue);
1627 } 1546 }
1628 s_criticalSectionLocal.Unlock();
1629 } 1547 }
1630 else 1548 }
1631 { 1549 s_criticalSectionLocal.Unlock();
1632 DEBUG_SETTINGS("SettingsWhitelist:Invalid checksum - Deleting file")
1633
1634 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERRO R_SETTINGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_READ_CHECKSUM, "SettingsWhiteli st::Read - Checksum")
1635 isRead = false;
1636 m_isDirtyWhitelist = true;
1637 }
1638 }
1639 else if (m_settingsFileWhitelist->GetLastError() == ERROR_FILE_NOT_FOUND)
1640 {
1641 m_isDirtyWhitelist = true;
1642 }
1643 else
1644 {
1645 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERROR_SE TTINGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_READ, "SettingsWhitelist::Read")
1646 }
1647 } 1550 }
1648 else 1551 else
1649 { 1552 {
1650 isRead = false; 1553 isRead = false;
1651 } 1554 }
1652 1555
1653 // Write file in case it is dirty
1654 WriteWhitelist(isDebug);
1655
1656 return isRead; 1556 return isRead;
1657 } 1557 }
1658 1558
1659 1559
1660 bool CPluginSettings::WriteWhitelist(bool isDebug) 1560 void CPluginSettings::AddWhiteListedDomain(const CString& domain)
1661 { 1561 {
1662 bool isWritten = true; 1562 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
1663 1563
1664 if (!m_isDirtyWhitelist) 1564 bool isNewVersion = false;
1665 { 1565 bool isForcingUpdateOnStart = false;
1666 return isWritten;
1667 }
1668
1669 if (isDebug)
1670 {
1671 DEBUG_GENERAL("*** Writing changed whitelist settings")
1672 }
1673 1566
1674 CPluginSettingsWhitelistLock lock; 1567 CPluginSettingsWhitelistLock lock;
1675 if (lock.IsLocked()) 1568 if (lock.IsLocked())
1676 { 1569 {
1677 m_settingsFileWhitelist->Clear(); 1570 ReadWhitelist(false);
1678 1571
1572 std::string newDomain = CW2A(domain, CP_UTF8);
1573
1574 //Domain already present?
1575 if (std::find(m_whitelistedDomains.begin(), m_whitelistedDomains.end(), newD omain) != m_whitelistedDomains.end())
1576 {
1577 return;
1578 }
1679 s_criticalSectionLocal.Lock(); 1579 s_criticalSectionLocal.Lock();
1680 { 1580 {
1681 // White list 1581 AdblockPlus::FilterPtr whitelistFilter = CPluginClient::GetInstance()->Get FilterEngine()->GetFilter(std::string("@@||").append(CW2A(domain)).append("^$doc ument"));
1682 int whitelistCount = 0; 1582 whitelistFilter->AddToList();
1683 CPluginIniFileW::TSectionData whitelist;
1684
1685 for (TDomainList::iterator it = m_whitelist.begin(); it != m_whitelist.end (); ++it)
1686 {
1687 CString whitelistCountStr;
1688 whitelistCountStr.Format(L"%d", ++whitelistCount);
1689
1690 CString reason;
1691 reason.Format(L"%d", it->second);
1692
1693 whitelist[L"domain" + whitelistCountStr] = it->first;
1694 whitelist[L"domain" + whitelistCountStr + L"r"] = reason;
1695 }
1696
1697 m_settingsFileWhitelist->UpdateSection("Whitelist", whitelist);
1698
1699 // White list (not yet committed)
1700 whitelistCount = 0;
1701 whitelist.clear();
1702
1703 for (TDomainList::iterator it = m_whitelistToGo.begin(); it != m_whitelist ToGo.end(); ++it)
1704 {
1705 CString whitelistCountStr;
1706 whitelistCountStr.Format(L"%d", ++whitelistCount);
1707
1708 CString reason;
1709 reason.Format(L"%d", it->second);
1710
1711 whitelist[L"domain" + whitelistCountStr] = it->first;
1712 whitelist[L"domain" + whitelistCountStr + L"r"] = reason;
1713 }
1714
1715 m_settingsFileWhitelist->UpdateSection("Whitelist togo", whitelist);
1716 } 1583 }
1717 s_criticalSectionLocal.Unlock(); 1584 s_criticalSectionLocal.Unlock();
1718 1585
1719 // Write file
1720 isWritten = m_settingsFileWhitelist->Write();
1721 if (!isWritten)
1722 {
1723 DEBUG_ERROR_LOG(m_settingsFileWhitelist->GetLastError(), PLUGIN_ERROR_SETT INGS_WHITELIST, PLUGIN_ERROR_SETTINGS_FILE_WRITE, "SettingsWhitelist::Write")
1724 }
1725
1726 m_isDirty = false;
1727 }
1728 else
1729 {
1730 isWritten = false;
1731 }
1732
1733 if (isWritten)
1734 {
1735 DEBUG_WHITELIST("Whitelist::Icrement version")
1736
1737 IncrementTabVersion(SETTING_TAB_WHITELIST_VERSION);
1738 }
1739
1740 return isWritten;
1741 }
1742
1743
1744 void CPluginSettings::AddWhiteListedDomain(const CString& domain, int reason, bo ol isToGo)
1745 {
1746 DEBUG_SETTINGS("SettingsWhitelist::AddWhiteListedDomain domain:" + domain)
1747
1748 bool isNewVersion = false;
1749 bool isForcingUpdateOnStart = false;
1750
1751 CPluginSettingsWhitelistLock lock;
1752 if (lock.IsLocked())
1753 {
1754 ReadWhitelist(false);
1755
1756 s_criticalSectionLocal.Lock();
1757 {
1758 bool isToGoMatcingReason = false;
1759 bool isToGoMatcingDomain = false;
1760
1761 TDomainList::iterator itToGo = m_whitelistToGo.find(domain);
1762 TDomainList::iterator it = m_whitelist.find(domain);
1763 if (isToGo)
1764 {
1765 if (itToGo != m_whitelistToGo.end())
1766 {
1767 isToGoMatcingDomain = true;
1768 isToGoMatcingReason = itToGo->second == reason;
1769
1770 if (reason == 3)
1771 {
1772 m_whitelistToGo.erase(itToGo);
1773 m_isDirtyWhitelist = true;
1774 }
1775 else if (!isToGoMatcingReason)
1776 {
1777 itToGo->second = reason;
1778 m_isDirtyWhitelist = true;
1779 }
1780 }
1781 else
1782 {
1783 m_whitelistToGo[domain] = reason;
1784 m_isDirtyWhitelist = true;
1785
1786 // Delete new togo item from saved white list
1787 if (it != m_whitelist.end())
1788 {
1789 m_whitelist.erase(it);
1790 }
1791 }
1792 }
1793 else
1794 {
1795 if (isToGoMatcingDomain)
1796 {
1797 m_whitelistToGo.erase(itToGo);
1798 m_isDirtyWhitelist = true;
1799 }
1800
1801 if (it != m_whitelist.end())
1802 {
1803 if (it->second != reason)
1804 {
1805 it->second = reason;
1806 m_isDirtyWhitelist = true;
1807 }
1808 }
1809 else
1810 {
1811 m_whitelist[domain] = reason;
1812 m_isDirtyWhitelist = true;
1813 }
1814 }
1815
1816 isForcingUpdateOnStart = m_whitelistToGo.size() > 0;
1817 }
1818 s_criticalSectionLocal.Unlock();
1819
1820 WriteWhitelist(false);
1821 } 1586 }
1822 1587
1823 if (isForcingUpdateOnStart) 1588 if (isForcingUpdateOnStart)
1824 { 1589 {
1825 ForceConfigurationUpdateOnStart(); 1590 ForceConfigurationUpdateOnStart();
1826 } 1591 }
1827 } 1592 }
1828 1593
1829 1594
1830 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const 1595 bool CPluginSettings::IsWhiteListedDomain(const CString& domain) const
1831 { 1596 {
1832 bool bIsWhiteListed; 1597 bool bIsWhiteListed;
1833 1598
1834 s_criticalSectionLocal.Lock(); 1599 s_criticalSectionLocal.Lock();
1835 { 1600 {
1836 bIsWhiteListed = m_whitelist.find(domain) != m_whitelist.end(); 1601 bIsWhiteListed = std::find(m_whitelistedDomains.begin(), m_whitelistedDomain s.end(), std::string(CW2A(domain, CP_UTF8))) != m_whitelistedDomains.end();
1837 if (!bIsWhiteListed)
1838 {
1839 TDomainList::const_iterator it = m_whitelistToGo.find(domain);
1840 bIsWhiteListed = it != m_whitelistToGo.end() && it->second != 3;
1841 }
1842 } 1602 }
1843 s_criticalSectionLocal.Unlock(); 1603 s_criticalSectionLocal.Unlock();
1844 1604
1845 return bIsWhiteListed; 1605 return bIsWhiteListed;
1846 } 1606 }
1847 1607
1848 int CPluginSettings::GetWhiteListedDomainCount() const 1608 int CPluginSettings::GetWhiteListedDomainCount() const
1849 { 1609 {
1850 int count = 0; 1610 int count = 0;
1851 1611
1852 s_criticalSectionLocal.Lock(); 1612 s_criticalSectionLocal.Lock();
1853 { 1613 {
1854 count = (int)m_whitelist.size(); 1614 count = (int)m_whitelistedDomains.size();
1855 } 1615 }
1856 s_criticalSectionLocal.Unlock(); 1616 s_criticalSectionLocal.Unlock();
1857 1617
1858 return count; 1618 return count;
1859 } 1619 }
1860 1620
1861 1621
1862 TDomainList CPluginSettings::GetWhiteListedDomainList(bool isToGo) const 1622 std::vector<std::string> CPluginSettings::GetWhiteListedDomainList(bool isToGo)
1863 { 1623 {
1864 TDomainList domainList; 1624 bool r = ReadWhitelist(false);
1865 1625 return m_whitelistedDomains;
1866 s_criticalSectionLocal.Lock();
1867 {
1868 if (isToGo)
1869 {
1870 domainList = m_whitelistToGo;
1871 }
1872 else
1873 {
1874 domainList = m_whitelist;
1875 }
1876 }
1877 s_criticalSectionLocal.Unlock();
1878
1879 return domainList;
1880 }
1881
1882
1883 void CPluginSettings::ReplaceWhiteListedDomains(const TDomainList& domains)
1884 {
1885 CPluginSettingsWhitelistLock lock;
1886 if (lock.IsLocked())
1887 {
1888 ReadWhitelist(false);
1889
1890 s_criticalSectionLocal.Lock();
1891 {
1892 if (m_whitelist != domains)
1893 {
1894 m_whitelist = domains;
1895 m_isDirtyWhitelist = true;
1896 }
1897
1898 // Delete entries in togo list
1899 bool isDeleted = true;
1900
1901 while (isDeleted)
1902 {
1903 isDeleted = false;
1904
1905 for (TDomainList::iterator it = m_whitelistToGo.begin(); it != m_whiteli stToGo.end(); ++it)
1906 {
1907 if (m_whitelist.find(it->first) != m_whitelist.end() || it->second == 3)
1908 {
1909 m_whitelistToGo.erase(it);
1910
1911 // Force another round...
1912 isDeleted = true;
1913 break;
1914 }
1915 }
1916 }
1917 }
1918 s_criticalSectionLocal.Unlock();
1919
1920 WriteWhitelist(false);
1921 }
1922 }
1923
1924
1925 void CPluginSettings::RemoveWhiteListedDomainsToGo(const TDomainList& domains)
1926 {
1927 CPluginSettingsWhitelistLock lock;
1928 if (lock.IsLocked())
1929 {
1930 ReadWhitelist(false);
1931
1932 s_criticalSectionLocal.Lock();
1933 {
1934 for (TDomainList::const_iterator it = domains.begin(); it != domains.end() ; ++it)
1935 {
1936 for (TDomainList::iterator itToGo = m_whitelistToGo.begin(); itToGo != m _whitelistToGo.end(); ++ itToGo)
1937 {
1938 if (it->first == itToGo->first)
1939 {
1940 m_whitelistToGo.erase(itToGo);
1941 m_isDirtyWhitelist = true;
1942 break;
1943 }
1944 }
1945 }
1946 }
1947 s_criticalSectionLocal.Unlock();
1948
1949 WriteWhitelist(false);
1950 }
1951 } 1626 }
1952 1627
1953 1628
1954 bool CPluginSettings::RefreshWhitelist() 1629 bool CPluginSettings::RefreshWhitelist()
1955 { 1630 {
1956 CPluginSettingsWhitelistLock lock; 1631 CPluginSettingsWhitelistLock lock;
1957 if (lock.IsLocked()) 1632 if (lock.IsLocked())
1958 { 1633 {
1959 ReadWhitelist(true); 1634 ReadWhitelist(true);
1960 } 1635 }
(...skipping 14 matching lines...) Expand all
1975 1650
1976 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 1651 osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
1977 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi); 1652 bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO*) &osvi);
1978 1653
1979 m_WindowsBuildNumber = osvi.dwBuildNumber; 1654 m_WindowsBuildNumber = osvi.dwBuildNumber;
1980 } 1655 }
1981 1656
1982 return m_WindowsBuildNumber; 1657 return m_WindowsBuildNumber;
1983 } 1658 }
1984 1659
1985 void CPluginSettings::SetSubscription(BSTR language) 1660 void CPluginSettings::SetSubscription(BSTR url)
1986 { 1661 {
1987 std::string lngConverted = CT2A(language); 1662 std::string urlConverted = CT2A(url);
1988 SetSubscription(lngConverted); 1663 SetSubscription(urlConverted);
1989 } 1664 }
1990 1665
1991 void CPluginSettings::SetSubscription(std::string language) 1666 void CPluginSettings::SetSubscription(std::string url)
1992 { 1667 {
1993 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine(); 1668 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine();
1994 //TODO: negotiate who should store what? Is the plugin responsible for storing selected subscription? 1669 AdblockPlus::SubscriptionPtr subscription = filterEngine->GetSubscription(url) ;
1995 const AdblockPlus::Subscription* subscription = filterEngine->FindSubscription( language); 1670 subscription->AddToList();
1996 if (subscription != NULL) 1671 }
1997 { 1672
1998 //TODO: API for this? 1673 CString CPluginSettings::GetSubscription()
1999 // filterEngine->SetActiveSubscription(*subscription); 1674 {
2000 } 1675 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine();
2001 } 1676 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis tedSubscriptions();
1677 for (int i = 0; i < subscriptions.size(); i ++)
1678 {
1679 if (subscriptions[i]->IsListed())
1680 {
1681 return CString(CA2T(subscriptions[i]->GetProperty("url", std::string()).c_ str()));
1682 }
1683 }
1684 return CString(L"");
1685 }
1686
2002 1687
2003 void CPluginSettings::RefreshFilterlist() 1688 void CPluginSettings::RefreshFilterlist()
2004 { 1689 {
2005 //TODO: Why does this have subscription as parameter? Shouldn't it update curr ently active filter? 1690 FilterEngine* filterEngine= CPluginClient::GetInstance()->GetFilterEngine();
2006 // CPluginClient::GetInstance()->GetFilterEngine()->UpdateSubscriptionFilters() ; 1691 std::vector<AdblockPlus::SubscriptionPtr> subscriptions = filterEngine->GetLis tedSubscriptions();
1692 for (int i = 0; i < subscriptions.size(); i ++)
1693 {
1694 if (subscriptions[i]->IsListed())
1695 {
1696 subscriptions[i]->UpdateFilters();
1697 }
1698 }
2007 } 1699 }
2008 1700
2009 #endif // SUPPORT_WHITELIST 1701 #endif // SUPPORT_WHITELIST
LEFTRIGHT

Powered by Google App Engine
This is Rietveld