Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2918)

Unified Diff: chrome/renderer/extensions/event_bindings.cc

Issue 200116: Fix bug where content scripts can get GC'd if they don't attach (Closed)
Patch Set: remove extra braces Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/extensions/bindings_utils.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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();
« no previous file with comments | « chrome/renderer/extensions/bindings_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698