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

Unified Diff: src/FilterEngine.cpp

Issue 29377570: Issue 4931 - add possibility to not send data depending on connection properties (Closed)
Patch Set: Created Feb. 28, 2017, 2:22 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/prefs.js ('k') | src/JsEngine.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/FilterEngine.cpp
diff --git a/src/FilterEngine.cpp b/src/FilterEngine.cpp
index fd4ff4d3634dbd141d13d847b36aea9910bcb5a9..3e11223e4cd0b3cded93a43e706d988cb4253032 100644
--- a/src/FilterEngine.cpp
+++ b/src/FilterEngine.cpp
@@ -178,9 +178,31 @@ void FilterEngine::CreateAsync(const JsEnginePtr& jsEngine,
{
FilterEnginePtr filterEngine(new FilterEngine(jsEngine));
auto sync = std::make_shared<Sync>();
- jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync](JsValueList& params)
+ auto isConnectionAllowed = params.isConnectionAllowed;
+ if (isConnectionAllowed)
+ jsEngine->SetIsConnectionAllowedCallback([sync, jsEngine]()->bool
+ {
+ sync->Wait();
+ return jsEngine->IsConnectionAllowed();
+ });
+ jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated, sync, isConnectionAllowed](JsValueList& params)
{
filterEngine->firstRun = params.size() && params[0]->AsBool();
+ if (isConnectionAllowed)
+ {
+ std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine;
+ jsEngine->SetIsConnectionAllowedCallback([weakFilterEngine, isConnectionAllowed]()->bool
+ {
+ auto filterEngine = weakFilterEngine.lock();
+ if (!filterEngine)
+ return false;
+ auto prefValue = filterEngine->GetAllowedConnectionType();
+ if (prefValue->IsUndefined())
+ return isConnectionAllowed(nullptr);
+ auto allowedConnectionType = prefValue->AsString();
+ return isConnectionAllowed(&allowedConnectionType);
+ });
+ }
sync->Set();
onCreated(filterEngine);
jsEngine->RemoveEventCallback("_init");
@@ -427,7 +449,8 @@ void FilterEngine::SetPref(const std::string& pref, JsValuePtr value)
JsValuePtr func = jsEngine->Evaluate("API.setPref");
JsValueList params;
params.push_back(jsEngine->NewValue(pref));
- params.push_back(value);
+ if (value)
+ params.push_back(value);
func->Call(params);
}
@@ -494,6 +517,16 @@ void FilterEngine::RemoveFilterChangeCallback()
jsEngine->RemoveEventCallback("filterChange");
}
+void FilterEngine::SetAllowedConnectionType(const std::string* value)
+{
+ SetPref("allowed_connection_type", value ? jsEngine->NewValue(*value) : nullptr);
+}
+
+JsValuePtr FilterEngine::GetAllowedConnectionType()
+{
+ return GetPref("allowed_connection_type");
+}
+
void FilterEngine::FilterChanged(FilterEngine::FilterChangeCallback callback, JsValueList& params)
{
std::string action(params.size() >= 1 && !params[0]->IsNull() ? params[0]->AsString() : "");
« no previous file with comments | « lib/prefs.js ('k') | src/JsEngine.cpp » ('j') | src/WebRequestJsObject.cpp » ('J')

Powered by Google App Engine
This is Rietveld