Support whitelist for extensions

Fix https://github.com/brave/brave-browser/issues/196
This commit is contained in:
Brian R. Bondy
2018-05-17 00:49:06 -04:00
parent 88525afa69
commit 5eae9c748e
9 changed files with 251 additions and 1 deletions
+3 -1
View File
@@ -15,7 +15,9 @@ If you update this file, be sure also to update google_chrome_strings.grd. -->
<message name="IDS_SHOW_BRAVE_PAYMENTS" desc="The show brave payments menu in the app menu">
Brave Payments
</message>
<message name="IDS_EXTENSION_CANT_INSTALL_ON_BRAVE" desc="Error message when user tries to install an extension that is not allowed in Brave.">
<ph name="EXTENSION_NAME">$1</ph> (extension ID "<ph name="EXTENSION_ID">$2<ex>abacabadabacabaeabacabadabacabaf</ex></ph>") is not allowed in Brave. Please see about:extensions to install extensions.
</message>
<!-- Importer Lock Dialog -->
<message name="IDS_CHROME_IMPORTER_LOCK_TITLE" desc="Dialog title for Chrome importer lock dialog">
Close Chrome
+2
View File
@@ -10,6 +10,8 @@ source_set("extensions") {
"brave_component_extension_resource_manager.h",
"brave_component_loader.cc",
"brave_component_loader.h",
"brave_extension_management.cc",
"brave_extension_management.h",
]
deps = [
"//brave/browser/resources:brave_extension_grit",
@@ -0,0 +1,22 @@
/* 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/extensions/brave_extension_management.h"
#include "brave/extensions/browser/brave_extension_provider.h"
namespace extensions {
BraveExtensionManagement::BraveExtensionManagement(
PrefService* pref_service,
bool is_signin_profile)
: ExtensionManagement(pref_service, is_signin_profile) {
providers_.push_back(
std::make_unique<BraveExtensionProvider>());
}
BraveExtensionManagement::~BraveExtensionManagement() {
}
} // namespace extensions
@@ -0,0 +1,21 @@
/* 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_EXTENSIONS_EXTENSION_MANAGEMENT_H_
#define BRAVE_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
#include "chrome/browser/extensions/extension_management.h"
namespace extensions {
class BraveExtensionManagement : public ExtensionManagement {
public:
BraveExtensionManagement(PrefService* pref_service, bool is_signin_profile);
~BraveExtensionManagement() override;
DISALLOW_COPY_AND_ASSIGN(BraveExtensionManagement);
};
} // namespace extensions
#endif // BRAVE_BROWSER_EXTENSIONS_EXTENSION_MANAGEMENT_H_
+2
View File
@@ -3,6 +3,8 @@ source_set("extensions") {
sources = [
"browser/brave_extension_prefs.cc",
"browser/brave_extension_prefs.h",
"browser/brave_extension_provider.cc",
"browser/brave_extension_provider.h",
]
public_deps = [
@@ -0,0 +1,134 @@
/* 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/extensions/browser/brave_extension_provider.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "brave/grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
namespace {
const char* brave_extension_id = "mnojpmjdmbbfmejpflffifhffcmidifd";
bool IsWhitelisted(const std::string& id) {
static std::vector<std::string> whitelist({
// Brave
brave_extension_id,
// CryptoTokenExtension
"kmendfapggjehodndflmmgagdbamhnfd",
// Cloud Print
"mfehgcgbbipciphmccgaenjidiccnmng",
// Chromium PDF Viewer
"mhjfbmdgcfjbbpaeojofohoefgiehjai",
// Web Store
"ahfgeienlihckogmohjhadlkjgocpleb",
// Grammarly for Chrome
"kbfnbcaeplbcioakkpcpgfkobkghlhen",
// Brave Ad Block Updater
"cffkpbalmllkdoenhmdmpbkajipdjfam",
// Brave Tracking Protection Updater
"afalakplffnnnlkncjhbmahjfjhmlkal",
// Brave HTTPS Everywhere Updater
"oofiananboodjbbmdelgdommihjbkfag",
// Test ID: Brave Ad Block Updater
"naccapggpomhlhoifnlebfoocegenbol",
// Test ID: Brave Tracking Protection Updater
"eclbkhjphkhalklhipiicaldjbnhdfkc",
// Test ID: Brave HTTPS Everywhere Updater
"bhlmpjhncoojbkemjkeppfahkglffilp",
// 1Password
"aomjjhallfgjeglblehebfpbcfeobpgk",
// Dashlane
"fdjamakpfbbddfjaooikfcpapjohcfmg",
// LastPass
"hdokiejnpimakedhajhdlcegeplioahd",
// Pocket
"niloccemoadcdkdjlinkgdfekeahmflj",
// Enpass
"kmcfomidfpdkfieipokbalgegidffkal",
// Vimium
"dbepggeogbaibhgnhhndojpepiihcmeb",
// bitwarden
"nngceckbapebfimnlniiiahkandclblb",
// Honey
"bmnlcjabgnpnenekpadlanbbkooimhnj",
// Pinterest
"gpdjojdkbbmdfjfahjcgigfpmkopogic",
// MetaMask
"nkbihfbeogaeaoehlefnkodbefgpgknn",
// Reddit Enhancement Suite
"kbmfpngjjgdllneeigpgjifpgocmfgmb",
// BetterTTV
"ajopnjidmegmdimjlfnijceegpefgped",
});
return std::find(whitelist.begin(), whitelist.end(), id) != whitelist.end();
}
} // namespace
namespace extensions {
BraveExtensionProvider::BraveExtensionProvider() {
}
BraveExtensionProvider::~BraveExtensionProvider() {
}
std::string BraveExtensionProvider::GetDebugPolicyProviderName() const {
#if defined(NDEBUG)
NOTREACHED();
return std::string();
#else
return "Brave Extension Provider";
#endif
}
bool BraveExtensionProvider::UserMayLoad(const Extension* extension,
base::string16* error) const {
if (!IsWhitelisted(extension->id())) {
if (error) {
*error =
l10n_util::GetStringFUTF16(IDS_EXTENSION_CANT_INSTALL_ON_BRAVE,
base::UTF8ToUTF16(extension->name()),
base::UTF8ToUTF16(extension->id()));
}
#if defined(NDEBUG)
LOG(ERROR) << "Extension will not install "
<< " ID: " << base::UTF8ToUTF16(extension->id()) << ", "
<< " Name: " << base::UTF8ToUTF16(extension->name());
#endif
return false;
}
return true;
}
bool BraveExtensionProvider::UserMayModifySettings(
const Extension* extension,
base::string16* error) const {
return true;
}
bool BraveExtensionProvider::MustRemainEnabled(const Extension* extension,
base::string16* error) const {
return false;
}
bool BraveExtensionProvider::MustRemainDisabled(
const Extension* extension,
disable_reason::DisableReason* reason,
base::string16* error) const {
return extension->id() == brave_extension_id;
}
bool BraveExtensionProvider::MustRemainInstalled(const Extension* extension,
base::string16* error) const {
return extension->id() == brave_extension_id;
}
} // namespace extensions
@@ -0,0 +1,34 @@
/* 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_EXTENSIONS_BROWSER_MANAGEMENT_POLICY_H_
#define BRAVE_EXTENSIONS_BROWSER_MANAGEMENT_POLICY_H_
#include "extensions/browser/management_policy.h"
namespace extensions {
class BraveExtensionProvider : public ManagementPolicy::Provider {
public:
BraveExtensionProvider();
~BraveExtensionProvider() override;
std::string GetDebugPolicyProviderName() const override;
bool UserMayLoad(const Extension* extension,
base::string16* error) const override;
bool UserMayModifySettings(const Extension* extension,
base::string16* error) const override;
bool MustRemainEnabled(const Extension* extension,
base::string16* error) const override;
bool MustRemainDisabled(const Extension* extension,
disable_reason::DisableReason* reason,
base::string16* error) const override;
bool MustRemainInstalled(const Extension* extension,
base::string16* error) const override;
private:
DISALLOW_COPY_AND_ASSIGN(BraveExtensionProvider);
};
} // namespace extensions
#endif
@@ -0,0 +1,21 @@
diff --git a/chrome/browser/extensions/extension_management.cc b/chrome/browser/extensions/extension_management.cc
index bc6fe02652cd98591180d3e3e5d794941abfb615..c0e7448bff844680c093d455153872b2cc38e9d6 100644
--- a/chrome/browser/extensions/extension_management.cc
+++ b/chrome/browser/extensions/extension_management.cc
@@ -15,6 +15,7 @@
#include "base/strings/string_util.h"
#include "base/trace_event/trace_event.h"
#include "base/version.h"
+#include "brave/browser/extensions/brave_extension_management.h"
#include "chrome/browser/extensions/extension_management_constants.h"
#include "chrome/browser/extensions/extension_management_internal.h"
#include "chrome/browser/extensions/external_policy_loader.h"
@@ -551,7 +552,7 @@ KeyedService* ExtensionManagementFactory::BuildServiceInstanceFor(
#if defined(OS_CHROMEOS)
is_signin_profile = chromeos::ProfileHelper::IsSigninProfile(profile);
#endif
- return new ExtensionManagement(profile->GetPrefs(), is_signin_profile);
+ return new BraveExtensionManagement(profile->GetPrefs(), is_signin_profile);
}
content::BrowserContext* ExtensionManagementFactory::GetBrowserContextToUse(
@@ -0,0 +1,12 @@
diff --git a/chrome/browser/extensions/extension_management.h b/chrome/browser/extensions/extension_management.h
index d7ffea9a5b7592821ef626326fbb7161173ae517..a6ca3e41d7d68329e8900480cf20032111509c81 100644
--- a/chrome/browser/extensions/extension_management.h
+++ b/chrome/browser/extensions/extension_management.h
@@ -163,6 +163,7 @@ class ExtensionManagement : public KeyedService {
std::string* required_version) const;
private:
+ friend class BraveExtensionManagement;
using SettingsIdMap =
std::unordered_map<ExtensionId,
std::unique_ptr<internal::IndividualSettings>>;