File: desktop_entrypoint_handlers.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 (142 lines) | stat: -rw-r--r-- 5,809 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
// Copyright 2025 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/privacy_sandbox/notice/desktop_entrypoint_handlers.h"

#include "chrome/browser/privacy_sandbox/notice/desktop_entrypoint_handlers_helper.h"
#include "chrome/browser/privacy_sandbox/notice/desktop_view_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_dialog_service.h"
#include "chrome/browser/search_engine_choice/search_engine_choice_dialog_service_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window/public/browser_window_features.h"
#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
#include "chrome/browser/ui/profiles/profile_customization_bubble_sync_controller.h"
#include "chrome/browser/ui/signin/signin_view_controller.h"
#include "chrome/common/webui_url_constants.h"
#include "components/privacy_sandbox/privacy_sandbox_features.h"
#include "components/sync/service/sync_service.h"
#include "components/tabs/public/tab_interface.h"
#include "components/web_modal/web_contents_modal_dialog_host.h"
#include "content/public/browser/navigation_handle.h"

namespace privacy_sandbox {

constexpr int kMinRequiredDialogHeight = 100;

//-----------------------------------------------------------------------------
// EntryPointHandler
//-----------------------------------------------------------------------------
EntryPointHandler::EntryPointHandler(
    base::RepeatingCallback<void(BrowserWindowInterface*)> entry_point_callback)
    : entry_point_callback_(std::move(entry_point_callback)) {}
EntryPointHandler::~EntryPointHandler() = default;

void EntryPointHandler::HandleEntryPoint(
    BrowserWindowInterface* browser_interface) {
  entry_point_callback_.Run(browser_interface);
}

//-----------------------------------------------------------------------------
// NavigationHandler
//-----------------------------------------------------------------------------
NavigationHandler::NavigationHandler(
    base::RepeatingCallback<void(BrowserWindowInterface*)> entry_point_callback)
    : EntryPointHandler(std::move(entry_point_callback)) {}

void NavigationHandler::HandleNewNavigation(
    content::NavigationHandle* navigation_handle,
    Profile* profile) {
  // TODO(crbug.com/408016824): Move this Feature flag check to the orchestrator
  // once implemented.
  if (!base::FeatureList::IsEnabled(
          privacy_sandbox::kPrivacySandboxNoticeFramework)) {
    return;
  }

  auto* tab_interface =
      tabs::TabInterface::GetFromContents(navigation_handle->GetWebContents());
  if (!tab_interface) {
    return;
  }

  auto* browser_window_interface = tab_interface->GetBrowserWindowInterface();
  if (!browser_window_interface) {
    return;
  }

  // Check whether the navigation target is a suitable prompt location. The
  // navigation URL, rather than the visible or committed URL, is required to
  // distinguish between different types of NTPs.
  if (!IsUrlSuitableForPrompt(navigation_handle->GetURL())) {
    return;
  }

// When navigating to a NTP that isn't Chrome-controlled on ChromeOS, open an
// about blank tab to display the prompt. On other platforms, it's being handled
// during startup.
#if BUILDFLAG(IS_CHROMEOS)
  MaybeOpenAboutBlankOnChrome(navigation_handle, profile,
                              navigation_handle->GetWebContents());
#endif  // BUILDFLAG(IS_CHROMEOS)

  // Avoid showing the prompt on popups, pip, anything that isn't a normal
  // browser.
  if (browser_window_interface->GetType() !=
      BrowserWindowInterface::TYPE_NORMAL) {
    return;
  }

  // If the windows height is too small, it is difficult to read or interact
  // with the dialog. The dialog is blocking modal, that is why we want to
  // prevent it from showing if there isn't enough space. The PrivacySandbox
  // prompt can always fit inside a normal tabbed window due to its minimum
  // width, so checking the height is enough here.
  auto* web_contents_modal_dialog_host =
      browser_window_interface->GetWebContentsModalDialogHostForWindow();
  if (!web_contents_modal_dialog_host ||
      web_contents_modal_dialog_host->GetMaximumDialogSize().height() <
          kMinRequiredDialogHeight) {
    return;
  }

  // If a sign-in dialog is being currently displayed or is about to be
  // displayed, the prompt should not be shown to avoid conflict.
  // TODO(crbug.com/370806609): When we add sign in notice to queue, put this
  // behind flag / remove.
  auto* browser = browser_window_interface->GetBrowserForMigrationOnly();
  bool signin_dialog_showing =
      browser->GetFeatures().signin_view_controller()->ShowsModalDialog();
#if !BUILDFLAG(IS_CHROMEOS)
  signin_dialog_showing =
      signin_dialog_showing ||
      IsProfileCustomizationBubbleSyncControllerRunning(browser);
#endif  // !BUILDFLAG(IS_CHROMEOS)
  if (signin_dialog_showing) {
    return;
  }

  // If a Sync setup is in progress, the prompt should not be shown.
  if (auto* sync_service = SyncServiceFactory::GetForProfile(profile)) {
    if (sync_service->IsSetupInProgress()) {
      return;
    }
  }

  // If the SearchEngineChoiceDialog has shown, we do not want to show our
  // notice.
  SearchEngineChoiceDialogService* search_engine_choice_dialog_service =
      SearchEngineChoiceDialogServiceFactory::GetForProfile(profile);
  if (search_engine_choice_dialog_service &&
      search_engine_choice_dialog_service->CanSuppressPrivacySandboxPromo()) {
    return;
  }

  // TODO(crbug.com/408016824):  Add error-event histograms.

  HandleEntryPoint(browser_window_interface);
}

}  // namespace privacy_sandbox