| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 12 matching lines...) Expand all Loading... |
| 23 namespace | 23 namespace |
| 24 { | 24 { |
| 25 enum FilterCategory | 25 enum FilterCategory |
| 26 { | 26 { |
| 27 NONE = 0, | 27 NONE = 0, |
| 28 WHITELIST = 1, | 28 WHITELIST = 1, |
| 29 BLOCKING = 2, | 29 BLOCKING = 2, |
| 30 ELEMHIDE = 4, | 30 ELEMHIDE = 4, |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 const FilterCategory filterTypeToCategory[] = { | 33 FilterCategory filterTypeToCategory(Filter::Type type) |
| 34 FilterCategory::BLOCKING, // UNKNOWN | 34 { |
| 35 FilterCategory::NONE, // INVALID | 35 if (type == Filter::Type::BLOCKING) |
| 36 FilterCategory::NONE, // COMMENT | 36 return FilterCategory::BLOCKING; |
| 37 FilterCategory::BLOCKING, // BLOCKING | 37 if (type == Filter::Type::WHITELIST) |
| 38 FilterCategory::WHITELIST, // WHITELIST | 38 return FilterCategory::WHITELIST; |
| 39 FilterCategory::ELEMHIDE, // ELEMHIDE | 39 if ((type & Filter::Type::ELEMHIDEBASE) == Filter::Type::ELEMHIDEBASE) |
| 40 FilterCategory::ELEMHIDE, // ELEMHIDEEXCEPTION | 40 return FilterCategory::ELEMHIDE; |
| 41 FilterCategory::ELEMHIDE, // ELEMHIDEEMULATION | |
| 42 }; | |
| 43 | 41 |
| 44 static_assert( | 42 return FilterCategory::NONE; |
| 45 sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Ty
pe::VALUE_COUNT, | 43 } |
| 46 "Unexpected number of filter types, was a new type added?" | |
| 47 ); | |
| 48 } | 44 } |
| 49 | 45 |
| 50 UserDefinedSubscription::UserDefinedSubscription(const String& id) | 46 UserDefinedSubscription::UserDefinedSubscription(const String& id) |
| 51 : Subscription(Type::USERDEFINED, id), mDefaults(0) | 47 : Subscription(classType, id), mDefaults(0) |
| 52 { | 48 { |
| 53 } | 49 } |
| 54 | 50 |
| 55 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const | 51 bool UserDefinedSubscription::IsDefaultFor(const Filter& filter) const |
| 56 { | 52 { |
| 57 if (filter.mType >= Filter::Type::VALUE_COUNT) | 53 return mDefaults & filterTypeToCategory(filter.mType); |
| 58 { | |
| 59 assert2(false, "Filter type exceeds valid range"); | |
| 60 abort(); | |
| 61 } | |
| 62 return mDefaults & filterTypeToCategory[filter.mType]; | |
| 63 } | 54 } |
| 64 | 55 |
| 65 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter) | 56 void UserDefinedSubscription::MakeDefaultFor(const Filter& filter) |
| 66 { | 57 { |
| 67 if (filter.mType >= Filter::Type::VALUE_COUNT) | 58 mDefaults |= filterTypeToCategory(filter.mType); |
| 68 { | |
| 69 assert2(false, "Filter type exceeds valid range"); | |
| 70 abort(); | |
| 71 } | |
| 72 mDefaults |= filterTypeToCategory[filter.mType]; | |
| 73 } | 59 } |
| 74 | 60 |
| 75 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos) | 61 void UserDefinedSubscription::InsertFilterAt(Filter& filter, unsigned pos) |
| 76 { | 62 { |
| 77 if (pos >= mFilters.size()) | 63 if (pos >= mFilters.size()) |
| 78 pos = mFilters.size(); | 64 pos = mFilters.size(); |
| 79 mFilters.emplace(mFilters.begin() + pos, &filter); | 65 mFilters.emplace(mFilters.begin() + pos, &filter); |
| 80 | 66 |
| 81 if (GetListed()) | 67 if (GetListed()) |
| 82 { | 68 { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 109 if (mDefaults & FilterCategory::BLOCKING) | 95 if (mDefaults & FilterCategory::BLOCKING) |
| 110 result.append(u" blocking"_str); | 96 result.append(u" blocking"_str); |
| 111 if (mDefaults & FilterCategory::WHITELIST) | 97 if (mDefaults & FilterCategory::WHITELIST) |
| 112 result.append(u" whitelist"_str); | 98 result.append(u" whitelist"_str); |
| 113 if (mDefaults & FilterCategory::ELEMHIDE) | 99 if (mDefaults & FilterCategory::ELEMHIDE) |
| 114 result.append(u" elemhide"_str); | 100 result.append(u" elemhide"_str); |
| 115 result.append(u'\n'); | 101 result.append(u'\n'); |
| 116 } | 102 } |
| 117 return result; | 103 return result; |
| 118 } | 104 } |
| OLD | NEW |