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

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

Issue 29424786: Issue 5182 - fix IsConnectionAllowed (Closed) Base URL: https://github.com/adblockplus/libadblockplus.git
Patch Set: Created April 28, 2017, 2:42 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
« no previous file with comments | « no previous file | lib/compat.js » ('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 <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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> values; 95 std::vector<std::unique_ptr<v8::Persistent<v8::Value>>> values;
96 }; 96 };
97 typedef std::list<JsWeakValuesList> JsWeakValuesLists; 97 typedef std::list<JsWeakValuesList> JsWeakValuesLists;
98 public: 98 public:
99 /** 99 /**
100 * Event callback function. 100 * Event callback function.
101 */ 101 */
102 typedef std::function<void(JsValueList&& params)> EventCallback; 102 typedef std::function<void(JsValueList&& params)> EventCallback;
103 103
104 /** 104 /**
105 * Callback function returning false when current connection is not allowed
106 * e.g. because it is a metered connection.
107 */
108 typedef std::function<bool()> IsConnectionAllowedCallback;
109
110 /**
111 * Maps events to callback functions. 105 * Maps events to callback functions.
112 */ 106 */
113 typedef std::map<std::string, EventCallback> EventMap; 107 typedef std::map<std::string, EventCallback> EventMap;
114 108
115 /** 109 /**
116 * An opaque structure representing ID of stored JsValueList. 110 * An opaque structure representing ID of stored JsValueList.
117 * 111 *
118 */ 112 */
119 class JsWeakValuesID 113 class JsWeakValuesID
120 { 114 {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 269
276 /** 270 /**
277 * Sets the `WebRequest` implementation used for XMLHttpRequests. 271 * Sets the `WebRequest` implementation used for XMLHttpRequests.
278 * Setting this is optional, the engine will use a `DefaultWebRequest` 272 * Setting this is optional, the engine will use a `DefaultWebRequest`
279 * instance by default, which might be sufficient. 273 * instance by default, which might be sufficient.
280 * @param The `WebRequest` instance to use. 274 * @param The `WebRequest` instance to use.
281 */ 275 */
282 void SetWebRequest(const WebRequestPtr& val); 276 void SetWebRequest(const WebRequestPtr& val);
283 277
284 /** 278 /**
285 * Registers the callback function to check whether current connection is
286 * allowed for network requests.
287 * @param callback callback function.
288 */
289 void SetIsConnectionAllowedCallback(const IsConnectionAllowedCallback& callb ack);
290
291 /**
292 * Checks whether current connection is allowed. If
293 * IsConnectionAllowedCallback is not set then then it returns true.
294 */
295 bool IsConnectionAllowed() const;
296
297 /**
298 * @see `SetLogSystem()`. 279 * @see `SetLogSystem()`.
299 */ 280 */
300 LogSystemPtr GetLogSystem() const; 281 LogSystemPtr GetLogSystem() const;
301 282
302 /** 283 /**
303 * Sets the `LogSystem` implementation used for logging (e.g. to handle 284 * Sets the `LogSystem` implementation used for logging (e.g. to handle
304 * `console.log()` calls from JavaScript). 285 * `console.log()` calls from JavaScript).
305 * Setting this is optional, the engine will use a `DefaultLogSystem` 286 * Setting this is optional, the engine will use a `DefaultLogSystem`
306 * instance by default, which might be sufficient. 287 * instance by default, which might be sufficient.
307 * @param The `LogSystem` instance to use. 288 * @param The `LogSystem` instance to use.
(...skipping 25 matching lines...) Expand all
333 /// Isolate must be disposed only after disposing of all objects which are 314 /// Isolate must be disposed only after disposing of all objects which are
334 /// using it. 315 /// using it.
335 ScopedV8IsolatePtr isolate; 316 ScopedV8IsolatePtr isolate;
336 317
337 FileSystemPtr fileSystem; 318 FileSystemPtr fileSystem;
338 WebRequestPtr webRequest; 319 WebRequestPtr webRequest;
339 LogSystemPtr logSystem; 320 LogSystemPtr logSystem;
340 std::unique_ptr<v8::Persistent<v8::Context>> context; 321 std::unique_ptr<v8::Persistent<v8::Context>> context;
341 EventMap eventCallbacks; 322 EventMap eventCallbacks;
342 std::mutex eventCallbacksMutex; 323 std::mutex eventCallbacksMutex;
343 mutable std::mutex isConnectionAllowedMutex;
344 IsConnectionAllowedCallback isConnectionAllowed;
345 JsWeakValuesLists jsWeakValuesLists; 324 JsWeakValuesLists jsWeakValuesLists;
346 std::mutex jsWeakValuesListsMutex; 325 std::mutex jsWeakValuesListsMutex;
347 TimerPtr timer; 326 TimerPtr timer;
348 }; 327 };
349 } 328 }
350 329
351 #endif 330 #endif
OLDNEW
« no previous file with comments | « no previous file | lib/compat.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld