 Issue 29426559:
  Issue 5137 - [emscripten] Added basic filter storage implementation  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluscore
    
  
    Issue 29426559:
  Issue 5137 - [emscripten] Added basic filter storage implementation  (Closed) 
  Base URL: https://hg.adblockplus.org/adblockpluscore| 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 | 
| 
Wladimir Palant
2017/05/01 14:47:25
Turns out that our current code doesn't really sup
 | 
| 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); |