| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/gtk/first_run_dialog.h" | 5 #include "chrome/browser/gtk/first_run_dialog.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 gtk_container_child_set_property(GTK_CONTAINER(container), | 79 gtk_container_child_set_property(GTK_CONTAINER(container), |
| 80 label, "y", &value); | 80 label, "y", &value); |
| 81 g_value_unset(&value); | 81 g_value_unset(&value); |
| 82 } | 82 } |
| 83 | 83 |
| 84 } // namespace | 84 } // namespace |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 bool FirstRunDialog::Show(Profile* profile, | 87 bool FirstRunDialog::Show(Profile* profile, |
| 88 bool randomize_search_engine_order) { | 88 bool randomize_search_engine_order) { |
| 89 // Figure out which dialogs we will show. |
| 90 // If the default search is managed via policy, we won't ask. |
| 91 const TemplateURLModel* search_engines_model = profile->GetTemplateURLModel(); |
| 92 bool show_search_engines_dialog = search_engines_model && |
| 93 !search_engines_model->is_default_search_managed(); |
| 94 |
| 95 #if defined(GOOGLE_CHROME_BUILD) |
| 96 // If the metrics reporting is managed, we won't ask. |
| 97 const PrefService::Preference* metrics_reporting_pref = |
| 98 g_browser_process->local_state()->FindPreference( |
| 99 prefs::kMetricsReportingEnabled); |
| 100 bool show_reporting_dialog = !metrics_reporting_pref || |
| 101 !metrics_reporting_pref->IsManaged(); |
| 102 #else |
| 103 bool show_reporting_dialog = false; |
| 104 #endif |
| 105 |
| 106 if (!show_search_engines_dialog && !show_reporting_dialog) |
| 107 return true; // Nothing to do |
| 108 |
| 89 int response = -1; | 109 int response = -1; |
| 90 // Object deletes itself. | 110 // Object deletes itself. |
| 91 new FirstRunDialog(profile, randomize_search_engine_order, response); | 111 new FirstRunDialog(profile, |
| 112 show_reporting_dialog, |
| 113 show_search_engines_dialog, |
| 114 &response); |
| 92 | 115 |
| 93 // TODO(port): it should be sufficient to just run the dialog: | 116 // TODO(port): it should be sufficient to just run the dialog: |
| 94 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); | 117 // int response = gtk_dialog_run(GTK_DIALOG(dialog)); |
| 95 // but that spins a nested message loop and hoses us. :( | 118 // but that spins a nested message loop and hoses us. :( |
| 96 // http://code.google.com/p/chromium/issues/detail?id=12552 | 119 // http://code.google.com/p/chromium/issues/detail?id=12552 |
| 97 // Instead, run a loop and extract the response manually. | 120 // Instead, run a loop and extract the response manually. |
| 98 MessageLoop::current()->Run(); | 121 MessageLoop::current()->Run(); |
| 99 | 122 |
| 100 return (response == GTK_RESPONSE_ACCEPT); | 123 return (response == GTK_RESPONSE_ACCEPT); |
| 101 } | 124 } |
| 102 | 125 |
| 103 FirstRunDialog::FirstRunDialog(Profile* profile, | 126 FirstRunDialog::FirstRunDialog(Profile* profile, |
| 104 bool randomize_search_engine_order, | 127 bool show_reporting_dialog, |
| 105 int& response) | 128 bool show_search_engines_dialog, |
| 129 int* response) |
| 106 : search_engine_window_(NULL), | 130 : search_engine_window_(NULL), |
| 107 dialog_(NULL), | 131 dialog_(NULL), |
| 108 report_crashes_(NULL), | 132 report_crashes_(NULL), |
| 109 make_default_(NULL), | 133 make_default_(NULL), |
| 110 profile_(profile), | 134 profile_(profile), |
| 111 chosen_search_engine_(NULL), | 135 chosen_search_engine_(NULL), |
| 136 show_reporting_dialog_(show_reporting_dialog), |
| 112 response_(response) { | 137 response_(response) { |
| 138 if (!show_search_engines_dialog) { |
| 139 ShowReportingDialog(); |
| 140 return; |
| 141 } |
| 113 search_engines_model_ = profile_->GetTemplateURLModel(); | 142 search_engines_model_ = profile_->GetTemplateURLModel(); |
| 143 |
| 114 ShowSearchEngineWindow(); | 144 ShowSearchEngineWindow(); |
| 115 | 145 |
| 116 search_engines_model_->AddObserver(this); | 146 search_engines_model_->AddObserver(this); |
| 117 if (search_engines_model_->loaded()) | 147 if (search_engines_model_->loaded()) |
| 118 OnTemplateURLModelChanged(); | 148 OnTemplateURLModelChanged(); |
| 119 else | 149 else |
| 120 search_engines_model_->Load(); | 150 search_engines_model_->Load(); |
| 121 } | 151 } |
| 122 | 152 |
| 123 FirstRunDialog::~FirstRunDialog() { | 153 FirstRunDialog::~FirstRunDialog() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 gtk_box_pack_start(GTK_BOX(bubble_area_box), search_engine_hbox_, | 214 gtk_box_pack_start(GTK_BOX(bubble_area_box), search_engine_hbox_, |
| 185 FALSE, FALSE, 0); | 215 FALSE, FALSE, 0); |
| 186 | 216 |
| 187 gtk_box_pack_start(GTK_BOX(content_area), bubble_area_background, | 217 gtk_box_pack_start(GTK_BOX(content_area), bubble_area_background, |
| 188 TRUE, TRUE, 0); | 218 TRUE, TRUE, 0); |
| 189 | 219 |
| 190 gtk_widget_show_all(content_area); | 220 gtk_widget_show_all(content_area); |
| 191 gtk_window_present(GTK_WINDOW(search_engine_window_)); | 221 gtk_window_present(GTK_WINDOW(search_engine_window_)); |
| 192 } | 222 } |
| 193 | 223 |
| 194 void FirstRunDialog::ShowDialog() { | 224 void FirstRunDialog::ShowReportingDialog() { |
| 195 // The purpose of the dialog is to ask the user to enable stats and crash | 225 // The purpose of the dialog is to ask the user to enable stats and crash |
| 196 // reporting. This setting may be controlled through configuration management | 226 // reporting. This setting may be controlled through configuration management |
| 197 // in enterprise scenarios. If that is the case, skip the dialog entirely, | 227 // in enterprise scenarios. If that is the case, skip the dialog entirely, |
| 198 // it's not worth bothering the user for only the default browser question | 228 // it's not worth bothering the user for only the default browser question |
| 199 // (which is likely to be forced in enterprise deployments anyway). | 229 // (which is likely to be forced in enterprise deployments anyway). |
| 200 const PrefService::Preference* metrics_reporting_pref = | 230 if (!show_reporting_dialog_) { |
| 201 g_browser_process->local_state()->FindPreference( | |
| 202 prefs::kMetricsReportingEnabled); | |
| 203 if (metrics_reporting_pref && metrics_reporting_pref->IsManaged()) { | |
| 204 OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); | 231 OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); |
| 205 return; | 232 return; |
| 206 } | 233 } |
| 207 | 234 |
| 208 #if defined(GOOGLE_CHROME_BUILD) | |
| 209 dialog_ = gtk_dialog_new_with_buttons( | 235 dialog_ = gtk_dialog_new_with_buttons( |
| 210 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), | 236 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_TITLE).c_str(), |
| 211 NULL, // No parent | 237 NULL, // No parent |
| 212 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), | 238 (GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR), |
| 213 NULL); | 239 NULL); |
| 214 gtk_util::AddButtonToDialog(dialog_, | 240 gtk_util::AddButtonToDialog(dialog_, |
| 215 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), | 241 l10n_util::GetStringUTF8(IDS_FIRSTRUN_DLG_OK).c_str(), |
| 216 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); | 242 GTK_STOCK_APPLY, GTK_RESPONSE_ACCEPT); |
| 217 gtk_window_set_deletable(GTK_WINDOW(dialog_), FALSE); | 243 gtk_window_set_deletable(GTK_WINDOW(dialog_), FALSE); |
| 218 | 244 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 244 gtk_util::IndentWidget(learn_more_link), | 270 gtk_util::IndentWidget(learn_more_link), |
| 245 FALSE, FALSE, 0); | 271 FALSE, FALSE, 0); |
| 246 g_signal_connect(learn_more_link, "clicked", | 272 g_signal_connect(learn_more_link, "clicked", |
| 247 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); | 273 G_CALLBACK(OnLearnMoreLinkClickedThunk), this); |
| 248 | 274 |
| 249 gtk_box_pack_start(GTK_BOX(content_area), learn_more_vbox, FALSE, FALSE, 0); | 275 gtk_box_pack_start(GTK_BOX(content_area), learn_more_vbox, FALSE, FALSE, 0); |
| 250 | 276 |
| 251 g_signal_connect(dialog_, "response", | 277 g_signal_connect(dialog_, "response", |
| 252 G_CALLBACK(OnResponseDialogThunk), this); | 278 G_CALLBACK(OnResponseDialogThunk), this); |
| 253 gtk_widget_show_all(dialog_); | 279 gtk_widget_show_all(dialog_); |
| 254 #else // !defined(GOOGLE_CHROME_BUILD) | |
| 255 // We don't show the dialog in chromium. Pretend the user accepted. | |
| 256 OnResponseDialog(NULL, GTK_RESPONSE_ACCEPT); | |
| 257 #endif // !defined(GOOGLE_CHROME_BUILD) | |
| 258 } | 280 } |
| 259 | 281 |
| 260 void FirstRunDialog::OnTemplateURLModelChanged() { | 282 void FirstRunDialog::OnTemplateURLModelChanged() { |
| 261 // We only watch the search engine model change once, on load. Remove | 283 // We only watch the search engine model change once, on load. Remove |
| 262 // observer so we don't try to redraw if engines change under us. | 284 // observer so we don't try to redraw if engines change under us. |
| 263 search_engines_model_->RemoveObserver(this); | 285 search_engines_model_->RemoveObserver(this); |
| 264 | 286 |
| 265 // Add search engines in |search_engines_model_| to buttons list. | 287 // Add search engines in |search_engines_model_| to buttons list. |
| 266 std::vector<const TemplateURL*> ballot_engines = | 288 std::vector<const TemplateURL*> ballot_engines = |
| 267 search_engines_model_->GetTemplateURLs(); | 289 search_engines_model_->GetTemplateURLs(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 void FirstRunDialog::OnSearchEngineButtonClicked(GtkWidget* sender) { | 363 void FirstRunDialog::OnSearchEngineButtonClicked(GtkWidget* sender) { |
| 342 chosen_search_engine_ = static_cast<TemplateURL*>( | 364 chosen_search_engine_ = static_cast<TemplateURL*>( |
| 343 g_object_get_data(G_OBJECT(sender), kSearchEngineKey)); | 365 g_object_get_data(G_OBJECT(sender), kSearchEngineKey)); |
| 344 gtk_widget_destroy(search_engine_window_); | 366 gtk_widget_destroy(search_engine_window_); |
| 345 } | 367 } |
| 346 | 368 |
| 347 void FirstRunDialog::OnSearchEngineWindowDestroy(GtkWidget* sender) { | 369 void FirstRunDialog::OnSearchEngineWindowDestroy(GtkWidget* sender) { |
| 348 search_engine_window_ = NULL; | 370 search_engine_window_ = NULL; |
| 349 if (chosen_search_engine_) { | 371 if (chosen_search_engine_) { |
| 350 search_engines_model_->SetDefaultSearchProvider(chosen_search_engine_); | 372 search_engines_model_->SetDefaultSearchProvider(chosen_search_engine_); |
| 351 ShowDialog(); | 373 ShowReportingDialog(); |
| 352 } else { | 374 } else { |
| 353 FirstRunDone(); | 375 FirstRunDone(); |
| 354 } | 376 } |
| 355 } | 377 } |
| 356 | 378 |
| 357 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { | 379 void FirstRunDialog::OnResponseDialog(GtkWidget* widget, int response) { |
| 358 if (dialog_) | 380 if (dialog_) |
| 359 gtk_widget_hide_all(dialog_); | 381 gtk_widget_hide_all(dialog_); |
| 360 response_ = response; | 382 *response_ = response; |
| 361 | 383 |
| 362 // Mark that first run has ran. | 384 // Mark that first run has ran. |
| 363 FirstRun::CreateSentinel(); | 385 FirstRun::CreateSentinel(); |
| 364 | 386 |
| 365 // Check if user has opted into reporting. | 387 // Check if user has opted into reporting. |
| 366 if (report_crashes_ && | 388 if (report_crashes_ && |
| 367 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { | 389 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(report_crashes_))) { |
| 368 #if defined(USE_LINUX_BREAKPAD) | 390 #if defined(USE_LINUX_BREAKPAD) |
| 369 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) | 391 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) |
| 370 InitCrashReporter(); | 392 InitCrashReporter(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 388 } | 410 } |
| 389 | 411 |
| 390 void FirstRunDialog::FirstRunDone() { | 412 void FirstRunDialog::FirstRunDone() { |
| 391 FirstRun::SetShowWelcomePagePref(); | 413 FirstRun::SetShowWelcomePagePref(); |
| 392 | 414 |
| 393 if (dialog_) | 415 if (dialog_) |
| 394 gtk_widget_destroy(dialog_); | 416 gtk_widget_destroy(dialog_); |
| 395 MessageLoop::current()->Quit(); | 417 MessageLoop::current()->Quit(); |
| 396 delete this; | 418 delete this; |
| 397 } | 419 } |
| OLD | NEW |