LEFT | RIGHT |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 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 <map> |
21 #include <stdexcept> | 22 #include <stdexcept> |
22 #include <stdint.h> | 23 #include <stdint.h> |
23 #include <string> | 24 #include <string> |
24 #include <v8.h> | 25 #include <v8.h> |
25 #include <AdblockPlus/AppInfo.h> | 26 #include <AdblockPlus/AppInfo.h> |
26 #include <AdblockPlus/tr1_functional.h> | 27 #include <AdblockPlus/tr1_functional.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> |
(...skipping 10 matching lines...) Expand all Loading... |
41 }; | 42 }; |
42 | 43 |
43 class JsEngine; | 44 class JsEngine; |
44 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; | 45 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; |
45 | 46 |
46 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> | 47 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> |
47 { | 48 { |
48 friend class JsValue; | 49 friend class JsValue; |
49 | 50 |
50 public: | 51 public: |
51 typedef std::tr1::function<void()> InitCallback; | 52 typedef std::tr1::function<void()> EventCallback; |
| 53 typedef std::map<std::string, EventCallback> EventMap; |
52 | 54 |
53 static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); | 55 static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); |
54 void SetInitCallback(InitCallback callback); | 56 void SetEventCallback(const std::string& eventName, EventCallback callback); |
55 void InitDone(void); | 57 void RemoveEventCallback(const std::string& eventName); |
| 58 void TriggerEvent(const std::string& eventName); |
56 JsValuePtr Evaluate(const std::string& source, | 59 JsValuePtr Evaluate(const std::string& source, |
57 const std::string& filename = ""); | 60 const std::string& filename = ""); |
58 void Gc(); | 61 void Gc(); |
59 JsValuePtr NewValue(const std::string& val); | 62 JsValuePtr NewValue(const std::string& val); |
60 JsValuePtr NewValue(int64_t val); | 63 JsValuePtr NewValue(int64_t val); |
61 JsValuePtr NewValue(bool val); | 64 JsValuePtr NewValue(bool val); |
62 inline JsValuePtr NewValue(const char* val) | 65 inline JsValuePtr NewValue(const char* val) |
63 { | 66 { |
64 return NewValue(std::string(val)); | 67 return NewValue(std::string(val)); |
65 } | 68 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 101 }; |
99 | 102 |
100 private: | 103 private: |
101 JsEngine(); | 104 JsEngine(); |
102 | 105 |
103 FileSystemPtr fileSystem; | 106 FileSystemPtr fileSystem; |
104 WebRequestPtr webRequest; | 107 WebRequestPtr webRequest; |
105 LogSystemPtr logSystem; | 108 LogSystemPtr logSystem; |
106 v8::Isolate* isolate; | 109 v8::Isolate* isolate; |
107 v8::Persistent<v8::Context> context; | 110 v8::Persistent<v8::Context> context; |
108 InitCallback initCallback; | 111 EventMap eventCallbacks; |
109 }; | 112 }; |
110 } | 113 } |
111 | 114 |
112 #endif | 115 #endif |
LEFT | RIGHT |