[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #include "gin/per_context_data.h" | ||||
6 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 8 | #include "gin/public/context_holder.h" |
[email protected] | c07006b | 2013-11-20 03:01:44 | [diff] [blame] | 9 | #include "gin/public/wrapper_info.h" |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 10 | |
11 | namespace gin { | ||||
12 | |||||
13 | ContextSupplement::ContextSupplement() { | ||||
14 | } | ||||
15 | |||||
16 | ContextSupplement::~ContextSupplement() { | ||||
17 | } | ||||
18 | |||||
[email protected] | 0d72f004 | 2013-11-25 02:19:34 | [diff] [blame] | 19 | PerContextData::PerContextData(v8::Handle<v8::Context> context) |
20 | : runner_(NULL) { | ||||
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 21 | context->SetAlignedPointerInEmbedderData( |
22 | kPerContextDataStartIndex + kEmbedderNativeGin, this); | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 23 | } |
24 | |||||
25 | PerContextData::~PerContextData() { | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 26 | DCHECK(supplements_.empty()); |
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 27 | } |
28 | |||||
29 | void PerContextData::Detach(v8::Handle<v8::Context> context) { | ||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 30 | DCHECK(From(context) == this); |
[email protected] | 36e37408 | 2013-12-06 01:51:17 | [diff] [blame] | 31 | context->SetAlignedPointerInEmbedderData( |
32 | kPerContextDataStartIndex + kEmbedderNativeGin, NULL); | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 33 | |
34 | SuplementVector supplements; | ||||
35 | supplements.swap(supplements_); | ||||
36 | |||||
37 | for (SuplementVector::iterator it = supplements.begin(); | ||||
38 | it != supplements.end(); ++it) { | ||||
39 | (*it)->Detach(context); | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 40 | } |
41 | } | ||||
42 | |||||
43 | PerContextData* PerContextData::From(v8::Handle<v8::Context> context) { | ||||
44 | return static_cast<PerContextData*>( | ||||
45 | context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex)); | ||||
46 | } | ||||
47 | |||||
[email protected] | 855ab43 | 2013-11-18 17:09:36 | [diff] [blame] | 48 | void PerContextData::AddSupplement(scoped_ptr<ContextSupplement> supplement) { |
49 | supplements_.push_back(supplement.release()); | ||||
[email protected] | 97f21ca | 2013-11-17 17:46:07 | [diff] [blame] | 50 | } |
51 | |||||
52 | } // namespace gin |