chrome: Add CefJSDialogHandler support (fixes #3702)

This commit is contained in:
Yuta Sekiguchi 2024-06-04 12:19:14 -04:00 committed by Marshall Greenblatt
parent fd7444c7a4
commit e4bb51f6f6
8 changed files with 58 additions and 24 deletions

View File

@ -1210,11 +1210,7 @@ void AlloyBrowserHostImpl::RendererResponsive(
content::JavaScriptDialogManager* content::JavaScriptDialogManager*
AlloyBrowserHostImpl::GetJavaScriptDialogManager(content::WebContents* source) { AlloyBrowserHostImpl::GetJavaScriptDialogManager(content::WebContents* source) {
if (!javascript_dialog_manager_) { return CefBrowserHostBase::GetJavaScriptDialogManager();
javascript_dialog_manager_ =
std::make_unique<CefJavaScriptDialogManager>(this);
}
return javascript_dialog_manager_.get();
} }
void AlloyBrowserHostImpl::RunFileChooser( void AlloyBrowserHostImpl::RunFileChooser(

View File

@ -18,7 +18,6 @@
#include "cef/libcef/browser/browser_host_base.h" #include "cef/libcef/browser/browser_host_base.h"
#include "cef/libcef/browser/browser_info.h" #include "cef/libcef/browser/browser_info.h"
#include "cef/libcef/browser/frame_host_impl.h" #include "cef/libcef/browser/frame_host_impl.h"
#include "cef/libcef/browser/javascript_dialog_manager.h"
#include "cef/libcef/browser/menu_manager.h" #include "cef/libcef/browser/menu_manager.h"
#include "cef/libcef/browser/request_context_impl.h" #include "cef/libcef/browser/request_context_impl.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
@ -363,9 +362,6 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase,
// on the UI thread. // on the UI thread.
bool window_destroyed_ = false; bool window_destroyed_ = false;
// Used for creating and managing JavaScript dialogs.
std::unique_ptr<CefJavaScriptDialogManager> javascript_dialog_manager_;
// Used for creating and managing context menus. // Used for creating and managing context menus.
std::unique_ptr<CefMenuManager> menu_manager_; std::unique_ptr<CefMenuManager> menu_manager_;

View File

@ -287,6 +287,10 @@ void CefBrowserHostBase::DestroyWebContents(
devtools_protocol_manager_.reset(); devtools_protocol_manager_.reset();
devtools_window_runner_.reset(); devtools_window_runner_.reset();
context_menu_observer_ = nullptr; context_menu_observer_ = nullptr;
if (javascript_dialog_manager_) {
javascript_dialog_manager_->Destroy();
javascript_dialog_manager_.reset();
}
browser_info_->WebContentsDestroyed(); browser_info_->WebContentsDestroyed();
platform_delegate_->WebContentsDestroyed(web_contents); platform_delegate_->WebContentsDestroyed(web_contents);
@ -1283,6 +1287,15 @@ void CefBrowserHostBase::SelectFileListenerDestroyed(
} }
} }
content::JavaScriptDialogManager*
CefBrowserHostBase::GetJavaScriptDialogManager() {
if (!javascript_dialog_manager_) {
javascript_dialog_manager_ =
std::make_unique<CefJavaScriptDialogManager>(this);
}
return javascript_dialog_manager_.get();
}
bool CefBrowserHostBase::MaybeAllowNavigation( bool CefBrowserHostBase::MaybeAllowNavigation(
content::RenderFrameHost* opener, content::RenderFrameHost* opener,
const content::OpenURLParams& params) { const content::OpenURLParams& params) {

View File

@ -20,6 +20,7 @@
#include "cef/libcef/browser/devtools/devtools_window_runner.h" #include "cef/libcef/browser/devtools/devtools_window_runner.h"
#include "cef/libcef/browser/file_dialog_manager.h" #include "cef/libcef/browser/file_dialog_manager.h"
#include "cef/libcef/browser/frame_host_impl.h" #include "cef/libcef/browser/frame_host_impl.h"
#include "cef/libcef/browser/javascript_dialog_manager.h"
#include "cef/libcef/browser/media_stream_registrar.h" #include "cef/libcef/browser/media_stream_registrar.h"
#include "cef/libcef/browser/request_context_impl.h" #include "cef/libcef/browser/request_context_impl.h"
#include "cef/libcef/features/features.h" #include "cef/libcef/features/features.h"
@ -357,6 +358,10 @@ class CefBrowserHostBase : public CefBrowserHost,
void* params); void* params);
void SelectFileListenerDestroyed(ui::SelectFileDialog::Listener* listener); void SelectFileListenerDestroyed(ui::SelectFileDialog::Listener* listener);
// Called from AlloyBrowserHostImpl::GetJavaScriptDialogManager and
// ChromeBrowserDelegate::GetJavaScriptDialogManager.
content::JavaScriptDialogManager* GetJavaScriptDialogManager();
// Called from CefBrowserInfoManager::MaybeAllowNavigation. // Called from CefBrowserInfoManager::MaybeAllowNavigation.
virtual bool MaybeAllowNavigation(content::RenderFrameHost* opener, virtual bool MaybeAllowNavigation(content::RenderFrameHost* opener,
const content::OpenURLParams& params); const content::OpenURLParams& params);
@ -471,6 +476,9 @@ class CefBrowserHostBase : public CefBrowserHost,
// Used for creating and managing file dialogs. // Used for creating and managing file dialogs.
std::unique_ptr<CefFileDialogManager> file_dialog_manager_; std::unique_ptr<CefFileDialogManager> file_dialog_manager_;
// Used for creating and managing JavaScript dialogs.
std::unique_ptr<CefJavaScriptDialogManager> javascript_dialog_manager_;
// Volatile state accessed from multiple threads. All access must be protected // Volatile state accessed from multiple threads. All access must be protected
// by |state_lock_|. // by |state_lock_|.
base::Lock state_lock_; base::Lock state_lock_;

View File

@ -619,6 +619,16 @@ void ChromeBrowserDelegate::CanDownload(
std::move(callback).Run(true); std::move(callback).Run(true);
} }
content::JavaScriptDialogManager*
ChromeBrowserDelegate::GetJavaScriptDialogManager(
content::WebContents* source) {
auto browser_host = ChromeBrowserHostImpl::GetBrowserForContents(source);
if (browser_host) {
return browser_host->GetJavaScriptDialogManager();
}
return nullptr;
}
KeyboardEventProcessingResult ChromeBrowserDelegate::PreHandleKeyboardEvent( KeyboardEventProcessingResult ChromeBrowserDelegate::PreHandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) { const content::NativeWebKeyboardEvent& event) {

View File

@ -118,6 +118,8 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
void CanDownload(const GURL& url, void CanDownload(const GURL& url,
const std::string& request_method, const std::string& request_method,
base::OnceCallback<void(bool)> callback) override; base::OnceCallback<void(bool)> callback) override;
content::JavaScriptDialogManager* GetJavaScriptDialogManager(
content::WebContents* source) override;
content::KeyboardEventProcessingResult PreHandleKeyboardEvent( content::KeyboardEventProcessingResult PreHandleKeyboardEvent(
content::WebContents* source, content::WebContents* source,
const content::NativeWebKeyboardEvent& event) override; const content::NativeWebKeyboardEvent& event) override;

View File

@ -182,13 +182,6 @@ void CefJavaScriptDialogManager::RunBeforeUnloadDialog(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
bool is_reload, bool is_reload,
DialogClosedCallback callback) { DialogClosedCallback callback) {
if (browser_->WillBeDestroyed()) {
// Currently destroying the browser. Accept the unload without showing
// the prompt.
std::move(callback).Run(true, std::u16string());
return;
}
const std::u16string& message_text = u"Is it OK to leave/reload this page?"; const std::u16string& message_text = u"Is it OK to leave/reload this page?";
// Always call DialogClosed(). // Always call DialogClosed().

View File

@ -131,7 +131,7 @@ index 6ca4ed42a601d..feec87943fee4 100644
] ]
} }
diff --git chrome/browser/ui/browser.cc chrome/browser/ui/browser.cc diff --git chrome/browser/ui/browser.cc chrome/browser/ui/browser.cc
index a1d50c2e47056..5519a1c7714d5 100644 index a1d50c2e47056..e85ee7027bd19 100644
--- chrome/browser/ui/browser.cc --- chrome/browser/ui/browser.cc
+++ chrome/browser/ui/browser.cc +++ chrome/browser/ui/browser.cc
@@ -269,6 +269,25 @@ @@ -269,6 +269,25 @@
@ -341,7 +341,23 @@ index a1d50c2e47056..5519a1c7714d5 100644
RenderWidgetHostView* view = render_widget_host->GetView(); RenderWidgetHostView* view = render_widget_host->GetView();
if (view && !render_widget_host->GetView()->IsHTMLFormPopup()) { if (view && !render_widget_host->GetView()->IsHTMLFormPopup()) {
TabDialogs::FromWebContents(source)->HideHungRendererDialog( TabDialogs::FromWebContents(source)->HideHungRendererDialog(
@@ -2089,6 +2195,11 @@ void Browser::DraggableRegionsChanged( @@ -2045,6 +2151,15 @@ void Browser::RendererResponsive(
content::JavaScriptDialogManager* Browser::GetJavaScriptDialogManager(
WebContents* source) {
+#if BUILDFLAG(ENABLE_CEF)
+ if (cef_browser_delegate_) {
+ auto* cef_js_dialog_manager =
+ cef_browser_delegate_->GetJavaScriptDialogManager(source);
+ if (cef_js_dialog_manager) {
+ return cef_js_dialog_manager;
+ }
+ }
+#endif
return javascript_dialogs::TabModalDialogManager::FromWebContents(source);
}
@@ -2089,6 +2204,11 @@ void Browser::DraggableRegionsChanged(
if (app_controller_) { if (app_controller_) {
app_controller_->DraggableRegionsChanged(regions, contents); app_controller_->DraggableRegionsChanged(regions, contents);
} }
@ -353,7 +369,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
} }
void Browser::DidFinishNavigation( void Browser::DidFinishNavigation(
@@ -2169,11 +2280,15 @@ void Browser::EnterFullscreenModeForTab( @@ -2169,11 +2289,15 @@ void Browser::EnterFullscreenModeForTab(
const blink::mojom::FullscreenOptions& options) { const blink::mojom::FullscreenOptions& options) {
exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab( exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
requesting_frame, options.display_id); requesting_frame, options.display_id);
@ -369,7 +385,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
} }
bool Browser::IsFullscreenForTabOrPending(const WebContents* web_contents) { bool Browser::IsFullscreenForTabOrPending(const WebContents* web_contents) {
@@ -2373,6 +2488,15 @@ void Browser::RequestMediaAccessPermission( @@ -2373,6 +2497,15 @@ void Browser::RequestMediaAccessPermission(
content::WebContents* web_contents, content::WebContents* web_contents,
const content::MediaStreamRequest& request, const content::MediaStreamRequest& request,
content::MediaResponseCallback callback) { content::MediaResponseCallback callback) {
@ -385,7 +401,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
const extensions::Extension* extension = const extensions::Extension* extension =
GetExtensionForOrigin(profile_, request.security_origin); GetExtensionForOrigin(profile_, request.security_origin);
MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
@@ -2917,9 +3041,11 @@ void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { @@ -2917,9 +3050,11 @@ void Browser::RemoveScheduledUpdatesFor(WebContents* contents) {
// Browser, Getters for UI (private): // Browser, Getters for UI (private):
StatusBubble* Browser::GetStatusBubble() { StatusBubble* Browser::GetStatusBubble() {
@ -398,7 +414,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
} }
// We hide the status bar for web apps windows as this matches native // We hide the status bar for web apps windows as this matches native
@@ -2927,6 +3053,12 @@ StatusBubble* Browser::GetStatusBubble() { @@ -2927,6 +3062,12 @@ StatusBubble* Browser::GetStatusBubble() {
// mode, as the minimal browser UI includes the status bar. // mode, as the minimal browser UI includes the status bar.
if (web_app::AppBrowserController::IsWebApp(this) && if (web_app::AppBrowserController::IsWebApp(this) &&
!app_controller()->HasMinimalUiButtons()) { !app_controller()->HasMinimalUiButtons()) {
@ -411,7 +427,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
return nullptr; return nullptr;
} }
@@ -3076,6 +3208,8 @@ void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) { @@ -3076,6 +3217,8 @@ void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) {
BookmarkTabHelper::FromWebContents(web_contents)->RemoveObserver(this); BookmarkTabHelper::FromWebContents(web_contents)->RemoveObserver(this);
web_contents_collection_.StopObserving(web_contents); web_contents_collection_.StopObserving(web_contents);
} }
@ -420,7 +436,7 @@ index a1d50c2e47056..5519a1c7714d5 100644
} }
void Browser::TabDetachedAtImpl(content::WebContents* contents, void Browser::TabDetachedAtImpl(content::WebContents* contents,
@@ -3230,6 +3364,14 @@ bool Browser::PictureInPictureBrowserSupportsWindowFeature( @@ -3230,6 +3373,14 @@ bool Browser::PictureInPictureBrowserSupportsWindowFeature(
bool Browser::SupportsWindowFeatureImpl(WindowFeature feature, bool Browser::SupportsWindowFeatureImpl(WindowFeature feature,
bool check_can_support) const { bool check_can_support) const {