Index: content/browser/renderer_host/render_widget_host_view_aura.cc |
diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc |
index e8214ca8c554fba3d4bcb70f9c2b4180dcc289e7..37010861dda9a5ae8ac1b608ed9006637b2ed9b9 100644 |
--- a/content/browser/renderer_host/render_widget_host_view_aura.cc |
+++ b/content/browser/renderer_host/render_widget_host_view_aura.cc |
@@ -48,6 +48,7 @@ |
#include "ui/aura/env.h" |
#include "ui/aura/root_window.h" |
#include "ui/aura/window.h" |
+#include "ui/aura/window_destruction_observer.h" |
#include "ui/aura/window_observer.h" |
#include "ui/aura/window_tracker.h" |
#include "ui/base/clipboard/scoped_clipboard_writer.h" |
@@ -2024,8 +2025,20 @@ void RenderWidgetHostViewAura::OnKeyEvent(ui::KeyEvent* event) { |
if (host_tracker_.get() && !host_tracker_->windows().empty()) { |
aura::Window* host = *(host_tracker_->windows().begin()); |
aura::client::FocusClient* client = aura::client::GetFocusClient(host); |
- if (client) |
+ if (client) { |
+ // Calling host->Focus may delete |this|. We create a local |
+ // observer for that. In that case we exit without further |
+ // access to any members. |
+ aura::WindowDestructionObserver destruction_observer; |
+ window_->AddObserver(&destruction_observer); |
+ const aura::Window* copy_window = window_; // local copy |
host->Focus(); |
+ if (destruction_observer.was_destroyed(copy_window)) { |
+ event->SetHandled(); |
+ return; |
+ } |
+ window_->RemoveObserver(&destruction_observer); |
+ } |
} |
if (!in_shutdown_) { |
in_shutdown_ = true; |