Chromium Code Reviews| Index: chrome/browser/ui/autofill/popup_controller_common.cc |
| diff --git a/chrome/browser/ui/autofill/popup_controller_common.cc b/chrome/browser/ui/autofill/popup_controller_common.cc |
| index 2c97b8b7c222c6fb58f61eebf43f28da21da1208..5c54f8418673813a1f5377db3f08107fdd5dced3 100644 |
| --- a/chrome/browser/ui/autofill/popup_controller_common.cc |
| +++ b/chrome/browser/ui/autofill/popup_controller_common.cc |
| @@ -4,11 +4,30 @@ |
| #include "chrome/browser/ui/autofill/popup_controller_common.h" |
| -#include "content/public/browser/render_view_host.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_widget_host_view.h" |
| #include "content/public/browser/web_contents.h" |
| namespace autofill { |
| +namespace { |
| + |
| +// Returns the RenderWidgetHost which should be currently consuming keyboard |
| +// events in |web_contents|. Can return null if there is no such |
| +// RenderWidgetHost. |
| +content::RenderWidgetHost* KeyPressHandlingTarget( |
| + content::WebContents* web_contents) { |
| + content::RenderFrameHost* frame = web_contents->GetFocusedFrame(); |
| + if (!frame) |
| + frame = web_contents->GetMainFrame(); |
| + content::RenderWidgetHostView* view = frame->GetView(); |
| + if (!view) |
| + return nullptr; |
| + return view->GetRenderWidgetHost(); |
| +} |
| + |
| +} // namespace |
| + |
| PopupControllerCommon::PopupControllerCommon( |
| const gfx::RectF& element_bounds, |
| base::i18n::TextDirection text_direction, |
| @@ -30,18 +49,17 @@ void PopupControllerCommon::SetKeyPressCallback( |
| void PopupControllerCommon::RegisterKeyPressCallback() { |
| if (web_contents_ && !key_press_event_target_) { |
| - key_press_event_target_ = web_contents_->GetRenderViewHost(); |
| - key_press_event_target_->GetWidget()->AddKeyPressEventCallback( |
| + key_press_event_target_ = KeyPressHandlingTarget(web_contents_); |
|
EhsanK
2017/03/27 19:35:09
I think both here and below for RemoveKeyPressCall
|
| + key_press_event_target_->AddKeyPressEventCallback( |
| key_press_event_callback_); |
| } |
| } |
| void PopupControllerCommon::RemoveKeyPressCallback() { |
| if (web_contents_ && (!web_contents_->IsBeingDestroyed()) && |
| - key_press_event_target_ == web_contents_->GetRenderViewHost()) { |
| - web_contents_->GetRenderViewHost() |
| - ->GetWidget() |
| - ->RemoveKeyPressEventCallback(key_press_event_callback_); |
| + key_press_event_target_ == KeyPressHandlingTarget(web_contents_)) { |
| + key_press_event_target_->RemoveKeyPressEventCallback( |
|
EhsanK
2017/03/27 19:35:09
There seems to be a memory leak, i.e., callbacks w
vabr (Chromium)
2017/03/27 20:28:53
The idea to use |key_press_event_target_| seems in
|
| + key_press_event_callback_); |
| } |
| key_press_event_target_ = NULL; |
| } |