diff options
author | Hokein.Wu@gmail.com <Hokein.Wu@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 04:50:27 +0000 |
---|---|---|
committer | Hokein.Wu@gmail.com <Hokein.Wu@gmail.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 04:50:27 +0000 |
commit | 3c31f032526d98d5ff234a938263ca8175f789e0 (patch) | |
tree | 13faef5906fb97a3fe66fcc7a6f777d179bd64c8 | |
parent | 896ad659e3f78abb5ac9ac154fa963ccc39b3a6d (diff) | |
download | chromium_src-3c31f032526d98d5ff234a938263ca8175f789e0.zip chromium_src-3c31f032526d98d5ff234a938263ca8175f789e0.tar.gz chromium_src-3c31f032526d98d5ff234a938263ca8175f789e0.tar.bz2 |
[App Shell] Fix a crash issue when clicking close button in root window.
BUG=338637
TEST=
1. click close button of the root window, app_shell exists normally.
2. click the blue close button inside root window, app_shell exists normally.
Review URL: https://codereview.chromium.org/157223002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250350 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | apps/shell/browser/shell_browser_main_parts.cc | 7 | ||||
-rw-r--r-- | apps/shell/browser/shell_browser_main_parts.h | 6 | ||||
-rw-r--r-- | apps/shell/browser/web_view_window.cc | 13 | ||||
-rw-r--r-- | apps/shell/browser/web_view_window.h | 10 |
4 files changed, 27 insertions, 9 deletions
diff --git a/apps/shell/browser/shell_browser_main_parts.cc b/apps/shell/browser/shell_browser_main_parts.cc index 9afadd0..7058673 100644 --- a/apps/shell/browser/shell_browser_main_parts.cc +++ b/apps/shell/browser/shell_browser_main_parts.cc @@ -125,8 +125,9 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { } else { // TODO(jamescook): For demo purposes create a window with a WebView just // to ensure that the content module is properly initialized. - ShowWebViewWindow(browser_context_.get(), - wm_test_helper_->root_window()->window()); + webview_window_.reset(CreateWebViewWindow(browser_context_.get(), + wm_test_helper_->root_window()->window())); + webview_window_->Show(); } } @@ -170,6 +171,8 @@ void ShellBrowserMainParts::CreateRootWindow() { } void ShellBrowserMainParts::DestroyRootWindow() { + // We should close widget before destroying root window. + webview_window_.reset(); wm_test_helper_->root_window()->RemoveRootWindowObserver(this); wm_test_helper_->root_window()->PrepareForShutdown(); wm_test_helper_.reset(); diff --git a/apps/shell/browser/shell_browser_main_parts.h b/apps/shell/browser/shell_browser_main_parts.h index 5a171b9..dbd9a92 100644 --- a/apps/shell/browser/shell_browser_main_parts.h +++ b/apps/shell/browser/shell_browser_main_parts.h @@ -25,6 +25,10 @@ class ShellExtensionsBrowserClient; class ShellExtensionSystem; } +namespace views { +class Widget; +} + namespace wm { class WMTestHelper; } @@ -87,6 +91,8 @@ class ShellBrowserMainParts : public content::BrowserMainParts, scoped_ptr<aura::TestScreen> test_screen_; + scoped_ptr<views::Widget> webview_window_; + // Owned by the BrowserContextKeyedService system. extensions::ShellExtensionSystem* extension_system_; diff --git a/apps/shell/browser/web_view_window.cc b/apps/shell/browser/web_view_window.cc index cee375e..88b24ce 100644 --- a/apps/shell/browser/web_view_window.cc +++ b/apps/shell/browser/web_view_window.cc @@ -44,7 +44,8 @@ views::View* WebViewWindowContents::GetContentsView() { void WebViewWindowContents::WindowClosing() { // Close the app when the window is closed. - base::MessageLoopForUI::current()->Quit(); + if (base::MessageLoopForUI::current()->is_running()) + base::MessageLoopForUI::current()->Quit(); } void WebViewWindowContents::ViewHierarchyChanged( @@ -68,16 +69,20 @@ void WebViewWindowContents::InitChildViews() { namespace apps { -void ShowWebViewWindow(content::BrowserContext* browser_context, - aura::Window* window_context) { +views::Widget* CreateWebViewWindow(content::BrowserContext* browser_context, + aura::Window* window_context) { views::Widget* widget = new views::Widget; views::Widget::InitParams params; params.delegate = new WebViewWindowContents(browser_context); params.context = window_context; + // Make widget owns the native_widget, so that the pointer of widget is still + // valid after user click the close button of the widget inside root window. + // app_shell client controls the widget lifetime. + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; params.bounds = window_context->bounds(); params.top_level = true; widget->Init(params); - widget->Show(); + return widget; } } // namespace apps diff --git a/apps/shell/browser/web_view_window.h b/apps/shell/browser/web_view_window.h index b785ed7..e3d53f7 100644 --- a/apps/shell/browser/web_view_window.h +++ b/apps/shell/browser/web_view_window.h @@ -13,11 +13,15 @@ namespace content { class BrowserContext; } +namespace views { +class Widget; +} + namespace apps { -// Shows an example window containing a WebView. -void ShowWebViewWindow(content::BrowserContext* browser_context, - aura::Window* window_context); +// Create an example window containing a WebView. +views::Widget* CreateWebViewWindow(content::BrowserContext* browser_context, + aura::Window* window_context); } // namespace apps |