| 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 | 
| 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> | 
|  | 27 #include <AdblockPlus/tr1_functional.h> | 
| 26 #include <AdblockPlus/LogSystem.h> | 28 #include <AdblockPlus/LogSystem.h> | 
| 27 #include <AdblockPlus/FileSystem.h> | 29 #include <AdblockPlus/FileSystem.h> | 
| 28 #include <AdblockPlus/JsValue.h> | 30 #include <AdblockPlus/JsValue.h> | 
| 29 #include <AdblockPlus/WebRequest.h> | 31 #include <AdblockPlus/WebRequest.h> | 
| 30 | 32 | 
| 31 #include "tr1_memory.h" | 33 #include "tr1_memory.h" | 
| 32 | 34 | 
| 33 namespace AdblockPlus | 35 namespace AdblockPlus | 
| 34 { | 36 { | 
| 35   class JsError : public std::runtime_error | 37   class JsError : public std::runtime_error | 
| 36   { | 38   { | 
| 37   public: | 39   public: | 
| 38     JsError(const v8::Handle<v8::Value> exception, | 40     JsError(const v8::Handle<v8::Value> exception, | 
| 39             const v8::Handle<v8::Message> message); | 41             const v8::Handle<v8::Message> message); | 
| 40   }; | 42   }; | 
| 41 | 43 | 
| 42   class JsEngine; | 44   class JsEngine; | 
| 43   typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; | 45   typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; | 
| 44 | 46 | 
| 45   class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> | 47   class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> | 
| 46   { | 48   { | 
| 47     friend class JsValue; | 49     friend class JsValue; | 
| 48 | 50 | 
| 49   public: | 51   public: | 
|  | 52     typedef std::tr1::function<void()> EventCallback; | 
|  | 53     typedef std::map<std::string, EventCallback> EventMap; | 
|  | 54 | 
| 50     static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); | 55     static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); | 
|  | 56     void SetEventCallback(const std::string& eventName, EventCallback callback); | 
|  | 57     void RemoveEventCallback(const std::string& eventName); | 
|  | 58     void TriggerEvent(const std::string& eventName); | 
| 51     JsValuePtr Evaluate(const std::string& source, | 59     JsValuePtr Evaluate(const std::string& source, | 
| 52         const std::string& filename = ""); | 60         const std::string& filename = ""); | 
| 53     void Gc(); | 61     void Gc(); | 
| 54     JsValuePtr NewValue(const std::string& val); | 62     JsValuePtr NewValue(const std::string& val); | 
| 55     JsValuePtr NewValue(int64_t val); | 63     JsValuePtr NewValue(int64_t val); | 
| 56     JsValuePtr NewValue(bool val); | 64     JsValuePtr NewValue(bool val); | 
| 57     inline JsValuePtr NewValue(const char* val) | 65     inline JsValuePtr NewValue(const char* val) | 
| 58     { | 66     { | 
| 59       return NewValue(std::string(val)); | 67       return NewValue(std::string(val)); | 
| 60     } | 68     } | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 93     }; | 101     }; | 
| 94 | 102 | 
| 95   private: | 103   private: | 
| 96     JsEngine(); | 104     JsEngine(); | 
| 97 | 105 | 
| 98     FileSystemPtr fileSystem; | 106     FileSystemPtr fileSystem; | 
| 99     WebRequestPtr webRequest; | 107     WebRequestPtr webRequest; | 
| 100     LogSystemPtr logSystem; | 108     LogSystemPtr logSystem; | 
| 101     v8::Isolate* isolate; | 109     v8::Isolate* isolate; | 
| 102     v8::Persistent<v8::Context> context; | 110     v8::Persistent<v8::Context> context; | 
|  | 111     EventMap eventCallbacks; | 
| 103   }; | 112   }; | 
| 104 } | 113 } | 
| 105 | 114 | 
| 106 #endif | 115 #endif | 
| OLD | NEW | 
|---|