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

Unified Diff: src/ReferrerMapping.cpp

Issue 5768603836088320: Issue 1564-Fix FilterEngine::Matches for allowing request which is whitelisted in the ascendant node
Patch Set: fix according to comments Created Dec. 12, 2014, 4:59 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/AdblockPlus/ReferrerMapping.h ('k') | test/ReferrerMapping.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ReferrerMapping.cpp
diff --git a/src/ReferrerMapping.cpp b/src/ReferrerMapping.cpp
index 7ac6cddff5bf2452670c6d2b986f0802fb5de4d2..0dae687e90bbd7af59ce89c117f6294411e0c937 100644
--- a/src/ReferrerMapping.cpp
+++ b/src/ReferrerMapping.cpp
@@ -24,12 +24,12 @@ ReferrerMapping::ReferrerMapping(const int maxCachedUrls)
{
}
-void ReferrerMapping::Add(const std::string& url, const std::string& referrer)
+void ReferrerMapping::Add(const Url& url, const Url& referrer, FrameIndicator isFrame)
{
if (mapping.find(url) != mapping.end())
cachedUrls.remove(url);
cachedUrls.push_back(url);
- mapping[url] = referrer;
+ mapping[url] = RequestInfo(referrer, isFrame);
const int urlsToPop = cachedUrls.size() - maxCachedUrls;
for (int i = 0; i < urlsToPop; i++)
@@ -40,21 +40,35 @@ void ReferrerMapping::Add(const std::string& url, const std::string& referrer)
}
}
-std::vector<std::string> ReferrerMapping::BuildReferrerChain(
- const std::string& url) const
+ReferrerMapping::Urls ReferrerMapping::BuildFrameStructure(const Url& url) const
{
- std::vector<std::string> referrerChain;
- referrerChain.push_back(url);
+ Urls frames;
// We need to limit the chain length to ensure we don't block indefinitely
// if there's a referrer loop.
const int maxChainLength = 10;
- std::map<std::string, std::string>::const_iterator currentEntry =
+ ReferrerMap::const_iterator currentEntry = url.empty() ? mapping.end() :
mapping.find(url);
+ ReferrerMap::const_iterator prevEntry = mapping.end();
for (int i = 0; i < maxChainLength && currentEntry != mapping.end(); i++)
{
- const std::string& currentUrl = currentEntry->second;
- referrerChain.insert(referrerChain.begin(), currentUrl);
- currentEntry = mapping.find(currentUrl);
+ if (currentEntry->second.IsFrame())
+ {
+ frames.insert(frames.begin(), currentEntry->first);
+ }
+ prevEntry = currentEntry;
+ currentEntry = mapping.find(currentEntry->second.referrer);
}
- return referrerChain;
+ if (prevEntry == mapping.end())
+ {
+ if (!url.empty())
+ {
+ // No data, just assume that the url is a frame.
+ frames.push_back(url);
+ }
+ }
+ else if (!prevEntry->second.referrer.empty())
+ {
+ frames.insert(frames.begin(), prevEntry->second.referrer);
+ }
+ return frames;
}
« no previous file with comments | « include/AdblockPlus/ReferrerMapping.h ('k') | test/ReferrerMapping.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld