From 94839c46a12c5e20cc3f16e864ac8ce5dfaa0622 Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Tue, 8 Jan 2019 11:00:17 -0500 Subject: [PATCH] Merge pull request #1227 from brave/hangouts Add support for Google Hangouts / Google Meet --- app/brave_generated_resources.grd | 3 ++ ...rave_content_browser_client_browsertest.cc | 30 +++++++++++++++++++ browser/brave_profile_prefs.cc | 3 ++ browser/brave_profile_prefs_browsertest.cc | 2 ++ .../api/settings_private/brave_prefs_util.cc | 3 ++ browser/extensions/brave_component_loader.cc | 11 +++++++ browser/extensions/brave_component_loader.h | 2 ++ .../brave_default_extensions_browser_proxy.js | 4 +++ .../brave_default_extensions_page.html | 6 ++++ .../brave_default_extensions_page.js | 5 ++++ .../brave_default_extensions_handler.cc | 28 +++++++++++++++++ .../brave_default_extensions_handler.h | 1 + .../md_settings_localized_strings_provider.cc | 2 ++ common/extensions/extension_constants.cc | 1 + common/extensions/extension_constants.h | 1 + common/pref_names.cc | 1 + common/pref_names.h | 1 + ...rowser-extensions-component_loader.h.patch | 18 ++++++++++- renderer/brave_content_settings_observer.cc | 2 ++ 19 files changed, 123 insertions(+), 1 deletion(-) diff --git a/app/brave_generated_resources.grd b/app/brave_generated_resources.grd index 32567c287902..1bffa574ee1e 100644 --- a/app/brave_generated_resources.grd +++ b/app/brave_generated_resources.grd @@ -337,6 +337,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U Uses WebTorrent to display torrents directly in the browser. Supports torrent files and magnet links. + + Uses Hangouts component to enable screen sharing and other features in the browser. + Manage Extensions diff --git a/browser/brave_content_browser_client_browsertest.cc b/browser/brave_content_browser_client_browsertest.cc index 6fee1350bfd7..3cf7f080499c 100644 --- a/browser/brave_content_browser_client_browsertest.cc +++ b/browser/brave_content_browser_client_browsertest.cc @@ -10,6 +10,7 @@ #include "brave/common/extensions/extension_constants.h" #include "brave/common/pref_names.h" #include "brave/components/brave_rewards/browser/buildflags/buildflags.h" +#include "chrome/browser/extensions/component_loader.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" @@ -27,6 +28,13 @@ class BraveContentBrowserClientTest : public InProcessBrowserTest { public: + void SetUp() override { + // This is needed because component extensions are not added by default + // without it. Theyu are found to interfere with tests otherwise. It's needed + // for loading the hangouts extension of which there are tests for below. + extensions::ComponentLoader::EnableBackgroundExtensionsForTesting(); + InProcessBrowserTest::SetUp(); + } void SetUpOnMainThread() override { InProcessBrowserTest::SetUpOnMainThread(); @@ -248,3 +256,25 @@ IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, EXPECT_STREQ(entry->GetURL().spec().c_str(), torrent_extension_url().spec().c_str()) << "No changes on the real URL"; } + +IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, + HangoutsEnabledByDefault) { + ASSERT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(kHangoutsEnabled)); + extensions::ExtensionRegistry* registry = + extensions::ExtensionRegistry::Get(browser()->profile()); + ASSERT_TRUE(registry->enabled_extensions().Contains(hangouts_extension_id)); +} + +IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, + PRE_HangoutsDisabledDoesNotLoadComponent) { + browser()->profile()->GetPrefs()->SetBoolean(kHangoutsEnabled, false); +} + +IN_PROC_BROWSER_TEST_F(BraveContentBrowserClientTest, + HangoutsDisabledDoesNotLoadComponent) { + ASSERT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(kHangoutsEnabled)); + extensions::ExtensionRegistry* registry = + extensions::ExtensionRegistry::Get(browser()->profile()); + ASSERT_FALSE(registry->enabled_extensions().Contains( + hangouts_extension_id)); +} diff --git a/browser/brave_profile_prefs.cc b/browser/brave_profile_prefs.cc index 7ce334fd1f60..9d0acc7993b3 100644 --- a/browser/brave_profile_prefs.cc +++ b/browser/brave_profile_prefs.cc @@ -40,6 +40,9 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { // WebTorrent registry->RegisterBooleanPref(kWebTorrentEnabled, true); + // Hangouts + registry->RegisterBooleanPref(kHangoutsEnabled, true); + // No sign into Brave functionality registry->SetDefaultPrefValue(prefs::kSigninAllowed, base::Value(false)); diff --git a/browser/brave_profile_prefs_browsertest.cc b/browser/brave_profile_prefs_browsertest.cc index 75876497f325..1e9ae2ea27a6 100644 --- a/browser/brave_profile_prefs_browsertest.cc +++ b/browser/brave_profile_prefs_browsertest.cc @@ -30,6 +30,8 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, MiscBravePrefs) { browser()->profile()->GetPrefs()->GetBoolean(kNoScriptControlType)); EXPECT_TRUE( browser()->profile()->GetPrefs()->GetBoolean(kWebTorrentEnabled)); + EXPECT_TRUE( + browser()->profile()->GetPrefs()->GetBoolean(kHangoutsEnabled)); } IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest, DisableGoogleServicesByDefault) { diff --git a/browser/extensions/api/settings_private/brave_prefs_util.cc b/browser/extensions/api/settings_private/brave_prefs_util.cc index 62bb001fa029..1e57756ae781 100644 --- a/browser/extensions/api/settings_private/brave_prefs_util.cc +++ b/browser/extensions/api/settings_private/brave_prefs_util.cc @@ -43,6 +43,9 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() { // WebTorrent pref (*s_brave_whitelist)[kWebTorrentEnabled] = settings_api::PrefType::PREF_TYPE_BOOLEAN; + // Hangouts pref + (*s_brave_whitelist)[kHangoutsEnabled] = + settings_api::PrefType::PREF_TYPE_BOOLEAN; return *s_brave_whitelist; } diff --git a/browser/extensions/brave_component_loader.cc b/browser/extensions/brave_component_loader.cc index 8165110c11bd..d2927217ec7d 100644 --- a/browser/extensions/brave_component_loader.cc +++ b/browser/extensions/brave_component_loader.cc @@ -73,6 +73,17 @@ void BraveComponentLoader::AddExtension(const std::string& extension_id, base::Unretained(this), extension_id, true)); } +void BraveComponentLoader::AddHangoutServicesExtension() { + if (!profile_prefs_->FindPreference(kHangoutsEnabled) || + profile_prefs_->GetBoolean(kHangoutsEnabled)) { + ForceAddHangoutServicesExtension(); + } +} + +void BraveComponentLoader::ForceAddHangoutServicesExtension() { + ComponentLoader::AddHangoutServicesExtension(); +} + void BraveComponentLoader::AddDefaultComponentExtensions( bool skip_session_components) { ComponentLoader::AddDefaultComponentExtensions(skip_session_components); diff --git a/browser/extensions/brave_component_loader.h b/browser/extensions/brave_component_loader.h index 6669bd49ef6f..e164ce3174ce 100644 --- a/browser/extensions/brave_component_loader.h +++ b/browser/extensions/brave_component_loader.h @@ -34,10 +34,12 @@ class BraveComponentLoader : public ComponentLoader { const std::string& manifest); void AddExtension(const std::string& id, const std::string& name, const std::string& public_key); + void ForceAddHangoutServicesExtension(); static bool IsPdfjsDisabled(); private: + void AddHangoutServicesExtension() override; friend class ::BravePDFExtensionTest; void ObserveOpenPdfExternallySetting(); // Callback for changes to the AlwaysOpenPdfExternally setting. diff --git a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.js b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.js index baa0cdfade17..24e1b0362e5e 100644 --- a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.js +++ b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_browser_proxy.js @@ -9,6 +9,7 @@ cr.define('settings', function() { * @param {boolean} value name. */ setWebTorrentEnabled(value) {} + setHangoutsEnabled(value) {} } /** @@ -19,6 +20,9 @@ cr.define('settings', function() { setWebTorrentEnabled(value) { chrome.send('setWebTorrentEnabled', [value]); } + setHangoutsEnabled(value) { + chrome.send('setHangoutsEnabled', [value]); + } } cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl); diff --git a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html index 39ee71e2fc8c..f97ddce54e62 100644 --- a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html +++ b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.html @@ -18,6 +18,12 @@ sub-label="$i18n{webTorrentEnabledDesc}" on-settings-boolean-control-change="onWebTorrentEnabledChange_"> + +
diff --git a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.js b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.js index 0227bdc02e03..439a32fa28b3 100644 --- a/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.js +++ b/browser/resources/settings/brave_default_extensions_page/brave_default_extensions_page.js @@ -23,6 +23,7 @@ Polymer({ /** @override */ ready: function() { this.onWebTorrentEnabledChange_ = this.onWebTorrentEnabledChange_.bind(this) + this.onHangoutsEnabledChange_ = this.onHangoutsEnabledChange_.bind(this) this.openExtensionsPage_ = this.openExtensionsPage_.bind(this) }, @@ -30,6 +31,10 @@ Polymer({ this.browserProxy_.setWebTorrentEnabled(this.$.webTorrentEnabled.checked); }, + onHangoutsEnabledChange_: function() { + this.browserProxy_.setHangoutsEnabled(this.$.hangoutsEnabled.checked); + }, + openExtensionsPage_: function() { window.open("chrome://extensions", "_self"); }, diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.cc b/browser/ui/webui/settings/brave_default_extensions_handler.cc index 5770a2187cc8..2a629c2b134e 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.cc +++ b/browser/ui/webui/settings/brave_default_extensions_handler.cc @@ -8,6 +8,7 @@ #include "base/bind.h" #include "base/values.h" +#include "brave/browser/extensions/brave_component_loader.h" #include "brave/common/extensions/extension_constants.h" #include "brave/components/brave_webtorrent/grit/brave_webtorrent_resources.h" #include "chrome/browser/extensions/component_loader.h" @@ -22,6 +23,10 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { "setWebTorrentEnabled", base::BindRepeating(&BraveDefaultExtensionsHandler::SetWebTorrentEnabled, base::Unretained(this))); + web_ui()->RegisterMessageCallback( + "setHangoutsEnabled", + base::BindRepeating(&BraveDefaultExtensionsHandler::SetHangoutsEnabled, + base::Unretained(this))); } void BraveDefaultExtensionsHandler::SetWebTorrentEnabled( @@ -48,3 +53,26 @@ void BraveDefaultExtensionsHandler::SetWebTorrentEnabled( extensions::disable_reason::DisableReason::DISABLE_BLOCKED_BY_POLICY); } } + +void BraveDefaultExtensionsHandler::SetHangoutsEnabled( + const base::ListValue* args) { + CHECK_EQ(args->GetSize(), 1U); + CHECK(profile_); + bool value; + args->GetBoolean(0, &value); + + extensions::ExtensionService* service = + extensions::ExtensionSystem::Get(profile_)->extension_service(); + + if (value) { + extensions::ComponentLoader* loader = service->component_loader(); + if (!loader->Exists(hangouts_extension_id)) { + static_cast(loader)-> + ForceAddHangoutServicesExtension(); + } + service->EnableExtension(hangouts_extension_id); + } else { + service->DisableExtension(hangouts_extension_id, + extensions::disable_reason::DisableReason::DISABLE_BLOCKED_BY_POLICY); + } +} diff --git a/browser/ui/webui/settings/brave_default_extensions_handler.h b/browser/ui/webui/settings/brave_default_extensions_handler.h index c394c8fd4eca..44d7393d4121 100644 --- a/browser/ui/webui/settings/brave_default_extensions_handler.h +++ b/browser/ui/webui/settings/brave_default_extensions_handler.h @@ -21,6 +21,7 @@ class BraveDefaultExtensionsHandler : public settings::SettingsPageUIHandler { void OnJavascriptDisallowed() override {} void SetWebTorrentEnabled(const base::ListValue* args); + void SetHangoutsEnabled(const base::ListValue* args); Profile* profile_ = nullptr; diff --git a/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc index 16316a9af229..f8d7827373f6 100644 --- a/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc +++ b/chromium_src/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc @@ -85,6 +85,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source, IDS_SETTINGS_BRAVE_DEFAULT_EXTENSIONS_TITLE}, {"webTorrentEnabledDesc", IDS_SETTINGS_WEBTORRENT_ENABLED_DESC}, + {"hangoutsEnabledDesc", + IDS_SETTINGS_HANGOUTS_ENABLED_DESC}, {"manageExtensionsLabel", IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL} }; diff --git a/common/extensions/extension_constants.cc b/common/extensions/extension_constants.cc index f07427d40054..39a478f1dec1 100644 --- a/common/extensions/extension_constants.cc +++ b/common/extensions/extension_constants.cc @@ -7,6 +7,7 @@ const char brave_extension_id[] = "mnojpmjdmbbfmejpflffifhffcmidifd"; const char brave_rewards_extension_id[] = "jidkidbbcafjabdphckchenhfomhnfma"; const char brave_webtorrent_extension_id[] = "lgjmpdmojkpocjcopdikifhejkkjglho"; +const char hangouts_extension_id[] = "nkeimhogjdpnpccoofpliimaahmaaome"; const char widevine_extension_id[] = "oimompecagnajdejgnnjijobebaeigek"; const char brave_sync_extension_id[] = "nomlkjnggnifocmealianaaiobmebgil"; diff --git a/common/extensions/extension_constants.h b/common/extensions/extension_constants.h index fb50d426827d..84516439f44a 100644 --- a/common/extensions/extension_constants.h +++ b/common/extensions/extension_constants.h @@ -5,6 +5,7 @@ extern const char brave_extension_id[]; extern const char brave_rewards_extension_id[]; extern const char brave_webtorrent_extension_id[]; +extern const char hangouts_extension_id[]; extern const char widevine_extension_id[]; extern const char brave_sync_extension_id[]; diff --git a/common/pref_names.cc b/common/pref_names.cc index ff65c8a08164..24882749b209 100644 --- a/common/pref_names.cc +++ b/common/pref_names.cc @@ -43,3 +43,4 @@ const char kRewardsAddFundsNotification[] = "brave.rewards.add_funds_notificatio const char kMigratedMuonProfile[] = "brave.muon.migrated_profile"; const char kBravePaymentsPinnedItemCount[] = "brave.muon.import_pinned_item_count"; const char kWebTorrentEnabled[] = "brave.webtorrent_enabled"; +const char kHangoutsEnabled[] = "brave.hangouts_enabled"; diff --git a/common/pref_names.h b/common/pref_names.h index 523073b459bf..5bb7c56f0b00 100644 --- a/common/pref_names.h +++ b/common/pref_names.h @@ -40,5 +40,6 @@ extern const char kRewardsAddFundsNotification[]; extern const char kMigratedMuonProfile[]; extern const char kBravePaymentsPinnedItemCount[]; extern const char kWebTorrentEnabled[]; +extern const char kHangoutsEnabled[]; #endif // BRAVE_COMMON_PREF_NAMES_H_ diff --git a/patches/chrome-browser-extensions-component_loader.h.patch b/patches/chrome-browser-extensions-component_loader.h.patch index fe78db7885fe..fcc96834a85f 100644 --- a/patches/chrome-browser-extensions-component_loader.h.patch +++ b/patches/chrome-browser-extensions-component_loader.h.patch @@ -1,5 +1,5 @@ diff --git a/chrome/browser/extensions/component_loader.h b/chrome/browser/extensions/component_loader.h -index 8a78a56e2425adf937754bd0b202549744597bd0..54badd2618b872ecdafff1457e0e955fdc057729 100644 +index 8a78a56e2425adf937754bd0b202549744597bd0..52a2735a5bf944e8f39e61ba8294d70ee3034a7f 100644 --- a/chrome/browser/extensions/component_loader.h +++ b/chrome/browser/extensions/component_loader.h @@ -83,7 +83,7 @@ class ComponentLoader { @@ -11,3 +11,19 @@ index 8a78a56e2425adf937754bd0b202549744597bd0..54badd2618b872ecdafff1457e0e955f // Similar to above but adds the default component extensions for kiosk mode. void AddDefaultComponentExtensionsForKioskMode(bool skip_session_components); +@@ -118,6 +118,7 @@ class ComponentLoader { + } + + private: ++ friend class BraveComponentLoader; + FRIEND_TEST_ALL_PREFIXES(ComponentLoaderTest, ParseManifest); + + // Information about a registered component extension. +@@ -166,6 +167,7 @@ class ComponentLoader { + void AddAudioPlayerExtension(); + void AddGalleryExtension(); + void AddZipArchiverExtension(); ++ virtual + void AddHangoutServicesExtension(); + void AddImageLoaderExtension(); + void AddNetworkSpeechSynthesisExtension(); diff --git a/renderer/brave_content_settings_observer.cc b/renderer/brave_content_settings_observer.cc index f3a23e45a714..152972c53061 100644 --- a/renderer/brave_content_settings_observer.cc +++ b/renderer/brave_content_settings_observer.cc @@ -268,6 +268,8 @@ bool BraveContentSettingsObserver::AllowAutoplay(bool default_value) { "[*.]pandora.com", "[*.]periscope.tv", "[*.]pscp.tv", + "[*.]hangouts.google.com", + "[*.]meet.google.com", }; for (const auto& pattern : kWhitelistPatterns) { if (ContentSettingsPattern::FromString(pattern).Matches(primary_url))