Vertically center excessively tall Views tab titles.
[chromium-blink-merge.git] / gin / shell_runner.h
blob645bc8e6df17d70290d3f64f299110e0646551a3
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_SHELL_RUNNER_H_
6 #define GIN_SHELL_RUNNER_H_
8 #include "gin/runner.h"
10 namespace gin {
12 class ContextHolder;
13 class ShellRunner;
14 class TryCatch;
16 // Subclass ShellRunnerDelegate to customize the behavior of ShellRunner.
17 // Typical embedders will want to subclass one of the specialized
18 // ShellRunnerDelegates, such as ModuleRunnerDelegate.
19 class GIN_EXPORT ShellRunnerDelegate {
20 public:
21 ShellRunnerDelegate();
22 virtual ~ShellRunnerDelegate();
24 // Returns the template for the global object.
25 virtual v8::Handle<v8::ObjectTemplate> GetGlobalTemplate(
26 ShellRunner* runner,
27 v8::Isolate* isolate);
28 virtual void DidCreateContext(ShellRunner* runner);
29 virtual void WillRunScript(ShellRunner* runner);
30 virtual void DidRunScript(ShellRunner* runner);
31 virtual void UnhandledException(ShellRunner* runner, TryCatch& try_catch);
34 // ShellRunner executes the script/functions directly in a v8::Context.
35 // ShellRunner owns a ContextHolder and v8::Context, both of which are destroyed
36 // when the ShellRunner is deleted.
37 class GIN_EXPORT ShellRunner : public Runner {
38 public:
39 ShellRunner(ShellRunnerDelegate* delegate, v8::Isolate* isolate);
40 virtual ~ShellRunner();
42 // Before running script in this context, you'll need to enter the runner's
43 // context by creating an instance of Runner::Scope on the stack.
45 // Runner overrides:
46 virtual void Run(const std::string& source,
47 const std::string& resource_name) OVERRIDE;
48 virtual v8::Handle<v8::Value> Call(v8::Handle<v8::Function> function,
49 v8::Handle<v8::Value> receiver,
50 int argc,
51 v8::Handle<v8::Value> argv[]) OVERRIDE;
52 virtual ContextHolder* GetContextHolder() OVERRIDE;
54 private:
55 friend class Scope;
57 void Run(v8::Handle<v8::Script> script);
59 ShellRunnerDelegate* delegate_;
61 scoped_ptr<ContextHolder> context_holder_;
63 DISALLOW_COPY_AND_ASSIGN(ShellRunner);
66 } // namespace gin
68 #endif // GIN_SHELL_RUNNER_H_