Delete ms-edge protocol handling

fix https://github.com/brave/brave-browser/issues/21553

Deleted all ms-edge protocol handling logic as Windows doesn't allow
3p applications as a default ms-edge protocol handler.
This commit is contained in:
Simon Hong
2022-03-11 16:48:23 +09:00
parent f474633f44
commit ed69d85439
25 changed files with 2 additions and 627 deletions
-13
View File
@@ -891,19 +891,6 @@ Are you sure you want to do this?
<message name="IDS_BRAVE_THEME_TYPE_SYSTEM" desc="Text for system theme type">
Same as Windows
</message>
<!-- MS-Edge protocol handler setting -->
<message name="IDS_SETTINGS_SYSTEM_PAGE_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL" desc="Text for ms-edge protocol handler option">
Default microsoft-edge protocol handler
</message>
<message name="IDS_SETTINGS_SYSTEM_PAGE_MAKE_BRAVE_AS_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL" desc="Text for ms-edge protocol handler option's sublabel">
Make Brave the microsoft-edge protocol handler
</message>
<message name="IDS_SETTINGS_SYSTEM_PAGE_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_MAKE_DEFAULT_BUTTON_LABEL" desc="Text for make default button">
Make default
</message>
<message name="IDS_SETTINGS_SYSTEM_PAGE_BRAVE_IS_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL" desc="Text for option when brave is already set as a default handler">
Brave is default microsoft-edge protocol handler
</message>
</if>
<if expr="is_macosx">
<message name="IDS_BRAVE_THEME_TYPE_SYSTEM" desc="Text for system theme type">
+1 -5
View File
@@ -59,16 +59,12 @@ source_set("unit_tests") {
deps = []
if (is_win) {
sources += [
"default_protocol_handler_utils_win_unittest.cc",
"microsoft_edge_protocol_util_unittest.cc",
]
sources += [ "default_protocol_handler_utils_win_unittest.cc" ]
deps += [
"//base",
"//brave/browser",
"//testing/gtest",
"//url",
]
}
}
-73
View File
@@ -1,73 +0,0 @@
/* 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/microsoft_edge_protocol_util.h"
#include <string>
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "url/url_util.h"
namespace {
std::string DecodeURL(base::StringPiece url) {
url::RawCanonOutputT<char16_t> unescaped;
url::DecodeURLEscapeSequences(url.data(), url.size(),
url::DecodeURLMode::kUTF8OrIsomorphic,
&unescaped);
std::string output;
base::UTF16ToUTF8(unescaped.data(), unescaped.length(), &output);
return output;
}
} // namespace
absl::optional<GURL> GetURLFromMSEdgeProtocol(
base::WStringPiece command_line_arg) {
constexpr base::WStringPiece kMSEdgeProtocol = L"microsoft-edge:";
if (!base::StartsWith(command_line_arg, kMSEdgeProtocol))
return absl::nullopt;
// From now on, it's "microsoft-edge:" protocol args.
base::WStringPiece protocol_arg = command_line_arg;
protocol_arg.remove_prefix(kMSEdgeProtocol.length());
// Handle protocol's arg is empty.
if (protocol_arg.empty())
return absl::nullopt;
// query stores string after '?'.
const bool has_query = protocol_arg[0] == '?';
if (!has_query) {
// If it's not a query string, we assume |protocol_arg| is url.
GURL url(DecodeURL(base::WideToUTF8(protocol_arg)));
if (url.is_valid())
return url;
return absl::nullopt;
}
// Remove first character '?'.
protocol_arg.remove_prefix(1);
// Windows Search passes link url in the query.
// Find URL key from cortana query.
for (const auto& cur :
base::SplitString(base::WideToUTF8(protocol_arg), "&",
base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) {
constexpr base::StringPiece kCortanaURLKey = "url=";
if (!base::StartsWith(cur, kCortanaURLKey))
continue;
// We assume query includes only one url key.
GURL url(DecodeURL(cur.substr(kCortanaURLKey.length())));
if (url.is_valid())
return url;
break;
}
return absl::nullopt;
}
-17
View File
@@ -1,17 +0,0 @@
/* 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_MICROSOFT_EDGE_PROTOCOL_UTIL_H_
#define BRAVE_BROWSER_MICROSOFT_EDGE_PROTOCOL_UTIL_H_
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"
// Returns url if |command_line_arg| is microsoft-edge protocol args and that
// args has link info. If args is not a valid url, returns nullopt.
absl::optional<GURL> GetURLFromMSEdgeProtocol(
base::WStringPiece command_line_arg);
#endif // BRAVE_BROWSER_MICROSOFT_EDGE_PROTOCOL_UTIL_H_
@@ -1,39 +0,0 @@
/* 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/microsoft_edge_protocol_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
TEST(MSEdgeProtocolTest, BasicTest) {
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L""));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"https://www.brave.com/"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge:"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge:test"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge:?"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge:?test"));
EXPECT_FALSE(GetURLFromMSEdgeProtocol(L"microsoft-edge:?abcd&url=test"));
EXPECT_EQ(
GURL("https://www.brave.com/"),
*GetURLFromMSEdgeProtocol(L"microsoft-edge:https://www.brave.com/"));
// Test encoded url. GetURLFromMSEdgeProtocol() will return decoded url.
EXPECT_EQ(
GURL("https://www.bing.com/search?q=test"),
*GetURLFromMSEdgeProtocol(
L"microsoft-edge:https%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3Dtest"));
// Test cortana args.
EXPECT_EQ(
GURL("https://www.bing.com/search?q=test"),
*GetURLFromMSEdgeProtocol(
L"microsoft-edge:?launchContext1=Microsoft.Windows.Cortana_"
L"cw5n1h2txyewy&url=https%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3Dtest"));
// no url key in query.
EXPECT_FALSE(GetURLFromMSEdgeProtocol(
L"microsoft-edge:?launchContext1=Microsoft.Windows.Cortana_"
L"cw5n1h2txyewy&https%3A%2F%2Fwww.bing.com%2Fsearch%3Fq%3Dtest"));
}
-4
View File
@@ -122,7 +122,6 @@ preprocess_if_expr("preprocess") {
"brave_overrides/site_settings_page.js",
"brave_overrides/sync_account_control.js",
"brave_overrides/sync_controls.js",
"brave_overrides/system_page.js",
"brave_reset_page/brave_reset_profile_dialog_behavior.js",
"brave_routes.js",
"brave_sync_page/brave_sync_browser_proxy.js",
@@ -173,8 +172,6 @@ preprocess_if_expr("preprocess_generated") {
"brave_sync_page/brave_sync_page.js",
"brave_sync_page/brave_sync_setup.js",
"brave_sync_page/brave_sync_subpage.js",
"brave_system_page/brave_system_page.js",
"brave_system_page/brave_system_page_browser_proxy.m.js",
"brave_wallet_page/add_wallet_network_dialog.js",
"brave_wallet_page/brave_wallet_browser_proxy.m.js",
"brave_wallet_page/brave_wallet_page.js",
@@ -202,7 +199,6 @@ group("web_modules") {
"brave_rewards_page:web_modules",
"brave_search_engines_page:web_modules",
"brave_sync_page:web_modules",
"brave_system_page:web_modules",
"brave_wallet_page:web_modules",
"default_brave_shields_page:web_modules",
"getting_started_page:web_modules",
@@ -37,4 +37,3 @@ import './site_details.js'
import './site_settings_page.js'
import './sync_account_control.js'
import './sync_controls.js'
import './system_page.js'
@@ -1,20 +0,0 @@
// 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/.
import {RegisterPolymerTemplateModifications} from 'chrome://brave-resources/polymer_overriding.js'
import '../brave_system_page/brave_system_page.js'
RegisterPolymerTemplateModifications({
'settings-system-page': (templateContent) => {
const hardwareAccelToggle = templateContent.getElementById('hardwareAcceleration')
if (!hardwareAccelToggle) {
console.error(`[Brave Settings Overrides] Couldn't find hardwareAcceleration toggle`)
} else {
hardwareAccelToggle.insertAdjacentHTML('afterend', `
<settings-brave-system-page prefs="{{prefs}}"></settings-brave-system-page>
`)
}
}
})
@@ -1,24 +0,0 @@
# Copyright (c) 2020 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/.
import("//tools/polymer/html_to_js.gni")
import("//ui/webui/resources/tools/js_modulizer.gni")
import("../settings.gni")
group("web_modules") {
public_deps = [
":modules",
":templatize",
]
}
html_to_js("templatize") {
js_files = [ "brave_system_page.js" ]
}
js_modulizer("modules") {
input_files = [ "brave_system_page_browser_proxy.js" ]
namespace_rewrites = settings_namespace_rewrites
}
@@ -1,25 +0,0 @@
<style include="cr-shared-style settings-shared iron-flex">
</style>
<if expr="is_win">
<template is="dom-if" if="[[shouldShowDefaultMSEdgeProtocolHandlerOption_]]">
<template is="dom-if" if="[[!isDefaultMSEdgeProtocolHandler_]]">
<div class="cr-row">
<div class="flex cr-padded-text">
<div>$i18n{defaultMSEdgeProtocolHandler}</div>
<div class="secondary">$i18n{makeBraveAsDefaultMSEdgeProtocolHandler}</div>
</div>
<div class="separator"></div>
<cr-button on-click="onSetDefaultProtocolHandlerTap_">
$i18n{defaultMSEdgeProtocolHandlerMakeDefaultButton}
</cr-button>
</div>
</template>
<template is="dom-if" if="[[isDefaultMSEdgeProtocolHandler_]]">
<div class="cr-row">
<div class="flex cr-padded-text">
$i18n{defaultMSEdgeProtocolHandler}
</div>
</div>
</template>
</template>
</if>
@@ -1,62 +0,0 @@
// 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/.
import {Polymer, html} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {WebUIListenerBehavior} from 'chrome://resources/js/web_ui_listener_behavior.m.js';
import {BraveSystemPageBrowserProxy, BraveSystemPageBrowserProxyImpl} from './brave_system_page_browser_proxy.m.js';
/**
* 'settings-brave-system-page' is the settings page area containing
* brave's system related settings that located in the chromium's system page
* area.
*/
Polymer({
is: 'settings-brave-system-page',
_template: html`{__html_template__}`,
behaviors: [
WebUIListenerBehavior,
],
properties: {
// <if expr="is_win">
isDefaultMSEdgeProtocolHandler_: Boolean,
shouldShowDefaultMSEdgeProtocolHandlerOption_: Boolean,
// </if>
},
/** @private {?settings.BraveSystemPageBrowserProxy} */
browserProxy_: null,
/** @override */
created: function() {
this.browserProxy_ = BraveSystemPageBrowserProxyImpl.getInstance();
// <if expr="is_win">
this.isDefaultMSEdgeProtocolHandler_ = false;
this.shouldShowDefaultMSEdgeProtocolHandlerOption_ =
loadTimeData.getBoolean('canSetDefaultMSEdgeProtocolHandler');
console.error(this.shouldShowDefaultMSEdgeProtocolHandlerOption_);
// </if>
},
/** @override */
ready: function() {
// <if expr="is_win">
if (this.shouldShowDefaultMSEdgeProtocolHandlerOption_) {
this.addWebUIListener('notify-ms-edge-protocol-default-handler-status', (isDefault) => {
this.isDefaultMSEdgeProtocolHandler_ = isDefault;
})
this.browserProxy_.checkDefaultMSEdgeProtocolHandlerState();
}
// </if>
},
// <if expr="is_win">
onSetDefaultProtocolHandlerTap_: function() {
this.browserProxy_.setAsDefaultMSEdgeProtocolHandler();
},
// </if>
});
@@ -1,31 +0,0 @@
/* 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/. */
import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js';
/** @interface */
export class BraveSystemPageBrowserProxy {
// <if expr="is_win">
checkDefaultMSEdgeProtocolHandlerState() {}
setAsDefaultMSEdgeProtocolHandler() {}
// </if>
}
/**
* @implements {BraveSystemPageBrowserProxy}
*/
export class BraveSystemPageBrowserProxyImpl {
/** @override */
// <if expr="is_win">
checkDefaultMSEdgeProtocolHandlerState() {
return chrome.send('checkDefaultMSEdgeProtocolHandlerState');
}
setAsDefaultMSEdgeProtocolHandler() {
chrome.send('setAsDefaultMSEdgeProtocolHandler');
}
// </if>
}
addSingletonGetter(BraveSystemPageBrowserProxyImpl);
-1
View File
@@ -9,7 +9,6 @@ settings_namespace_rewrites = [
"settings.BravePrivacyBrowserProxyImpl|BravePrivacyBrowserProxyImpl",
"settings.BraveRewardsBrowserProxyImpl|BraveRewardsBrowserProxyImpl",
"settings.BraveSyncBrowserProxy|BraveSyncBrowserProxy",
"settings.BraveSystemPageBrowserProxy|BraveSystemPageBrowserProxy",
"settings.DefaultBraveShieldsBrowserProxyImpl|DefaultBraveShieldsBrowserProxyImpl",
"settings.SocialBlockingPageProxyImpl|SocialBlockingPageProxyImpl",
"settings.Router|Router",
-3
View File
@@ -53,7 +53,6 @@ brave_deps_chrome_browser_resources_settings_in_files = [
"brave_overrides/site_settings_page.js",
"brave_overrides/sync_account_control.js",
"brave_overrides/sync_controls.js",
"brave_overrides/system_page.js",
"brave_privacy_page/brave_personalization_options.m.js",
"brave_privacy_page/brave_privacy_page_browser_proxy.m.js",
"brave_reset_page/brave_reset_profile_dialog_behavior.js",
@@ -67,8 +66,6 @@ brave_deps_chrome_browser_resources_settings_in_files = [
"brave_sync_page/brave_sync_page.js",
"brave_sync_page/brave_sync_setup.js",
"brave_sync_page/brave_sync_subpage.js",
"brave_system_page/brave_system_page.js",
"brave_system_page/brave_system_page_browser_proxy.m.js",
"brave_wallet_page/add_wallet_network_dialog.js",
"brave_wallet_page/brave_wallet_browser_proxy.m.js",
"brave_wallet_page/brave_wallet_page.js",
-2
View File
@@ -329,8 +329,6 @@ if (is_win) {
brave_chrome_browser_sources += [
"//brave/browser/default_protocol_handler_utils_win.cc",
"//brave/browser/default_protocol_handler_utils_win.h",
"//brave/browser/microsoft_edge_protocol_util.cc",
"//brave/browser/microsoft_edge_protocol_util.h",
]
brave_chrome_browser_deps += [
"//chrome/install_static:install_static_util",
-7
View File
@@ -559,13 +559,6 @@ source_set("ui") {
}
}
if (is_win) {
sources += [
"webui/settings/ms_edge_protocol_message_handler.cc",
"webui/settings/ms_edge_protocol_message_handler.h",
]
}
if (is_win && is_official_build) {
sources += [
"//chrome/browser/ui/webui/help/version_updater_win.cc",
-13
View File
@@ -38,10 +38,6 @@
#include "brave/components/brave_vpn/brave_vpn_utils.h"
#endif
#if defined(OS_WIN)
#include "brave/browser/ui/webui/settings/ms_edge_protocol_message_handler.h"
#endif
using ntp_background_images::ViewCounterServiceFactory;
BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
@@ -55,10 +51,6 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
web_ui->AddMessageHandler(std::make_unique<BraveAppearanceHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveSyncHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveWalletHandler>());
#if defined(OS_WIN)
if (MSEdgeProtocolMessageHandler::CanSetDefaultMSEdgeProtocolHandler())
web_ui->AddMessageHandler(std::make_unique<MSEdgeProtocolMessageHandler>());
#endif
}
BraveSettingsUI::~BraveSettingsUI() {}
@@ -94,9 +86,4 @@ void BraveSettingsUI::AddResources(content::WebUIDataSource* html_source,
"isNativeBraveWalletFeatureEnabled",
base::FeatureList::IsEnabled(
brave_wallet::features::kNativeBraveWalletFeature));
#if defined(OS_WIN)
html_source->AddBoolean(
"canSetDefaultMSEdgeProtocolHandler",
MSEdgeProtocolMessageHandler::CanSetDefaultMSEdgeProtocolHandler());
#endif
}
@@ -1,150 +0,0 @@
// 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/ui/webui/settings/ms_edge_protocol_message_handler.h"
#include <shlobj.h>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "base/path_service.h"
#include "base/task/thread_pool.h"
#include "base/win/windows_version.h"
#include "brave/browser/default_protocol_handler_utils_win.h"
#include "chrome/installer/util/shell_util.h"
using protocol_handler_utils::IsDefaultProtocolHandlerFor;
using protocol_handler_utils::SetDefaultProtocolHandlerFor;
namespace {
constexpr wchar_t kMSEdgeProtocol[] = L"microsoft-edge";
constexpr wchar_t kMSEdgeProtocolRegKey[] =
L"SOFTWARE\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\micro"
L"soft-edge";
} // namespace
// static
bool MSEdgeProtocolMessageHandler::CanSetDefaultMSEdgeProtocolHandler() {
base::win::OSInfo* os_info = base::win::OSInfo::GetInstance();
const auto& version_number = os_info->version_number();
// MS will not allow setting 3p application as a default microsoft-edge
// handler. See
// https://www.ctrl.blog/entry/microsoft-edge-protocol-competition.html
// Hope this constraint disappeared!
if (version_number.major <= 10)
return true;
return version_number.build < 22494;
}
MSEdgeProtocolMessageHandler::MSEdgeProtocolMessageHandler()
: user_choice_key_(HKEY_CURRENT_USER, kMSEdgeProtocolRegKey, KEY_NOTIFY) {
DCHECK(CanSetDefaultMSEdgeProtocolHandler());
StartWatching();
}
MSEdgeProtocolMessageHandler::~MSEdgeProtocolMessageHandler() = default;
void MSEdgeProtocolMessageHandler::StartWatching() {
if (user_choice_key_.Valid()) {
user_choice_key_.StartWatching(
base::BindOnce(&MSEdgeProtocolMessageHandler::OnRegValChanged,
base::Unretained(this)));
}
}
void MSEdgeProtocolMessageHandler::OnRegValChanged() {
CheckMSEdgeProtocolDefaultHandlerState();
StartWatching();
}
void MSEdgeProtocolMessageHandler::CheckMSEdgeProtocolDefaultHandlerState() {
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
base::BindOnce(&IsDefaultProtocolHandlerFor, kMSEdgeProtocol),
base::BindOnce(&MSEdgeProtocolMessageHandler::OnIsDefaultProtocolHandler,
weak_factory_.GetWeakPtr()));
}
void MSEdgeProtocolMessageHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"checkDefaultMSEdgeProtocolHandlerState",
base::BindRepeating(&MSEdgeProtocolMessageHandler::
HandleCheckDefaultMSEdgeProtocolHandlerState,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"setAsDefaultMSEdgeProtocolHandler",
base::BindRepeating(&MSEdgeProtocolMessageHandler::
HandleSetAsDefaultMSEdgeProtocolHandler,
base::Unretained(this)));
}
void MSEdgeProtocolMessageHandler::HandleCheckDefaultMSEdgeProtocolHandlerState(
base::Value::ConstListView args) {
AllowJavascript();
CheckMSEdgeProtocolDefaultHandlerState();
}
void MSEdgeProtocolMessageHandler::HandleSetAsDefaultMSEdgeProtocolHandler(
base::Value::ConstListView args) {
AllowJavascript();
// Test purpose switch to use system ui.
constexpr char kUseSystemUIForMSEdgeProtocol[] = "use-system-ui-for-ms-edge";
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
kUseSystemUIForMSEdgeProtocol)) {
LaunchSystemDialog();
return;
}
base::ThreadPool::PostTaskAndReplyWithResult(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
base::BindOnce(&SetDefaultProtocolHandlerFor, kMSEdgeProtocol),
base::BindOnce(&MSEdgeProtocolMessageHandler::OnSetDefaultProtocolHandler,
weak_factory_.GetWeakPtr()));
}
void MSEdgeProtocolMessageHandler::OnIsDefaultProtocolHandler(bool is_default) {
if (IsJavascriptAllowed()) {
FireWebUIListener("notify-ms-edge-protocol-default-handler-status",
base::Value(is_default));
}
}
void MSEdgeProtocolMessageHandler::OnSetDefaultProtocolHandler(bool success) {
if (!success) {
LaunchSystemDialog();
return;
}
if (IsJavascriptAllowed()) {
FireWebUIListener("notify-ms-edge-protocol-default-handler-status",
base::Value(success));
}
::SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nullptr, nullptr);
}
void MSEdgeProtocolMessageHandler::LaunchSystemDialog() {
base::FilePath brave_exe;
if (!base::PathService::Get(base::FILE_EXE, &brave_exe)) {
LOG(ERROR) << "Failed to get app exe path";
return;
}
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_BLOCKING},
base::BindOnce(
[](const base::FilePath& brave_exe) {
ShellUtil::ShowMakeChromeDefaultProtocolClientSystemUI(
brave_exe, kMSEdgeProtocol);
},
brave_exe));
}
@@ -1,46 +0,0 @@
// 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_UI_WEBUI_SETTINGS_MS_EDGE_PROTOCOL_MESSAGE_HANDLER_H_
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_MS_EDGE_PROTOCOL_MESSAGE_HANDLER_H_
#include "base/memory/weak_ptr.h"
#include "base/values.h"
#include "base/win/registry.h"
#include "content/public/browser/web_ui_message_handler.h"
class MSEdgeProtocolMessageHandler : public content::WebUIMessageHandler {
public:
static bool CanSetDefaultMSEdgeProtocolHandler();
MSEdgeProtocolMessageHandler();
~MSEdgeProtocolMessageHandler() override;
MSEdgeProtocolMessageHandler(const MSEdgeProtocolMessageHandler&) = delete;
MSEdgeProtocolMessageHandler& operator=(const MSEdgeProtocolMessageHandler&) =
delete;
private:
// content::WebUIMessageHandler overrides:
void RegisterMessages() override;
void HandleCheckDefaultMSEdgeProtocolHandlerState(
base::Value::ConstListView args);
void HandleSetAsDefaultMSEdgeProtocolHandler(base::Value::ConstListView args);
void OnIsDefaultProtocolHandler(bool is_default);
void OnSetDefaultProtocolHandler(bool success);
void CheckMSEdgeProtocolDefaultHandlerState();
// Watch ms-edge UserChoice reg change.
void StartWatching();
void OnRegValChanged();
void LaunchSystemDialog();
base::win::RegKey user_choice_key_;
base::WeakPtrFactory<MSEdgeProtocolMessageHandler> weak_factory_{this};
};
#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_MS_EDGE_PROTOCOL_MESSAGE_HANDLER_H_
@@ -8,10 +8,6 @@
#include "brave/components/tor/buildflags/buildflags.h"
#include "chrome/browser/ui/startup/startup_browser_creator_impl.h"
#if defined(OS_WIN)
#include "brave/browser/microsoft_edge_protocol_util.h"
#endif
#if BUILDFLAG(ENABLE_TOR)
#include "brave/browser/tor/tor_profile_manager.h"
#endif
@@ -1,15 +0,0 @@
/* 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_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_
// Need to friend the right class, overriden to adapt GetCommandLineTabs() in
// chromium_src/chrome/browser/ui/startup/startup_tab_provider.{h,cc}.
#define StartupTabProviderImpl ChromiumStartupTabProviderImpl
#include "src/chrome/browser/ui/startup/startup_browser_creator.h"
#undef StartupTabProviderImpl
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_STARTUP_BROWSER_CREATOR_H_
@@ -1,36 +0,0 @@
/* 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 "chrome/browser/ui/startup/startup_tab_provider.h"
#include "chrome/browser/ui/startup/startup_browser_creator.h"
#if defined(OS_WIN)
#include "brave/browser/microsoft_edge_protocol_util.h"
#endif
#define StartupTabProviderImpl ChromiumStartupTabProviderImpl
#include "src/chrome/browser/ui/startup/startup_tab_provider.cc"
#undef StartupTabProviderImpl
StartupTabs StartupTabProviderImpl::GetCommandLineTabs(
const base::CommandLine& command_line,
const base::FilePath& cur_dir,
Profile* profile) const {
StartupTabs result = ChromiumStartupTabProviderImpl::GetCommandLineTabs(
command_line, cur_dir, profile);
#if defined(OS_WIN)
for (const std::wstring& arg : command_line.GetArgs()) {
// Fetch url from command line args if it includes microsoft-edge protocol
// and url is delivered.
absl::optional<GURL> url = GetURLFromMSEdgeProtocol(arg);
if (!url)
continue;
if (url->is_valid())
result.push_back(StartupTab(url.value()));
}
#endif
return result;
}
@@ -1,24 +0,0 @@
/* 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_UI_STARTUP_STARTUP_TAB_PROVIDER_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_STARTUP_TAB_PROVIDER_H_
#define StartupTabProviderImpl ChromiumStartupTabProviderImpl
#include "src/chrome/browser/ui/startup/startup_tab_provider.h"
#undef StartupTabProviderImpl
class StartupTabProviderImpl : public ChromiumStartupTabProviderImpl {
public:
StartupTabProviderImpl() = default;
StartupTabProviderImpl(const StartupTabProviderImpl&) = delete;
StartupTabProviderImpl& operator=(const StartupTabProviderImpl&) = delete;
StartupTabs GetCommandLineTabs(const base::CommandLine& command_line,
const base::FilePath& cur_dir,
Profile* profile) const override;
};
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_STARTUP_STARTUP_TAB_PROVIDER_H_
@@ -106,16 +106,6 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_APPEARANCE_SETTINGS_GET_MORE_THEMES},
{"appearanceBraveDefaultImagesOptionLabel",
IDS_SETTINGS_APPEARANCE_SETTINGS_BRAVE_DEFAULT_IMAGES_OPTION_LABEL},
#if defined(OS_WIN)
{"defaultMSEdgeProtocolHandler",
IDS_SETTINGS_SYSTEM_PAGE_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL},
{"makeBraveAsDefaultMSEdgeProtocolHandler",
IDS_SETTINGS_SYSTEM_PAGE_MAKE_BRAVE_AS_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL}, // NOLINT
{"defaultMSEdgeProtocolHandlerMakeDefaultButton",
IDS_SETTINGS_SYSTEM_PAGE_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_MAKE_DEFAULT_BUTTON_LABEL}, // NOLINT
{"braveIsDefaultMSEdgeProtocolHandler",
IDS_SETTINGS_SYSTEM_PAGE_BRAVE_IS_DEFAULT_MS_EDGE_PROTOCOL_HANDLER_LABEL},
#endif
#if BUILDFLAG(ENABLE_SIDEBAR)
{"appearanceSettingsShowOptionTitle", IDS_SIDEBAR_SHOW_OPTION_TITLE},
{"appearanceSettingsShowOptionAlways", IDS_SIDEBAR_SHOW_OPTION_ALWAYS},
@@ -39,8 +39,7 @@ int GetIconIndexForFileType() {
#define BRAVE_BROWSER_PROTOCOL_ASSOCIATIONS BRAVE_IPFS, BRAVE_IPNS,
#define BRAVE_POTENTIAL_PROTOCOL_ASSOCIATIONS \
BRAVE_IPFS, BRAVE_IPNS, L"microsoft-edge",
#define BRAVE_POTENTIAL_PROTOCOL_ASSOCIATIONS BRAVE_IPFS, BRAVE_IPNS,
#define BRAVE_GET_TARGET_FOR_DEFAULT_APP_SETTINGS \
if (base::EqualsCaseInsensitiveASCII(protocol, BRAVE_IPFS)) \