blob: 5fedf52a522fb52499b19ed08118cc86d951f393 [file] [log] [blame]
[email protected]97f21ca2013-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#include "gin/per_context_data.h"
6
[email protected]855ab432013-11-18 17:09:367#include "base/logging.h"
[email protected]36e374082013-12-06 01:51:178#include "gin/public/context_holder.h"
[email protected]c07006b2013-11-20 03:01:449#include "gin/public/wrapper_info.h"
[email protected]97f21ca2013-11-17 17:46:0710
11namespace gin {
12
13ContextSupplement::ContextSupplement() {
14}
15
16ContextSupplement::~ContextSupplement() {
17}
18
[email protected]0d72f0042013-11-25 02:19:3419PerContextData::PerContextData(v8::Handle<v8::Context> context)
20 : runner_(NULL) {
[email protected]36e374082013-12-06 01:51:1721 context->SetAlignedPointerInEmbedderData(
22 kPerContextDataStartIndex + kEmbedderNativeGin, this);
[email protected]97f21ca2013-11-17 17:46:0723}
24
25PerContextData::~PerContextData() {
[email protected]855ab432013-11-18 17:09:3626 DCHECK(supplements_.empty());
[email protected]97f21ca2013-11-17 17:46:0727}
28
29void PerContextData::Detach(v8::Handle<v8::Context> context) {
[email protected]855ab432013-11-18 17:09:3630 DCHECK(From(context) == this);
[email protected]36e374082013-12-06 01:51:1731 context->SetAlignedPointerInEmbedderData(
32 kPerContextDataStartIndex + kEmbedderNativeGin, NULL);
[email protected]97f21ca2013-11-17 17:46:0733
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]97f21ca2013-11-17 17:46:0740 }
41}
42
[email protected]1771610d2014-02-27 06:08:2443// static
[email protected]97f21ca2013-11-17 17:46:0744PerContextData* PerContextData::From(v8::Handle<v8::Context> context) {
45 return static_cast<PerContextData*>(
46 context->GetAlignedPointerFromEmbedderData(kEncodedValueIndex));
47}
48
[email protected]855ab432013-11-18 17:09:3649void PerContextData::AddSupplement(scoped_ptr<ContextSupplement> supplement) {
50 supplements_.push_back(supplement.release());
[email protected]97f21ca2013-11-17 17:46:0751}
52
53} // namespace gin