Merge pull request #6644 from electron/webcontents-is-focused-crash
Check view before checking top level native window
This commit is contained in:
commit
ea6e6dab8c
2 changed files with 5 additions and 3 deletions
|
@ -743,7 +743,7 @@ bool WebContents::OnMessageReceived(const IPC::Message& message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// There are three ways of destroying a webContents:
|
// There are three ways of destroying a webContents:
|
||||||
// 1. call webContents.destory();
|
// 1. call webContents.destroy();
|
||||||
// 2. garbage collection;
|
// 2. garbage collection;
|
||||||
// 3. user closes the window of webContents;
|
// 3. user closes the window of webContents;
|
||||||
// For webview only #1 will happen, for BrowserWindow both #1 and #3 may
|
// For webview only #1 will happen, for BrowserWindow both #1 and #3 may
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue