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 and add some tests Created Nov. 26, 2014, 10:35 a.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
Index: src/ReferrerMapping.cpp
===================================================================
--- a/src/ReferrerMapping.cpp
+++ b/src/ReferrerMapping.cpp
@@ -24,12 +24,12 @@
{
}
-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,48 @@
}
}
-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 =
- mapping.find(url);
+ ReferrerMap::const_iterator currentEntry = mapping.end();
+ ReferrerMap::const_iterator prevEntry = mapping.end();
+ // process the current url beyond the loop below because we should add it
Wladimir Palant 2014/12/09 21:20:03 beyond => outside
+ // even if `mapping` is empty.
+ if (!url.empty())
+ {
+ currentEntry = mapping.find(url);
+ if (currentEntry != mapping.end())
+ {
+ if (currentEntry->second.IsFrame())
+ {
+ frames.push_back(url);
+ }
+ prevEntry = currentEntry;
+ currentEntry = mapping.find(currentEntry->second.referrer);
+ }
+ else
+ {
+ // If there is no information for the url in `mapping` then assume that
+ // it's a frame, despite it's not necessary to be a frame.
Wladimir Palant 2014/12/09 21:20:03 Nit: "despite it not necessarily being a frame"
+ frames.push_back(url);
+ }
+ }
Wladimir Palant 2014/12/09 21:20:03 Can't we check prevEntry after the loop instead of
sergei 2014/12/12 17:07:07 That does work, please check the updated version.
+
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() && !prevEntry->second.referrer.empty())
+ {
+ frames.insert(frames.begin(), prevEntry->second.referrer);
+ }
+ return frames;
}

Powered by Google App Engine
This is Rietveld