From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <sattard@slack-corp.com>
Date: Mon, 8 Mar 2021 16:27:39 -0800
Subject: extend ApplyWebPreferences with Electron-specific logic

On macOS, popup menus are rendered by the main process by default.
This causes problems in OSR, since when the popup is rendered separately,
it won't be captured in the rendered image.
Offscreen can be updated at runtime, as such we need to apply the
turn on/off ExternalPopupMenu in the ApplyPreferences method.
There is no current way to attach an observer to these prefs so patching
is our only option.

Ideally we could add an embedder observer pattern here but that can be
done in future work.

diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc
index 89a578d1246a54b01597937d0441452ab1169ebf..4d4d2c9951de9e2718c272f2723ee158ab4b6cb6 100644
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
@@ -1897,6 +1897,8 @@ void WebView::ApplyWebPreferences(const web_pref::WebPreferences& prefs,
 #if BUILDFLAG(IS_MAC)
   web_view_impl->SetMaximumLegibleScale(
       prefs.default_maximum_page_scale_factor);
+  web_view_impl->GetChromeClient().SetUseExternalPopupMenus(
+      !prefs.offscreen);
 #endif
 
 #if BUILDFLAG(IS_WIN)
