Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: chrome_frame/turndown_prompt/turndown_prompt_window.cc

Issue 17153006: Chrome Frame turndown prompt. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 #include "chrome_frame/turndown_prompt/turndown_prompt_window.h"
6
7 #include <atlctrls.h>
8 #include <commctrl.h>
9 #include <shellapi.h>
10
11 #include "base/compiler_specific.h"
12 #include "chrome_frame/ready_mode/internal/url_launcher.h"
13 #include "chrome_frame/simple_resource_loader.h"
14 #include "grit/chrome_frame_dialogs.h"
15 #include "grit/chromium_strings.h"
16
17 // atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts
18 // with STL headers. Hence we include them out of the order defined by style
19 // guidelines. As a result you may not refer to std::min or std::max in this
20 // file.
21 #include <minmax.h> // NOLINT
22 #include <atlctrlx.h> // NOLINT
23
24 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance(
25 InfobarContent::Frame* frame,
26 UrlLauncher* url_launcher,
27 const base::Closure& uninstall_callback) {
28 DCHECK(frame != NULL);
29 DCHECK(url_launcher != NULL);
30
31 base::WeakPtr<TurndownPromptWindow> instance(
32 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback))
33 ->weak_ptr_factory_.GetWeakPtr());
34
35 DCHECK(!instance->IsWindow());
36
37 if (instance->Create(frame->GetFrameWindow()) == NULL) {
38 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow.";
39 return base::WeakPtr<TurndownPromptWindow>();
40 }
41
42 // Subclass the "Learn more." text to make it behave like a link. Clicks are
43 // routed to OnLearnMore().
44 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK);
45 instance->link_.reset(new CHyperLink());
46 instance->link_->SubclassWindow(rte);
47 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON,
48 HLINK_NOTIFYBUTTON);
49
50 return instance;
51 }
52
53 TurndownPromptWindow::TurndownPromptWindow(
54 InfobarContent::Frame* frame,
55 UrlLauncher* url_launcher,
56 const base::Closure& uninstall_closure)
57 : frame_(frame),
58 url_launcher_(url_launcher),
59 uninstall_closure_(uninstall_closure),
60 weak_ptr_factory_(this) {
61 // Use the theme of a tooltip to make the infobar pop.
62 CThemeImpl::SetThemeClassList(L"Tooltip");
63 }
64
65 TurndownPromptWindow::~TurndownPromptWindow() {}
66
67 void TurndownPromptWindow::OnFinalMessage(HWND) {
68 delete this;
69 }
70
71 HBRUSH TurndownPromptWindow::OnCtlColorDlg(HDC device_context, HWND window) {
72 return brush_;
73 }
74
75 void TurndownPromptWindow::OnDestroy() {
76 frame_ = NULL;
77 brush_.Close();
78 }
79
80 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) {
81 // Ordinarily this would happen in OnCreate, but that isn't sent for a dialog.
82 if (!OpenThemeData())
83 DLOG(INFO) << "No theme data for class " << m_lpstrThemeClassList;
84 DlgResize_Init(false); // false => 'no gripper'
85 return TRUE;
86 }
87
88 void TurndownPromptWindow::OnThemeChanged() {
89 brush_.Close();
90 }
91
92 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/,
93 LPNMHDR /*lParam*/,
94 BOOL& /*bHandled*/) {
95 url_launcher_->LaunchUrl(SimpleResourceLoader::Get(
96 IDS_CHROME_FRAME_TURNDOWN_LEARN_MORE_URL));
97 return 0;
98 }
99
100 LRESULT TurndownPromptWindow::OnDismiss(WORD /*wNotifyCode*/,
101 WORD /*wID*/,
102 HWND /*hWndCtl*/,
103 BOOL& /*bHandled*/) {
104 frame_->CloseInfobar();
105 return 0;
106 }
107
108 LRESULT TurndownPromptWindow::OnUninstall(WORD /*wNotifyCode*/,
109 WORD /*wID*/,
110 HWND /*hWndCtl*/,
111 BOOL& /*bHandled*/) {
112 frame_->CloseInfobar();
113 if (!uninstall_closure_.is_null())
114 uninstall_closure_.Run();
115 return 0;
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698