From 0c882b2856e5851765ce89f63d337902a3e6b823 Mon Sep 17 00:00:00 2001 From: "darin@chromium.org" Date: Wed, 7 Oct 2009 17:01:28 +0000 Subject: Invent WebFrameImpl::ClientHandle as a weak reference to WebFrameClient. Unfortunately, I can't use base::WeakPtr for this since this code will all move into webkit/api shortly. R=dglazkov BUG=10034 TEST=none Review URL: http://codereview.chromium.org/263007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28267 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/webframe_impl.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'webkit/glue/webframe_impl.h') diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h index 773422c..b4cff81 100644 --- a/webkit/glue/webframe_impl.h +++ b/webkit/glue/webframe_impl.h @@ -37,6 +37,7 @@ MSVC_PUSH_WARNING_LEVEL(0); #include "ResourceHandleClient.h" #include "Frame.h" #include "PlatformString.h" +#include MSVC_POP_WARNING(); class ChromePrintContext; @@ -64,8 +65,7 @@ class WebFrameClient; } // Implementation of WebFrame, note that this is a reference counted object. -class WebFrameImpl : public WebKit::WebFrame, - public base::RefCounted { +class WebFrameImpl : public WebKit::WebFrame, public RefCounted { public: // WebFrame methods: virtual WebKit::WebString name() const; @@ -169,7 +169,7 @@ class WebFrameImpl : public WebKit::WebFrame, virtual WebKit::WebString contentAsText(size_t max_chars) const; virtual WebKit::WebString contentAsMarkup() const; - WebFrameImpl(WebKit::WebFrameClient* client); + static PassRefPtr create(WebKit::WebFrameClient* client); ~WebFrameImpl(); static int live_object_count() { @@ -242,12 +242,29 @@ class WebFrameImpl : public WebKit::WebFrame, webkit_glue::PasswordAutocompleteListener* GetPasswordListener( WebCore::HTMLInputElement* user_name_input_element); - WebKit::WebFrameClient* client() const { return client_; } - void drop_client() { client_ = NULL; } + WebKit::WebFrameClient* client() const { return client_handle_->client(); } + void drop_client() { client_handle_->drop_client(); } protected: friend class WebFrameLoaderClient; + // A weak reference to the WebFrameClient. Each WebFrame in the hierarchy + // owns a reference to a ClientHandle. When the main frame is destroyed, it + // clears the WebFrameClient. + class ClientHandle : public RefCounted { + public: + static PassRefPtr create(WebKit::WebFrameClient* client) { + return adoptRef(new ClientHandle(client)); + } + WebKit::WebFrameClient* client() { return client_; } + void drop_client() { client_ = NULL; } + private: + ClientHandle(WebKit::WebFrameClient* client) : client_(client) {} + WebKit::WebFrameClient* client_; + }; + + WebFrameImpl(PassRefPtr client_handle); + // Informs the WebFrame that the Frame is being closed, called by the // WebFrameLoaderClient void Closing(); @@ -261,7 +278,7 @@ class WebFrameImpl : public WebKit::WebFrame, // asynchronously in order to scope string matches during a find operation. ScopedRunnableMethodFactory scope_matches_factory_; - WebKit::WebFrameClient* client_; + RefPtr client_handle_; // This is a weak pointer to our corresponding WebCore frame. A reference to // ourselves is held while frame_ is valid. See our Closing method. -- cgit v1.1