| OLD | NEW | 
|---|
| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 192   FilterEnginePtr filterEngine(new FilterEngine(jsEngine)); | 192   FilterEnginePtr filterEngine(new FilterEngine(jsEngine)); | 
| 193   { | 193   { | 
| 194     // TODO: replace weakFilterEngine by this when it's possible to control the | 194     // TODO: replace weakFilterEngine by this when it's possible to control the | 
| 195     // execution time of the asynchronous part below. | 195     // execution time of the asynchronous part below. | 
| 196     std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine; | 196     std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine; | 
| 197     auto isSubscriptionDownloadAllowedCallback = params.isSubscriptionDownloadAl
     lowedCallback; | 197     auto isSubscriptionDownloadAllowedCallback = params.isSubscriptionDownloadAl
     lowedCallback; | 
| 198     jsEngine->SetEventCallback("_isSubscriptionDownloadAllowed", [weakFilterEngi
     ne, isSubscriptionDownloadAllowedCallback](JsValueList&& params){ | 198     jsEngine->SetEventCallback("_isSubscriptionDownloadAllowed", [weakFilterEngi
     ne, isSubscriptionDownloadAllowedCallback](JsValueList&& params){ | 
| 199       auto filterEngine = weakFilterEngine.lock(); | 199       auto filterEngine = weakFilterEngine.lock(); | 
| 200       if (!filterEngine) | 200       if (!filterEngine) | 
| 201         return; | 201         return; | 
| 202       auto jsEngine = filterEngine->GetJsEngine(); | 202       auto& jsEngine = filterEngine->GetJsEngine(); | 
| 203 | 203 | 
| 204       // param[0] - nullable string Prefs.allowed_connection_type | 204       // param[0] - nullable string Prefs.allowed_connection_type | 
| 205       // param[1] - function(Boolean) | 205       // param[1] - function(Boolean) | 
| 206       bool areArgumentsValid = params.size() == 2 && (params[0].IsNull() || para
     ms[0].IsString()) && params[1].IsFunction(); | 206       bool areArgumentsValid = params.size() == 2 && (params[0].IsNull() || para
     ms[0].IsString()) && params[1].IsFunction(); | 
| 207       assert(areArgumentsValid && "Invalid argument: there should be two args an
     d the second one should be a function"); | 207       assert(areArgumentsValid && "Invalid argument: there should be two args an
     d the second one should be a function"); | 
| 208       if (!areArgumentsValid) | 208       if (!areArgumentsValid) | 
| 209         return; | 209         return; | 
| 210       if (!isSubscriptionDownloadAllowedCallback) | 210       if (!isSubscriptionDownloadAllowedCallback) | 
| 211       { | 211       { | 
| 212         params[1].Call(jsEngine->NewValue(true)); | 212         params[1].Call(jsEngine.NewValue(true)); | 
| 213         return; | 213         return; | 
| 214       } | 214       } | 
| 215       auto valuesID = jsEngine->StoreJsValues(params); | 215       auto valuesID = jsEngine.StoreJsValues(params); | 
| 216       auto callJsCallback = [weakFilterEngine, valuesID](bool isAllowed) | 216       auto callJsCallback = [weakFilterEngine, valuesID](bool isAllowed) | 
| 217       { | 217       { | 
| 218         auto filterEngine = weakFilterEngine.lock(); | 218         auto filterEngine = weakFilterEngine.lock(); | 
| 219         if (!filterEngine) | 219         if (!filterEngine) | 
| 220           return; | 220           return; | 
| 221         auto jsEngine = filterEngine->GetJsEngine(); | 221         auto& jsEngine = filterEngine->GetJsEngine(); | 
| 222         auto jsParams = jsEngine->TakeJsValues(valuesID); | 222         auto jsParams = jsEngine.TakeJsValues(valuesID); | 
| 223         jsParams[1].Call(jsEngine->NewValue(isAllowed)); | 223         jsParams[1].Call(jsEngine.NewValue(isAllowed)); | 
| 224       }; | 224       }; | 
| 225       std::string allowedConnectionType = params[0].IsString() ? params[0].AsStr
     ing() : std::string(); | 225       std::string allowedConnectionType = params[0].IsString() ? params[0].AsStr
     ing() : std::string(); | 
| 226       isSubscriptionDownloadAllowedCallback(params[0].IsString() ? &allowedConne
     ctionType : nullptr, callJsCallback); | 226       isSubscriptionDownloadAllowedCallback(params[0].IsString() ? &allowedConne
     ctionType : nullptr, callJsCallback); | 
| 227     }); | 227     }); | 
| 228   } | 228   } | 
| 229 | 229 | 
| 230   jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated](JsValu
     eList&& params) | 230   jsEngine->SetEventCallback("_init", [jsEngine, filterEngine, onCreated](JsValu
     eList&& params) | 
| 231   { | 231   { | 
| 232     filterEngine->firstRun = params.size() && params[0].AsBool(); | 232     filterEngine->firstRun = params.size() && params[0].AsBool(); | 
| 233     onCreated(filterEngine); | 233     onCreated(filterEngine); | 
| 234     jsEngine->RemoveEventCallback("_init"); | 234     jsEngine->RemoveEventCallback("_init"); | 
| 235   }); | 235   }); | 
| 236 | 236 | 
| 237   std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine; | 237   std::weak_ptr<FilterEngine> weakFilterEngine = filterEngine; | 
| 238   filterEngine->SetFilterChangeCallback([weakFilterEngine](const std::string& re
     ason, JsValue&&) | 238   filterEngine->SetFilterChangeCallback([weakFilterEngine](const std::string& re
     ason, JsValue&&) | 
| 239   { | 239   { | 
| 240     auto filterEngine = weakFilterEngine.lock(); | 240     auto filterEngine = weakFilterEngine.lock(); | 
| 241     if (!filterEngine) | 241     if (!filterEngine) | 
| 242       return; | 242       return; | 
| 243     if (reason == "save") | 243     if (reason == "save") | 
| 244       filterEngine->GetJsEngine()->NotifyLowMemory(); | 244       filterEngine->GetJsEngine().NotifyLowMemory(); | 
| 245   }); | 245   }); | 
| 246 | 246 | 
| 247   // Lock the JS engine while we are loading scripts, no timeouts should fire | 247   // Lock the JS engine while we are loading scripts, no timeouts should fire | 
| 248   // until we are done. | 248   // until we are done. | 
| 249   const JsContext context(*jsEngine); | 249   const JsContext context(*jsEngine); | 
| 250   // Set the preconfigured prefs | 250   // Set the preconfigured prefs | 
| 251   auto preconfiguredPrefsObject = jsEngine->NewObject(); | 251   auto preconfiguredPrefsObject = jsEngine->NewObject(); | 
| 252   for (const auto& pref : params.preconfiguredPrefs) | 252   for (const auto& pref : params.preconfiguredPrefs) | 
| 253   { | 253   { | 
| 254     preconfiguredPrefsObject.SetProperty(pref.first, pref.second); | 254     preconfiguredPrefsObject.SetProperty(pref.first, pref.second); | 
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 591     FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
     Url); | 591     FilterPtr filter = GetWhitelistingFilter(currentUrl, contentTypeMask, parent
     Url); | 
| 592     if (filter) | 592     if (filter) | 
| 593     { | 593     { | 
| 594       return filter; | 594       return filter; | 
| 595     } | 595     } | 
| 596     currentUrl = parentUrl; | 596     currentUrl = parentUrl; | 
| 597   } | 597   } | 
| 598   while (urlIterator != documentUrls.end()); | 598   while (urlIterator != documentUrls.end()); | 
| 599   return FilterPtr(); | 599   return FilterPtr(); | 
| 600 } | 600 } | 
| OLD | NEW | 
|---|