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

Unified Diff: compiled/ElemHide.h

Issue 29587914: Issue 5142 - Convert Element Hiding to C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: mFiltersByDomain is now an OwnedStringMap Created Jan. 26, 2018, 8:41 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 | « no previous file | compiled/ElemHide.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/ElemHide.h
===================================================================
new file mode 100644
--- /dev/null
+++ b/compiled/ElemHide.h
@@ -0,0 +1,106 @@
+/*
+ * This file is part of Adblock Plus <https://adblockplus.org/>,
+ * Copyright (C) 2006-present eyeo GmbH
+ *
+ * Adblock Plus is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * Adblock Plus is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * @fileOverview Element hiding implementation.
+ */
+
+#pragma once
+
+#include <vector>
+
+#include "bindings/runtime.h"
+#include "intrusive_ptr.h"
+#include "StringMap.h"
+#include "filter/Filter.h"
+#include "filter/ElemHideBase.h"
+#include "filter/ElemHideException.h"
+
+class ElemHide_SelectorList : public ref_counted
+{
+ std::vector<ElemHideBasePtr> mSelectors;
+public:
+ size_t BINDINGS_EXPORTED GetSelectorCount() const
+ {
+ return mSelectors.size();
+ }
+ OwnedString BINDINGS_EXPORTED SelectorAt(size_t idx) const;
+ const String& BINDINGS_EXPORTED FilterKeyAt(size_t idx) const;
+
+ void push_back(const ElemHideBasePtr& filter)
+ {
+ mSelectors.push_back(filter);
+ }
+
+ void append(const ElemHide_SelectorList& list)
+ {
+ mSelectors.insert(mSelectors.end(),
+ list.mSelectors.cbegin(), list.mSelectors.cend());
+ }
+};
+
+class ElemHide : public ref_counted
+{
+ // All filters. Key is filter text. Exception filters excluded.
+ StringMap<ElemHideBasePtr> mFilters;
+ // Filters by domain. Key is domain.
+ // In value key is filter text, value is filter or NULL
+ OwnedStringMap<OwnedStringMap<ElemHideBasePtr>> mFiltersByDomain;
+
+ // Exceptions. The key is the selector.
+ OwnedStringMap<std::vector<ElemHideExceptionPtr>> mExceptions;
+ // Known exceptions. Filter text as keys.
+ StringSet mKnownExceptions;
+
+ // Unconditional selectors. Filter selector as key. Filter as value.
+ OwnedStringMap<ElemHideBasePtr> mUnconditionalSelectors;
+
+ mutable intrusive_ptr<ElemHide_SelectorList> mUnconditionalSelectorsCache;
+
+public:
+ static ElemHide* BINDINGS_EXPORTED Create()
+ {
+ return new ElemHide();
+ }
+ // Used by GetSelectorsForDomain to narrow down selectors to return.
+ // Keep these value up to date in the ElemHide.js import script.
+ enum Criteria
+ {
+ // Return all selectors applying to a particular hostname.
+ ALL_MATCHING = 0,
+ // Exclude selectors which apply to all websites without exception.
+ NO_UNCONDITIONAL = 1,
+ // Return only selectors for filters which specifically match the
+ // given host name.
+ SPECIFIC_ONLY = 2,
+ };
+
+ void BINDINGS_EXPORTED Clear();
+ void BINDINGS_EXPORTED Add(ElemHideBase& filter);
+ void BINDINGS_EXPORTED Remove(ElemHideBase& filter);
+
+ ElemHide_SelectorList* BINDINGS_EXPORTED GetSelectorsForDomain(const String& domain,
+ Criteria criteria) const;
+ ElemHide_SelectorList* BINDINGS_EXPORTED GetUnconditionalSelectors() const;
+
+ ElemHideException* BINDINGS_EXPORTED GetException(const ElemHideBase& filter,
+ DependentString& docDomain) const;
+
+private:
+ void AddToFiltersByDomain(const ElemHideBasePtr & filter);
+};
+
« no previous file with comments | « no previous file | compiled/ElemHide.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld