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

Side by Side Diff: src/FilterEngine.cpp

Issue 4578638519336960: Issue 1296 - Add SetUpdateAvailableCallback (Closed)
Patch Set: Fix typo, only invoke callback when the updater passes a URL Created Sept. 19, 2014, 2:51 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (params.size() >= 1 && !params[0]->IsNull())
360 callback(params[0]->AsString());
361 }
362
363 void FilterEngine::ForceUpdateCheck(
364 FilterEngine::UpdateCheckDoneCallback callback)
344 { 365 {
345 std::string eventName = "updateCheckDone"; 366 std::string eventName = "updateCheckDone";
346 eventName += ++updateCheckId; 367 eventName += ++updateCheckId;
347 368
348 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone, 369 jsEngine->SetEventCallback(eventName, std::tr1::bind(&FilterEngine::UpdateChec kDone,
349 this, eventName, callback, std::tr1::placeholders::_1)); 370 this, eventName, callback, std::tr1::placeholders::_1));
350 371
351 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck"); 372 JsValuePtr func = jsEngine->Evaluate("API.forceUpdateCheck");
352 JsValueList params; 373 JsValueList params;
353 params.push_back(jsEngine->NewValue(eventName)); 374 params.push_back(jsEngine->NewValue(eventName));
354 func->Call(params); 375 func->Call(params);
355 } 376 }
356 377
357 void FilterEngine::UpdateCheckDone(const std::string& eventName, FilterEngine::U pdaterCallback callback, JsValueList& params) 378 void FilterEngine::UpdateCheckDone(const std::string& eventName,
379 FilterEngine::UpdateCheckDoneCallback callback, JsValueList& params)
358 { 380 {
359 jsEngine->RemoveEventCallback(eventName); 381 jsEngine->RemoveEventCallback(eventName);
360 382
361 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : ""); 383 std::string error(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsSt ring() : "");
362 callback(error); 384 callback(error);
363 } 385 }
364 386
365 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback) 387 void FilterEngine::SetFilterChangeCallback(FilterEngine::FilterChangeCallback ca llback)
366 { 388 {
367 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged, 389 jsEngine->SetEventCallback("filterChange", std::tr1::bind(&FilterEngine::Filte rChanged,
(...skipping 13 matching lines...) Expand all
381 } 403 }
382 404
383 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2) 405 int FilterEngine::CompareVersions(const std::string& v1, const std::string& v2)
384 { 406 {
385 JsValueList params; 407 JsValueList params;
386 params.push_back(jsEngine->NewValue(v1)); 408 params.push_back(jsEngine->NewValue(v1));
387 params.push_back(jsEngine->NewValue(v2)); 409 params.push_back(jsEngine->NewValue(v2));
388 JsValuePtr func = jsEngine->Evaluate("API.compareVersions"); 410 JsValuePtr func = jsEngine->Evaluate("API.compareVersions");
389 return func->Call(params)->AsInt(); 411 return func->Call(params)->AsInt();
390 } 412 }
OLDNEW
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | test/FilterEngine.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld