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

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

Issue 29453572: Issue 5286 - Update to use libadblockplus rev. b88d098aeab5 (Closed)
Patch Set: Created June 1, 2017, 11:10 a.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 | « include/AdblockPlus/IWebRequest.h ('k') | include/AdblockPlus/WebRequest.h » ('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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 * Shared smart pointer to a `JsEngine` instance. 50 * Shared smart pointer to a `JsEngine` instance.
51 */ 51 */
52 typedef std::shared_ptr<JsEngine> JsEnginePtr; 52 typedef std::shared_ptr<JsEngine> JsEnginePtr;
53 53
54 /** 54 /**
55 * A factory to construct DefaultTimer. 55 * A factory to construct DefaultTimer.
56 */ 56 */
57 TimerPtr CreateDefaultTimer(); 57 TimerPtr CreateDefaultTimer();
58 58
59 /** 59 /**
60 * A factory to construct DefaultWebRequest.
61 */
62 WebRequestPtr CreateDefaultWebRequest();
63
64 /**
60 * Scope based isolate manager. Creates a new isolate instance on 65 * Scope based isolate manager. Creates a new isolate instance on
61 * constructing and disposes it on destructing. 66 * constructing and disposes it on destructing.
62 */ 67 */
63 class ScopedV8Isolate 68 class ScopedV8Isolate
64 { 69 {
65 public: 70 public:
66 ScopedV8Isolate(); 71 ScopedV8Isolate();
67 ~ScopedV8Isolate(); 72 ~ScopedV8Isolate();
68 v8::Isolate* Get() 73 v8::Isolate* Get()
69 { 74 {
70 return isolate; 75 return isolate;
71 } 76 }
72 private: 77 private:
73 ScopedV8Isolate(const ScopedV8Isolate&); 78 ScopedV8Isolate(const ScopedV8Isolate&);
74 ScopedV8Isolate& operator=(const ScopedV8Isolate&); 79 ScopedV8Isolate& operator=(const ScopedV8Isolate&);
75 80
76 v8::Isolate* isolate; 81 v8::Isolate* isolate;
77 }; 82 };
78 83
79 /** 84 /**
80 * Shared smart pointer to ScopedV8Isolate instance;
81 */
82 typedef std::shared_ptr<ScopedV8Isolate> ScopedV8IsolatePtr;
83
84 /**
85 * JavaScript engine used by `FilterEngine`, wraps v8. 85 * JavaScript engine used by `FilterEngine`, wraps v8.
86 */ 86 */
87 class JsEngine : public std::enable_shared_from_this<JsEngine> 87 class JsEngine : public std::enable_shared_from_this<JsEngine>
88 { 88 {
89 friend class JsValue; 89 friend class JsValue;
90 friend class JsContext; 90 friend class JsContext;
91 91
92 struct JsWeakValuesList 92 struct JsWeakValuesList
93 { 93 {
94 ~JsWeakValuesList(); 94 ~JsWeakValuesList();
(...skipping 18 matching lines...) Expand all
113 class JsWeakValuesID 113 class JsWeakValuesID
114 { 114 {
115 friend class JsEngine; 115 friend class JsEngine;
116 JsWeakValuesLists::const_iterator iterator; 116 JsWeakValuesLists::const_iterator iterator;
117 }; 117 };
118 118
119 /** 119 /**
120 * Creates a new JavaScript engine instance. 120 * Creates a new JavaScript engine instance.
121 * @param appInfo Information about the app. 121 * @param appInfo Information about the app.
122 * @param timer Implementation of timer. 122 * @param timer Implementation of timer.
123 * @param webRequest Implementation of web request.
123 * @param isolate v8::Isolate wrapper. This parameter should be considered 124 * @param isolate v8::Isolate wrapper. This parameter should be considered
124 * as a temporary hack for tests, it will go away. Issue #3593. 125 * as a temporary hack for tests, it will go away. Issue #3593.
125 * @return New `JsEngine` instance. 126 * @return New `JsEngine` instance.
126 */ 127 */
127 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(), 128 static JsEnginePtr New(const AppInfo& appInfo = AppInfo(),
128 TimerPtr timer = CreateDefaultTimer(), 129 TimerPtr timer = CreateDefaultTimer(),
129 const ScopedV8IsolatePtr& isolate = ScopedV8IsolatePtr(new ScopedV8Isolate ())); 130 WebRequestPtr webRequest = CreateDefaultWebRequest());
130 131
131 /** 132 /**
132 * Registers the callback function for an event. 133 * Registers the callback function for an event.
133 * @param eventName Event name. Note that this can be any string - it's a 134 * @param eventName Event name. Note that this can be any string - it's a
134 * general purpose event handling mechanism. 135 * general purpose event handling mechanism.
135 * @param callback Event callback function. 136 * @param callback Event callback function.
136 */ 137 */
137 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback); 138 void SetEventCallback(const std::string& eventName, const EventCallback& cal lback);
138 139
139 /** 140 /**
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 */ 235 */
235 JsValueList TakeJsValues(const JsWeakValuesID& id); 236 JsValueList TakeJsValues(const JsWeakValuesID& id);
236 237
237 /* 238 /*
238 * Private functionality required to implement timers. 239 * Private functionality required to implement timers.
239 * @param arguments `v8::Arguments` is the arguments received in C++ 240 * @param arguments `v8::Arguments` is the arguments received in C++
240 * callback associated for global setTimeout method. 241 * callback associated for global setTimeout method.
241 */ 242 */
242 static void ScheduleTimer(const v8::Arguments& arguments); 243 static void ScheduleTimer(const v8::Arguments& arguments);
243 244
245 /*
246 * Private functionality required to implement web requests.
247 * @param arguments `v8::Arguments` is the arguments received in C++
248 * callback associated for global GET method.
249 */
250 static void ScheduleWebRequest(const v8::Arguments& arguments);
251
244 /** 252 /**
245 * Converts v8 arguments to `JsValue` objects. 253 * Converts v8 arguments to `JsValue` objects.
246 * @param arguments `v8::Arguments` object containing the arguments to 254 * @param arguments `v8::Arguments` object containing the arguments to
247 * convert. 255 * convert.
248 * @return List of arguments converted to `const JsValue` objects. 256 * @return List of arguments converted to `const JsValue` objects.
249 */ 257 */
250 JsValueList ConvertArguments(const v8::Arguments& arguments); 258 JsValueList ConvertArguments(const v8::Arguments& arguments);
251 259
252 /** 260 /**
253 * @see `SetFileSystem()`. 261 * @see `SetFileSystem()`.
254 */ 262 */
255 FileSystemPtr GetFileSystem() const; 263 FileSystemPtr GetFileSystem() const;
256 264
257 /** 265 /**
258 * Sets the `FileSystem` implementation used for all file I/O. 266 * Sets the `FileSystem` implementation used for all file I/O.
259 * Setting this is optional, the engine will use a `DefaultFileSystem` 267 * Setting this is optional, the engine will use a `DefaultFileSystem`
260 * instance by default, which might be sufficient. 268 * instance by default, which might be sufficient.
261 * @param The `FileSystem` instance to use. 269 * @param The `FileSystem` instance to use.
262 */ 270 */
263 void SetFileSystem(const FileSystemPtr& val); 271 void SetFileSystem(const FileSystemPtr& val);
264 272
265 /** 273 /**
266 * @see `SetWebRequest()`.
267 */
268 WebRequestPtr GetWebRequest() const;
269
270 /**
271 * Sets the `WebRequest` implementation used for XMLHttpRequests. 274 * Sets the `WebRequest` implementation used for XMLHttpRequests.
272 * Setting this is optional, the engine will use a `DefaultWebRequest` 275 * Setting this is optional, the engine will use a `DefaultWebRequest`
273 * instance by default, which might be sufficient. 276 * instance by default, which might be sufficient.
274 * @param The `WebRequest` instance to use. 277 * @param The `WebRequest` instance to use.
275 */ 278 */
276 void SetWebRequest(const WebRequestPtr& val); 279 void SetWebRequest(const WebRequestSharedPtr& val);
277 280
278 /** 281 /**
279 * @see `SetLogSystem()`. 282 * @see `SetLogSystem()`.
280 */ 283 */
281 LogSystemPtr GetLogSystem() const; 284 LogSystemPtr GetLogSystem() const;
282 285
283 /** 286 /**
284 * Sets the `LogSystem` implementation used for logging (e.g. to handle 287 * Sets the `LogSystem` implementation used for logging (e.g. to handle
285 * `console.log()` calls from JavaScript). 288 * `console.log()` calls from JavaScript).
286 * Setting this is optional, the engine will use a `DefaultLogSystem` 289 * Setting this is optional, the engine will use a `DefaultLogSystem`
287 * instance by default, which might be sufficient. 290 * instance by default, which might be sufficient.
288 * @param The `LogSystem` instance to use. 291 * @param The `LogSystem` instance to use.
289 */ 292 */
290 void SetLogSystem(const LogSystemPtr& val); 293 void SetLogSystem(const LogSystemPtr& val);
291 294
292 /** 295 /**
293 * Sets a global property that can be accessed by all the scripts. 296 * Sets a global property that can be accessed by all the scripts.
294 * @param name Name of the property to set. 297 * @param name Name of the property to set.
295 * @param value Value of the property to set. 298 * @param value Value of the property to set.
296 */ 299 */
297 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value); 300 void SetGlobalProperty(const std::string& name, const AdblockPlus::JsValue& value);
298 301
299 /** 302 /**
300 * Returns a pointer to associated v8::Isolate. 303 * Returns a pointer to associated v8::Isolate.
301 */ 304 */
302 v8::Isolate* GetIsolate() 305 v8::Isolate* GetIsolate()
303 { 306 {
304 return isolate->Get(); 307 return isolate.Get();
305 } 308 }
306 309
310 /**
311 * Notifies JS engine about critically low memory what should cause a
312 * garbage collection.
313 */
314 void NotifyLowMemory();
307 private: 315 private:
308 void CallTimerTask(const JsWeakValuesID& timerParamsID); 316 void CallTimerTask(const JsWeakValuesID& timerParamsID);
309 317
310 explicit JsEngine(const ScopedV8IsolatePtr& isolate, TimerPtr timer); 318 explicit JsEngine(TimerPtr timer, WebRequestPtr webRequest);
311 319
312 JsValue GetGlobalObject(); 320 JsValue GetGlobalObject();
313 321
314 /// Isolate must be disposed only after disposing of all objects which are 322 /// Isolate must be disposed only after disposing of all objects which are
315 /// using it. 323 /// using it.
316 ScopedV8IsolatePtr isolate; 324 ScopedV8Isolate isolate;
317 325
318 FileSystemPtr fileSystem; 326 FileSystemPtr fileSystem;
319 WebRequestPtr webRequest;
320 LogSystemPtr logSystem; 327 LogSystemPtr logSystem;
321 std::unique_ptr<v8::Persistent<v8::Context>> context; 328 std::unique_ptr<v8::Persistent<v8::Context>> context;
322 EventMap eventCallbacks; 329 EventMap eventCallbacks;
323 std::mutex eventCallbacksMutex; 330 std::mutex eventCallbacksMutex;
324 JsWeakValuesLists jsWeakValuesLists; 331 JsWeakValuesLists jsWeakValuesLists;
325 std::mutex jsWeakValuesListsMutex; 332 std::mutex jsWeakValuesListsMutex;
326 TimerPtr timer; 333 TimerPtr timer;
334 WebRequestPtr webRequest;
335 WebRequestSharedPtr webRequestLegacy;
327 }; 336 };
328 } 337 }
329 338
330 #endif 339 #endif
OLDNEW
« no previous file with comments | « include/AdblockPlus/IWebRequest.h ('k') | include/AdblockPlus/WebRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld