Skip to content

Commit 281a6e4

Browse files
mkruisselbrinkChromium LUCI CQ
authored and
Chromium LUCI CQ
committed
Don't treat policy installed apps as user initiated.
On Mac, if a shortcut is created with a user initiated reason we highlight the created shortcut in Finder. When an app is installed via enterprise policy this should not be considered user initiated. Bug: 1249771 Change-Id: I29e7c9d23c6cb1f3f5375d7517e66d3c1695a76d Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3894793 Reviewed-by: Daniel Murphy <[email protected]> Reviewed-by: Phillis Tang <[email protected]> Commit-Queue: Marijn Kruisselbrink <[email protected]> Cr-Commit-Position: refs/heads/main@{#1047648}
1 parent 0d04308 commit 281a6e4

8 files changed

+38
-10
lines changed

Diff for: chrome/browser/web_applications/commands/run_on_os_login_command.cc

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ void RunOnOsLoginCommand::UpdateRunOnOsLoginModeWithOsIntegration() {
203203
} else {
204204
web_app::InstallOsHooksOptions install_options;
205205
install_options.os_hooks[web_app::OsHookType::kRunOnOsLogin] = true;
206+
install_options.reason = SHORTCUT_CREATION_AUTOMATED;
206207
os_integration_manager_->InstallOsHooks(
207208
app_id_,
208209
base::BindOnce(&RunOnOsLoginCommand::OnOsHooksSet,

Diff for: chrome/browser/web_applications/os_integration/os_integration_manager.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ void OsIntegrationManager::InstallOsHooks(
219219
// TODO(ortuno): Make adding a shortcut to the applications menu independent
220220
// from adding a shortcut to desktop.
221221
if (options.os_hooks[OsHookType::kShortcuts]) {
222-
CreateShortcuts(app_id, options.add_to_desktop,
222+
CreateShortcuts(app_id, options.add_to_desktop, options.reason,
223223
std::move(shortcuts_callback));
224224
} else {
225225
base::SequencedTaskRunnerHandle::Get()->PostTask(
@@ -414,9 +414,10 @@ FakeOsIntegrationManager* OsIntegrationManager::AsTestOsIntegrationManager() {
414414

415415
void OsIntegrationManager::CreateShortcuts(const AppId& app_id,
416416
bool add_to_desktop,
417+
ShortcutCreationReason reason,
417418
CreateShortcutsCallback callback) {
418419
if (shortcut_manager_->CanCreateShortcuts()) {
419-
shortcut_manager_->CreateShortcuts(app_id, add_to_desktop,
420+
shortcut_manager_->CreateShortcuts(app_id, add_to_desktop, reason,
420421
std::move(callback));
421422
} else {
422423
std::move(callback).Run(false);

Diff for: chrome/browser/web_applications/os_integration/os_integration_manager.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ struct InstallOsHooksOptions {
5959
OsHooksOptions os_hooks;
6060
bool add_to_desktop = false;
6161
bool add_to_quick_launch_bar = false;
62+
ShortcutCreationReason reason = SHORTCUT_CREATION_BY_USER;
6263
};
6364

6465
// Retire these 3 once the sub-manager project is done.
@@ -235,6 +236,7 @@ class OsIntegrationManager : public AppRegistrarObserver {
235236

236237
virtual void CreateShortcuts(const AppId& app_id,
237238
bool add_to_desktop,
239+
ShortcutCreationReason reason,
238240
CreateShortcutsCallback callback);
239241

240242
// Installation:

Diff for: chrome/browser/web_applications/os_integration/os_integration_manager_unittest.cc

+8-4
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ TEST_F(OsIntegrationManagerTest, InstallOsHooksOnlyShortcuts) {
8080

8181
testing::StrictMock<MockOsIntegrationManager> manager;
8282
EXPECT_CALL(manager, MacAppShimOnAppInstalledForProfile(app_id)).Times(1);
83-
EXPECT_CALL(manager, CreateShortcuts(app_id, false, testing::_))
84-
.WillOnce(base::test::RunOnceCallback<2>(true));
83+
EXPECT_CALL(manager, CreateShortcuts(app_id, false,
84+
SHORTCUT_CREATION_AUTOMATED, testing::_))
85+
.WillOnce(base::test::RunOnceCallback<3>(true));
8586

8687
InstallOsHooksOptions options;
8788
options.os_hooks[OsHookType::kShortcuts] = true;
89+
options.reason = SHORTCUT_CREATION_AUTOMATED;
8890
manager.InstallOsHooks(app_id, std::move(callback), nullptr, options);
8991
run_loop.Run();
9092
EXPECT_FALSE(install_errors[OsHookType::kShortcuts]);
@@ -106,8 +108,9 @@ TEST_F(OsIntegrationManagerTest, InstallOsHooksEverything) {
106108
// added here.
107109
testing::StrictMock<MockOsIntegrationManager> manager;
108110
EXPECT_CALL(manager, MacAppShimOnAppInstalledForProfile(app_id)).Times(1);
109-
EXPECT_CALL(manager, CreateShortcuts(app_id, true, testing::_))
110-
.WillOnce(base::test::RunOnceCallback<2>(true));
111+
EXPECT_CALL(manager, CreateShortcuts(app_id, true, SHORTCUT_CREATION_BY_USER,
112+
testing::_))
113+
.WillOnce(base::test::RunOnceCallback<3>(true));
111114
EXPECT_CALL(manager, RegisterFileHandlers(app_id, testing::_)).Times(1);
112115
EXPECT_CALL(manager, RegisterProtocolHandlers(app_id, testing::_)).Times(1);
113116
EXPECT_CALL(manager, RegisterUrlHandlers(app_id, testing::_)).Times(1);
@@ -122,6 +125,7 @@ TEST_F(OsIntegrationManagerTest, InstallOsHooksEverything) {
122125
InstallOsHooksOptions options;
123126
options.add_to_desktop = true;
124127
options.add_to_quick_launch_bar = true;
128+
options.reason = SHORTCUT_CREATION_BY_USER;
125129
// Set all hooks to true.
126130
options.os_hooks.set();
127131
manager.InstallOsHooks(app_id, std::move(callback), nullptr, options);

Diff for: chrome/browser/web_applications/os_integration/web_app_shortcut_manager.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void WebAppShortcutManager::SuppressShortcutsForTesting() {
128128

129129
void WebAppShortcutManager::CreateShortcuts(const AppId& app_id,
130130
bool add_to_desktop,
131+
ShortcutCreationReason reason,
131132
CreateShortcutsCallback callback) {
132133
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
133134
DCHECK(CanCreateShortcuts());
@@ -136,7 +137,7 @@ void WebAppShortcutManager::CreateShortcuts(const AppId& app_id,
136137
app_id,
137138
base::BindOnce(
138139
&WebAppShortcutManager::OnShortcutInfoRetrievedCreateShortcuts,
139-
weak_ptr_factory_.GetWeakPtr(), add_to_desktop,
140+
weak_ptr_factory_.GetWeakPtr(), add_to_desktop, reason,
140141
base::BindOnce(&WebAppShortcutManager::OnShortcutsCreated,
141142
weak_ptr_factory_.GetWeakPtr(), app_id,
142143
std::move(callback))));
@@ -229,6 +230,7 @@ void WebAppShortcutManager::OnShortcutsDeleted(const AppId& app_id,
229230

230231
void WebAppShortcutManager::OnShortcutInfoRetrievedCreateShortcuts(
231232
bool add_to_desktop,
233+
ShortcutCreationReason reason,
232234
CreateShortcutsCallback callback,
233235
std::unique_ptr<ShortcutInfo> info) {
234236
if (suppress_shortcuts_for_testing_) {
@@ -247,9 +249,9 @@ void WebAppShortcutManager::OnShortcutInfoRetrievedCreateShortcuts(
247249
locations.on_desktop = add_to_desktop;
248250
locations.applications_menu_location = APP_MENU_LOCATION_SUBDIR_CHROMEAPPS;
249251

250-
internals::ScheduleCreatePlatformShortcuts(
251-
shortcut_data_dir, locations, SHORTCUT_CREATION_BY_USER, std::move(info),
252-
std::move(callback));
252+
internals::ScheduleCreatePlatformShortcuts(shortcut_data_dir, locations,
253+
reason, std::move(info),
254+
std::move(callback));
253255
}
254256

255257
void WebAppShortcutManager::OnShortcutsMenuIconsReadRegisterShortcutsMenu(

Diff for: chrome/browser/web_applications/os_integration/web_app_shortcut_manager.h

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class WebAppShortcutManager {
5959
bool CanCreateShortcuts() const;
6060
void CreateShortcuts(const AppId& app_id,
6161
bool add_to_desktop,
62+
ShortcutCreationReason reason,
6263
CreateShortcutsCallback callback);
6364
// Fetch already-updated shortcut data and deploy to OS integration.
6465
void UpdateShortcuts(const AppId& app_id,
@@ -129,6 +130,7 @@ class WebAppShortcutManager {
129130

130131
void OnShortcutInfoRetrievedCreateShortcuts(
131132
bool add_to_desktop,
133+
ShortcutCreationReason reason,
132134
CreateShortcutsCallback callback,
133135
std::unique_ptr<ShortcutInfo> info);
134136

Diff for: chrome/browser/web_applications/test/mock_os_integration_manager.h

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class MockOsIntegrationManager : public OsIntegrationManager {
2727
CreateShortcuts,
2828
(const AppId& app_id,
2929
bool add_to_desktop,
30+
ShortcutCreationReason reason,
3031
CreateShortcutsCallback callback),
3132
(override));
3233

Diff for: chrome/browser/web_applications/web_app_install_finalizer.cc

+15
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,21 @@ void WebAppInstallFinalizer::OnDatabaseCommitCompletedForInstall(
519519
hooks_options.os_hooks[OsHookType::kFileHandlers] = true;
520520
hooks_options.os_hooks[OsHookType::kProtocolHandlers] = true;
521521

522+
switch (finalize_options.source) {
523+
case WebAppManagement::kSystem:
524+
case WebAppManagement::kPolicy:
525+
case WebAppManagement::kDefault:
526+
hooks_options.reason = SHORTCUT_CREATION_AUTOMATED;
527+
break;
528+
case WebAppManagement::kKiosk:
529+
case WebAppManagement::kSubApp:
530+
case WebAppManagement::kWebAppStore:
531+
case WebAppManagement::kSync:
532+
case WebAppManagement::kCommandLine:
533+
hooks_options.reason = SHORTCUT_CREATION_BY_USER;
534+
break;
535+
}
536+
522537
os_integration_manager_->InstallOsHooks(
523538
app_id,
524539
base::BindOnce(&WebAppInstallFinalizer::OnInstallHooksFinished,

0 commit comments

Comments
 (0)