Chromium Code Reviews| Index: chrome/renderer/extensions/event_bindings.cc |
| diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc |
| index 416ab2cf5dd4ec0f7932185c2ecabf74f03d5c02..1d7feb9086bd08fabfe5750c0966e32a939c3175 100644 |
| --- a/chrome/renderer/extensions/event_bindings.cc |
| +++ b/chrome/renderer/extensions/event_bindings.cc |
| @@ -22,12 +22,16 @@ using bindings_utils::CallFunctionInContext; |
| using bindings_utils::ContextInfo; |
| using bindings_utils::ContextList; |
| using bindings_utils::GetContexts; |
| +using bindings_utils::GetInfoForCurrentContext; |
| using bindings_utils::GetStringResource; |
| using bindings_utils::ExtensionBase; |
| using bindings_utils::GetPendingRequestMap; |
| using bindings_utils::PendingRequestMap; |
| using WebKit::WebFrame; |
| +static void ContextWeakReferenceCallback(v8::Persistent<v8::Value> context, |
| + void*); |
| + |
| namespace { |
| // Keep a local cache of RenderThread so that we can mock it out for unit tests. |
| @@ -79,11 +83,7 @@ class ExtensionImpl : public ExtensionBase { |
| std::string event_name(*v8::String::AsciiValue(args[0])); |
| bool has_permission = |
| ExtensionProcessBindings::CurrentContextHasPermission(event_name); |
| -#if EXTENSION_TIME_TO_BREAK_API |
| bool allow_api = has_permission; |
|
Matt Perry
2009/09/14 18:07:47
may as well remove this and use has_permission dir
|
| -#else |
| - bool allow_api = true; |
| -#endif |
| // Increment the count even if the caller doesn't have permission, so that |
| // refcounts stay balanced. |
| @@ -92,6 +92,10 @@ class ExtensionImpl : public ExtensionBase { |
| new ViewHostMsg_ExtensionAddListener(event_name)); |
| } |
| + ContextInfo* current_context_info = GetInfoForCurrentContext(); |
| + if (++current_context_info->num_connected_events == 1) |
| + current_context_info->context.ClearWeak(); |
| + |
| if (!has_permission) { |
| return ExtensionProcessBindings::ThrowPermissionDeniedException( |
| event_name); |
| @@ -112,6 +116,13 @@ class ExtensionImpl : public ExtensionBase { |
| EventBindings::GetRenderThread()->Send( |
| new ViewHostMsg_ExtensionRemoveListener(event_name)); |
| } |
| + |
| + ContextInfo* current_context_info = GetInfoForCurrentContext(); |
| + if (current_context_info && |
|
Matt Perry
2009/09/14 18:07:47
why the NULL-check here but not in AttachEvent?
|
| + --current_context_info->num_connected_events == 0) { |
| + current_context_info->context.MakeWeak(NULL, |
| + &ContextWeakReferenceCallback); |
| + } |
| } |
| return v8::Undefined(); |