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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 10213003: Make JsEngine::Evaluate() return a wrapper for v8::Value to accessdifferent variable types easily (Closed)
Left Patch Set: Extended JsValue API to support all FilterEngine functions Created April 13, 2013, 8:42 p.m.
Right Patch Set: Addressed review comments Created April 17, 2013, 7:56 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « libadblockplus.gyp ('k') | src/JsEngine.cpp » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #include <algorithm> 1 #include <algorithm>
2 #include <cctype> 2 #include <cctype>
3 #include <functional> 3 #include <functional>
4 4
5 #include <AdblockPlus.h> 5 #include <AdblockPlus.h>
6 6
7 using namespace AdblockPlus; 7 using namespace AdblockPlus;
8 8
9 #if !FILTER_ENGINE_STUBS 9 #if !FILTER_ENGINE_STUBS
10 extern const char* jsSources[]; 10 extern const char* jsSources[];
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (text.find("!") == 0) 102 if (text.find("!") == 0)
103 type = TYPE_COMMENT; 103 type = TYPE_COMMENT;
104 else if (text.find("@@") == 0) 104 else if (text.find("@@") == 0)
105 type = TYPE_EXCEPTION; 105 type = TYPE_EXCEPTION;
106 else if (text.find("#@") != std::string::npos) 106 else if (text.find("#@") != std::string::npos)
107 type = TYPE_ELEMHIDE_EXCEPTION; 107 type = TYPE_ELEMHIDE_EXCEPTION;
108 else if (text.find("#") != std::string::npos) 108 else if (text.find("#") != std::string::npos)
109 type = TYPE_ELEMHIDE; 109 type = TYPE_ELEMHIDE;
110 else 110 else
111 type = TYPE_BLOCKING; 111 type = TYPE_BLOCKING;
112 SetProperty("type", (int64_t)type); 112 SetProperty("type", type);
113 } 113 }
114 #else 114 #else
115 Filter::Filter(JsValuePtr value) 115 Filter::Filter(JsValuePtr value)
116 : JsObject(value) 116 : JsObject(value)
117 { 117 {
118 // Hack: set `type` property according to class name 118 // Hack: set `type` property according to class name
119 std::string className = GetClassName(); 119 std::string className = GetClassName();
120 Type type; 120 Type type;
121 if (className == "BlockingFilter") 121 if (className == "BlockingFilter")
122 type = TYPE_BLOCKING; 122 type = TYPE_BLOCKING;
123 else if (className == "WhitelistFilter") 123 else if (className == "WhitelistFilter")
124 type = TYPE_EXCEPTION; 124 type = TYPE_EXCEPTION;
125 else if (className == "ElemHideFilter") 125 else if (className == "ElemHideFilter")
126 type = TYPE_ELEMHIDE; 126 type = TYPE_ELEMHIDE;
127 else if (className == "ElemHideException") 127 else if (className == "ElemHideException")
128 type = TYPE_ELEMHIDE_EXCEPTION; 128 type = TYPE_ELEMHIDE_EXCEPTION;
129 else if (className == "CommentFilter") 129 else if (className == "CommentFilter")
130 type = TYPE_COMMENT; 130 type = TYPE_COMMENT;
131 else 131 else
132 type = TYPE_INVALID; 132 type = TYPE_INVALID;
133 SetProperty("type", (int64_t)type); 133 SetProperty("type", type);
134 } 134 }
135 #endif 135 #endif
136 136
137 bool Filter::IsListed() 137 bool Filter::IsListed()
138 { 138 {
139 #if FILTER_ENGINE_STUBS 139 #if FILTER_ENGINE_STUBS
140 for (std::vector<FilterPtr>::iterator it = filterEngine.listedFilters.begin(); 140 for (std::vector<FilterPtr>::iterator it = filterEngine.listedFilters.begin();
141 it != filterEngine.listedFilters.end(); ++it) 141 it != filterEngine.listedFilters.end(); ++it)
142 { 142 {
143 if (it->get() == this) 143 if (it->get() == this)
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 #else 247 #else
248 JsValuePtr func = jsEngine.Evaluate("API.removeSubscriptionFromList"); 248 JsValuePtr func = jsEngine.Evaluate("API.removeSubscriptionFromList");
249 JsValueList params; 249 JsValueList params;
250 params.push_back(shared_from_this()); 250 params.push_back(shared_from_this());
251 func->Call(params); 251 func->Call(params);
252 #endif 252 #endif
253 } 253 }
254 254
255 void Subscription::UpdateFilters() 255 void Subscription::UpdateFilters()
256 { 256 {
257 #if !FILTER_ENGINE_STUBS
258 JsValuePtr func = jsEngine.Evaluate("API.updateSubscription");
259 JsValueList params;
260 params.push_back(shared_from_this());
261 func->Call(params);
262 #endif
263 }
264
265 bool Subscription::IsUpdating()
266 {
267 #if FILTER_ENGINE_STUBS
268 return false;
269 #else
270 JsValuePtr func = jsEngine.Evaluate("API.isSubscriptionUpdating");
271 JsValueList params;
272 params.push_back(shared_from_this());
273 JsValuePtr result = func->Call(params);
274 return result->AsBool();
275 #endif
257 } 276 }
258 277
259 bool Subscription::operator==(const Subscription& subscription) const 278 bool Subscription::operator==(const Subscription& subscription) const
260 { 279 {
261 return GetProperty("url", "") == subscription.GetProperty("url", ""); 280 return GetProperty("url", "") == subscription.GetProperty("url", "");
262 } 281 }
263 282
264 FilterEngine::FilterEngine(JsEngine& jsEngine) : jsEngine(jsEngine) 283 FilterEngine::FilterEngine(JsEngine& jsEngine) : jsEngine(jsEngine)
265 { 284 {
266 #if !FILTER_ENGINE_STUBS 285 #if !FILTER_ENGINE_STUBS
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 JsValuePtr func = jsEngine.Evaluate("API.getElementHidingSelectors"); 416 JsValuePtr func = jsEngine.Evaluate("API.getElementHidingSelectors");
398 JsValueList params; 417 JsValueList params;
399 params.push_back(jsEngine.NewValue(domain)); 418 params.push_back(jsEngine.NewValue(domain));
400 JsValueList result = func->Call(params)->AsList(); 419 JsValueList result = func->Call(params)->AsList();
401 std::vector<std::string> selectors; 420 std::vector<std::string> selectors;
402 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) 421 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it)
403 selectors.push_back((*it)->AsString()); 422 selectors.push_back((*it)->AsString());
404 return selectors; 423 return selectors;
405 #endif 424 #endif
406 } 425 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld