From 99519dc7184abc349683c092a292923604ba9f5b Mon Sep 17 00:00:00 2001 From: "darin@chromium.org" Date: Tue, 11 Aug 2009 19:36:56 +0000 Subject: Remove WebView::SetDelegate because I'd like to avoid having a method like this in the WebKit API. The only consumer was TestShell. It was using this method to replace its TestWebViewDelegate instance. Instead, with this change, it has a manual Reset method. To avoid duplication with the constructor, Reset uses operator=(). This required a couple changes: 1- Remove DISALLOW_COPY_AND_ASSIGN from WebViewDelegate. Anyways, that didn't make sense since you cannot 'copy' a class with pure virtual methods. 2- Change scoped_ptr members of TestWebViewDelegate to linked_ptr. The extra overhead of the linked_ptr seems warranted in this case. I also changed TestWebViewDelegate to not be reference counted since it wasn't necessary. R=tony BUG=none TEST=none Review URL: http://codereview.chromium.org/164308 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23068 0039d316-1c4b-4281-b951-d872f2087c98 --- .../tools/test_shell/mac/test_webview_delegate.mm | 3 -- webkit/tools/test_shell/test_shell.cc | 17 +++++----- webkit/tools/test_shell/test_shell.h | 4 +-- webkit/tools/test_shell/test_shell_gtk.cc | 5 +-- webkit/tools/test_shell/test_webview_delegate.cc | 32 ++++++++++++++++++ webkit/tools/test_shell/test_webview_delegate.h | 39 ++++++---------------- .../tools/test_shell/test_webview_delegate_gtk.cc | 3 -- .../tools/test_shell/test_webview_delegate_win.cc | 4 --- 8 files changed, 56 insertions(+), 51 deletions(-) (limited to 'webkit/tools/test_shell') diff --git a/webkit/tools/test_shell/mac/test_webview_delegate.mm b/webkit/tools/test_shell/mac/test_webview_delegate.mm index 7724532..1adb264 100644 --- a/webkit/tools/test_shell/mac/test_webview_delegate.mm +++ b/webkit/tools/test_shell/mac/test_webview_delegate.mm @@ -23,9 +23,6 @@ using WebKit::WebWidget; // WebViewDelegate ----------------------------------------------------------- -TestWebViewDelegate::~TestWebViewDelegate() { -} - WebWidget* TestWebViewDelegate::CreatePopupWidgetWithInfo( WebView* webview, const WebPopupMenuInfo& info) { diff --git a/webkit/tools/test_shell/test_shell.cc b/webkit/tools/test_shell/test_shell.cc index 1d296bf..df1f953 100644 --- a/webkit/tools/test_shell/test_shell.cc +++ b/webkit/tools/test_shell/test_shell.cc @@ -112,8 +112,8 @@ TestShell::TestShell() test_is_pending_(false), is_modal_(false), dump_stats_table_on_exit_(false) { - delegate_ = new TestWebViewDelegate(this); - popup_delegate_ = new TestWebViewDelegate(this); + delegate_.reset(new TestWebViewDelegate(this)); + popup_delegate_.reset(new TestWebViewDelegate(this)); layout_test_controller_.reset(new LayoutTestController(this)); event_sending_controller_.reset(new EventSendingController(this)); text_input_controller_.reset(new TextInputController(this)); @@ -126,6 +126,8 @@ TestShell::TestShell() } TestShell::~TestShell() { + delegate_->RevokeDragDrop(); + // Navigate to an empty page to fire all the destruction logic for the // current page. LoadURL(L"about:blank"); @@ -134,7 +136,9 @@ TestShell::~TestShell() { CallJSGC(); CallJSGC(); - webView()->SetDelegate(NULL); + // Destroy the WebView before the TestWebViewDelegate. + m_webViewHost.reset(); + PlatformCleanUp(); StatsTable *table = StatsTable::current(); @@ -502,14 +506,11 @@ void TestShell::SizeToDefault() { void TestShell::ResetTestController() { layout_test_controller_->Reset(); event_sending_controller_->Reset(); - - // Reset state in the test webview delegate. - delegate_ = new TestWebViewDelegate(this); - webView()->SetDelegate(delegate_); + delegate_->Reset(); } void TestShell::LoadURL(const wchar_t* url) { - LoadURLForFrame(url, NULL); + LoadURLForFrame(url, NULL); } bool TestShell::Navigate(const TestNavigationEntry& entry, bool reload) { diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index 1c18e4f..4b6ed14 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -324,8 +324,8 @@ private: scoped_ptr navigation_controller_; - scoped_refptr delegate_; - scoped_refptr popup_delegate_; + scoped_ptr delegate_; + scoped_ptr popup_delegate_; const TestParams* test_params_; diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc index 27aafcd..4ce9e5a 100644 --- a/webkit/tools/test_shell/test_shell_gtk.cc +++ b/webkit/tools/test_shell/test_shell_gtk.cc @@ -369,7 +369,8 @@ bool TestShell::Initialize(const std::wstring& startingURL) { gtk_toolbar_insert(GTK_TOOLBAR(toolbar), tool_item, -1 /* append */); gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); - m_webViewHost.reset(WebViewHost::Create(vbox, delegate_, *TestShell::web_prefs_)); + m_webViewHost.reset( + WebViewHost::Create(vbox, delegate_.get(), *TestShell::web_prefs_)); // Enables output of "EDDITING DELEGATE: " debugging lines in the layout test // output. @@ -476,7 +477,7 @@ void TestShell::DestroyWindow(gfx::NativeWindow windowHandle) { WebWidget* TestShell::CreatePopupWidget(WebView* webview) { GtkWidget* popupwindow = gtk_window_new(GTK_WINDOW_POPUP); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); - WebWidgetHost* host = WebWidgetHost::Create(vbox, popup_delegate_); + WebWidgetHost* host = WebWidgetHost::Create(vbox, popup_delegate_.get()); gtk_container_add(GTK_CONTAINER(popupwindow), vbox); m_popupHost = host; diff --git a/webkit/tools/test_shell/test_webview_delegate.cc b/webkit/tools/test_shell/test_webview_delegate.cc index f3ae7e8..654dc314 100644 --- a/webkit/tools/test_shell/test_webview_delegate.cc +++ b/webkit/tools/test_shell/test_webview_delegate.cc @@ -845,6 +845,32 @@ WebScreenInfo TestWebViewDelegate::screenInfo() { return WebScreenInfo(); } +// Public methods ------------------------------------------------------------ + +TestWebViewDelegate::TestWebViewDelegate(TestShell* shell) + : policy_delegate_enabled_(false), + policy_delegate_is_permissive_(false), + policy_delegate_should_notify_done_(false), + shell_(shell), + top_loading_frame_(NULL), + page_id_(-1), + last_page_id_updated_(-1), +#if defined(OS_LINUX) + cursor_type_(GDK_X_CURSOR), +#endif + smart_insert_delete_enabled_(true), +#if defined(OS_WIN) + select_trailing_whitespace_enabled_(true), +#else + select_trailing_whitespace_enabled_(false), +#endif + block_redirects_(false) { +} + +void TestWebViewDelegate::Reset() { + *this = TestWebViewDelegate(shell_); +} + void TestWebViewDelegate::SetSmartInsertDeleteEnabled(bool enabled) { smart_insert_delete_enabled_ = enabled; // In upstream WebKit, smart insert/delete is mutually exclusive with select @@ -868,6 +894,12 @@ void TestWebViewDelegate::RegisterDragDrop() { #endif } +void TestWebViewDelegate::RevokeDragDrop() { +#if defined(OS_WIN) + ::RevokeDragDrop(shell_->webViewWnd()); +#endif +} + void TestWebViewDelegate::SetCustomPolicyDelegate(bool is_custom, bool is_permissive) { policy_delegate_enabled_ = is_custom; diff --git a/webkit/tools/test_shell/test_webview_delegate.h b/webkit/tools/test_shell/test_webview_delegate.h index 81e7bab..6224b9c 100644 --- a/webkit/tools/test_shell/test_webview_delegate.h +++ b/webkit/tools/test_shell/test_webview_delegate.h @@ -21,8 +21,7 @@ #endif #include "base/basictypes.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" +#include "base/linked_ptr.h" #if defined(OS_MACOSX) #include "webkit/api/public/WebRect.h" #include "webkit/api/public/WebPopupMenuInfo.h" @@ -41,8 +40,7 @@ class GURL; class TestShell; class WebWidgetHost; -class TestWebViewDelegate : public base::RefCounted, - public WebViewDelegate { +class TestWebViewDelegate : public WebViewDelegate { public: struct CapturedContextMenuEvent { CapturedContextMenuEvent(ContextNodeType in_node_type, @@ -60,27 +58,6 @@ class TestWebViewDelegate : public base::RefCounted, typedef std::vector CapturedContextMenuEvents; - TestWebViewDelegate(TestShell* shell) - : policy_delegate_enabled_(false), - policy_delegate_is_permissive_(false), - policy_delegate_should_notify_done_(false), - shell_(shell), - top_loading_frame_(NULL), - page_id_(-1), - last_page_id_updated_(-1), -#if defined(OS_LINUX) - cursor_type_(GDK_X_CURSOR), -#endif - smart_insert_delete_enabled_(true), -#if defined(OS_WIN) - select_trailing_whitespace_enabled_(true), -#else - select_trailing_whitespace_enabled_(false), -#endif - block_redirects_(false) { - } - virtual ~TestWebViewDelegate(); - // WebViewDelegate virtual WebView* CreateWebView(WebView* webview, bool user_gesture, @@ -257,6 +234,9 @@ class TestWebViewDelegate : public base::RefCounted, virtual WebKit::WebRect windowResizerRect(); virtual WebKit::WebScreenInfo screenInfo(); + TestWebViewDelegate(TestShell* shell); + void Reset(); + void SetSmartInsertDeleteEnabled(bool enabled); void SetSelectTrailingWhitespaceEnabled(bool enabled); @@ -283,6 +263,9 @@ class TestWebViewDelegate : public base::RefCounted, // Sets the webview as a drop target. void RegisterDragDrop(); + void RevokeDragDrop(); + + void ResetDragDrop(); void SetCustomPolicyDelegate(bool is_custom, bool is_permissive); void WaitForPolicyDelegate(); @@ -350,7 +333,7 @@ class TestWebViewDelegate : public base::RefCounted, int page_id_; int last_page_id_updated_; - scoped_ptr pending_extra_data_; + linked_ptr pending_extra_data_; // Maps resource identifiers to a descriptive string. typedef std::map ResourceMap; @@ -375,7 +358,7 @@ class TestWebViewDelegate : public base::RefCounted, #endif #if defined(OS_MACOSX) - scoped_ptr popup_menu_info_; + linked_ptr popup_menu_info_; WebKit::WebRect popup_bounds_; #endif @@ -387,8 +370,6 @@ class TestWebViewDelegate : public base::RefCounted, // true if we should block any redirects bool block_redirects_; - - DISALLOW_COPY_AND_ASSIGN(TestWebViewDelegate); }; #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_WEBVIEW_DELEGATE_H_ diff --git a/webkit/tools/test_shell/test_webview_delegate_gtk.cc b/webkit/tools/test_shell/test_webview_delegate_gtk.cc index 66d7a62..460dceb 100644 --- a/webkit/tools/test_shell/test_webview_delegate_gtk.cc +++ b/webkit/tools/test_shell/test_webview_delegate_gtk.cc @@ -84,9 +84,6 @@ void SelectionClipboardGetContents(GtkClipboard* clipboard, // WebViewDelegate ----------------------------------------------------------- -TestWebViewDelegate::~TestWebViewDelegate() { -} - WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( WebView* webview, const GURL& url, diff --git a/webkit/tools/test_shell/test_webview_delegate_win.cc b/webkit/tools/test_shell/test_webview_delegate_win.cc index d49cb9d..fe57540 100644 --- a/webkit/tools/test_shell/test_webview_delegate_win.cc +++ b/webkit/tools/test_shell/test_webview_delegate_win.cc @@ -41,10 +41,6 @@ using WebKit::WebRect; // WebViewDelegate ----------------------------------------------------------- -TestWebViewDelegate::~TestWebViewDelegate() { - RevokeDragDrop(shell_->webViewWnd()); -} - WebPluginDelegate* TestWebViewDelegate::CreatePluginDelegate( WebView* webview, const GURL& url, -- cgit v1.1