Built UserAgent according to OS And Product.
[platform/framework/web/crosswalk-tizen.git] / atom / browser / javascript_environment.h
1 // Copyright (c) 2013 GitHub, Inc.
2 // Use of this source code is governed by the MIT license that can be
3 // found in the LICENSE file.
4
5 #ifndef ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
6 #define ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
7
8 #include "base/macros.h"
9 #include "gin/public/isolate_holder.h"
10
11 namespace node {
12 class Environment;
13 }
14
15 namespace atom {
16
17 // Manage the V8 isolate and context automatically.
18 class JavascriptEnvironment {
19  public:
20   JavascriptEnvironment();
21
22   void OnMessageLoopCreated();
23   void OnMessageLoopDestroying();
24   void SetupLocker();
25
26   v8::Isolate* isolate() const { return isolate_; }
27   v8::Local<v8::Context> context() const {
28     return v8::Local<v8::Context>::New(isolate_, context_);
29   }
30
31  private:
32   bool Initialize();
33
34   bool initialized_;
35   gin::IsolateHolder isolate_holder_;
36   v8::Isolate* isolate_;
37   v8::Isolate::Scope isolate_scope_;
38   std::unique_ptr<v8::Locker> locker_;
39   v8::HandleScope handle_scope_;
40   v8::UniquePersistent<v8::Context> context_;
41   v8::Context::Scope context_scope_;
42
43   DISALLOW_COPY_AND_ASSIGN(JavascriptEnvironment);
44 };
45
46 // Manage the Node Environment automatically.
47 class NodeEnvironment {
48  public:
49   explicit NodeEnvironment(node::Environment* env);
50   ~NodeEnvironment();
51
52  private:
53   node::Environment* env_;
54
55   DISALLOW_COPY_AND_ASSIGN(NodeEnvironment);
56 };
57
58 }  // namespace atom
59
60 #endif  // ATOM_BROWSER_JAVASCRIPT_ENVIRONMENT_H_