Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / gin / per_isolate_data.cc
blob8f72d7661452c59bded0228c0dd02b0a3d6c3a7e
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 "base/logging.h"
6 #include "base/single_thread_task_runner.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "gin/per_isolate_data.h"
9 #include "gin/public/gin_embedders.h"
11 using v8::ArrayBuffer;
12 using v8::Eternal;
13 using v8::Isolate;
14 using v8::Local;
15 using v8::Object;
16 using v8::FunctionTemplate;
17 using v8::ObjectTemplate;
19 namespace gin {
21 PerIsolateData::PerIsolateData(Isolate* isolate,
22 ArrayBuffer::Allocator* allocator)
23 : isolate_(isolate),
24 allocator_(allocator),
25 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
26 isolate_->SetData(kEmbedderNativeGin, this);
29 PerIsolateData::~PerIsolateData() {
30 isolate_->SetData(kEmbedderNativeGin, NULL);
33 PerIsolateData* PerIsolateData::From(Isolate* isolate) {
34 return static_cast<PerIsolateData*>(isolate->GetData(kEmbedderNativeGin));
37 void PerIsolateData::SetObjectTemplate(WrapperInfo* info,
38 Local<ObjectTemplate> templ) {
39 object_templates_[info] = Eternal<ObjectTemplate>(isolate_, templ);
42 void PerIsolateData::SetFunctionTemplate(WrapperInfo* info,
43 Local<FunctionTemplate> templ) {
44 function_templates_[info] = Eternal<FunctionTemplate>(isolate_, templ);
47 v8::Local<v8::ObjectTemplate> PerIsolateData::GetObjectTemplate(
48 WrapperInfo* info) {
49 ObjectTemplateMap::iterator it = object_templates_.find(info);
50 if (it == object_templates_.end())
51 return v8::Local<v8::ObjectTemplate>();
52 return it->second.Get(isolate_);
55 v8::Local<v8::FunctionTemplate> PerIsolateData::GetFunctionTemplate(
56 WrapperInfo* info) {
57 FunctionTemplateMap::iterator it = function_templates_.find(info);
58 if (it == function_templates_.end())
59 return v8::Local<v8::FunctionTemplate>();
60 return it->second.Get(isolate_);
63 void PerIsolateData::SetIndexedPropertyInterceptor(
64 WrappableBase* base,
65 IndexedPropertyInterceptor* interceptor) {
66 indexed_interceptors_[base] = interceptor;
69 void PerIsolateData::SetNamedPropertyInterceptor(
70 WrappableBase* base,
71 NamedPropertyInterceptor* interceptor) {
72 named_interceptors_[base] = interceptor;
75 void PerIsolateData::ClearIndexedPropertyInterceptor(
76 WrappableBase* base,
77 IndexedPropertyInterceptor* interceptor) {
78 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
79 if (it != indexed_interceptors_.end())
80 indexed_interceptors_.erase(it);
81 else
82 NOTREACHED();
85 void PerIsolateData::ClearNamedPropertyInterceptor(
86 WrappableBase* base,
87 NamedPropertyInterceptor* interceptor) {
88 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
89 if (it != named_interceptors_.end())
90 named_interceptors_.erase(it);
91 else
92 NOTREACHED();
95 IndexedPropertyInterceptor* PerIsolateData::GetIndexedPropertyInterceptor(
96 WrappableBase* base) {
97 IndexedPropertyInterceptorMap::iterator it = indexed_interceptors_.find(base);
98 if (it != indexed_interceptors_.end())
99 return it->second;
100 else
101 return NULL;
104 NamedPropertyInterceptor* PerIsolateData::GetNamedPropertyInterceptor(
105 WrappableBase* base) {
106 NamedPropertyInterceptorMap::iterator it = named_interceptors_.find(base);
107 if (it != named_interceptors_.end())
108 return it->second;
109 else
110 return NULL;
113 } // namespace gin