| 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 | 
| 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
| 12  * GNU General Public License for more details. | 12  * GNU General Public License for more details. | 
| 13  * | 13  * | 
| 14  * You should have received a copy of the GNU General Public License | 14  * You should have received a copy of the GNU General Public License | 
| 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 15  * along with Adblock Plus.  If not, see <http://www.gnu.org/licenses/>. | 
| 16  */ | 16  */ | 
| 17 | 17 | 
| 18 #include <cstdlib> | 18 #include <cstdlib> | 
| 19 | 19 | 
| 20 #include "UserDefinedSubscription.h" | 20 #include "UserDefinedSubscription.h" | 
|  | 21 #include "../FilterNotifier.h" | 
| 21 | 22 | 
| 22 namespace | 23 namespace | 
| 23 { | 24 { | 
| 24   enum FilterCategory | 25   enum FilterCategory | 
| 25   { | 26   { | 
|  | 27     NONE = 0, | 
| 26     WHITELIST = 1, | 28     WHITELIST = 1, | 
| 27     BLOCKING = 2, | 29     BLOCKING = 2, | 
| 28     ELEMHIDE = 4, | 30     ELEMHIDE = 4, | 
| 29   }; | 31   }; | 
| 30 | 32 | 
| 31   const FilterCategory filterTypeToCategory[] = { | 33   const FilterCategory filterTypeToCategory[] = { | 
| 32     FilterCategory::BLOCKING,   // UNKNOWN | 34     FilterCategory::BLOCKING,   // UNKNOWN | 
| 33     FilterCategory::BLOCKING,   // INVALID | 35     FilterCategory::NONE,       // INVALID | 
| 34     FilterCategory::BLOCKING,   // COMMENT | 36     FilterCategory::NONE,       // COMMENT | 
| 35     FilterCategory::BLOCKING,   // BLOCKING | 37     FilterCategory::BLOCKING,   // BLOCKING | 
| 36     FilterCategory::WHITELIST,  // WHITELIST | 38     FilterCategory::WHITELIST,  // WHITELIST | 
| 37     FilterCategory::ELEMHIDE,   // ELEMHIDE | 39     FilterCategory::ELEMHIDE,   // ELEMHIDE | 
| 38     FilterCategory::ELEMHIDE,   // ELEMHIDEEXCEPTION | 40     FilterCategory::ELEMHIDE,   // ELEMHIDEEXCEPTION | 
| 39     FilterCategory::ELEMHIDE,   // ELEMHIDEEMULATION | 41     FilterCategory::ELEMHIDE,   // ELEMHIDEEMULATION | 
| 40   }; | 42   }; | 
| 41 | 43 | 
| 42   static_assert( | 44   static_assert( | 
| 43     sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Ty
     pe::VALUE_COUNT, | 45     sizeof(filterTypeToCategory) / sizeof(filterTypeToCategory[0]) == Filter::Ty
     pe::VALUE_COUNT, | 
| 44     "Unexpected number of filter types, was a new type added?" | 46     "Unexpected number of filter types, was a new type added?" | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 66   { | 68   { | 
| 67     assert(false, "Filter type exceeds valid range"); | 69     assert(false, "Filter type exceeds valid range"); | 
| 68     abort(); | 70     abort(); | 
| 69   } | 71   } | 
| 70   mDefaults |= filterTypeToCategory[filter->mType]; | 72   mDefaults |= filterTypeToCategory[filter->mType]; | 
| 71 } | 73 } | 
| 72 | 74 | 
| 73 void UserDefinedSubscription::InsertFilterAt(Filter* filter, unsigned pos) | 75 void UserDefinedSubscription::InsertFilterAt(Filter* filter, unsigned pos) | 
| 74 { | 76 { | 
| 75   if (pos >= mFilters.size()) | 77   if (pos >= mFilters.size()) | 
| 76     mFilters.emplace_back(filter); | 78     pos = mFilters.size(); | 
| 77   else | 79   mFilters.emplace(mFilters.begin() + pos, filter); | 
| 78     mFilters.emplace(mFilters.begin() + pos, filter); | 80 | 
|  | 81   if (GetListed()) | 
|  | 82   { | 
|  | 83     FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_ADDED, filter, th
     is, | 
|  | 84         pos); | 
|  | 85   } | 
| 79 } | 86 } | 
| 80 | 87 | 
| 81 bool UserDefinedSubscription::RemoveFilterAt(unsigned pos) | 88 bool UserDefinedSubscription::RemoveFilterAt(unsigned pos) | 
| 82 { | 89 { | 
| 83   if (pos >= mFilters.size()) | 90   if (pos >= mFilters.size()) | 
| 84     return false; | 91     return false; | 
| 85 | 92 | 
|  | 93   FilterPtr filter(mFilters[pos]); | 
| 86   mFilters.erase(mFilters.begin() + pos); | 94   mFilters.erase(mFilters.begin() + pos); | 
|  | 95   if (GetListed()) | 
|  | 96   { | 
|  | 97     FilterNotifier::FilterChange(FilterNotifier::Topic::FILTER_REMOVED, | 
|  | 98         filter.get(), this, pos); | 
|  | 99   } | 
| 87   return true; | 100   return true; | 
| 88 } | 101 } | 
| 89 | 102 | 
| 90 OwnedString UserDefinedSubscription::Serialize() const | 103 OwnedString UserDefinedSubscription::Serialize() const | 
| 91 { | 104 { | 
| 92   OwnedString result(Subscription::Serialize()); | 105   OwnedString result(Subscription::Serialize()); | 
| 93   if (mDefaults) | 106   if (!IsGeneric()) | 
| 94   { | 107   { | 
| 95     result.append(u"defaults="_str); | 108     result.append(u"defaults="_str); | 
| 96     if (mDefaults & FilterCategory::BLOCKING) | 109     if (mDefaults & FilterCategory::BLOCKING) | 
| 97       result.append(u" blocking"_str); | 110       result.append(u" blocking"_str); | 
| 98     if (mDefaults & FilterCategory::WHITELIST) | 111     if (mDefaults & FilterCategory::WHITELIST) | 
| 99       result.append(u" whitelist"_str); | 112       result.append(u" whitelist"_str); | 
| 100     if (mDefaults & FilterCategory::ELEMHIDE) | 113     if (mDefaults & FilterCategory::ELEMHIDE) | 
| 101       result.append(u" elemhide"_str); | 114       result.append(u" elemhide"_str); | 
| 102     result.append(u'\n'); | 115     result.append(u'\n'); | 
| 103   } | 116   } | 
| 104   return result; | 117   return result; | 
| 105 } | 118 } | 
| OLD | NEW | 
|---|