DCHECK() that the source WebContents being passed to Browser::OpenURLInTab() is part...
[chromium-blink-merge.git] / gin / per_isolate_data.h
blobed9354547494c01964f42e23447fbac0147b9d67
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_ISOLATE_DATA_H_
6 #define GIN_PER_ISOLATE_DATA_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "gin/gin_export.h"
12 #include "gin/public/wrapper_info.h"
13 #include "v8/include/v8.h"
15 namespace gin {
17 // There is one instance of PerIsolateData per v8::Isolate managed by Gin. This
18 // class stores all the Gin-related data that varies per isolate.
19 class GIN_EXPORT PerIsolateData {
20 public:
21 explicit PerIsolateData(v8::Isolate* isolate);
22 ~PerIsolateData();
24 static PerIsolateData* From(v8::Isolate* isolate);
26 // Each isolate is associated with a collection of v8::ObjectTemplates and
27 // v8::FunctionTemplates. Typically these template objects are created
28 // lazily.
29 void SetObjectTemplate(WrapperInfo* info,
30 v8::Local<v8::ObjectTemplate> object_template);
31 void SetFunctionTemplate(WrapperInfo* info,
32 v8::Local<v8::FunctionTemplate> function_template);
34 // These are low-level functions for retrieving object or function templates
35 // stored in this object. Because these templates are often created lazily,
36 // most clients should call higher-level functions that know how to populate
37 // these templates if they haven't already been created.
38 v8::Local<v8::ObjectTemplate> GetObjectTemplate(WrapperInfo* info);
39 v8::Local<v8::FunctionTemplate> GetFunctionTemplate(WrapperInfo* info);
41 v8::Isolate* isolate() { return isolate_; }
43 private:
44 typedef std::map<
45 WrapperInfo*, v8::Eternal<v8::ObjectTemplate> > ObjectTemplateMap;
46 typedef std::map<
47 WrapperInfo*, v8::Eternal<v8::FunctionTemplate> > FunctionTemplateMap;
49 // PerIsolateData doesn't actually own |isolate_|. Instead, the isolate is
50 // owned by the IsolateHolder, which also owns the PerIsolateData.
51 v8::Isolate* isolate_;
52 ObjectTemplateMap object_templates_;
53 FunctionTemplateMap function_templates_;
55 DISALLOW_COPY_AND_ASSIGN(PerIsolateData);
58 } // namespace gin
60 #endif // GIN_PER_ISOLATE_DATA_H_