blob: 680831f75a9dc377480b64e1098113fd74d67383 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2013 The Chromium Authors
[email protected]31e4d8f2013-12-05 11:32:542// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/extensions/launch_util.h"
6
David Bertoni290539a2025-03-10 22:45:147#include <optional>
Jinho Bangb5216cec2018-01-17 19:43:118
avia2f4804a2015-12-24 23:11:139#include "build/build_config.h"
Yuta Hijikata1290fee22020-11-25 09:46:2810#include "build/chromeos_buildflags.h"
[email protected]dccba4f82014-05-29 00:52:5611#include "chrome/browser/extensions/extension_sync_service.h"
[email protected]31e4d8f2013-12-05 11:32:5412#include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
[email protected]f0c8c4992014-05-15 17:37:2613#include "components/pref_registry/pref_registry_syncable.h"
macourteau86b29d82015-01-23 13:24:4514#include "extensions/browser/extension_registry.h"
David Bertoni290539a2025-03-10 22:45:1415#include "extensions/browser/launch_util.h"
[email protected]31e4d8f2013-12-05 11:32:5416#include "extensions/common/extension.h"
17
[email protected]31e4d8f2013-12-05 11:32:5418namespace extensions {
[email protected]a9f74a62014-01-10 06:48:3619
macourteau86b29d82015-01-23 13:24:4520void SetLaunchType(content::BrowserContext* context,
[email protected]31e4d8f2013-12-05 11:32:5421 const std::string& extension_id,
22 LaunchType launch_type) {
David Bertoni290539a2025-03-10 22:45:1423 SetLaunchTypePrefValue(context, extension_id, launch_type);
[email protected]a9f74a62014-01-10 06:48:3624
25 // Sync the launch type.
macourteau86b29d82015-01-23 13:24:4526 const Extension* extension =
27 ExtensionRegistry::Get(context)
28 ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING);
29 if (extension)
30 ExtensionSyncService::Get(context)->SyncExtensionChangeIfNeeded(*extension);
[email protected]31e4d8f2013-12-05 11:32:5431}
32
Nancy Wangdcfd56a02022-07-04 17:16:0033apps::LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs,
34 const Extension* extension) {
35 apps::LaunchContainer manifest_launch_container =
[email protected]31e4d8f2013-12-05 11:32:5436 AppLaunchInfo::GetLaunchContainer(extension);
37
Arthur Sonzognife132ee2024-01-15 11:01:0438 std::optional<apps::LaunchContainer> result;
[email protected]31e4d8f2013-12-05 11:32:5439
Eric Willigers618e1302019-06-23 23:03:4740 if (manifest_launch_container ==
Nancy Wangdcfd56a02022-07-04 17:16:0041 apps::LaunchContainer::kLaunchContainerPanelDeprecated) {
Hiroshige Hayashizakia4756d22020-04-01 06:48:5542 result = manifest_launch_container;
43 } else if (manifest_launch_container ==
Nancy Wangdcfd56a02022-07-04 17:16:0044 apps::LaunchContainer::kLaunchContainerTab) {
[email protected]31e4d8f2013-12-05 11:32:5445 // Look for prefs that indicate the user's choice of launch container. The
46 // app's menu on the NTP provides a UI to set this preference.
47 LaunchType prefs_launch_type = GetLaunchType(prefs, extension);
48
49 if (prefs_launch_type == LAUNCH_TYPE_WINDOW) {
50 // If the pref is set to launch a window (or no pref is set, and
51 // window opening is the default), make the container a window.
Nancy Wangdcfd56a02022-07-04 17:16:0052 result = apps::LaunchContainer::kLaunchContainerWindow;
David Bertoni53445f62024-10-11 19:50:5453#if BUILDFLAG(IS_CHROMEOS)
scottmgd12621f2016-03-18 16:14:2754 } else if (prefs_launch_type == LAUNCH_TYPE_FULLSCREEN) {
[email protected]31e4d8f2013-12-05 11:32:5455 // LAUNCH_TYPE_FULLSCREEN launches in a maximized app window in ash.
56 // For desktop chrome AURA on all platforms we should open the
57 // application in full screen mode in the current tab, on the same
58 // lines as non AURA chrome.
Nancy Wangdcfd56a02022-07-04 17:16:0059 result = apps::LaunchContainer::kLaunchContainerWindow;
[email protected]31e4d8f2013-12-05 11:32:5460#endif
61 } else {
62 // All other launch types (tab, pinned, fullscreen) are
63 // implemented as tabs in a window.
Nancy Wangdcfd56a02022-07-04 17:16:0064 result = apps::LaunchContainer::kLaunchContainerTab;
[email protected]31e4d8f2013-12-05 11:32:5465 }
66 } else {
67 // If a new value for app.launch.container is added, logic for it should be
Nancy Wangdcfd56a02022-07-04 17:16:0068 // added here. apps::LaunchContainer::kLaunchContainerWindow is not
Devlin Cronined380dc42022-01-17 01:23:4769 // present because there is no way to set it in a manifest.
Peter Boström7051b502024-11-06 02:06:4870 NOTREACHED() << static_cast<int>(manifest_launch_container);
[email protected]31e4d8f2013-12-05 11:32:5471 }
72
73 // All paths should set |result|.
Hans Wennborgd3f6afb2017-12-09 00:16:3774 if (!result) {
[email protected]31e4d8f2013-12-05 11:32:5475 DLOG(FATAL) << "Failed to set a launch container.";
Nancy Wangdcfd56a02022-07-04 17:16:0076 result = apps::LaunchContainer::kLaunchContainerTab;
[email protected]31e4d8f2013-12-05 11:32:5477 }
78
Hans Wennborgd3f6afb2017-12-09 00:16:3779 return *result;
[email protected]31e4d8f2013-12-05 11:32:5480}
81
[email protected]31e4d8f2013-12-05 11:32:5482} // namespace extensions