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

Side by Side Diff: include/AdblockPlus/JsEngine.h

Issue 29377570: Issue 4931 - add possibility to not send data depending on connection properties (Closed)
Patch Set: Created Feb. 28, 2017, 10:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H 18 #ifndef ADBLOCK_PLUS_JS_ENGINE_H
19 #define ADBLOCK_PLUS_JS_ENGINE_H 19 #define ADBLOCK_PLUS_JS_ENGINE_H
20 20
21 #include <functional> 21 #include <functional>
22 #include <map> 22 #include <map>
23 #include <stdexcept> 23 #include <stdexcept>
24 #include <stdint.h> 24 #include <stdint.h>
25 #include <string> 25 #include <string>
26 #include <mutex>
26 #include <AdblockPlus/AppInfo.h> 27 #include <AdblockPlus/AppInfo.h>
27 #include <AdblockPlus/LogSystem.h> 28 #include <AdblockPlus/LogSystem.h>
28 #include <AdblockPlus/FileSystem.h> 29 #include <AdblockPlus/FileSystem.h>
29 #include <AdblockPlus/JsValue.h> 30 #include <AdblockPlus/JsValue.h>
30 #include <AdblockPlus/WebRequest.h> 31 #include <AdblockPlus/WebRequest.h>
31 32
32 namespace v8 33 namespace v8
33 { 34 {
34 class Arguments; 35 class Arguments;
35 class Isolate; 36 class Isolate;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 friend class JsValue; 82 friend class JsValue;
82 friend class JsContext; 83 friend class JsContext;
83 84
84 public: 85 public:
85 /** 86 /**
86 * Event callback function. 87 * Event callback function.
87 */ 88 */
88 typedef std::function<void(JsValueList& params)> EventCallback; 89 typedef std::function<void(JsValueList& params)> EventCallback;
89 90
90 /** 91 /**
92 * Callback function returning false when current connection is not allowed
93 * e.g. because it is a metered connection.
94 */
95 typedef std::function<bool()> IsConnectionAllowedCallback;
96
97 /**
91 * Maps events to callback functions. 98 * Maps events to callback functions.
92 */ 99 */
93 typedef std::map<std::string, EventCallback> EventMap; 100 typedef std::map<std::string, EventCallback> EventMap;
94 101
95 /** 102 /**
96 * Creates a new JavaScript engine instance. 103 * Creates a new JavaScript engine instance.
97 * @param appInfo Information about the app. 104 * @param appInfo Information about the app.
98 * @param isolate v8::Isolate wrapper. This parameter should be considered 105 * @param isolate v8::Isolate wrapper. This parameter should be considered
99 * as a temporary hack for tests, it will go away. Issue #3593. 106 * as a temporary hack for tests, it will go away. Issue #3593.
100 * @return New `JsEngine` instance. 107 * @return New `JsEngine` instance.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 222
216 /** 223 /**
217 * Sets the `WebRequest` implementation used for XMLHttpRequests. 224 * Sets the `WebRequest` implementation used for XMLHttpRequests.
218 * Setting this is optional, the engine will use a `DefaultWebRequest` 225 * Setting this is optional, the engine will use a `DefaultWebRequest`
219 * instance by default, which might be sufficient. 226 * instance by default, which might be sufficient.
220 * @param The `WebRequest` instance to use. 227 * @param The `WebRequest` instance to use.
221 */ 228 */
222 void SetWebRequest(WebRequestPtr val); 229 void SetWebRequest(WebRequestPtr val);
223 230
224 /** 231 /**
232 * Registers the callback function to check whether current connection is
233 * allowed for network requests.
234 * @param callback callback function.
235 */
236 void SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callb ack);
237
238 /**
239 * Checks whether current connection is allowed. If
240 * IsConnectionAllowedCallback is not set then then it returns true.
241 */
242 bool IsConnectionAllowed();
243
244 /**
225 * @see `SetLogSystem()`. 245 * @see `SetLogSystem()`.
226 */ 246 */
227 LogSystemPtr GetLogSystem(); 247 LogSystemPtr GetLogSystem();
228 248
229 /** 249 /**
230 * Sets the `LogSystem` implementation used for logging (e.g. to handle 250 * Sets the `LogSystem` implementation used for logging (e.g. to handle
231 * `console.log()` calls from JavaScript). 251 * `console.log()` calls from JavaScript).
232 * Setting this is optional, the engine will use a `DefaultLogSystem` 252 * Setting this is optional, the engine will use a `DefaultLogSystem`
233 * instance by default, which might be sufficient. 253 * instance by default, which might be sufficient.
234 * @param The `LogSystem` instance to use. 254 * @param The `LogSystem` instance to use.
(...skipping 22 matching lines...) Expand all
257 277
258 /// Isolate must be disposed only after disposing of all objects which are 278 /// Isolate must be disposed only after disposing of all objects which are
259 /// using it. 279 /// using it.
260 ScopedV8IsolatePtr isolate; 280 ScopedV8IsolatePtr isolate;
261 281
262 FileSystemPtr fileSystem; 282 FileSystemPtr fileSystem;
263 WebRequestPtr webRequest; 283 WebRequestPtr webRequest;
264 LogSystemPtr logSystem; 284 LogSystemPtr logSystem;
265 std::unique_ptr<v8::Persistent<v8::Context>> context; 285 std::unique_ptr<v8::Persistent<v8::Context>> context;
266 EventMap eventCallbacks; 286 EventMap eventCallbacks;
287 std::mutex isConnectionAllowedMutex;
288 IsConnectionAllowedCallback isConnectionAllowed;
267 }; 289 };
268 } 290 }
269 291
270 #endif 292 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/FilterEngine.h ('k') | lib/prefs.js » ('j') | src/FilterEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld