diff options
author | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:12:25 +0000 |
---|---|---|
committer | tc@google.com <tc@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-26 23:12:25 +0000 |
commit | d555e4f9f90e27cf38f7f777504d7e4ffcdcccde (patch) | |
tree | 18ac0d2b9cb36942b6268e06ed3d08d0d2b805de /chrome | |
parent | bbc94503de28cde2f8050ddc69f25c167ef93c1b (diff) | |
download | chromium_src-d555e4f9f90e27cf38f7f777504d7e4ffcdcccde.zip chromium_src-d555e4f9f90e27cf38f7f777504d7e4ffcdcccde.tar.gz chromium_src-d555e4f9f90e27cf38f7f777504d7e4ffcdcccde.tar.bz2 |
Fix our browser window close path to be more like windows.
We try to run onbeforeunload handlers (and cause the renderer
to hang) and we close all the tabs first which properly destroys
the tabcontents and webcontents.
Review URL: http://codereview.chromium.org/53083
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12616 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 42 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.h | 4 |
2 files changed, 38 insertions, 8 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 05ce1e6..fcc8fa6 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -328,15 +328,12 @@ void BrowserWindowGtk::SetBounds(const gfx::Rect& bounds) { } void BrowserWindowGtk::Close() { - // TODO(tc): There's a lot missing here that's in the windows shutdown code - // path. This method should try to close (see BrowserView::CanClose), - // although it may not succeed (e.g., if the page has an unload handler). - // Currently we just go ahead and close. + if (!CanClose()) + return; - // TODO(tc): Once the tab strip model is hooked up, this call can be removed. - // It should get called by TabDetachedAt when the window is being closed, but - // we don't have a TabStripModel yet. - find_bar_controller_->ChangeWebContents(NULL); + // TODO(tc): We should store the window position, perhaps using + // gtk_window_set_role. + //SaveWindowPosition(); GtkWidget* window = GTK_WIDGET(window_); // To help catch bugs in any event handlers that might get fired during the @@ -563,6 +560,35 @@ void BrowserWindowGtk::OnStateChanged(GdkWindowState state) { state_ = state; } +bool BrowserWindowGtk::CanClose() const { + // TODO(tc): We don't have tab dragging yet. + // You cannot close a frame for which there is an active originating drag + // session. + //if (tabstrip_->IsDragSessionActive()) + // return false; + + // Give beforeunload handlers the chance to cancel the close before we hide + // the window below. + if (!browser_->ShouldCloseWindow()) + return false; + + if (!browser_->tabstrip_model()->empty()) { + // Tab strip isn't empty. Hide the window (so it appears to have closed + // immediately) and close all the tabs, allowing the renderers to shut + // down. When the tab strip is empty we'll be called back again. + gtk_widget_hide(GTK_WIDGET(window_)); + browser_->OnWindowClosing(); + return false; + } + + // Empty TabStripModel, it's now safe to allow the Window to be closed. + NotificationService::current()->Notify( + NotificationType::WINDOW_CLOSED, + Source<GtkWindow>(window_), + NotificationService::NoDetails()); + return true; +} + void BrowserWindowGtk::ConnectAccelerators() { GtkAccelGroup* accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(window_, accel_group); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index 7cf1674..073ff45 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -87,6 +87,10 @@ class BrowserWindowGtk : public BrowserWindow, void OnBoundsChanged(const gfx::Rect& bounds); void OnStateChanged(GdkWindowState state); + // Returns false if we're not ready to close yet. E.g., a tab may have an + // onbeforeunload handler that prevents us from closing. + bool CanClose() const; + protected: virtual void DestroyBrowser(); GtkWindow* window_; |