Browse Source

fix: crash on missing `RenderWidgetHostView` (#38100)

chore: fix crash on missing RenderWidgetHostView
Shelley Vohr 2 years ago
parent
commit
f4b7e59b2d
1 changed files with 8 additions and 6 deletions
  1. 8 6
      shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm

+ 8 - 6
shell/browser/ui/cocoa/electron_inspectable_web_contents_view.mm

@@ -287,12 +287,14 @@
     // Temporarily pretend that the WebContents is fully non-draggable while we
     // re-send the mouse event. This allows the re-dispatched event to "land"
     // on the WebContents, instead of "falling through" back to the window.
-    api_contents->SetForceNonDraggable(true);
-    BaseView* contentsView = (BaseView*)contents->GetRenderWidgetHostView()
-                                 ->GetNativeView()
-                                 .GetNativeNSView();
-    [contentsView mouseEvent:event];
-    api_contents->SetForceNonDraggable(false);
+    auto* rwhv = contents->GetRenderWidgetHostView();
+    if (rwhv) {
+      api_contents->SetForceNonDraggable(true);
+      BaseView* contentsView =
+          (BaseView*)rwhv->GetNativeView().GetNativeNSView();
+      [contentsView mouseEvent:event];
+      api_contents->SetForceNonDraggable(false);
+    }
   }
 }