Skip to content

Commit

Permalink
Merge pull request #8253 from brave/default_browser_prompt
Browse files Browse the repository at this point in the history
Add don't ask again checkbox to default browser prompt
  • Loading branch information
simonhong authored Apr 6, 2021
2 parents 18adec8 + ef4d703 commit de13afc
Show file tree
Hide file tree
Showing 10 changed files with 36 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 @@ -967,9 +967,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 disabling 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
2 changes: 2 additions & 0 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
BraveWindowTracker::RegisterPrefs(registry);
BraveUptimeTracker::RegisterPrefs(registry);
dark_mode::RegisterBraveDarkModeLocalStatePrefs(registry);

registry->RegisterBooleanPref(kDefaultBrowserPromptEnabled, true);
#endif

#if BUILDFLAG(ENABLE_WIDEVINE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "brave/components/brave_wallet/common/buildflags/buildflags.h"
#include "brave/components/brave_wayback_machine/buildflags.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
Expand Down Expand Up @@ -36,6 +37,7 @@
#endif

using BraveProfilePrefsBrowserTest = InProcessBrowserTest;
using BraveLocalStatePrefsBrowserTest = InProcessBrowserTest;

// Check download prompt preference is set to true by default.
IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DownloadPromptDefault) {
Expand Down Expand Up @@ -123,3 +125,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
EXPECT_TRUE(
browser()->profile()->GetPrefs()->GetBoolean(prefs::kHideWebStoreIcon));
}

IN_PROC_BROWSER_TEST_F(BraveLocalStatePrefsBrowserTest, DefaultLocalStateTest) {
EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(
kDefaultBrowserPromptEnabled));
}
1 change: 1 addition & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ source_set("ui") {
"//brave/ui/brave_ads/public/cpp",
"//chrome/app:command_ids",
"//chrome/app/vector_icons:vector_icons",
"//chrome/browser:browser_process",
"//chrome/common",
"//chrome/services/qrcode_generator",
"//components/content_settings/browser",
Expand Down
7 changes: 5 additions & 2 deletions browser/ui/startup/default_brave_browser_prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,18 @@ void ShowDefaultBraveBrowserPrompt(Profile* profile) {
return;
#endif

PrefService* local_prefs = g_browser_process->local_state();
// Do not check if Chrome is the default browser if there is a policy in
// control of this setting.
if (g_browser_process->local_state()->IsManagedPreference(
prefs::kDefaultBrowserSettingEnabled)) {
if (local_prefs->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) {
// Handling of the browser.default_browser_setting_enabled policy setting is
// taken care of in BrowserProcessImpl.
return;
}

if (!local_prefs->GetBoolean(kDefaultBrowserPromptEnabled))
return;

PrefService* prefs = profile->GetPrefs();
// Reset preferences if kResetCheckDefaultBrowser is true.
if (prefs->GetBoolean(prefs::kResetCheckDefaultBrowser)) {
Expand Down
13 changes: 11 additions & 2 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/browser_process.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 Down Expand Up @@ -105,7 +110,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 +151,8 @@ void BraveDefaultBrowserDialogView::OnDialogInitialized() {
}

void BraveDefaultBrowserDialogView::OnCancelButtonClicked() {
// Do nothing.
g_browser_process->local_state()->SetBoolean(
kDefaultBrowserPromptEnabled, !dont_ask_again_checkbox_->GetChecked());
}

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

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

Expand All @@ -37,6 +38,7 @@ class BraveDefaultBrowserDialogView : public views::DialogDelegateView {

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 kDefaultBrowserPromptEnabled[] =
"brave.default_browser_prompot_enabled";

This comment has been minimized.

Copy link
@stephendonner

stephendonner Apr 7, 2021

Contributor

@simonhong _prompot_enabled looks to be a typo, here, just FYI

This comment has been minimized.

Copy link
@simonhong

simonhong Apr 7, 2021

Author Member

@stephendonner Thanks for catching. Pushed #8474

#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 kDefaultBrowserPromptEnabled[];
#if !BUILDFLAG(USE_GCM_FROM_PLATFORM)
extern const char kBraveGCMChannelStatus[];
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ if (!is_android) {
"//brave/app/brave_main_delegate_browsertest.cc",
"//brave/app/brave_main_delegate_runtime_flags_browsertest.cc",
"//brave/browser/brave_content_browser_client_browsertest.cc",
"//brave/browser/brave_profile_prefs_browsertest.cc",
"//brave/browser/brave_prefs_browsertest.cc",
"//brave/browser/brave_resources_browsertest.cc",
"//brave/browser/brave_scheme_load_browsertest.cc",
"//brave/browser/brave_search/brave_search_browsertest.cc",
Expand Down

0 comments on commit de13afc

Please sign in to comment.