2012-04-16 23:15:27 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
#ifndef CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
|
2012-04-16 23:15:27 +02:00
|
|
|
#pragma once
|
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
#include <memory>
|
2012-04-16 23:15:27 +02:00
|
|
|
#include <string>
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/cef_jsdialog_handler.h"
|
|
|
|
#include "cef/libcef/browser/javascript_dialog_runner.h"
|
2013-02-23 01:43:28 +01:00
|
|
|
#include "content/public/browser/javascript_dialog_manager.h"
|
2012-04-16 23:15:27 +02:00
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
class CefBrowserHostBase;
|
2012-04-16 23:15:27 +02:00
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
class CefJavaScriptDialogManager : public content::JavaScriptDialogManager {
|
2012-04-16 23:15:27 +02:00
|
|
|
public:
|
2015-11-17 19:20:13 +01:00
|
|
|
// |runner| may be NULL if the platform doesn't implement dialogs.
|
2022-06-02 11:49:50 +02:00
|
|
|
explicit CefJavaScriptDialogManager(CefBrowserHostBase* browser);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefJavaScriptDialogManager(const CefJavaScriptDialogManager&) = delete;
|
|
|
|
CefJavaScriptDialogManager& operator=(const CefJavaScriptDialogManager&) =
|
|
|
|
delete;
|
|
|
|
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefJavaScriptDialogManager() override;
|
2012-04-16 23:15:27 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
// Delete the runner to free any platform constructs.
|
|
|
|
void Destroy();
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
// JavaScriptDialogManager methods.
|
2017-05-17 11:29:28 +02:00
|
|
|
void RunJavaScriptDialog(content::WebContents* web_contents,
|
2018-03-20 21:15:08 +01:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::JavaScriptDialogType message_type,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& message_text,
|
|
|
|
const std::u16string& default_prompt_text,
|
2017-10-20 19:45:20 +02:00
|
|
|
DialogClosedCallback callback,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool* did_suppress_message) override;
|
|
|
|
void RunBeforeUnloadDialog(content::WebContents* web_contents,
|
2017-12-07 22:44:24 +01:00
|
|
|
content::RenderFrameHost* render_frame_host,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool is_reload,
|
2017-10-20 19:45:20 +02:00
|
|
|
DialogClosedCallback callback) override;
|
2022-06-02 11:49:50 +02:00
|
|
|
bool HandleJavaScriptDialog(content::WebContents* web_contents,
|
|
|
|
bool accept,
|
|
|
|
const std::u16string* prompt_override) override;
|
2016-11-23 21:54:29 +01:00
|
|
|
void CancelDialogs(content::WebContents* web_contents,
|
|
|
|
bool reset_state) override;
|
2012-04-16 23:15:27 +02:00
|
|
|
|
|
|
|
private:
|
2015-11-17 19:20:13 +01:00
|
|
|
// Method executed by the callback passed to CefJavaScriptDialogRunner::Run.
|
2017-10-20 19:45:20 +02:00
|
|
|
void DialogClosed(DialogClosedCallback callback,
|
2015-11-17 19:20:13 +01:00
|
|
|
bool success,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& user_input);
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
bool InitializeRunner();
|
2012-04-16 23:15:27 +02:00
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
bool CanUseChromeDialogs() const;
|
|
|
|
|
|
|
|
// CefBrowserHostBase pointer is guaranteed to outlive this object.
|
|
|
|
CefBrowserHostBase* const browser_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2022-06-02 11:49:50 +02:00
|
|
|
CefRefPtr<CefJSDialogHandler> handler_;
|
|
|
|
|
|
|
|
std::unique_ptr<CefJavaScriptDialogRunner> runner_;
|
|
|
|
bool runner_initialized_ = false;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
|
|
|
// Must be the last member.
|
|
|
|
base::WeakPtrFactory<CefJavaScriptDialogManager> weak_ptr_factory_;
|
2012-04-16 23:15:27 +02:00
|
|
|
};
|
|
|
|
|
2013-02-23 01:43:28 +01:00
|
|
|
#endif // CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
|