| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* Copyright (c) 2025 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/. */ | ||
|
|
||
| #include "content/browser/web_contents/web_contents_impl.h" | ||
|
|
||
| namespace content { | ||
|
|
||
| bool WebContentsImpl::ShouldDoLearning() { | ||
| if (!ShouldDoLearning_ChromiumImpl()) { | ||
| return false; | ||
| } | ||
| return !GetContentClient()->browser()->IsWindowsRecallDisabled(); | ||
| } | ||
|
|
||
| bool WebContentsImpl::GetShouldDoLearningForTesting() { | ||
| return ShouldDoLearning(); | ||
| } | ||
|
|
||
| } // namespace content | ||
|
|
||
| #define ShouldDoLearning(...) ShouldDoLearning_ChromiumImpl(__VA_ARGS__) | ||
|
|
||
| #include "src/content/browser/web_contents/web_contents_impl.cc" | ||
|
|
||
| #undef ShouldDoLearning |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /* Copyright (c) 2025 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/. */ | ||
|
|
||
| #ifndef BRAVE_CHROMIUM_SRC_CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ | ||
| #define BRAVE_CHROMIUM_SRC_CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ | ||
|
|
||
| #include "content/browser/renderer_host/render_widget_host_delegate.h" | ||
|
|
||
| #define ShouldDoLearning(...) \ | ||
| ShouldDoLearning_ChromiumImpl(__VA_ARGS__); \ | ||
| bool GetShouldDoLearningForTesting() override; \ | ||
| bool ShouldDoLearning(__VA_ARGS__) | ||
|
|
||
| #include "src/content/browser/web_contents/web_contents_impl.h" // IWYU pragma: export | ||
|
|
||
| #undef ShouldDoLearning | ||
|
|
||
| #endif // BRAVE_CHROMIUM_SRC_CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_IMPL_H_ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /* Copyright (c) 2024 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/. */ | ||
|
|
||
| #include "src/content/public/browser/web_contents.cc" | ||
|
|
||
| namespace content { | ||
|
|
||
| bool WebContents::GetShouldDoLearningForTesting() { | ||
| return true; | ||
| } | ||
|
|
||
| } // namespace content |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /* Copyright (c) 2024 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/. */ | ||
|
|
||
| #ifndef BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_ | ||
| #define BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_ | ||
|
|
||
| #define IsLoading(...) \ | ||
| GetShouldDoLearningForTesting(); \ | ||
| virtual bool IsLoading(__VA_ARGS__) | ||
|
|
||
| #include "src/content/public/browser/web_contents.h" // IWYU pragma: export | ||
|
|
||
| #undef IsLoading | ||
|
|
||
| #endif // BRAVE_CHROMIUM_SRC_CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_H_ |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Copyright (c) 2025 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("//brave/build/config.gni") | ||
|
|
||
| assert(is_win) | ||
|
|
||
| static_library("windows_recall") { | ||
| sources = [ | ||
| "windows_recall.cc", | ||
| "windows_recall.h", | ||
| ] | ||
|
|
||
| deps = [ | ||
| "//base", | ||
| "//components/prefs", | ||
| ] | ||
| } | ||
|
|
||
| source_set("unit_tests") { | ||
| testonly = true | ||
|
|
||
| sources = [ "windows_recall_unittest.cc" ] | ||
|
|
||
| deps = [ | ||
| ":windows_recall", | ||
| "//base", | ||
| "//base/test:test_support", | ||
| "//components/prefs:test_support", | ||
| "//testing/gtest", | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| include_rules = [ | ||
| "+components/prefs", | ||
| "+content/public/browser", | ||
| ] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| /* Copyright (c) 2025 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/. */ | ||
|
|
||
| #include "brave/components/windows_recall/windows_recall.h" | ||
|
|
||
| #include "base/check_is_test.h" | ||
| #include "base/win/windows_version.h" | ||
| #include "components/prefs/pref_registry_simple.h" | ||
| #include "components/prefs/pref_service.h" | ||
|
|
||
| namespace windows_recall { | ||
|
|
||
| namespace { | ||
| bool* g_windows_recall_disabled_override_for_testing = nullptr; | ||
| } | ||
|
|
||
| bool IsWindowsRecallAvailable() { | ||
| return base::win::GetVersion() >= base::win::Version::WIN11; | ||
bridiver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| void RegisterLocalStatePrefs(PrefRegistrySimple* registry) { | ||
| if (!IsWindowsRecallAvailable()) { | ||
| return; | ||
| } | ||
|
|
||
| registry->RegisterBooleanPref(prefs::kWindowsRecallDisabled, true); | ||
| } | ||
|
|
||
| bool IsWindowsRecallDisabled(PrefService* local_state) { | ||
| if (!IsWindowsRecallAvailable()) { | ||
| return false; | ||
| } | ||
|
|
||
| static bool disabled = local_state->GetBoolean(prefs::kWindowsRecallDisabled); | ||
|
|
||
| if (g_windows_recall_disabled_override_for_testing) { | ||
| CHECK_IS_TEST(); | ||
| return *g_windows_recall_disabled_override_for_testing; | ||
| } | ||
|
|
||
| return disabled; | ||
| } | ||
|
|
||
| namespace test { | ||
|
|
||
| // static | ||
| ScopedWindowsRecallDisabledOverride* | ||
| ScopedWindowsRecallDisabledOverride::instance_ = nullptr; | ||
|
|
||
| ScopedWindowsRecallDisabledOverride::ScopedWindowsRecallDisabledOverride( | ||
| bool disabled) | ||
| : disabled_(disabled), original_instance_(instance_) { | ||
| CHECK_IS_TEST(); | ||
| instance_ = this; | ||
| g_windows_recall_disabled_override_for_testing = &instance_->disabled_; | ||
| } | ||
|
|
||
| ScopedWindowsRecallDisabledOverride::~ScopedWindowsRecallDisabledOverride() { | ||
| instance_ = original_instance_; | ||
| g_windows_recall_disabled_override_for_testing = | ||
| instance_ ? &instance_->disabled_ : nullptr; | ||
| } | ||
|
|
||
| } // namespace test | ||
|
|
||
| } // namespace windows_recall | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* Copyright (c) 2025 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/. */ | ||
|
|
||
| #ifndef BRAVE_COMPONENTS_WINDOWS_RECALL_WINDOWS_RECALL_H_ | ||
| #define BRAVE_COMPONENTS_WINDOWS_RECALL_WINDOWS_RECALL_H_ | ||
|
|
||
| #include "base/memory/raw_ptr.h" | ||
|
|
||
| class PrefRegistrySimple; | ||
| class PrefService; | ||
|
|
||
| namespace windows_recall { | ||
|
|
||
| namespace prefs { | ||
| inline constexpr char kWindowsRecallDisabled[] = | ||
| "brave.windows_recall_disabled"; | ||
| } | ||
|
|
||
| void RegisterLocalStatePrefs(PrefRegistrySimple* registry); | ||
|
|
||
| // Checks whether the Window Recall service functionality is potentially | ||
| // available; currently, this verifies if the version is Windows 11 or newer. | ||
| bool IsWindowsRecallAvailable(); | ||
bridiver marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Gets the current state of the setting in the browser. | ||
| // NOTE: This is not related to system settings and does not check the status of | ||
| // the system service. | ||
| bool IsWindowsRecallDisabled(PrefService* local_state); | ||
|
|
||
| namespace test { | ||
|
|
||
| class ScopedWindowsRecallDisabledOverride { | ||
| public: | ||
| explicit ScopedWindowsRecallDisabledOverride(bool disabled); | ||
| ~ScopedWindowsRecallDisabledOverride(); | ||
|
|
||
| private: | ||
| bool disabled_ = false; | ||
| raw_ptr<ScopedWindowsRecallDisabledOverride> original_instance_ = nullptr; | ||
| static ScopedWindowsRecallDisabledOverride* instance_; | ||
| }; | ||
|
|
||
| } // namespace test | ||
|
|
||
| } // namespace windows_recall | ||
|
|
||
| #endif // BRAVE_COMPONENTS_WINDOWS_RECALL_WINDOWS_RECALL_H_ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| // Copyright (c) 2025 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/. | ||
|
|
||
| #include "brave/components/windows_recall/windows_recall.h" | ||
|
|
||
| #include "base/test/scoped_os_info_override_win.h" | ||
| #include "build/build_config.h" | ||
| #include "components/prefs/testing_pref_service.h" | ||
| #include "testing/gtest/include/gtest/gtest.h" | ||
|
|
||
| namespace window_recall { | ||
|
|
||
| TEST(WindowsRecallTest, IsWindowsRecallAvailable) { | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin10Home); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin10Pro); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin10Pro21H1); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWinServer2016); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWinServer2022); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin11HomeN); | ||
| EXPECT_TRUE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin11Home); | ||
| EXPECT_TRUE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin11Pro); | ||
| EXPECT_TRUE(windows_recall::IsWindowsRecallAvailable()); | ||
| } | ||
| } | ||
|
|
||
| TEST(WindowsRecallTest, IsWindowsRecallDisabled) { | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin10Home); | ||
| TestingPrefServiceSimple prefs; | ||
| windows_recall::RegisterLocalStatePrefs(prefs.registry()); | ||
| EXPECT_FALSE( | ||
| prefs.FindPreference(windows_recall::prefs::kWindowsRecallDisabled)); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallDisabled(&prefs)); | ||
| } | ||
| { | ||
| base::test::ScopedOSInfoOverride win_version( | ||
| base::test::ScopedOSInfoOverride::Type::kWin11Home); | ||
| TestingPrefServiceSimple prefs; | ||
| windows_recall::RegisterLocalStatePrefs(prefs.registry()); | ||
| ASSERT_TRUE( | ||
| prefs.GetBoolean(windows_recall::prefs::kWindowsRecallDisabled)); | ||
| EXPECT_TRUE(windows_recall::IsWindowsRecallDisabled(&prefs)); | ||
| prefs.SetBoolean(windows_recall::prefs::kWindowsRecallDisabled, false); | ||
| // value is cached | ||
| EXPECT_TRUE(windows_recall::IsWindowsRecallDisabled(&prefs)); | ||
|
|
||
| // reset the value to match the current pref | ||
| windows_recall::test::ScopedWindowsRecallDisabledOverride override( | ||
| prefs.GetBoolean(windows_recall::prefs::kWindowsRecallDisabled)); | ||
| EXPECT_FALSE(windows_recall::IsWindowsRecallDisabled(&prefs)); | ||
| } | ||
| } | ||
|
|
||
| } // namespace window_recall |
Uh oh!
There was an error while loading. Please reload this page.