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/location.h" | 7 #include "base/location.h" |
8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
9 #include "base/threading/thread_task_runner_handle.h" | 9 #include "base/threading/thread_task_runner_handle.h" |
10 #include "content/public/common/url_constants.h" | 10 #include "content/public/common/url_constants.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 g_context_set = this; | 30 g_context_set = this; |
31 } | 31 } |
32 | 32 |
33 ScriptContextSet::~ScriptContextSet() { | 33 ScriptContextSet::~ScriptContextSet() { |
34 g_context_set = nullptr; | 34 g_context_set = nullptr; |
35 } | 35 } |
36 | 36 |
37 ScriptContext* ScriptContextSet::Register( | 37 ScriptContext* ScriptContextSet::Register( |
38 blink::WebLocalFrame* frame, | 38 blink::WebLocalFrame* frame, |
39 const v8::Local<v8::Context>& v8_context, | 39 const v8::Local<v8::Context>& v8_context, |
| 40 Feature::SessionType session_type, |
40 int extension_group, | 41 int extension_group, |
41 int world_id) { | 42 int world_id) { |
42 const Extension* extension = | 43 const Extension* extension = |
43 GetExtensionFromFrameAndWorld(frame, world_id, false); | 44 GetExtensionFromFrameAndWorld(frame, world_id, false); |
44 const Extension* effective_extension = | 45 const Extension* effective_extension = |
45 GetExtensionFromFrameAndWorld(frame, world_id, true); | 46 GetExtensionFromFrameAndWorld(frame, world_id, true); |
46 | 47 |
47 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); | 48 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); |
48 Feature::Context context_type = | 49 Feature::Context context_type = |
49 ClassifyJavaScriptContext(extension, extension_group, frame_url, | 50 ClassifyJavaScriptContext(extension, extension_group, frame_url, |
50 frame->document().getSecurityOrigin()); | 51 frame->document().getSecurityOrigin()); |
51 Feature::Context effective_context_type = ClassifyJavaScriptContext( | 52 Feature::Context effective_context_type = ClassifyJavaScriptContext( |
52 effective_extension, extension_group, | 53 effective_extension, extension_group, |
53 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), | 54 ScriptContext::GetEffectiveDocumentURL(frame, frame_url, true), |
54 frame->document().getSecurityOrigin()); | 55 frame->document().getSecurityOrigin()); |
55 | 56 |
56 ScriptContext* context = | 57 ScriptContext* context = new ScriptContext( |
57 new ScriptContext(v8_context, frame, extension, context_type, | 58 v8_context, frame, extension, context_type, session_type, |
58 effective_extension, effective_context_type); | 59 effective_extension, effective_context_type); |
59 contexts_.insert(context); // takes ownership | 60 contexts_.insert(context); // takes ownership |
60 return context; | 61 return context; |
61 } | 62 } |
62 | 63 |
63 void ScriptContextSet::Remove(ScriptContext* context) { | 64 void ScriptContextSet::Remove(ScriptContext* context) { |
64 if (contexts_.erase(context)) { | 65 if (contexts_.erase(context)) { |
65 context->Invalidate(); | 66 context->Invalidate(); |
66 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, context); | 67 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, context); |
67 } | 68 } |
68 } | 69 } |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 return Feature::WEB_PAGE_CONTEXT; | 223 return Feature::WEB_PAGE_CONTEXT; |
223 } | 224 } |
224 | 225 |
225 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, | 226 void ScriptContextSet::RecordAndRemove(std::set<ScriptContext*>* removed, |
226 ScriptContext* context) { | 227 ScriptContext* context) { |
227 removed->insert(context); | 228 removed->insert(context); |
228 Remove(context); // Note: context deletion is deferred to the message loop. | 229 Remove(context); // Note: context deletion is deferred to the message loop. |
229 } | 230 } |
230 | 231 |
231 } // namespace extensions | 232 } // namespace extensions |
OLD | NEW |