Disable WebViewTest.TestConfirmDialog on Mac
[chromium-blink-merge.git] / gin / per_isolate_data.cc
blobcec082174bf5a598291e86043c205516148b8ff0
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 #include "gin/per_isolate_data.h"
7 #include "base/logging.h"
8 #include "base/single_thread_task_runner.h"
9 #include "base/thread_task_runner_handle.h"
10 #include "gin/public/gin_embedders.h"
12 using v8::ArrayBuffer;
13 using v8::Eternal;
14 using v8::Isolate;
15 using v8::Local;
16 using v8::Object;
17 using v8::FunctionTemplate;
18 using v8::ObjectTemplate;
20 namespace gin {
22 PerIsolateData::PerIsolateData(Isolate* isolate,
23 ArrayBuffer::Allocator* allocator)
24 : isolate_(isolate),
25 allocator_(allocator),
26 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
27 isolate_->SetData(kEmbedderNativeGin, this);
30 PerIsolateData::~PerIsolateData() {
31 isolate_->SetData(kEmbedderNativeGin, NULL);
34 PerIsolateData* PerIsolateData::From(Isolate* isolate) {
35 return static_cast<PerIsolateData*>(isolate->GetData(kEmbedderNativeGin));
38 void PerIsolateData::SetObjectTemplate(WrapperInfo* info,
39 Local<ObjectTemplate> templ) {
40 object_templates_[info] = Eternal<ObjectTemplate>(isolate_, templ);
43 void PerIsolateData::SetFunctionTemplate(WrapperInfo* info,
44 Local<FunctionTemplate> templ) {
45 function_templates_[info] = Eternal<FunctionTemplate>(isolate_, templ);
48 v8::Local<v8::ObjectTemplate> PerIsolateData::GetObjectTemplate(
49 WrapperInfo* info) {
50 ObjectTemplateMap::iterator it = object_templates_.find(info);
51 if (it == object_templates_.end())
52 return v8::Local<v8::ObjectTemplate>();
53 return it->second.Get(isolate_);
56 v8::Local<v8::FunctionTemplate> PerIsolateData::GetFunctionTemplate(
57 WrapperInfo* info) {
58 FunctionTemplateMap::iterator it = function_templates_.find(info);
59 if (it == function_templates_.end())
60 return v8::Local<v8::FunctionTemplate>();
61 return it->second.Get(isolate_);
64 void PerIsolateData::SetIndexedPropertyInterceptor(
65 WrappableBase* base,
66 IndexedPropertyInterceptor* interceptor) {
67 indexed_interceptors_[base] = interceptor;
70 void PerIsolateData::SetNamedPropertyInterceptor(
71 WrappableBase* base,
72 NamedPropertyInterceptor* interceptor) {
73 named_interceptors_[base] = interceptor;
76 void PerIsolateData::ClearIndexedPropertyInterceptor(
77 WrappableBase* base,
78 IndexedPropertyInterceptor* interceptor) {
79 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
80 if (it != indexed_interceptors_.end())
81 indexed_interceptors_.erase(it);
82 else
83 NOTREACHED();
86 void PerIsolateData::ClearNamedPropertyInterceptor(
87 WrappableBase* base,
88 NamedPropertyInterceptor* interceptor) {
89 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
90 if (it != named_interceptors_.end())
91 named_interceptors_.erase(it);
92 else
93 NOTREACHED();
96 IndexedPropertyInterceptor* PerIsolateData::GetIndexedPropertyInterceptor(
97 WrappableBase* base) {
98 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
99 if (it != indexed_interceptors_.end())
100 return it->second;
101 else
102 return NULL;
105 NamedPropertyInterceptor* PerIsolateData::GetNamedPropertyInterceptor(
106 WrappableBase* base) {
107 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
108 if (it != named_interceptors_.end())
109 return it->second;
110 else
111 return NULL;
114 void PerIsolateData::EnableIdleTasks(
115 scoped_ptr<V8IdleTaskRunner> idle_task_runner) {
116 idle_task_runner_ = idle_task_runner.Pass();
119 } // namespace gin