-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11125 from brave/default_browser_win
Set Brave as a default browser w/o system UI on Windows
- Loading branch information
Showing
7 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
10 changes: 10 additions & 0 deletions
10
chromium_src/chrome/browser/ui/webui/settings/settings_default_browser_handler.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |