File: supervised_user_verification_page_youtube.cc

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (128 lines) | stat: -rw-r--r-- 4,778 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
// Copyright 2024 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/supervised_user/supervised_user_verification_page_youtube.h"

#include <utility>

#include "base/metrics/histogram_functions.h"
#include "components/grit/components_resources.h"
#include "components/security_interstitials/content/security_interstitial_controller_client.h"
#include "components/security_interstitials/core/common_string_util.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "ui/base/l10n/l10n_util.h"

namespace {
constexpr char kSubframeYoutubeReauthenticationInterstitiaHistogramName[] =
    "FamilyLinkUser.SubframeYoutubeReauthenticationInterstitial";

void RecordUkmForMainFrame(SupervisedUserVerificationPage::Status status,
                           ukm::SourceId source_id) {
  auto builder =
      ukm::builders::FamilyLinkUser_ReauthenticationInterstitial(source_id);
  switch (status) {
    case SupervisedUserVerificationPage::Status::SHOWN:
      builder.SetInterstitialShown(true);
      break;
    case SupervisedUserVerificationPage::Status::REAUTH_STARTED:
      builder.SetReauthenticationStarted(true);
      break;
    case SupervisedUserVerificationPage::Status::REAUTH_COMPLETED:
      builder.SetReauthenticationCompleted(true);
      break;
    default:
      NOTREACHED();
  }
  builder.Record(ukm::UkmRecorder::Get());
}

void RecordUmaForSubFrame(SupervisedUserVerificationPage::Status status) {
  base::UmaHistogramEnumeration(
      kSubframeYoutubeReauthenticationInterstitiaHistogramName,
      SupervisedUserVerificationPage::
          GetReauthenticationInterstitialStateFromStatus(status));
}
}  // namespace

// static
const security_interstitials::SecurityInterstitialPage::TypeID
    SupervisedUserVerificationPageForYouTube::kTypeForTesting =
        &SupervisedUserVerificationPageForYouTube::kTypeForTesting;

SupervisedUserVerificationPageForYouTube::
    SupervisedUserVerificationPageForYouTube(
        content::WebContents* web_contents,
        const std::string& email_to_reauth,
        const GURL& request_url,
        supervised_user::ChildAccountService* child_account_service,
        ukm::SourceId source_id,
        std::unique_ptr<
            security_interstitials::SecurityInterstitialControllerClient>
            controller_client,
        bool is_main_frame)
    : SupervisedUserVerificationPage(web_contents,
                                     email_to_reauth,
                                     request_url,
                                     child_account_service,
                                     std::move(controller_client)),
      source_id_(source_id),
      is_main_frame_(is_main_frame) {
  // Demo interstitials are created without `child_account_service` and should
  // not have metrics recorded.
  if (child_account_service) {
    RecordReauthStatusMetrics(Status::SHOWN);
  }
}

SupervisedUserVerificationPageForYouTube::
    ~SupervisedUserVerificationPageForYouTube() {
  if (IsReauthCompleted()) {
    RecordReauthStatusMetrics(Status::REAUTH_COMPLETED);
  }
}

security_interstitials::SecurityInterstitialPage::TypeID
SupervisedUserVerificationPageForYouTube::GetTypeForTesting() {
  return SupervisedUserVerificationPageForYouTube::kTypeForTesting;
}

void SupervisedUserVerificationPageForYouTube::PopulateInterstitialStrings(
    base::Value::Dict& load_time_data) {
  if (is_main_frame_) {
    load_time_data.Set("type", "SUPERVISED_USER_VERIFY");
  } else {
    load_time_data.Set("type", "SUPERVISED_USER_VERIFY_SUBFRAME");
  }

  PopulateCommonStrings(load_time_data);

  load_time_data.Set(
      "tabTitle",
      l10n_util::GetStringUTF16(IDS_SUPERVISED_USER_VERIFY_PAGE_TAB_TITLE));
  load_time_data.Set(
      "heading",
      is_main_frame_
          ? l10n_util::GetStringUTF16(
                IDS_SUPERVISED_USER_VERIFY_PAGE_PRIMARY_HEADING)
          : l10n_util::GetStringUTF16(
                IDS_SUPERVISED_USER_VERIFY_PAGE_SUBFRAME_YOUTUBE_HEADING));
  load_time_data.Set("primaryParagraph",
                     l10n_util::GetStringUTF16(
                         IDS_SUPERVISED_USER_VERIFY_PAGE_PRIMARY_PARAGRAPH));
  load_time_data.Set("primaryButtonText",
                     l10n_util::GetStringUTF16(
                         IDS_SUPERVISED_USER_VERIFY_PAGE_PRIMARY_BUTTON));
}

void SupervisedUserVerificationPageForYouTube::RecordReauthStatusMetrics(
    Status status) {
  if (is_main_frame_) {
    RecordUkmForMainFrame(status, source_id_);
  } else {
    RecordUmaForSubFrame(status);
  }
}