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

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

Issue 10727002: Get rid of dependencies on v8.h in public header files (Closed)
Patch Set: Added helper class to make using v8 values via auto_ptr less awkward Created May 23, 2013, 4:08 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 | include/AdblockPlus/JsValue.h » ('j') | include/AdblockPlus/JsValue.h » ('J')
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 <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 <map>
22 #include <stdexcept> 22 #include <stdexcept>
23 #include <stdint.h> 23 #include <stdint.h>
24 #include <string> 24 #include <string>
25 #include <v8.h>
26 #include <AdblockPlus/AppInfo.h> 25 #include <AdblockPlus/AppInfo.h>
27 #include <AdblockPlus/tr1_functional.h> 26 #include <AdblockPlus/tr1_functional.h>
28 #include <AdblockPlus/LogSystem.h> 27 #include <AdblockPlus/LogSystem.h>
29 #include <AdblockPlus/FileSystem.h> 28 #include <AdblockPlus/FileSystem.h>
30 #include <AdblockPlus/JsValue.h> 29 #include <AdblockPlus/JsValue.h>
31 #include <AdblockPlus/WebRequest.h> 30 #include <AdblockPlus/WebRequest.h>
32 31
33 #include "tr1_memory.h" 32 #include "tr1_memory.h"
33 #include "V8ValueHolder.h"
34
35 namespace v8
36 {
37 class Arguments;
38 class Isolate;
39 class Context;
40 template <class T> class Handle;
Felix Dahlke 2013/05/24 15:45:41 I thought we agreed on "template<class T>" (no spa
41 template <class T> class Persistent;
42 typedef Handle<Value>(*InvocationCallback)(const Arguments &args);
43 }
34 44
35 namespace AdblockPlus 45 namespace AdblockPlus
36 { 46 {
37 class JsError : public std::runtime_error
38 {
39 public:
40 JsError(const v8::Handle<v8::Value> exception,
41 const v8::Handle<v8::Message> message);
42 };
43
44 class JsEngine; 47 class JsEngine;
45 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr; 48 typedef std::tr1::shared_ptr<JsEngine> JsEnginePtr;
46 49
47 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine> 50 class JsEngine : public std::tr1::enable_shared_from_this<JsEngine>
48 { 51 {
49 friend class JsValue; 52 friend class JsValue;
53 friend class JsContext;
50 54
51 public: 55 public:
52 typedef std::tr1::function<void()> EventCallback; 56 typedef std::tr1::function<void()> EventCallback;
53 typedef std::map<std::string, EventCallback> EventMap; 57 typedef std::map<std::string, EventCallback> EventMap;
54 58
55 static JsEnginePtr New(const AppInfo& appInfo = AppInfo()); 59 static JsEnginePtr New(const AppInfo& appInfo = AppInfo());
56 void SetEventCallback(const std::string& eventName, EventCallback callback); 60 void SetEventCallback(const std::string& eventName, EventCallback callback);
57 void RemoveEventCallback(const std::string& eventName); 61 void RemoveEventCallback(const std::string& eventName);
58 void TriggerEvent(const std::string& eventName); 62 void TriggerEvent(const std::string& eventName);
59 JsValuePtr Evaluate(const std::string& source, 63 JsValuePtr Evaluate(const std::string& source,
(...skipping 21 matching lines...) Expand all
81 static JsEnginePtr FromArguments(const v8::Arguments& arguments); 85 static JsEnginePtr FromArguments(const v8::Arguments& arguments);
82 JsValueList ConvertArguments(const v8::Arguments& arguments); 86 JsValueList ConvertArguments(const v8::Arguments& arguments);
83 87
84 FileSystemPtr GetFileSystem(); 88 FileSystemPtr GetFileSystem();
85 void SetFileSystem(FileSystemPtr val); 89 void SetFileSystem(FileSystemPtr val);
86 WebRequestPtr GetWebRequest(); 90 WebRequestPtr GetWebRequest();
87 void SetWebRequest(WebRequestPtr val); 91 void SetWebRequest(WebRequestPtr val);
88 LogSystemPtr GetLogSystem(); 92 LogSystemPtr GetLogSystem();
89 void SetLogSystem(LogSystemPtr val); 93 void SetLogSystem(LogSystemPtr val);
90 94
91 class Context
92 {
93 public:
94 Context(const JsEnginePtr jsEngine);
95 virtual inline ~Context() {};
96
97 private:
98 const v8::Locker locker;
99 const v8::HandleScope handleScope;
100 const v8::Context::Scope contextScope;
101 };
102
103 private: 95 private:
104 JsEngine(); 96 JsEngine();
105 97
106 FileSystemPtr fileSystem; 98 FileSystemPtr fileSystem;
107 WebRequestPtr webRequest; 99 WebRequestPtr webRequest;
108 LogSystemPtr logSystem; 100 LogSystemPtr logSystem;
109 v8::Isolate* isolate; 101 v8::Isolate* isolate;
110 v8::Persistent<v8::Context> context; 102 V8ValueHolder<v8::Context> context;
111 EventMap eventCallbacks; 103 EventMap eventCallbacks;
112 }; 104 };
113 } 105 }
114 106
115 #endif 107 #endif
OLDNEW
« no previous file with comments | « no previous file | include/AdblockPlus/JsValue.h » ('j') | include/AdblockPlus/JsValue.h » ('J')

Powered by Google App Engine
This is Rietveld