| OLD | NEW | 
|    1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H |    1 #ifndef ADBLOCKPLUS_FILTER_ENGINE_H | 
|    2 #define ADBLOCKPLUS_FILTER_ENGINE_H |    2 #define ADBLOCKPLUS_FILTER_ENGINE_H | 
|    3  |    3  | 
|    4 #include <vector> |    4 #include <vector> | 
|    5 #include <map> |    5 #include <map> | 
|    6 #include <string> |    6 #include <string> | 
|    7 #ifdef _MSC_VER |    7 #ifdef _MSC_VER | 
|    8 #include <memory> |    8 #include <memory> | 
|    9 #else |    9 #else | 
|   10 #include <tr1/memory> |   10 #include <tr1/memory> | 
|   11 #endif |   11 #endif | 
 |   12 #include <AdblockPlus/JsValue.h> | 
 |   13  | 
|   12 namespace AdblockPlus |   14 namespace AdblockPlus | 
|   13 { |   15 { | 
|   14   class JsEngine; |   16   class JsEngine; | 
|   15   class FilterEngine; |   17   class FilterEngine; | 
|   16  |   18  | 
 |   19 #if FILTER_ENGINE_STUBS | 
|   17   class JsObject |   20   class JsObject | 
 |   21 #else | 
 |   22   class JsObject : public JsValue | 
 |   23 #endif | 
|   18   { |   24   { | 
|   19   public: |   25   public: | 
|   20     std::string GetProperty(const std::string& name, const std::string& defaultV
     alue) const; |   26     std::string GetProperty(const std::string& name, const std::string& defaultV
     alue) const; | 
|   21     int GetProperty(const std::string& name, int defaultValue) const; |   27     int64_t GetProperty(const std::string& name, int64_t defaultValue) const; | 
|   22     bool GetProperty(const std::string& name, bool defaultValue) const; |   28     bool GetProperty(const std::string& name, bool defaultValue) const; | 
|   23     inline std::string GetProperty(const std::string& name, const char* defaultV
     alue) const |   29     inline std::string GetProperty(const std::string& name, const char* defaultV
     alue) const | 
|   24     { |   30     { | 
|   25       return GetProperty(name, std::string(defaultValue)); |   31       return GetProperty(name, std::string(defaultValue)); | 
|   26     } |   32     } | 
 |   33     inline int64_t GetProperty(const std::string& name, int defaultValue) const | 
 |   34     { | 
 |   35       return GetProperty(name, (int64_t)defaultValue); | 
 |   36     } | 
|   27  |   37  | 
 |   38 #if FILTER_ENGINE_STUBS | 
|   28     void SetProperty(const std::string& name, const std::string& value); |   39     void SetProperty(const std::string& name, const std::string& value); | 
|   29     void SetProperty(const std::string& name, int value); |   40     void SetProperty(const std::string& name, int64_t value); | 
|   30     void SetProperty(const std::string& name, bool value); |   41     void SetProperty(const std::string& name, bool value); | 
|   31     inline void SetProperty(const std::string& name, const char* value) |   42     inline void SetProperty(const std::string& name, const char* value) | 
|   32     { |   43     { | 
|   33       SetProperty(name, std::string(value)); |   44       SetProperty(name, std::string(value)); | 
|   34     } |   45     } | 
 |   46     inline void SetProperty(const std::string& name, int value) | 
 |   47     { | 
 |   48       SetProperty(name, (int64_t)value); | 
 |   49     } | 
 |   50 #endif | 
|   35  |   51  | 
|   36   protected: |   52   protected: | 
|   37 #if FILTER_ENGINE_STUBS |   53 #if FILTER_ENGINE_STUBS | 
|   38     JsObject(FilterEngine& filterEngine); |   54     JsObject(FilterEngine& filterEngine); | 
|   39  |   55  | 
|   40     FilterEngine& filterEngine; |   56     FilterEngine& filterEngine; | 
|   41     std::map<std::string, std::string> stringProperties; |   57     std::map<std::string, std::string> stringProperties; | 
|   42     std::map<std::string, int> intProperties; |   58     std::map<std::string, int64_t> intProperties; | 
|   43     std::map<std::string, bool> boolProperties; |   59     std::map<std::string, bool> boolProperties; | 
|   44 #else |   60 #else | 
|   45     JsObject(); |   61     JsObject(JsValuePtr value); | 
|   46 #endif |   62 #endif | 
|   47   }; |   63   }; | 
|   48  |   64  | 
|   49   class Filter : public JsObject, |   65   class Filter : public JsObject, | 
|   50                  public std::tr1::enable_shared_from_this<Filter> |   66                  public std::tr1::enable_shared_from_this<Filter> | 
|   51   { |   67   { | 
|   52     friend class FilterEngine; |  | 
|   53  |  | 
|   54   public: |   68   public: | 
|   55     enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, |   69     enum Type {TYPE_BLOCKING, TYPE_EXCEPTION, | 
|   56                TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, |   70                TYPE_ELEMHIDE, TYPE_ELEMHIDE_EXCEPTION, | 
|   57                TYPE_COMMENT, TYPE_INVALID}; |   71                TYPE_COMMENT, TYPE_INVALID}; | 
|   58  |   72  | 
|   59     bool IsListed() const; |   73     bool IsListed(); | 
|   60     void AddToList(); |   74     void AddToList(); | 
|   61     void RemoveFromList(); |   75     void RemoveFromList(); | 
 |   76     bool operator==(const Filter& filter) const; | 
|   62  |   77  | 
 |   78 #if FILTER_ENGINE_STUBS | 
|   63   private: |   79   private: | 
|   64 #if FILTER_ENGINE_STUBS |   80     friend class FilterEngine; | 
|   65     Filter(FilterEngine& filterEngine, const std::string& text); |   81     Filter(FilterEngine& filterEngine, const std::string& text); | 
|   66 #else |   82 #else | 
|   67     Filter(); |   83     Filter(JsValuePtr value); | 
|   68 #endif |   84 #endif | 
|   69   }; |   85   }; | 
|   70  |   86  | 
|   71   class Subscription : public JsObject, |   87   class Subscription : public JsObject, | 
|   72                        public std::tr1::enable_shared_from_this<Subscription> |   88                        public std::tr1::enable_shared_from_this<Subscription> | 
|   73   { |   89   { | 
|   74     friend class FilterEngine; |  | 
|   75  |  | 
|   76   public: |   90   public: | 
|   77     bool IsListed() const; |   91     bool IsListed(); | 
|   78     void AddToList(); |   92     void AddToList(); | 
|   79     void RemoveFromList(); |   93     void RemoveFromList(); | 
|   80     void UpdateFilters(); |   94     void UpdateFilters(); | 
 |   95     bool IsUpdating(); | 
 |   96     bool operator==(const Subscription& subscription) const; | 
|   81  |   97  | 
 |   98 #if FILTER_ENGINE_STUBS | 
|   82   private: |   99   private: | 
|   83 #if FILTER_ENGINE_STUBS |  100     friend class FilterEngine; | 
|   84     Subscription(FilterEngine& filterEngine, const std::string& url); |  101     Subscription(FilterEngine& filterEngine, const std::string& url); | 
|   85 #else |  102 #else | 
|   86     Subscription(); |  103     Subscription(JsValuePtr value); | 
|   87 #endif |  104 #endif | 
|   88   }; |  105   }; | 
|   89  |  106  | 
|   90   typedef std::tr1::shared_ptr<Filter> FilterPtr; |  107   typedef std::tr1::shared_ptr<Filter> FilterPtr; | 
|   91   typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; |  108   typedef std::tr1::shared_ptr<Subscription> SubscriptionPtr; | 
|   92   typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&); |  109   typedef void (*SubscriptionsCallback)(const std::vector<SubscriptionPtr>&); | 
|   93  |  110  | 
|   94   class FilterEngine |  111   class FilterEngine | 
|   95   { |  112   { | 
 |  113 #if FILTER_ENGINE_STUBS | 
|   96     friend class Filter; |  114     friend class Filter; | 
|   97     friend class Subscription; |  115     friend class Subscription; | 
 |  116 #endif | 
 |  117  | 
|   98   public: |  118   public: | 
|   99     explicit FilterEngine(JsEngine& jsEngine); |  119     explicit FilterEngine(JsEngine& jsEngine); | 
|  100     FilterPtr GetFilter(const std::string& text); |  120     FilterPtr GetFilter(const std::string& text); | 
|  101     SubscriptionPtr GetSubscription(const std::string& url); |  121     SubscriptionPtr GetSubscription(const std::string& url); | 
|  102     const std::vector<FilterPtr>& GetListedFilters() const; |  122     const std::vector<FilterPtr> GetListedFilters() const; | 
|  103     const std::vector<SubscriptionPtr>& GetListedSubscriptions() const; |  123     const std::vector<SubscriptionPtr> GetListedSubscriptions() const; | 
|  104     void FetchAvailableSubscriptions(SubscriptionsCallback callback); |  124     void FetchAvailableSubscriptions(SubscriptionsCallback callback); | 
|  105     FilterPtr Matches(const std::string& url, |  125     FilterPtr Matches(const std::string& url, | 
|  106         const std::string& contentType, |  126         const std::string& contentType, | 
|  107         const std::string& documentUrl); |  127         const std::string& documentUrl); | 
|  108     std::vector<std::string> GetElementHidingSelectors(const std::string& domain
     ) const; |  128     std::vector<std::string> GetElementHidingSelectors(const std::string& domain
     ) const; | 
|  109  |  129  | 
|  110   private: |  130   private: | 
|  111     JsEngine& jsEngine; |  131     JsEngine& jsEngine; | 
|  112 #if FILTER_ENGINE_STUBS |  132 #if FILTER_ENGINE_STUBS | 
|  113     std::map<std::string, FilterPtr> knownFilters; |  133     std::map<std::string, FilterPtr> knownFilters; | 
|  114     std::vector<FilterPtr> listedFilters; |  134     std::vector<FilterPtr> listedFilters; | 
|  115     std::map<std::string, SubscriptionPtr> knownSubscriptions; |  135     std::map<std::string, SubscriptionPtr> knownSubscriptions; | 
|  116     std::vector<SubscriptionPtr> listedSubscriptions; |  136     std::vector<SubscriptionPtr> listedSubscriptions; | 
|  117 #endif |  137 #endif | 
|  118   }; |  138   }; | 
|  119 } |  139 } | 
|  120  |  140  | 
|  121 #endif |  141 #endif | 
| OLD | NEW |