Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Google Hangouts / Google Meet #1250

Merged
merged 1 commit into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_WEBTORRENT_ENABLED_DESC" desc="The description for WebTorrent switch in settings">
Uses WebTorrent to display torrents directly in the browser. Supports torrent files and magnet links.
</message>
<message name="IDS_SETTINGS_HANGOUTS_ENABLED_DESC" desc="The description for Hangouts switch in settings">
Uses Hangouts component to enable screen sharing and other features in the browser.
</message>
<message name="IDS_SETTINGS_MANAGE_EXTENSIONS_LABEL" desc="The label of manage extensions link in settings">
Manage Extensions
</message>
Expand Down
30 changes: 30 additions & 0 deletions browser/brave_content_browser_client_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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();

Expand Down Expand Up @@ -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));
}
3 changes: 3 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 2 additions & 0 deletions browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions browser/extensions/api/settings_private/brave_prefs_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions browser/extensions/brave_component_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions browser/extensions/brave_component_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cr.define('settings', function() {
* @param {boolean} value name.
*/
setWebTorrentEnabled(value) {}
setHangoutsEnabled(value) {}
}

/**
Expand All @@ -19,6 +20,9 @@ cr.define('settings', function() {
setWebTorrentEnabled(value) {
chrome.send('setWebTorrentEnabled', [value]);
}
setHangoutsEnabled(value) {
chrome.send('setHangoutsEnabled', [value]);
}
}

cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
sub-label="$i18n{webTorrentEnabledDesc}"
on-settings-boolean-control-change="onWebTorrentEnabledChange_">
</settings-toggle-button>
<settings-toggle-button id="hangoutsEnabled"
pref="{{prefs.brave.hangouts_enabled}}"
label="Hangouts"
sub-label="$i18n{hangoutsEnabledDesc}"
on-settings-boolean-control-change="onHangoutsEnabledChange_">
</settings-toggle-button>
<div class="settings-row continuation" id="manageExtensionsRow">
<cr-link-row class="first" icon-class="icon-external"
label="$i18n{manageExtensionsLabel}" on-click="openExtensionsPage_">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ Polymer({
/** @override */
ready: function() {
this.onWebTorrentEnabledChange_ = this.onWebTorrentEnabledChange_.bind(this)
this.onHangoutsEnabledChange_ = this.onHangoutsEnabledChange_.bind(this)
this.openExtensionsPage_ = this.openExtensionsPage_.bind(this)
},

onWebTorrentEnabledChange_: function() {
this.browserProxy_.setWebTorrentEnabled(this.$.webTorrentEnabled.checked);
},

onHangoutsEnabledChange_: function() {
this.browserProxy_.setHangoutsEnabled(this.$.hangoutsEnabled.checked);
},

openExtensionsPage_: function() {
window.open("chrome://extensions", "_self");
},
Expand Down
28 changes: 28 additions & 0 deletions browser/ui/webui/settings/brave_default_extensions_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand All @@ -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<extensions::BraveComponentLoader*>(loader)->
ForceAddHangoutServicesExtension();
}
service->EnableExtension(hangouts_extension_id);
} else {
service->DisableExtension(hangouts_extension_id,
extensions::disable_reason::DisableReason::DISABLE_BLOCKED_BY_POLICY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
};
Expand Down
1 change: 1 addition & 0 deletions common/extensions/extension_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
1 change: 1 addition & 0 deletions common/extensions/extension_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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[];

Expand Down
1 change: 1 addition & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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";
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
18 changes: 17 additions & 1 deletion patches/chrome-browser-extensions-component_loader.h.patch
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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();
2 changes: 2 additions & 0 deletions renderer/brave_content_settings_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down