Index: Shared/AdblockPlusClient.cpp |
=================================================================== |
--- a/Shared/AdblockPlusClient.cpp |
+++ b/Shared/AdblockPlusClient.cpp |
@@ -18,6 +18,10 @@ |
CAdblockPlusClient::CAdblockPlusClient() : CPluginClientBase() |
{ |
m_filter = std::auto_ptr<CPluginFilter>(new CPluginFilter()); |
+ fileReader = std::auto_ptr<LibFileReader>(new LibFileReader()); |
+ errorCallback = std::auto_ptr<CerrErrorCallback>(new CerrErrorCallback()); |
+ jsEngine = std::auto_ptr<AdblockPlus::JsEngine>(new AdblockPlus::JsEngine(fileReader.get(), errorCallback.get())); |
+ filterEngine = std::auto_ptr<AdblockPlus::FilterEngine>(new AdblockPlus::FilterEngine(*jsEngine)); |
} |
CAdblockPlusClient::~CAdblockPlusClient() |
{ |
@@ -45,6 +49,15 @@ |
return instance; |
} |
+bool CAdblockPlusClient::LoadFilters() |
+{ |
+ return m_filter->LoadHideFilters(filterEngine->GetElementHidingRules()); |
+} |
+ |
+AdblockPlus::FilterEngine* CAdblockPlusClient::GetFilterEngine() |
+{ |
+ return filterEngine.get(); |
+} |
bool CAdblockPlusClient::ShouldBlock(CString src, int contentType, const CString& domain, bool addDebug) |
{ |
@@ -90,99 +103,6 @@ |
return isBlocked; |
} |
-void CAdblockPlusClient::RequestFilterDownload(const CString& filter, const CString& filterPath) |
-{ |
- DEBUG_GENERAL(L"*** Requesting filter download:" + filter) |
- |
- m_criticalSectionFilter.Lock(); |
- { |
- m_filterDownloads.insert(std::make_pair(filter, filterPath)); |
- } |
- m_criticalSectionFilter.Unlock(); |
-} |
- |
- |
-bool CAdblockPlusClient::DownloadFirstMissingFilter() |
-{ |
- bool isDownloaded = false; |
- |
- CString filterFilename; |
- CString filterDownloadPath; |
- |
- m_criticalSectionFilter.Lock(); |
- { |
- TFilterFileList::iterator it = m_filterDownloads.begin(); |
- if (it != m_filterDownloads.end()) |
- { |
- filterFilename = it->first; |
- filterDownloadPath = it->second; |
- |
- m_filterDownloads.erase(it); |
- } |
- } |
- m_criticalSectionFilter.Unlock(); |
- |
- if (!filterFilename.IsEmpty() && m_filter->DownloadFilterFile(filterDownloadPath, filterFilename)) |
- { |
- isDownloaded = true; |
- |
- CPluginSettings* settings = CPluginSettings::GetInstance(); |
- |
- settings->IncrementTabVersion(SETTING_TAB_FILTER_VERSION); |
- } |
- |
- return isDownloaded; |
-} |
- |
- |
-//in this method we read the filter that are in the persistent storage |
-//then we read them and use these to create a new filterclass |
- |
-void CAdblockPlusClient::ReadFilters() |
-{ |
- CPluginSettings* settings = CPluginSettings::GetInstance(); |
- |
- // Check existence of filter file |
- // if (settings->IsMainProcess()) |
- // { |
- // CPluginFilter::CreateFilters(); |
- // } |
- |
- TFilterFileList filterFileNames; |
- |
- TFilterUrlList filters = settings->GetFilterUrlList(); |
- std::map<CString, CString> filterFileNameList = settings->GetFilterFileNamesList(); |
- |
- // Remember first entry in the map, is the filename, second is the version of the filter |
- for (TFilterUrlList::iterator it = filters.begin(); it != filters.end(); ++it) |
- { |
- DEBUG_FILTER(L"Filter::ReadFilters - adding url:" + it->first) |
- |
- CString filename = ""; |
- if (filterFileNameList.find(it->first) != filterFileNameList.end() ) |
- { |
- filename = filterFileNameList.find(it->first)->second; |
- } |
- else |
- { |
- filename = it->first.Right(it->first.GetLength() - it->first.ReverseFind('/') - 1); |
- } |
- filterFileNames.insert(std::make_pair(filename, it->first)); |
- } |
- |
- // Create our filter class which can be used from now on |
- std::auto_ptr<CPluginFilter> filter = std::auto_ptr<CPluginFilter>(new CPluginFilter(filterFileNames, CPluginSettings::GetDataPath())); |
- |
- m_criticalSectionFilter.Lock(); |
- { |
- m_filter = filter; |
- } |
- m_criticalSectionFilter.Unlock(); |
- |
- ClearWhiteListCache(); |
-} |
- |
- |
bool CAdblockPlusClient::IsElementHidden(const CString& tag, IHTMLElement* pEl, const CString& domain, const CString& indent) |
{ |
bool isHidden; |