diff --git a/browser/brave_browser_process_impl.cc b/browser/brave_browser_process_impl.cc index 780656e74f3..1af66e918fa 100644 --- a/browser/brave_browser_process_impl.cc +++ b/browser/brave_browser_process_impl.cc @@ -43,7 +43,6 @@ #include "chrome/common/chrome_paths.h" #include "components/component_updater/component_updater_service.h" #include "components/component_updater/timer_update_scheduler.h" -#include "components/prefs/pref_service.h" #include "content/public/browser/browser_thread.h" #include "services/network/public/cpp/resource_request.h" #include "services/network/public/cpp/shared_url_loader_factory.h" @@ -101,19 +100,6 @@ void InitSystemRequestHandlerCallback() { ->RegisterOnBeforeSystemRequestCallback(before_system_request_callback); } -PrefService* BraveGetPrefs() { - return ProfileManager::GetActiveUserProfile() - ->GetOriginalProfile() - ->GetPrefs(); -} - -void InitGetPrefsCallback() { - prefs::BravePrefService::GetPrefsCallback get_prefs_callback = - base::Bind(BraveGetPrefs); - prefs::BravePrefService::GetInstance()->RegisterGetPrefsCallback( - get_prefs_callback); -} - } // namespace BraveBrowserProcessImpl* g_brave_browser_process = nullptr; @@ -175,8 +161,6 @@ void BraveBrowserProcessImpl::Init() { #endif InitSystemRequestHandlerCallback(); - - InitGetPrefsCallback(); } brave_component_updater::BraveComponent::Delegate* diff --git a/chromium_src/components/external_intents/android/intercept_navigation_delegate_impl.cc b/chromium_src/components/external_intents/android/intercept_navigation_delegate_impl.cc index 12695f57854..ddf7cfca9aa 100644 --- a/chromium_src/components/external_intents/android/intercept_navigation_delegate_impl.cc +++ b/chromium_src/components/external_intents/android/intercept_navigation_delegate_impl.cc @@ -10,6 +10,8 @@ #include "components/navigation_interception/intercept_navigation_delegate.h" #include "components/navigation_interception/navigation_params.h" #include "components/prefs/pref_service.h" +#include "components/user_prefs/user_prefs.h" +#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/web_contents.h" #include "net/base/escape.h" @@ -21,30 +23,14 @@ namespace { using navigation_interception::InterceptNavigationDelegate; using navigation_interception::NavigationParams; -bool ShouldPlayVideoInBrowser(const GURL& url) { - PrefService* pref_service = - prefs::BravePrefService::GetInstance()->GetPrefs(); - if (!pref_service) { - NOTREACHED(); - return false; - } - - if (!pref_service->GetBoolean(kPlayYTVideoInBrowserEnabled)) { - return false; - } - - if (url.host().find("youtube.com") != std::string::npos || - url.host().find("youtu.be") != std::string::npos) { - return true; - } - - return false; -} - class BraveInterceptNavigationDelegate : public InterceptNavigationDelegate { public: - BraveInterceptNavigationDelegate(JNIEnv* env, jobject jdelegate) - : InterceptNavigationDelegate(env, jdelegate) {} + BraveInterceptNavigationDelegate(JNIEnv* env, + jobject jdelegate, + PrefService* pref_service) + : InterceptNavigationDelegate(env, jdelegate) { + pref_service_ = pref_service; + } bool ShouldIgnoreNavigation( const NavigationParams& navigation_params) override { @@ -58,6 +44,27 @@ class BraveInterceptNavigationDelegate : public InterceptNavigationDelegate { return InterceptNavigationDelegate::ShouldIgnoreNavigation( chrome_navigation_params); } + + private: + bool ShouldPlayVideoInBrowser(const GURL& url) { + if (!pref_service_) { + NOTREACHED(); + return false; + } + + if (!pref_service_->GetBoolean(kPlayYTVideoInBrowserEnabled)) { + return false; + } + + if (url.host().find("youtube.com") != std::string::npos || + url.host().find("youtu.be") != std::string::npos) { + return true; + } + + return false; + } + + PrefService* pref_service_; }; } // namespace @@ -71,7 +78,9 @@ static void JNI_InterceptNavigationDelegateImpl_AssociateWithWebContents( content::WebContents::FromJavaWebContents(jweb_contents); InterceptNavigationDelegate::Associate( web_contents, - std::make_unique(env, jdelegate)); + std::make_unique( + env, jdelegate, + user_prefs::UserPrefs::Get(web_contents->GetBrowserContext()))); } } // namespace external_intents diff --git a/chromium_src/components/prefs/pref_service.cc b/chromium_src/components/prefs/pref_service.cc deleted file mode 100644 index 467d4a8fccc..00000000000 --- a/chromium_src/components/prefs/pref_service.cc +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) 2020 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 "../../../../components/prefs/pref_service.cc" - -namespace prefs { - -BravePrefService* BravePrefService::GetInstance() { - return base::Singleton::get(); -} - -void BravePrefService::RegisterGetPrefsCallback(const GetPrefsCallback& cb) { - get_prefs_callback_ = cb; -} - -PrefService* BravePrefService::GetPrefs() { - if (!get_prefs_callback_) { - NOTREACHED(); - return nullptr; - } - return get_prefs_callback_.Run(); -} - -BravePrefService::BravePrefService() {} - -BravePrefService::~BravePrefService() {} - -} // namespace prefs diff --git a/chromium_src/components/prefs/pref_service.h b/chromium_src/components/prefs/pref_service.h deleted file mode 100644 index 0d908120814..00000000000 --- a/chromium_src/components/prefs/pref_service.h +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2020 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/. */ - -#ifndef BRAVE_CHROMIUM_SRC_COMPONENTS_PREFS_PREF_SERVICE_H_ -#define BRAVE_CHROMIUM_SRC_COMPONENTS_PREFS_PREF_SERVICE_H_ - -#include "../../../../components/prefs/pref_service.h" -#include "base/callback.h" -#include "base/memory/singleton.h" - -namespace prefs { - -// Allows access to active user's profile PrefService in components -class COMPONENTS_PREFS_EXPORT BravePrefService { - public: - typedef base::Callback GetPrefsCallback; - - static BravePrefService* GetInstance(); - - void RegisterGetPrefsCallback(const GetPrefsCallback& cb); - - PrefService* GetPrefs(); - - private: - friend struct base::DefaultSingletonTraits; - - BravePrefService(); - ~BravePrefService(); - - GetPrefsCallback get_prefs_callback_; - - DISALLOW_COPY_AND_ASSIGN(BravePrefService); -}; - -} // namespace prefs - -#endif // BRAVE_CHROMIUM_SRC_COMPONENTS_PREFS_PREF_SERVICE_H_ diff --git a/components/external_intents/android/BUILD.gn b/components/external_intents/android/BUILD.gn new file mode 100644 index 00000000000..5b85b45de72 --- /dev/null +++ b/components/external_intents/android/BUILD.gn @@ -0,0 +1,8 @@ +group("android") { + deps = [ + "//brave/common", + "//components/prefs", + "//components/user_prefs", + "//url", + ] +} diff --git a/patches/components-external_intents-android-BUILD.gn.patch b/patches/components-external_intents-android-BUILD.gn.patch new file mode 100644 index 00000000000..cc0ea4e0af8 --- /dev/null +++ b/patches/components-external_intents-android-BUILD.gn.patch @@ -0,0 +1,12 @@ +diff --git a/components/external_intents/android/BUILD.gn b/components/external_intents/android/BUILD.gn +index 530cfa2c449b94854ace00cc710818fb496d2a7e..4dab931ff4d955f8a04bfe7bdfce7cde9f37ebd8 100644 +--- a/components/external_intents/android/BUILD.gn ++++ b/components/external_intents/android/BUILD.gn +@@ -57,6 +57,7 @@ static_library("android") { + "//components/navigation_interception", + "//content/public/browser", + ] ++ deps += [ "//brave/components/external_intents/android" ] + } + + android_library("javatests") {