OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/first_run/try_chrome_dialog_view.h" | 5 #include "chrome/browser/first_run/try_chrome_dialog_view.h" |
6 | 6 |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "chrome/browser/process_singleton.h" | 12 #include "chrome/browser/process_singleton.h" |
13 #include "chrome/installer/util/browser_distribution.h" | 13 #include "chrome/installer/util/user_experiment.h" |
14 #include "grit/chromium_strings.h" | 14 #include "grit/chromium_strings.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "grit/ui_resources.h" | 17 #include "grit/ui_resources.h" |
18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
21 #include "ui/views/controls/button/checkbox.h" | 21 #include "ui/views/controls/button/checkbox.h" |
22 #include "ui/views/controls/button/image_button.h" | 22 #include "ui/views/controls/button/image_button.h" |
23 #include "ui/views/controls/button/radio_button.h" | 23 #include "ui/views/controls/button/radio_button.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 views::GridLayout::USE_PREF, 0, 0); | 167 views::GridLayout::USE_PREF, 0, 0); |
168 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | 168 columns->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
169 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, | 169 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1, |
170 views::GridLayout::USE_PREF, 0, 0); | 170 views::GridLayout::USE_PREF, 0, 0); |
171 | 171 |
172 // First row. | 172 // First row. |
173 layout->StartRow(0, 0); | 173 layout->StartRow(0, 0); |
174 layout->AddView(icon); | 174 layout->AddView(icon); |
175 | 175 |
176 // Find out what experiment we are conducting. | 176 // Find out what experiment we are conducting. |
177 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 177 installer::ExperimentDetails experiment; |
178 if (!dist) { | 178 if (!installer::CreateExperimentDetails(flavor_, &experiment) || |
grt (UTC plus 2)
2013/03/12 19:36:18
if (!BrowserDistribution::GetDistribution()->HasUs
huangs
2013/03/14 17:20:45
Done.
| |
179 NOTREACHED() << "Cannot determine browser distribution"; | |
180 return DIALOG_ERROR; | |
181 } | |
182 BrowserDistribution::UserExperiment experiment; | |
183 if (!dist->GetExperimentDetails(&experiment, flavor_) || | |
184 !experiment.heading) { | 179 !experiment.heading) { |
185 NOTREACHED() << "Cannot determine which headline to show."; | 180 NOTREACHED() << "Cannot determine which headline to show."; |
186 return DIALOG_ERROR; | 181 return DIALOG_ERROR; |
187 } | 182 } |
188 views::Label* label = new views::Label( | 183 views::Label* label = new views::Label( |
189 l10n_util::GetStringUTF16(experiment.heading)); | 184 l10n_util::GetStringUTF16(experiment.heading)); |
190 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 185 label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
191 label->SetMultiLine(true); | 186 label->SetMultiLine(true); |
192 label->SizeToFit(200); | 187 label->SizeToFit(200); |
193 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 188 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
(...skipping 13 matching lines...) Expand all Loading... | |
207 layout->StartRowWithPadding(0, 1, 0, 10); | 202 layout->StartRowWithPadding(0, 1, 0, 10); |
208 try_chrome_ = new views::RadioButton( | 203 try_chrome_ = new views::RadioButton( |
209 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); | 204 l10n_util::GetStringUTF16(IDS_TRY_TOAST_TRY_OPT), kRadioGroupID); |
210 try_chrome_->SetChecked(true); | 205 try_chrome_->SetChecked(true); |
211 try_chrome_->set_tag(BT_TRY_IT_RADIO); | 206 try_chrome_->set_tag(BT_TRY_IT_RADIO); |
212 try_chrome_->set_listener(this); | 207 try_chrome_->set_listener(this); |
213 layout->AddView(try_chrome_); | 208 layout->AddView(try_chrome_); |
214 | 209 |
215 // Decide if the don't bug me is a button or a radio button. | 210 // Decide if the don't bug me is a button or a radio button. |
216 bool dont_bug_me_button = | 211 bool dont_bug_me_button = |
217 ((experiment.flags & BrowserDistribution::kDontBugMeAsButton) != 0); | 212 !!(experiment.flags & installer::kToastUiDontBugMeAsButton); |
218 | 213 |
219 // Optional third and fourth row. | 214 // Optional third and fourth row. |
220 if (!dont_bug_me_button) { | 215 if (!dont_bug_me_button) { |
221 layout->StartRow(0, 1); | 216 layout->StartRow(0, 1); |
222 dont_try_chrome_ = new views::RadioButton( | 217 dont_try_chrome_ = new views::RadioButton( |
223 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); | 218 l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL), kRadioGroupID); |
224 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); | 219 dont_try_chrome_->set_tag(BT_DONT_BUG_RADIO); |
225 dont_try_chrome_->set_listener(this); | 220 dont_try_chrome_->set_listener(this); |
226 layout->AddView(dont_try_chrome_); | 221 layout->AddView(dont_try_chrome_); |
227 } | 222 } |
228 if (experiment.flags & BrowserDistribution::kUninstall) { | 223 if (experiment.flags & installer::kToastUiUninstall) { |
229 layout->StartRow(0, 2); | 224 layout->StartRow(0, 2); |
230 kill_chrome_ = new views::RadioButton( | 225 kill_chrome_ = new views::RadioButton( |
231 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); | 226 l10n_util::GetStringUTF16(IDS_UNINSTALL_CHROME), kRadioGroupID); |
232 layout->AddView(kill_chrome_); | 227 layout->AddView(kill_chrome_); |
233 } | 228 } |
234 | 229 |
235 views::Button* accept_button = new views::NativeTextButton( | 230 views::Button* accept_button = new views::NativeTextButton( |
236 this, l10n_util::GetStringUTF16(IDS_OK)); | 231 this, l10n_util::GetStringUTF16(IDS_OK)); |
237 accept_button->set_tag(BT_OK_BUTTON); | 232 accept_button->set_tag(BT_OK_BUTTON); |
238 | 233 |
239 views::Separator* separator = NULL; | 234 views::Separator* separator = NULL; |
240 if (experiment.flags & BrowserDistribution::kMakeDefault) { | 235 if (experiment.flags & installer::kToastUiMakeDefault) { |
241 // In this flavor we have some veritical space, then a separator line | 236 // In this flavor we have some veritical space, then a separator line |
242 // and the 'make default' checkbox and the OK button on the same row. | 237 // and the 'make default' checkbox and the OK button on the same row. |
243 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 238 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
244 layout->StartRow(0, 6); | 239 layout->StartRow(0, 6); |
245 separator = new views::Separator; | 240 separator = new views::Separator; |
246 layout->AddView(separator); | 241 layout->AddView(separator); |
247 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 242 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
248 | 243 |
249 layout->StartRow(0, 7); | 244 layout->StartRow(0, 7); |
250 make_default_ = new views::Checkbox( | 245 make_default_ = new views::Checkbox( |
251 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); | 246 l10n_util::GetStringUTF16(IDS_TRY_TOAST_SET_DEFAULT)); |
252 make_default_->SetChecked(true); | 247 make_default_->SetChecked(true); |
253 layout->AddView(make_default_); | 248 layout->AddView(make_default_); |
254 layout->AddView(accept_button); | 249 layout->AddView(accept_button); |
255 } else { | 250 } else { |
256 // On this other flavor there is no checkbox, the OK button and possibly | 251 // On this other flavor there is no checkbox, the OK button and possibly |
257 // the cancel button are in the same row. | 252 // the cancel button are in the same row. |
258 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); | 253 layout->StartRowWithPadding(0, dont_bug_me_button ? 3 : 5, 0, 10); |
259 layout->AddView(accept_button); | 254 layout->AddView(accept_button); |
260 if (dont_bug_me_button) { | 255 if (dont_bug_me_button) { |
261 // The dialog needs a "Don't bug me" as a button or as a radio button, | 256 // The dialog needs a "Don't bug me" as a button or as a radio button, |
262 // this the button case. | 257 // this the button case. |
263 views::Button* cancel_button = new views::NativeTextButton( | 258 views::Button* cancel_button = new views::NativeTextButton( |
264 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); | 259 this, l10n_util::GetStringUTF16(IDS_TRY_TOAST_CANCEL)); |
265 cancel_button->set_tag(BT_CLOSE_BUTTON); | 260 cancel_button->set_tag(BT_CLOSE_BUTTON); |
266 layout->AddView(cancel_button); | 261 layout->AddView(cancel_button); |
267 } | 262 } |
268 } | 263 } |
269 | 264 |
270 if (experiment.flags & BrowserDistribution::kWhyLink) { | 265 if (experiment.flags & installer::kToastUiWhyLink) { |
271 layout->StartRowWithPadding(0, 4, 0, 10); | 266 layout->StartRowWithPadding(0, 4, 0, 10); |
272 views::Link* link = new views::Link( | 267 views::Link* link = new views::Link( |
273 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); | 268 l10n_util::GetStringUTF16(IDS_TRY_TOAST_WHY)); |
274 link->set_listener(this); | 269 link->set_listener(this); |
275 layout->AddView(link); | 270 layout->AddView(link); |
276 } | 271 } |
277 | 272 |
278 // We resize the window according to the layout manager. This takes into | 273 // We resize the window according to the layout manager. This takes into |
279 // account the differences between XP and Vista fonts and buttons. | 274 // account the differences between XP and Vista fonts and buttons. |
280 layout->Layout(root_view); | 275 layout->Layout(root_view); |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 result_ = TRY_CHROME_AS_DEFAULT; | 370 result_ = TRY_CHROME_AS_DEFAULT; |
376 } | 371 } |
377 | 372 |
378 popup_->Close(); | 373 popup_->Close(); |
379 MessageLoop::current()->Quit(); | 374 MessageLoop::current()->Quit(); |
380 } | 375 } |
381 | 376 |
382 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { | 377 void TryChromeDialogView::LinkClicked(views::Link* source, int event_flags) { |
383 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); | 378 ::ShellExecuteW(NULL, L"open", kHelpCenterUrl, NULL, NULL, SW_SHOW); |
384 } | 379 } |
OLD | NEW |