Left: | ||
Right: |
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-2014 Eyeo GmbH | 3 * Copyright (C) 2006-2014 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 } | 333 } |
334 | 334 |
335 std::string FilterEngine::GetHostFromURL(const std::string& url) | 335 std::string FilterEngine::GetHostFromURL(const std::string& url) |
336 { | 336 { |
337 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); | 337 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); |
338 JsValueList params; | 338 JsValueList params; |
339 params.push_back(jsEngine->NewValue(url)); | 339 params.push_back(jsEngine->NewValue(url)); |
340 return func->Call(params)->AsString(); | 340 return func->Call(params)->AsString(); |
341 } | 341 } |
342 | 342 |
343 void FilterEngine::ForceUpdateCheck(FilterEngine::UpdaterCallback callback) | 343 void FilterEngine::SetUpdateAvailableCallback( |
344 FilterEngine::UpdateAvailableCallback callback) | |
345 { | |
346 jsEngine->SetEventCallback("updateAvailable", | |
347 std::tr1::bind(&FilterEngine::UpdateAvailable, this, callback, | |
348 std::tr1::placeholders::_1)); | |
349 } | |
350 | |
351 void FilterEngine::RemoveUpdateAvailableCallback() | |
352 { | |
353 jsEngine->RemoveEventCallback("updateAvailable"); | |
354 } | |
355 | |
356 void FilterEngine::UpdateAvailable( | |
357 FilterEngine::UpdateAvailableCallback callback, JsValueList& params) | |
358 { | |
359 callback(params[0]->AsString()); | |
Wladimir Palant
2014/09/18 19:44:17
I'd rather not crash if the JS code unexpectedly d
Felix Dahlke
2014/09/19 02:51:41
Knowing that the updater actually ensures a valid
| |
360 } | |
361 | |
362 void FilterEngine::ForceUpdateCheck( | |
363 FilterEngine::UpdateCheckDoneCallback callback) | |
344 { | 364 { |
345 std::string eventName = "updateCheckDone"; | 365 std::string eventName = "updateCheckDone"; |
346 eventName += ++updateCheckId; | 366 eventName += ++updateCheckId; |
347 | 367 |
348 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, | 368 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, |
349 this, eventName, callback, std::tr1::placeholders::_1)); | 369 this, eventName, callback, std::tr1::placeholders::_1)); |
350 | 370 |
351 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); | 371 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); |
352 JsValueList params; | 372 JsValueList params; |
353 params.push_back(jsEngine->NewValue(eventName)); | 373 params.push_back(jsEngine->NewValue(eventName)); |
354 func->Call(params); | 374 func->Call(params); |
355 } | 375 } |
356 | 376 |
357 void FilterEngine::UpdateCheckDone(const std::string& eventName, FilterEngine::U pdaterCallback callback, JsValueList& params) | 377 void FilterEngine::UpdateCheckDone(const std::string& eventName, |
378 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params) | |
358 { | 379 { |
359 jsEngine->RemoveEventCallback(eventName); | 380 jsEngine->RemoveEventCallback(eventName); |
360 | 381 |
361 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); | 382 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); |
362 callback(error); | 383 callback(error); |
363 } | 384 } |
364 | 385 |
365 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) | 386 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) |
366 { | 387 { |
367 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged, | 388 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged, |
(...skipping 13 matching lines...) Expand all Loading... | |
381 } | 402 } |
382 | 403 |
383 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) | 404 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) |
384 { | 405 { |
385 JsValueList params; | 406 JsValueList params; |
386 params.push_back(jsEngine->NewValue(v1)); | 407 params.push_back(jsEngine->NewValue(v1)); |
387 params.push_back(jsEngine->NewValue(v2)); | 408 params.push_back(jsEngine->NewValue(v2)); |
388 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); | 409 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); |
389 return func->Call(params)->AsInt(); | 410 return func->Call(params)->AsInt(); |
390 } | 411 } |
OLD | NEW |