| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/script_context_set.h" | 5 #include "extensions/renderer/script_context_set.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/location.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" |
| 8 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
| 9 #include "content/public/renderer/render_frame.h" | 11 #include "content/public/renderer/render_frame.h" |
| 10 #include "extensions/common/extension.h" | 12 #include "extensions/common/extension.h" |
| 11 #include "extensions/renderer/extension_groups.h" | 13 #include "extensions/renderer/extension_groups.h" |
| 12 #include "extensions/renderer/script_context.h" | 14 #include "extensions/renderer/script_context.h" |
| 13 #include "extensions/renderer/script_injection.h" | 15 #include "extensions/renderer/script_injection.h" |
| 14 #include "third_party/WebKit/public/web/WebDocument.h" | 16 #include "third_party/WebKit/public/web/WebDocument.h" |
| 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 16 #include "v8/include/v8.h" | 18 #include "v8/include/v8.h" |
| 17 | 19 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 ScriptContext* context = | 56 ScriptContext* context = |
| 55 new ScriptContext(v8_context, frame, extension, context_type, | 57 new ScriptContext(v8_context, frame, extension, context_type, |
| 56 effective_extension, effective_context_type); | 58 effective_extension, effective_context_type); |
| 57 contexts_.insert(context); // takes ownership | 59 contexts_.insert(context); // takes ownership |
| 58 return context; | 60 return context; |
| 59 } | 61 } |
| 60 | 62 |
| 61 void ScriptContextSet::Remove(ScriptContext* context) { | 63 void ScriptContextSet::Remove(ScriptContext* context) { |
| 62 if (contexts_.erase(context)) { | 64 if (contexts_.erase(context)) { |
| 63 context->Invalidate(); | 65 context->Invalidate(); |
| 64 base::MessageLoop::current()->DeleteSoon(FROM_HERE, context); | 66 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, context); |
| 65 } | 67 } |
| 66 } | 68 } |
| 67 | 69 |
| 68 ScriptContext* ScriptContextSet::GetCurrent() const { | 70 ScriptContext* ScriptContextSet::GetCurrent() const { |
| 69 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 71 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 70 return isolate->InContext() ? GetByV8Context(isolate->GetCurrentContext()) | 72 return isolate->InContext() ? GetByV8Context(isolate->GetCurrentContext()) |
| 71 : nullptr; | 73 : nullptr; |
| 72 } | 74 } |
| 73 | 75 |
| 74 ScriptContext* ScriptContextSet::GetByV8Context( | 76 ScriptContext* ScriptContextSet::GetByV8Context( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 return Feature::WEB_PAGE_CONTEXT; | 216 return Feature::WEB_PAGE_CONTEXT; |
| 215 } | 217 } |
| 216 | 218 |
| 217 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, | 219 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, |
| 218 ScriptContext* context) { | 220 ScriptContext* context) { |
| 219 removed->insert(context); | 221 removed->insert(context); |
| 220 Remove(context); // Note: context deletion is deferred to the message loop. | 222 Remove(context); // Note: context deletion is deferred to the message loop. |
| 221 } | 223 } |
| 222 | 224 |
| 223 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |