summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/extensions/event_bindings.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 19:08:41 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-14 19:08:41 +0000
commit9cec718466e9dec2fc36d7cc3951aee737df5f64 (patch)
tree65b4f49488a9fcac2e1b7b568e26917e0857372f /chrome/renderer/extensions/event_bindings.cc
parent886f4f9d55ddaf72f7e0b870f5510538dae38281 (diff)
downloadchromium_src-9cec718466e9dec2fc36d7cc3951aee737df5f64.zip
chromium_src-9cec718466e9dec2fc36d7cc3951aee737df5f64.tar.gz
chromium_src-9cec718466e9dec2fc36d7cc3951aee737df5f64.tar.bz2
Fix bug where content scripts can get GC'd if they don't
attach to any DOM events. BUG=17410 TEST=none Review URL: http://codereview.chromium.org/200116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26136 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/extensions/event_bindings.cc')
-rw-r--r--chrome/renderer/extensions/event_bindings.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc
index 416ab2c..c30c364 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,19 +83,18 @@ 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;
-#else
- bool allow_api = true;
-#endif
// Increment the count even if the caller doesn't have permission, so that
// refcounts stay balanced.
- if (EventIncrementListenerCount(event_name) == 1 && allow_api) {
+ if (EventIncrementListenerCount(event_name) == 1 && has_permission) {
EventBindings::GetRenderThread()->Send(
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 +115,13 @@ class ExtensionImpl : public ExtensionBase {
EventBindings::GetRenderThread()->Send(
new ViewHostMsg_ExtensionRemoveListener(event_name));
}
+
+ ContextInfo* current_context_info = GetInfoForCurrentContext();
+ if (current_context_info &&
+ --current_context_info->num_connected_events == 0) {
+ current_context_info->context.MakeWeak(NULL,
+ &ContextWeakReferenceCallback);
+ }
}
return v8::Undefined();