diff --git a/app/brave_settings_strings.grdp b/app/brave_settings_strings.grdp
index 747f2b7b5441..4cfe0659a5b2 100644
--- a/app/brave_settings_strings.grdp
+++ b/app/brave_settings_strings.grdp
@@ -1089,6 +1089,9 @@
Close
+
+ Remove
+
Enable NoScript™
diff --git a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.ts b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.ts
index 9f777771daf8..470714db64de 100644
--- a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.ts
+++ b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.ts
@@ -10,6 +10,7 @@ export type ExtensionV2 = {
id: string
name: string
description: string
+ installed: boolean
enabled: boolean
}
@@ -23,6 +24,7 @@ export interface BraveDefaultExtensionsBrowserProxy {
isMediaRouterEnabled(): boolean
getExtensionsManifestV2(): Promise
enableExtensionManifestV2(id: string, enabled: boolean): Promise
+ removeExtensionManifestV2(id: string): Promise
}
export class BraveDefaultExtensionsBrowserProxyImpl implements BraveDefaultExtensionsBrowserProxy {
@@ -59,7 +61,11 @@ export class BraveDefaultExtensionsBrowserProxyImpl implements BraveDefaultExten
}
enableExtensionManifestV2(id: string, enabled: boolean) {
- return sendWithPromise('enableExtensionManifestV2', id, enabled);
+ return sendWithPromise('enableExtensionManifestV2', id, enabled)
+ }
+
+ removeExtensionManifestV2(id:string) {
+ return sendWithPromise('removeExtensionManifestV2', id)
}
static getInstance(): BraveDefaultExtensionsBrowserProxy {
diff --git a/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.html b/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.html
index 91428a317ed7..e3d68de76b35 100644
--- a/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.html
+++ b/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.html
@@ -46,8 +46,13 @@
+ on-settings-boolean-control-change="onExtensionV2EnabledChange_" checked="[[item.enabled]]"
+ pref="[[itemPref_(item.enabled)]]" no-pref-set disabled="[[installInProgress_]]">
+
+
+ $i18n{extensionsV2RemoveButtonLabel}
+
+
diff --git a/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.ts b/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.ts
index a6d44d6bf15e..42b05e4fc05c 100644
--- a/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.ts
+++ b/browser/resources/settings/brave_default_extensions_page/brave_extensions_manifest_v2_subpage.ts
@@ -95,6 +95,15 @@ class BraveExtensionsV2Subpage extends BraveExtensionsV2SubpageBase {
})
}
+ removeExtension_(e: any) {
+ e.stopPropagation()
+ this.browserProxy_.removeExtensionManifestV2(e.target.id)
+ }
+
+ showRemoveButton_(ext: ExtensionV2): boolean {
+ return ext.installed && !ext.enabled
+ }
+
itemPref_(enabled: boolean) {
return {
key: '',
diff --git a/browser/ui/webui/settings/brave_extensions_manifest_v2_browsertest.cc b/browser/ui/webui/settings/brave_extensions_manifest_v2_browsertest.cc
index 8a1507f50a16..ca17f719079c 100644
--- a/browser/ui/webui/settings/brave_extensions_manifest_v2_browsertest.cc
+++ b/browser/ui/webui/settings/brave_extensions_manifest_v2_browsertest.cc
@@ -30,6 +30,14 @@ bool ClickExtensionToggle(content::WebContents* web_contents) {
.value.is_none();
}
+bool ClickExtensionRemove(content::WebContents* web_contents) {
+ return EvalJs(web_contents,
+ "window.testing.extensionsV2Subpage.getElementById('"
+ "doojmbjmlfjjnbmnoijecmcbfeoakpjm').querySelector('#"
+ "doojmbjmlfjjnbmnoijecmcbfeoakpjm').click()")
+ .value.is_none();
+}
+
bool IsExtensionToggled(content::WebContents* web_contents) {
return EvalJs(web_contents,
"window.testing.extensionsV2Subpage.getElementById('"
@@ -86,6 +94,12 @@ class BraveExtensionsManifestV2BrowserTest : public InProcessBrowserTest {
}
}
+ bool IsExtensionEnabled() {
+ return extensions::ExtensionRegistry::Get(browser()->profile())
+ ->enabled_extensions()
+ .Contains(kExtensionId);
+ }
+
bool IsExtensionInstalled() {
return extensions::ExtensionRegistry::Get(browser()->profile())
->GetInstalledExtension(kExtensionId);
@@ -147,9 +161,16 @@ IN_PROC_BROWSER_TEST_F(BraveExtensionsManifestV2BrowserTest,
ClickExtensionToggle(web_contents);
WaitExtensionToggled(true);
EXPECT_TRUE(IsExtensionInstalled());
+ EXPECT_TRUE(IsExtensionEnabled());
- // disabled from settings -> uninstalled.
+ // disabled from settings.
ClickExtensionToggle(web_contents);
WaitExtensionToggled(false);
+ EXPECT_TRUE(IsExtensionInstalled());
+ EXPECT_FALSE(IsExtensionEnabled());
+
+ // remove from settings.
+ ClickExtensionRemove(web_contents);
EXPECT_FALSE(IsExtensionInstalled());
+ EXPECT_FALSE(IsExtensionEnabled());
}
diff --git a/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.cc b/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.cc
index 30b3e09d7548..04753a51ffe1 100644
--- a/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.cc
+++ b/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.cc
@@ -63,6 +63,7 @@ struct ExtensionManifestV2 {
std::string id;
std::u16string name;
std::u16string description;
+ bool installed = false;
bool enabled = false;
base::Value ToValue() const {
@@ -70,6 +71,7 @@ struct ExtensionManifestV2 {
v.Set("id", id);
v.Set("name", name);
v.Set("description", description);
+ v.Set("installed", installed);
v.Set("enabled", enabled);
return base::Value(std::move(v));
}
@@ -123,6 +125,11 @@ void BraveExtensionsManifestV2Handler::RegisterMessages() {
base::BindRepeating(
&BraveExtensionsManifestV2Handler::EnableExtensionManifestV2,
base::Unretained(this)));
+ web_ui()->RegisterMessageCallback(
+ "removeExtensionManifestV2",
+ base::BindRepeating(
+ &BraveExtensionsManifestV2Handler::RemoveExtensionManifestV2,
+ base::Unretained(this)));
observation_.Observe(GetExtensionRegistry());
}
@@ -131,7 +138,7 @@ void BraveExtensionsManifestV2Handler::OnExtensionLoaded(
content::BrowserContext* browser_context,
const extensions::Extension* extension) {
DCHECK(extension);
- NotifyExtensionManifestV2Changed(browser_context, extension->id(), true);
+ NotifyExtensionManifestV2Changed(browser_context, extension->id());
}
void BraveExtensionsManifestV2Handler::OnExtensionUnloaded(
@@ -139,28 +146,28 @@ void BraveExtensionsManifestV2Handler::OnExtensionUnloaded(
const extensions::Extension* extension,
extensions::UnloadedExtensionReason reason) {
DCHECK(extension);
- NotifyExtensionManifestV2Changed(browser_context, extension->id(), false);
+ NotifyExtensionManifestV2Changed(browser_context, extension->id());
}
void BraveExtensionsManifestV2Handler::OnExtensionInstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
bool is_update) {
- OnExtensionLoaded(browser_context, extension);
+ DCHECK(extension);
+ NotifyExtensionManifestV2Changed(browser_context, extension->id());
}
void BraveExtensionsManifestV2Handler::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) {
- OnExtensionUnloaded(browser_context, extension,
- extensions::UnloadedExtensionReason::UNINSTALL);
+ DCHECK(extension);
+ NotifyExtensionManifestV2Changed(browser_context, extension->id());
}
void BraveExtensionsManifestV2Handler::NotifyExtensionManifestV2Changed(
content::BrowserContext* browser_context,
- const std::string& id,
- bool enabled) {
+ const std::string& id) {
if (!IsJavascriptAllowed() ||
browser_context != web_ui()->GetWebContents()->GetBrowserContext()) {
return;
@@ -169,7 +176,6 @@ void BraveExtensionsManifestV2Handler::NotifyExtensionManifestV2Changed(
if (fnd == extensions_.end()) {
return;
}
- fnd->enabled = enabled;
FireWebUIListener("brave-extension-manifest-v2-changed");
}
@@ -216,10 +222,33 @@ void BraveExtensionsManifestV2Handler::EnableExtensionManifestV2(
}
} else {
installer_.reset();
+ extension_service->DisableExtension(
+ id, extensions::disable_reason::DISABLE_USER_ACTION);
+ ResolveJavascriptCallback(args[0], base::Value(true));
+ }
+}
+
+void BraveExtensionsManifestV2Handler::RemoveExtensionManifestV2(
+ const base::Value::List& args) {
+ CHECK_EQ(args.size(), 2U);
+ const std::string id = args[1].GetString();
+
+ const bool installed =
+ GetExtensionRegistry()->GetInstalledExtension(id) != nullptr;
+
+ installer_.reset();
+
+ if (installed) {
+ auto* profile = Profile::FromBrowserContext(
+ web_ui()->GetWebContents()->GetBrowserContext());
+ auto* extension_service =
+ extensions::ExtensionSystem::Get(profile)->extension_service();
extension_service->UninstallExtension(
id, extensions::UNINSTALL_REASON_INTERNAL_MANAGEMENT, nullptr);
- ResolveJavascriptCallback(args[0], base::Value(true));
}
+
+ AllowJavascript();
+ ResolveJavascriptCallback(args[0], base::Value(true));
}
void BraveExtensionsManifestV2Handler::GetExtensionsManifestV2(
@@ -229,6 +258,8 @@ void BraveExtensionsManifestV2Handler::GetExtensionsManifestV2(
base::Value::List result;
for (auto& e : extensions_) {
+ e.installed =
+ GetExtensionRegistry()->GetInstalledExtension(e.id) != nullptr;
e.enabled = GetExtensionRegistry()->enabled_extensions().Contains(e.id);
result.Append(e.ToValue());
}
diff --git a/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.h b/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.h
index 70b26426100c..a5dd3bb1046a 100644
--- a/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.h
+++ b/browser/ui/webui/settings/brave_extensions_manifest_v2_handler.h
@@ -52,13 +52,13 @@ class BraveExtensionsManifestV2Handler
void NotifyExtensionManifestV2Changed(
content::BrowserContext* browser_context,
- const std::string& id,
- bool enabled);
+ const std::string& id);
extensions::ExtensionRegistry* GetExtensionRegistry();
void GetExtensionsManifestV2(const base::Value::List& args);
void EnableExtensionManifestV2(const base::Value::List& args);
+ void RemoveExtensionManifestV2(const base::Value::List& args);
void OnExtensionManifestV2Installed(
base::Value js_callback,
bool success,
diff --git a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
index e9befdfa8f94..10516d124932 100644
--- a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
+++ b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc
@@ -622,6 +622,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
IDS_SETTINGS_MANAGE_EXTENSIONS_V2_SUBLABEL},
{"extensionsV2ToastConfirmButtonLabel",
IDS_SETTINGS_MANAGE_EXTENSIONS_V2_TOAST_CONFIRM},
+ {"extensionsV2RemoveButtonLabel",
+ IDS_SETTINGS_MANAGE_EXTENSIONS_V2_REMOVE_BUTTON},
{"manageExtensionsLabel", IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL},
{"keyboardShortcuts", IDS_EXTENSIONS_SIDEBAR_KEYBOARD_SHORTCUTS},
{"getMoreExtensionsLabel", IDS_BRAVE_SETTINGS_GET_MORE_EXTENSIONS_LABEL},