1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_SHELL_BROWSER_SHELL_JAVASCRIPT_DIALOG_MANAGER_H_ 6 #define CONTENT_SHELL_BROWSER_SHELL_JAVASCRIPT_DIALOG_MANAGER_H_ 7 8 #include <memory> 9 10 #include "base/callback.h" 11 #include "base/compiler_specific.h" 12 #include "base/macros.h" 13 #include "build/build_config.h" 14 #include "content/public/browser/javascript_dialog_manager.h" 15 16 namespace content { 17 18 class ShellJavaScriptDialog; 19 20 class ShellJavaScriptDialogManager : public JavaScriptDialogManager { 21 public: 22 ShellJavaScriptDialogManager(); 23 ~ShellJavaScriptDialogManager() override; 24 25 // JavaScriptDialogManager: 26 void RunJavaScriptDialog(WebContents* web_contents, 27 RenderFrameHost* render_frame_host, 28 JavaScriptDialogType dialog_type, 29 const base::string16& message_text, 30 const base::string16& default_prompt_text, 31 DialogClosedCallback callback, 32 bool* did_suppress_message) override; 33 34 void RunBeforeUnloadDialog(WebContents* web_contents, 35 RenderFrameHost* render_frame_host, 36 bool is_reload, 37 DialogClosedCallback callback) override; 38 39 void CancelDialogs(WebContents* web_contents, 40 bool reset_state) override; 41 42 // Called by the ShellJavaScriptDialog when it closes. 43 void DialogClosed(ShellJavaScriptDialog* dialog); 44 45 // Used for content_browsertests. set_dialog_request_callback(base::OnceClosure callback)46 void set_dialog_request_callback(base::OnceClosure callback) { 47 dialog_request_callback_ = std::move(callback); 48 } set_should_proceed_on_beforeunload(bool proceed,bool success)49 void set_should_proceed_on_beforeunload(bool proceed, bool success) { 50 should_proceed_on_beforeunload_ = proceed; 51 beforeunload_success_ = success; 52 } 53 54 private: 55 #if defined(OS_MAC) || defined(OS_WIN) 56 // The dialog being shown. No queueing. 57 std::unique_ptr<ShellJavaScriptDialog> dialog_; 58 #else 59 // TODO: implement ShellJavaScriptDialog for other platforms, drop this #if 60 #endif 61 62 base::OnceClosure dialog_request_callback_; 63 64 // Whether to automatically proceed when asked to display a BeforeUnload 65 // dialog, and the return value that should be passed (success or failure). 66 bool should_proceed_on_beforeunload_; 67 bool beforeunload_success_; 68 69 DialogClosedCallback before_unload_callback_; 70 71 DISALLOW_COPY_AND_ASSIGN(ShellJavaScriptDialogManager); 72 }; 73 74 } // namespace content 75 76 #endif // CONTENT_SHELL_BROWSER_SHELL_JAVASCRIPT_DIALOG_MANAGER_H_ 77