OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/extensions/chrome_v8_context_set.h" | 5 #include "chrome/renderer/extensions/chrome_v8_context_set.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/tracked_objects.h" | 9 #include "base/tracked_objects.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 context->Invalidate(); | 53 context->Invalidate(); |
54 base::MessageLoop::current()->DeleteSoon(FROM_HERE, context); | 54 base::MessageLoop::current()->DeleteSoon(FROM_HERE, context); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll() const { | 58 ChromeV8ContextSet::ContextSet ChromeV8ContextSet::GetAll() const { |
59 return contexts_; | 59 return contexts_; |
60 } | 60 } |
61 | 61 |
62 ChromeV8Context* ChromeV8ContextSet::GetCurrent() const { | 62 ChromeV8Context* ChromeV8ContextSet::GetCurrent() const { |
63 if (!v8::Context::InContext()) | 63 v8::Local<v8::Context> current = v8::Context::GetCurrent(); |
64 return NULL; | 64 return current.IsEmpty() ? NULL : GetByV8Context(current); |
65 else | 65 } |
66 return GetByV8Context(v8::Context::GetCurrent()); | 66 |
| 67 ChromeV8Context* ChromeV8ContextSet::GetCalling() const { |
| 68 v8::Local<v8::Context> calling = v8::Context::GetCalling(); |
| 69 return calling.IsEmpty() ? NULL : GetByV8Context(calling); |
67 } | 70 } |
68 | 71 |
69 ChromeV8Context* ChromeV8ContextSet::GetByV8Context( | 72 ChromeV8Context* ChromeV8ContextSet::GetByV8Context( |
70 v8::Handle<v8::Context> v8_context) const { | 73 v8::Handle<v8::Context> v8_context) const { |
71 for (ContextSet::const_iterator iter = contexts_.begin(); | 74 for (ContextSet::const_iterator iter = contexts_.begin(); |
72 iter != contexts_.end(); ++iter) { | 75 iter != contexts_.end(); ++iter) { |
73 if ((*iter)->v8_context() == v8_context) | 76 if ((*iter)->v8_context() == v8_context) |
74 return *iter; | 77 return *iter; |
75 } | 78 } |
76 | 79 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 (*it)->DispatchOnUnloadEvent(); | 127 (*it)->DispatchOnUnloadEvent(); |
125 removed.insert(*it); | 128 removed.insert(*it); |
126 Remove(*it); | 129 Remove(*it); |
127 } | 130 } |
128 } | 131 } |
129 | 132 |
130 return removed; | 133 return removed; |
131 } | 134 } |
132 | 135 |
133 } // namespace extensions | 136 } // namespace extensions |
OLD | NEW |