[go: nahoru, domu]

blob: 5f9d0f7dc78fabffbeeba8c5a37963ed2d7212b2 [file] [log] [blame]
abarth@chromium.org97f21ca2013-11-17 17:46:071// 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.
4
5#ifndef GIN_PER_CONTEXT_DATA_H_
6#define GIN_PER_CONTEXT_DATA_H_
7
abarth@chromium.org97f21ca2013-11-17 17:46:078#include "base/basictypes.h"
sky@chromium.orgf2eec2ec2014-02-28 15:26:499#include "base/supports_user_data.h"
jochen@chromium.org48c21632013-12-12 21:32:3410#include "gin/gin_export.h"
abarth@chromium.org97f21ca2013-11-17 17:46:0711#include "v8/include/v8.h"
12
13namespace gin {
14
abarth@chromium.org0d72f002013-11-25 02:19:3415class Runner;
16
abarth@chromium.org60531d52013-11-27 02:10:1517// There is one instance of PerContextData per v8::Context managed by Gin. This
sky@chromium.orgf2eec2ec2014-02-28 15:26:4918// class stores all the Gin-related data that varies per context. Arbitrary data
19// can be associated with this class by way of the SupportsUserData methods.
20// Instances of this class (and any associated user data) are destroyed before
21// the associated v8::Context.
22class GIN_EXPORT PerContextData : public base::SupportsUserData {
abarth@chromium.org97f21ca2013-11-17 17:46:0723 public:
24 explicit PerContextData(v8::Handle<v8::Context> context);
sky@chromium.orgf2eec2ec2014-02-28 15:26:4925 virtual ~PerContextData();
abarth@chromium.org97f21ca2013-11-17 17:46:0726
27 // Can return NULL after the ContextHolder has detached from context.
sky@chromium.orgf2eec2ec2014-02-28 15:26:4928 static PerContextData* From(v8::Handle<v8::Context> context);
abarth@chromium.org97f21ca2013-11-17 17:46:0729
abarth@chromium.org60531d52013-11-27 02:10:1530 // The Runner associated with this context. To execute script in this context,
31 // please use the appropriate API on Runner.
abarth@chromium.org0d72f002013-11-25 02:19:3432 Runner* runner() const { return runner_; }
abarth@chromium.org60531d52013-11-27 02:10:1533 void set_runner(Runner* runner) { runner_ = runner; }
abarth@chromium.org0d72f002013-11-25 02:19:3434
abarth@chromium.org97f21ca2013-11-17 17:46:0735 private:
abarth@chromium.org0d72f002013-11-25 02:19:3436 Runner* runner_;
abarth@chromium.org97f21ca2013-11-17 17:46:0737
38 DISALLOW_COPY_AND_ASSIGN(PerContextData);
39};
40
41} // namespace gin
42
43#endif // GIN_PER_CONTEXT_DATA_H_