Skip to content

Commit

Permalink
Uplift of #11125 (squashed) to release
Browse files Browse the repository at this point in the history
  • Loading branch information
brave-browser-releases authored and simonhong committed Nov 23, 2021
1 parent 89db54a commit 436f1fb
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 2 deletions.
47 changes: 47 additions & 0 deletions browser/brave_shell_integration.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/brave_shell_integration.h"

#if defined(OS_WIN)
#include <shlobj.h>

#include <utility>

#include "brave/browser/default_protocol_handler_utils_win.h"
#include "chrome/installer/util/shell_util.h"
#endif

namespace shell_integration {

BraveDefaultBrowserWorker::BraveDefaultBrowserWorker() = default;
BraveDefaultBrowserWorker::~BraveDefaultBrowserWorker() = default;

void BraveDefaultBrowserWorker::SetAsDefaultImpl(
base::OnceClosure on_finished_callback) {
#if defined(OS_WIN)
if (GetDefaultWebClientSetPermission() != SET_DEFAULT_NOT_ALLOWED) {
bool success = false;
const wchar_t* kAssociations[] = {L"https", L"http", L".html", L".htm"};
for (const wchar_t* association : kAssociations) {
success =
protocol_handler_utils::SetDefaultProtocolHandlerFor(association);
if (!success)
break;
}

if (success) {
std::move(on_finished_callback).Run();

// Notify shell to refresh icons
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
return;
}
}
#endif
DefaultBrowserWorker::SetAsDefaultImpl(std::move(on_finished_callback));
}

} // namespace shell_integration
29 changes: 29 additions & 0 deletions browser/brave_shell_integration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_H_
#define BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_H_

#include "chrome/browser/shell_integration.h"

namespace shell_integration {

class BraveDefaultBrowserWorker : public DefaultBrowserWorker {
public:
BraveDefaultBrowserWorker();

BraveDefaultBrowserWorker(const BraveDefaultBrowserWorker&) = delete;
BraveDefaultBrowserWorker& operator=(const BraveDefaultBrowserWorker&) =
delete;

protected:
~BraveDefaultBrowserWorker() override;

void SetAsDefaultImpl(base::OnceClosure on_finished_callback) override;
};

} // namespace shell_integration

#endif // BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_H_
2 changes: 2 additions & 0 deletions browser/sources.gni
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ brave_chrome_browser_sources = [
"//brave/browser/brave_local_state_prefs.h",
"//brave/browser/brave_profile_prefs.cc",
"//brave/browser/brave_profile_prefs.h",
"//brave/browser/brave_shell_integration.cc",
"//brave/browser/brave_shell_integration.h",
"//brave/browser/brave_tab_helpers.cc",
"//brave/browser/brave_tab_helpers.h",
"//brave/browser/browser_context_keyed_service_factories.cc",
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/brave_default_browser_dialog_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

#include "base/bind.h"
#include "base/memory/scoped_refptr.h"
#include "brave/browser/brave_shell_integration.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"
Expand Down Expand Up @@ -159,6 +159,6 @@ void BraveDefaultBrowserDialogView::OnAcceptButtonClicked() {
// 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.
base::MakeRefCounted<shell_integration::DefaultBrowserWorker>()
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
->StartSetAsDefault(base::NullCallback());
}
15 changes: 15 additions & 0 deletions chromium_src/chrome/browser/shell_integration.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SHELL_INTEGRATION_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SHELL_INTEGRATION_H_

#define BRAVE_DEFAULT_BROWSER_WORKER_H friend class BraveDefaultBrowserWorker;

#include "../../../../chrome/browser/shell_integration.h"

#undef BRAVE_DEFAULT_BROWSER_WORKER_H

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_SHELL_INTEGRATION_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* Copyright (c) 2021 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/brave_shell_integration.h"

#define DefaultBrowserWorker BraveDefaultBrowserWorker
#include "../../../../../../../chrome/browser/ui/webui/settings/settings_default_browser_handler.cc"
#undef DefaultBrowserWorker
12 changes: 12 additions & 0 deletions patches/chrome-browser-shell_integration.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/shell_integration.h b/chrome/browser/shell_integration.h
index 29e98f5b2839a44a488d6baec756b660935302dd..b761dea9fbb8f0009976997a41d9a10b2aaf3df1 100644
--- a/chrome/browser/shell_integration.h
+++ b/chrome/browser/shell_integration.h
@@ -235,6 +235,7 @@ class DefaultBrowserWorker : public DefaultWebClientWorker {
protected:
~DefaultBrowserWorker() override;

+ BRAVE_DEFAULT_BROWSER_WORKER_H
private:
// Check if Chrome is the default browser.
DefaultWebClientState CheckIsDefaultImpl() override;

0 comments on commit 436f1fb

Please sign in to comment.