File: supervised_user_interstitial.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 (151 lines) | stat: -rw-r--r-- 5,959 bytes parent folder | download | duplicates (3)
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
140
141
142
143
144
145
146
147
148
149
150
151
// 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 "components/supervised_user/core/browser/supervised_user_interstitial.h"

#include <stddef.h>

#include <memory>
#include <string>

#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/prefs/pref_service.h"
#include "components/supervised_user/core/browser/supervised_user_error_page.h"
#include "components/supervised_user/core/browser/supervised_user_service.h"
#include "components/supervised_user/core/browser/supervised_user_utils.h"
#include "components/supervised_user/core/browser/web_content_handler.h"
#include "components/supervised_user/core/common/features.h"
#include "components/supervised_user/core/common/pref_names.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"

namespace supervised_user {

// static
std::unique_ptr<SupervisedUserInterstitial> SupervisedUserInterstitial::Create(
    std::unique_ptr<WebContentHandler> web_content_handler,
    SupervisedUserService& supervised_user_service,
    const GURL& url,
    const std::u16string& supervised_user_name,
    FilteringBehaviorReason reason) {
  std::unique_ptr<SupervisedUserInterstitial> interstitial =
      base::WrapUnique(new SupervisedUserInterstitial(
          std::move(web_content_handler), supervised_user_service, url,
          supervised_user_name, reason));

  interstitial->web_content_handler()->CleanUpInfoBarOnMainFrame();
  // Caller is responsible for deleting the interstitial.
  return interstitial;
}

SupervisedUserInterstitial::SupervisedUserInterstitial(
    std::unique_ptr<WebContentHandler> web_content_handler,
    SupervisedUserService& supervised_user_service,
    const GURL& url,
    const std::u16string& supervised_user_name,
    FilteringBehaviorReason reason)
    : supervised_user_service_(supervised_user_service),
      web_content_handler_(std::move(web_content_handler)),
      url_(url),
      supervised_user_name_(supervised_user_name),
      filtering_behavior_reason_(reason) {
  CHECK(supervised_user_service.GetURLFilter());
  url_formatter_ = std::make_unique<UrlFormatter>(
      *supervised_user_service.GetURLFilter(), reason);
}

SupervisedUserInterstitial::~SupervisedUserInterstitial() {
  web_content_handler_->MaybeCloseLocalApproval();
}

#if BUILDFLAG(IS_ANDROID)
// static
std::string SupervisedUserInterstitial::GetHTMLContentsWithoutApprovals(
    const GURL& url,
    const std::string& application_locale) {
  return BuildErrorPageHtmlWithoutApprovals(url, application_locale);
}
#endif  // BUILDFLAG(IS_ANDROID)

// static
std::string SupervisedUserInterstitial::GetHTMLContentsWithApprovals(
    SupervisedUserService* supervised_user_service,
    PrefService* pref_service,
    FilteringBehaviorReason reason,
    bool already_sent_request,
    bool is_main_frame,
    const std::string& application_locale,
    std::optional<float> ios_font_size_multiplier) {
  bool allow_access_requests =
      supervised_user_service->remote_web_approvals_manager()
          .AreApprovalRequestsEnabled();
  return BuildErrorPageHtmlWithApprovals(
      allow_access_requests, supervised_user_service->GetCustodian(),
      supervised_user_service->GetSecondCustodian(), reason, application_locale,
      already_sent_request, is_main_frame, ios_font_size_multiplier);
}

void SupervisedUserInterstitial::GoBack() {
  web_content_handler_->GoBack();
  UMA_HISTOGRAM_ENUMERATION(kInterstitialCommandHistogramName, Commands::BACK,
                            Commands::HISTOGRAM_BOUNDING_VALUE);
}

void SupervisedUserInterstitial::RequestUrlAccessRemote(
    base::OnceCallback<void(bool)> callback) {
  UMA_HISTOGRAM_ENUMERATION(kInterstitialCommandHistogramName,
                            Commands::REMOTE_ACCESS_REQUEST,
                            Commands::HISTOGRAM_BOUNDING_VALUE);
  OutputRequestPermissionSourceMetric();

  supervised_user_service_->remote_web_approvals_manager().RequestApproval(
      url_, *url_formatter_.get(), std::move(callback));
}

void SupervisedUserInterstitial::RequestUrlAccessLocal(
    base::OnceCallback<void(bool)> callback) {
  UMA_HISTOGRAM_ENUMERATION(kInterstitialCommandHistogramName,
                            Commands::LOCAL_ACCESS_REQUEST,
                            Commands::HISTOGRAM_BOUNDING_VALUE);
  OutputRequestPermissionSourceMetric();

  DLOG_IF(WARNING, supervised_user_name_.empty())
      << "Supervised user name for local web approval request should not be "
         "empty";
  web_content_handler_->RequestLocalApproval(
      url_, supervised_user_name_, *url_formatter_.get(),
      filtering_behavior_reason_, std::move(callback));
}

#if BUILDFLAG(IS_ANDROID)
void SupervisedUserInterstitial::LearnMore(base::OnceClosure open_help_page) {
  web_content_handler_->LearnMore(std::move(open_help_page));
  UMA_HISTOGRAM_ENUMERATION(kInterstitialCommandHistogramName,
                            Commands::LEARN_MORE,
                            Commands::HISTOGRAM_BOUNDING_VALUE);
}
#endif  // BUILDFLAG(IS_ANDROID)

void SupervisedUserInterstitial::OutputRequestPermissionSourceMetric() {
  RequestPermissionSource source;
  if (web_content_handler_->IsMainFrame()) {
    source = RequestPermissionSource::MAIN_FRAME;
  } else {
    source = RequestPermissionSource::SUB_FRAME;
  }

  UMA_HISTOGRAM_ENUMERATION(kInterstitialPermissionSourceHistogramName, source,
                            RequestPermissionSource::HISTOGRAM_BOUNDING_VALUE);
}
}  // namespace supervised_user