OLD | NEW |
(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/common/pref_names.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 |
| 54 if (!metrics_reporting_pref || |
| 55 !metrics_reporting_pref->IsManaged()) { |
| 56 FirstRunDialog* dialog = new FirstRunDialog(profile); |
| 57 views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show(); |
| 58 |
| 59 // Use the widget's window itself so that the message loop |
| 60 // exists when the dialog is closed by some other means than |
| 61 // |Accept|. |
| 62 // |
| 63 // This is the same trick used in simple_message_box_views.cc, minus the |
| 64 // refcounting. |
| 65 aura::Window* anchor = dialog->GetWidget()->GetNativeWindow(); |
| 66 aura::client::DispatcherClient* client = |
| 67 aura::client::GetDispatcherClient(anchor->GetRootWindow()); |
| 68 client->RunWithDispatcher(dialog, anchor, true); |
| 69 dialog_shown = true; |
| 70 } |
| 71 #endif // defined(GOOGLE_CHROME_BUILD) |
| 72 |
| 73 return dialog_shown; |
| 74 } |
| 75 |
| 76 FirstRunDialog::FirstRunDialog(Profile* profile) |
| 77 : profile_(profile), |
| 78 make_default_(NULL), |
| 79 report_crashes_(NULL), |
| 80 should_show_dialog_(true) { |
| 81 GridLayout* layout = GridLayout::CreatePanel(this); |
| 82 SetLayoutManager(layout); |
| 83 |
| 84 const int related_y = views::kRelatedControlVerticalSpacing; |
| 85 |
| 86 views::ColumnSet* column_set = layout->AddColumnSet(0); |
| 87 column_set->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, |
| 88 GridLayout::USE_PREF, 0, 0); |
| 89 |
| 90 layout->StartRow(0, 0); |
| 91 make_default_ = new views::Checkbox(l10n_util::GetStringUTF16( |
| 92 IDS_FR_CUSTOMIZE_DEFAULT_BROWSER)); |
| 93 make_default_->SetChecked(true); |
| 94 layout->AddView(make_default_); |
| 95 |
| 96 layout->StartRowWithPadding(0, 0, 0, related_y); |
| 97 report_crashes_ = new views::Checkbox(l10n_util::GetStringUTF16( |
| 98 IDS_OPTIONS_ENABLE_LOGGING)); |
| 99 layout->AddView(report_crashes_); |
| 100 } |
| 101 |
| 102 FirstRunDialog::~FirstRunDialog() { |
| 103 } |
| 104 |
| 105 views::View* FirstRunDialog::CreateExtraView() { |
| 106 views::Link* link = new views::Link(l10n_util::GetStringUTF16( |
| 107 IDS_LEARN_MORE)); |
| 108 link->set_listener(this); |
| 109 return link; |
| 110 } |
| 111 |
| 112 void FirstRunDialog::OnClosed() { |
| 113 should_show_dialog_ = false; |
| 114 first_run::SetShouldShowWelcomePage(); |
| 115 } |
| 116 |
| 117 bool FirstRunDialog::Accept() { |
| 118 should_show_dialog_ = false; |
| 119 GetWidget()->Hide(); |
| 120 |
| 121 if (report_crashes_ && report_crashes_->checked()) { |
| 122 if (GoogleUpdateSettings::SetCollectStatsConsent(true)) |
| 123 breakpad::InitCrashReporter(std::string()); |
| 124 } else { |
| 125 GoogleUpdateSettings::SetCollectStatsConsent(false); |
| 126 } |
| 127 |
| 128 if (make_default_ && make_default_->checked()) |
| 129 ShellIntegration::SetAsDefaultBrowser(); |
| 130 |
| 131 return true; |
| 132 } |
| 133 |
| 134 int FirstRunDialog::GetDialogButtons() const { |
| 135 return ui::DIALOG_BUTTON_OK; |
| 136 } |
| 137 |
| 138 void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) { |
| 139 platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL)); |
| 140 } |
| 141 |
| 142 bool FirstRunDialog::Dispatch(const base::NativeEvent& event) { |
| 143 aura::Env::GetInstance()->GetDispatcher()->Dispatch(event); |
| 144 return should_show_dialog_; |
| 145 } |
OLD | NEW |