| 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/ui/gtk/first_run_dialog.h" | 5 #include "chrome/browser/ui/gtk/first_run_dialog.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 g_value_set_int(&value, y); | 61 g_value_set_int(&value, y); |
| 62 gtk_container_child_set_property(GTK_CONTAINER(container), | 62 gtk_container_child_set_property(GTK_CONTAINER(container), |
| 63 label, "y", &value); | 63 label, "y", &value); |
| 64 g_value_unset(&value); | 64 g_value_unset(&value); |
| 65 } | 65 } |
| 66 | 66 |
| 67 } // namespace | 67 } // namespace |
| 68 | 68 |
| 69 namespace first_run { | 69 namespace first_run { |
| 70 | 70 |
| 71 void ShowFirstRunDialog(Profile* profile) { | 71 bool ShowFirstRunDialog(Profile* profile) { |
| 72 FirstRunDialog::Show(); | 72 return FirstRunDialog::Show(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace first_run | 75 } // namespace first_run |
| 76 | 76 |
| 77 // static | 77 // static |
| 78 bool FirstRunDialog::Show() { | 78 bool FirstRunDialog::Show() { |
| 79 #if !defined(GOOGLE_CHROME_BUILD) | 79 bool dialog_shown = false; |
| 80 return true; // Nothing to do | 80 #if defined(GOOGLE_CHROME_BUILD) |
| 81 #else | |
| 82 // If the metrics reporting is managed, we won't ask. | 81 // If the metrics reporting is managed, we won't ask. |
| 83 const PrefService::Preference* metrics_reporting_pref = | 82 const PrefService::Preference* metrics_reporting_pref = |
| 84 g_browser_process->local_state()->FindPreference( | 83 g_browser_process->local_state()->FindPreference( |
| 85 prefs::kMetricsReportingEnabled); | 84 prefs::kMetricsReportingEnabled); |
| 86 bool show_reporting_dialog = !metrics_reporting_pref || | 85 bool show_reporting_dialog = !metrics_reporting_pref || |
| 87 !metrics_reporting_pref->IsManaged(); | 86 !metrics_reporting_pref->IsManaged(); |
| 88 | 87 |
| 89 if (!show_reporting_dialog) | 88 if (show_reporting_dialog) { |
| 90 return true; // Nothing to do | 89 // Object deletes itself. |
| 90 new FirstRunDialog(); |
| 91 dialog_shown = true; |
| 91 | 92 |
| 92 int response = -1; | 93 // TODO(port): it should be sufficient to just run the dialog: |
| 93 // Object deletes itself. | 94 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); |
| 94 new FirstRunDialog(show_reporting_dialog, &response); | 95 // but that spins a nested message loop and hoses us. :( |
| 95 | 96 // http://code.google.com/p/chromium/issues/detail?id=12552 |
| 96 // TODO(port): it should be sufficient to just run the dialog: | 97 // Instead, run a loop directly here. |
| 97 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); | 98 MessageLoop::current()->Run(); |
| 98 // but that spins a nested message loop and hoses us. :( | 99 } |
| 99 // http://code.google.com/p/chromium/issues/detail?id=12552 | |
| 100 // Instead, run a loop and extract the response manually. | |
| 101 MessageLoop::current()->Run(); | |
| 102 | |
| 103 return (response == GTK_RESPONSE_ACCEPT); | |
| 104 #endif // defined(GOOGLE_CHROME_BUILD) | 100 #endif // defined(GOOGLE_CHROME_BUILD) |
| 101 return dialog_shown; |
| 105 } | 102 } |
| 106 | 103 |
| 107 FirstRunDialog::FirstRunDialog(bool show_reporting_dialog, int* response) | 104 FirstRunDialog::FirstRunDialog() |
| 108 : dialog_(NULL), | 105 : dialog_(NULL), |
| 109 report_crashes_(NULL), | 106 report_crashes_(NULL), |
| 110 make_default_(NULL), | 107 make_default_(NULL) { |
| 111 show_reporting_dialog_(show_reporting_dialog), | |
| 112 response_(response) { | |
| 113 ShowReportingDialog(); | 108 ShowReportingDialog(); |
| 114 } | 109 } |
| 115 | 110 |
| 116 FirstRunDialog::~FirstRunDialog() { | 111 FirstRunDialog::~FirstRunDialog() { |
| 117 } | 112 } |
| 118 | 113 |
| 119 void FirstRunDialog::ShowReportingDialog() { | 114 void FirstRunDialog::ShowReportingDialog() { |
| 120 // The purpose of the dialog is to ask the user to enable stats and crash | |
| 121 // reporting. This setting may be controlled through configuration management | |
| 122 // in enterprise scenarios. If that is the case, skip the dialog entirely, | |
| 123 // it's not worth bothering the user for only the default browser question | |
| 124 // (which is likely to be forced in enterprise deployments anyway). | |
| 125 if (!show_reporting_dialog_) { | |
| 126 OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); | |
| 127 return; | |
| 128 } | |
| 129 | |
| 130 dialog_ = gtk_dialog_new_with_buttons( | 115 dialog_ = gtk_dialog_new_with_buttons( |
| 131 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), | 116 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), |
| 132 NULL, // No parent | 117 NULL, // No parent |
| 133 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 118 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 134 NULL); | 119 NULL); |
| 135 gtk_util::AddButtonToDialog(dialog_, | 120 gtk_util::AddButtonToDialog(dialog_, |
| 136 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), | 121 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), |
| 137 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 122 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
| 138 gtk_window_set_deletable(GTK_WINDOW(dialog_), FALSE); | 123 gtk_window_set_deletable(GTK_WINDOW(dialog_), FALSE); |
| 139 | 124 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 170 gtk_box_pack_start(GTK_BOX(content_area), learn_more_vbox, FALSE, FALSE, 0); | 155 gtk_box_pack_start(GTK_BOX(content_area), learn_more_vbox, FALSE, FALSE, 0); |
| 171 | 156 |
| 172 g_signal_connect(dialog_, "response", | 157 g_signal_connect(dialog_, "response", |
| 173 G_CALLBACK(OnResponseDialogThunk), this); | 158 G_CALLBACK(OnResponseDialogThunk), this); |
| 174 gtk_widget_show_all(dialog_); | 159 gtk_widget_show_all(dialog_); |
| 175 } | 160 } |
| 176 | 161 |
| 177 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { | 162 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { |
| 178 if (dialog_) | 163 if (dialog_) |
| 179 gtk_widget_hide_all(dialog_); | 164 gtk_widget_hide_all(dialog_); |
| 180 *response_ = response; | |
| 181 | 165 |
| 182 // Mark that first run has ran. | 166 // Mark that first run has ran. |
| 183 first_run::CreateSentinel(); | 167 first_run::CreateSentinel(); |
| 184 | 168 |
| 185 // Check if user has opted into reporting. | 169 // Check if user has opted into reporting. |
| 186 if (report_crashes_ && | 170 if (report_crashes_ && |
| 187 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { | 171 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { |
| 188 #if defined(USE_LINUX_BREAKPAD) | 172 #if defined(USE_LINUX_BREAKPAD) |
| 189 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) | 173 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) |
| 190 InitCrashReporter(); | 174 InitCrashReporter(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 207 } | 191 } |
| 208 | 192 |
| 209 void FirstRunDialog::FirstRunDone() { | 193 void FirstRunDialog::FirstRunDone() { |
| 210 first_run::SetShouldShowWelcomePage(); | 194 first_run::SetShouldShowWelcomePage(); |
| 211 | 195 |
| 212 if (dialog_) | 196 if (dialog_) |
| 213 gtk_widget_destroy(dialog_); | 197 gtk_widget_destroy(dialog_); |
| 214 MessageLoop::current()->Quit(); | 198 MessageLoop::current()->Quit(); |
| 215 delete this; | 199 delete this; |
| 216 } | 200 } |
| OLD | NEW |