| Index: chrome/browser/ui/startup/default_browser_prompt.cc
|
| diff --git a/chrome/browser/ui/startup/default_browser_prompt.cc b/chrome/browser/ui/startup/default_browser_prompt.cc
|
| index 8765d386d80a1a3dbbaa14a796fac3be68b70d32..b423a00ad60c01494754b57090f70898f96e0b73 100644
|
| --- a/chrome/browser/ui/startup/default_browser_prompt.cc
|
| +++ b/chrome/browser/ui/startup/default_browser_prompt.cc
|
| @@ -4,16 +4,14 @@
|
|
|
| #include "chrome/browser/ui/startup/default_browser_prompt.h"
|
|
|
| +#include <limits>
|
| #include <string>
|
|
|
| #include "base/location.h"
|
| #include "base/macros.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "base/metrics/histogram_macros.h"
|
| -#include "base/metrics/user_metrics_action.h"
|
| #include "base/single_thread_task_runner.h"
|
| #include "base/strings/string_number_conversions.h"
|
| -#include "base/threading/thread_task_runner_handle.h"
|
| #include "base/time/time.h"
|
| #include "base/version.h"
|
| #include "build/build_config.h"
|
| @@ -23,195 +21,18 @@
|
| #include "chrome/browser/profiles/profile_manager.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_finder.h"
|
| +#include "chrome/browser/ui/startup/default_browser_infobar_delegate.h"
|
| #include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| #include "chrome/common/pref_names.h"
|
| -#include "chrome/grit/chromium_strings.h"
|
| -#include "chrome/grit/generated_resources.h"
|
| -#include "components/infobars/core/confirm_infobar_delegate.h"
|
| -#include "components/infobars/core/infobar.h"
|
| #include "components/prefs/pref_registry_simple.h"
|
| #include "components/prefs/pref_service.h"
|
| #include "components/variations/variations_associated_data.h"
|
| #include "components/version_info/version_info.h"
|
| -#include "content/public/browser/user_metrics.h"
|
| -#include "grit/theme_resources.h"
|
| -#include "ui/base/l10n/l10n_util.h"
|
| -#include "ui/gfx/vector_icons_public.h"
|
|
|
| -#if defined(OS_WIN)
|
| -#include "base/win/windows_version.h"
|
| -#endif
|
| +namespace chrome {
|
|
|
| namespace {
|
|
|
| -// The delegate for the infobar shown when Chrome is not the default browser.
|
| -// Ownership of the delegate is given to the infobar itself, the lifetime of
|
| -// which is bound to the containing WebContents.
|
| -class DefaultBrowserInfoBarDelegate : public ConfirmInfoBarDelegate {
|
| - public:
|
| - // Creates a default browser infobar and delegate and adds the infobar to
|
| - // |infobar_service|.
|
| - static void Create(InfoBarService* infobar_service, Profile* profile);
|
| -
|
| - private:
|
| - // Possible user interactions with the default browser info bar.
|
| - // Do not modify the ordering as it is important for UMA.
|
| - enum InfoBarUserInteraction {
|
| - // The user clicked the "OK" (i.e., "Set as default") button.
|
| - ACCEPT_INFO_BAR = 0,
|
| - // The user clicked the "Cancel" (i.e., "Don't ask again") button.
|
| - CANCEL_INFO_BAR = 1,
|
| - // The user did not interact with the info bar.
|
| - IGNORE_INFO_BAR = 2,
|
| - NUM_INFO_BAR_USER_INTERACTION_TYPES
|
| - };
|
| -
|
| - explicit DefaultBrowserInfoBarDelegate(Profile* profile);
|
| - ~DefaultBrowserInfoBarDelegate() override;
|
| -
|
| - void AllowExpiry() { should_expire_ = true; }
|
| -
|
| - // InfoBarDelegate:
|
| - Type GetInfoBarType() const override;
|
| - infobars::InfoBarDelegate::InfoBarIdentifier GetIdentifier() const override;
|
| - int GetIconId() const override;
|
| - gfx::VectorIconId GetVectorIconId() const override;
|
| - bool ShouldExpire(const NavigationDetails& details) const override;
|
| - void InfoBarDismissed() override;
|
| -
|
| - // ConfirmInfoBarDelegate:
|
| - base::string16 GetMessageText() const override;
|
| - base::string16 GetButtonLabel(InfoBarButton button) const override;
|
| - bool OKButtonTriggersUACPrompt() const override;
|
| - bool Accept() override;
|
| - bool Cancel() override;
|
| -
|
| - // The WebContents's corresponding profile.
|
| - Profile* profile_;
|
| -
|
| - // Whether the info-bar should be dismissed on the next navigation.
|
| - bool should_expire_ = false;
|
| -
|
| - // Used to delay the expiration of the info-bar.
|
| - base::WeakPtrFactory<DefaultBrowserInfoBarDelegate> weak_factory_;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(DefaultBrowserInfoBarDelegate);
|
| -};
|
| -
|
| -// static
|
| -void DefaultBrowserInfoBarDelegate::Create(InfoBarService* infobar_service,
|
| - Profile* profile) {
|
| - infobar_service->AddInfoBar(infobar_service->CreateConfirmInfoBar(
|
| - std::unique_ptr<ConfirmInfoBarDelegate>(
|
| - new DefaultBrowserInfoBarDelegate(profile))));
|
| -}
|
| -
|
| -DefaultBrowserInfoBarDelegate::DefaultBrowserInfoBarDelegate(Profile* profile)
|
| - : ConfirmInfoBarDelegate(), profile_(profile), weak_factory_(this) {
|
| - // We want the info-bar to stick-around for few seconds and then be hidden
|
| - // on the next navigation after that.
|
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
|
| - FROM_HERE, base::Bind(&DefaultBrowserInfoBarDelegate::AllowExpiry,
|
| - weak_factory_.GetWeakPtr()),
|
| - base::TimeDelta::FromSeconds(8));
|
| -}
|
| -
|
| -DefaultBrowserInfoBarDelegate::~DefaultBrowserInfoBarDelegate() = default;
|
| -
|
| -infobars::InfoBarDelegate::Type DefaultBrowserInfoBarDelegate::GetInfoBarType()
|
| - const {
|
| -#if defined(OS_WIN)
|
| - return WARNING_TYPE;
|
| -#else
|
| - return PAGE_ACTION_TYPE;
|
| -#endif
|
| -}
|
| -
|
| -infobars::InfoBarDelegate::InfoBarIdentifier
|
| -DefaultBrowserInfoBarDelegate::GetIdentifier() const {
|
| - return DEFAULT_BROWSER_INFOBAR_DELEGATE;
|
| -}
|
| -
|
| -int DefaultBrowserInfoBarDelegate::GetIconId() const {
|
| - return IDR_PRODUCT_LOGO_32;
|
| -}
|
| -
|
| -gfx::VectorIconId DefaultBrowserInfoBarDelegate::GetVectorIconId() const {
|
| -#if defined(OS_MACOSX) || defined(OS_ANDROID)
|
| - return gfx::VectorIconId::VECTOR_ICON_NONE;
|
| -#else
|
| - return gfx::VectorIconId::CHROME_PRODUCT;
|
| -#endif
|
| -}
|
| -
|
| -bool DefaultBrowserInfoBarDelegate::ShouldExpire(
|
| - const NavigationDetails& details) const {
|
| - return should_expire_ && ConfirmInfoBarDelegate::ShouldExpire(details);
|
| -}
|
| -
|
| -void DefaultBrowserInfoBarDelegate::InfoBarDismissed() {
|
| - content::RecordAction(
|
| - base::UserMetricsAction("DefaultBrowserInfoBar_Dismiss"));
|
| - UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
|
| - IGNORE_INFO_BAR,
|
| - NUM_INFO_BAR_USER_INTERACTION_TYPES);
|
| -}
|
| -
|
| -base::string16 DefaultBrowserInfoBarDelegate::GetMessageText() const {
|
| - return l10n_util::GetStringUTF16(IDS_DEFAULT_BROWSER_INFOBAR_SHORT_TEXT);
|
| -}
|
| -
|
| -base::string16 DefaultBrowserInfoBarDelegate::GetButtonLabel(
|
| - InfoBarButton button) const {
|
| -#if defined(OS_WIN)
|
| - // On Windows 10, the "OK" button opens the Windows Settings application,
|
| - // through which the user must make their default browser choice.
|
| - const int kSetAsDefaultButtonMessageId =
|
| - base::win::GetVersion() >= base::win::VERSION_WIN10
|
| - ? IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL_WIN_10
|
| - : IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
|
| -#else
|
| - const int kSetAsDefaultButtonMessageId =
|
| - IDS_DEFAULT_BROWSER_INFOBAR_OK_BUTTON_LABEL;
|
| -#endif
|
| - return l10n_util::GetStringUTF16(
|
| - button == BUTTON_OK ? kSetAsDefaultButtonMessageId
|
| - : IDS_DEFAULT_BROWSER_INFOBAR_CANCEL_BUTTON_LABEL);
|
| -}
|
| -
|
| -// Setting an app as the default browser doesn't require elevation directly, but
|
| -// it does require registering it as the protocol handler for "http", so if
|
| -// protocol registration in general requires elevation, this does as well.
|
| -bool DefaultBrowserInfoBarDelegate::OKButtonTriggersUACPrompt() const {
|
| - return shell_integration::IsElevationNeededForSettingDefaultProtocolClient();
|
| -}
|
| -
|
| -bool DefaultBrowserInfoBarDelegate::Accept() {
|
| - content::RecordAction(
|
| - base::UserMetricsAction("DefaultBrowserInfoBar_Accept"));
|
| - UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
|
| - ACCEPT_INFO_BAR,
|
| - NUM_INFO_BAR_USER_INTERACTION_TYPES);
|
| - // The worker pointer is reference counted. While it is running, the
|
| - // message loops of the FILE and UI thread will hold references to it
|
| - // and it will be automatically freed once all its tasks have finished.
|
| - scoped_refptr<shell_integration::DefaultBrowserWorker>(
|
| - new shell_integration::DefaultBrowserWorker(
|
| - shell_integration::DefaultWebClientWorkerCallback()))
|
| - ->StartSetAsDefault();
|
| - return true;
|
| -}
|
| -
|
| -bool DefaultBrowserInfoBarDelegate::Cancel() {
|
| - chrome::DefaultBrowserPromptDeclined(profile_);
|
| - content::RecordAction(
|
| - base::UserMetricsAction("DefaultBrowserInfoBar_Cancel"));
|
| - UMA_HISTOGRAM_ENUMERATION("DefaultBrowser.InfoBar.UserInteraction",
|
| - CANCEL_INFO_BAR,
|
| - NUM_INFO_BAR_USER_INTERACTION_TYPES);
|
| - return true;
|
| -}
|
| -
|
| void ResetCheckDefaultBrowserPref(const base::FilePath& profile_path) {
|
| Profile* profile =
|
| g_browser_process->profile_manager()->GetProfileByPath(profile_path);
|
| @@ -287,8 +108,6 @@ void OnCheckIsDefaultBrowserFinished(
|
|
|
| } // namespace
|
|
|
| -namespace chrome {
|
| -
|
| void RegisterDefaultBrowserPromptPrefs(PrefRegistrySimple* registry) {
|
| registry->RegisterStringPref(
|
| prefs::kBrowserSuppressDefaultBrowserPrompt, std::string());
|
|
|