OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/gtk/first_run_dialog.h" | |
6 | |
7 #include <string> | |
8 #include <vector> | |
9 | |
10 #include "base/i18n/rtl.h" | |
11 #include "base/message_loop/message_loop.h" | |
12 #include "base/strings/utf_string_conversions.h" | |
13 #include "chrome/browser/first_run/first_run_dialog.h" | |
14 #include "chrome/browser/platform_util.h" | |
15 #include "chrome/browser/process_singleton.h" | |
16 #include "chrome/browser/shell_integration.h" | |
17 #include "chrome/browser/ui/gtk/gtk_chrome_link_button.h" | |
18 #include "chrome/browser/ui/gtk/gtk_util.h" | |
19 #include "chrome/common/pref_names.h" | |
20 #include "chrome/common/url_constants.h" | |
21 #include "chrome/installer/util/google_update_settings.h" | |
22 #include "components/breakpad/app/breakpad_linux.h" | |
23 #include "grit/chromium_strings.h" | |
24 #include "grit/generated_resources.h" | |
25 #include "grit/locale_settings.h" | |
26 #include "grit/theme_resources.h" | |
27 #include "ui/base/gtk/gtk_floating_container.h" | |
28 #include "ui/base/gtk/gtk_hig_constants.h" | |
29 #include "ui/base/l10n/l10n_util.h" | |
30 #include "ui/base/resource/resource_bundle.h" | |
31 | |
32 #if defined(GOOGLE_CHROME_BUILD) | |
33 #include "base/prefs/pref_service.h" | |
34 #include "chrome/browser/browser_process.h" | |
35 #endif | |
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 #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 || | |
54 !metrics_reporting_pref->IsManaged(); | |
55 | |
56 if (show_reporting_dialog) { | |
57 // Object deletes itself. | |
58 new FirstRunDialog(profile); | |
59 dialog_shown = true; | |
60 | |
61 // TODO(port): it should be sufficient to just run the dialog: | |
62 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
63 // but that spins a nested message loop and hoses us. :( | |
64 // http://code.google.com/p/chromium/issues/detail?id=12552 | |
65 // Instead, run a loop directly here. | |
66 base::MessageLoop::current()->Run(); | |
67 } | |
68 #endif // defined(GOOGLE_CHROME_BUILD) | |
69 return dialog_shown; | |
70 } | |
71 | |
72 FirstRunDialog::FirstRunDialog(Profile* profile) | |
73 : profile_(profile), | |
74 dialog_(NULL), | |
75 report_crashes_(NULL), | |
76 make_default_(NULL) { | |
77 ShowReportingDialog(); | |
78 } | |
79 | |
80 FirstRunDialog::~FirstRunDialog() { | |
81 } | |
82 | |
83 void FirstRunDialog::ShowReportingDialog() { | |
84 dialog_ = gtk_dialog_new_with_buttons( | |
85 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), | |
86 NULL, // No parent | |
87 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | |
88 NULL); | |
89 gtk_util::AddButtonToDialog(dialog_, | |
90 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), | |
91 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | |
92 gtk_window_set_deletable(GTK_WINDOW(dialog_), FALSE); | |
93 | |
94 gtk_window_set_resizable(GTK_WINDOW(dialog_), FALSE); | |
95 | |
96 g_signal_connect(dialog_, "delete-event", | |
97 G_CALLBACK(gtk_widget_hide_on_delete), NULL); | |
98 | |
99 GtkWidget* content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog_)); | |
100 | |
101 make_default_ = gtk_check_button_new_with_label( | |
102 l10n_util::GetStringUTF8(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER).c_str()); | |
103 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(make_default_), TRUE); | |
104 gtk_box_pack_start(GTK_BOX(content_area), make_default_, FALSE, FALSE, 0); | |
105 | |
106 report_crashes_ = gtk_check_button_new(); | |
107 GtkWidget* check_label = gtk_label_new( | |
108 l10n_util::GetStringUTF8(IDS_OPTIONS_ENABLE_LOGGING).c_str()); | |
109 gtk_label_set_line_wrap(GTK_LABEL(check_label), TRUE); | |
110 gtk_container_add(GTK_CONTAINER(report_crashes_), check_label); | |
111 GtkWidget* learn_more_vbox = gtk_vbox_new(FALSE, 0); | |
112 gtk_box_pack_start(GTK_BOX(learn_more_vbox), report_crashes_, | |
113 FALSE, FALSE, 0); | |
114 | |
115 GtkWidget* learn_more_link = gtk_chrome_link_button_new( | |
116 l10n_util::GetStringUTF8(IDS_LEARN_MORE).c_str()); | |
117 gtk_button_set_alignment(GTK_BUTTON(learn_more_link), 0.0, 0.5); | |
118 gtk_box_pack_start(GTK_BOX(learn_more_vbox), | |
119 gtk_util::IndentWidget(learn_more_link), | |
120 FALSE, FALSE, 0); | |
121 g_signal_connect(learn_more_link, "clicked", | |
122 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); | |
123 | |
124 gtk_box_pack_start(GTK_BOX(content_area), learn_more_vbox, FALSE, FALSE, 0); | |
125 | |
126 g_signal_connect(dialog_, "response", | |
127 G_CALLBACK(OnResponseDialogThunk), this); | |
128 gtk_widget_show_all(dialog_); | |
129 } | |
130 | |
131 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { | |
132 if (dialog_) | |
133 gtk_widget_hide_all(dialog_); | |
134 | |
135 // Check if user has opted into reporting. | |
136 if (report_crashes_ && | |
137 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { | |
138 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) | |
139 breakpad::InitCrashReporter(std::string()); | |
140 } else { | |
141 GoogleUpdateSettings::SetCollectStatsConsent(false); | |
142 } | |
143 | |
144 // If selected set as default browser. | |
145 if (make_default_ && | |
146 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(make_default_))) { | |
147 ShellIntegration::SetAsDefaultBrowser(); | |
148 } | |
149 | |
150 FirstRunDone(); | |
151 } | |
152 | |
153 void FirstRunDialog::OnLearnMoreLinkClicked(GtkButton* button) { | |
154 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL)); | |
155 } | |
156 | |
157 void FirstRunDialog::FirstRunDone() { | |
158 first_run::SetShouldShowWelcomePage(); | |
159 | |
160 if (dialog_) | |
161 gtk_widget_destroy(dialog_); | |
162 base::MessageLoop::current()->Quit(); | |
163 delete this; | |
164 } | |
OLD | NEW |