Propagate theme color updates to the WebContentsDelegates.
[chromium-blink-merge.git] / gin / runner.h
blob31995698ffddca20060a43686c321422f6b6fe8b
1 // Copyright 2013 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_RUNNER_H_
6 #define GIN_RUNNER_H_
8 #include <string>
10 #include "base/memory/weak_ptr.h"
11 #include "gin/gin_export.h"
12 #include "gin/public/context_holder.h"
13 #include "v8/include/v8.h"
15 namespace gin {
17 // Runner is responsible for running code in a v8::Context.
18 class GIN_EXPORT Runner {
19 public:
20 Runner();
21 virtual ~Runner();
23 // Before running script in this context, you'll need to enter the runner's
24 // context by creating an instance of Runner::Scope on the stack.
25 virtual void Run(const std::string& source,
26 const std::string& resource_name) = 0;
27 virtual v8::Local<v8::Value> Call(v8::Local<v8::Function> function,
28 v8::Local<v8::Value> receiver,
29 int argc,
30 v8::Local<v8::Value> argv[]) = 0;
31 virtual ContextHolder* GetContextHolder() = 0;
33 v8::Local<v8::Object> global() {
34 return GetContextHolder()->context()->Global();
37 // Useful for running script in this context asynchronously. Rather than
38 // holding a raw pointer to the runner, consider holding a WeakPtr.
39 base::WeakPtr<Runner> GetWeakPtr() {
40 return weak_factory_.GetWeakPtr();
43 class GIN_EXPORT Scope {
44 public:
45 explicit Scope(Runner* runner);
46 ~Scope();
48 private:
49 v8::Isolate::Scope isolate_scope_;
50 v8::HandleScope handle_scope_;
51 v8::Context::Scope scope_;
53 DISALLOW_COPY_AND_ASSIGN(Scope);
56 private:
57 friend class Scope;
59 base::WeakPtrFactory<Runner> weak_factory_;
61 DISALLOW_COPY_AND_ASSIGN(Runner);
64 } // namespace gin
66 #endif // GIN_RUNNER_H_