Fix import error in mac_platform_backend.py
[chromium-blink-merge.git] / gin / per_context_data.h
blob3ad68d2d37cfaf712f6ec44d507a8a45974da16d
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_PER_CONTEXT_DATA_H_
6 #define GIN_PER_CONTEXT_DATA_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/scoped_vector.h"
11 #include "gin/gin_export.h"
12 #include "v8/include/v8.h"
14 namespace gin {
16 class Runner;
18 // Embedders can store additional per-context data by subclassing
19 // ContextSupplement.
20 class GIN_EXPORT ContextSupplement {
21 public:
22 ContextSupplement();
23 virtual ~ContextSupplement();
25 // Detach will be called before ContextHolder disposes the v8::Context.
26 // Embedders should not interact with |context| after Detach has been called.
27 virtual void Detach(v8::Handle<v8::Context> context) = 0;
29 private:
30 DISALLOW_COPY_AND_ASSIGN(ContextSupplement);
33 // There is one instance of PerContextData per v8::Context managed by Gin. This
34 // class stores all the Gin-related data that varies per context.
35 class GIN_EXPORT PerContextData {
36 public:
37 explicit PerContextData(v8::Handle<v8::Context> context);
38 ~PerContextData();
40 // Can return NULL after the ContextHolder has detached from context.
41 static PerContextData* From(v8::Handle<v8::Context>);
42 void Detach(v8::Handle<v8::Context> context);
44 // The Runner associated with this context. To execute script in this context,
45 // please use the appropriate API on Runner.
46 Runner* runner() const { return runner_; }
47 void set_runner(Runner* runner) { runner_ = runner; }
49 void AddSupplement(scoped_ptr<ContextSupplement> supplement);
51 private:
52 typedef ScopedVector<ContextSupplement> SuplementVector;
54 Runner* runner_;
55 SuplementVector supplements_;
57 DISALLOW_COPY_AND_ASSIGN(PerContextData);
60 } // namespace gin
62 #endif // GIN_PER_CONTEXT_DATA_H_