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