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

Unified Diff: compiled/subscription/UserDefinedSubscription.cpp

Issue 29426559: Issue 5137 - [emscripten] Added basic filter storage implementation (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Improved type names and added finally block Created May 8, 2017, 12:53 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 | « compiled/subscription/UserDefinedSubscription.h ('k') | lib/filterStorage.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/subscription/UserDefinedSubscription.cpp
===================================================================
--- a/compiled/subscription/UserDefinedSubscription.cpp
+++ b/compiled/subscription/UserDefinedSubscription.cpp
@@ -13,30 +13,32 @@
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include "UserDefinedSubscription.h"
+#include "../FilterNotifier.h"
namespace
{
enum FilterCategory
{
+ NONE = 0,
WHITELIST = 1,
BLOCKING = 2,
ELEMHIDE = 4,
};
const FilterCategory filterTypeToCategory[] = {
FilterCategory::BLOCKING, // UNKNOWN
- FilterCategory::BLOCKING, // INVALID
- FilterCategory::BLOCKING, // COMMENT
+ FilterCategory::NONE, // INVALID
+ FilterCategory::NONE, // COMMENT
FilterCategory::BLOCKING, // BLOCKING
FilterCategory::WHITELIST, // WHITELIST
FilterCategory::ELEMHIDE, // ELEMHIDE
FilterCategory::ELEMHIDE, // ELEMHIDEEXCEPTION
FilterCategory::ELEMHIDE, // ELEMHIDEEMULATION
};
static_assert(
@@ -68,34 +70,45 @@ void UserDefinedSubscription::MakeDefaul
abort();
}
mDefaults |= filterTypeToCategory[filter->mType];
}
void UserDefinedSubscription::InsertFilterAt(Filter* filter, unsigned pos)
{
if (pos >= mFilters.size())
- mFilters.emplace_back(filter);
- else
- mFilters.emplace(mFilters.begin() + pos, filter);
+ pos = mFilters.size();
+ mFilters.emplace(mFilters.begin() + pos, filter);
+
+ if (GetListed())
+ {
+ FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_ADDED, filter, this,
+ pos);
+ }
}
bool UserDefinedSubscription::RemoveFilterAt(unsigned pos)
{
if (pos >= mFilters.size())
return false;
+ FilterPtr filter(mFilters[pos]);
mFilters.erase(mFilters.begin() + pos);
+ if (GetListed())
+ {
+ FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_REMOVED,
+ filter.get(), this, pos);
+ }
return true;
}
OwnedString UserDefinedSubscription::Serialize() const
{
OwnedString result(Subscription::Serialize());
- if (mDefaults)
+ if (!IsGeneric())
{
result.append(u"defaults="_str);
if (mDefaults & FilterCategory::BLOCKING)
result.append(u" blocking"_str);
if (mDefaults & FilterCategory::WHITELIST)
result.append(u" whitelist"_str);
if (mDefaults & FilterCategory::ELEMHIDE)
result.append(u" elemhide"_str);
« no previous file with comments | « compiled/subscription/UserDefinedSubscription.h ('k') | lib/filterStorage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld