// Copyright 2012 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ #define CHROME_BROWSER_SHELL_INTEGRATION_H_ #include <map> #include <string> #include "base/files/file_path.h" #include "base/functional/callback.h" #include "base/memory/ref_counted.h" #include "build/build_config.h" #include "ui/gfx/image/image_family.h" #include "url/gurl.h" namespace base { class CommandLine; } namespace shell_integration { // Sets Chrome as the default browser (only for the current user). // // Don't use this, because: // - This does not work on Windows version 8 or higher. // - This cannot provide feedback as to success because setting a default // browser is asynchronous. // // Use `DefaultBrowserWorker` instead. // TODO(crbug.com/40248220): Extend `DefaultBrowserWorker` to work better // on the Mac and remove this function. bool SetAsDefaultBrowser(); // Sets Chrome as the default client application for the given scheme (only // for the current user). Prefer to use the `DefaultSchemeClientWorker` class // below since it works on all OSs. // // TODO(crbug.com/40248220): Extend `DefaultSchemeClientWorker` to work // better on the Mac and remove this function. bool SetAsDefaultClientForScheme(const std::string& scheme); // The different types of permissions required to set a default web client. enum DefaultWebClientSetPermission { … }; // Returns requirements for making the running browser the default browser. DefaultWebClientSetPermission GetDefaultBrowserSetPermission(); // Returns requirements for making the running browser the default client // application for specific schemes outside of the default browser. DefaultWebClientSetPermission GetDefaultSchemeClientSetPermission(); // Returns true if the running browser can be set as the default browser, // whether user interaction is needed or not. Use // GetDefaultWebClientSetPermission() if this distinction is important. bool CanSetAsDefaultBrowser(); // Returns a string representing the application to be launched given the // scheme of the requested url. This string may be a name or a path, but // neither is guaranteed and it should only be used as a display string. // Returns an empty string on failure. std::u16string GetApplicationNameForScheme(const GURL& url); #if BUILDFLAG(IS_MAC) // Returns a vector which containing all the application paths that can be used // to launch the requested URL. // Returns an empty vector if no application is found. std::vector<base::FilePath> GetAllApplicationPathsForURL(const GURL& url); // Returns true if the application at `path` can be used to launch the given // `url`. bool CanApplicationHandleURL(const base::FilePath& app_path, const GURL& url); #endif // Chrome's default web client state as a browser as a scheme client. If the // current install mode is not default, the brand's other modes are // checked. This allows callers to take specific action in case the current mode // (e.g., Chrome Dev) is not the default handler, but another of the brand's // modes (e.g., stable Chrome) is. enum DefaultWebClientState { … }; // Attempt to determine if this instance of Chrome is the default browser and // return the appropriate state. (Defined as being the handler for HTTP/HTTPS // schemes; we don't want to report "no" here if the user has simply chosen // to open HTML files in a text editor and FTP links with an FTP client.) DefaultWebClientState GetDefaultBrowser(); // Returns true if Firefox is likely to be the default browser for the current // user. This method is very fast so it can be invoked in the UI thread. bool IsFirefoxDefaultBrowser(); #if BUILDFLAG(IS_WIN) // Returns true if IE is likely to be the default browser for the current // user. This method is very fast so it can be invoked in the UI thread. bool IsIEDefaultBrowser(); // Returns the install id of the installation set as default browser. If no // installation of Firefox is set as the default browser, returns an empty // string. std::string GetFirefoxProgIdSuffix(); #endif // Attempt to determine if this instance of Chrome is the default client // application for the given scheme and return the appropriate state. DefaultWebClientState IsDefaultClientForScheme(const std::string& scheme); // Is the current instance of Chrome running in App mode. bool IsRunningInAppMode(); // Set up command line arguments for launching a URL or an app. // The new command line reuses the current process's user data directory (and // login profile, for ChromeOS). // If |extension_app_id| is non-empty, the arguments use kAppId=<id>. // Otherwise, kApp=<url> is used. base::CommandLine CommandLineArgsForLauncher( const GURL& url, const std::string& extension_app_id, const base::FilePath& profile_path, const std::string& run_on_os_login_mode); // Set up command line arguments for launching chrome at the given url using the // given profile. All arguments must be non-empty and valid. base::CommandLine CommandLineArgsForUrlShortcut( const base::FilePath& chrome_exe_program, const base::FilePath& profile_path, const GURL& url); // Append command line arguments for launching a new chrome.exe process // based on the current process. // The new command line reuses the current process's user data directory and // profile. void AppendProfileArgs(const base::FilePath& profile_path, base::CommandLine* command_line); #if !BUILDFLAG(IS_WIN) // Gets the name of the Chrome Apps menu folder in which to place app // shortcuts. This is needed for Mac and Linux. std::u16string GetAppShortcutsSubdirName(); #endif // The type of callback used to communicate processing state to consumers of // DefaultBrowserWorker and DefaultSchemeClientWorker. DefaultWebClientWorkerCallback; // The type of callback used to communicate processing state to consumers of // DefaultBrowserWorker and DefaultSchemeClientWorker. DefaultSchemeHandlerWorkerCallback; // Helper objects that handle checking if Chrome is the default browser // or application for a url scheme on Windows and Linux, and also setting // it as the default. These operations are performed asynchronously on a // blocking sequence since registry access (on Windows) or the preference // database (on Linux) are involved and this can be slow. // By default, the worker will present the user with an interactive flow if // required by the platform. This can be suppressed via // set_interactive_permitted(), in which case an attempt to set Chrome as // the default handler will silently fail on such platforms. class DefaultWebClientWorker : public base::RefCountedThreadSafe<DefaultWebClientWorker> { … }; // Worker for checking and setting the default browser. class DefaultBrowserWorker : public DefaultWebClientWorker { … }; // Worker for checking and setting the default client application // for a given scheme. A different worker instance is needed for each // scheme you are interested in, so to check or set the default for // multiple scheme you should use multiple worker objects. class DefaultSchemeClientWorker : public DefaultWebClientWorker { … }; namespace internal { // The different ways to set the default web client. enum class WebClientSetMethod { … }; // Returns requirements for making the running browser either the default // browser or the default client application for specific schemes for the // current user, according to a specific platform. DefaultWebClientSetPermission GetPlatformSpecificDefaultWebClientSetPermission( WebClientSetMethod method); } // namespace internal } // namespace shell_integration #endif // CHROME_BROWSER_SHELL_INTEGRATION_H_