[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / gin / shell_runner.h
1 // Copyright 2014 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GIN_SHELL_RUNNER_H_
6 #define GIN_SHELL_RUNNER_H_
7
8 #include <memory>
9
10 #include "base/memory/raw_ptr.h"
11 #include "gin/runner.h"
12
13 namespace gin {
14
15 class ContextHolder;
16 class ShellRunner;
17 class TryCatch;
18
19 // Subclass ShellRunnerDelegate to customize the behavior of ShellRunner.
20 // Typical embedders will want to subclass one of the specialized
21 // ShellRunnerDelegates, such as ModuleRunnerDelegate.
22 class GIN_EXPORT ShellRunnerDelegate {
23  public:
24   ShellRunnerDelegate();
25   virtual ~ShellRunnerDelegate();
26
27   // Returns the template for the global object.
28   virtual v8::Local<v8::ObjectTemplate> GetGlobalTemplate(
29       ShellRunner* runner,
30       v8::Isolate* isolate);
31   virtual void DidCreateContext(ShellRunner* runner);
32   virtual void WillRunScript(ShellRunner* runner);
33   virtual void DidRunScript(ShellRunner* runner);
34   virtual void UnhandledException(ShellRunner* runner, TryCatch& try_catch);
35 };
36
37 // ShellRunner executes the script/functions directly in a v8::Context.
38 // ShellRunner owns a ContextHolder and v8::Context, both of which are destroyed
39 // when the ShellRunner is deleted.
40 class GIN_EXPORT ShellRunner : public Runner {
41  public:
42   ShellRunner(ShellRunnerDelegate* delegate, v8::Isolate* isolate);
43   ShellRunner(const ShellRunner&) = delete;
44   ShellRunner& operator=(const ShellRunner&) = delete;
45   ~ShellRunner() override;
46
47   // Before running script in this context, you'll need to enter the runner's
48   // context by creating an instance of Runner::Scope on the stack.
49
50   // Runner overrides:
51   v8::MaybeLocal<v8::Value> Run(const std::string& source,
52                                 const std::string& resource_name) override;
53   ContextHolder* GetContextHolder() override;
54
55  private:
56   friend class Scope;
57
58   v8::MaybeLocal<v8::Value> Run(v8::Local<v8::Script> script);
59
60   raw_ptr<ShellRunnerDelegate> delegate_;
61
62   std::unique_ptr<ContextHolder> context_holder_;
63 };
64
65 }  // namespace gin
66
67 #endif  // GIN_SHELL_RUNNER_H_