OLD | NEW |
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 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 { | 86 { |
87 const Context context(shared_from_this()); | 87 const Context context(shared_from_this()); |
88 const v8::TryCatch tryCatch; | 88 const v8::TryCatch tryCatch; |
89 const v8::Handle<v8::Script> script = CompileScript(source, filename); | 89 const v8::Handle<v8::Script> script = CompileScript(source, filename); |
90 CheckTryCatch(tryCatch); | 90 CheckTryCatch(tryCatch); |
91 v8::Local<v8::Value> result = script->Run(); | 91 v8::Local<v8::Value> result = script->Run(); |
92 CheckTryCatch(tryCatch); | 92 CheckTryCatch(tryCatch); |
93 return JsValuePtr(new JsValue(shared_from_this(), result)); | 93 return JsValuePtr(new JsValue(shared_from_this(), result)); |
94 } | 94 } |
95 | 95 |
| 96 void AdblockPlus::JsEngine::SetEventCallback(const std::string& eventName, |
| 97 AdblockPlus::JsEngine::EventCallback callback) |
| 98 { |
| 99 eventCallbacks[eventName] = callback; |
| 100 } |
| 101 |
| 102 void AdblockPlus::JsEngine::RemoveEventCallback(const std::string& eventName) |
| 103 { |
| 104 eventCallbacks.erase(eventName); |
| 105 } |
| 106 |
| 107 void AdblockPlus::JsEngine::TriggerEvent(const std::string& eventName) |
| 108 { |
| 109 EventMap::iterator it = eventCallbacks.find(eventName); |
| 110 if (it != eventCallbacks.end()) |
| 111 it->second(); |
| 112 } |
| 113 |
96 void AdblockPlus::JsEngine::Gc() | 114 void AdblockPlus::JsEngine::Gc() |
97 { | 115 { |
98 while (!v8::V8::IdleNotification()); | 116 while (!v8::V8::IdleNotification()); |
99 } | 117 } |
100 | 118 |
101 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) | 119 AdblockPlus::JsValuePtr AdblockPlus::JsEngine::NewValue(const std::string& val) |
102 { | 120 { |
103 const Context context(shared_from_this()); | 121 const Context context(shared_from_this()); |
104 return JsValuePtr(new JsValue(shared_from_this(), | 122 return JsValuePtr(new JsValue(shared_from_this(), |
105 v8::String::New(val.c_str(), val.length()))); | 123 v8::String::New(val.c_str(), val.length()))); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 throw std::runtime_error("LogSystem cannot be null"); | 219 throw std::runtime_error("LogSystem cannot be null"); |
202 | 220 |
203 logSystem = val; | 221 logSystem = val; |
204 } | 222 } |
205 | 223 |
206 AdblockPlus::JsEngine::Context::Context(const JsEnginePtr jsEngine) | 224 AdblockPlus::JsEngine::Context::Context(const JsEnginePtr jsEngine) |
207 : locker(jsEngine->isolate), handleScope(), | 225 : locker(jsEngine->isolate), handleScope(), |
208 contextScope(jsEngine->context) | 226 contextScope(jsEngine->context) |
209 { | 227 { |
210 } | 228 } |
OLD | NEW |