diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 23:13:32 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-01 23:13:32 +0000 |
commit | 8313fef77dd4f51e2c96bc47e8a20c0601eb9312 (patch) | |
tree | c1de06f8518307f0af8131b33328da78df7344d4 /chrome/browser/browser_init.cc | |
parent | cbc5da797407079b913d53a65f326083399b2088 (diff) | |
download | chromium_src-8313fef77dd4f51e2c96bc47e8a20c0601eb9312.zip chromium_src-8313fef77dd4f51e2c96bc47e8a20c0601eb9312.tar.gz chromium_src-8313fef77dd4f51e2c96bc47e8a20c0601eb9312.tar.bz2 |
If Chrome is not the default browser, tell the user, unless:
- it is the first run
- the user already said not to warn him/her about it
- an info-bar is already showing.
BUG=9049
TEST=Run a new install of chrome, proceed through the first run flow, don't
make Chrome your default browser. No info-bar warning about Chrome not
being the default browser should be shown.
Restart Chrome, such an info-bar should be shown. Click the x on the
info-bar to close it. Restart Chrome. The info-bar should be shown.
Select "Set as default". Restart Chrome, the info-bar should not be shown.
Start IE, make it your default browser (Tools menu, 'Internet option',
Programs tab). Restart Chrome, it should show the default browser info-bar.
Select "Don't ask me again". Restart Chrome, the info-bar should not be
shown.
Review URL: http://codereview.chromium.org/99301
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15115 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_init.cc')
-rw-r--r-- | chrome/browser/browser_init.cc | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index 88eae8b..bc47d65 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -18,12 +18,14 @@ #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/first_run.h" #include "chrome/browser/net/dns_global.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/session_startup_pref.h" #include "chrome/browser/sessions/session_restore.h" +#include "chrome/browser/shell_integration.h" #include "chrome/browser/tab_contents/infobar_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/web_contents.h" @@ -54,6 +56,112 @@ namespace { +class SetAsDefaultBrowserTask : public Task { + public: + SetAsDefaultBrowserTask() { } + virtual void Run() { + ShellIntegration::SetAsDefaultBrowser(); + } + + private: + DISALLOW_COPY_AND_ASSIGN(SetAsDefaultBrowserTask); +}; + +// The delegate for the infobar shown when Chrome is not the default browser. +class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate { + public: + explicit DefaultBrowserInfoBarDelegate(TabContents* contents) + : ConfirmInfoBarDelegate(contents), + profile_(contents->profile()), + action_taken_(false) { + } + + // Overridden from ConfirmInfoBarDelegate: + virtual void InfoBarClosed() { + if (!action_taken_) + UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.Ignored", 1); + delete this; + } + + virtual std::wstring GetMessageText() const { + return l10n_util::GetString(IDS_DEFAULT_BROWSER_INFOBAR_TEXT); + } + + virtual SkBitmap* GetIcon() const { + return NULL; + } + + virtual int GetButtons() const { return BUTTON_OK | BUTTON_CANCEL; } + + virtual std::wstring GetButtonLabel(InfoBarButton button) const { + return button == BUTTON_OK ? + l10n_util::GetString(IDS_SET_AS_DEFAULT_INFOBAR_BUTTON_LABEL) : + l10n_util::GetString(IDS_DONT_ASK_AGAIN_INFOBAR_BUTTON_LABEL); + } + + virtual bool Accept() { + action_taken_ = true; + UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.SetAsDefault", 1); + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + new SetAsDefaultBrowserTask()); + return true; + } + + virtual bool Cancel() { + action_taken_ = true; + UMA_HISTOGRAM_COUNTS("DefaultBrowserWarning.DontSetAsDefault", 1); + // User clicked "Don't ask me again", remember that. + profile_->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, false); + return true; + } + + private: + // The Profile that we restore sessions from. + Profile* profile_; + + // Whether the user clicked one of the buttons. + bool action_taken_; + + DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate); +}; + +class NotifyNotDefaultBrowserTask : public Task { + public: + NotifyNotDefaultBrowserTask() { } + + virtual void Run() { + Browser* browser = BrowserList::GetLastActive(); + if (!browser) { + NOTREACHED(); + return; + } + TabContents* tab = browser->GetSelectedTabContents(); + // Don't show the info-bar if there are already info-bars showing. + if (tab->infobar_delegate_count() > 0) + return; + tab->AddInfoBar(new DefaultBrowserInfoBarDelegate(tab)); + } + + private: + DISALLOW_COPY_AND_ASSIGN(NotifyNotDefaultBrowserTask); +}; + +class CheckDefaultBrowserTask : public Task { + public: + explicit CheckDefaultBrowserTask(MessageLoop* ui_loop) : ui_loop_(ui_loop) { + } + + virtual void Run() { + if (!ShellIntegration::IsDefaultBrowser()) + ui_loop_->PostTask(FROM_HERE, new NotifyNotDefaultBrowserTask()); + } + + private: + MessageLoop* ui_loop_; + + DISALLOW_COPY_AND_ASSIGN(CheckDefaultBrowserTask); +}; + // A delegate for the InfoBar shown when the previous session has crashed. The // bar deletes itself automatically after it is closed. // TODO(timsteele): This delegate can leak when a tab is closed, see @@ -244,6 +352,8 @@ bool BrowserInit::LaunchWithProfile::Launch(Profile* profile, browser = BrowserList::GetLastActive(); OpenURLsInBrowser(browser, process_startup, urls_to_open); } + // Check whether we are the default browser. + CheckDefaultBrowser(profile); } else { RecordLaunchModeHistogram(LM_AS_WEBAPP); } @@ -408,6 +518,18 @@ void BrowserInit::LaunchWithProfile::AddStartupURLs( } } +void BrowserInit::LaunchWithProfile::CheckDefaultBrowser(Profile* profile) { + // We do not check if we are the default browser if: + // - the user said "don't ask me again" on the infobar earlier. + // - this is the first launch after the first run flow. + if (!profile->GetPrefs()->GetBoolean(prefs::kCheckDefaultBrowser) || + FirstRun::IsChromeFirstRun()) { + return; + } + g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, + new CheckDefaultBrowserTask(MessageLoop::current())); +} + bool BrowserInit::ProcessCommandLine( const CommandLine& command_line, const std::wstring& cur_dir, bool process_startup, Profile* profile, int* return_code) { |