Skip to content

Commit

Permalink
Merge pull request #5616 from brave/keep_extension
Browse files Browse the repository at this point in the history
Fix 3650: Enable google sign in for extensions
  • Loading branch information
jumde authored Aug 19, 2020
2 parents d4c9b43 + 4317137 commit 50b1ac4
Show file tree
Hide file tree
Showing 28 changed files with 338 additions and 43 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if (!is_ios) {
deps = [
"browser",
"chromium_src:browser",
"chromium_src/chrome/app",
"common",
"//components/omnibox/common",
"//services/device/public/cpp:device_features",
Expand Down
2 changes: 1 addition & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,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 for 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
5 changes: 5 additions & 0 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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/device/public/cpp/device_features.h"
#include "services/network/public/cpp/features.h"
#include "third_party/blink/public/common/features.h"
Expand Down Expand Up @@ -91,6 +92,8 @@ const char kBraveOriginTrialsPublicKey[] =
"bYUKPJoPnCxeNvu72j4EmPuK7tr1PAC7SHh8ld9Mw3E=,"
"fMS4mpO6buLQ/QMd+zJmxzty/VQ6B1EUZqoCU04zoRU=";

const char kDummyUrl[] = "https://no-thanks.invalid";

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

Expand Down Expand Up @@ -192,6 +195,8 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
command_line.AppendSwitchASCII(switches::kSyncServiceURL,
brave_sync_service_url.c_str());

command_line.AppendSwitchASCII(switches::kLsoUrl, kDummyUrl);

// 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 @@ -124,7 +124,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
1 change: 1 addition & 0 deletions browser/resources/settings/brave_overrides/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Steps to take:
- Create a JS module which calls any of the polymer_overriding exported functions, e.g. `RegisterStyleOverride`, depending on what you want to inject:
- Definition-time html polymer template changes? Use `RegisterPolymerTemplateModifications`.
- Runtime functionality hooks? Use `RegisterPolymerComponentBehaviors`.
- Runtime properties `RegisterPolymerComponentProperties`
- CSS style? Use `RegisterStyleOverride`.
- Import the module to the index.js inside this directory.
- Include the module in settings_resources.grd.
1 change: 1 addition & 0 deletions browser/resources/settings/brave_overrides/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ import './settings_menu.js'
import './settings_section.js'
import './settings_ui.js'
import './site_settings_page.js'
import './sync_account_control.js'
import './sync_controls.js'
32 changes: 32 additions & 0 deletions browser/resources/settings/brave_overrides/sync_account_control.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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/.

import {RegisterPolymerComponentProperties, RegisterPolymerTemplateModifications} from 'chrome://brave-resources/polymer_overriding.js'

RegisterPolymerTemplateModifications({
'settings-sync-account-control': (templateContent) => {
const banner = templateContent.querySelector('#banner')
const promo_header = templateContent.querySelector('#promo-header')
if (!banner) {
console.error('[Brave Settings Overrides] Could not find sync banner')
return
}
if (!promo_header) {
console.error('[Brave Settings Overrides] Could not find promo header')
return
}
banner.hidden = true
promo_header.hidden = true
}
})

RegisterPolymerComponentProperties({
'settings-sync-account-control': {
shouldShowAvatarRow_: {
type: Boolean,
value: false
}
}
})
1 change: 1 addition & 0 deletions browser/resources/settings/settings.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ settings_namespace_rewrites += [
"settings.BravePrivacyBrowserProxyImpl|BravePrivacyBrowserProxyImpl",
"settings.BraveSyncBrowserProxy|BraveSyncBrowserProxy",
"settings.DefaultBraveShieldsBrowserProxyImpl|DefaultBraveShieldsBrowserProxyImpl",
"settings.SocialBlockingPageProxyImpl|SocialBlockingPageProxyImpl",
"settings.Router|Router"
]

Expand Down
5 changes: 5 additions & 0 deletions browser/resources/settings/settings_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
compress="false"
preprocess="true"
type="BINDATA" />
<include name="IDR_SETTINGS_BRAVE_OVERRIDES_SYNC_ACCOUNT_CONTROL_JS"
file="brave_overrides/sync_account_control.js"
compress="false"
preprocess="true"
type="BINDATA" />
<include name="IDR_SETTINGS_BRAVE_OVERRIDES_SYNC_CONTROLS_JS"
file="brave_overrides/sync_controls.js"
compress="false"
Expand Down
6 changes: 6 additions & 0 deletions browser/resources/settings/settings_resources_generated.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
preprocess="true"
compress="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SOCIAL_BLOCKING_PAGE_PROXY_M_JS"
file="${root_gen_dir}/brave/browser/resources/settings/social_blocking_page/social_blocking_page_proxy.m.js"
use_base_dir="false"
preprocess="true"
compress="false"
type="BINDATA" />
<include name="IDR_SETTINGS_SOCIAL_BLOCKING_PAGE_M_JS"
file="${root_gen_dir}/brave/browser/resources/settings/social_blocking_page/social_blocking_page.m.js"
use_base_dir="false"
Expand Down
12 changes: 11 additions & 1 deletion browser/resources/settings/social_blocking_page/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ import("../settings.gni")
group("web_modules") {
public_deps = [
":social_blocking_page_module",
":modules",
]
}

polymer_modulizer("social_blocking_page") {
js_file = "social_blocking_page.js"
html_file = "social_blocking_page.html"
html_type = "dom-module"
auto_imports = settings_auto_imports
auto_imports = settings_auto_imports + [
"brave/browser/resources/settings/social_blocking_page/social_blocking_page_proxy.html|SocialBlockingPageProxy, SocialBlockingPageProxyImpl",
]
namespace_rewrites = settings_namespace_rewrites
}

js_modulizer("modules") {
input_files = [
"social_blocking_page_proxy.js",
]
namespace_rewrites = settings_namespace_rewrites
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/md_select_css.html">
<link rel="import" href="social_blocking_page_proxy.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">

Expand All @@ -12,7 +13,16 @@
<settings-toggle-button id="googleLoginControlType"
class="cr-row"
pref="{{prefs.brave.google_login_default}}"
label="$i18n{googleLoginControlLabel}">
label="$i18n{googleLoginControlLabel}"
learn-more-url="$i18n{googleLoginLearnMoreURL}"
on-settings-boolean-control-change="setSignInEnabledAtNextStartup_"
>
<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"
class="cr-row"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,34 @@
* social blocking options
*/
Polymer({
is: 'settings-social-blocking-page'
is: 'settings-social-blocking-page',

properties: {},

/** @private {?settings.SocialBlockingPageProxy} */
browserProxy_: null,

/** @override */
created: function() {
this.browserProxy_ = settings.SocialBlockingPageProxyImpl.getInstance();
},

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

shouldShowRestart_: function(value) {
return this.browserProxy_.wasSignInEnabledAtStartup() != value;
},

setSignInEnabledAtNextStartup_: function() {
this.browserProxy_.setSignInEnabledAtNextStartup(this.$.googleLoginControlType.checked);
},

restartBrowser_: function(e) {
e.stopPropagation();
window.open("chrome://restart", "_self");
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<link rel="href" src="chrome://resources/html/cr.html">
<script src="social_blocking_page_proxy.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* 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/. */

// clang-format off
// #import {addSingletonGetter, sendWithPromise} from 'chrome://resources/js/cr.m.js';
// clang-format on

cr.define('settings', function() {
/** @interface */
class SocialBlockingPageProxy {
/**
* @param {boolean} enabled (true/false).
*/
setSignInEnabledAtNextStartup(value) {}
/**
* @return {boolean}
*/
wasSignInEnabledAtStartup() {}
}

/**
* @implements {settings.SocialBlockingPageProxy}
*/
/* #export */ class SocialBlockingPageProxyImpl {
setSignInEnabledAtNextStartup(value) {
chrome.settingsPrivate.setPref('signin.allowed_on_next_startup', value);
}

wasSignInEnabledAtStartup() {
return loadTimeData.getBoolean('signInAllowedOnNextStartupInitialValue');
}
}

cr.addSingletonGetter(SocialBlockingPageProxyImpl);

// #cr_define_end
return {
SocialBlockingPageProxy: SocialBlockingPageProxy,
SocialBlockingPageProxyImpl: SocialBlockingPageProxyImpl,
};
});
4 changes: 4 additions & 0 deletions build/commands/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const Config = function () {
this.targetApkBase ='classic'
this.braveGoogleApiKey = getNPMConfig(['brave_google_api_key']) || 'AIzaSyAQfxPJiounkhOjODEO5ZieffeBv6yft2Q'
this.googleApiEndpoint = getNPMConfig(['brave_google_api_endpoint']) || 'https://www.googleapis.com/geolocation/v1/geolocate?key='
this.googleDefaultClientId = getNPMConfig(['google_default_client_id']) || ''
this.googleDefaultClientSecret = getNPMConfig(['google_default_client_secret']) || ''
this.braveServicesKey = getNPMConfig(['brave_services_key']) || ''
this.infuraProjectId = getNPMConfig(['brave_infura_project_id']) || ''
this.binanceClientId = getNPMConfig(['binance_client_id']) || ''
Expand Down Expand Up @@ -186,6 +188,8 @@ Config.prototype.buildArgs = function () {
brave_channel: this.channel,
brave_google_api_key: this.braveGoogleApiKey,
brave_google_api_endpoint: this.googleApiEndpoint,
google_default_client_id: this.googleDefaultClientId,
google_default_client_secret: this.googleDefaultClientSecret,
brave_infura_project_id: this.infuraProjectId,
binance_client_id: this.binanceClientId,
gemini_client_id: this.geminiClientId,
Expand Down
10 changes: 10 additions & 0 deletions chromium_src/chrome/app/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2019 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/.

group("app") {
deps = [
"//google_apis"
]
}
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 @@ -50,7 +50,7 @@ TEST(AccountConsistencyDisabledTest, NewProfile) {
}
std::unique_ptr<TestingProfile> profile = profile_builder.Build();
ASSERT_TRUE(profile->IsNewProfile());
EXPECT_FALSE(AccountConsistencyModeManager::IsDiceEnabledForProfile(
EXPECT_TRUE(AccountConsistencyModeManager::IsDiceEnabledForProfile(
profile.get()));
}

Expand All @@ -60,9 +60,9 @@ TEST(AccountConsistencyDisabledTest, DiceFixAuthErrorsForAllProfiles) {
{
// Regular profile.
TestingProfile profile;
EXPECT_FALSE(
EXPECT_TRUE(
AccountConsistencyModeManager::IsDiceEnabledForProfile(&profile));
EXPECT_EQ(signin::AccountConsistencyMethod::kDisabled,
EXPECT_EQ(signin::AccountConsistencyMethod::kDice,
AccountConsistencyModeManager::GetMethodForProfile(&profile));

// Incognito profile.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "brave/browser/ui/webui/settings/brave_privacy_handler.h"
#include "brave/browser/version_info.h"
#include "chrome/browser/ui/webui/webui_util.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"

namespace settings {
void BraveAddLocalizedStrings(content::WebUIDataSource*, Profile*);
Expand Down Expand Up @@ -42,6 +44,9 @@ const char kBraveBuildInstructionsUrl[] =
const char kBraveLicenseUrl[] = "https://mozilla.org/MPL/2.0/";
const char kBraveReleaseTagPrefix[] =
"https://github.com/brave/brave-browser/releases/tag/v";
const char kGoogleLoginLearnMoreURL[] =
"https://github.com/brave/brave-browser/wiki/"
"Social-Blocking:-Allow-Google-login";

void BraveAddCommonStrings(content::WebUIDataSource* html_source,
Profile* profile) {
Expand Down Expand Up @@ -298,6 +303,8 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
AddLocalizedStringsBulk(html_source, localized_strings);
html_source->AddString("webRTCLearnMoreURL",
base::ASCIIToUTF16(kWebRTCLearnMoreURL));
html_source->AddString("googleLoginLearnMoreURL",
base::ASCIIToUTF16(kGoogleLoginLearnMoreURL));
html_source->AddString(
"getMoreExtensionsUrl",
base::ASCIIToUTF16(
Expand All @@ -324,12 +331,19 @@ void BraveAddAboutStrings(content::WebUIDataSource* html_source,
html_source->AddString("aboutProductLicense", license);
}

void BraveAddSocialBlockingLoadTimeData(content::WebUIDataSource* html_source,
Profile* profile) {
html_source->AddBoolean("signInAllowedOnNextStartupInitialValue",
profile->GetPrefs()->GetBoolean(prefs::kSigninAllowedOnNextStartup));
}

void BraveAddLocalizedStrings(content::WebUIDataSource* html_source,
Profile* profile) {
BraveAddCommonStrings(html_source, profile);
BraveAddResources(html_source, profile);
BraveAddAboutStrings(html_source, profile);
BravePrivacyHandler::AddLoadTimeData(html_source, profile);
BraveAddSocialBlockingLoadTimeData(html_source, profile);
}

} // namespace settings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* 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/components/signin/internal/identity_manager/brave_mutable_profile_oauth2_token_service_delegate.cc" // NOLINT
#include "../../../../../../components/signin/internal/identity_manager/mutable_profile_oauth2_token_service_delegate.cc" // NOLINT
Loading

0 comments on commit 50b1ac4

Please sign in to comment.