Return early when render widget host view is null

This commit is contained in:
Kevin Sawicki 2016-07-28 15:47:52 -07:00
parent b790ad6c1a
commit bd2ce5327c

View file

@ -13,6 +13,9 @@ namespace atom {
namespace api { namespace api {
bool WebContents::IsFocused() const { bool WebContents::IsFocused() const {
auto view = web_contents()->GetRenderWidgetHostView();
if (!view) return false;
if (GetType() != BACKGROUND_PAGE) { if (GetType() != BACKGROUND_PAGE) {
auto window = web_contents()->GetTopLevelNativeWindow(); auto window = web_contents()->GetTopLevelNativeWindow();
// On Mac the render widget host view does not lose focus when the window // On Mac the render widget host view does not lose focus when the window
@ -21,8 +24,7 @@ bool WebContents::IsFocused() const {
return false; return false;
} }
auto view = web_contents()->GetRenderWidgetHostView(); return view->HasFocus();
return view && view->HasFocus();
} }
} // namespace api } // namespace api