Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select default browser on welcome page import page #17270

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion browser/ui/webui/brave_welcome_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <string>

#include "base/feature_list.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/task/single_thread_task_runner.h"
#include "brave/browser/ui/webui/brave_webui_source.h"
Expand Down Expand Up @@ -122,8 +123,12 @@ class WelcomeDOMHandler : public WebUIMessageHandler {
private:
void HandleImportNowRequested(const base::Value::List& args);
void HandleRecordP3A(const base::Value::List& args);
void HandleGetDefaultBrowser(const base::Value::List& args);
void SetLocalStateBooleanEnabled(const std::string& path,
const base::Value::List& args);
void OnGetDefaultBrowser(const std::string& callback_id,
shell_integration::DefaultWebClientState state,
const std::u16string& name);
void SetP3AEnabled(const base::Value::List& args);
void HandleOpenSettingsPage(const base::Value::List& args);
void HandleSetMetricsReportingEnabled(const base::Value::List& args);
Expand All @@ -132,7 +137,8 @@ class WelcomeDOMHandler : public WebUIMessageHandler {
int screen_number_ = 0;
bool finished_ = false;
bool skipped_ = false;
Profile* profile_ = nullptr;
raw_ptr<Profile> profile_ = nullptr;
base::WeakPtrFactory<WelcomeDOMHandler> weak_ptr_factory_{this};
};

WelcomeDOMHandler::WelcomeDOMHandler(Profile* profile) : profile_(profile) {}
Expand Down Expand Up @@ -164,6 +170,10 @@ void WelcomeDOMHandler::RegisterMessages() {
"setMetricsReportingEnabled",
base::BindRepeating(&WelcomeDOMHandler::HandleSetMetricsReportingEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getDefaultBrowser",
base::BindRepeating(&WelcomeDOMHandler::HandleGetDefaultBrowser,
base::Unretained(this)));
}

void WelcomeDOMHandler::HandleImportNowRequested(
Expand All @@ -172,6 +182,25 @@ void WelcomeDOMHandler::HandleImportNowRequested(
chrome::kImportDataSubPage);
}

void WelcomeDOMHandler::HandleGetDefaultBrowser(const base::Value::List& args) {
CHECK_EQ(1U, args.size());
const auto& callback_id = args[0].GetString();
AllowJavascript();

base::MakeRefCounted<shell_integration::DefaultSchemeClientWorker>(
GURL("https://brave.com"))
->StartCheckIsDefaultAndGetDefaultClientName(
base::BindOnce(&WelcomeDOMHandler::OnGetDefaultBrowser,
weak_ptr_factory_.GetWeakPtr(), callback_id));
}

void WelcomeDOMHandler::OnGetDefaultBrowser(
const std::string& callback_id,
shell_integration::DefaultWebClientState state,
const std::u16string& name) {
ResolveJavascriptCallback(base::Value(callback_id), base::Value(name));
}

void WelcomeDOMHandler::HandleRecordP3A(const base::Value::List& args) {
if (!args[0].is_int() || !args[1].is_bool() || !args[2].is_bool())
return;
Expand Down
12 changes: 7 additions & 5 deletions chromium_src/chrome/browser/importer/importer_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void AddChromeToProfiles(std::vector<importer::SourceProfile>* profiles,
chrome.importer_name = base::UTF8ToUTF16(base::StrCat({brand, " ", *name}));
chrome.importer_type = type;
chrome.services_supported = items;
chrome.profile = base::UTF8ToUTF16(brand);
spylogsster marked this conversation as resolved.
Show resolved Hide resolved
chrome.source_path = user_data_folder.Append(
base::FilePath::StringType(profile->begin(), profile->end()));
profiles->push_back(chrome);
Expand All @@ -59,23 +60,24 @@ void DetectChromeProfiles(std::vector<importer::SourceProfile>* profiles) {
profiles,
GetChromeSourceProfiles(GetChromeUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetChromeUserDataFolder(), "Chrome", importer::TYPE_CHROME);
GetChromeUserDataFolder(), "Google Chrome", importer::TYPE_CHROME);
AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetChromeBetaUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetChromeBetaUserDataFolder(), "Chrome Beta", importer::TYPE_CHROME);
GetChromeBetaUserDataFolder(), "Google Chrome Beta",
importer::TYPE_CHROME);
AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetChromeDevUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetChromeDevUserDataFolder(), "Chrome Dev", importer::TYPE_CHROME);
GetChromeDevUserDataFolder(), "Google Chrome Dev", importer::TYPE_CHROME);
#if !BUILDFLAG(IS_LINUX)
AddChromeToProfiles(
profiles,
GetChromeSourceProfiles(GetCanaryUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetCanaryUserDataFolder(), "Chrome Canary", importer::TYPE_CHROME);
GetCanaryUserDataFolder(), "Google Chrome Canary", importer::TYPE_CHROME);
#endif
AddChromeToProfiles(
profiles,
Expand Down Expand Up @@ -111,7 +113,7 @@ void DetectChromeProfiles(std::vector<importer::SourceProfile>* profiles) {
profiles,
GetChromeSourceProfiles(GetWhaleUserDataFolder().Append(
base::FilePath::StringType(FILE_PATH_LITERAL("Local State")))),
GetWhaleUserDataFolder(), "Whale", importer::TYPE_WHALE);
GetWhaleUserDataFolder(), "NAVER Whale", importer::TYPE_WHALE);

#if BUILDFLAG(IS_LINUX)
// Installed via snap Opera has different profile path.
Expand Down
6 changes: 6 additions & 0 deletions components/brave_welcome_ui/api/welcome_browser_proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at https://mozilla.org/MPL/2.0/.

import { sendWithPromise } from 'chrome://resources/js/cr.js'
import { DefaultBrowserBrowserProxyImpl } from './default_browser_browser_proxy'
import { ImportDataBrowserProxyImpl, BrowserProfile as _BrowserProfile } from './import_data_browser_proxy'

Expand Down Expand Up @@ -31,6 +32,7 @@ export interface WelcomeBrowserProxy {
setP3AEnabled: (enabled: boolean) => void
setMetricsReportingEnabled: (enabled: boolean) => void
openSettingsPage: () => void
getDefaultBrowser: () => Promise<string>
}

export { DefaultBrowserBrowserProxyImpl, ImportDataBrowserProxyImpl }
Expand All @@ -52,6 +54,10 @@ export class WelcomeBrowserProxyImpl implements WelcomeBrowserProxy {
chrome.send('openSettingsPage')
}

getDefaultBrowser (): Promise<string> {
return sendWithPromise('getDefaultBrowser')
}

static getInstance (): WelcomeBrowserProxy {
return instance || (instance = new WelcomeBrowserProxyImpl())
}
Expand Down
20 changes: 15 additions & 5 deletions components/brave_welcome_ui/components/select-browser/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { getLocale } from '$web-common/locale'

import ChromeCanarySVG from '../svg/browser-icons/chrome-canary'
import ChromeSVG from '../svg/browser-icons/chrome'
import ChromeBetaSVG from '../svg/browser-icons/chrome-beta'
import ChromeDevSVG from '../svg/browser-icons/chrome-dev'
import ChromiumSVG from '../svg/browser-icons/chromium'
import EdgeSVG from '../svg/browser-icons/edge'
import FirefoxSVG from '../svg/browser-icons/firefox'
Expand All @@ -33,15 +35,17 @@ interface BrowserItemButtonProps {
}

const browserIcons = {
'Chrome Canary': <ChromeCanarySVG />,
'Chrome': <ChromeSVG />,
'Google Chrome Canary': <ChromeCanarySVG />,
'Google Chrome': <ChromeSVG />,
'Google Chrome Dev': <ChromeDevSVG />,
'Google Chrome Beta': <ChromeBetaSVG />,
'Chromium': <ChromiumSVG />,
'Microsoft Edge': <EdgeSVG />,
'Mozilla Firefox': <FirefoxSVG />,
'Firefox': <FirefoxSVG />,
'Opera': <OperaSVG />,
'Safari': <SafariSVG />,
'Vivaldi': <VivaldiSVG />,
'Whale': <WhaleSVG />,
'NAVER Whale': <WhaleSVG />,
'Yandex': <YandexSVG />,
'Microsoft Internet Explorer': <MicrosoftIE />
}
Expand Down Expand Up @@ -78,7 +82,6 @@ function BrowserItemButton (props: BrowserItemButtonProps) {
function SelectBrowser () {
const { browserProfiles, currentSelectedBrowser, setCurrentSelectedBrowser, setViewType, incrementCount, scenes } = React.useContext(DataContext)
const browserTypes = getUniqueBrowserTypes(browserProfiles ?? [])

const handleSelectionChange = (browserName: string) => {
setCurrentSelectedBrowser?.(browserName)
}
Expand Down Expand Up @@ -107,6 +110,13 @@ function SelectBrowser () {
WelcomeBrowserProxyImpl.getInstance().recordP3A({ currentScreen: ViewType.ImportSelectBrowser, isFinished: false, isSkipped: true })
}

React.useEffect(() => {
WelcomeBrowserProxyImpl.getInstance().getDefaultBrowser().then(
(name: string) => {
setCurrentSelectedBrowser?.(name)
})
}, [])

return (
<S.MainBox>
<div className="view-header-box">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2023 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 https://mozilla.org/MPL/2.0/.

import * as React from 'react'

const SvgComponent = (props: any) => (
<svg viewBox="0 0 256 256" fill="none" xmlns="http://www.w3.org/2000/svg">
<path
d="M211.358 181.183C209.473 184.533 207.441 187.703 205.295 190.681L227.844 181.183H211.358Z"
fill="#202124"
/>
<path
d="M127.95 178.012C155.557 178.012 177.937 155.618 177.937 127.994C177.937 100.369 155.557 77.9751 127.95 77.9751C100.343 77.9751 77.9633 100.369 77.9633 127.994C77.9633 155.618 100.343 178.012 127.95 178.012Z"
fill="white"
/>
<path
d="M171.338 153.047L128.093 227.996C145.638 228.012 162.877 223.4 178.073 214.626C193.268 205.852 205.885 193.224 214.65 178.017C223.415 162.809 228.02 145.559 228.001 128.003C227.982 110.448 223.338 93.2072 214.539 78.0193H128.048L127.975 78.0626C136.758 78.0339 145.392 80.3239 153.007 84.7014C160.622 89.0793 166.948 95.3897 171.347 102.996C175.745 110.602 178.06 119.235 178.059 128.023C178.058 136.811 175.739 145.442 171.338 153.047Z"
fill="url(#paint0_linear_6294_21486)"
/>
<path
d="M84.6595 153.047L41.4156 78.1025C32.6307 93.2983 28.0034 110.542 28 128.098C27.9966 145.653 32.6172 162.899 41.3961 178.098C50.1752 193.298 62.8025 205.913 78.0057 214.674C93.209 223.434 110.451 228.031 127.996 228L171.24 153.047V152.964C166.873 160.589 160.574 166.927 152.978 171.337C145.381 175.747 136.756 178.074 127.974 178.082C119.191 178.09 110.562 175.78 102.957 171.385C95.3519 166.989 89.0403 160.664 84.6595 153.047Z"
fill="url(#paint1_linear_6294_21486)"
/>
<path
d="M127.949 167.636C149.804 167.636 167.522 149.907 167.522 128.038C167.522 106.168 149.804 88.4395 127.949 88.4395C106.093 88.4395 88.3759 106.168 88.3759 128.038C88.3759 149.907 106.093 167.636 127.949 167.636Z"
fill="#1A73E8"
/>
<path
d="M127.95 78.0191H214.438C205.679 62.8073 193.068 50.1743 177.876 41.393C162.684 32.6116 145.447 27.9921 127.903 28C110.358 28.0079 93.1253 32.6428 77.9412 41.4377C62.7569 50.2327 50.1575 62.877 41.4124 78.0966L84.6586 153.047L84.732 153.088C80.3162 145.492 77.9816 136.864 77.9628 128.076C77.9445 119.289 80.2432 110.652 84.627 103.037C89.0111 95.4219 95.3249 89.0995 102.931 84.707C110.538 80.3141 119.167 78.0074 127.95 78.0191Z"
fill="url(#paint2_linear_6294_21486)"
/>
<path
d="M93.6066 121.785C93.6066 120.059 95.0053 118.659 96.7307 118.659H227.946V181.183H96.7307C95.0053 181.183 93.6066 179.783 93.6066 178.056V121.785Z"
fill="#3C4043"
/>
<path
d="M129.761 148.121C131.144 147.439 132.326 146.409 133.193 145.131C134.123 143.73 134.603 142.077 134.57 140.394C134.592 138.576 134.089 136.79 133.123 135.252C132.16 133.735 130.814 132.501 129.223 131.675C127.61 130.822 125.814 130.378 123.992 130.382H110.791V167.115H124.699C126.609 167.124 128.492 166.663 130.183 165.77C131.849 164.902 133.255 163.604 134.256 162.01C135.274 160.389 135.804 158.507 135.783 156.591C135.815 154.654 135.193 152.764 134.018 151.228C132.923 149.806 131.446 148.729 129.761 148.121ZM128.061 161.681C127.124 162.269 126.038 162.573 124.933 162.555H115.497V150.621H124.751C125.9 150.596 127.035 150.891 128.028 151.472C128.94 152.015 129.694 152.788 130.215 153.714C130.715 154.58 130.983 155.561 130.993 156.563C130.985 157.562 130.725 158.544 130.239 159.416C129.723 160.349 128.972 161.13 128.061 161.681ZM129.119 143.153C128.623 144.025 127.912 144.754 127.054 145.273C126.124 145.831 125.057 146.116 123.973 146.095H115.497V134.97H124.193C125.244 134.948 126.279 135.234 127.171 135.792C128.002 136.319 128.686 137.049 129.162 137.912C129.611 138.703 129.853 139.596 129.864 140.507C129.854 141.432 129.604 142.339 129.138 143.139L129.119 143.153Z"
fill="white"
/>
<path
d="M159.648 141.51C157.645 140.313 155.355 139.708 153.035 139.764C150.688 139.727 148.383 140.405 146.417 141.713C144.524 142.993 143.003 144.769 142.014 146.855C140.976 149.047 140.447 151.455 140.471 153.889C140.434 156.382 141 158.846 142.121 161.06C143.171 163.133 144.765 164.867 146.723 166.07C148.735 167.293 151.04 167.923 153.382 167.891C155.83 167.958 158.245 167.301 160.334 165.999C162.261 164.739 163.83 162.986 164.885 160.914L164.997 160.696L160.992 158.71L160.886 158.903C159.171 161.936 156.715 163.473 153.545 163.473C152.18 163.47 150.836 163.13 149.629 162.48C148.357 161.792 147.293 160.763 146.551 159.504C145.732 158.098 145.269 156.507 145.202 154.873H165.256L165.302 154.698C165.415 154.246 165.468 153.779 165.46 153.312C165.503 150.896 164.99 148.503 163.963 146.325C163.005 144.332 161.508 142.661 159.648 141.51ZM152.984 144.163C154.455 144.108 155.91 144.483 157.178 145.247C158.213 145.891 159.057 146.81 159.62 147.905C160.077 148.819 160.365 149.809 160.473 150.829H145.485C145.853 149.008 146.757 147.346 148.076 146.065C149.405 144.801 151.167 144.118 152.984 144.163Z"
fill="white"
/>
<path
d="M180.373 163.427C179.891 163.461 179.407 163.385 178.959 163.203C178.51 163.022 178.109 162.74 177.785 162.379C177.285 161.736 177.033 160.702 177.033 159.316V145.169H183.288V140.8H177.033V133.508H172.286V140.8H167.806V145.169H172.286V160.345C172.261 161.443 172.436 162.538 172.805 163.573C173.153 164.459 173.687 165.26 174.37 165.922C175.045 166.555 175.839 167.045 176.706 167.364C177.657 167.723 178.666 167.903 179.681 167.895C180.362 167.905 181.043 167.851 181.713 167.735C182.263 167.628 182.796 167.453 183.302 167.214L183.437 167.148V162.375L183.082 162.6C182.276 163.131 181.336 163.418 180.373 163.427Z"
fill="white"
/>
<path
d="M207.698 142.604C205.672 140.709 202.859 139.762 199.339 139.762C197.279 139.736 195.241 140.2 193.388 141.117C191.671 141.958 190.208 143.256 189.155 144.874L189.039 145.058L192.625 147.797L192.76 147.584C193.439 146.494 194.396 145.613 195.53 145.035C196.725 144.419 198.047 144.104 199.386 144.116C201.175 144.05 202.926 144.658 204.303 145.821C204.935 146.375 205.436 147.066 205.77 147.843C206.104 148.621 206.261 149.465 206.231 150.313V151.488C205.356 151.05 204.434 150.716 203.484 150.493C202.06 150.138 200.599 149.965 199.134 149.976C195.987 149.976 193.342 150.772 191.27 152.345C189.197 153.918 188.117 156.169 188.117 158.978C188.093 160.597 188.523 162.189 189.356 163.569C190.209 164.941 191.424 166.041 192.862 166.743C194.457 167.529 196.212 167.923 197.984 167.895C199.771 167.922 201.532 167.455 203.079 166.544C204.332 165.818 205.412 164.818 206.24 163.616V167.085H210.767V150.36C210.757 147.105 209.728 144.499 207.698 142.604ZM198.384 163.602C196.973 163.655 195.588 163.205 194.469 162.328C193.978 161.941 193.584 161.441 193.32 160.87C193.055 160.298 192.927 159.671 192.946 159.04C192.926 158.339 193.07 157.643 193.364 157.009C193.659 156.375 194.096 155.821 194.641 155.392C195.782 154.444 197.514 153.97 199.791 153.97C201.023 153.965 202.25 154.135 203.437 154.473C204.422 154.741 205.363 155.155 206.231 155.7C206.22 157.068 205.852 158.409 205.164 159.585C204.462 160.793 203.471 161.8 202.282 162.513C201.106 163.232 199.757 163.609 198.384 163.602Z"
fill="white"
/>
<defs>
<linearGradient id="paint0_linear_6294_21486" x1="117.536" y1="221.242" x2="203.275" y2="72.8335" gradientUnits="userSpaceOnUse">
<stop stopColor="#FCC934"/>
<stop offset="1" stopColor="#FBBC04"/>
</linearGradient>
<linearGradient id="paint1_linear_6294_21486" x1="145.604" y1="195.938" x2="19.0799" y2="122.937" gradientUnits="userSpaceOnUse">
<stop stopColor="#1E8E3E"/>
<stop offset="1" stopColor="#34A853"/>
</linearGradient>
<linearGradient id="paint2_linear_6294_21486" x1="43.4528" y1="90.5436" x2="212.537" y2="90.5436" gradientUnits="userSpaceOnUse">
<stop stopColor="#D93025"/>
<stop offset="1" stopColor="#EA4335"/>
</linearGradient>
</defs>
</svg>
)

export default SvgComponent
Loading