Pin to taskbar on Windows
fix https://github.com/brave/brave-browser/issues/24054 * Pin to taskbar from first run or default browser dialog when user want to do it. * Pin to taskbar from settings. Use upstream's api for pin state checking pin to taskbar With this, this pin to shortcut feature is available also on Win7/8.
This commit is contained in:
@@ -928,6 +928,11 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
|
||||
Maybe later
|
||||
</message>
|
||||
|
||||
<if expr="is_win">
|
||||
<message name="IDS_FIRSTRUN_DLG_PIN_SHORTCUT_TEXT" desc="Text for pin to taskbar checkbox">
|
||||
Pin to taskbar
|
||||
</message>
|
||||
</if>
|
||||
<!-- Importer -->
|
||||
<message name="IDS_BRAVE_IMPORT_FROM_EDGE" desc="browser combo box: Microsoft Edge Legacy">
|
||||
Microsoft Edge Legacy
|
||||
|
||||
@@ -140,6 +140,19 @@
|
||||
Customize the background image and widgets that appear on the new tab page
|
||||
</message>
|
||||
|
||||
<!-- Settings / Pin shortcut-->
|
||||
<if expr="is_win">
|
||||
<message name="IDS_SETTINGS_CAN_PIN_SHORTCUT">
|
||||
Pin to taskbar
|
||||
</message>
|
||||
<message name="IDS_SETTINGS_PIN_SHORTCUT">
|
||||
Pin
|
||||
</message>
|
||||
<message name="IDS_SETTINGS_SHORTCUT_PINNED">
|
||||
Brave is already pinned
|
||||
</message>
|
||||
</if>
|
||||
|
||||
<!-- Settings / Shields -->
|
||||
<message name="IDS_SETTINGS_BRAVE_SHIELDS_TITLE" desc="The title for Brave shields section in settings">
|
||||
Shields
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
#include "brave/browser/brave_shell_integration_win.h"
|
||||
|
||||
#include <shlobj.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
@@ -21,7 +18,6 @@
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/task/thread_pool.h"
|
||||
#include "base/win/shortcut.h"
|
||||
#include "base/win/windows_version.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/profiles/profile_attributes_entry.h"
|
||||
@@ -30,6 +26,7 @@
|
||||
#include "chrome/browser/shell_integration_win.h"
|
||||
#include "chrome/installer/util/install_util.h"
|
||||
#include "chrome/installer/util/shell_util.h"
|
||||
#include "chrome/installer/util/taskbar_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "third_party/abseil-cpp/absl/types/optional.h"
|
||||
|
||||
@@ -106,120 +103,13 @@ absl::optional<ScopedShortcutFile> GetShortcutPath(
|
||||
return absl::optional<ScopedShortcutFile>(shortcut_path);
|
||||
}
|
||||
|
||||
// NOTE: Below Pin/IsPin method is copied lastest chromium.
|
||||
// Delete and use upstreams one when it's available from our trunk.
|
||||
|
||||
// ScopedPIDLFromPath class, and the idea of using IPinnedList3::Modify,
|
||||
// are thanks to Gee Law <https://geelaw.blog/entries/msedge-pins/>
|
||||
class ScopedPIDLFromPath {
|
||||
public:
|
||||
explicit ScopedPIDLFromPath(PCWSTR path)
|
||||
: p_id_list_(ILCreateFromPath(path)) {}
|
||||
~ScopedPIDLFromPath() {
|
||||
if (p_id_list_)
|
||||
ILFree(p_id_list_);
|
||||
}
|
||||
PIDLIST_ABSOLUTE Get() const { return p_id_list_; }
|
||||
|
||||
private:
|
||||
PIDLIST_ABSOLUTE const p_id_list_;
|
||||
};
|
||||
|
||||
enum class PinnedListModifyCaller { kExplorer = 4 };
|
||||
|
||||
constexpr GUID CLSID_TaskbandPin = {
|
||||
0x90aa3a4e,
|
||||
0x1cba,
|
||||
0x4233,
|
||||
{0xb8, 0xbb, 0x53, 0x57, 0x73, 0xd4, 0x84, 0x49}};
|
||||
|
||||
// Undocumented COM interface for manipulating taskbar pinned list.
|
||||
class __declspec(uuid("0DD79AE2-D156-45D4-9EEB-3B549769E940")) IPinnedList3
|
||||
: public IUnknown {
|
||||
public:
|
||||
virtual HRESULT STDMETHODCALLTYPE EnumObjects() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPinnableInfo() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE IsPinnable() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE Resolve() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE LegacyModify() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetChangeCount() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE IsPinned(PCIDLIST_ABSOLUTE) = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPinnedItem() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetAppIDForPinnedItem() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE ItemChangeNotify() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE UpdateForRemovedItemsAsNecessary() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE PinShellLink() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPinnedItemForAppID() = 0;
|
||||
virtual HRESULT STDMETHODCALLTYPE Modify(PCIDLIST_ABSOLUTE unpin,
|
||||
PCIDLIST_ABSOLUTE pin,
|
||||
PinnedListModifyCaller caller) = 0;
|
||||
};
|
||||
|
||||
// Returns the taskbar pinned list if successful, an empty ComPtr otherwise.
|
||||
Microsoft::WRL::ComPtr<IPinnedList3> GetTaskbarPinnedList() {
|
||||
if (base::win::GetVersion() < base::win::Version::WIN10_RS5)
|
||||
return nullptr;
|
||||
|
||||
Microsoft::WRL::ComPtr<IPinnedList3> pinned_list;
|
||||
if (FAILED(CoCreateInstance(CLSID_TaskbandPin, nullptr, CLSCTX_INPROC_SERVER,
|
||||
IID_PPV_ARGS(&pinned_list)))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return pinned_list;
|
||||
}
|
||||
|
||||
void PinShortcutWin10(const base::FilePath& shortcut) {
|
||||
Microsoft::WRL::ComPtr<IPinnedList3> pinned_list = GetTaskbarPinnedList();
|
||||
if (!pinned_list)
|
||||
return;
|
||||
|
||||
ScopedPIDLFromPath item_id_list(shortcut.value().data());
|
||||
pinned_list->Modify(nullptr, item_id_list.Get(),
|
||||
PinnedListModifyCaller::kExplorer);
|
||||
}
|
||||
|
||||
absl::optional<bool> IsShortcutPinnedWin10(const base::FilePath& shortcut) {
|
||||
Microsoft::WRL::ComPtr<IPinnedList3> pinned_list = GetTaskbarPinnedList();
|
||||
if (!pinned_list.Get())
|
||||
return absl::nullopt;
|
||||
|
||||
ScopedPIDLFromPath item_id_list(shortcut.value().data());
|
||||
HRESULT hr = pinned_list->IsPinned(item_id_list.Get());
|
||||
// S_OK means `shortcut` is pinned, S_FALSE mean it's not pinned.
|
||||
return SUCCEEDED(hr) ? absl::optional<bool>(hr == S_OK) : absl::nullopt;
|
||||
}
|
||||
|
||||
bool IsShortcutPinned(const ShellUtil::ShortcutProperties& properties) {
|
||||
// Generate the shortcut to check pin state.
|
||||
absl::optional<ScopedShortcutFile> shortcut_path =
|
||||
GetShortcutPath(ExtractShortcutNameFromProperties(properties));
|
||||
if (!shortcut_path) {
|
||||
LOG(ERROR) << __func__ << " failed to get shortcut path";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateShortcut(properties, shortcut_path->file_path())) {
|
||||
LOG(ERROR) << __func__ << " Failed to create shortcut";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check pin state with newly created shortcut.
|
||||
auto pinned = IsShortcutPinnedWin10(shortcut_path->file_path());
|
||||
if (!pinned) {
|
||||
LOG(ERROR) << __func__ << " Can't use pin method.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return pinned.value();
|
||||
}
|
||||
|
||||
// All args could be empty when we want to pin default profile's shortcut.
|
||||
void PinToTaskbarImpl(const base::FilePath& profile_path,
|
||||
bool PinToTaskbarImpl(const base::FilePath& profile_path,
|
||||
const std::u16string& profile_name,
|
||||
const std::wstring& aumid) {
|
||||
base::FilePath chrome_exe;
|
||||
base::PathService::Get(base::FILE_EXE, &chrome_exe);
|
||||
if (!base::PathService::Get(base::FILE_EXE, &chrome_exe))
|
||||
return false;
|
||||
|
||||
ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
|
||||
ShellUtil::AddDefaultShortcutProperties(chrome_exe, &properties);
|
||||
@@ -243,131 +133,89 @@ void PinToTaskbarImpl(const base::FilePath& profile_path,
|
||||
GetShortcutPath(ExtractShortcutNameFromProperties(properties));
|
||||
if (!shortcut_path) {
|
||||
LOG(ERROR) << __func__ << " failed to get shortcut path";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CreateShortcut(properties, shortcut_path->file_path())) {
|
||||
LOG(ERROR) << __func__ << " Failed to create shortcut";
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check pin state with newly created shortcut.
|
||||
auto pinned = IsShortcutPinnedWin10(shortcut_path->file_path());
|
||||
if (!pinned) {
|
||||
LOG(ERROR) << __func__ << " Can't use pin method.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't try to pin again when it's already pinned.
|
||||
if (pinned.value())
|
||||
return;
|
||||
|
||||
PinShortcutWin10(shortcut_path->file_path());
|
||||
return PinShortcutToTaskbar(shortcut_path->file_path());
|
||||
}
|
||||
|
||||
bool HasTaskbarAnyPinnedBraveShortcuts(
|
||||
const std::vector<std::tuple<base::FilePath, std::u16string, std::wstring>>&
|
||||
profile_attrs) {
|
||||
base::FilePath chrome_exe;
|
||||
base::PathService::Get(base::FILE_EXE, &chrome_exe);
|
||||
|
||||
ShellUtil::ShortcutProperties properties(ShellUtil::CURRENT_USER);
|
||||
ShellUtil::AddDefaultShortcutProperties(chrome_exe, &properties);
|
||||
for (const auto& attr : profile_attrs) {
|
||||
const auto profile_path = std::get<0>(attr);
|
||||
const auto profile_name = std::get<1>(attr);
|
||||
const auto profile_aumid = std::get<2>(attr);
|
||||
if (!profile_path.empty()) {
|
||||
properties.set_arguments(
|
||||
profiles::internal::CreateProfileShortcutFlags(profile_path));
|
||||
properties.set_shortcut_name(
|
||||
profiles::internal::GetShortcutFilenameForProfile(profile_name));
|
||||
properties.set_app_id(profile_aumid);
|
||||
}
|
||||
|
||||
if (IsShortcutPinned(properties))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DoPinToTaskbar(Profile* profile) {
|
||||
void DoPinToTaskbar(const base::FilePath& profile_path,
|
||||
base::OnceCallback<void(bool)> callback) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
base::FilePath profile_path;
|
||||
std::u16string profile_name;
|
||||
std::wstring aumid;
|
||||
if (profile) {
|
||||
if (!profile_path.empty()) {
|
||||
ProfileManager* profile_manager = g_browser_process->profile_manager();
|
||||
ProfileAttributesEntry* entry =
|
||||
profile_manager->GetProfileAttributesStorage()
|
||||
.GetProfileAttributesWithPath(profile->GetPath());
|
||||
profile_path = profile->GetPath();
|
||||
.GetProfileAttributesWithPath(profile_path);
|
||||
profile_name = entry->GetName();
|
||||
aumid = shell_integration::win::GetAppUserModelIdForBrowser(profile_path);
|
||||
}
|
||||
|
||||
base::ThreadPool::CreateCOMSTATaskRunner({base::MayBlock()})
|
||||
->PostTask(FROM_HERE, base::BindOnce(&PinToTaskbarImpl, profile_path,
|
||||
profile_name, aumid));
|
||||
}
|
||||
|
||||
bool CanPinToTaskbar() {
|
||||
base::FilePath chrome_exe;
|
||||
if (!base::PathService::Get(base::FILE_EXE, &chrome_exe))
|
||||
return false;
|
||||
|
||||
// TODO(simonhong): Support win7/8
|
||||
if (base::win::GetVersion() < base::win::Version::WIN10_RS5)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
->PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&PinToTaskbarImpl, profile_path, profile_name, aumid),
|
||||
std::move(callback));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace shell_integration::win {
|
||||
|
||||
void PinToTaskbar(Profile* profile) {
|
||||
// Disable pin-to-taskabar uitll we have checkbox to ask the user to use it.
|
||||
return;
|
||||
|
||||
void PinToTaskbar(Profile* profile,
|
||||
base::OnceCallback<void(bool)> result_callback) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
if (!CanPinToTaskbar())
|
||||
if (!CanPinShortcutToTaskbar()) {
|
||||
std::move(result_callback).Run(false);
|
||||
return;
|
||||
|
||||
// At the very early stage, |g_browser_process| or its profile_manager
|
||||
// are not initialzied yet. In that case, skip checking existing pin state.
|
||||
std::vector<std::tuple<base::FilePath, std::u16string, std::wstring>>
|
||||
profile_attrs;
|
||||
// Gather data that is available on UI thread and pass it.
|
||||
if (g_browser_process && g_browser_process->profile_manager()) {
|
||||
for (const auto* entry : g_browser_process->profile_manager()
|
||||
->GetProfileAttributesStorage()
|
||||
.GetAllProfilesAttributes()) {
|
||||
profile_attrs.push_back(
|
||||
std::make_tuple(entry->GetPath(), entry->GetName(),
|
||||
win::GetAppUserModelIdForBrowser(entry->GetPath())));
|
||||
}
|
||||
}
|
||||
|
||||
base::ThreadPool::CreateCOMSTATaskRunner({base::MayBlock()})
|
||||
->PostTaskAndReplyWithResult(
|
||||
FROM_HERE,
|
||||
base::BindOnce(&HasTaskbarAnyPinnedBraveShortcuts,
|
||||
std::move(profile_attrs)),
|
||||
base::BindOnce(
|
||||
[](Profile* profile, bool has_pin) {
|
||||
if (has_pin) {
|
||||
VLOG(2) << " Taskbar has already pinned brave shortcuts";
|
||||
return;
|
||||
}
|
||||
DoPinToTaskbar(profile);
|
||||
},
|
||||
profile));
|
||||
return;
|
||||
base::FilePath profile_path;
|
||||
if (profile)
|
||||
profile_path = profile->GetPath();
|
||||
|
||||
// TODO(simonhong): handle connection error state if caller wants.
|
||||
GetIsPinnedToTaskbarState(
|
||||
base::DoNothing(),
|
||||
base::BindOnce(
|
||||
[](const base::FilePath& profile_path,
|
||||
base::OnceCallback<void(bool)> result_callback, bool succeeded,
|
||||
bool is_pinned_to_taskbar) {
|
||||
if (succeeded && is_pinned_to_taskbar) {
|
||||
// Early return. Already pinned.
|
||||
std::move(result_callback).Run(true);
|
||||
return;
|
||||
}
|
||||
DoPinToTaskbar(profile_path, std::move(result_callback));
|
||||
},
|
||||
std::move(profile_path), std::move(result_callback)));
|
||||
}
|
||||
|
||||
void IsShortcutPinned(base::OnceCallback<void(bool)> result_callback) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
if (!CanPinShortcutToTaskbar()) {
|
||||
std::move(result_callback).Run(false);
|
||||
return;
|
||||
}
|
||||
|
||||
GetIsPinnedToTaskbarState(
|
||||
base::DoNothing(),
|
||||
base::BindOnce(
|
||||
[](base::OnceCallback<void(bool)> result_callback, bool succeeded,
|
||||
bool is_pinned_to_taskbar) {
|
||||
std::move(result_callback).Run(succeeded && is_pinned_to_taskbar);
|
||||
},
|
||||
std::move(result_callback)));
|
||||
}
|
||||
|
||||
} // namespace shell_integration::win
|
||||
|
||||
@@ -6,12 +6,21 @@
|
||||
#ifndef BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_WIN_H_
|
||||
#define BRAVE_BROWSER_BRAVE_SHELL_INTEGRATION_WIN_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/callback_helpers.h"
|
||||
|
||||
class Profile;
|
||||
|
||||
namespace shell_integration::win {
|
||||
|
||||
// Pin profile-specific shortcut when |profile| is non-null.
|
||||
void PinToTaskbar(Profile* profile = nullptr);
|
||||
void PinToTaskbar(
|
||||
Profile* profile = nullptr,
|
||||
base::OnceCallback<void(bool)> result_callback = base::DoNothing());
|
||||
|
||||
// Returns true when taskbar has any shortcuts(default or profile-specific
|
||||
// ones).
|
||||
void IsShortcutPinned(base::OnceCallback<void(bool)> result_callback);
|
||||
|
||||
} // namespace shell_integration::win
|
||||
|
||||
|
||||
@@ -179,6 +179,13 @@ preprocess_if_expr("preprocess_generated") {
|
||||
"getting_started_page/getting_started.js",
|
||||
"social_blocking_page/social_blocking_page.m.js",
|
||||
]
|
||||
|
||||
if (is_win) {
|
||||
in_files += [
|
||||
"pin_shortcut_page/pin_shortcut_page.js",
|
||||
"pin_shortcut_page/pin_shortcut_page_browser_proxy.m.js",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
group("web_modules") {
|
||||
@@ -201,8 +208,13 @@ group("web_modules") {
|
||||
"brave_wallet_page:web_modules",
|
||||
"default_brave_shields_page:web_modules",
|
||||
"getting_started_page:web_modules",
|
||||
"pin_shortcut_page:web_modules",
|
||||
"social_blocking_page:web_modules",
|
||||
]
|
||||
|
||||
if (is_win) {
|
||||
public_deps += [ "pin_shortcut_page:web_modules" ]
|
||||
}
|
||||
}
|
||||
|
||||
polymer_modulizer("icons") {
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
<settings-animated-pages id="pages" section="getStarted">
|
||||
<div route-path="default">
|
||||
<settings-default-browser-page></settings-default-browser-page>
|
||||
<if expr="is_win">
|
||||
<settings-pin-shortcut-page></settings-pin-shortcut-page>
|
||||
</if>
|
||||
<div class="settings-box">$i18n{onStartup}</div>
|
||||
<div class="settings-box continuation">
|
||||
<settings-on-startup-page prefs="{{prefs}}">
|
||||
|
||||
@@ -10,6 +10,10 @@ import '../settings_page/settings_animated_pages.js'
|
||||
import '../default_browser_page/default_browser_page.js'
|
||||
import '../on_startup_page/on_startup_page.js'
|
||||
|
||||
// <if expr="is_win">
|
||||
import '../pin_shortcut_page/pin_shortcut_page.js'
|
||||
// </if>
|
||||
|
||||
Polymer({
|
||||
is: 'brave-settings-getting-started',
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
# Copyright (c) 2022 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",
|
||||
]
|
||||
}
|
||||
|
||||
js_modulizer("modules") {
|
||||
input_files = [ "pin_shortcut_page_browser_proxy.js" ]
|
||||
namespace_rewrites = settings_namespace_rewrites
|
||||
}
|
||||
|
||||
html_to_js("templatize") {
|
||||
js_files = [ "pin_shortcut_page.js" ]
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<!-- Copyright (c) 2022 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/. -->
|
||||
|
||||
<if expr="is_win">
|
||||
<style include="cr-shared-style settings-shared iron-flex">
|
||||
</style>
|
||||
<template is="dom-if" if="[[!pinned_]]">
|
||||
<div class="cr-row">
|
||||
<div class="flex cr-padded-text">
|
||||
<div>$i18n{canPinShortcut}</div>
|
||||
</div>
|
||||
<div class="separator"></div>
|
||||
<cr-button on-click="onPinShortcutTap_">
|
||||
$i18n{pinShortcut}
|
||||
</cr-button>
|
||||
</div>
|
||||
</template>
|
||||
<template is="dom-if" if="[[pinned_]]">
|
||||
<div class="cr-row">
|
||||
<div class="flex cr-padded-text">
|
||||
$i18n{shortcutPinned}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</if>
|
||||
@@ -0,0 +1,48 @@
|
||||
/* Copyright (c) 2022 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 '../settings_shared.css.js';
|
||||
import '../settings_vars.css.js';
|
||||
|
||||
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
|
||||
import {WebUIListenerMixin} from 'chrome://resources/js/web_ui_listener_mixin.js';
|
||||
import {SettingsPinShortcutPageBrowserProxyImpl} from './pin_shortcut_page_browser_proxy.m.js';
|
||||
|
||||
const SettingsPinShortcutPageBase = WebUIListenerMixin(PolymerElement)
|
||||
|
||||
class SettingsPinShortcutPage extends SettingsPinShortcutPageBase {
|
||||
static get is() {
|
||||
return 'settings-pin-shortcut-page'
|
||||
}
|
||||
|
||||
static get template() {
|
||||
return html`{__html_template__}`
|
||||
}
|
||||
|
||||
static get properties() {
|
||||
return {
|
||||
pinned_: {
|
||||
readOnly: false,
|
||||
type: Boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
browserProxy_ = SettingsPinShortcutPageBrowserProxyImpl.getInstance()
|
||||
|
||||
ready() {
|
||||
super.ready()
|
||||
this.pinned_ = false
|
||||
|
||||
this.browserProxy_.checkShortcutPinState()
|
||||
this.addWebUIListener('shortcut-pin-state-changed', pinned => this.set('pinned_', pinned))
|
||||
}
|
||||
|
||||
onPinShortcutTap_() {
|
||||
this.browserProxy_.pinShortcut()
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define(SettingsPinShortcutPage.is, SettingsPinShortcutPage);
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2022 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 {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js';
|
||||
|
||||
/** @interface */
|
||||
export class SettingsPinShortcutPageBrowserProxy {
|
||||
checkShortcutPinState() {}
|
||||
pinShortcut() {}
|
||||
}
|
||||
|
||||
/**
|
||||
* @implements {settings.SettingsPinShortcutPageBrowserProxy}
|
||||
*/
|
||||
export class SettingsPinShortcutPageBrowserProxyImpl {
|
||||
/** @override */
|
||||
checkShortcutPinState() {
|
||||
chrome.send('checkShortcutPinState');
|
||||
}
|
||||
|
||||
pinShortcut() {
|
||||
chrome.send('pinShortcut');
|
||||
}
|
||||
}
|
||||
|
||||
addSingletonGetter(SettingsPinShortcutPageBrowserProxyImpl)
|
||||
@@ -15,5 +15,11 @@ settings_namespace_rewrites = [
|
||||
"settings.Router|Router",
|
||||
]
|
||||
|
||||
if (is_win) {
|
||||
settings_namespace_rewrites += [
|
||||
"settings.PinShortcutPageBrowserProxyImpl|PinShortcutPageBrowserProxyImpl",
|
||||
]
|
||||
}
|
||||
|
||||
settings_auto_imports =
|
||||
[ "chrome/browser/resources/settings/router.html|Router,Route" ]
|
||||
|
||||
@@ -86,6 +86,13 @@ brave_deps_chrome_browser_resources_settings_in_files = [
|
||||
"social_blocking_page/social_blocking_page.m.js",
|
||||
]
|
||||
|
||||
if (is_win) {
|
||||
brave_deps_chrome_browser_resources_settings_in_files += [
|
||||
"pin_shortcut_page/pin_shortcut_page.js",
|
||||
"pin_shortcut_page/pin_shortcut_page_browser_proxy.m.js",
|
||||
]
|
||||
}
|
||||
|
||||
brave_deps_chrome_browser_resources_settings_extra_deps = [
|
||||
"//brave/browser/resources/settings:preprocess",
|
||||
"//brave/browser/resources/settings:preprocess_generated",
|
||||
|
||||
+7
-2
@@ -145,8 +145,6 @@ source_set("ui") {
|
||||
"webui/settings/brave_privacy_handler.h",
|
||||
"webui/settings/brave_search_engines_handler.cc",
|
||||
"webui/settings/brave_search_engines_handler.h",
|
||||
"webui/settings/brave_settings_default_browser_handler.cc",
|
||||
"webui/settings/brave_settings_default_browser_handler.h",
|
||||
"webui/settings/brave_settings_localized_strings_provider.cc",
|
||||
"webui/settings/brave_settings_localized_strings_provider.h",
|
||||
"webui/settings/brave_sync_handler.cc",
|
||||
@@ -163,6 +161,13 @@ source_set("ui") {
|
||||
"webui/speedreader/speedreader_panel_ui.h",
|
||||
]
|
||||
|
||||
if (is_win) {
|
||||
sources += [
|
||||
"webui/settings/pin_shortcut_handler.cc",
|
||||
"webui/settings/pin_shortcut_handler.h",
|
||||
]
|
||||
}
|
||||
|
||||
if (is_mac) {
|
||||
sources += [ "webui/settings/brave_import_data_handler_mac.mm" ]
|
||||
} else {
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
E_CPONLY(kColorIconBase) \
|
||||
E_CPONLY(kColorMenuItemSubText) \
|
||||
E_CPONLY(kColorBookmarkBarInstructionsText) \
|
||||
E_CPONLY(kColorLocationBarFocusRing)
|
||||
E_CPONLY(kColorLocationBarFocusRing) \
|
||||
E_CPONLY(kColorDialogDontAskAgainButton) \
|
||||
E_CPONLY(kColorDialogDontAskAgainButtonHovered) \
|
||||
|
||||
#define BRAVE_SEARCH_CONVERSION_COLOR_IDS \
|
||||
E_CPONLY(kColorSearchConversionBannerTypeBackgroundBorder) \
|
||||
|
||||
@@ -280,6 +280,9 @@ void AddChromeLightThemeColorMixer(ui::ColorProvider* provider,
|
||||
mixer[kColorToolbarContentAreaSeparator] = {ui::kColorFrameActive};
|
||||
mixer[kColorToolbarTopSeparatorFrameActive] = {kColorToolbar};
|
||||
mixer[kColorToolbarTopSeparatorFrameInactive] = {kColorToolbar};
|
||||
mixer[kColorDialogDontAskAgainButton] = {SkColorSetRGB(0x86, 0x8E, 0x96)};
|
||||
mixer[kColorDialogDontAskAgainButtonHovered] = {
|
||||
SkColorSetRGB(0x49, 0x50, 0x57)};
|
||||
mixer[ui::kColorFrameActive] = {kLightFrame};
|
||||
mixer[ui::kColorFrameInactive] = {
|
||||
color_utils::HSLShift(kLightFrame, {-1, -1, 0.6})};
|
||||
@@ -323,6 +326,9 @@ void AddChromeDarkThemeColorMixer(ui::ColorProvider* provider,
|
||||
mixer[kColorToolbarContentAreaSeparator] = {kColorToolbar};
|
||||
mixer[kColorToolbarTopSeparatorFrameActive] = {kColorToolbar};
|
||||
mixer[kColorToolbarTopSeparatorFrameInactive] = {kColorToolbar};
|
||||
mixer[kColorDialogDontAskAgainButton] = {SkColorSetRGB(0x84, 0x88, 0x9C)};
|
||||
mixer[kColorDialogDontAskAgainButtonHovered] = {
|
||||
SkColorSetRGB(0xC2, 0xC4, 0xCF)};
|
||||
mixer[ui::kColorFrameActive] = {kDarkFrame};
|
||||
mixer[ui::kColorFrameInactive] = {
|
||||
color_utils::HSLShift(kDarkFrame, {-1, -1, 0.6})};
|
||||
|
||||
@@ -11,17 +11,20 @@
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "brave/browser/brave_shell_integration.h"
|
||||
#include "brave/browser/ui/browser_dialogs.h"
|
||||
#include "brave/browser/ui/color/brave_color_id.h"
|
||||
#include "brave/components/constants/pref_names.h"
|
||||
#include "brave/components/l10n/common/locale_util.h"
|
||||
#include "brave/grit/brave_generated_resources.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/browser_process.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/metadata/metadata_impl_macros.h"
|
||||
#include "ui/color/color_provider.h"
|
||||
#include "ui/views/bubble/bubble_frame_view.h"
|
||||
#include "ui/views/controls/button/checkbox.h"
|
||||
#include "ui/views/controls/button/label_button.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/layout/box_layout.h"
|
||||
#include "ui/views/layout/layout_provider.h"
|
||||
@@ -44,27 +47,73 @@ namespace {
|
||||
|
||||
constexpr int kPadding = 24;
|
||||
|
||||
class NoSnappedBubbleFrameView : public views::BubbleFrameView {
|
||||
class DontAskAgainButton : public views::LabelButton {
|
||||
public:
|
||||
using BubbleFrameView::BubbleFrameView;
|
||||
~NoSnappedBubbleFrameView() override = default;
|
||||
METADATA_HEADER(DontAskAgainButton);
|
||||
|
||||
NoSnappedBubbleFrameView(const NoSnappedBubbleFrameView&) = delete;
|
||||
NoSnappedBubbleFrameView& operator=(const NoSnappedBubbleFrameView&) = delete;
|
||||
explicit DontAskAgainButton(PressedCallback callback)
|
||||
: LabelButton(std::move(callback)) {
|
||||
SetFontList();
|
||||
SetText(brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_BRAVE_DEFAULT_BROWSER_DIALOG_DONT_ASK));
|
||||
}
|
||||
DontAskAgainButton(const DontAskAgainButton&) = delete;
|
||||
DontAskAgainButton& operator=(const DontAskAgainButton&) = delete;
|
||||
~DontAskAgainButton() override = default;
|
||||
|
||||
private:
|
||||
// views::BubbleFrarmeView overrides:
|
||||
// BubbleFrameView::GetFrameWidthForClientWidth() uses snapped dialog width
|
||||
// if dialog uses buttons. This width doesn't align with our design.
|
||||
int GetFrameWidthForClientWidth(int client_width) const override {
|
||||
// This doesn't use title bar. So, just using |client_width| is fine.
|
||||
return client_width;
|
||||
void SetFontList() {
|
||||
gfx::FontList font_list;
|
||||
constexpr int kFontSize = 13;
|
||||
font_list.Derive(kFontSize - font_list.GetFontSize(),
|
||||
font_list.GetFontStyle(), gfx::Font::Weight::NORMAL);
|
||||
label()->SetFontList(font_list);
|
||||
}
|
||||
|
||||
// views::LabelButton overrides:
|
||||
void OnThemeChanged() override {
|
||||
LabelButton::OnThemeChanged();
|
||||
|
||||
auto* cp = GetColorProvider();
|
||||
SetTextColor(views::Button::STATE_NORMAL,
|
||||
cp->GetColor(kColorDialogDontAskAgainButton));
|
||||
SetTextColor(views::Button::STATE_HOVERED,
|
||||
cp->GetColor(kColorDialogDontAskAgainButtonHovered));
|
||||
}
|
||||
};
|
||||
|
||||
BEGIN_METADATA(DontAskAgainButton, views::LabelButton)
|
||||
END_METADATA
|
||||
|
||||
class CustomCheckbox : public views::Checkbox {
|
||||
public:
|
||||
METADATA_HEADER(CustomCheckbox);
|
||||
|
||||
explicit CustomCheckbox(const std::u16string& label) : Checkbox(label) {
|
||||
SetFontList();
|
||||
}
|
||||
~CustomCheckbox() override = default;
|
||||
CustomCheckbox(const CustomCheckbox&) = delete;
|
||||
CustomCheckbox& operator=(const CustomCheckbox&) = delete;
|
||||
|
||||
private:
|
||||
void SetFontList() {
|
||||
gfx::FontList font_list;
|
||||
constexpr int kFontSize = 14;
|
||||
font_list.Derive(kFontSize - font_list.GetFontSize(),
|
||||
font_list.GetFontStyle(), gfx::Font::Weight::NORMAL);
|
||||
label()->SetFontList(font_list);
|
||||
}
|
||||
};
|
||||
|
||||
BEGIN_METADATA(CustomCheckbox, views::Checkbox)
|
||||
END_METADATA
|
||||
|
||||
} // namespace
|
||||
|
||||
BraveDefaultBrowserDialogView::BraveDefaultBrowserDialogView() {
|
||||
set_should_ignore_snapping(true);
|
||||
|
||||
SetButtonLabel(ui::DIALOG_BUTTON_OK,
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_BRAVE_DEFAULT_BROWSER_DIALOG_OK_BUTTON_LABEL));
|
||||
@@ -78,7 +127,6 @@ BraveDefaultBrowserDialogView::BraveDefaultBrowserDialogView() {
|
||||
SetCancelCallback(
|
||||
base::BindOnce(&BraveDefaultBrowserDialogView::OnCancelButtonClicked,
|
||||
base::Unretained(this)));
|
||||
|
||||
CreateChildViews();
|
||||
}
|
||||
|
||||
@@ -119,30 +167,19 @@ void BraveDefaultBrowserDialogView::CreateChildViews() {
|
||||
contents_label_->SetMultiLine(true);
|
||||
contents_label_->SetMaximumWidth(350);
|
||||
|
||||
dont_ask_again_checkbox_ = AddChildView(std::make_unique<views::Checkbox>(
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
pin_shortcut_checkbox_ = AddChildView(std::make_unique<CustomCheckbox>(
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_FIRSTRUN_DLG_PIN_SHORTCUT_TEXT)));
|
||||
SetExtraView(std::make_unique<DontAskAgainButton>(
|
||||
views::Button::PressedCallback(base::BindRepeating(
|
||||
&BraveDefaultBrowserDialogView::OnDontAskAgainButtonPressed,
|
||||
base::Unretained(this)))));
|
||||
#else
|
||||
dont_ask_again_checkbox_ = AddChildView(std::make_unique<CustomCheckbox>(
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_BRAVE_DEFAULT_BROWSER_DIALOG_DONT_ASK)));
|
||||
}
|
||||
|
||||
std::unique_ptr<views::NonClientFrameView>
|
||||
BraveDefaultBrowserDialogView::CreateNonClientFrameView(views::Widget* widget) {
|
||||
if (!use_custom_frame())
|
||||
return DialogDelegateView::CreateNonClientFrameView(widget);
|
||||
|
||||
views::LayoutProvider* provider = views::LayoutProvider::Get();
|
||||
auto frame = std::make_unique<NoSnappedBubbleFrameView>(
|
||||
provider->GetInsetsMetric(views::INSETS_DIALOG_TITLE), gfx::Insets());
|
||||
|
||||
const views::BubbleBorder::Shadow kShadow =
|
||||
views::BubbleBorder::DIALOG_SHADOW;
|
||||
std::unique_ptr<views::BubbleBorder> border =
|
||||
std::make_unique<views::BubbleBorder>(views::BubbleBorder::FLOAT,
|
||||
kShadow);
|
||||
if (GetParams().round_corners)
|
||||
border->SetCornerRadius(GetCornerRadius());
|
||||
frame->SetFootnoteView(DisownFootnoteView());
|
||||
frame->SetBubbleBorder(std::move(border));
|
||||
return frame;
|
||||
#endif
|
||||
}
|
||||
|
||||
ui::ModalType BraveDefaultBrowserDialogView::GetModalType() const {
|
||||
@@ -158,8 +195,10 @@ void BraveDefaultBrowserDialogView::OnWidgetInitialized() {
|
||||
}
|
||||
|
||||
void BraveDefaultBrowserDialogView::OnCancelButtonClicked() {
|
||||
#if !BUILDFLAG(IS_WIN)
|
||||
g_browser_process->local_state()->SetBoolean(
|
||||
kDefaultBrowserPromptEnabled, !dont_ask_again_checkbox_->GetChecked());
|
||||
#endif
|
||||
}
|
||||
|
||||
void BraveDefaultBrowserDialogView::OnAcceptButtonClicked() {
|
||||
@@ -168,14 +207,27 @@ void BraveDefaultBrowserDialogView::OnAcceptButtonClicked() {
|
||||
// and it will be automatically freed once all its tasks have finished.
|
||||
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
->StartSetAsDefault(
|
||||
base::BindOnce([](shell_integration::DefaultWebClientState state) {
|
||||
->StartSetAsDefault(base::BindOnce(
|
||||
[](bool pin_to_taskbar,
|
||||
shell_integration::DefaultWebClientState state) {
|
||||
if (state == shell_integration::DefaultWebClientState::IS_DEFAULT) {
|
||||
// Try to pin to taskbar when Brave is set as a default browser.
|
||||
shell_integration::win::PinToTaskbar();
|
||||
}
|
||||
}));
|
||||
},
|
||||
pin_shortcut_checkbox_->GetChecked()));
|
||||
#else
|
||||
->StartSetAsDefault(base::NullCallback());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
void BraveDefaultBrowserDialogView::OnDontAskAgainButtonPressed() {
|
||||
g_browser_process->local_state()->SetBoolean(kDefaultBrowserPromptEnabled,
|
||||
false);
|
||||
CancelDialog();
|
||||
}
|
||||
#endif
|
||||
|
||||
BEGIN_METADATA(BraveDefaultBrowserDialogView, views::DialogDelegateView)
|
||||
END_METADATA
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/base/metadata/metadata_header_macros.h"
|
||||
#include "ui/views/window/dialog_delegate.h"
|
||||
|
||||
namespace views {
|
||||
@@ -17,6 +20,8 @@ class Label;
|
||||
|
||||
class BraveDefaultBrowserDialogView : public views::DialogDelegateView {
|
||||
public:
|
||||
METADATA_HEADER(BraveDefaultBrowserDialogView);
|
||||
|
||||
BraveDefaultBrowserDialogView();
|
||||
~BraveDefaultBrowserDialogView() override;
|
||||
|
||||
@@ -27,8 +32,6 @@ class BraveDefaultBrowserDialogView : public views::DialogDelegateView {
|
||||
// views::DialogDelegateView overrides:
|
||||
ui::ModalType GetModalType() const override;
|
||||
bool ShouldShowCloseButton() const override;
|
||||
std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
|
||||
views::Widget* widget) override;
|
||||
void OnWidgetInitialized() override;
|
||||
|
||||
private:
|
||||
@@ -36,9 +39,18 @@ class BraveDefaultBrowserDialogView : public views::DialogDelegateView {
|
||||
void OnAcceptButtonClicked();
|
||||
void CreateChildViews();
|
||||
|
||||
views::Label* header_label_ = nullptr;
|
||||
views::Label* contents_label_ = nullptr;
|
||||
views::Checkbox* dont_ask_again_checkbox_ = nullptr;
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
void OnDontAskAgainButtonPressed();
|
||||
#endif
|
||||
|
||||
raw_ptr<views::Label> header_label_ = nullptr;
|
||||
raw_ptr<views::Label> contents_label_ = nullptr;
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
raw_ptr<views::Checkbox> pin_shortcut_checkbox_ = nullptr;
|
||||
#else
|
||||
raw_ptr<views::Checkbox> dont_ask_again_checkbox_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_DEFAULT_BROWSER_DIALOG_VIEW_H_
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
#include "base/bind.h"
|
||||
#include "base/memory/scoped_refptr.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "brave/components/l10n/common/locale_util.h"
|
||||
#include "brave/grit/brave_generated_resources.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/first_run/first_run.h"
|
||||
#include "chrome/browser/first_run/first_run_dialog.h"
|
||||
#include "chrome/browser/ui/ui_features.h"
|
||||
#include "chrome/grit/chromium_strings.h"
|
||||
#include "ui/base/l10n/l10n_util.h"
|
||||
#include "ui/base/metadata/metadata_impl_macros.h"
|
||||
#include "ui/gfx/font.h"
|
||||
#include "ui/gfx/geometry/insets.h"
|
||||
#include "ui/views/controls/button/checkbox.h"
|
||||
#include "ui/views/controls/label.h"
|
||||
#include "ui/views/layout/box_layout.h"
|
||||
#include "ui/views/window/dialog_delegate.h"
|
||||
@@ -32,8 +32,6 @@
|
||||
#include "chrome/browser/shell_integration.h"
|
||||
#endif
|
||||
|
||||
namespace first_run {
|
||||
|
||||
namespace {
|
||||
|
||||
void ShowBraveFirstRunDialogViews(Profile* profile) {
|
||||
@@ -42,8 +40,38 @@ void ShowBraveFirstRunDialogViews(Profile* profile) {
|
||||
run_loop.Run();
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
class PinShortcutCheckbox : public views::Checkbox {
|
||||
public:
|
||||
METADATA_HEADER(PinShortcutCheckbox);
|
||||
|
||||
PinShortcutCheckbox() {
|
||||
SetFontList();
|
||||
SetText(brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_FIRSTRUN_DLG_PIN_SHORTCUT_TEXT));
|
||||
}
|
||||
~PinShortcutCheckbox() override = default;
|
||||
PinShortcutCheckbox(const PinShortcutCheckbox&) = delete;
|
||||
PinShortcutCheckbox& operator=(const PinShortcutCheckbox&) = delete;
|
||||
|
||||
private:
|
||||
void SetFontList() {
|
||||
gfx::FontList font_list;
|
||||
constexpr int kFontSize = 14;
|
||||
font_list.Derive(kFontSize - font_list.GetFontSize(),
|
||||
font_list.GetFontStyle(), gfx::Font::Weight::NORMAL);
|
||||
label()->SetFontList(font_list);
|
||||
}
|
||||
};
|
||||
|
||||
BEGIN_METADATA(PinShortcutCheckbox, views::Checkbox)
|
||||
END_METADATA
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace first_run {
|
||||
|
||||
void ShowFirstRunDialog(Profile* profile) {
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
if (base::FeatureList::IsEnabled(features::kViewsFirstRunDialog))
|
||||
@@ -71,19 +99,11 @@ BraveFirstRunDialog::BraveFirstRunDialog(base::RepeatingClosure quit_runloop)
|
||||
SetTitle(IDS_FIRST_RUN_DIALOG_WINDOW_TITLE);
|
||||
#endif
|
||||
SetButtonLabel(ui::DIALOG_BUTTON_OK,
|
||||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_OK_BUTTON_LABEL));
|
||||
SetButtonLabel(
|
||||
ui::DIALOG_BUTTON_CANCEL,
|
||||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_CANCEL_BUTTON_LABEL));
|
||||
constexpr int kChildSpacing = 16;
|
||||
constexpr int kPadding = 24;
|
||||
constexpr int kTopPadding = 20;
|
||||
constexpr int kBottomPadding = 55;
|
||||
|
||||
SetLayoutManager(std::make_unique<views::BoxLayout>(
|
||||
views::BoxLayout::Orientation::kVertical,
|
||||
gfx::Insets::TLBR(kTopPadding, kPadding, kBottomPadding, kPadding),
|
||||
kChildSpacing));
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_FIRSTRUN_DLG_OK_BUTTON_LABEL));
|
||||
SetButtonLabel(ui::DIALOG_BUTTON_CANCEL,
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_FIRSTRUN_DLG_CANCEL_BUTTON_LABEL));
|
||||
|
||||
constexpr int kHeaderFontSize = 16;
|
||||
int size_diff =
|
||||
@@ -93,7 +113,8 @@ BraveFirstRunDialog::BraveFirstRunDialog(base::RepeatingClosure quit_runloop)
|
||||
.DeriveWithSizeDelta(size_diff)
|
||||
.DeriveWithWeight(gfx::Font::Weight::SEMIBOLD)};
|
||||
auto* header_label = AddChildView(std::make_unique<views::Label>(
|
||||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_HEADER_TEXT), header_font));
|
||||
brave_l10n::GetLocalizedResourceUTF16String(IDS_FIRSTRUN_DLG_HEADER_TEXT),
|
||||
header_font));
|
||||
header_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
||||
|
||||
constexpr int kContentFontSize = 15;
|
||||
@@ -104,12 +125,32 @@ BraveFirstRunDialog::BraveFirstRunDialog(base::RepeatingClosure quit_runloop)
|
||||
.DeriveWithSizeDelta(size_diff)
|
||||
.DeriveWithWeight(gfx::Font::Weight::NORMAL)};
|
||||
auto* contents_label = AddChildView(std::make_unique<views::Label>(
|
||||
l10n_util::GetStringUTF16(IDS_FIRSTRUN_DLG_CONTENTS_TEXT),
|
||||
brave_l10n::GetLocalizedResourceUTF16String(
|
||||
IDS_FIRSTRUN_DLG_CONTENTS_TEXT),
|
||||
contents_font));
|
||||
contents_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
||||
contents_label->SetMultiLine(true);
|
||||
constexpr int kMaxWidth = 350;
|
||||
contents_label->SetMaximumWidth(kMaxWidth);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
pin_shortcut_checkbox_ =
|
||||
AddChildView(std::make_unique<PinShortcutCheckbox>());
|
||||
#endif
|
||||
|
||||
constexpr int kChildSpacing = 16;
|
||||
constexpr int kPadding = 24;
|
||||
constexpr int kTopPadding = 20;
|
||||
int kBottomPadding = 55;
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
kBottomPadding -= pin_shortcut_checkbox_->GetPreferredSize().height();
|
||||
#endif
|
||||
|
||||
SetLayoutManager(std::make_unique<views::BoxLayout>(
|
||||
views::BoxLayout::Orientation::kVertical,
|
||||
gfx::Insets::TLBR(kTopPadding, kPadding, kBottomPadding, kPadding),
|
||||
kChildSpacing));
|
||||
}
|
||||
|
||||
BraveFirstRunDialog::~BraveFirstRunDialog() = default;
|
||||
@@ -124,13 +165,16 @@ bool BraveFirstRunDialog::Accept() {
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
base::MakeRefCounted<shell_integration::BraveDefaultBrowserWorker>()
|
||||
->StartSetAsDefault(
|
||||
base::BindOnce([](shell_integration::DefaultWebClientState state) {
|
||||
if (state == shell_integration::DefaultWebClientState::IS_DEFAULT) {
|
||||
->StartSetAsDefault(base::BindOnce(
|
||||
[](bool pin_to_shortcut,
|
||||
shell_integration::DefaultWebClientState state) {
|
||||
if (pin_to_shortcut &&
|
||||
state == shell_integration::DefaultWebClientState::IS_DEFAULT) {
|
||||
// Try to pin to taskbar when Brave is set as a default browser.
|
||||
shell_integration::win::PinToTaskbar();
|
||||
}
|
||||
}));
|
||||
},
|
||||
pin_shortcut_checkbox_->GetChecked()));
|
||||
#else
|
||||
shell_integration::SetAsDefaultBrowser();
|
||||
#endif
|
||||
|
||||
@@ -7,9 +7,15 @@
|
||||
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_FIRST_RUN_DIALOG_H_
|
||||
|
||||
#include "base/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "build/build_config.h"
|
||||
#include "ui/base/metadata/metadata_header_macros.h"
|
||||
#include "ui/views/window/dialog_delegate.h"
|
||||
|
||||
namespace views {
|
||||
class Checkbox;
|
||||
} // namespace views
|
||||
|
||||
class BraveFirstRunDialog : public views::DialogDelegateView {
|
||||
public:
|
||||
METADATA_HEADER(BraveFirstRunDialog);
|
||||
@@ -33,6 +39,10 @@ class BraveFirstRunDialog : public views::DialogDelegateView {
|
||||
void WindowClosing() override;
|
||||
|
||||
base::RepeatingClosure quit_runloop_;
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
raw_ptr<views::Checkbox> pin_shortcut_checkbox_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_FIRST_RUN_DIALOG_H_
|
||||
|
||||
@@ -29,12 +29,17 @@
|
||||
#include "brave/components/speedreader/common/buildflags.h"
|
||||
#include "brave/components/tor/buildflags/buildflags.h"
|
||||
#include "brave/components/version_info/version_info.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/webui/settings/metrics_reporting_handler.h"
|
||||
#include "components/sync/base/command_line_switches.h"
|
||||
#include "content/public/browser/web_ui_data_source.h"
|
||||
#include "content/public/common/content_features.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include "brave/browser/ui/webui/settings/pin_shortcut_handler.h"
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_SPEEDREADER)
|
||||
#include "brave/components/speedreader/common/features.h"
|
||||
#endif
|
||||
@@ -64,6 +69,9 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
|
||||
#if BUILDFLAG(ENABLE_TOR)
|
||||
web_ui->AddMessageHandler(std::make_unique<BraveTorHandler>());
|
||||
#endif
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
web_ui->AddMessageHandler(std::make_unique<PinShortcutHandler>());
|
||||
#endif
|
||||
}
|
||||
|
||||
BraveSettingsUI::~BraveSettingsUI() = default;
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
/* Copyright (c) 2022 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/brave_settings_default_browser_handler.h"
|
||||
|
||||
#include "build/build_config.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include "brave/browser/brave_shell_integration_win.h"
|
||||
#endif
|
||||
|
||||
namespace settings {
|
||||
|
||||
BraveDefaultBrowserHandler::~BraveDefaultBrowserHandler() = default;
|
||||
|
||||
void BraveDefaultBrowserHandler::SetAsDefaultBrowser(
|
||||
const base::Value::List& args) {
|
||||
DefaultBrowserHandler::SetAsDefaultBrowser(args);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
// Trying to pin when user ask this as a default browser.
|
||||
shell_integration::win::PinToTaskbar(Profile::FromWebUI(web_ui()));
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace settings
|
||||
@@ -1,27 +0,0 @@
|
||||
/* Copyright (c) 2022 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_BRAVE_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
|
||||
#include "chrome/browser/ui/webui/settings/settings_default_browser_handler.h"
|
||||
|
||||
namespace settings {
|
||||
|
||||
class BraveDefaultBrowserHandler : public DefaultBrowserHandler {
|
||||
public:
|
||||
using DefaultBrowserHandler::DefaultBrowserHandler;
|
||||
BraveDefaultBrowserHandler(const BraveDefaultBrowserHandler&) = delete;
|
||||
BraveDefaultBrowserHandler& operator=(const BraveDefaultBrowserHandler&) =
|
||||
delete;
|
||||
~BraveDefaultBrowserHandler() override;
|
||||
|
||||
// DefaultBrowserHandler overrides:
|
||||
void SetAsDefaultBrowser(const base::Value::List& args) override;
|
||||
};
|
||||
|
||||
} // namespace settings
|
||||
|
||||
#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
@@ -270,6 +270,12 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
|
||||
{"braveNewTabNewTabPageShows", IDS_SETTINGS_NEW_TAB_NEW_TAB_PAGE_SHOWS},
|
||||
{"braveNewTabNewTabCustomizeWidgets",
|
||||
IDS_SETTINGS_NEW_TAB_NEW_TAB_CUSTOMIZE_WIDGETS},
|
||||
// Pin shortcut page
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
{"canPinShortcut", IDS_SETTINGS_CAN_PIN_SHORTCUT},
|
||||
{"pinShortcut", IDS_SETTINGS_PIN_SHORTCUT},
|
||||
{"shortcutPinned", IDS_SETTINGS_SHORTCUT_PINNED},
|
||||
#endif
|
||||
// Rewards page
|
||||
{"braveRewards", IDS_SETTINGS_BRAVE_REWARDS_TITLE},
|
||||
{"braveRewardsDisabledLabel", IDS_SETTINGS_BRAVE_REWARDS_DISABLED_LABEL},
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
/* Copyright (c) 2022 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/pin_shortcut_handler.h"
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "build/build_config.h"
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/web_ui.h"
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
#include "brave/browser/brave_shell_integration_win.h"
|
||||
#endif
|
||||
|
||||
PinShortcutHandler::PinShortcutHandler() = default;
|
||||
|
||||
PinShortcutHandler::~PinShortcutHandler() = default;
|
||||
|
||||
void PinShortcutHandler::RegisterMessages() {
|
||||
web_ui()->RegisterMessageCallback(
|
||||
"checkShortcutPinState",
|
||||
base::BindRepeating(&PinShortcutHandler::HandleCheckShortcutPinState,
|
||||
base::Unretained(this)));
|
||||
web_ui()->RegisterMessageCallback(
|
||||
"pinShortcut", base::BindRepeating(&PinShortcutHandler::HandlePinShortcut,
|
||||
base::Unretained(this)));
|
||||
}
|
||||
|
||||
void PinShortcutHandler::HandlePinShortcut(const base::Value::List& args) {
|
||||
AllowJavascript();
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
shell_integration::win::PinToTaskbar(
|
||||
Profile::FromWebUI(web_ui()),
|
||||
base::BindOnce(&PinShortcutHandler::OnPinShortcut,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
#endif
|
||||
}
|
||||
|
||||
void PinShortcutHandler::HandleCheckShortcutPinState(
|
||||
const base::Value::List& args) {
|
||||
AllowJavascript();
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
shell_integration::win::IsShortcutPinned(
|
||||
base::BindOnce(&PinShortcutHandler::OnCheckShortcutPinState,
|
||||
weak_factory_.GetWeakPtr()));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
void PinShortcutHandler::OnPinShortcut(bool pinned) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
NotifyShortcutPinStateChangeToPage(pinned);
|
||||
}
|
||||
|
||||
void PinShortcutHandler::OnCheckShortcutPinState(bool pinned) {
|
||||
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
||||
|
||||
NotifyShortcutPinStateChangeToPage(pinned);
|
||||
}
|
||||
#endif // BUILDFLAG(IS_WIN)
|
||||
|
||||
void PinShortcutHandler::NotifyShortcutPinStateChangeToPage(bool pinned) {
|
||||
if (IsJavascriptAllowed()) {
|
||||
FireWebUIListener("shortcut-pin-state-changed", base::Value(pinned));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/* Copyright (c) 2022 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_PIN_SHORTCUT_HANDLER_H_
|
||||
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_PIN_SHORTCUT_HANDLER_H_
|
||||
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
|
||||
|
||||
class PinShortcutHandler : public settings::SettingsPageUIHandler {
|
||||
public:
|
||||
PinShortcutHandler();
|
||||
~PinShortcutHandler() override;
|
||||
|
||||
PinShortcutHandler(const PinShortcutHandler&) = delete;
|
||||
PinShortcutHandler& operator=(const PinShortcutHandler&) = delete;
|
||||
|
||||
private:
|
||||
// SettingsPageUIHandler overrides:
|
||||
void RegisterMessages() override;
|
||||
void OnJavascriptAllowed() override {}
|
||||
void OnJavascriptDisallowed() override {}
|
||||
|
||||
void HandleCheckShortcutPinState(const base::Value::List& args);
|
||||
void HandlePinShortcut(const base::Value::List& args);
|
||||
void NotifyShortcutPinStateChangeToPage(bool pinned);
|
||||
|
||||
#if BUILDFLAG(IS_WIN)
|
||||
void OnPinShortcut(bool pinned);
|
||||
void OnCheckShortcutPinState(bool pinned);
|
||||
|
||||
base::WeakPtrFactory<PinShortcutHandler> weak_factory_{this};
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_PIN_SHORTCUT_HANDLER_H_
|
||||
@@ -1,19 +0,0 @@
|
||||
/* Copyright (c) 2022 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_WEBUI_SETTINGS_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_WEBUI_SETTINGS_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
|
||||
#include "chrome/browser/shell_integration.h"
|
||||
|
||||
#define SetAsDefaultBrowser \
|
||||
UnUsed() {} \
|
||||
friend class BraveDefaultBrowserHandler; \
|
||||
virtual void SetAsDefaultBrowser
|
||||
|
||||
#include "src/chrome/browser/ui/webui/settings/settings_default_browser_handler.h"
|
||||
#undef SetAsDefaultBrowser
|
||||
|
||||
#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_UI_WEBUI_SETTINGS_SETTINGS_DEFAULT_BROWSER_HANDLER_H_
|
||||
@@ -5,12 +5,9 @@
|
||||
|
||||
#include "brave/browser/ui/webui/settings/brave_import_data_handler.h"
|
||||
#include "brave/browser/ui/webui/settings/brave_search_engines_handler.h"
|
||||
#include "brave/browser/ui/webui/settings/brave_settings_default_browser_handler.h"
|
||||
|
||||
#define ImportDataHandler BraveImportDataHandler
|
||||
#define SearchEnginesHandler BraveSearchEnginesHandler
|
||||
#define DefaultBrowserHandler BraveDefaultBrowserHandler
|
||||
#include "src/chrome/browser/ui/webui/settings/settings_ui.cc"
|
||||
#undef DefaultBrowserHandler
|
||||
#undef ImportDataHandler
|
||||
#undef SearchEnginesHandler
|
||||
|
||||
Reference in New Issue
Block a user