File: web_app_ui_manager.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 (113 lines) | stat: -rw-r--r-- 4,048 bytes parent folder | download | duplicates (6)
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
// Copyright 2022 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/web_applications/web_app_ui_manager.h"

#include "base/auto_reset.h"
#include "base/feature_list.h"
#include "chrome/browser/web_applications/web_app_callback_app_identity.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"

namespace web_app {

namespace {

// Keeps track of whether the testing code has set an action to be performed
// when the app identity update confirmation dialog is set to show. The behavior
// is determined by the IdentityUpdateDialogAction enum in
// web_app_ui_manager.h.
std::optional<AppIdentityUpdate>
    g_auto_resolve_app_identity_update_dialog_for_testing = std::nullopt;

}  // namespace

base::AutoReset<std::optional<AppIdentityUpdate>>
SetIdentityUpdateDialogActionForTesting(  // IN-TEST
    std::optional<AppIdentityUpdate> auto_accept_action) {
  return base::AutoReset<std::optional<AppIdentityUpdate>>(
      &g_auto_resolve_app_identity_update_dialog_for_testing,
      auto_accept_action);
}

std::optional<AppIdentityUpdate>
GetIdentityUpdateDialogActionForTesting() {  // IN-TEST
  return g_auto_resolve_app_identity_update_dialog_for_testing;
}

// static
apps::AppLaunchParams WebAppUiManager::CreateAppLaunchParamsWithoutWindowConfig(
    const webapps::AppId& app_id,
    const base::CommandLine& command_line,
    const base::FilePath& current_directory,
    const std::optional<GURL>& url_handler_launch_url,
    const std::optional<GURL>& protocol_handler_launch_url,
    const std::optional<GURL>& file_launch_url,
    const std::vector<base::FilePath>& launch_files) {
  // At most one of these parameters should be non-empty.
  DCHECK_LE(url_handler_launch_url.has_value() +
                protocol_handler_launch_url.has_value() + !launch_files.empty(),
            1);

  apps::LaunchSource launch_source = apps::LaunchSource::kFromCommandLine;

  if (url_handler_launch_url.has_value()) {
    launch_source = apps::LaunchSource::kFromUrlHandler;
  } else if (!launch_files.empty()) {
    DCHECK(file_launch_url.has_value());
    launch_source = apps::LaunchSource::kFromFileManager;
  }

  if (base::FeatureList::IsEnabled(features::kDesktopPWAsRunOnOsLogin) &&
      command_line.HasSwitch(switches::kAppRunOnOsLoginMode)) {
    launch_source = apps::LaunchSource::kFromOsLogin;
  } else if (protocol_handler_launch_url.has_value()) {
    launch_source = apps::LaunchSource::kFromProtocolHandler;
  }

  apps::AppLaunchParams params(app_id,
                               apps::LaunchContainer::kLaunchContainerNone,
                               WindowOpenDisposition::UNKNOWN, launch_source);
  params.command_line = command_line;
  params.current_directory = current_directory;
  params.launch_files = launch_files;
  params.url_handler_launch_url = url_handler_launch_url;
  params.protocol_handler_launch_url = protocol_handler_launch_url;
  if (file_launch_url) {
    params.override_url = *file_launch_url;
  } else {
    params.override_url = GURL(command_line.GetSwitchValueASCII(
        switches::kAppLaunchUrlForShortcutsMenuItem));
  }

  return params;
}

WebAppUiManager::WebAppUiManager() = default;

WebAppUiManager::~WebAppUiManager() {
  for (WebAppUiManagerObserver& observer : observers_)
    observer.OnWebAppUiManagerDestroyed();
}

base::WeakPtr<WebAppUiManager> WebAppUiManager::GetWeakPtr() {
  return weak_ptr_factory_.GetWeakPtr();
}

void WebAppUiManager::AddObserver(WebAppUiManagerObserver* observer) {
  observers_.AddObserver(observer);
}

void WebAppUiManager::RemoveObserver(WebAppUiManagerObserver* observer) {
  observers_.RemoveObserver(observer);
}

void WebAppUiManager::NotifyReadyToCommitNavigation(
    const webapps::AppId& app_id,
    content::NavigationHandle* navigation_handle) {
  for (WebAppUiManagerObserver& observer : observers_)
    observer.OnReadyToCommitNavigation(app_id, navigation_handle);
}

}  // namespace web_app