• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   ~CefJavaScriptDialogManager() override;
26 
27   // Delete the runner to free any platform constructs.
28   void Destroy();
29 
30   // JavaScriptDialogManager methods.
31   void RunJavaScriptDialog(content::WebContents* web_contents,
32                            content::RenderFrameHost* render_frame_host,
33                            content::JavaScriptDialogType message_type,
34                            const std::u16string& message_text,
35                            const std::u16string& default_prompt_text,
36                            DialogClosedCallback callback,
37                            bool* did_suppress_message) override;
38   void RunBeforeUnloadDialog(content::WebContents* web_contents,
39                              content::RenderFrameHost* render_frame_host,
40                              bool is_reload,
41                              DialogClosedCallback callback) override;
42   void CancelDialogs(content::WebContents* web_contents,
43                      bool reset_state) override;
44 
45  private:
46   // Method executed by the callback passed to CefJavaScriptDialogRunner::Run.
47   void DialogClosed(DialogClosedCallback callback,
48                     bool success,
49                     const std::u16string& user_input);
50 
51   // AlloyBrowserHostImpl pointer is guaranteed to outlive this object.
52   AlloyBrowserHostImpl* browser_;
53 
54   std::unique_ptr<CefJavaScriptDialogRunner> runner_;
55 
56   // True if a dialog is currently running.
57   bool dialog_running_;
58 
59   // Must be the last member.
60   base::WeakPtrFactory<CefJavaScriptDialogManager> weak_ptr_factory_;
61 
62   DISALLOW_COPY_AND_ASSIGN(CefJavaScriptDialogManager);
63 };
64 
65 #endif  // CEF_LIBCEF_BROWSER_JAVASCRIPT_DIALOG_MANAGER_H_
66