Skip to content

Commit

Permalink
Fix 3650: Enable google sign in for extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
jumde committed Jun 1, 2020
1 parent 4f1cd8b commit a5753f0
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 26 deletions.
2 changes: 1 addition & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
Show the number of blocked items on the Shields icon
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_GOOGLE_LOGIN_LABEL" desc="Label for a switch control which allows Google social buttons to be enabled/disabled">
Allow Google login buttons on third party sites
Allow Google login in extensions and third party sites
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_FACEBOOK_EMBEDDED_POSTS_LABEL" desc="Label for a switch control which allows Facebook embedded posts">
Allow Facebook logins and embedded posts
Expand Down
12 changes: 12 additions & 0 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "components/translate/core/browser/translate_prefs.h"
#include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h"
#include "google_apis/gaia/gaia_switches.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/widevine/cdm/buildflags.h"
Expand All @@ -60,6 +61,11 @@ base::LazyInstance<BraveContentBrowserClient>::DestructorAtExit
g_brave_content_browser_client = LAZY_INSTANCE_INITIALIZER;
#endif

// Setting the gaia host using the command line switch instead of
// updating the kDefaultGaiaURL in google_apis/gaia/gaia_urls.cc
// to avoid enabling google LSO
const char kGaiaHost[] = "https://accounts.google.com";

BraveMainDelegate::BraveMainDelegate()
: ChromeMainDelegate() {}

Expand Down Expand Up @@ -150,6 +156,12 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
command_line.AppendSwitchASCII(switches::kSyncServiceURL,
"https://no-thanks.invalid");

// GaiaURL is not gated behind the preference because
// GaiaURLs are initialized before profile init, this is okay
// because kSigninAllowedOnNextStartup will still be disabled
command_line.AppendSwitchASCII(switches::kGaiaUrl,
kGaiaHost);

// Enabled features.
std::unordered_set<const char*> enabled_features = {
// Upgrade all mixed content
Expand Down
2 changes: 1 addition & 1 deletion browser/brave_profile_prefs_browsertest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ IN_PROC_BROWSER_TEST_F(BraveProfilePrefsBrowserTest,
EXPECT_EQ(browser()->profile()->GetPrefs()->GetInteger(
prefs::kNetworkPredictionOptions),
chrome_browser_net::NETWORK_PREDICTION_NEVER);
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
prefs::kSigninAllowedOnNextStartup));
// Verify cloud print is disabled.
EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,27 @@
cr.define('settings', function() {
/** @interface */
class SocialBlockingBrowserProxy {
/**
* @param {boolean} enabled (true/false).
*/
setGoogleLoginEnabled(value) {}
/**
* @return {boolean}
*/
wasGoogleLoginEnabledAtStartup() {}
}

/**
* @implements {settings.SocialBlockingBrowserProxy}
*/
class SocialBlockingBrowserProxyImpl {
setGoogleLoginEnabled(value) {
chrome.send('setGoogleLoginEnabled', [value]);
}

wasGoogleLoginEnabledAtStartup() {
return loadTimeData.getBoolean('googleLoginEnabledAtStartup');
}
}

cr.addSingletonGetter(SocialBlockingBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
</style>
<settings-toggle-button id="googleLoginControlType"
pref="{{prefs.brave.google_login_default}}"
label="$i18n{googleLoginControlLabel}">
label="$i18n{googleLoginControlLabel}"
on-settings-boolean-control-change="setGoogleLoginEnabled_">
<template is="dom-if" if="[[shouldShowRestart_(
prefs.brave.google_login_default.value)]]">
<cr-button on-click="restartBrowser_" slot="more-actions">
$i18n{restart}
</cr-button>
</template>
</settings-toggle-button>
<settings-toggle-button id="fbEmbedControlType"
pref="{{prefs.brave.fb_embed_default}}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ Polymer({
},

/** @override */
ready: function() {},
ready: function() {
this.setGoogleLoginEnabled_ = this.setGoogleLoginEnabled_.bind(this)
this.restartBrowser_ = this.restartBrowser_.bind(this)
},

setGoogleLoginEnabled_: function() {
this.browserProxy_.setGoogleLoginEnabled(this.$.googleLoginControlType.checked)
},

shouldShowRestart_: function(enabled) {
return enabled != this.browserProxy_.wasGoogleLoginEnabledAtStartup();
},

restartBrowser_: function(e) {
e.stopPropagation();
window.open("chrome://restart", "_self");
},

});
})();
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ source_set("ui") {
"webui/settings/brave_import_data_handler.h",
"webui/settings/brave_privacy_handler.cc",
"webui/settings/brave_privacy_handler.h",
"webui/settings/brave_social_blocking_handler.cc",
"webui/settings/brave_social_blocking_handler.h",
"webui/settings/default_brave_shields_handler.cc",
"webui/settings/default_brave_shields_handler.h",
]
Expand Down
2 changes: 2 additions & 0 deletions browser/ui/webui/brave_settings_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "brave/browser/ui/webui/settings/brave_appearance_handler.h"
#include "brave/browser/ui/webui/settings/brave_default_extensions_handler.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/ui/webui/settings/brave_social_blocking_handler.h"
#include "brave/browser/ui/webui/settings/default_brave_shields_handler.h"
#include "brave/browser/version_info.h"
#include "brave/components/brave_sync/buildflags/buildflags.h"
Expand Down Expand Up @@ -44,6 +45,7 @@ BraveSettingsUI::BraveSettingsUI(content::WebUI* web_ui,
web_ui->AddMessageHandler(std::make_unique<DefaultBraveShieldsHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveDefaultExtensionsHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveAppearanceHandler>());
web_ui->AddMessageHandler(std::make_unique<BraveSocialBlockingHandler>());
#if BUILDFLAG(ENABLE_SPARKLE)
// Use sparkle's relaunch api for browser relaunch on update.
web_ui->AddMessageHandler(std::make_unique<BraveRelaunchHandler>());
Expand Down
50 changes: 50 additions & 0 deletions browser/ui/webui/settings/brave_social_blocking_handler.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* 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 "brave/browser/ui/webui/settings/brave_social_blocking_handler.h"

#include <string>

#include "base/bind.h"
#include "base/values.h"
#include "brave/common/pref_names.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_data_source.h"

BraveSocialBlockingHandler::BraveSocialBlockingHandler()
: weak_ptr_factory_(this) {}

BraveSocialBlockingHandler::~BraveSocialBlockingHandler() {}

void BraveSocialBlockingHandler::RegisterMessages() {
profile_ = Profile::FromWebUI(web_ui());
web_ui()->RegisterMessageCallback(
"setGoogleLoginEnabled",
base::BindRepeating(&BraveSocialBlockingHandler::SetGoogleLoginEnabled,
base::Unretained(this)));
}

void BraveSocialBlockingHandler::SetGoogleLoginEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);
CHECK(profile_);
bool enabled;
args->GetBoolean(0, &enabled);

profile_->GetPrefs()->SetBoolean(prefs::kSigninAllowedOnNextStartup, enabled);
}

// static
void BraveSocialBlockingHandler::AddLoadTimeData(
content::WebUIDataSource* data_source,
Profile* profile) {
data_source->AddBoolean(
"googleLoginEnabledAtStartup",
profile->GetPrefs()->GetBoolean(prefs::kSigninAllowedOnNextStartup));
}
40 changes: 40 additions & 0 deletions browser/ui/webui/settings/brave_social_blocking_handler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* 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_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SOCIAL_BLOCKING_HANDLER_H_
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SOCIAL_BLOCKING_HANDLER_H_

#include <string>

#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"

class Profile;

namespace content {
class WebUIDataSource;
}

class BraveSocialBlockingHandler : public settings::SettingsPageUIHandler {
public:
BraveSocialBlockingHandler();
~BraveSocialBlockingHandler() override;
static void AddLoadTimeData(content::WebUIDataSource* data_source,
Profile* profile);

private:
void RegisterMessages() override;
void OnJavascriptAllowed() override {}
void OnJavascriptDisallowed() override {}

void SetGoogleLoginEnabled(const base::ListValue* args);

Profile* profile_ = nullptr;
base::WeakPtrFactory<BraveSocialBlockingHandler> weak_ptr_factory_;

DISALLOW_COPY_AND_ASSIGN(BraveSocialBlockingHandler);
};

#endif // BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_SOCIAL_BLOCKING_HANDLER_H_
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ void RegisterProfilePrefs(bool is_signin_profile,
// Disable spell check service
registry->SetDefaultPrefValue(
spellcheck::prefs::kSpellCheckUseSpellingService, base::Value(false));

// Make sure sign into Brave is not enabled
// The older kSigninAllowed is deprecated and only in use in Android until
// C71.
registry->SetDefaultPrefValue(prefs::kSigninAllowedOnNextStartup,
base::Value(false));

#if defined(OS_LINUX)
// Use brave theme by default instead of gtk theme.
registry->SetDefaultPrefValue(prefs::kUsesSystemTheme, base::Value(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "chrome/browser/ui/webui/webui_util.h"
#include "base/stl_util.h"
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/ui/webui/settings/brave_social_blocking_handler.h"

namespace settings {
void BraveAddLocalizedStrings(content::WebUIDataSource*, Profile*);
Expand Down Expand Up @@ -227,6 +228,7 @@ void BraveAddLocalizedStrings(content::WebUIDataSource* html_source,
BraveAddCommonStrings(html_source, profile);
BraveAddResources(html_source, profile);
BravePrivacyHandler::AddLoadTimeData(html_source, profile);
BraveSocialBlockingHandler::AddLoadTimeData(html_source, profile);
}

} // namespace settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* 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/signin/internal/identity_manager/primary_account_manager.h"

#include "extensions/common/url_pattern.h"
#include "google_apis/gaia/gaia_urls.h"
#include "url/gurl.h"

// Ensures that requests to accounts.google.com is not initiated at startup if
// google login for extensions is enabled
#define BRAVE_NO_GAIA_REQUEST_ON_STARTUP \
if (account_tracker_service_->GetAccounts().empty()) { \
return; \
} \

#include "../../../../../../components/signin/internal/identity_manager/primary_account_manager.cc"
#undef BRAVE_NO_GAIA_REQUEST_ON_STARTUP
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* 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/sync/driver/sync_session_durations_metrics_recorder.h"

// Ensures that sync driver metrics are disabled if google login for extensions
// is enabled
#define BRAVE_NO_SYNC_METRICS return;

#include "../../../../../components/sync/driver/sync_session_durations_metrics_recorder.cc" // NOLINT
#undef BRAVE_NO_SYNC_METRICS

This file was deleted.

14 changes: 14 additions & 0 deletions patches/chrome-browser-ui-startup-bad_flags_prompt.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/chrome/browser/ui/startup/bad_flags_prompt.cc b/chrome/browser/ui/startup/bad_flags_prompt.cc
index c8522bc517cb1e7c0c588f786474676295ec1f18..e1f3437ac6205b14d68219cc823dd114127688b3 100644
--- a/chrome/browser/ui/startup/bad_flags_prompt.cc
+++ b/chrome/browser/ui/startup/bad_flags_prompt.cc
@@ -80,7 +80,9 @@ static const char* kBadFlags[] = {
switches::kIgnoreCertificateErrors,

// These flags change the URLs that handle PII.
+#if !defined(BRAVE_CHROMIUM_BUILD)
switches::kGaiaUrl,
+#endif
translate::switches::kTranslateScriptURL,

#if BUILDFLAG(ENABLE_EXTENSIONS)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/components/signin/internal/identity_manager/primary_account_manager.cc b/components/signin/internal/identity_manager/primary_account_manager.cc
index aebcdb1d75a1f1ae91a39fa5c8a1087df5e19111..e3c714c83feafc077f687553d7aff9ec54b6bbdc 100644
--- a/components/signin/internal/identity_manager/primary_account_manager.cc
+++ b/components/signin/internal/identity_manager/primary_account_manager.cc
@@ -126,6 +126,7 @@ void PrimaryAccountManager::Initialize(PrefService* local_state) {
// It is important to only load credentials after starting to observe the
// token service.
token_service_->AddObserver(this);
+ BRAVE_NO_GAIA_REQUEST_ON_STARTUP
token_service_->LoadCredentials(GetAuthenticatedAccountId());
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/components/sync/driver/sync_session_durations_metrics_recorder.cc b/components/sync/driver/sync_session_durations_metrics_recorder.cc
index e8ab17ed1cbaaf50017421d20b0d27eac8388f4f..4a6e81ad4a8662b45baf6d6a5894df0db0723830 100644
--- a/components/sync/driver/sync_session_durations_metrics_recorder.cc
+++ b/components/sync/driver/sync_session_durations_metrics_recorder.cc
@@ -28,6 +28,7 @@ SyncSessionDurationsMetricsRecorder::SyncSessionDurationsMetricsRecorder(
SyncService* sync_service,
signin::IdentityManager* identity_manager)
: sync_service_(sync_service), identity_manager_(identity_manager) {
+ BRAVE_NO_SYNC_METRICS
// |sync_service| can be null if sync is disabled by a command line flag.
if (sync_service_) {
sync_observer_.Add(sync_service_);

0 comments on commit a5753f0

Please sign in to comment.