Skip to content

Commit

Permalink
Add don't ask again checkbox to default browser prompt
Browse files Browse the repository at this point in the history
Default browser prompot is disabled if it's checked.

fix brave/brave-browser#14469
  • Loading branch information
simonhong committed Mar 15, 2021
1 parent 344fe30 commit 0460237
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 8 deletions.
7 changes: 4 additions & 3 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,10 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Set Brave as your default browser
</message>
<message name="IDS_BRAVE_DEFAULT_BROWSER_DIALOG_CONTENTS_TEXT" desc="The contents for default browser dialog">
Brave browser is currently not set as your default browser.
Set Brave as your default to keep browsing the web faster -
up to 6x faster on major news sites.
Keep browsing the web faster - up to 6x faster on major news sites.
</message>
<message name="IDS_BRAVE_DEFAULT_BROWSER_DIALOG_DONT_ASK" desc="The text for diabling default browser dialog checkbox">
Don't ask again
</message>
<message name="IDS_BRAVE_DEFAULT_BROWSER_DIALOG_OK_BUTTON_LABEL" desc="The text for default browser dialog ok button">
Set as default
Expand Down
1 change: 1 addition & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// if widevine is disabled.
// F/u issue: https://github.com/brave/brave-browser/issues/7000
registry->RegisterBooleanPref(kAskWidevineInstall, true);
registry->RegisterBooleanPref(kDefaultBrowserPromptDisabled, false);

// Default Brave shields
registry->RegisterBooleanPref(kHTTPSEVerywhereControlType, true);
Expand Down
2 changes: 2 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DownloadPromptDefault) {
}

IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) {
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
kDefaultBrowserPromptDisabled));
EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
kHTTPSEVerywhereControlType));
EXPECT_FALSE(
Expand Down
3 changes: 3 additions & 0 deletions browser/ui/startup/default_brave_browser_prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ void ShowDefaultBraveBrowserPrompt(Profile* profile) {
}

PrefService* prefs = profile->GetPrefs();
if (prefs->GetBoolean(kDefaultBrowserPromptDisabled))
return;

// Reset preferences if kResetCheckDefaultBrowser is true.
if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) {
prefs->SetBoolean(prefs::kResetCheckDefaultBrowser, false);
Expand Down
19 changes: 15 additions & 4 deletions browser/ui/views/brave_default_browser_dialog_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "brave/browser/ui/browser_dialogs.h"
#include "brave/common/pref_names.h"
#include "brave/grit/brave_generated_resources.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "components/constrained_window/constrained_window_views.h"
#include "components/prefs/pref_service.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/layout_provider.h"
Expand All @@ -24,7 +29,8 @@ namespace brave {

void ShowDefaultBrowserDialog(Browser* browser) {
constrained_window::CreateBrowserModalDialogViews(
new BraveDefaultBrowserDialogView(), browser->window()->GetNativeWindow())
new BraveDefaultBrowserDialogView(browser->profile()),
browser->window()->GetNativeWindow())
->Show();
}

Expand Down Expand Up @@ -54,7 +60,8 @@ class NoSnappedBubbleFrameView : public views::BubbleFrameView {

} // namespace

BraveDefaultBrowserDialogView::BraveDefaultBrowserDialogView() {
BraveDefaultBrowserDialogView::BraveDefaultBrowserDialogView(Profile* profile)
: profile_(profile) {
SetButtonLabel(ui::DIALOG_BUTTON_OK,
l10n_util::GetStringUTF16(
IDS_BRAVE_DEFAULT_BROWSER_DIALOG_OK_BUTTON_LABEL));
Expand Down Expand Up @@ -105,7 +112,10 @@ void BraveDefaultBrowserDialogView::CreateChildViews() {
contents_font));
contents_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
contents_label_->SetMultiLine(true);
contents_label_->SetMaxLines(3);
contents_label_->SetMaximumWidth(350);

dont_ask_again_checkbox_ = AddChildView(std::make_unique<views::Checkbox>(
l10n_util::GetStringUTF16(IDS_BRAVE_DEFAULT_BROWSER_DIALOG_DONT_ASK)));
}

std::unique_ptr<views::NonClientFrameView>
Expand Down Expand Up @@ -143,7 +153,8 @@ void BraveDefaultBrowserDialogView::OnDialogInitialized() {
}

void BraveDefaultBrowserDialogView::OnCancelButtonClicked() {
// Do nothing.
profile_->GetPrefs()->SetBoolean(kDefaultBrowserPromptDisabled,
dont_ask_again_checkbox_->GetChecked());
}

void BraveDefaultBrowserDialogView::OnAcceptButtonClicked() {
Expand Down
7 changes: 6 additions & 1 deletion browser/ui/views/brave_default_browser_dialog_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
#include "ui/views/window/dialog_delegate.h"

namespace views {
class Checkbox;
class Label;
} // namespace views

class Profile;

class BraveDefaultBrowserDialogView : public views::DialogDelegateView {
public:
BraveDefaultBrowserDialogView();
explicit BraveDefaultBrowserDialogView(Profile* profile);
~BraveDefaultBrowserDialogView() override;

BraveDefaultBrowserDialogView(const BraveDefaultBrowserDialogView&) = delete;
Expand All @@ -35,8 +38,10 @@ class BraveDefaultBrowserDialogView : public views::DialogDelegateView {
void OnAcceptButtonClicked();
void CreateChildViews();

Profile* profile_ = nullptr;
views::Label* header_label_ = nullptr;
views::Label* contents_label_ = nullptr;
views::Checkbox* dont_ask_again_checkbox_ = nullptr;
};

#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_DEFAULT_BROWSER_DIALOG_VIEW_H_
2 changes: 2 additions & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ const char kBraveSuggestedSiteSuggestionsEnabled[] =
const char kBraveDarkMode[] = "brave.dark_mode";
const char kOtherBookmarksMigrated[] = "brave.other_bookmarks_migrated";
const char kBraveShieldsSettingsVersion[] = "brave.shields_settings_version";
const char kDefaultBrowserPromptDisabled[] =
"brave.default_browser_prompot_disabled";
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
const char kBraveGCMChannelStatus[] = "brave.gcm.channel_status";
#endif
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ extern const char kOtherBookmarksMigrated[];
extern const char kBraveShieldsSettingsVersion[];
extern const char kBinanceAccessToken[];
extern const char kBinanceRefreshToken[];
extern const char kDefaultBrowserPromptDisabled[];
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
extern const char kBraveGCMChannelStatus[];
#endif
Expand Down

0 comments on commit 0460237

Please sign in to comment.