From f816c01e9c6f6f0365ba80ba3f661e38461a0537 Mon Sep 17 00:00:00 2001 From: "mpcomplete@chromium.org" Date: Fri, 26 Jun 2009 21:48:32 +0000 Subject: 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 --- webkit/glue/webframe.h | 14 ++++++++++++++ webkit/glue/webframe_impl.cc | 11 +++++++++++ webkit/glue/webframe_impl.h | 6 ++++++ webkit/glue/webframeloaderclient_impl.cc | 14 ++++++++++++++ webkit/glue/webframeloaderclient_impl.h | 5 ++--- webkit/glue/webview_delegate.h | 10 ++++++++++ webkit/port/bindings/v8/v8_proxy.cpp | 3 +++ 7 files changed, 60 insertions(+), 3 deletions(-) (limited to 'webkit') 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 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 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 WebFrameImpl::GetScriptContext() { + if (!frame_) + return v8::Local(); + + 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 { virtual NPObject* GetWindowNPObject(); +#if USE(V8) + // Returns the V8 context for this frame, or an empty handle if there is + // none. + virtual v8::Local 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(); } -- cgit v1.1