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

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: 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/url_constants.h"
12 #include "chrome/installer/util/google_update_settings.h"
13 #include "components/breakpad/app/breakpad_linux.h"
14 #include "grit/chromium_strings.h"
15 #include "grit/generated_resources.h"
16 #include "grit/locale_settings.h"
17 #include "grit/theme_resources.h"
18 #include "ui/aura/client/dispatcher_client.h"
19 #include "ui/aura/env.h"
20 #include "ui/aura/root_window.h"
21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/views/controls/button/checkbox.h"
23 #include "ui/views/controls/link.h"
24 #include "ui/views/layout/grid_layout.h"
25 #include "ui/views/layout/layout_constants.h"
26 #include "ui/views/widget/widget.h"
27 #include "ui/views/window/dialog_delegate.h"
28
29 #if defined(GOOGLE_CHROME_BUILD)
30 #include "base/prefs/pref_service.h"
31 #include "chrome/browser/browser_process.h"
32 #endif
33
34 using views::GridLayout;
35
36 namespace first_run {
37
38 bool ShowFirstRunDialog(Profile* profile) {
39 return FirstRunDialog::Show(profile);
40 }
41
42 } // namespace first_run
43
44 // static
45 bool FirstRunDialog::Show(Profile* profile) {
46 bool dialog_shown = false;
47
48 #if defined(GOOGLE_CHROME_BUILD)
49 // If the metrics reporting is managed, we won't ask.
50 const PrefService::Preference* metrics_reporting_pref =
51 g_browser_process->local_state()->FindPreference(
52 prefs::kMetricsReportingEnabled);
53 bool show_reporting_dialog = !metrics_reporting_pref ||
msw 2014/01/15 20:22:41 nit: this could be inlined
54 !metrics_reporting_pref->IsManaged();
55
56 if (show_reporting_dialog) {
57 FirstRunDialog* dialog = new FirstRunDialog(profile);
58 CreateBrowserModalDialogViews(dialog, NULL)->Show();
msw 2014/01/15 20:22:41 Will this show over an actual running browser wind
Elliot Glaysher 2014/01/15 20:41:31 I previously did that and had some focus issues. I
msw 2014/01/15 20:59:37 Hmm, then doesn't this just equate to DialogDelega
Elliot Glaysher 2014/01/15 22:01:39 Tested again. Worked this time. Done.
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 Init();
83 }
84
85 FirstRunDialog::~FirstRunDialog() {
86 }
87
88 void FirstRunDialog::Init() {
msw 2014/01/15 20:22:41 nit: this could be inlined to the ctor
89 GridLayout* layout = GridLayout::CreatePanel(this);
90 SetLayoutManager(layout);
91
92 const int related_y = views::kRelatedControlVerticalSpacing;
93
94 views::ColumnSet* column_set = layout->AddColumnSet(0);
95 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
96 GridLayout::USE_PREF, 0, 0);
97
98 layout->StartRow(0, 0);
99 make_default_ = new views::Checkbox(l10n_util::GetStringUTF16(
100 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER));
101 make_default_->SetChecked(true);
102 layout->AddView(make_default_);
103
104 layout->StartRowWithPadding(0, 0, 0, related_y);
105 report_crashes_ = new views::Checkbox(l10n_util::GetStringUTF16(
106 IDS_OPTIONS_ENABLE_LOGGING));
107 layout->AddView(report_crashes_);
108
109 // layout->StartRowWithPadding(0, 0, 0, related_y);
msw 2014/01/15 20:22:41 nit: remove commented code.
110 // layout->AddView(link);
111 }
112
113 views::View* FirstRunDialog::CreateExtraView() {
114 views::Link* link = new views::Link(l10n_util::GetStringUTF16(
115 IDS_LEARN_MORE));
116 link->set_listener(this);
117 return link;
118 }
119
120 void FirstRunDialog::OnClosed() {
msw 2014/01/15 20:22:41 Should this also set should_show_dialog_ to false?
121 first_run::SetShouldShowWelcomePage();
122 }
123
124 bool FirstRunDialog::Accept() {
125 should_show_dialog_= false;
msw 2014/01/15 20:22:41 nit: add a space before '='.
126 GetWidget()->Hide();
127
128 if (report_crashes_ && report_crashes_->checked()) {
129 if (GoogleUpdateSettings::SetCollectStatsConsent(true))
130 breakpad::InitCrashReporter(std::string());
131 } else {
132 GoogleUpdateSettings::SetCollectStatsConsent(false);
133 }
134
135 if (make_default_ && make_default_->checked())
136 ShellIntegration::SetAsDefaultBrowser();
137
138 return true;
139 }
140
141 int FirstRunDialog::GetDialogButtons() const {
142 return ui::DIALOG_BUTTON_OK;
143 }
144
145 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) {
146 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL));
147 }
148
149 bool FirstRunDialog::Dispatch(const base::NativeEvent& event) {
150 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event);
151 return should_show_dialog_;
152 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698