diff options
-rw-r--r-- | chrome/renderer/extensions/bindings_utils.h | 12 | ||||
-rw-r--r-- | chrome/renderer/extensions/event_bindings.cc | 28 |
2 files changed, 19 insertions, 21 deletions
diff --git a/chrome/renderer/extensions/bindings_utils.h b/chrome/renderer/extensions/bindings_utils.h index 558bd64..65e8db8 100644 --- a/chrome/renderer/extensions/bindings_utils.h +++ b/chrome/renderer/extensions/bindings_utils.h @@ -16,6 +16,10 @@ class RenderView; +namespace WebKit { +class WebFrame; +} + namespace bindings_utils { // This is a base class for chrome extension bindings. Common features that @@ -66,8 +70,8 @@ struct ContextInfo { std::string extension_id; // empty if the context is not an extension // If this context is a content script, parent will be the frame that it - // was injected in. This is empty if the context is not a content script. - v8::Persistent<v8::Context> parent_context; + // was injected in. This is NULL if the context is not a content script. + WebKit::WebFrame* parent_frame; // The RenderView that this context belongs to. This is not guaranteed to be // a valid pointer, and is used for comparisons only. Do not dereference. @@ -79,10 +83,10 @@ struct ContextInfo { ContextInfo(v8::Persistent<v8::Context> context, const std::string& extension_id, - v8::Persistent<v8::Context> parent_context, + WebKit::WebFrame* parent_frame, RenderView* render_view) : context(context), extension_id(extension_id), - parent_context(parent_context), render_view(render_view), + parent_frame(parent_frame), render_view(render_view), num_connected_events(0) {} }; typedef std::list< linked_ptr<ContextInfo> > ContextList; diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc index ba7e898..46072bf 100644 --- a/chrome/renderer/extensions/event_bindings.cc +++ b/chrome/renderer/extensions/event_bindings.cc @@ -180,11 +180,6 @@ static void UnregisterContext(ContextList::iterator context_iter, bool in_gc) { } } - if (!(*context_iter)->parent_context.IsEmpty()) { - (*context_iter)->parent_context.Dispose(); - (*context_iter)->parent_context.Clear(); - } - // Remove it from our registered contexts. (*context_iter)->context.ClearWeak(); if (!in_gc) { @@ -234,19 +229,18 @@ void EventBindings::HandleContextCreated(WebFrame* frame, bool content_script) { // care about content scripts and extension frames. // (Unless we're in unit tests, in which case we don't care what the URL // is). - DCHECK(frame_context == context); + DCHECK(frame_context.IsEmpty() || frame_context == context); if (!in_unit_tests) return; } v8::Persistent<v8::Context> persistent_context = v8::Persistent<v8::Context>::New(context); - v8::Persistent<v8::Context> parent_context; + WebFrame* parent_frame = NULL; if (content_script) { DCHECK(frame_context != context); - - parent_context = v8::Persistent<v8::Context>::New(frame_context); + parent_frame = frame; // Content script contexts can get GCed before their frame goes away, so // set up a GC callback. persistent_context.MakeWeak(NULL, &ContextWeakReferenceCallback); @@ -257,7 +251,7 @@ void EventBindings::HandleContextCreated(WebFrame* frame, bool content_script) { render_view = RenderView::FromWebView(frame->view()); contexts.push_back(linked_ptr<ContextInfo>( - new ContextInfo(persistent_context, extension_id, parent_context, + new ContextInfo(persistent_context, extension_id, parent_frame, render_view))); v8::Handle<v8::Value> argv[1]; @@ -272,18 +266,18 @@ void EventBindings::HandleContextDestroyed(WebFrame* frame) { v8::HandleScope handle_scope; v8::Local<v8::Context> context = frame->mainWorldScriptContext(); - DCHECK(!context.IsEmpty()); - - ContextList::iterator context_iter = bindings_utils::FindContext(context); - if (context_iter != GetContexts().end()) - UnregisterContext(context_iter, false); + if (!context.IsEmpty()) { + ContextList::iterator context_iter = bindings_utils::FindContext(context); + if (context_iter != GetContexts().end()) + UnregisterContext(context_iter, false); + } // Unload any content script contexts for this frame. Note that the frame - // itself might not be registered, but can still be a parent context. + // itself might not be registered, but can still be a parent frame. for (ContextList::iterator it = GetContexts().begin(); it != GetContexts().end(); ) { ContextList::iterator current = it++; - if ((*current)->parent_context == context) + if ((*current)->parent_frame == frame) UnregisterContext(current, false); } } |