diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 17:01:28 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 17:01:28 +0000 |
commit | 0c882b2856e5851765ce89f63d337902a3e6b823 (patch) | |
tree | 1f691120230073bc5999f8a249b1ee38bebd6f59 /webkit/glue/webframe_impl.h | |
parent | 6ad4d363216093052720febaf67545187d6f9997 (diff) | |
download | chromium_src-0c882b2856e5851765ce89f63d337902a3e6b823.zip chromium_src-0c882b2856e5851765ce89f63d337902a3e6b823.tar.gz chromium_src-0c882b2856e5851765ce89f63d337902a3e6b823.tar.bz2 |
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
Diffstat (limited to 'webkit/glue/webframe_impl.h')
-rw-r--r-- | webkit/glue/webframe_impl.h | 29 |
1 files changed, 23 insertions, 6 deletions
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 <wtf/RefCounted.h> 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<WebFrameImpl> { +class WebFrameImpl : public WebKit::WebFrame, public RefCounted<WebFrameImpl> { 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<WebFrameImpl> 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<ClientHandle> { + public: + static PassRefPtr<ClientHandle> 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<ClientHandle> 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<WebFrameImpl> scope_matches_factory_; - WebKit::WebFrameClient* client_; + RefPtr<ClientHandle> 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. |