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 May 22, 2020
1 parent 858cd58 commit 4a775b3
Show file tree
Hide file tree
Showing 13 changed files with 182 additions and 25 deletions.
6 changes: 6 additions & 0 deletions app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 @@ -61,6 +62,8 @@ base::LazyInstance<BraveContentBrowserClient>::DestructorAtExit
g_brave_content_browser_client = LAZY_INSTANCE_INITIALIZER;
#endif

const char kBraveGaiaProxy[] = "https://gaia.brave.com";

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

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

command_line.AppendSwitchASCII(switches::kGaiaUrl,
kBraveGaiaProxy);

// Enabled features.
std::unordered_set<const char*> enabled_features = {
// Upgrade all mixed content
Expand Down
3 changes: 2 additions & 1 deletion browser/brave_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "brave/common/pref_names.h"
#include "brave/components/brave_sync/features.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "components/sync/driver/sync_driver_switches.h"
#include "content/public/browser/render_frame_host.h"
Expand Down Expand Up @@ -114,8 +115,8 @@ void BraveBrowserMainParts::PostProfileInit() {

#if defined(OS_ANDROID)
if (profile()->GetPrefs()->GetBoolean(kBackgroundVideoPlaybackEnabled)) {
content::RenderFrameHost::AllowInjectingJavaScript();
auto* command_line = base::CommandLine::ForCurrentProcess();
content::RenderFrameHost::AllowInjectingJavaScript();
command_line->AppendSwitch(switches::kDisableMediaSuspend);
}
#endif
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
@@ -1,8 +1,12 @@
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/polymer.html">

<link rel="import" href="chrome://resources/cr_elements/cr_link_row/cr_link_row.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/html/web_ui_listener_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/md_select_css.html">
<link rel="import" href="social_blocking_browser_proxy.html">
<link rel="import" href="../settings_page/settings_section.html">
<link rel="import" href="../settings_shared_css.html">
<link rel="import" href="../settings_vars_css.html">

Expand All @@ -12,7 +16,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 @@ -12,6 +12,10 @@
Polymer({
is: 'settings-social-blocking-page',

behaviors: [
WebUIListenerBehavior,
],

properties: {},

/** @private {?settings.DefaultBraveShieldsBrowserProxy} */
Expand All @@ -23,6 +27,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
55 changes: 55 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,55 @@
/* 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/. */

#include "brave/browser/ui/webui/settings/brave_social_blocking_handler.h"

#include <string>

#include "base/bind.h"
#include "base/values.h"
#include "brave/browser/brave_browser_process_impl.h"
#include "brave/common/pref_names.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/common/chrome_switches.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));
}
43 changes: 43 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,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/. */

#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 "brave/browser/tor/buildflags.h"
#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "chrome/common/extensions/webstore_install_result.h"
#include "components/prefs/pref_change_registrar.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,7 @@ 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 All @@ -72,6 +66,14 @@ std::unique_ptr<sync_preferences::PrefServiceSyncable> CreatePrefService(
g_browser_process->profile_manager()->GetProfileByPath(original_path);
DCHECK(original_profile);
PrefStore* extension_pref_store = nullptr;

// Make sure sign into Brave is not enabled
// The older kSigninAllowed is deprecated and only in use in Android until
// C71.
// auto googleLogin = original_profile->GetPrefs()->GetBoolean(kGoogleLoginControlType);
//original_profile->GetPrefs()->SetBoolean(prefs::kSigninAllowedOnNextStartup,
// false);

#if BUILDFLAG(ENABLE_EXTENSIONS)
extension_pref_store = new ExtensionPrefStore(
ExtensionPrefValueMapFactory::GetForBrowserContext(original_profile),
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 @@ -220,6 +221,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

This file was deleted.

12 changes: 12 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,12 @@
diff --git a/chrome/browser/ui/startup/bad_flags_prompt.cc b/chrome/browser/ui/startup/bad_flags_prompt.cc
index 7803de645e87d0b3fd4c7d50f843f467269077f0..5d46c1756aae719f02acc688bed5d4ae26803afe 100644
--- a/chrome/browser/ui/startup/bad_flags_prompt.cc
+++ b/chrome/browser/ui/startup/bad_flags_prompt.cc
@@ -79,7 +79,6 @@ static const char* kBadFlags[] = {
switches::kIgnoreCertificateErrors,

// These flags change the URLs that handle PII.
- switches::kGaiaUrl,
translate::switches::kTranslateScriptURL,

#if BUILDFLAG(ENABLE_EXTENSIONS)

0 comments on commit 4a775b3

Please sign in to comment.