1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_APPS_APP_SERVICE_LAUNCH_UTILS_H_
6 #define CHROME_BROWSER_APPS_APP_SERVICE_LAUNCH_UTILS_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "chrome/browser/apps/app_service/app_launch_params.h"
12 #include "components/services/app_service/public/mojom/types.mojom.h"
13 #include "ui/base/window_open_disposition.h"
14 
15 class Browser;
16 class Profile;
17 
18 namespace base {
19 class CommandLine;
20 class FilePath;
21 }  // namespace base
22 
23 namespace content {
24 class WebContents;
25 }  // namespace content
26 
27 namespace apps {
28 
29 std::string GetAppIdForWebContents(content::WebContents* web_contents);
30 
31 bool IsInstalledApp(Profile* profile, const std::string& app_id);
32 
33 void SetAppIdForWebContents(Profile* profile,
34                             content::WebContents* web_contents,
35                             const std::string& app_id);
36 
37 // Converts file arguments to an app on |command_line| into base::FilePaths.
38 std::vector<base::FilePath> GetLaunchFilesFromCommandLine(
39     const base::CommandLine& command_line);
40 
41 // When a command line launch has an unknown app id, we open a browser with only
42 // the new tab page.
43 Browser* CreateBrowserWithNewTabPage(Profile* profile);
44 
45 // Helper to create AppLaunchParams using event flags that allows user to
46 // override the user-configured container using modifier keys. |display_id| is
47 // the id of the display from which the app is launched.
48 AppLaunchParams CreateAppIdLaunchParamsWithEventFlags(
49     const std::string& app_id,
50     int event_flags,
51     apps::mojom::AppLaunchSource source,
52     int64_t display_id,
53     apps::mojom::LaunchContainer fallback_container);
54 
55 apps::AppLaunchParams CreateAppLaunchParamsForIntent(
56     const std::string& app_id,
57     int32_t event_flags,
58     apps::mojom::AppLaunchSource source,
59     int64_t display_id,
60     apps::mojom::LaunchContainer fallback_container,
61     apps::mojom::IntentPtr&& intent);
62 
63 apps::mojom::AppLaunchSource GetAppLaunchSource(
64     apps::mojom::LaunchSource launch_source);
65 
66 // Returns event flag for |container| and |disposition|. If |prefer_container|
67 // is true, |disposition| will be ignored. Otherwise, |container| is ignored and
68 // an event flag based on |disposition| will be returned.
69 int GetEventFlags(apps::mojom::LaunchContainer container,
70                   WindowOpenDisposition disposition,
71                   bool prefer_container);
72 
73 }  // namespace apps
74 
75 #endif  // CHROME_BROWSER_APPS_APP_SERVICE_LAUNCH_UTILS_H_
76