File: first_run_dialog.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (139 lines) | stat: -rw-r--r-- 4,616 bytes parent folder | download | duplicates (5)
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