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

Side by Side Diff: ui/complete_wnd.cc

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « ui/complete_wnd.h ('k') | ui/progress_wnd.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2007-2009 Google Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 // ========================================================================
15
16
17 #include "omaha/ui/complete_wnd.h"
18 #include "omaha/base/const_addresses.h"
19 #include "omaha/base/debug.h"
20 #include "omaha/base/error.h"
21 #include "omaha/base/logging.h"
22 #include "omaha/base/safe_format.h"
23 #include "omaha/base/omaha_version.h"
24 #include "omaha/base/vistautil.h"
25 #include "omaha/common/goopdate_utils.h"
26 #include "omaha/ui/ui_metrics.h"
27
28 namespace omaha {
29
30 CompleteWnd::CompleteWnd(CMessageLoop* message_loop, HWND parent)
31 : OmahaWnd(IDD_PROGRESS, message_loop, parent),
32 events_sink_(NULL),
33 control_classes_(ICC_STANDARD_CLASSES) {
34 CORE_LOG(L3, (_T("[CompleteWnd::CompleteWnd]")));
35 }
36
37 // dialog_id specifies the dialog resource to use.
38 // control_classes specifies the control classes required for dialog_id.
39 CompleteWnd::CompleteWnd(int dialog_id,
40 DWORD control_classes,
41 CMessageLoop* message_loop,
42 HWND parent)
43 : OmahaWnd(dialog_id, message_loop, parent),
44 events_sink_(NULL),
45 control_classes_(control_classes | ICC_STANDARD_CLASSES) {
46 CORE_LOG(L3, (_T("[CompleteWnd::CompleteWnd]")));
47 }
48
49 HRESULT CompleteWnd::Initialize() {
50 CORE_LOG(L3, (_T("[CompleteWnd::Initialize]")));
51
52 HRESULT hr = InitializeCommonControls(control_classes_);
53 if (FAILED(hr)) {
54 return hr;
55 }
56
57 return OmahaWnd::Initialize();
58 }
59
60 void CompleteWnd::SetEventSink(CompleteWndEvents* ev) {
61 events_sink_ = ev;
62 OmahaWnd::SetEventSink(events_sink_);
63 }
64
65 LRESULT CompleteWnd::OnInitDialog(UINT message,
66 WPARAM w_param,
67 LPARAM l_param,
68 BOOL& handled) { // NOLINT
69 CORE_LOG(L3, (_T("[CompleteWnd::OnInitDialog]")));
70 UNREFERENCED_PARAMETER(message);
71 UNREFERENCED_PARAMETER(w_param);
72 UNREFERENCED_PARAMETER(l_param);
73 handled = true;
74
75 InitializeDialog();
76
77 SetControlAttributes(IDC_COMPLETE_TEXT, kDisabledNonButtonAttributes);
78 SetControlAttributes(IDC_ERROR_TEXT, kDisabledNonButtonAttributes);
79 SetControlAttributes(IDC_IMAGE, kDisabledNonButtonAttributes);
80 SetControlAttributes(IDC_GET_HELP_TEXT, kDisabledNonButtonAttributes);
81 SetControlAttributes(IDC_CLOSE, kDefaultActiveButtonAttributes);
82
83 return 1; // Let the system set the focus.
84 }
85
86 LRESULT CompleteWnd::OnClickedButton(WORD notify_code,
87 WORD id,
88 HWND wnd_ctl,
89 BOOL& handled) { // NOLINT
90 CORE_LOG(L3, (_T("[CompleteWnd::OnClickedButton]")));
91 UNREFERENCED_PARAMETER(id);
92 UNREFERENCED_PARAMETER(notify_code);
93 UNREFERENCED_PARAMETER(wnd_ctl);
94 ASSERT1(id == IDC_CLOSE);
95 ASSERT1(is_complete());
96 handled = true;
97
98 VERIFY1(SUCCEEDED(CloseWindow()));
99
100 return 0;
101 }
102
103 LRESULT CompleteWnd::OnUrlClicked(int, LPNMHDR params, BOOL& handled) { // NOLI NT
104 CORE_LOG(L3, (_T("[CompleteWnd::OnUrlClicked]")));
105 ASSERT1(params);
106
107 if (IDC_GET_HELP_TEXT == params->idFrom) {
108 ++metric_worker_ui_get_help_click;
109 }
110
111 NMSTATICEX* notification = reinterpret_cast<NMSTATICEX*>(params);
112 ASSERT1(events_sink_);
113 if (events_sink_) {
114 bool is_launched = events_sink_->DoLaunchBrowser(notification->action);
115 // Assert that the launch succeeded because this code should not be called
116 // if the launch mechanism (i.e. IProcessLauncher when running elevated) is
117 // not in place. This could also fail if the default browser has been
118 // uninstalled, but that is unlikely.
119 ASSERT1(is_launched);
120 // TODO(omaha): Consider doing something if the browser launch failed.
121 // Could display a message in English saying it failed for some reason,
122 // please CTRL-C this dialog, get the URL and paste it into a browser.
123 }
124
125 handled = true;
126 return 1;
127 }
128
129 bool CompleteWnd::MaybeCloseWindow() {
130 VERIFY1(SUCCEEDED(CloseWindow()));
131 return true;
132 }
133
134 void CompleteWnd::DisplayCompletionDialog(bool is_success,
135 const CString& text,
136 const CString& help_url) {
137 CORE_LOG(L3, (_T("[CompleteWnd::DisplayCompletionDialog]")
138 _T("[success=%d][text=%s]"), is_success, text));
139 ASSERT1(!text.IsEmpty());
140
141 // FormatMessage() converts all LFs to CRLFs, which display as boxes in UI.
142 // We have also observed some BITS error messages with boxes that may have
143 // been caused by CRLFs.
144 // To avoid boxes, convert all CRLFs to LFs, which result in line breaks.
145 CString display_text = text;
146 display_text.Replace(_T("\r\n"), _T("\n"));
147
148 if (!OmahaWnd::OnComplete()) {
149 return;
150 }
151
152 // It is possible for the OnComplete callback to be called multiple times.
153 // Subclassing the control multiple times results in a crash, therefore
154 // unsubclass the control if the control has been created and subclassed
155 // before.
156 if (complete_text_ != NULL) {
157 // TODO(omaha3): I'm not sure this can happen in the polling model.
158 ASSERT1(false);
159
160 complete_text_->UnsubclassWindow(true);
161 complete_text_.reset(NULL);
162 }
163
164 CString s;
165 if (is_success) {
166 VERIFY1(s.LoadString(IDS_CLOSE));
167 VERIFY1(::SetWindowText(GetDlgItem(IDC_CLOSE), s));
168 complete_text_.reset(new StaticEx);
169 complete_text_->SubclassWindow(GetDlgItem(IDC_COMPLETE_TEXT));
170 VERIFY1(::SetWindowText(GetDlgItem(IDC_COMPLETE_TEXT), text));
171 } else {
172 VERIFY1(s.LoadString(IDS_CLOSE));
173 VERIFY1(::SetWindowText(GetDlgItem(IDC_CLOSE), s));
174 complete_text_.reset(new StaticEx);
175 complete_text_->SubclassWindow(GetDlgItem(IDC_ERROR_TEXT));
176 VERIFY1(::SetWindowText(GetDlgItem(IDC_ERROR_TEXT), display_text));
177 VERIFY1(SUCCEEDED(ShowGetHelpLink(help_url)));
178 }
179
180 VERIFY1(SUCCEEDED(SetControlState(is_success)));
181
182 return;
183 }
184
185
186 HRESULT CompleteWnd::SetControlState(bool is_success) {
187 SetControlAttributes(is_success ? IDC_COMPLETE_TEXT : IDC_ERROR_TEXT,
188 kVisibleTextAttributes);
189 if (is_success) {
190 SetControlAttributes(IDC_IMAGE, kVisibleImageAttributes);
191 } else {
192 SetControlAttributes(IDC_GET_HELP_TEXT, kVisibleTextAttributes);
193 }
194 SetControlAttributes(IDC_CLOSE, kDefaultActiveButtonAttributes);
195
196 return S_OK;
197 }
198
199 // If help_url is empty, no link will be displayed.
200 HRESULT CompleteWnd::ShowGetHelpLink(const CString& help_url) {
201 // If there is no event sink, clicking the URL will fail.
202 ASSERT1(events_sink_);
203
204 if (help_url.IsEmpty()) {
205 return S_OK;
206 }
207 ASSERT1(0 == help_url.Find(_T("http://")));
208
209 const TCHAR* const kLinkFormat = _T("<b><a=%s>%s</a></b>");
210 CString display_text;
211 VERIFY1(display_text.LoadString(IDS_GET_HELP_TEXT));
212 CString link_string;
213 SafeCStringFormat(&link_string, kLinkFormat, help_url, display_text);
214
215 get_help_text_.reset(new StaticEx);
216 get_help_text_->SubclassWindow(GetDlgItem(IDC_GET_HELP_TEXT));
217 VERIFY1(::SetWindowText(GetDlgItem(IDC_GET_HELP_TEXT), link_string));
218
219 ++metric_worker_ui_get_help_displayed;
220 return S_OK;
221 }
222
223 } // namespace omaha
224
OLDNEW
« no previous file with comments | « ui/complete_wnd.h ('k') | ui/progress_wnd.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698