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

Side by Side Diff: chrome/browser/ui/views/first_run_dialog.cc

Issue 137393008: linux_aura: Port the linux first run dialog to aura. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: msw comments Created 6 years, 11 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 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.
4
5 #include "chrome/browser/ui/views/first_run_dialog.h"
6
7 #include "chrome/browser/first_run/first_run.h"
8 #include "chrome/browser/platform_util.h"
9 #include "chrome/browser/shell_integration.h"
10 #include "chrome/browser/ui/views/constrained_window_views.h"
11 #include "chrome/common/pref_names.h"
12 #include "chrome/common/url_constants.h"
13 #include "chrome/installer/util/google_update_settings.h"
14 #include "components/breakpad/app/breakpad_linux.h"
15 #include "grit/chromium_strings.h"
16 #include "grit/generated_resources.h"
17 #include "grit/locale_settings.h"
18 #include "grit/theme_resources.h"
19 #include "ui/aura/client/dispatcher_client.h"
20 #include "ui/aura/env.h"
21 #include "ui/aura/root_window.h"
22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/views/controls/button/checkbox.h"
24 #include "ui/views/controls/link.h"
25 #include "ui/views/layout/grid_layout.h"
26 #include "ui/views/layout/layout_constants.h"
27 #include "ui/views/widget/widget.h"
28 #include "ui/views/window/dialog_delegate.h"
29
30 #if defined(GOOGLE_CHROME_BUILD)
31 #include "base/prefs/pref_service.h"
32 #include "chrome/browser/browser_process.h"
33 #endif
34
35 using views::GridLayout;
36
37 namespace first_run {
38
39 bool ShowFirstRunDialog(Profile* profile) {
40 return FirstRunDialog::Show(profile);
41 }
42
43 } // namespace first_run
44
45 // static
46 bool FirstRunDialog::Show(Profile* profile) {
47 bool dialog_shown = false;
48
49 #if defined(GOOGLE_CHROME_BUILD)
50 // If the metrics reporting is managed, we won't ask.
51 const PrefService::Preference* metrics_reporting_pref =
52 g_browser_process->local_state()->FindPreference(
53 prefs::kMetricsReportingEnabled);
54
55 if (!metrics_reporting_pref ||
56 !metrics_reporting_pref->IsManaged()) {
57 FirstRunDialog* dialog = new FirstRunDialog(profile);
58 CreateBrowserModalDialogViews(dialog, NULL)->Show();
59
60 // Use the widget's window itself so that the message loop
61 // exists when the dialog is closed by some other means than
62 // |Accept|.
63 //
64 // This is the same trick used in simple_message_box_views.cc, minus the
65 // refcounting.
66 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow();
67 aura::client::DispatcherClient* client =
68 aura::client::GetDispatcherClient(anchor->GetRootWindow());
69 client->RunWithDispatcher(dialog, anchor, true);
70 dialog_shown = true;
71 }
72 #endif // defined(GOOGLE_CHROME_BUILD)
73
74 return dialog_shown;
75 }
76
77 FirstRunDialog::FirstRunDialog(Profile* profile)
78 : profile_(profile),
79 make_default_(NULL),
80 report_crashes_(NULL),
81 should_show_dialog_(true) {
82 GridLayout* layout = GridLayout::CreatePanel(this);
83 SetLayoutManager(layout);
84
85 const int related_y = views::kRelatedControlVerticalSpacing;
86
87 views::ColumnSet* column_set = layout->AddColumnSet(0);
88 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
89 GridLayout::USE_PREF, 0, 0);
90
91 layout->StartRow(0, 0);
92 make_default_ = new views::Checkbox(l10n_util::GetStringUTF16(
93 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER));
94 make_default_->SetChecked(true);
95 layout->AddView(make_default_);
96
97 layout->StartRowWithPadding(0, 0, 0, related_y);
98 report_crashes_ = new views::Checkbox(l10n_util::GetStringUTF16(
99 IDS_OPTIONS_ENABLE_LOGGING));
100 layout->AddView(report_crashes_);
101 }
102
103 FirstRunDialog::~FirstRunDialog() {
104 }
105
106 views::View* FirstRunDialog::CreateExtraView() {
107 views::Link* link = new views::Link(l10n_util::GetStringUTF16(
108 IDS_LEARN_MORE));
109 link->set_listener(this);
110 return link;
111 }
112
113 void FirstRunDialog::OnClosed() {
114 should_show_dialog_ = false;
115 first_run::SetShouldShowWelcomePage();
116 }
117
118 bool FirstRunDialog::Accept() {
119 should_show_dialog_ = false;
120 GetWidget()->Hide();
121
122 if (report_crashes_ && report_crashes_->checked()) {
123 if (GoogleUpdateSettings::SetCollectStatsConsent(true))
124 breakpad::InitCrashReporter(std::string());
125 } else {
126 GoogleUpdateSettings::SetCollectStatsConsent(false);
127 }
128
129 if (make_default_ && make_default_->checked())
130 ShellIntegration::SetAsDefaultBrowser();
131
132 return true;
133 }
134
135 int FirstRunDialog::GetDialogButtons() const {
136 return ui::DIALOG_BUTTON_OK;
137 }
138
139 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) {
140 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL));
141 }
142
143 bool FirstRunDialog::Dispatch(const base::NativeEvent& event) {
144 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event);
145 return should_show_dialog_;
146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698