summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 23:13:32 +0000
committerjcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-01 23:13:32 +0000
commit8313fef77dd4f51e2c96bc47e8a20c0601eb9312 (patch)
treec1de06f8518307f0af8131b33328da78df7344d4
parentcbc5da797407079b913d53a65f326083399b2088 (diff)
downloadchromium_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
-rw-r--r--chrome/browser/browser.cc1
-rw-r--r--chrome/browser/browser_init.cc122
-rw-r--r--chrome/browser/browser_init.h4
-rw-r--r--chrome/browser/first_run.cc13
-rw-r--r--chrome/browser/views/options/general_page_view.cc3
-rw-r--r--chrome/common/pref_names.cc4
-rw-r--r--chrome/common/pref_names.h2
7 files changed, 146 insertions, 3 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index ac79476..c5762fe 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -1174,6 +1174,7 @@ void Browser::RegisterUserPrefs(PrefService* prefs) {
prefs->RegisterBooleanPref(prefs::kDeletePasswords, false);
prefs->RegisterBooleanPref(prefs::kDeleteFormData, true);
prefs->RegisterIntegerPref(prefs::kDeleteTimePeriod, 0);
+ prefs->RegisterBooleanPref(prefs::kCheckDefaultBrowser, true);
}
// static
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) {
diff --git a/chrome/browser/browser_init.h b/chrome/browser/browser_init.h
index a456d5d..6be28502 100644
--- a/chrome/browser/browser_init.h
+++ b/chrome/browser/browser_init.h
@@ -78,6 +78,10 @@ class BrowserInit {
// Adds additional startup URLs to the specified vector.
void AddStartupURLs(std::vector<GURL>* startup_urls) const;
+ // Checks whether Chrome is still the default browser (unless the user
+ // previously instructed not to do so) and warns the user if it is not.
+ void CheckDefaultBrowser(Profile* profile);
+
std::wstring cur_dir_;
const CommandLine& command_line_;
Profile* profile_;
diff --git a/chrome/browser/first_run.cc b/chrome/browser/first_run.cc
index c402812..d14e0c1 100644
--- a/chrome/browser/first_run.cc
+++ b/chrome/browser/first_run.cc
@@ -154,11 +154,18 @@ bool WriteEULAtoTempFile(FilePath* eula_path) {
} // namespace
bool FirstRun::IsChromeFirstRun() {
+ // A troolean, 0 means not yet set, 1 means set to true, 2 set to false.
+ static int first_run = 0;
+ if (first_run != 0)
+ return first_run == 1;
+
std::wstring first_run_sentinel;
- if (!GetFirstRunSentinelFilePath(&first_run_sentinel))
- return false;
- if (file_util::PathExists(first_run_sentinel))
+ if (!GetFirstRunSentinelFilePath(&first_run_sentinel) ||
+ file_util::PathExists(first_run_sentinel)) {
+ first_run = 2;
return false;
+ }
+ first_run = 1;
return true;
}
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index a314fe7..4fd0801 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -581,6 +581,9 @@ void GeneralPageView::ButtonPressed(views::Button* sender) {
} else if (sender == default_browser_use_as_default_button_) {
default_browser_worker_->StartSetAsDefaultBrowser();
UserMetricsRecordAction(L"Options_SetAsDefaultBrowser", NULL);
+ // If the user made Chrome the default browser, then he/she arguably wants
+ // to be notified when that changes.
+ profile()->GetPrefs()->SetBoolean(prefs::kCheckDefaultBrowser, true);
} else if (sender == default_search_manage_engines_button_) {
UserMetricsRecordAction(L"Options_ManageSearchEngines", NULL);
KeywordEditorView::Show(profile());
diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc
index 77a6aff..aaf54cc 100644
--- a/chrome/common/pref_names.cc
+++ b/chrome/common/pref_names.cc
@@ -243,6 +243,10 @@ const wchar_t kPrintingPageFooterLeft[] = L"printing.page.footer.left";
const wchar_t kPrintingPageFooterCenter[] = L"printing.page.footer.center";
const wchar_t kPrintingPageFooterRight[] = L"printing.page.footer.right";
+// Boolean that indicates whether we should check if we are the default browser
+// on start-up.
+const wchar_t kCheckDefaultBrowser[] = L"browser.check_default_browser";
+
// *************** LOCAL STATE ***************
// These are attached to the machine/installation
diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h
index a9a37ab..53385fd 100644
--- a/chrome/common/pref_names.h
+++ b/chrome/common/pref_names.h
@@ -87,6 +87,8 @@ extern const wchar_t kPrintingPageHeaderRight[];
extern const wchar_t kPrintingPageFooterLeft[];
extern const wchar_t kPrintingPageFooterCenter[];
extern const wchar_t kPrintingPageFooterRight[];
+extern const wchar_t kCheckDefaultBrowser[];
+
// Local state
extern const wchar_t kAvailableProfiles[];