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

Delta Between Two Patch Sets: src/ReferrerMapping.cpp

Issue 5768603836088320: Issue 1564-Fix FilterEngine::Matches for allowing request which is whitelisted in the ascendant node
Left Patch Set: fix according to comments and add some tests Created Nov. 26, 2014, 10:35 a.m.
Right Patch Set: fix according to comments Created Dec. 12, 2014, 4:59 p.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 | « include/AdblockPlus/ReferrerMapping.h ('k') | test/ReferrerMapping.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 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 28 matching lines...) Expand all
39 mapping.erase(poppedUrl); 39 mapping.erase(poppedUrl);
40 } 40 }
41 } 41 }
42 42
43 ReferrerMapping::Urls ReferrerMapping::BuildFrameStructure(const Url& url) const 43 ReferrerMapping::Urls ReferrerMapping::BuildFrameStructure(const Url& url) const
44 { 44 {
45 Urls frames; 45 Urls frames;
46 // We need to limit the chain length to ensure we don't block indefinitely 46 // We need to limit the chain length to ensure we don't block indefinitely
47 // if there's a referrer loop. 47 // if there's a referrer loop.
48 const int maxChainLength = 10; 48 const int maxChainLength = 10;
49 ReferrerMap::const_iterator currentEntry = mapping.end(); 49 ReferrerMap::const_iterator currentEntry = url.empty() ? mapping.end() :
50 mapping.find(url);
50 ReferrerMap::const_iterator prevEntry = mapping.end(); 51 ReferrerMap::const_iterator prevEntry = mapping.end();
51 // process the current url beyond the loop below because we should add it
Wladimir Palant 2014/12/09 21:20:03 beyond => outside
52 // even if `mapping` is empty.
53 if (!url.empty())
54 {
55 currentEntry = mapping.find(url);
56 if (currentEntry != mapping.end())
57 {
58 if (currentEntry->second.IsFrame())
59 {
60 frames.push_back(url);
61 }
62 prevEntry = currentEntry;
63 currentEntry = mapping.find(currentEntry->second.referrer);
64 }
65 else
66 {
67 // If there is no information for the url in `mapping` then assume that
68 // 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"
69 frames.push_back(url);
70 }
71 }
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.
72
73 for (int i = 0; i < maxChainLength && currentEntry != mapping.end(); i++) 52 for (int i = 0; i < maxChainLength && currentEntry != mapping.end(); i++)
74 { 53 {
75 if (currentEntry->second.IsFrame()) 54 if (currentEntry->second.IsFrame())
76 { 55 {
77 frames.insert(frames.begin(), currentEntry->first); 56 frames.insert(frames.begin(), currentEntry->first);
78 } 57 }
79 prevEntry = currentEntry; 58 prevEntry = currentEntry;
80 currentEntry = mapping.find(currentEntry->second.referrer); 59 currentEntry = mapping.find(currentEntry->second.referrer);
81 } 60 }
82 if (prevEntry != mapping.end() && !prevEntry->second.referrer.empty()) 61 if (prevEntry == mapping.end())
62 {
63 if (!url.empty())
64 {
65 // No data, just assume that the url is a frame.
66 frames.push_back(url);
67 }
68 }
69 else if (!prevEntry->second.referrer.empty())
83 { 70 {
84 frames.insert(frames.begin(), prevEntry->second.referrer); 71 frames.insert(frames.begin(), prevEntry->second.referrer);
85 } 72 }
86 return frames; 73 return frames;
87 } 74 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld