• 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_NATIVE_JAVASCRIPT_DIALOG_RUNNER_WIN_H_
7 #define CEF_LIBCEF_BROWSER_NATIVE_JAVASCRIPT_DIALOG_RUNNER_WIN_H_
8 #pragma once
9 
10 #include <windows.h>
11 
12 #include "libcef/browser/javascript_dialog_runner.h"
13 
14 class CefJavaScriptDialogRunnerWin : public CefJavaScriptDialogRunner {
15  public:
16   CefJavaScriptDialogRunnerWin();
17   ~CefJavaScriptDialogRunnerWin() override;
18 
19   // CefJavaScriptDialogRunner methods:
20   void Run(AlloyBrowserHostImpl* browser,
21            content::JavaScriptDialogType message_type,
22            const std::u16string& display_url,
23            const std::u16string& message_text,
24            const std::u16string& default_prompt_text,
25            DialogClosedCallback callback) override;
26   void Cancel() override;
27 
28  private:
29   void CloseDialog(bool success, const std::wstring& user_input);
30 
31   HWND dialog_win_;
32   HWND parent_win_;
33 
34   content::JavaScriptDialogType message_type_;
35   std::wstring message_text_;
36   std::wstring default_prompt_text_;
37   DialogClosedCallback callback_;
38 
39   bool hook_installed_;
40 
41   static INT_PTR CALLBACK DialogProc(HWND dialog,
42                                      UINT message,
43                                      WPARAM wparam,
44                                      LPARAM lparam);
45 
46   // Since the message loop we expect to run in isn't going to be nicely
47   // calling IsDialogMessage(), we need to hook the wnd proc and call it
48   // ourselves. See http://support.microsoft.com/kb/q187988/
49   static bool InstallMessageHook();
50   static bool UninstallMessageHook();
51   static LRESULT CALLBACK GetMsgProc(int code, WPARAM wparam, LPARAM lparam);
52   static HHOOK msg_hook_;
53   static int msg_hook_user_count_;
54 };
55 
56 #endif  // CEF_LIBCEF_BROWSER_NATIVE_JAVASCRIPT_DIALOG_RUNNER_WIN_H_
57