| Index: apps/shell_window.cc
|
| diff --git a/apps/shell_window.cc b/apps/shell_window.cc
|
| index d0dd9cc0c05de467155ba9aea376cfc8b0b678a1..4f8bd4222043c5fa9207e91bfdac0175666cd0ee 100644
|
| --- a/apps/shell_window.cc
|
| +++ b/apps/shell_window.cc
|
| @@ -280,9 +280,15 @@ void ShellWindow::RequestToLockMouse(WebContents* web_contents,
|
| }
|
|
|
| void ShellWindow::OnNativeClose() {
|
| - extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this);
|
| - if (shell_window_contents_)
|
| - shell_window_contents_->NativeWindowClosed();
|
| + if (extension_) {
|
| + // If |extension_| is NULL here, it is because the extension has been
|
| + // unloaded. In this case, the window will have already been removed from
|
| + // the ShellWindowRegistry, and the app can not be informed of the window
|
| + // closing as it has gone.
|
| + extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this);
|
| + if (shell_window_contents_)
|
| + shell_window_contents_->NativeWindowClosed();
|
| + }
|
| delete this;
|
| }
|
|
|
| @@ -447,7 +453,7 @@ void ShellWindow::UpdateExtensionAppIcon() {
|
| }
|
|
|
| void ShellWindow::CloseContents(WebContents* contents) {
|
| - native_app_window_->Close();
|
| + Close();
|
| }
|
|
|
| bool ShellWindow::ShouldSuppressDialogs() {
|
| @@ -526,12 +532,16 @@ void ShellWindow::Observe(int type,
|
| const extensions::Extension* unloaded_extension =
|
| content::Details<extensions::UnloadedExtensionInfo>(
|
| details)->extension;
|
| - if (extension_ == unloaded_extension)
|
| - native_app_window_->Close();
|
| + if (extension_ == unloaded_extension) {
|
| + Close();
|
| + // After this notification finishes processing, the Extension will be
|
| + // deleted, so we null out our reference to avoid bad access.
|
| + extension_ = NULL;
|
| + }
|
| break;
|
| }
|
| case chrome::NOTIFICATION_APP_TERMINATING:
|
| - native_app_window_->Close();
|
| + Close();
|
| break;
|
| default:
|
| NOTREACHED() << "Received unexpected notification";
|
| @@ -557,6 +567,11 @@ WebContentsModalDialogHost* ShellWindow::GetWebContentsModalDialogHost() {
|
| return native_app_window_.get();
|
| }
|
|
|
| +void ShellWindow::Close() {
|
| + extensions::ShellWindowRegistry::Get(profile_)->RemoveShellWindow(this);
|
| + native_app_window_->Close();
|
| +}
|
| +
|
| void ShellWindow::AddMessageToDevToolsConsole(ConsoleMessageLevel level,
|
| const std::string& message) {
|
| content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
|
|
|