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

Delta Between Two Patch Sets: src/FilterEngine.cpp

Issue 29396582: Issue 5039 - add support of nullable non-object values in settings
Left Patch Set: Created March 28, 2017, 9:25 a.m.
Right Patch Set: rebase Created March 29, 2017, 4:39 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/prefs.js ('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
(no file at all)
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-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 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 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 { 410 {
411 JsValuePtr func = jsEngine->Evaluate("API.getPref"); 411 JsValuePtr func = jsEngine->Evaluate("API.getPref");
412 return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref))); 412 return std::make_shared<JsValue>(func->Call(*jsEngine->NewValue(pref)));
413 } 413 }
414 414
415 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value) 415 void FilterEngine::SetPref(const std::string& pref, JsValuePtr value)
416 { 416 {
417 JsValuePtr func = jsEngine->Evaluate("API.setPref"); 417 JsValuePtr func = jsEngine->Evaluate("API.setPref");
418 JsConstValueList params; 418 JsConstValueList params;
419 params.push_back(jsEngine->NewValue(pref)); 419 params.push_back(jsEngine->NewValue(pref));
420 if (value) 420 params.push_back(value);
421 params.push_back(value);
422 func->Call(params); 421 func->Call(params);
423 } 422 }
424 423
425 std::string FilterEngine::GetHostFromURL(const std::string& url) const 424 std::string FilterEngine::GetHostFromURL(const std::string& url) const
426 { 425 {
427 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl"); 426 JsValuePtr func = jsEngine->Evaluate("API.getHostFromUrl");
428 return func->Call(*jsEngine->NewValue(url)).AsString(); 427 return func->Call(*jsEngine->NewValue(url)).AsString();
429 } 428 }
430 429
431 void FilterEngine::SetUpdateAvailableCallback( 430 void FilterEngine::SetUpdateAvailableCallback(
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 this, callback, std::placeholders::_1)); 477 this, callback, std::placeholders::_1));
479 } 478 }
480 479
481 void FilterEngine::RemoveFilterChangeCallback() 480 void FilterEngine::RemoveFilterChangeCallback()
482 { 481 {
483 jsEngine->RemoveEventCallback("filterChange"); 482 jsEngine->RemoveEventCallback("filterChange");
484 } 483 }
485 484
486 void FilterEngine::SetAllowedConnectionType(const std::string* value) 485 void FilterEngine::SetAllowedConnectionType(const std::string* value)
487 { 486 {
488 SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : jsEngi ne->NewValue("")); 487 SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : jsEngi ne->NullValue());
489 } 488 }
490 489
491 std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const 490 std::unique_ptr<std::string> FilterEngine::GetAllowedConnectionType() const
492 { 491 {
493 auto prefValue = GetPref("allowed_connection_type"); 492 auto prefValue = GetPref("allowed_connection_type");
494 if (prefValue->AsString().empty()) 493 if (prefValue->IsNull())
495 return nullptr; 494 return nullptr;
496 return std::unique_ptr<std::string>(new std::string(prefValue->AsString())); 495 return std::unique_ptr<std::string>(new std::string(prefValue->AsString()));
497 } 496 }
498 497
499 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params) 498 void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, Js ValueList& params)
500 { 499 {
501 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : ""); 500 std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsS tring() : "");
502 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false)); 501 JsValuePtr item(params.size() >= 2 ? params[1] : jsEngine->NewValue(false));
503 callback(action, item); 502 callback(action, item);
504 } 503 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url); 553 FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent Url);
555 if (filter) 554 if (filter)
556 { 555 {
557 return filter; 556 return filter;
558 } 557 }
559 currentUrl = parentUrl; 558 currentUrl = parentUrl;
560 } 559 }
561 while (urlIterator != documentUrls.end()); 560 while (urlIterator != documentUrls.end());
562 return FilterPtr(); 561 return FilterPtr();
563 } 562 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld