Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: chrome/browser/ui/autofill/popup_controller_common.cc

Issue 2762233004: Fix autofill popup controller key press callback registration (Closed)
Patch Set: Handle null RenderWidgetHostView gracefully Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/autofill/popup_controller_common.h" 5 #include "chrome/browser/ui/autofill/popup_controller_common.h"
6 6
7 #include "content/public/browser/render_view_host.h" 7 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/browser/render_widget_host_view.h"
8 #include "content/public/browser/web_contents.h" 9 #include "content/public/browser/web_contents.h"
9 10
10 namespace autofill { 11 namespace autofill {
11 12
13 namespace {
14
15 content::RenderWidgetHost* KeyPressHandlingTarget(
Mathieu 2017/03/26 02:03:51 since it's in the anonymous namespace, a short fun
vabr (Chromium) 2017/03/26 03:25:40 Done.
16 content::WebContents* web_contents) {
17 content::RenderFrameHost* frame = web_contents->GetFocusedFrame();
18 if (!frame)
19 frame = web_contents->GetMainFrame();
20 content::RenderWidgetHostView* view = frame->GetView();
21 if (!view)
22 return nullptr;
Mathieu 2017/03/26 02:03:51 this is a sure crash on line 50, no?
vabr (Chromium) 2017/03/26 03:25:40 For some reason I only saw the view being null dur
23 return view->GetRenderWidgetHost();
24 }
25
26 } // namespace
27
12 PopupControllerCommon::PopupControllerCommon( 28 PopupControllerCommon::PopupControllerCommon(
13 const gfx::RectF& element_bounds, 29 const gfx::RectF& element_bounds,
14 base::i18n::TextDirection text_direction, 30 base::i18n::TextDirection text_direction,
15 const gfx::NativeView container_view, 31 const gfx::NativeView container_view,
16 content::WebContents* web_contents) 32 content::WebContents* web_contents)
17 : element_bounds_(element_bounds), 33 : element_bounds_(element_bounds),
18 text_direction_(text_direction), 34 text_direction_(text_direction),
19 container_view_(container_view), 35 container_view_(container_view),
20 web_contents_(web_contents), 36 web_contents_(web_contents),
21 key_press_event_target_(NULL) { 37 key_press_event_target_(NULL) {
22 } 38 }
23 PopupControllerCommon::~PopupControllerCommon() {} 39 PopupControllerCommon::~PopupControllerCommon() {}
24 40
25 void PopupControllerCommon::SetKeyPressCallback( 41 void PopupControllerCommon::SetKeyPressCallback(
26 content::RenderWidgetHost::KeyPressEventCallback callback) { 42 content::RenderWidgetHost::KeyPressEventCallback callback) {
27 DCHECK(key_press_event_callback_.is_null()); 43 DCHECK(key_press_event_callback_.is_null());
28 key_press_event_callback_ = callback; 44 key_press_event_callback_ = callback;
29 } 45 }
30 46
31 void PopupControllerCommon::RegisterKeyPressCallback() { 47 void PopupControllerCommon::RegisterKeyPressCallback() {
32 if (web_contents_ && !key_press_event_target_) { 48 if (web_contents_ && !key_press_event_target_) {
33 key_press_event_target_ = web_contents_->GetRenderViewHost(); 49 key_press_event_target_ = KeyPressHandlingTarget(web_contents_);
34 key_press_event_target_->GetWidget()->AddKeyPressEventCallback( 50 key_press_event_target_->AddKeyPressEventCallback(
35 key_press_event_callback_); 51 key_press_event_callback_);
36 } 52 }
37 } 53 }
38 54
39 void PopupControllerCommon::RemoveKeyPressCallback() { 55 void PopupControllerCommon::RemoveKeyPressCallback() {
40 if (web_contents_ && (!web_contents_->IsBeingDestroyed()) && 56 if (web_contents_ && (!web_contents_->IsBeingDestroyed()) &&
41 key_press_event_target_ == web_contents_->GetRenderViewHost()) { 57 key_press_event_target_ == KeyPressHandlingTarget(web_contents_)) {
42 web_contents_->GetRenderViewHost() 58 key_press_event_target_->RemoveKeyPressEventCallback(
43 ->GetWidget() 59 key_press_event_callback_);
44 ->RemoveKeyPressEventCallback(key_press_event_callback_);
45 } 60 }
46 key_press_event_target_ = NULL; 61 key_press_event_target_ = NULL;
47 } 62 }
48 63
49 } // namespace autofill 64 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698