1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. 2 // Portions copyright (c) 2012 The Chromium Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 6 #ifndef CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_ 7 #define CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_ 8 #pragma once 9 10 #include <string> 11 12 #include "libcef/browser/javascript_dialog_runner.h" 13 14 #include "base/compiler_specific.h" 15 #include "base/memory/weak_ptr.h" 16 #include "content/public/browser/javascript_dialog_manager.h" 17 18 class AlloyBrowserHostImpl; 19 20 class CefJavaScriptDialogManager : public content::JavaScriptDialogManager { 21 public: 22 // |runner| may be NULL if the platform doesn't implement dialogs. 23 CefJavaScriptDialogManager(AlloyBrowserHostImpl* browser, 24 std::unique_ptr<CefJavaScriptDialogRunner> runner); 25 26 CefJavaScriptDialogManager(const CefJavaScriptDialogManager&) = delete; 27 CefJavaScriptDialogManager& operator=(const CefJavaScriptDialogManager&) = 28 delete; 29 30 ~CefJavaScriptDialogManager() override; 31 32 // Delete the runner to free any platform constructs. 33 void Destroy(); 34 35 // JavaScriptDialogManager methods. 36 void RunJavaScriptDialog(content::WebContents* web_contents, 37 content::RenderFrameHost* render_frame_host, 38 content::JavaScriptDialogType message_type, 39 const std::u16string& message_text, 40 const std::u16string& default_prompt_text, 41 DialogClosedCallback callback, 42 bool* did_suppress_message) override; 43 void RunBeforeUnloadDialog(content::WebContents* web_contents, 44 content::RenderFrameHost* render_frame_host, 45 bool is_reload, 46 DialogClosedCallback callback) override; 47 void CancelDialogs(content::WebContents* web_contents, 48 bool reset_state) override; 49 50 private: 51 // Method executed by the callback passed to CefJavaScriptDialogRunner::Run. 52 void DialogClosed(DialogClosedCallback callback, 53 bool success, 54 const std::u16string& user_input); 55 56 // AlloyBrowserHostImpl pointer is guaranteed to outlive this object. 57 AlloyBrowserHostImpl* browser_; 58 59 std::unique_ptr<CefJavaScriptDialogRunner> runner_; 60 61 // True if a dialog is currently running. 62 bool dialog_running_; 63 64 // Must be the last member. 65 base::WeakPtrFactory<CefJavaScriptDialogManager> weak_ptr_factory_; 66 }; 67 68 #endif // CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_ 69