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.
5 #ifndef CHROME_FRAME_TURNDOWN_PROMPT_TURNDOWN_PROMPT_WINDOW_H_
6 #define CHROME_FRAME_TURNDOWN_PROMPT_TURNDOWN_PROMPT_WINDOW_H_
16 #include "base/debug/debugger.h"
17 #include "base/callback.h"
18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h"
20 #include "base/strings/string16.h"
21 #include "base/win/scoped_comptr.h"
22 #include "base/win/scoped_handle.h"
23 #include "chrome_frame/infobars/infobar_content.h"
24 #include "chrome_frame/resource.h"
25 #include "grit/chrome_frame_dialogs.h"
33 // Implements a dialog with text and buttons notifying the user that Chrome
34 // Frame is being turned down, offering them a link to learn more about moving
35 // to a modern browser.
36 class TurndownPromptWindow
37 : public CDialogImpl<TurndownPromptWindow, CWindow>,
38 public CDialogResize<TurndownPromptWindow>,
39 public CThemeImpl<TurndownPromptWindow> {
41 enum { IDD = IDD_CHROME_FRAME_TURNDOWN_PROMPT };
43 // Creates and initializes a dialog for display in the provided frame. The
44 // UrlLauncher may be used to launch a new tab containing a knowledge-base
45 // article about the turndown.
47 // Upon success, takes ownership of itself (to be deleted upon WM_DESTROY) and
48 // returns a weak pointer to this dialog. Upon failure, returns a null weak
49 // pointer and deletes self.
51 // In either case, takes ownership of the UrlLauncher but not the frame.
52 // |uninstall_closure| is invoked if/when the Uninstall button is activated.
53 static base::WeakPtr<TurndownPromptWindow> CreateInstance(
54 InfobarContent::Frame* frame,
55 UrlLauncher* url_launcher,
56 const base::Closure& uninstall_closure);
58 BEGIN_MSG_MAP(InfobarWindow)
59 CHAIN_MSG_MAP(CThemeImpl<TurndownPromptWindow>)
60 MSG_WM_DESTROY(OnDestroy)
61 MSG_WM_INITDIALOG(OnInitDialog)
62 NOTIFY_HANDLER(IDC_TD_PROMPT_LINK, NM_CLICK, OnLearnMore)
63 COMMAND_HANDLER(IDUNINSTALL, BN_CLICKED, OnUninstall)
64 CHAIN_MSG_MAP(CDialogResize<TurndownPromptWindow>)
67 BEGIN_DLGRESIZE_MAP(InfobarWindow)
68 DLGRESIZE_CONTROL(IDUNINSTALL, DLSZ_CENTER_Y | DLSZ_MOVE_X)
69 DLGRESIZE_CONTROL(IDC_TD_PROMPT_LINK, DLSZ_CENTER_Y | DLSZ_MOVE_X)
70 DLGRESIZE_CONTROL(IDC_TD_PROMPT_MESSAGE, DLSZ_SIZE_Y | DLSZ_SIZE_X)
73 virtual void OnFinalMessage(HWND);
76 // Call CreateInstance() to get an initialized TurndownPromptWindow.
77 TurndownPromptWindow(InfobarContent::Frame* frame,
78 UrlLauncher* url_launcher,
79 const base::Closure& uninstall_closure);
81 // The TurndownPromptWindow manages its own destruction.
82 virtual ~TurndownPromptWindow();
86 BOOL OnInitDialog(CWindow wndFocus, LPARAM lInitParam);
87 LRESULT OnLearnMore(WORD wParam, LPNMHDR lParam, BOOL& bHandled); // NOLINT
88 LRESULT OnUninstall(WORD wNotifyCode,
93 // Returns the prompt text for the current version of IE.
94 static string16 GetPromptText();
96 InfobarContent::Frame* frame_; // Not owned by this instance
97 scoped_ptr<WTL::CHyperLink> link_;
98 scoped_ptr<UrlLauncher> url_launcher_;
99 base::Closure uninstall_closure_;
101 base::WeakPtrFactory<TurndownPromptWindow> weak_ptr_factory_;
102 DISALLOW_COPY_AND_ASSIGN(TurndownPromptWindow);
103 }; // class TurndownPromptWindow
105 #endif // CHROME_FRAME_TURNDOWN_PROMPT_TURNDOWN_PROMPT_WINDOW_H_