blob: daecacf1246f20b95046347188e5fffa97daeee6 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// Copyright (c) 2006-2008 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.
initial.commit09911bf2008-07-26 23:55:294
5#ifndef CHROME_BROWSER_SHELL_INTEGRATION_H__
6#define CHROME_BROWSER_SHELL_INTEGRATION_H__
7
8#include <string>
9
[email protected]b96aa932009-08-12 21:34:4910#include "base/basictypes.h"
[email protected]d24c4012009-07-28 01:57:3111#include "base/ref_counted.h"
[email protected]b96aa932009-08-12 21:34:4912#include "base/string16.h"
[email protected]42896802009-08-28 23:39:4413#include "googleurl/src/gurl.h"
[email protected]d24c4012009-07-28 01:57:3114
[email protected]b96aa932009-08-12 21:34:4915class FilePath;
[email protected]d24c4012009-07-28 01:57:3116class MessageLoop;
17
initial.commit09911bf2008-07-26 23:55:2918class ShellIntegration {
19 public:
initial.commit09911bf2008-07-26 23:55:2920 // Sets Chrome as default browser (only for current user). Returns false if
21 // this operation fails.
22 static bool SetAsDefaultBrowser();
23
[email protected]264f74d12009-09-04 23:39:5824 // On Linux, it may not be possible to determine or set the default browser
25 // on some desktop environments or configurations. So, we use this enum and
26 // not a plain bool. (Note however that if used like a bool, this enum will
27 // have reasonable behavior.)
28 enum DefaultBrowserState {
29 NOT_DEFAULT_BROWSER = 0,
30 IS_DEFAULT_BROWSER,
31 UNKNOWN_DEFAULT_BROWSER
32 };
33
34 // Attempt to determine if this instance of Chrome is the default browser and
35 // return the appropriate state. (Defined as being the handler for HTTP/HTTPS
36 // protocols; we don't want to report "no" here if the user has simply chosen
37 // to open HTML files in a text editor and FTP links with an FTP client.)
38 static DefaultBrowserState IsDefaultBrowser();
initial.commit09911bf2008-07-26 23:55:2939
[email protected]cd63ef62009-05-06 19:41:3740 // Returns true if Firefox is likely to be the default browser for the current
initial.commit09911bf2008-07-26 23:55:2941 // user. This method is very fast so it can be invoked in the UI thread.
42 static bool IsFirefoxDefaultBrowser();
[email protected]d24c4012009-07-28 01:57:3143
[email protected]b96aa932009-08-12 21:34:4944#if defined(OS_LINUX)
45 // Returns filename for .desktop file based on |url|, sanitized for security.
46 static FilePath GetDesktopShortcutFilename(const GURL& url);
47
48 // Returns contents for .desktop file based on |template_contents|, |url|
49 // and |title|. The |template_contents| should be contents of .desktop file
50 // used to launch Chrome.
51 static std::string GetDesktopFileContents(
52 const std::string& template_contents, const GURL& url,
53 const string16& title);
54
[email protected]42896802009-08-28 23:39:4455 struct ShortcutInfo {
56 GURL url;
57 string16 title;
58
59 bool create_on_desktop;
60 bool create_in_applications_menu;
61 };
62
63 // Creates a desktop shortcut. It is not guaranteed to exist immediately after
64 // returning from this function, because actual file operation is done on the
65 // file thread.
66 static void CreateDesktopShortcut(const ShortcutInfo& shortcut_info);
[email protected]b96aa932009-08-12 21:34:4967#endif // defined(OS_LINUX)
[email protected]d24c4012009-07-28 01:57:3168
69 // The current default browser UI state
70 enum DefaultBrowserUIState {
71 STATE_PROCESSING,
[email protected]264f74d12009-09-04 23:39:5872 STATE_NOT_DEFAULT,
73 STATE_IS_DEFAULT,
74 STATE_UNKNOWN
[email protected]d24c4012009-07-28 01:57:3175 };
76
77 class DefaultBrowserObserver {
78 public:
79 // Updates the UI state to reflect the current default browser state.
80 virtual void SetDefaultBrowserUIState(DefaultBrowserUIState state) = 0;
81 virtual ~DefaultBrowserObserver() {}
82 };
83 // A helper object that handles checking if Chrome is the default browser on
84 // Windows and also setting it as the default browser. These operations are
85 // performed asynchronously on the file thread since registry access is
86 // involved and this can be slow.
87 //
88 class DefaultBrowserWorker
89 : public base::RefCountedThreadSafe<DefaultBrowserWorker> {
90 public:
91 explicit DefaultBrowserWorker(DefaultBrowserObserver* observer);
92 virtual ~DefaultBrowserWorker() {}
93
94 // Checks if Chrome is the default browser.
95 void StartCheckDefaultBrowser();
96
97 // Sets Chrome as the default browser.
98 void StartSetAsDefaultBrowser();
99
100 // Called to notify the worker that the view is gone.
101 void ObserverDestroyed();
102
103 private:
104 // Functions that track the process of checking if Chrome is the default
105 // browser. |ExecuteCheckDefaultBrowser| checks the registry on the file
106 // thread. |CompleteCheckDefaultBrowser| notifies the view to update on the
107 // UI thread.
108 void ExecuteCheckDefaultBrowser();
[email protected]264f74d12009-09-04 23:39:58109 void CompleteCheckDefaultBrowser(DefaultBrowserState state);
[email protected]d24c4012009-07-28 01:57:31110
111 // Functions that track the process of setting Chrome as the default
112 // browser. |ExecuteSetAsDefaultBrowser| updates the registry on the file
113 // thread. |CompleteSetAsDefaultBrowser| notifies the view to update on the
114 // UI thread.
115 void ExecuteSetAsDefaultBrowser();
116 void CompleteSetAsDefaultBrowser();
117
118 // Updates the UI in our associated view with the current default browser
119 // state.
[email protected]264f74d12009-09-04 23:39:58120 void UpdateUI(DefaultBrowserState state);
[email protected]d24c4012009-07-28 01:57:31121
122 DefaultBrowserObserver* observer_;
123
124 MessageLoop* ui_loop_;
125 MessageLoop* file_loop_;
126
127 DISALLOW_COPY_AND_ASSIGN(DefaultBrowserWorker);
128 };
initial.commit09911bf2008-07-26 23:55:29129};
130
131#endif // CHROME_BROWSER_SHELL_INTEGRATION_H__