summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 21:48:32 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-26 21:48:32 +0000
commitf816c01e9c6f6f0365ba80ba3f661e38461a0537 (patch)
tree1f3cd0fdfd2951c10c164c41f8bd209e14c3fc0a
parent49a415c979692c045b25eb4c3e0369a83b5316e6 (diff)
downloadchromium_src-f816c01e9c6f6f0365ba80ba3f661e38461a0537.zip
chromium_src-f816c01e9c6f6f0365ba80ba3f661e38461a0537.tar.gz
chromium_src-f816c01e9c6f6f0365ba80ba3f661e38461a0537.tar.bz2
Add notifications for when V8Proxy creates or destroys a V8 Context.
BUG=no TEST=no Review URL: http://codereview.chromium.org/147124 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19424 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/extensions/event_bindings.cc17
-rw-r--r--chrome/renderer/extensions/event_bindings.h5
-rw-r--r--chrome/renderer/render_view.cc9
-rw-r--r--chrome/renderer/render_view.h2
-rw-r--r--webkit/glue/webframe.h14
-rw-r--r--webkit/glue/webframe_impl.cc11
-rw-r--r--webkit/glue/webframe_impl.h6
-rw-r--r--webkit/glue/webframeloaderclient_impl.cc14
-rw-r--r--webkit/glue/webframeloaderclient_impl.h5
-rw-r--r--webkit/glue/webview_delegate.h10
-rw-r--r--webkit/port/bindings/v8/v8_proxy.cpp3
11 files changed, 93 insertions, 3 deletions
diff --git a/chrome/renderer/extensions/event_bindings.cc b/chrome/renderer/extensions/event_bindings.cc
index 576beba..7c988e2 100644
--- a/chrome/renderer/extensions/event_bindings.cc
+++ b/chrome/renderer/extensions/event_bindings.cc
@@ -12,6 +12,7 @@
#include "chrome/renderer/js_only_v8_extensions.h"
#include "chrome/renderer/render_thread.h"
#include "grit/renderer_resources.h"
+#include "webkit/glue/webframe.h"
namespace {
@@ -164,6 +165,22 @@ void EventBindings::SetRenderThread(RenderThreadBase* thread) {
render_thread = thread;
}
+// static
+void EventBindings::HandleContextCreated(WebFrame* frame) {
+ v8::HandleScope handle_scope;
+ v8::Local<v8::Context> context = frame->GetScriptContext();
+ DCHECK(!context.IsEmpty());
+ // TODO(mpcomplete): register it
+}
+
+// static
+void EventBindings::HandleContextDestroyed(WebFrame* frame) {
+ v8::HandleScope handle_scope;
+ v8::Local<v8::Context> context = frame->GetScriptContext();
+ DCHECK(!context.IsEmpty());
+ // TODO(mpcomplete): unregister it, dispatch event
+}
+
void EventBindings::CallFunction(const std::string& function_name,
int argc, v8::Handle<v8::Value>* argv) {
for (ContextList::iterator it = GetRegisteredContexts().begin();
diff --git a/chrome/renderer/extensions/event_bindings.h b/chrome/renderer/extensions/event_bindings.h
index 0ca59c0..a026c19 100644
--- a/chrome/renderer/extensions/event_bindings.h
+++ b/chrome/renderer/extensions/event_bindings.h
@@ -10,6 +10,7 @@
#include <string>
class RenderThreadBase;
+class WebFrame;
// This class deals with the javascript bindings related to Event objects.
class EventBindings {
@@ -20,6 +21,10 @@ class EventBindings {
// Allow RenderThread to be mocked out.
static void SetRenderThread(RenderThreadBase* thread);
+ // Handle a script context coming / going away.
+ static void HandleContextCreated(WebFrame* frame);
+ static void HandleContextDestroyed(WebFrame* frame);
+
// Calls the given function in each registered context which is listening
// for events. The function can be an object property, ie:
// "chromium.Event.dispatch_".
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 051b8d6..d1aea1c 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -35,6 +35,7 @@
#include "chrome/renderer/audio_message_filter.h"
#include "chrome/renderer/devtools_agent.h"
#include "chrome/renderer/devtools_client.h"
+#include "chrome/renderer/extensions/event_bindings.h"
#include "chrome/renderer/extensions/extension_process_bindings.h"
#include "chrome/renderer/localized_error.h"
#include "chrome/renderer/media/audio_renderer_impl.h"
@@ -1425,6 +1426,14 @@ void RenderView::DocumentElementAvailable(WebFrame* frame) {
frame, UserScript::DOCUMENT_START);
}
+void RenderView::DidCreateScriptContext(WebFrame* webframe) {
+ EventBindings::HandleContextCreated(webframe);
+}
+
+void RenderView::DidDestroyScriptContext(WebFrame* webframe) {
+ EventBindings::HandleContextDestroyed(webframe);
+}
+
WindowOpenDisposition RenderView::DispositionForNavigationAction(
WebView* webview,
WebFrame* frame,
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 07cbc02..97f8130 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -222,6 +222,8 @@ class RenderView : public RenderWidget,
virtual void WindowObjectCleared(WebFrame* webframe);
virtual void DocumentElementAvailable(WebFrame* webframe);
+ virtual void DidCreateScriptContext(WebFrame* webframe);
+ virtual void DidDestroyScriptContext(WebFrame* webframe);
virtual WindowOpenDisposition DispositionForNavigationAction(
WebView* webview,
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h
index 2a7f524..1f5974c 100644
--- a/webkit/glue/webframe.h
+++ b/webkit/glue/webframe.h
@@ -11,6 +11,7 @@
#include "base/string16.h"
#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/platform_canvas.h"
+#include "webkit/api/public/WebCommon.h"
class GURL;
class WebView;
@@ -30,6 +31,13 @@ struct WebSize;
struct WebURLError;
}
+#if WEBKIT_USING_V8
+namespace v8 {
+ template <class T> class Local;
+ class Context;
+}
+#endif
+
// Every frame in a web page is represented by one WebFrame, including the
// outermost frame.
class WebFrame {
@@ -69,6 +77,12 @@ class WebFrame {
virtual NPObject* GetWindowNPObject() = 0;
+#if WEBKIT_USING_V8
+ // Returns the V8 context for this frame, or an empty handle if there is
+ // none.
+ virtual v8::Local<v8::Context> GetScriptContext() = 0;
+#endif
+
// Loads the given WebURLRequest.
virtual void LoadRequest(const WebKit::WebURLRequest& request) = 0;
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 7a8f190..a02e73a 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -819,6 +819,17 @@ NPObject* WebFrameImpl::GetWindowNPObject() {
return frame_->script()->windowScriptNPObject();
}
+#if USE(V8)
+ // Returns the V8 context for this frame, or an empty handle if there is
+ // none.
+v8::Local<v8::Context> WebFrameImpl::GetScriptContext() {
+ if (!frame_)
+ return v8::Local<v8::Context>();
+
+ return frame_->script()->proxy()->GetContext();
+}
+#endif
+
void WebFrameImpl::InvalidateArea(AreaToInvalidate area) {
ASSERT(frame() && frame()->view());
#if defined(OS_WIN) || defined(OS_LINUX)
diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h
index 9a344c0c..f164214 100644
--- a/webkit/glue/webframe_impl.h
+++ b/webkit/glue/webframe_impl.h
@@ -119,6 +119,12 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
virtual NPObject* GetWindowNPObject();
+#if USE(V8)
+ // Returns the V8 context for this frame, or an empty handle if there is
+ // none.
+ virtual v8::Local<v8::Context> GetScriptContext();
+#endif
+
virtual void GetContentAsPlainText(int max_chars, std::wstring* text) const;
virtual bool Find(
int request_id,
diff --git a/webkit/glue/webframeloaderclient_impl.cc b/webkit/glue/webframeloaderclient_impl.cc
index dc0e9c0..5def74f 100644
--- a/webkit/glue/webframeloaderclient_impl.cc
+++ b/webkit/glue/webframeloaderclient_impl.cc
@@ -125,6 +125,20 @@ void WebFrameLoaderClient::documentElementAvailable() {
d->DocumentElementAvailable(webframe_);
}
+void WebFrameLoaderClient::didCreateScriptContext() {
+ WebViewImpl* webview = webframe_->GetWebViewImpl();
+ WebViewDelegate* d = webview->delegate();
+ if (d)
+ d->DidCreateScriptContext(webframe_);
+}
+
+void WebFrameLoaderClient::didDestroyScriptContext() {
+ WebViewImpl* webview = webframe_->GetWebViewImpl();
+ WebViewDelegate* d = webview->delegate();
+ if (d)
+ d->DidDestroyScriptContext(webframe_);
+}
+
void WebFrameLoaderClient::didPerformFirstNavigation() const {
}
diff --git a/webkit/glue/webframeloaderclient_impl.h b/webkit/glue/webframeloaderclient_impl.h
index e5d6927..e31e7e4 100644
--- a/webkit/glue/webframeloaderclient_impl.h
+++ b/webkit/glue/webframeloaderclient_impl.h
@@ -44,9 +44,8 @@ class WebFrameLoaderClient : public WebCore::FrameLoaderClient {
virtual void windowObjectCleared();
virtual void documentElementAvailable();
- // TODO(mpcomplete): roll DEPS
- virtual void didCreateScriptContext() {}
- virtual void didDestroyScriptContext() {}
+ virtual void didCreateScriptContext();
+ virtual void didDestroyScriptContext();
virtual bool hasWebView() const; // mainly for assertions
virtual bool hasFrameView() const; // ditto
diff --git a/webkit/glue/webview_delegate.h b/webkit/glue/webview_delegate.h
index bd081c4..94fd4f5 100644
--- a/webkit/glue/webview_delegate.h
+++ b/webkit/glue/webview_delegate.h
@@ -210,6 +210,16 @@ class WebViewDelegate : virtual public WebWidgetDelegate {
virtual void DocumentElementAvailable(WebFrame* webframe) {
}
+ // Notifies that a new script context has been created for this frame.
+ // This is similar to WindowObjectCleared but only called once per frame
+ // context.
+ virtual void DidCreateScriptContext(WebFrame* webframe) {
+ }
+
+ // Notifies that this frame's script context has been destroyed.
+ virtual void DidDestroyScriptContext(WebFrame* webframe) {
+ }
+
// PolicyDelegate ----------------------------------------------------------
// This method is called to notify the delegate, and let it modify a
diff --git a/webkit/port/bindings/v8/v8_proxy.cpp b/webkit/port/bindings/v8/v8_proxy.cpp
index d11ee18..e1f23ef 100644
--- a/webkit/port/bindings/v8/v8_proxy.cpp
+++ b/webkit/port/bindings/v8/v8_proxy.cpp
@@ -45,6 +45,7 @@
#include "CSSMutableStyleDeclaration.h"
#include "DOMObjectsInclude.h"
#include "DocumentLoader.h"
+#include "FrameLoaderClient.h"
#include "ScriptController.h"
#include "V8CustomBinding.h"
#include "V8DOMMap.h"
@@ -1931,6 +1932,7 @@ void V8Proxy::ClearDocumentWrapperCache()
void V8Proxy::DisposeContextHandles() {
if (!m_context.IsEmpty()) {
+ m_frame->loader()->client()->didDestroyScriptContext();
m_context.Dispose();
m_context.Clear();
}
@@ -2334,6 +2336,7 @@ void V8Proxy::InitContextIfNeeded()
SetSecurityToken();
+ m_frame->loader()->client()->didCreateScriptContext();
m_frame->loader()->dispatchWindowObjectAvailable();
}