Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid crashing in NativeViewHost::SetParentAccessible on Windows 10 #26924

Merged
merged 1 commit into from Dec 11, 2020

Conversation

poiru
Copy link
Contributor

@poiru poiru commented Dec 10, 2020

This fixes #26905. The patch was obtained from @deepak1556, who in turn
got it from the Microsoft Teams folks.

I believe the crash started happening due to the changes in
https://chromium.googlesource.com/chromium/src.git/+/5c6c8e994bce2bfb867279ae5068e9f9134e70c3%5E!/#F15

This affects Electron 9 and later.

Notes: Fix occasional crash on Windows

@poiru poiru requested a review from a team as a code owner December 10, 2020 17:12
after the changes in
https://chromium.googlesource.com/chromium/src.git/+/5c6c8e994bce2bfb867279ae5068e9f9134e70c3%5E!/#F15

For context, see: https://github.com/electron/electron/issues/26905
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We require all patches to describe a plan for their own removal, or else a reason why they should be maintained forever, per https://github.com/electron/electron/blob/master/docs/development/patches.md#patch-justification.

Can this patch be upstreamed? If not, why not? Can we fix this crash without a patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nornagon Updated!

This fixes electron#26905. The patch was obtained from @deepak1556, who in turn
got it from the Microsoft Teams folks.

I believe the crash started happening due to the changes in
https://chromium.googlesource.com/chromium/src.git/+/5c6c8e994bce2bfb867279ae5068e9f9134e70c3%5E!/#F15

This affects Electron 9 and later.

Notes: Fix occasional crash on Windows
@poiru poiru force-pushed the poiru/fix-setparentaccessible branch from 7576f52 to a74da42 Compare December 10, 2020 17:20
@miniak miniak requested a review from nornagon December 10, 2020 18:10
@jkleinsc jkleinsc added the semver/patch backwards-compatible bug fixes label Dec 10, 2020
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Dec 10, 2020
@deepak1556
Copy link
Member

This is based on the investigation done by Way Vadhanasin and Julie Koubova from MS teams. The original trace from memory dump was

views::NativeViewHost::SetParentAccessible(IAccessible * accessible) Line 57 C++
ui::AXPlatformNode::NotifyAddAXModeFlags(ui::AXMode mode_flags) Line 97 C++
content::BrowserAccessibilityStateImpl::AddAccessibilityModeFlags(ui::AXMode mode) Line 227 C++
ui::AXPlatformNodeWin::QueryService(const _GUID & guidService, const _GUID & riid, void * * object) Line 4529 C++
oleacc.dll!AccWrap_Base::QueryService() Unknown
nvdaHelperRemote.dll!00007ffd31ff8dff() Unknown
nvdaHelperRemote.dll!00007ffd31fec10e() Unknown
nvdaHelperRemote.dll!00007ffd31fe3afb() Unknown
user32.dll!__ClientCallWinEventProc() Unknown
ntdll.dll!KiUserCallbackDispatcherContinue() Unknown
win32u.dll!NtUserNotifyWinEvent() Unknown
user32.dll!NotifyWinEvent() Unknown
ui::AXSystemCaretWin::MoveCaretTo(const gfx::Rect & bounds_physical_pixels) Line 72 C++
views::HWNDMessageHandler::OnCaretBoundsChanged(const ui::TextInputClient * client) Line 1060 C++
ui::InputMethodBase::NotifyTextInputCaretBoundsChanged(const ui::TextInputClient * client) Line 158 C++
ui::InputMethodWinTSF::OnCaretBoundsChanged(const ui::TextInputClient * client) Line 111 C++
ui::InputMethodWinTSF::OnDidChangeFocusedClient(ui::TextInputClient * focused_before, ui::TextInputClient * focused) Line 168 C++
[Inline Frame] ui::InputMethodBase::SetFocusedTextInputClientInternal(ui::TextInputClient * client) Line 169 C++
ui::InputMethodBase::SetFocusedTextInputClient(ui::TextInputClient * client) Line 53 C++
content::RenderWidgetHostViewAura::OnWindowFocused(aura::Window * gained_focus, aura::Window * lost_focus) Line 1800 C++
wm::FocusController::SetFocusedWindow(aura::Window * window) Line 287 C++
wm::FocusController::FocusAndActivateWindow(wm::ActivationChangeObserver::ActivationReason reason, aura::Window * window) Line 244 C++
views::View::Focus() Line 2001 C++
views::FocusManager::SetFocusedViewWithReason(views::View * view, views::FocusManager::FocusChangeReason reason) Line 378 C++
views::FocusManager::RestoreFocusedView() Line 456 C++
views::DesktopNativeWidgetAura::OnWindowActivated(wm::ActivationChangeObserver::ActivationReason reason, aura::Window * gained_active, aura::Window * lost_active) Line 1182 C++
electron::ElectronDesktopNativeWidgetAura::OnWindowActivated(wm::ActivationChangeObserver::ActivationReason reason, aura::Window * gained_active, aura::Window * lost_active) Line 47 C++
wm::FocusController::SetActiveWindow(wm::ActivationChangeObserver::ActivationReason reason, aura::Window * requested_window, aura::Window * window) Line 366 C++
wm::FocusController::FocusAndActivateWindow(wm::ActivationChangeObserver::ActivationReason reason, aura::Window * window) Line 217 C++
electron::api::BrowserWindow::OnWindowFocus() Line 287 C++

Inspecting the dump had showed that NativeViewHost does not have a valid native_wrapper_ set. The instance of NativeViewHost comes from a holder_ member of WebView. And this causes the Ax notification to dereference a null pointer.

Tracing the construction of the above WebView instance

views::WebView::WebView
electron::InspectableWebContentsViewViews::InspectableWebContentsViewViews
electron::InspectableWebContentsImpl::InspectableWebContentsImpl
electron::CommonWebContentsDelegate::InitWithWebContents
electron::api::WebContents::InitWithSessionAndOptions
electron::api::WebContents::WebContents
electron::api::WebContents::Create
base::internal::FunctorTraits<v8::Local<v8::Promise> (*)(v8::Isolate *, const base::trace_event::TraceConfig &),void>::Invoke
base::internal::InvokeHelper<0,v8::Local<v8::Promise> >::MakeItSo
base::internal::Invoker<base::internal::BindState<v8::Local<v8::Promise> (*)(…
base::internal::Invoker<base::internal::BindState<v8::Local<v8::Promise> (*)(…
base::RepeatingCallback<gin::Handle<electron::api::WebContents> (v8::Isolate *, const gin_helper::Dictionary &)>::Run
gin_helper::Invoker<gin_helper::IndicesHolder<0,1>,v8::Isolate *,const gin_helper::Dictionary &>::DispatchToCallback
gin_helper::Dispatcher<gin::Handle<electron::api::WebContents> (v8::Isolate *, const gin_helper::Dictionary &)>::DispatchToCallback
v8::internal::FunctionCallbackArguments::Call

It comes from

devtools_web_view_(new views::WebView(nullptr)),
devtools_visible_(false),
devtools_window_delegate_(nullptr),
title_(base::ASCIIToUTF16("Developer Tools")) {
if (!inspectable_web_contents_->IsGuest() &&
inspectable_web_contents_->GetWebContents()->GetNativeView()) {
auto* contents_web_view = new views::WebView(nullptr);

The reason why WebView doesn't get a native_wrapper_ is because the parent of these view's which is electron::InspectableWebContentsViewViews is not of type RootView where there is an enforcement of a valid Widget

@deepak1556
Copy link
Member

deepak1556 commented Dec 10, 2020

I am not sure of the reason why we consider electron::InspectableWebContentsViewViews as Root, @zcbenz might have more context on this. But I thought #22739 might fix the RootView assumption and it did not.

So for now teams have incorporated this patch that fixes the crash path but definitely doesn't address the root issue, which is with how we maintain the view tree.

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Dec 11, 2020
Copy link
Member

@nornagon nornagon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted for now, I hope that we can find a fix for this that does not require a patch.

@nornagon nornagon merged commit b4c1e54 into electron:master Dec 11, 2020
@release-clerk
Copy link

release-clerk bot commented Dec 11, 2020

Release Notes Persisted

Fixed an occasional crash on Windows related to NativeViewHost::SetParentAccessible.

@trop
Copy link
Contributor

trop bot commented Dec 11, 2020

I have automatically backported this PR to "10-x-y", please check out #26949

@trop
Copy link
Contributor

trop bot commented Dec 11, 2020

I have automatically backported this PR to "9-x-y", please check out #26950

@trop
Copy link
Contributor

trop bot commented Dec 11, 2020

I have automatically backported this PR to "11-x-y", please check out #26951

@trop
Copy link
Contributor

trop bot commented Dec 11, 2020

I have automatically backported this PR to "12-x-y", please check out #26952

@poiru poiru deleted the poiru/fix-setparentaccessible branch December 11, 2020 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows crash in views::NativeViewHost::SetParentAccessible
6 participants