OLD | NEW |
---|---|
(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 "chrome_frame/utils.h" | |
15 #include "grit/chrome_frame_dialogs.h" | |
16 #include "grit/chromium_strings.h" | |
17 | |
18 // atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts | |
19 // with STL headers. Hence we include them out of the order defined by style | |
20 // guidelines. As a result you may not refer to std::min or std::max in this | |
21 // file. | |
22 #include <minmax.h> // NOLINT | |
23 #include <atlctrlx.h> // NOLINT | |
24 | |
25 base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( | |
26 InfobarContent::Frame* frame, | |
27 UrlLauncher* url_launcher, | |
28 const base::Closure& uninstall_callback) { | |
29 DCHECK(frame != NULL); | |
30 DCHECK(url_launcher != NULL); | |
31 | |
32 base::WeakPtr<TurndownPromptWindow> instance( | |
33 (new TurndownPromptWindow(frame, url_launcher, uninstall_callback)) | |
34 ->weak_ptr_factory_.GetWeakPtr()); | |
35 | |
36 DCHECK(!instance->IsWindow()); | |
37 | |
38 if (instance->Create(frame->GetFrameWindow()) == NULL) { | |
39 DPLOG(ERROR) << "Failed to create HWND for TurndownPromptWindow."; | |
40 return base::WeakPtr<TurndownPromptWindow>(); | |
41 } | |
42 | |
43 // Subclass the "Learn more." text to make it behave like a link. Clicks are | |
44 // routed to OnLearnMore(). | |
45 CWindow rte = instance->GetDlgItem(IDC_TD_PROMPT_LINK); | |
46 instance->link_.reset(new CHyperLink()); | |
47 instance->link_->SubclassWindow(rte); | |
48 instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, | |
49 HLINK_NOTIFYBUTTON); | |
50 | |
51 // Substitue the proper text given the current IE version. | |
robertshield
2013/06/20 21:45:10
Substitute
grt (UTC plus 2)
2013/06/21 19:25:57
Done.
| |
52 CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); | |
53 string16 prompt_text(GetPromptText()); | |
54 if (!prompt_text.empty()) | |
55 text.SetWindowText(prompt_text.c_str()); | |
56 | |
57 return instance; | |
58 } | |
59 | |
60 TurndownPromptWindow::TurndownPromptWindow( | |
61 InfobarContent::Frame* frame, | |
62 UrlLauncher* url_launcher, | |
63 const base::Closure& uninstall_closure) | |
64 : frame_(frame), | |
65 url_launcher_(url_launcher), | |
66 uninstall_closure_(uninstall_closure), | |
67 weak_ptr_factory_(this) { | |
68 } | |
69 | |
70 TurndownPromptWindow::~TurndownPromptWindow() {} | |
71 | |
72 void TurndownPromptWindow::OnFinalMessage(HWND) { | |
73 delete this; | |
74 } | |
75 | |
76 void TurndownPromptWindow::OnDestroy() { | |
77 frame_ = NULL; | |
78 } | |
79 | |
80 BOOL TurndownPromptWindow::OnInitDialog(CWindow wndFocus, LPARAM lInitParam) { | |
81 DlgResize_Init(false); // false => 'no gripper' | |
82 return TRUE; | |
83 } | |
84 | |
85 LRESULT TurndownPromptWindow::OnLearnMore(WORD /*wParam*/, | |
86 LPNMHDR /*lParam*/, | |
87 BOOL& /*bHandled*/) { | |
88 url_launcher_->LaunchUrl(SimpleResourceLoader::Get( | |
89 IDS_CHROME_FRAME_TURNDOWN_LEARN_MORE_URL)); | |
90 return 0; | |
91 } | |
92 | |
93 LRESULT TurndownPromptWindow::OnUninstall(WORD /*wNotifyCode*/, | |
94 WORD /*wID*/, | |
95 HWND /*hWndCtl*/, | |
96 BOOL& /*bHandled*/) { | |
97 frame_->CloseInfobar(); | |
98 if (!uninstall_closure_.is_null()) | |
99 uninstall_closure_.Run(); | |
100 return 0; | |
101 } | |
102 | |
103 LRESULT TurndownPromptWindow::OnDismiss(WORD /*wNotifyCode*/, | |
104 WORD /*wID*/, | |
105 HWND /*hWndCtl*/, | |
106 BOOL& /*bHandled*/) { | |
107 frame_->CloseInfobar(); | |
108 return 0; | |
109 } | |
110 | |
111 // static | |
112 string16 TurndownPromptWindow::GetPromptText() { | |
113 IEVersion ie_version = GetIEVersion(); | |
114 int message_id = 0; | |
115 switch (ie_version) { | |
116 case IE_6: | |
117 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_6; | |
118 break; | |
119 case IE_7: | |
120 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_7; | |
121 break; | |
122 case IE_8: | |
123 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_8; | |
124 break; | |
125 case IE_9: | |
126 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_9; | |
127 break; | |
128 case IE_10: | |
129 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_IE_10; | |
130 break; | |
131 default: // IE_INVALID or IE_UNSUPPORTED | |
132 message_id = IDS_CHROME_FRAME_TURNDOWN_TEXT_UNKNOWN; | |
133 break; | |
134 } | |
135 return SimpleResourceLoader::GetInstance()->Get(message_id); | |
136 } | |
OLD | NEW |