Chromium Code Reviews| Index: extensions/renderer/script_context.cc |
| diff --git a/extensions/renderer/script_context.cc b/extensions/renderer/script_context.cc |
| index a1af29591c3b6f497d9222a6e68e21d8995d9366..beb8f333e4843d25dc7b2637e8c61306ba0088a0 100644 |
| --- a/extensions/renderer/script_context.cc |
| +++ b/extensions/renderer/script_context.cc |
| @@ -30,27 +30,68 @@ using content::V8ValueConverter; |
| namespace extensions { |
| +namespace { |
| + |
| +std::string GetContextTypeDescriptionString(Feature::Context context_type) { |
| + switch (context_type) { |
| + case Feature::UNSPECIFIED_CONTEXT: |
| + return "UNSPECIFIED"; |
| + case Feature::BLESSED_EXTENSION_CONTEXT: |
| + return "BLESSED_EXTENSION"; |
| + case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| + return "UNBLESSED_EXTENSION"; |
| + case Feature::CONTENT_SCRIPT_CONTEXT: |
| + return "CONTENT_SCRIPT"; |
| + case Feature::WEB_PAGE_CONTEXT: |
| + return "WEB_PAGE"; |
| + case Feature::BLESSED_WEB_PAGE_CONTEXT: |
| + return "BLESSED_WEB_PAGE"; |
| + case Feature::WEBUI_CONTEXT: |
| + return "WEBUI"; |
| + } |
| + NOTREACHED(); |
| + return std::string(); |
| +} |
| + |
| +const std::string& GetIDForExtension(const Extension* extension) { |
| + if (extension) |
| + return extension->id(); |
| + return base::EmptyString(); |
|
Devlin
2014/09/04 19:15:11
base::EmptyString is expensive. It'd probably be
Marijn Kruisselbrink
2014/09/04 23:41:11
Good point, done.
|
| +} |
| + |
| +} // namespace |
| + |
| ScriptContext::ScriptContext(const v8::Handle<v8::Context>& v8_context, |
| blink::WebFrame* web_frame, |
| const Extension* extension, |
| - Feature::Context context_type) |
| + Feature::Context context_type, |
| + const Extension* effective_extension, |
| + Feature::Context effective_context_type) |
| : v8_context_(v8_context), |
| web_frame_(web_frame), |
| extension_(extension), |
| context_type_(context_type), |
| + effective_extension_(effective_extension), |
| + effective_context_type_(effective_context_type), |
| safe_builtins_(this), |
| isolate_(v8_context->GetIsolate()) { |
| VLOG(1) << "Created context:\n" |
| << " extension id: " << GetExtensionID() << "\n" |
| << " frame: " << web_frame_ << "\n" |
| << " URL: " << GetURL() << "\n" |
| - << " context type: " << GetContextTypeDescription(); |
| + << " context type: " << GetContextTypeDescription() << "\n" |
| + << " effective extension id: " |
| + << GetIDForExtension(effective_extension_.get()) << "\n" |
| + << " effective context type: " |
| + << GetEffectiveContextTypeDescription(); |
| gin::PerContextData::From(v8_context)->set_runner(this); |
| } |
| ScriptContext::~ScriptContext() { |
| VLOG(1) << "Destroyed context for extension\n" |
| - << " extension id: " << GetExtensionID(); |
| + << " extension id: " << GetExtensionID() << "\n" |
| + << " effective extension id: " |
| + << GetIDForExtension(effective_extension_.get()); |
| Invalidate(); |
| } |
| @@ -133,24 +174,11 @@ void ScriptContext::DispatchOnUnloadEvent() { |
| } |
| std::string ScriptContext::GetContextTypeDescription() { |
| - switch (context_type_) { |
| - case Feature::UNSPECIFIED_CONTEXT: |
| - return "UNSPECIFIED"; |
| - case Feature::BLESSED_EXTENSION_CONTEXT: |
| - return "BLESSED_EXTENSION"; |
| - case Feature::UNBLESSED_EXTENSION_CONTEXT: |
| - return "UNBLESSED_EXTENSION"; |
| - case Feature::CONTENT_SCRIPT_CONTEXT: |
| - return "CONTENT_SCRIPT"; |
| - case Feature::WEB_PAGE_CONTEXT: |
| - return "WEB_PAGE"; |
| - case Feature::BLESSED_WEB_PAGE_CONTEXT: |
| - return "BLESSED_WEB_PAGE"; |
| - case Feature::WEBUI_CONTEXT: |
| - return "WEBUI"; |
| - } |
| - NOTREACHED(); |
| - return std::string(); |
| + return GetContextTypeDescriptionString(context_type_); |
| +} |
| + |
| +std::string ScriptContext::GetEffectiveContextTypeDescription() { |
| + return GetContextTypeDescriptionString(effective_context_type_); |
| } |
| GURL ScriptContext::GetURL() const { |