shell_integration.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_path.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/string16.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "googleurl/src/gurl.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/image/image.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CommandLine;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ShellIntegration {
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets Chrome as the default browser (only for the current user). Returns
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // false if this operation fails.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetAsDefaultBrowser();
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initiates an OS shell flow which (if followed by the user) should set
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Chrome as the default browser. Returns false if the flow cannot be
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // initialized, if it is not supported (introduced for Windows 8) or if the
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // user cancels the operation. This is a blocking call and requires a FILE
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // thread. If Chrome is already default browser, no interactive dialog will be
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // shown and this method returns true.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetAsDefaultBrowserInteractive();
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Sets Chrome as the default client application for the given protocol
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // (only for the current user). Returns false if this operation fails.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetAsDefaultProtocolClient(const std::string& protocol);
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Initiates an OS shell flow which (if followed by the user) should set
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Chrome as the default handler for |protocol|. Returns false if the flow
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // cannot be initialized, if it is not supported (introduced for Windows 8)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // or if the user cancels the operation. This is a blocking call and requires
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a FILE thread. If Chrome is already default for |protocol|, no interactive
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // dialog will be shown and this method returns true.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool SetAsDefaultProtocolClientInteractive(
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& protocol);
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // In Windows 8 a browser can be made default-in-metro only in an interactive
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // flow. We will distinguish between two types of permissions here to avoid
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // forcing the user into UI interaction when this should not be done.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum DefaultWebClientSetPermission {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SET_DEFAULT_NOT_ALLOWED = 0,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SET_DEFAULT_UNATTENDED,
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    SET_DEFAULT_INTERACTIVE,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns requirements for making the running browser the user's default.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DefaultWebClientSetPermission CanSetAsDefaultBrowser();
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns requirements for making the running browser the user's default
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // client application for specific protocols.
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DefaultWebClientSetPermission CanSetAsDefaultProtocolClient();
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // On Linux, it may not be possible to determine or set the default browser
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // on some desktop environments or configurations. So, we use this enum and
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // not a plain bool. (Note however that if used like a bool, this enum will
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // have reasonable behavior.)
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum DefaultWebClientState {
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    NOT_DEFAULT_WEB_CLIENT = 0,
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    IS_DEFAULT_WEB_CLIENT,
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    UNKNOWN_DEFAULT_WEB_CLIENT = -1
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Attempt to determine if this instance of Chrome is the default browser and
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // protocols; we don't want to report "no" here if the user has simply chosen
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to open HTML files in a text editor and FTP links with an FTP client.)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DefaultWebClientState IsDefaultBrowser();
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if Firefox is likely to be the default browser for the current
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // user. This method is very fast so it can be invoked in the UI thread.
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static bool IsFirefoxDefaultBrowser();
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Attempt to determine if this instance of Chrome is the default client
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // application for the given protocol and return the appropriate state.
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static DefaultWebClientState
855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      IsDefaultProtocolClient(const std::string& protocol);
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct ShortcutInfo {
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ShortcutInfo();
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ~ShortcutInfo();
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    GURL url;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // If |extension_id| is non-empty, this is short cut is to an extension-app
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // and the launch url will be detected at start-up. In this case, |url|
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // is still used to generate the app id (windows app id, not chrome app id).
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string extension_id;
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    string16 title;
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    string16 description;
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FilePath extension_path;
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    gfx::Image favicon;
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    FilePath profile_path;
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool create_on_desktop;
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool create_in_applications_menu;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // For Windows, this refers to quick launch bar prior to Win7. In Win7,
1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // this means "pin to taskbar". For Mac/Linux, this could be used for
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Mac dock or the gnome/kde application launcher. However, those are not
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // implemented yet.
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    bool create_in_quick_launch_bar;
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Data that needs to be passed between the app launcher stub and Chrome.
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  struct AppModeInfo {
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void SetAppModeInfo(const AppModeInfo* info);
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const AppModeInfo* AppModeInfo();
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Is the current instance of Chrome running in App mode.
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool IsRunningInAppMode();
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set up command line arguments for launching a URL or an app.
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The new command line reuses the current process's user data directory (and
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // login profile, for ChromeOS).
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // If |extension_app_id| is non-empty, the arguments use kAppId=<id>.
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Otherwise, kApp=<url> is used.
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static CommandLine CommandLineArgsForLauncher(
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const GURL& url,
1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const std::string& extension_app_id,
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const FilePath& profile_path);
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generates an application user model ID (AppUserModelId) for a given app
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // name and profile path. The returned app id is in the format of
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // "|app_name|[.<profile_id>]". "profile_id" is appended when user override
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the default value.
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Note: If the app has an installation specific suffix (e.g. on user-level
1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Chrome installs), |app_name| should already be suffixed, this method will
1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // then further suffix it with the profile id as described above.
1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static string16 GetAppModelIdForProfile(const string16& app_name,
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const FilePath& profile_path);
1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Generates an application user model ID (AppUserModelId) for Chromium by
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // calling GetAppModelIdForProfile() with ShellUtil::GetAppId() as app_name.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static string16 GetChromiumModelIdForProfile(const FilePath& profile_path);
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Get the AppUserModelId for the App List, for the profile in |profile_path|.
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static string16 GetAppListAppModelIdForProfile(const FilePath& profile_path);
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the path to the Chromium icon. This is used to specify the icon
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to use for the taskbar group on Win 7.
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static string16 GetChromiumIconPath();
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Migrates existing chrome shortcuts by tagging them with correct app id.
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // see http://crbug.com/28104
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static void MigrateChromiumShortcuts();
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns the path to the Start Menu shortcut for the given Chrome.
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static FilePath GetStartMenuShortcut(const FilePath& chrome_exe);
1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_WIN)
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The current default web client application UI state. This is used when
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // querying if Chrome is the default browser or the default handler
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // application for a url protocol, and communicates the state and result of
1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a request.
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum DefaultWebClientUIState {
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_PROCESSING,
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_NOT_DEFAULT,
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_IS_DEFAULT,
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    STATE_UNKNOWN
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DefaultWebClientObserver {
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~DefaultWebClientObserver() {}
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Updates the UI state to reflect the current default browser state.
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void SetDefaultWebClientUIState(DefaultWebClientUIState state) = 0;
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called to notify the UI of the immediate result of invoking
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // SetAsDefault.
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual void OnSetAsDefaultConcluded(bool succeeded) {}
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Observer classes that return true to OwnedByWorker are automatically
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // freed by the worker when they are no longer needed. False by default.
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool IsOwnedByWorker();
1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // An observer can permit or decline set-as-default operation if it
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // requires triggering user interaction. By default not allowed.
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool IsInteractiveSetDefaultPermitted();
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  Helper objects that handle checking if Chrome is the default browser
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  or application for a url protocol on Windows and Linux, and also setting
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  it as the default. These operations are performed asynchronously on the
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  file thread since registry access (on Windows) or the preference database
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  (on Linux) are involved and this can be slow.
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DefaultWebClientWorker
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      : public base::RefCountedThreadSafe<DefaultWebClientWorker> {
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    explicit DefaultWebClientWorker(DefaultWebClientObserver* observer);
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Checks to see if Chrome is the default web client application. The result
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // will be passed back to the observer via the SetDefaultWebClientUIState
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // function. If there is no observer, this function does not do anything.
2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void StartCheckIsDefault();
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Sets Chrome as the default web client application. If there is an
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // observer, once the operation has completed the new default will be
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // queried and the current status reported via SetDefaultWebClientUIState.
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void StartSetAsDefault();
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Called to notify the worker that the view is gone.
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void ObserverDestroyed();
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    friend class base::RefCountedThreadSafe<DefaultWebClientWorker>;
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~DefaultWebClientWorker() {}
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Function that performs the check.
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual DefaultWebClientState CheckIsDefault() = 0;
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Function that sets Chrome as the default web client. Returns false if
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the operation fails or has been cancelled by the user.
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool SetAsDefault(bool interactive_permitted) = 0;
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Function that handles performing the check on the file thread. This
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // function is posted as a task onto the file thread, where it performs
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the check. When the check has finished the CompleteCheckIsDefault
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // function is posted to the UI thread, where the result is sent back to
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // the observer.
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void ExecuteCheckIsDefault();
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Function that handles setting Chrome as the default web client on the
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // file thread. This function is posted as a task onto the file thread.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Once it is finished the CompleteSetAsDefault function is posted to the
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // UI thread which will check the status of Chrome as the default, and
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // send this to the observer.
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // |interactive_permitted| indicates if the routine is allowed to carry on
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // in context where user interaction is required (CanSetAsDefault*
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // returns SET_DEFAULT_INTERACTIVE).
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void ExecuteSetAsDefault(bool interactive_permitted);
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Communicate results to the observer. This function is posted as a task
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // onto the UI thread by the ExecuteCheckIsDefault function running in the
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // file thread.
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void CompleteCheckIsDefault(DefaultWebClientState state);
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // When the action to set Chrome as the default has completed this function
2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // is run. It is posted as a task back onto the UI thread by the
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // ExecuteSetAsDefault function running in the file thread. This function
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // will the start the check process, which, if an observer is present,
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // reports to it the new status.
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // |succeeded| is true if the actual call to a set-default function (from
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // ExecuteSetAsDefault) was successful.
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void CompleteSetAsDefault(bool succeeded);
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Updates the UI in our associated view with the current default web
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // client state.
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    void UpdateUI(DefaultWebClientState state);
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DefaultWebClientObserver* observer_;
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(DefaultWebClientWorker);
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Worker for checking and setting the default browser.
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DefaultBrowserWorker : public DefaultWebClientWorker {
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    explicit DefaultBrowserWorker(DefaultWebClientObserver* observer);
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~DefaultBrowserWorker() {}
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Check if Chrome is the default browser.
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Set Chrome as the default browser.
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Worker for checking and setting the default client application
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // for a given protocol. A different worker instance is needed for each
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // protocol you are interested in, so to check or set the default for
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // multiple protocols you should use multiple worker objects.
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  class DefaultProtocolClientWorker : public DefaultWebClientWorker {
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   public:
2875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DefaultProtocolClientWorker(DefaultWebClientObserver* observer,
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                const std::string& protocol);
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const std::string& protocol() const { return protocol_; }
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   protected:
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual ~DefaultProtocolClientWorker() {}
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)   private:
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Check is Chrome is the default handler for this protocol.
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual DefaultWebClientState CheckIsDefault() OVERRIDE;
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Set Chrome as the default handler for this protocol.
3005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    virtual bool SetAsDefault(bool interactive_permitted) OVERRIDE;
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    std::string protocol_;
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    DISALLOW_COPY_AND_ASSIGN(DefaultProtocolClientWorker);
3055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CHROME_BROWSER_SHELL_INTEGRATION_H_
309