1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/views/first_run_dialog.h"
#include <string>
#include "base/functional/bind.h"
#include "base/run_loop.h"
#include "build/build_config.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/browser/first_run/first_run_dialog.h"
#include "chrome/browser/headless/headless_mode_util.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/crash/core/app/crashpad.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/link.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"
namespace first_run {
void ShowFirstRunDialog() {
// Don't show first run dialog when running in headless mode since this
// would effectively block the UI because there is no one to interact with
// the dialog.
if (headless::IsHeadlessMode()) {
return;
}
#if BUILDFLAG(IS_MAC)
if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog)) {
ShowFirstRunDialogViews();
} else {
ShowFirstRunDialogCocoa();
}
#else
ShowFirstRunDialogViews();
#endif
}
void ShowFirstRunDialogViews() {
base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
FirstRunDialog::Show(
base::BindRepeating(&platform_util::OpenExternal,
GURL(chrome::kLearnMoreReportingURL)),
run_loop.QuitClosure());
run_loop.Run();
}
} // namespace first_run
// static
void FirstRunDialog::Show(base::RepeatingClosure learn_more_callback,
base::RepeatingClosure quit_runloop) {
FirstRunDialog* dialog = new FirstRunDialog(std::move(learn_more_callback),
std::move(quit_runloop));
views::DialogDelegate::CreateDialogWidget(dialog, gfx::NativeWindow(),
gfx::NativeView())
->Show();
}
FirstRunDialog::FirstRunDialog(base::RepeatingClosure learn_more_callback,
base::RepeatingClosure quit_runloop)
: quit_runloop_(quit_runloop) {
SetTitle(l10n_util::GetStringUTF16(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE));
SetButtons(static_cast<int>(ui::mojom::DialogButton::kOk));
SetExtraView(
std::make_unique<views::Link>(l10n_util::GetStringUTF16(IDS_LEARN_MORE)))
->SetCallback(std::move(learn_more_callback));
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical,
ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
views::DialogContentType::kControl,
views::DialogContentType::kControl),
ChromeLayoutProvider::Get()->GetDistanceMetric(
views::DISTANCE_RELATED_CONTROL_VERTICAL)));
make_default_ = AddChildView(std::make_unique<views::Checkbox>(
l10n_util::GetStringUTF16(IDS_FR_CUSTOMIZE_DEFAULT_BROWSER)));
make_default_->SetChecked(true);
report_crashes_ = AddChildView(std::make_unique<views::Checkbox>(
l10n_util::GetStringUTF16(IDS_FR_ENABLE_LOGGING)));
// Having this box checked means the user has to opt-out of metrics recording.
report_crashes_->SetChecked(true);
}
FirstRunDialog::~FirstRunDialog() = default;
void FirstRunDialog::Done() {
CHECK(!quit_runloop_.is_null());
if (!closed_through_accept_button_) {
ChangeMetricsReportingState(
false, ChangeMetricsReportingStateCalledFrom::kUiFirstRun);
}
quit_runloop_.Run();
}
bool FirstRunDialog::Accept() {
GetWidget()->Hide();
closed_through_accept_button_ = true;
ChangeMetricsReportingState(
report_crashes_->GetChecked(),
ChangeMetricsReportingStateCalledFrom::kUiFirstRun);
if (make_default_->GetChecked()) {
shell_integration::SetAsDefaultBrowser();
}
Done();
return true;
}
void FirstRunDialog::WindowClosing() {
Done();
}
BEGIN_METADATA(FirstRunDialog)
END_METADATA
|