| 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/message_loop/message_loop.h" |
| 8 #include "content/public/common/url_constants.h" | 8 #include "content/public/common/url_constants.h" |
| 9 #include "content/public/renderer/render_view.h" | 9 #include "content/public/renderer/render_view.h" |
| 10 #include "extensions/common/extension.h" | 10 #include "extensions/common/extension.h" |
| 11 #include "extensions/renderer/extension_groups.h" | 11 #include "extensions/renderer/extension_groups.h" |
| 12 #include "extensions/renderer/script_context.h" | 12 #include "extensions/renderer/script_context.h" |
| 13 #include "extensions/renderer/script_injection.h" | 13 #include "extensions/renderer/script_injection.h" |
| 14 #include "third_party/WebKit/public/web/WebDocument.h" | 14 #include "third_party/WebKit/public/web/WebDocument.h" |
| 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 16 #include "v8/include/v8.h" | 16 #include "v8/include/v8.h" |
| 17 | 17 |
| 18 namespace extensions { | 18 namespace extensions { |
| 19 | 19 |
| 20 ScriptContextSet::ScriptContextSet(ExtensionSet* extensions, | 20 ScriptContextSet::ScriptContextSet(ExtensionSet* extensions, |
| 21 ExtensionIdSet* active_extension_ids) | 21 ExtensionIdSet* active_extension_ids) |
| 22 : extensions_(extensions), active_extension_ids_(active_extension_ids) { | 22 : extensions_(extensions), active_extension_ids_(active_extension_ids) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 ScriptContextSet::~ScriptContextSet() { | 25 ScriptContextSet::~ScriptContextSet() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 ScriptContext* ScriptContextSet::Register( | 28 ScriptContext* ScriptContextSet::Register( |
| 29 blink::WebLocalFrame* frame, | 29 blink::WebLocalFrame* frame, |
| 30 const v8::Handle<v8::Context>& v8_context, | 30 const v8::Local<v8::Context>& v8_context, |
| 31 int extension_group, | 31 int extension_group, |
| 32 int world_id) { | 32 int world_id) { |
| 33 const Extension* extension = | 33 const Extension* extension = |
| 34 GetExtensionFromFrameAndWorld(frame, world_id, false); | 34 GetExtensionFromFrameAndWorld(frame, world_id, false); |
| 35 const Extension* effective_extension = | 35 const Extension* effective_extension = |
| 36 GetExtensionFromFrameAndWorld(frame, world_id, true); | 36 GetExtensionFromFrameAndWorld(frame, world_id, true); |
| 37 | 37 |
| 38 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); | 38 GURL frame_url = ScriptContext::GetDataSourceURLForFrame(frame); |
| 39 Feature::Context context_type = | 39 Feature::Context context_type = |
| 40 ClassifyJavaScriptContext(extension, extension_group, frame_url, | 40 ClassifyJavaScriptContext(extension, extension_group, frame_url, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 64 : nullptr; | 64 : nullptr; |
| 65 } | 65 } |
| 66 | 66 |
| 67 ScriptContext* ScriptContextSet::GetCalling() const { | 67 ScriptContext* ScriptContextSet::GetCalling() const { |
| 68 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 68 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 69 v8::Local<v8::Context> calling = isolate->GetCallingContext(); | 69 v8::Local<v8::Context> calling = isolate->GetCallingContext(); |
| 70 return calling.IsEmpty() ? nullptr : GetByV8Context(calling); | 70 return calling.IsEmpty() ? nullptr : GetByV8Context(calling); |
| 71 } | 71 } |
| 72 | 72 |
| 73 ScriptContext* ScriptContextSet::GetByV8Context( | 73 ScriptContext* ScriptContextSet::GetByV8Context( |
| 74 const v8::Handle<v8::Context>& v8_context) const { | 74 const v8::Local<v8::Context>& v8_context) const { |
| 75 for (ScriptContext* script_context : contexts_) { | 75 for (ScriptContext* script_context : contexts_) { |
| 76 if (script_context->v8_context() == v8_context) | 76 if (script_context->v8_context() == v8_context) |
| 77 return script_context; | 77 return script_context; |
| 78 } | 78 } |
| 79 return nullptr; | 79 return nullptr; |
| 80 } | 80 } |
| 81 | 81 |
| 82 void ScriptContextSet::ForEach( | 82 void ScriptContextSet::ForEach( |
| 83 const std::string& extension_id, | 83 const std::string& extension_id, |
| 84 content::RenderView* render_view, | 84 content::RenderView* render_view, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 | 203 |
| 204 void ScriptContextSet::DispatchOnUnloadEventAndRemove( | 204 void ScriptContextSet::DispatchOnUnloadEventAndRemove( |
| 205 std::set<ScriptContext*>* out, | 205 std::set<ScriptContext*>* out, |
| 206 ScriptContext* context) { | 206 ScriptContext* context) { |
| 207 context->DispatchOnUnloadEvent(); | 207 context->DispatchOnUnloadEvent(); |
| 208 Remove(context); // deleted asynchronously | 208 Remove(context); // deleted asynchronously |
| 209 out->insert(context); | 209 out->insert(context); |
| 210 } | 210 } |
| 211 | 211 |
| 212 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |