1 // Copyright 2014 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 #include "chrome/browser/ui/views/first_run_dialog.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h"
9 #include "chrome/browser/first_run/first_run.h"
10 #include "chrome/browser/platform_util.h"
11 #include "chrome/browser/shell_integration.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/common/url_constants.h"
14 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h"
16 #include "chrome/grit/locale_settings.h"
17 #include "chrome/installer/util/google_update_settings.h"
18 #include "components/crash/app/breakpad_linux.h"
19 #include "grit/components_strings.h"
20 #include "ui/aura/env.h"
21 #include "ui/aura/window.h"
22 #include "ui/aura/window_event_dispatcher.h"
23 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/views/controls/button/checkbox.h"
25 #include "ui/views/controls/link.h"
26 #include "ui/views/layout/grid_layout.h"
27 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/widget/widget.h"
29 #include "ui/views/window/dialog_delegate.h"
31 #if defined(GOOGLE_CHROME_BUILD)
32 #include "base/prefs/pref_service.h"
33 #include "chrome/browser/browser_process.h"
36 using views::GridLayout
;
40 bool ShowFirstRunDialog(Profile
* profile
) {
41 return FirstRunDialog::Show(profile
);
44 } // namespace first_run
47 bool FirstRunDialog::Show(Profile
* profile
) {
48 bool dialog_shown
= false;
50 #if defined(GOOGLE_CHROME_BUILD)
51 // If the metrics reporting is managed, we won't ask.
52 const PrefService::Preference
* metrics_reporting_pref
=
53 g_browser_process
->local_state()->FindPreference(
54 prefs::kMetricsReportingEnabled
);
56 if (!metrics_reporting_pref
||
57 !metrics_reporting_pref
->IsManaged()) {
58 FirstRunDialog
* dialog
= new FirstRunDialog(profile
);
59 views::DialogDelegate::CreateDialogWidget(dialog
, NULL
, NULL
)->Show();
61 base::MessageLoopForUI
* loop
= base::MessageLoopForUI::current();
62 base::MessageLoopForUI::ScopedNestableTaskAllower
allow_nested(loop
);
63 base::RunLoop run_loop
;
64 dialog
->quit_runloop_
= run_loop
.QuitClosure();
68 #endif // defined(GOOGLE_CHROME_BUILD)
73 FirstRunDialog::FirstRunDialog(Profile
* profile
)
76 report_crashes_(NULL
) {
77 GridLayout
* layout
= GridLayout::CreatePanel(this);
78 SetLayoutManager(layout
);
80 const int related_y
= views::kRelatedControlVerticalSpacing
;
82 views::ColumnSet
* column_set
= layout
->AddColumnSet(0);
83 column_set
->AddColumn(GridLayout::FILL
, GridLayout::CENTER
, 0,
84 GridLayout::USE_PREF
, 0, 0);
86 layout
->StartRow(0, 0);
87 make_default_
= new views::Checkbox(l10n_util::GetStringUTF16(
88 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER
));
89 make_default_
->SetChecked(true);
90 layout
->AddView(make_default_
);
92 layout
->StartRowWithPadding(0, 0, 0, related_y
);
93 report_crashes_
= new views::Checkbox(l10n_util::GetStringUTF16(
94 IDS_OPTIONS_ENABLE_LOGGING
));
95 layout
->AddView(report_crashes_
);
98 FirstRunDialog::~FirstRunDialog() {
101 void FirstRunDialog::Done() {
102 CHECK(!quit_runloop_
.is_null());
106 views::View
* FirstRunDialog::CreateExtraView() {
107 views::Link
* link
= new views::Link(l10n_util::GetStringUTF16(
109 link
->set_listener(this);
113 void FirstRunDialog::OnClosed() {
114 first_run::SetShouldShowWelcomePage();
118 bool FirstRunDialog::Accept() {
121 if (report_crashes_
&& report_crashes_
->checked()) {
122 if (GoogleUpdateSettings::SetCollectStatsConsent(true))
123 breakpad::InitCrashReporter(std::string());
125 GoogleUpdateSettings::SetCollectStatsConsent(false);
128 if (make_default_
&& make_default_
->checked())
129 ShellIntegration::SetAsDefaultBrowser();
135 int FirstRunDialog::GetDialogButtons() const {
136 return ui::DIALOG_BUTTON_OK
;
139 void FirstRunDialog::LinkClicked(views::Link
* source
, int event_flags
) {
140 platform_util::OpenExternal(profile_
, GURL(chrome::kLearnMoreReportingURL
));