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

Unified Diff: include/AdblockPlus/ReferrerMapping.h

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
« no previous file with comments | « no previous file | src/ReferrerMapping.cpp » ('j') | src/ReferrerMapping.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/AdblockPlus/ReferrerMapping.h
===================================================================
--- a/include/AdblockPlus/ReferrerMapping.h
+++ b/include/AdblockPlus/ReferrerMapping.h
@@ -22,18 +22,29 @@
#include <map>
#include <string>
#include <vector>
+#include "FilterEngine.h"
namespace AdblockPlus
{
/**
* Stores a mapping between URLs and their referrers.
- * This can be used to build a chain of referrers for any URL
- * (see `BuildReferrerChain()`), which approximates the frame structure, see
- * FilterEngine::Matches().
+ * This can be used to build a frame structure for any URL
+ * (see `BuildFrameStructure()`), it's useful for FilterEngine::Matches().
*/
class ReferrerMapping
{
public:
+ /// The type for URL.
+ typedef std::string Url;
+
+ /// Contains the ordered list of URLs.
Wladimir Palant 2014/12/09 21:20:03 Nit: *an* ordered list
+ typedef std::vector<Url> Urls;
+
+ /// Indicates whether the URL is a frame or not.
+ enum FrameIndicator
+ {
+ FRAME_INDICATOR_NOT_A_FRAME = 0, FRAME_INDICATOR_FRAME= 1
Wladimir Palant 2014/12/09 21:20:03 Extreme nit: articles seem wrong in constant names
sergei 2014/12/12 17:07:07 I know, I thought about it but don't remember the
+ };
/**
* Constructor.
* @param maxCachedUrls Number of URL mappings to store. The higher the
@@ -46,21 +57,37 @@
* Records the refferer for a URL.
* @param url Request URL.
* @param referrer Request referrer.
+ * @param isFrame Indicates whether the url is a frame.
*/
- void Add(const std::string& url, const std::string& referrer);
+ void Add(const Url& url, const Url& referrer, FrameIndicator isFrame);
/**
- * Builds a chain of referrers for the supplied URL.
+ * Builds a frame structure for the supplied URL.
* This should reconstruct a document's parent frame URLs.
* @param url URL to build the chain for.
- * @return List of URLs, starting with `url`.
+ * @return List of URLs, finishing with `url`.
*/
- std::vector<std::string> BuildReferrerChain(const std::string& url) const;
+ Urls BuildFrameStructure(const Url& url) const;
private:
const int maxCachedUrls;
- std::map<std::string, std::string> mapping;
- std::list<std::string> cachedUrls;
+ struct RequestInfo
+ {
+ explicit RequestInfo(const Url& referrerArg = Url(),
+ FrameIndicator frameIndicatorArg = FrameIndicator::FRAME_INDICATOR_NOT_A_FRAME)
Wladimir Palant 2014/12/09 21:20:03 Shouldn't you have that default value in method Ad
sergei 2014/12/12 17:07:07 These default arguments are required by std::map,
+ : referrer(referrerArg), frameIndicator(frameIndicatorArg)
+ {
+ }
+ bool IsFrame() const
+ {
+ return frameIndicator == FrameIndicator::FRAME_INDICATOR_FRAME;
+ }
+ Url referrer;
+ FrameIndicator frameIndicator;
+ };
+ typedef std::map<Url, RequestInfo> ReferrerMap;
+ ReferrerMap mapping;
+ std::list<Url> cachedUrls;
};
}
« no previous file with comments | « no previous file | src/ReferrerMapping.cpp » ('j') | src/ReferrerMapping.cpp » ('J')

Powered by Google App Engine
This is Rietveld