These classes were hoisted and renamed. This has been replaced in Chromium as well. This is a mechanical change for Brave, done with the following script. ``` git grep -lw 'Value::List' | xargs sed -i 's/\bValue::List\b/ListValue/g' git grep -lw 'Value::Dict' | xargs sed -i 's/\bValue::Dict\b/DictValue/g' git cl format ``` Chromium changes: https://chromium.googlesource.com/chromium/src/+/6bc468d481835992696083e99e556516fb7f5f80 ``` commit 6bc468d481835992696083e99e556516fb7f5f80 Author: Avi Drissman <avi@chromium.org> Date: Thu Jan 29 22:14:50 2026 -0800 Remove aliases for base::DictValue and base::ListValue This removes a few last stragglers as well. Fixed: 478100525 Cq-Include-Trybots: luci.chromium.try:win-official,mac-official,linux-official,android-official,android-desktop-x64-official Change-Id: If92142b8ab0562a82c609b71c6b2a7665cea6ec6 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7513889 Auto-Submit: Avi Drissman <avi@chromium.org> Commit-Queue: Daniel Cheng <dcheng@chromium.org> Owners-Override: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Cr-Commit-Position: refs/heads/main@{#1577038} ``` Issue: https://github.com/brave/brave-browser/issues/52435
105 lines
3.8 KiB
C++
105 lines
3.8 KiB
C++
/* Copyright (c) 2019 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/extensions/brave_component_loader.h"
|
|
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
#include "base/check.h"
|
|
#include "base/check_op.h"
|
|
#include "base/command_line.h"
|
|
#include "base/feature_list.h"
|
|
#include "base/functional/bind.h"
|
|
#include "base/json/json_reader.h"
|
|
#include "brave/components/brave_extension/grit/brave_extension.h"
|
|
#include "brave/components/constants/brave_switches.h"
|
|
#include "brave/components/constants/pref_names.h"
|
|
#include "brave/components/web_discovery/buildflags/buildflags.h"
|
|
#include "chrome/browser/extensions/extension_service.h"
|
|
#include "chrome/browser/profiles/profile.h"
|
|
#include "components/prefs/pref_service.h"
|
|
#include "extensions/browser/extension_registry.h"
|
|
#include "extensions/browser/extension_system.h"
|
|
#include "extensions/common/constants.h"
|
|
#include "extensions/common/mojom/manifest.mojom.h"
|
|
#include "ui/base/resource/resource_bundle.h"
|
|
|
|
#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
|
|
#include "brave/components/web_discovery/common/features.h"
|
|
#endif
|
|
|
|
namespace extensions {
|
|
|
|
BraveComponentLoader::BraveComponentLoader(Profile* profile)
|
|
: ComponentLoader(profile),
|
|
profile_(profile),
|
|
profile_prefs_(profile->GetPrefs()) {
|
|
pref_change_registrar_.Init(profile_prefs_);
|
|
pref_change_registrar_.Add(
|
|
kWebDiscoveryEnabled,
|
|
base::BindRepeating(&BraveComponentLoader::UpdateBraveExtension,
|
|
base::Unretained(this)));
|
|
}
|
|
|
|
BraveComponentLoader::~BraveComponentLoader() = default;
|
|
|
|
void BraveComponentLoader::AddDefaultComponentExtensions(
|
|
bool skip_session_components) {
|
|
ComponentLoader::AddDefaultComponentExtensions(skip_session_components);
|
|
UpdateBraveExtension();
|
|
}
|
|
|
|
bool BraveComponentLoader::UseBraveExtensionBackgroundPage() {
|
|
bool native_enabled = false;
|
|
#if BUILDFLAG(ENABLE_WEB_DISCOVERY_NATIVE)
|
|
native_enabled = base::FeatureList::IsEnabled(
|
|
web_discovery::features::kBraveWebDiscoveryNative);
|
|
#endif
|
|
return !native_enabled && profile_prefs_->GetBoolean(kWebDiscoveryEnabled);
|
|
}
|
|
|
|
void BraveComponentLoader::UpdateBraveExtension() {
|
|
const base::CommandLine& command_line =
|
|
*base::CommandLine::ForCurrentProcess();
|
|
if (command_line.HasSwitch(switches::kDisableBraveExtension)) {
|
|
return;
|
|
}
|
|
|
|
base::FilePath brave_extension_path(FILE_PATH_LITERAL(""));
|
|
brave_extension_path =
|
|
brave_extension_path.Append(FILE_PATH_LITERAL("brave_extension"));
|
|
auto& resource_bundle = ui::ResourceBundle::GetSharedInstance();
|
|
std::optional<base::DictValue> manifest = base::JSONReader::ReadDict(
|
|
resource_bundle.LoadDataResourceString(IDR_BRAVE_EXTENSION),
|
|
base::JSON_PARSE_CHROMIUM_EXTENSIONS);
|
|
CHECK(manifest) << "invalid Brave Extension manifest";
|
|
|
|
// The background page is a conditional. Replace MAYBE_background in the
|
|
// manifest to "background" or remove it.
|
|
auto background_value = manifest->Extract("MAYBE_background");
|
|
if (UseBraveExtensionBackgroundPage() && background_value) {
|
|
manifest->Set("background", std::move(*background_value));
|
|
}
|
|
|
|
extensions::ExtensionRegistry* registry =
|
|
extensions::ExtensionRegistry::Get(profile_);
|
|
const Extension* current_extension =
|
|
registry->GetInstalledExtension(brave_extension_id);
|
|
|
|
if (current_extension) {
|
|
const auto* current_manifest = current_extension->manifest();
|
|
if (current_manifest && *current_manifest->value() == *manifest) {
|
|
return; // Skip reload, nothing is actually changed.
|
|
}
|
|
Remove(brave_extension_id);
|
|
}
|
|
|
|
const auto id = Add(std::move(*manifest), brave_extension_path);
|
|
CHECK_EQ(id, brave_extension_id);
|
|
}
|
|
|
|
} // namespace extensions
|