Avi Drissman | 4a8573c | 2022-09-09 19:35:54 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 2 | // 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 Bertoni | 290539a | 2025-03-10 22:45:14 | [diff] [blame] | 7 | #include <optional> |
Jinho Bang | b5216cec | 2018-01-17 19:43:11 | [diff] [blame] | 8 | |
avi | a2f4804a | 2015-12-24 23:11:13 | [diff] [blame] | 9 | #include "build/build_config.h" |
Yuta Hijikata | 1290fee2 | 2020-11-25 09:46:28 | [diff] [blame] | 10 | #include "build/chromeos_buildflags.h" |
[email protected] | dccba4f8 | 2014-05-29 00:52:56 | [diff] [blame] | 11 | #include "chrome/browser/extensions/extension_sync_service.h" |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 12 | #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
[email protected] | f0c8c499 | 2014-05-15 17:37:26 | [diff] [blame] | 13 | #include "components/pref_registry/pref_registry_syncable.h" |
macourteau | 86b29d8 | 2015-01-23 13:24:45 | [diff] [blame] | 14 | #include "extensions/browser/extension_registry.h" |
David Bertoni | 290539a | 2025-03-10 22:45:14 | [diff] [blame] | 15 | #include "extensions/browser/launch_util.h" |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 16 | #include "extensions/common/extension.h" |
| 17 | |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 18 | namespace extensions { |
[email protected] | a9f74a6 | 2014-01-10 06:48:36 | [diff] [blame] | 19 | |
macourteau | 86b29d8 | 2015-01-23 13:24:45 | [diff] [blame] | 20 | void SetLaunchType(content::BrowserContext* context, |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 21 | const std::string& extension_id, |
| 22 | LaunchType launch_type) { |
David Bertoni | 290539a | 2025-03-10 22:45:14 | [diff] [blame] | 23 | SetLaunchTypePrefValue(context, extension_id, launch_type); |
[email protected] | a9f74a6 | 2014-01-10 06:48:36 | [diff] [blame] | 24 | |
| 25 | // Sync the launch type. |
macourteau | 86b29d8 | 2015-01-23 13:24:45 | [diff] [blame] | 26 | const Extension* extension = |
| 27 | ExtensionRegistry::Get(context) |
| 28 | ->GetExtensionById(extension_id, ExtensionRegistry::EVERYTHING); |
| 29 | if (extension) |
| 30 | ExtensionSyncService::Get(context)->SyncExtensionChangeIfNeeded(*extension); |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 31 | } |
| 32 | |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 33 | apps::LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs, |
| 34 | const Extension* extension) { |
| 35 | apps::LaunchContainer manifest_launch_container = |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 36 | AppLaunchInfo::GetLaunchContainer(extension); |
| 37 | |
Arthur Sonzogni | fe132ee | 2024-01-15 11:01:04 | [diff] [blame] | 38 | std::optional<apps::LaunchContainer> result; |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 39 | |
Eric Willigers | 618e130 | 2019-06-23 23:03:47 | [diff] [blame] | 40 | if (manifest_launch_container == |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 41 | apps::LaunchContainer::kLaunchContainerPanelDeprecated) { |
Hiroshige Hayashizaki | a4756d2 | 2020-04-01 06:48:55 | [diff] [blame] | 42 | result = manifest_launch_container; |
| 43 | } else if (manifest_launch_container == |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 44 | apps::LaunchContainer::kLaunchContainerTab) { |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 45 | // 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 Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 52 | result = apps::LaunchContainer::kLaunchContainerWindow; |
David Bertoni | 53445f6 | 2024-10-11 19:50:54 | [diff] [blame] | 53 | #if BUILDFLAG(IS_CHROMEOS) |
scottmg | d12621f | 2016-03-18 16:14:27 | [diff] [blame] | 54 | } else if (prefs_launch_type == LAUNCH_TYPE_FULLSCREEN) { |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 55 | // 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 Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 59 | result = apps::LaunchContainer::kLaunchContainerWindow; |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 60 | #endif |
| 61 | } else { |
| 62 | // All other launch types (tab, pinned, fullscreen) are |
| 63 | // implemented as tabs in a window. |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 64 | result = apps::LaunchContainer::kLaunchContainerTab; |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 65 | } |
| 66 | } else { |
| 67 | // If a new value for app.launch.container is added, logic for it should be |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 68 | // added here. apps::LaunchContainer::kLaunchContainerWindow is not |
Devlin Cronin | ed380dc4 | 2022-01-17 01:23:47 | [diff] [blame] | 69 | // present because there is no way to set it in a manifest. |
Peter Boström | 7051b50 | 2024-11-06 02:06:48 | [diff] [blame] | 70 | NOTREACHED() << static_cast<int>(manifest_launch_container); |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | // All paths should set |result|. |
Hans Wennborg | d3f6afb | 2017-12-09 00:16:37 | [diff] [blame] | 74 | if (!result) { |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 75 | DLOG(FATAL) << "Failed to set a launch container."; |
Nancy Wang | dcfd56a0 | 2022-07-04 17:16:00 | [diff] [blame] | 76 | result = apps::LaunchContainer::kLaunchContainerTab; |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 77 | } |
| 78 | |
Hans Wennborg | d3f6afb | 2017-12-09 00:16:37 | [diff] [blame] | 79 | return *result; |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | 31e4d8f | 2013-12-05 11:32:54 | [diff] [blame] | 82 | } // namespace extensions |