File: first_run_dialog.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (135 lines) | stat: -rw-r--r-- 4,305 bytes parent folder | download | duplicates (2)
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
// Copyright 2014 The Chromium Authors. All rights reserved.
// 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/bind.h"
#include "base/run_loop.h"
#include "chrome/browser/first_run/first_run.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/views/chrome_layout_provider.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/chromium_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/strings/grit/components_strings.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/link.h"
#include "ui/views/layout/grid_layout.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/dialog_delegate.h"

#if defined(OS_WIN)
#include "components/crash/content/app/breakpad_win.h"
#elif defined(OS_LINUX)
#include "components/crash/content/app/breakpad_linux.h"
#endif

namespace {

void InitCrashReporterIfEnabled(bool enabled) {
  if (enabled)
    breakpad::InitCrashReporter(std::string());
}

}  // namespace

namespace first_run {

void ShowFirstRunDialog(Profile* profile) {
  FirstRunDialog::Show(profile);
}

}  // namespace first_run

// static
void FirstRunDialog::Show(Profile* profile) {
  FirstRunDialog* dialog = new FirstRunDialog(profile);
  views::DialogDelegate::CreateDialogWidget(dialog, NULL, NULL)->Show();

  base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed);
  dialog->quit_runloop_ = run_loop.QuitClosure();
  run_loop.Run();
}

FirstRunDialog::FirstRunDialog(Profile* profile)
    : profile_(profile),
      make_default_(NULL),
      report_crashes_(NULL) {
  set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
      views::TEXT, views::TEXT));
  views::GridLayout* layout =
      SetLayoutManager(std::make_unique<views::GridLayout>(this));

  views::ColumnSet* column_set = layout->AddColumnSet(0);
  column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
                        views::GridLayout::kFixedSize,
                        views::GridLayout::USE_PREF, 0, 0);

  layout->StartRow(views::GridLayout::kFixedSize, 0);
  make_default_ = new views::Checkbox(l10n_util::GetStringUTF16(
      IDS_FR_CUSTOMIZE_DEFAULT_BROWSER));
  make_default_->SetChecked(true);
  layout->AddView(make_default_);

  layout->StartRowWithPadding(views::GridLayout::kFixedSize, 0,
                              views::GridLayout::kFixedSize,
                              ChromeLayoutProvider::Get()->GetDistanceMetric(
                                  views::DISTANCE_RELATED_CONTROL_VERTICAL));
  report_crashes_ = new views::Checkbox(
      l10n_util::GetStringUTF16(IDS_SETTINGS_ENABLE_LOGGING));
  // Having this box checked means the user has to opt-out of metrics recording.
  report_crashes_->SetChecked(!first_run::IsMetricsReportingOptIn());
  layout->AddView(report_crashes_);
  chrome::RecordDialogCreation(chrome::DialogIdentifier::FIRST_RUN_DIALOG);
}

FirstRunDialog::~FirstRunDialog() {
}

void FirstRunDialog::Done() {
  CHECK(!quit_runloop_.is_null());
  quit_runloop_.Run();
}

views::View* FirstRunDialog::CreateExtraView() {
  views::Link* link = new views::Link(l10n_util::GetStringUTF16(
      IDS_LEARN_MORE));
  link->set_listener(this);
  return link;
}

bool FirstRunDialog::Accept() {
  GetWidget()->Hide();

  ChangeMetricsReportingStateWithReply(report_crashes_->checked(),
                                       base::Bind(&InitCrashReporterIfEnabled));

  if (make_default_->checked())
    shell_integration::SetAsDefaultBrowser();

  Done();
  return true;
}

int FirstRunDialog::GetDialogButtons() const {
  return ui::DIALOG_BUTTON_OK;
}

void FirstRunDialog::WindowClosing() {
  first_run::SetShouldShowWelcomePage();
  Done();
}

void FirstRunDialog::LinkClicked(views::Link* source, int event_flags) {
  platform_util::OpenExternal(profile_, GURL(chrome::kLearnMoreReportingURL));
}