OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 JsValuePtr result = func->Call(params); | 127 JsValuePtr result = func->Call(params); |
128 return result->AsBool(); | 128 return result->AsBool(); |
129 } | 129 } |
130 | 130 |
131 bool Subscription::operator==(const Subscription& subscription) const | 131 bool Subscription::operator==(const Subscription& subscription) const |
132 { | 132 { |
133 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); | 133 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt
ring(); |
134 } | 134 } |
135 | 135 |
136 FilterEngine::FilterEngine(JsEnginePtr jsEngine) | 136 FilterEngine::FilterEngine(JsEnginePtr jsEngine) |
137 : jsEngine(jsEngine), initialized(false) | 137 : jsEngine(jsEngine), initialized(false), firstRun(false) |
138 { | 138 { |
139 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, thi
s)); | 139 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, |
| 140 this, std::tr1::placeholders::_1)); |
140 for (int i = 0; !jsSources[i].empty(); i += 2) | 141 for (int i = 0; !jsSources[i].empty(); i += 2) |
141 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); | 142 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); |
142 | 143 |
143 // TODO: This should really be implemented via a conditional variable | 144 // TODO: This should really be implemented via a conditional variable |
144 while (!initialized) | 145 while (!initialized) |
145 ::Sleep(10); | 146 ::Sleep(10); |
146 } | 147 } |
147 | 148 |
148 void FilterEngine::InitDone() | 149 void FilterEngine::InitDone(JsValueList& params) |
149 { | 150 { |
150 jsEngine->RemoveEventCallback("init"); | 151 jsEngine->RemoveEventCallback("init"); |
151 initialized = true; | 152 initialized = true; |
| 153 firstRun = params.size() && params[0]->AsBool(); |
| 154 } |
| 155 |
| 156 bool FilterEngine::IsFirstRun() const |
| 157 { |
| 158 return firstRun; |
152 } | 159 } |
153 | 160 |
154 FilterPtr FilterEngine::GetFilter(const std::string& text) | 161 FilterPtr FilterEngine::GetFilter(const std::string& text) |
155 { | 162 { |
156 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); | 163 JsValuePtr func = jsEngine->Evaluate("API.getFilterFromText"); |
157 JsValueList params; | 164 JsValueList params; |
158 params.push_back(jsEngine->NewValue(text)); | 165 params.push_back(jsEngine->NewValue(text)); |
159 return FilterPtr(new Filter(func->Call(params))); | 166 return FilterPtr(new Filter(func->Call(params))); |
160 } | 167 } |
161 | 168 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 { | 224 { |
218 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); | 225 JsValuePtr func = jsEngine->Evaluate("API.getElementHidingSelectors"); |
219 JsValueList params; | 226 JsValueList params; |
220 params.push_back(jsEngine->NewValue(domain)); | 227 params.push_back(jsEngine->NewValue(domain)); |
221 JsValueList result = func->Call(params)->AsList(); | 228 JsValueList result = func->Call(params)->AsList(); |
222 std::vector<std::string> selectors; | 229 std::vector<std::string> selectors; |
223 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) | 230 for (JsValueList::iterator it = result.begin(); it != result.end(); ++it) |
224 selectors.push_back((*it)->AsString()); | 231 selectors.push_back((*it)->AsString()); |
225 return selectors; | 232 return selectors; |
226 } | 233 } |
OLD | NEW |