shell_integration.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CHROME_BROWSER_SHELL_INTEGRATION_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CHROME_BROWSER_SHELL_INTEGRATION_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/files/file_path.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/string16.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ui/gfx/image/image_family.h" 15eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "url/gurl.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace base { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CommandLine; 19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)} 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ShellIntegration { 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets Chrome as the default browser (only for the current user). Returns 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // false if this operation fails. 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetAsDefaultBrowser(); 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initiates an OS shell flow which (if followed by the user) should set 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome as the default browser. Returns false if the flow cannot be 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // initialized, if it is not supported (introduced for Windows 8) or if the 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user cancels the operation. This is a blocking call and requires a FILE 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thread. If Chrome is already default browser, no interactive dialog will be 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // shown and this method returns true. 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetAsDefaultBrowserInteractive(); 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets Chrome as the default client application for the given protocol 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (only for the current user). Returns false if this operation fails. 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetAsDefaultProtocolClient(const std::string& protocol); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initiates an OS shell flow which (if followed by the user) should set 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome as the default handler for |protocol|. Returns false if the flow 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // cannot be initialized, if it is not supported (introduced for Windows 8) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or if the user cancels the operation. This is a blocking call and requires 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a FILE thread. If Chrome is already default for |protocol|, no interactive 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // dialog will be shown and this method returns true. 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool SetAsDefaultProtocolClientInteractive( 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& protocol); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // In Windows 8 a browser can be made default-in-metro only in an interactive 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // flow. We will distinguish between two types of permissions here to avoid 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // forcing the user into UI interaction when this should not be done. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum DefaultWebClientSetPermission { 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) SET_DEFAULT_NOT_ALLOWED, 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SET_DEFAULT_UNATTENDED, 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SET_DEFAULT_INTERACTIVE, 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns requirements for making the running browser the user's default. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static DefaultWebClientSetPermission CanSetAsDefaultBrowser(); 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns requirements for making the running browser the user's default 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // client application for specific protocols. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient(); 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 64a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns a string representing the application to be launched given the 65a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // protocol of the requested url. This string may be a name or a path, but 66a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // neither is guaranteed and it should only be used as a display string. 67a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Returns an empty string on failure. 68a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static base::string16 GetApplicationNameForProtocol(const GURL& url); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On Linux, it may not be possible to determine or set the default browser 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // on some desktop environments or configurations. So, we use this enum and 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // not a plain bool. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum DefaultWebClientState { 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NOT_DEFAULT, 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) IS_DEFAULT, 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) UNKNOWN_DEFAULT, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NUM_DEFAULT_STATES 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Attempt to determine if this instance of Chrome is the default browser and 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // return the appropriate state. (Defined as being the handler for HTTP/HTTPS 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // protocols; we don't want to report "no" here if the user has simply chosen 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to open HTML files in a text editor and FTP links with an FTP client.) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static DefaultWebClientState GetDefaultBrowser(); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if Firefox is likely to be the default browser for the current 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // user. This method is very fast so it can be invoked in the UI thread. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static bool IsFirefoxDefaultBrowser(); 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Attempt to determine if this instance of Chrome is the default client 915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // application for the given protocol and return the appropriate state. 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static DefaultWebClientState 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) IsDefaultProtocolClient(const std::string& protocol); 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct ShortcutInfo { 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ShortcutInfo(); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~ShortcutInfo(); 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) GURL url; 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |extension_id| is non-empty, this is short cut is to an extension-app 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // and the launch url will be detected at start-up. In this case, |url| 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is still used to generate the app id (windows app id, not chrome app id). 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string extension_id; 1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_platform_app; 105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 title; 106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16 description; 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath extension_path; 108c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) gfx::ImageFamily favicon; 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath profile_path; 110868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) std::string profile_name; 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // This specifies a folder in the system applications menu (e.g the Start Menu 114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // on Windows). 115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // These represent the applications menu root, the "Google Chrome" folder and 117a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // the "Chrome Apps" folder respectively. 118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // 119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // NB: On Linux, these locations may not be used by the window manager (e.g 120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Unity and Gnome Shell). 121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) enum ApplicationsMenuLocation { 122a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) APP_MENU_LOCATION_NONE, 123a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) APP_MENU_LOCATION_ROOT, 124a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) APP_MENU_LOCATION_SUBDIR_CHROME, 125a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) APP_MENU_LOCATION_SUBDIR_CHROMEAPPS, 126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) }; 127a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 1282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Info about which locations to create app shortcuts in. 1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) struct ShortcutLocations { 1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ShortcutLocations(); 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool on_desktop; 133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ApplicationsMenuLocation applications_menu_location; 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For Windows, this refers to quick launch bar prior to Win7. In Win7, 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this means "pin to taskbar". For Mac/Linux, this could be used for 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Mac dock or the gnome/kde application launcher. However, those are not 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // implemented yet. 1402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool in_quick_launch_bar; 1412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if defined(OS_POSIX) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // For Linux, this refers to a shortcut which the system knows about (for 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the purpose of identifying windows and giving them the correct 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // title/icon), but which does not show up in menus or search results. 146a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Ignored if applications_menu_location is not APP_MENU_LOCATION_NONE. 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool hidden; 148a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Data that needs to be passed between the app launcher stub and Chrome. 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) struct AppModeInfo { 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void SetAppModeInfo(const AppModeInfo* info); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const AppModeInfo* AppModeInfo(); 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Is the current instance of Chrome running in App mode. 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool IsRunningInAppMode(); 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set up command line arguments for launching a URL or an app. 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The new command line reuses the current process's user data directory (and 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // login profile, for ChromeOS). 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If |extension_app_id| is non-empty, the arguments use kAppId=<id>. 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Otherwise, kApp=<url> is used. 165a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static base::CommandLine CommandLineArgsForLauncher( 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& extension_app_id, 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path); 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 170a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // Append command line arguments for launching a new chrome.exe process 171a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // based on the current process. 172a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // The new command line reuses the current process's user data directory and 173a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) // profile. 174a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) static void AppendProfileArgs(const base::FilePath& profile_path, 175a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::CommandLine* command_line); 176a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN) 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generates an application user model ID (AppUserModelId) for a given app 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // name and profile path. The returned app id is in the format of 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // "|app_name|[.<profile_id>]". "profile_id" is appended when user override 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the default value. 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Note: If the app has an installation specific suffix (e.g. on user-level 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Chrome installs), |app_name| should already be suffixed, this method will 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // then further suffix it with the profile id as described above. 185a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static base::string16 GetAppModelIdForProfile(const base::string16& app_name, 1862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path); 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Generates an application user model ID (AppUserModelId) for Chromium by 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name. 190a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static base::string16 GetChromiumModelIdForProfile( 1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path); 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Get the AppUserModelId for the App List, for the profile in |profile_path|. 194a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static base::string16 GetAppListAppModelIdForProfile( 1952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& profile_path); 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Migrates existing chrome shortcuts by tagging them with correct app id. 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // see http://crbug.com/28104 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void MigrateChromiumShortcuts(); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Migrates all shortcuts in |path| which point to |chrome_exe| such that they 2022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // have the appropriate AppUserModelId. Also makes sure those shortcuts have 2032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the dual_mode property set if such is requested by |check_dual_mode|. 2042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the number of shortcuts migrated. 2052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method should not be called prior to Windows 7. 2062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // This method is only public for the sake of tests and shouldn't be called 2072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // externally otherwise. 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static int MigrateShortcutsInPathInternal(const base::FilePath& chrome_exe, 2092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const base::FilePath& path, 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool check_dual_mode); 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the path to the Start Menu shortcut for the given Chrome. 2132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static base::FilePath GetStartMenuShortcut(const base::FilePath& chrome_exe); 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // defined(OS_WIN) 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#if !defined(OS_WIN) 217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // TODO(calamity): replace with 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // BrowserDistribution::GetStartMenuShortcutSubfolder() once 219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // BrowserDistribution is cross-platform. 220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Gets the name of the Chrome Apps menu folder in which to place app 221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // shortcuts. This is needed for Mac and Linux. 222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) static base::string16 GetAppShortcutsSubdirName(); 223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif 224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The current default web client application UI state. This is used when 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // querying if Chrome is the default browser or the default handler 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // application for a url protocol, and communicates the state and result of 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a request. 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum DefaultWebClientUIState { 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_PROCESSING, 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_NOT_DEFAULT, 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_IS_DEFAULT, 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) STATE_UNKNOWN 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class DefaultWebClientObserver { 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DefaultWebClientObserver() {} 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the UI state to reflect the current default browser state. 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0; 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called to notify the UI of the immediate result of invoking 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // SetAsDefault. 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnSetAsDefaultConcluded(bool succeeded) {} 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Observer classes that return true to OwnedByWorker are automatically 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // freed by the worker when they are no longer needed. False by default. 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsOwnedByWorker(); 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // An observer can permit or decline set-as-default operation if it 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // requires triggering user interaction. By default not allowed. 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool IsInteractiveSetDefaultPermitted(); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Helper objects that handle checking if Chrome is the default browser 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // or application for a url protocol on Windows and Linux, and also setting 2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it as the default. These operations are performed asynchronously on the 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file thread since registry access (on Windows) or the preference database 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // (on Linux) are involved and this can be slow. 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class DefaultWebClientWorker 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) : public base::RefCountedThreadSafe<DefaultWebClientWorker> { 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit DefaultWebClientWorker(DefaultWebClientObserver* observer); 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Checks to see if Chrome is the default web client application. The result 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will be passed back to the observer via the SetDefaultWebClientUIState 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function. If there is no observer, this function does not do anything. 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartCheckIsDefault(); 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Sets Chrome as the default web client application. If there is an 2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // observer, once the operation has completed the new default will be 2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // queried and the current status reported via SetDefaultWebClientUIState. 2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void StartSetAsDefault(); 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called to notify the worker that the view is gone. 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ObserverDestroyed(); 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) friend class base::RefCountedThreadSafe<DefaultWebClientWorker>; 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DefaultWebClientWorker() {} 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Function that performs the check. 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual DefaultWebClientState CheckIsDefault() = 0; 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Function that sets Chrome as the default web client. Returns false if 2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the operation fails or has been cancelled by the user. 2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SetAsDefault(bool interactive_permitted) = 0; 2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Function that handles performing the check on the file thread. This 2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function is posted as a task onto the file thread, where it performs 2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the check. When the check has finished the CompleteCheckIsDefault 2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // function is posted to the UI thread, where the result is sent back to 2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the observer. 2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ExecuteCheckIsDefault(); 2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Function that handles setting Chrome as the default web client on the 2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file thread. This function is posted as a task onto the file thread. 2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Once it is finished the CompleteSetAsDefault function is posted to the 2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // UI thread which will check the status of Chrome as the default, and 2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // send this to the observer. 3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |interactive_permitted| indicates if the routine is allowed to carry on 3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in context where user interaction is required (CanSetAsDefault* 3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // returns SET_DEFAULT_INTERACTIVE). 3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ExecuteSetAsDefault(bool interactive_permitted); 3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Communicate results to the observer. This function is posted as a task 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // onto the UI thread by the ExecuteCheckIsDefault function running in the 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // file thread. 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CompleteCheckIsDefault(DefaultWebClientState state); 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // When the action to set Chrome as the default has completed this function 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is run. It is posted as a task back onto the UI thread by the 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ExecuteSetAsDefault function running in the file thread. This function 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will the start the check process, which, if an observer is present, 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reports to it the new status. 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |succeeded| is true if the actual call to a set-default function (from 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ExecuteSetAsDefault) was successful. 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CompleteSetAsDefault(bool succeeded); 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates the UI in our associated view with the current default web 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // client state. 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UpdateUI(DefaultWebClientState state); 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DefaultWebClientObserver* observer_; 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker); 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Worker for checking and setting the default browser. 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class DefaultBrowserWorker : public DefaultWebClientWorker { 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit DefaultBrowserWorker(DefaultWebClientObserver* observer); 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DefaultBrowserWorker() {} 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check if Chrome is the default browser. 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual DefaultWebClientState CheckIsDefault() OVERRIDE; 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set Chrome as the default browser. 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE; 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker); 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Worker for checking and setting the default client application 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // for a given protocol. A different worker instance is needed for each 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // protocol you are interested in, so to check or set the default for 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // multiple protocols you should use multiple worker objects. 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) class DefaultProtocolClientWorker : public DefaultWebClientWorker { 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DefaultProtocolClientWorker(DefaultWebClientObserver* observer, 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& protocol); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const std::string& protocol() const { return protocol_; } 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected: 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~DefaultProtocolClientWorker() {} 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check is Chrome is the default handler for this protocol. 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual DefaultWebClientState CheckIsDefault() OVERRIDE; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Set Chrome as the default handler for this protocol. 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE; 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string protocol_; 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker); 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CHROME_BROWSER_SHELL_INTEGRATION_H_ 373