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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29317074: Issue 2693 - Update adblockplus dependency (Closed)
Left Patch Set: Created June 18, 2015, 3:31 p.m.
Right Patch Set: rebase Created July 2, 2015, 1:37 p.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') | test/Notification.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 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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
127 params.push_back(shared_from_this()); 127 params.push_back(shared_from_this());
128 JsValuePtr result = func->Call(params); 128 JsValuePtr result = func->Call(params);
129 return result->AsBool(); 129 return result->AsBool();
130 } 130 }
131 131
132 bool Subscription::operator==(const Subscription& subscription) const 132 bool Subscription::operator==(const Subscription& subscription) const
133 { 133 {
134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring(); 134 return GetProperty("url")->AsString() == subscription.GetProperty("url")->AsSt ring();
135 } 135 }
136 136
137 FilterEngine::FilterEngine(JsEnginePtr jsEngine) 137 FilterEngine::FilterEngine(JsEnginePtr jsEngine,
138 const FilterEngine::Prefs& preconfiguredPrefs)
138 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0) 139 : jsEngine(jsEngine), initialized(false), firstRun(false), updateCheckId(0)
139 { 140 {
140 jsEngine->SetEventCallback("init", std::tr1::bind(&FilterEngine::InitDone, 141 jsEngine->SetEventCallback("_init", std::tr1::bind(&FilterEngine::InitDone,
141 this, std::tr1::placeholders::_1)); 142 this, std::tr1::placeholders::_1));
142 143
143 { 144 {
144 // Lock the JS engine while we are loading scripts, no timeouts should fire 145 // Lock the JS engine while we are loading scripts, no timeouts should fire
145 // until we are done. 146 // until we are done.
146 const JsContext context(jsEngine); 147 const JsContext context(jsEngine);
148
149 // Set the preconfigured prefs
150 JsValuePtr preconfiguredPrefsObject = jsEngine->NewObject();
151 for (FilterEngine::Prefs::const_iterator it = preconfiguredPrefs.begin();
152 it != preconfiguredPrefs.end(); it++)
153 {
154 preconfiguredPrefsObject->SetProperty(it->first, it->second);
155 }
156 jsEngine->SetGlobalProperty("_preconfiguredPrefs", preconfiguredPrefsObject) ;
157 // Load adblockplus scripts
147 for (int i = 0; !jsSources[i].empty(); i += 2) 158 for (int i = 0; !jsSources[i].empty(); i += 2)
148 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]); 159 jsEngine->Evaluate(jsSources[i + 1], jsSources[i]);
149 } 160 }
150 161
151 // TODO: This should really be implemented via a conditional variable 162 // TODO: This should really be implemented via a conditional variable
152 while (!initialized) 163 while (!initialized)
153 ::Sleep(10); 164 ::Sleep(10);
154 } 165 }
155 166
156 namespace 167 namespace
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 it != contentTypes.end(); it++) 205 it != contentTypes.end(); it++)
195 { 206 {
196 if (it->second == contentTypeUpper) 207 if (it->second == contentTypeUpper)
197 return it->first; 208 return it->first;
198 } 209 }
199 throw std::invalid_argument("Cannot convert argument to ContentType"); 210 throw std::invalid_argument("Cannot convert argument to ContentType");
200 } 211 }
201 212
202 void FilterEngine::InitDone(JsValueList& params) 213 void FilterEngine::InitDone(JsValueList& params)
203 { 214 {
204 jsEngine->RemoveEventCallback("init"); 215 jsEngine->RemoveEventCallback("_init");
205 initialized = true; 216 initialized = true;
206 firstRun = params.size() && params[0]->AsBool(); 217 firstRun = params.size() && params[0]->AsBool();
207 } 218 }
208 219
209 bool FilterEngine::IsFirstRun() const 220 bool FilterEngine::IsFirstRun() const
210 { 221 {
211 return firstRun; 222 return firstRun;
212 } 223 }
213 224
214 FilterPtr FilterEngine::GetFilter(const std::string& text) 225 FilterPtr FilterEngine::GetFilter(const std::string& text)
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 { 272 {
262 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification"); 273 JsValuePtr func = jsEngine->Evaluate("API.showNextNotification");
263 JsValueList params; 274 JsValueList params;
264 if (!url.empty()) 275 if (!url.empty())
265 { 276 {
266 params.push_back(jsEngine->NewValue(url)); 277 params.push_back(jsEngine->NewValue(url));
267 } 278 }
268 func->Call(params); 279 func->Call(params);
269 } 280 }
270 281
271 void FilterEngine::SetNotificationAvailableCallback(const NotificationAvailableC allback& value) 282 void FilterEngine::SetShowNotificationCallback(const ShowNotificationCallback& v alue)
272 { 283 {
273 if (!value) 284 if (!value)
274 return; 285 return;
275 286
276 jsEngine->SetEventCallback("notificationAvailable", 287 jsEngine->SetEventCallback("_showNotification",
277 std::tr1::bind(&FilterEngine::NotificationAvailable, this, value, 288 std::tr1::bind(&FilterEngine::ShowNotification, this, value,
278 std::tr1::placeholders::_1)); 289 std::tr1::placeholders::_1));
279 } 290 }
280 291
281 void FilterEngine::RemoveNotificationAvailableCallback() 292 void FilterEngine::RemoveShowNotificationCallback()
282 { 293 {
283 jsEngine->RemoveEventCallback("notificationAvailable"); 294 jsEngine->RemoveEventCallback("_showNotification");
284 } 295 }
285 296
286 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url, 297 AdblockPlus::FilterPtr FilterEngine::Matches(const std::string& url,
287 ContentType contentType, 298 ContentType contentType,
288 const std::string& documentUrl) const 299 const std::string& documentUrl) const
289 { 300 {
290 std::vector<std::string> documentUrls; 301 std::vector<std::string> documentUrls;
291 documentUrls.push_back(documentUrl); 302 documentUrls.push_back(documentUrl);
292 return Matches(url, contentType, documentUrls); 303 return Matches(url, contentType, documentUrls);
293 } 304 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 void FilterEngine::UpdateAvailable( 394 void FilterEngine::UpdateAvailable(
384 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) 395 FilterEngine::UpdateAvailableCallback callback, JsValueList& params)
385 { 396 {
386 if (params.size() >= 1 && !params[0]->IsNull()) 397 if (params.size() >= 1 && !params[0]->IsNull())
387 callback(params[0]->AsString()); 398 callback(params[0]->AsString());
388 } 399 }
389 400
390 void FilterEngine::ForceUpdateCheck( 401 void FilterEngine::ForceUpdateCheck(
391 FilterEngine::UpdateCheckDoneCallback callback) 402 FilterEngine::UpdateCheckDoneCallback callback)
392 { 403 {
393 std::string eventName = "updateCheckDone"; 404 std::string eventName = "_updateCheckDone";
394 eventName += ++updateCheckId; 405 eventName += ++updateCheckId;
395 406
396 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, 407 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone,
397 this, eventName, callback, std::tr1::placeholders::_1)); 408 this, eventName, callback, std::tr1::placeholders::_1));
398 409
399 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); 410 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck");
400 JsValueList params; 411 JsValueList params;
401 params.push_back(jsEngine->NewValue(eventName)); 412 params.push_back(jsEngine->NewValue(eventName));
402 func->Call(params); 413 func->Call(params);
403 } 414 }
(...skipping 18 matching lines...) Expand all
422 jsEngine->RemoveEventCallback("filterChange"); 433 jsEngine->RemoveEventCallback("filterChange");
423 } 434 }
424 435
425 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) 436 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params)
426 { 437 {
427 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); 438 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : "");
428 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); 439 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
429 callback(action, item); 440 callback(action, item);
430 } 441 }
431 442
432 void FilterEngine::NotificationAvailable(const NotificationAvailableCallback& ca llback, 443 void FilterEngine::ShowNotification(const ShowNotificationCallback& callback,
433 const JsValueList& params) 444 const JsValueList& params)
434 { 445 {
435 if (params.size() < 1) 446 if (params.size() < 1)
436 return; 447 return;
437 448
438 callback(Notification::JsValueToNotification(params[0])); 449 callback(Notification::JsValueToNotification(params[0]));
439 } 450 }
440 451
441 452
442 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 453 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
443 { 454 {
444 JsValueList params; 455 JsValueList params;
445 params.push_back(jsEngine->NewValue(v1)); 456 params.push_back(jsEngine->NewValue(v1));
446 params.push_back(jsEngine->NewValue(v2)); 457 params.push_back(jsEngine->NewValue(v2));
447 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 458 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
448 return func->Call(params)->AsInt(); 459 return func->Call(params)->AsInt();
449 } 460 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld