Skip to content

Commit

Permalink
Match kExtensionContentVerification behavior on Chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
bsclifton committed Apr 6, 2021
1 parent 64211a6 commit b6080fc
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
7 changes: 0 additions & 7 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
command_line.AppendSwitch(switches::kDisableDomainReliability);
command_line.AppendSwitch(switches::kNoPings);

// Setting these to default values in Chromium to maintain parity
// See: ChromeContentVerifierDelegate::GetDefaultMode for ContentVerification
// See: GetStatus in install_verifier.cc for InstallVerification
command_line.AppendSwitchASCII(
switches::kExtensionContentVerification,
switches::kExtensionContentVerificationEnforceStrict);

if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
embedder_support::kOriginTrialPublicKey)) {
command_line.AppendSwitchASCII(embedder_support::kOriginTrialPublicKey,
Expand Down
26 changes: 26 additions & 0 deletions browser/extensions/chrome_content_verifier_delegate_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright (c) 2021 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 "chrome/browser/extensions/chrome_content_verifier_delegate.h"

#include "testing/gtest/include/gtest/gtest.h"

#if defined(OFFICIAL_BUILD)

TEST(ChromeContentVerifierDelegateUnitTest, TestShouldEnforce) {
EXPECT_EQ(
extensions::ChromeContentVerifierDelegate::GetDefaultMode(),
extensions::ChromeContentVerifierDelegate::VerifyInfo::Mode::ENFORCE_STRICT);
}

#else

TEST(ChromeContentVerifierDelegateUnitTest, TestShouldNotEnforce) {
EXPECT_EQ(
extensions::ChromeContentVerifierDelegate::GetDefaultMode(),
extensions::ChromeContentVerifierDelegate::VerifyInfo::Mode::NONE);
}

#endif // defined(OFFICIAL_BUILD)
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* Copyright (c) 2021 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 "chrome/browser/extensions/chrome_content_verifier_delegate.h"

#include <algorithm>
#include <memory>
#include <set>
#include <vector>

#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h"
#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/syslog_logging.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/version.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/extensions/policy_extension_reinstaller.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/extensions/extension_constants.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/management_policy.h"
#include "extensions/browser/pref_types.h"
#include "extensions/common/extension_urls.h"
#include "extensions/common/extensions_client.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_url_handlers.h"
#include "net/base/backoff_entry.h"
#include "net/base/escape.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/extensions/extension_assets_manager_chromeos.h"
#endif

// All above headers copied from original chrome_content_verifier_delegate.cc
// are included to prevent below GOOGLE_CHROME_BUILD affect them.

// `VerifyInfo::Mode::ENFORCE_STRICT` is only defaulted for google chrome.
#if defined(OFFICIAL_BUILD)
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
#define BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING() (1)
#endif
#include "../../../../../chrome/browser/extensions/chrome_content_verifier_delegate.cc"
#if defined(OFFICIAL_BUILD)
#undef BUILDFLAG_INTERNAL_GOOGLE_CHROME_BRANDING
#endif
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ test("brave_unit_tests") {
if (enable_extensions) {
sources += [
"//brave/browser/extensions/api/brave_extensions_api_client_unittest.cc",
"//brave/browser/extensions/chrome_content_verifier_delegate_unittest.cc",
"//brave/browser/extensions/install_verifier_unittest.cc",
"//brave/chromium_src/extensions/browser/sandboxed_unpacker_unittest.cc",
"//brave/common/importer/chrome_importer_utils_unittest.cc",
Expand Down

0 comments on commit b6080fc

Please sign in to comment.