Skip to content

Commit

Permalink
Merge pull request #4228 from brave/bsc-remote-debugging-uplift
Browse files Browse the repository at this point in the history
Remote debugging can now be enabled via brave://settings/privacy (uplift to 1.2.x)
  • Loading branch information
kjozwiak authored Dec 17, 2019
2 parents d969be6 + 2f19ece commit e535669
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 11 deletions.
4 changes: 4 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<message name="IDS_SETTINGS_PUSH_MESSAGING" desc="Select value">
Use Google Services for Push Messaging
</message>
<!-- Remote Debugging -->
<message name="IDS_SETTINGS_REMOTE_DEBUGGING_TITLE" desc="Select value">
Remote debugging
</message>
<!-- Brave Sync Settings -->
<message name="IDS_SETTINGS_BRAVE_SYNC_TITLE" desc="The title for Brave Sync in settings">
Sync
Expand Down
6 changes: 4 additions & 2 deletions browser/brave_local_state_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include "brave/browser/brave_stats_updater.h"
#include "brave/browser/metrics/metrics_reporting_util.h"
#include "brave/browser/tor/buildflags.h"
#include "brave/common/pref_names.h"
#include "brave/components/brave_referrals/buildflags/buildflags.h"
#include "brave/components/brave_shields/browser/ad_block_service.h"
#include "brave/components/brave_shields/browser/brave_shields_p3a.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/brave_p3a_service.h"
#include "chrome/common/pref_names.h"
#include "brave/components/p3a/buildflags.h"
#include "chrome/browser/first_run/first_run.h"
#include "chrome/common/pref_names.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/prefs/pref_registry_simple.h"

Expand All @@ -36,6 +37,7 @@ namespace brave {
void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
brave_shields::RegisterPrefsForAdBlockService(registry);
RegisterPrefsForBraveStatsUpdater(registry);
registry->RegisterBooleanPref(kRemoteDebuggingEnabled, false);
#if BUILDFLAG(ENABLE_BRAVE_REFERRALS)
RegisterPrefsForBraveReferralsService(registry);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
</cr-button>
</template>
</settings-toggle-button>
<settings-toggle-button id="remoteDebuggingEnabled"
pref=""
checked="[[remoteDebuggingEnabled_]]"
label="$i18n{remoteDebuggingEnabledTitle}"
on-settings-boolean-control-change="onRemoteDebuggingEnabledChange_">
</settings-toggle-button>
</template>
<script src="brave_personalization_options.js"></script>
</dom-module>
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
Polymer({
is: 'settings-brave-personalization-options',

behaviors: [
WebUIListenerBehavior,
],

properties: {
webRTCPolicies_: {
readOnly: true,
Expand All @@ -23,7 +27,8 @@ Polymer({
},

webRTCPolicy_: String,
p3aEnabled_: Boolean
p3aEnabled_: Boolean,
remoteDebuggingEnabled_: Boolean
},

/** @private {?settings.BravePrivacyBrowserProxy} */
Expand All @@ -46,6 +51,12 @@ Polymer({
this.browserProxy_.getP3AEnabled().then(enabled => {
this.p3aEnabled_ = enabled;
});
this.browserProxy_.getRemoteDebuggingEnabled().then(enabled => {
this.remoteDebuggingEnabled_ = enabled;
});
this.addWebUIListener('remote-debugging-enabled-changed', (enabled) => {
this.remoteDebuggingEnabled_ = enabled
})
},

/**
Expand All @@ -65,7 +76,11 @@ Polymer({
onP3AEnabledChange_: function() {
this.browserProxy_.setP3AEnabled(this.$.p3aEnabled.checked);
},


onRemoteDebuggingEnabledChange_: function() {
this.browserProxy_.setRemoteDebuggingEnabled(this.$.remoteDebuggingEnabled.checked);
},

shouldShowRestart_: function(enabled) {
return enabled != this.browserProxy_.wasPushMessagingEnabledAtStartup();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ cr.define('settings', function() {
* @param {boolean} enabled (true/false).
*/
setP3AEnabled(value) {}
/**
* @return {!Promise<string>}
*/
getRemoteDebuggingEnabled() {}
/**
* @param {boolean} enabled (true/false).
*/
setRemoteDebuggingEnabled(value) {}
/**
* @return {boolean}
*/
Expand All @@ -31,26 +39,31 @@ cr.define('settings', function() {
* @implements {settings.BravePrivacyBrowserProxy}
*/
class BravePrivacyBrowserProxyImpl {
/** @override */
/** @overrides */
getWebRTCPolicy() {
return cr.sendWithPromise('getWebRTCPolicy');
}

/** @override */
setWebRTCPolicy(policy) {
chrome.send('setWebRTCPolicy', [policy]);
}

/** @override */
getP3AEnabled() {
return cr.sendWithPromise('getP3AEnabled');
}

/** @override */
setP3AEnabled(value) {
chrome.send('setP3AEnabled', [value])
}

getRemoteDebuggingEnabled() {
return cr.sendWithPromise('getRemoteDebuggingEnabled');
}

setRemoteDebuggingEnabled(value) {
chrome.send('setRemoteDebuggingEnabled', [value])
}

wasPushMessagingEnabledAtStartup() {
return loadTimeData.getBoolean('pushMessagingEnabledAtStartup');
}
Expand Down
52 changes: 52 additions & 0 deletions browser/ui/webui/settings/brave_privacy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "base/bind.h"
#include "base/values.h"
#include "brave/common/pref_names.h"
#include "brave/components/p3a/pref_names.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
Expand All @@ -23,6 +24,18 @@
#include "brave/browser/gcm_driver/brave_gcm_channel_status.h"
#endif

BravePrivacyHandler::BravePrivacyHandler() {
local_state_change_registrar_.Init(g_browser_process->local_state());
local_state_change_registrar_.Add(
kRemoteDebuggingEnabled,
base::Bind(&BravePrivacyHandler::OnRemoteDebuggingEnabledChanged,
base::Unretained(this)));
}

BravePrivacyHandler::~BravePrivacyHandler() {
local_state_change_registrar_.RemoveAll();
}

void BravePrivacyHandler::RegisterMessages() {
profile_ = Profile::FromWebUI(web_ui());

Expand All @@ -40,6 +53,14 @@ void BravePrivacyHandler::RegisterMessages() {
web_ui()->RegisterMessageCallback(
"getP3AEnabled", base::BindRepeating(&BravePrivacyHandler::GetP3AEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"setRemoteDebuggingEnabled",
base::BindRepeating(&BravePrivacyHandler::SetRemoteDebuggingEnabled,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"getRemoteDebuggingEnabled",
base::BindRepeating(&BravePrivacyHandler::GetRemoteDebuggingEnabled,
base::Unretained(this)));
}

// static
Expand Down Expand Up @@ -97,3 +118,34 @@ void BravePrivacyHandler::GetP3AEnabled(const base::ListValue* args) {
AllowJavascript();
ResolveJavascriptCallback(args->GetList()[0].Clone(), base::Value(enabled));
}

void BravePrivacyHandler::SetRemoteDebuggingEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);

bool enabled;
args->GetBoolean(0, &enabled);

PrefService* local_state = g_browser_process->local_state();
local_state->SetBoolean(kRemoteDebuggingEnabled, enabled);
}

void BravePrivacyHandler::GetRemoteDebuggingEnabled(
const base::ListValue* args) {
CHECK_EQ(args->GetSize(), 1U);

PrefService* local_state = g_browser_process->local_state();
bool enabled = local_state->GetBoolean(kRemoteDebuggingEnabled);

AllowJavascript();
ResolveJavascriptCallback(args->GetList()[0].Clone(), base::Value(enabled));
}

void BravePrivacyHandler::OnRemoteDebuggingEnabledChanged() {
if (IsJavascriptAllowed()) {
PrefService* local_state = g_browser_process->local_state();
bool enabled = local_state->GetBoolean(kRemoteDebuggingEnabled);

FireWebUIListener("remote-debugging-enabled-changed", base::Value(enabled));
}
}
10 changes: 8 additions & 2 deletions browser/ui/webui/settings/brave_privacy_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define BRAVE_BROWSER_UI_WEBUI_SETTINGS_BRAVE_PRIVACY_HANDLER_H_

#include "chrome/browser/ui/webui/settings/settings_page_ui_handler.h"
#include "components/prefs/pref_change_registrar.h"

namespace content {
class WebUIDataSource;
Expand All @@ -16,8 +17,8 @@ class Profile;

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

Expand All @@ -33,7 +34,12 @@ class BravePrivacyHandler : public settings::SettingsPageUIHandler {
void SetP3AEnabled(const base::ListValue* args);
void GetP3AEnabled(const base::ListValue* args);

void SetRemoteDebuggingEnabled(const base::ListValue* args);
void GetRemoteDebuggingEnabled(const base::ListValue* args);
void OnRemoteDebuggingEnabledChanged();

Profile* profile_ = nullptr;
PrefChangeRegistrar local_state_change_registrar_;

DISALLOW_COPY_AND_ASSIGN(BravePrivacyHandler);
};
Expand Down
26 changes: 26 additions & 0 deletions chromium_src/chrome/browser/devtools/devtools_ui_bindings.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* 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/common/pref_names.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_ui_bindings.h"

#define IsValidRemoteFrontendURL IsValidRemoteFrontendURL_ChromiumImpl
#include "../../../../../../chrome/browser/devtools/devtools_ui_bindings.cc"
#undef IsValidRemoteFrontendURL

bool DevToolsUIBindings::IsValidRemoteFrontendURL(const GURL& url) {
PrefService* local_state = g_browser_process->local_state();
if (local_state) {
if (!local_state->GetBoolean(kRemoteDebuggingEnabled)) {
LOG(ERROR)
<< "Remote debugging is DISABLED. If you want to use it, please "
"enable in brave://settings/privacy";
return false;
}
}

return IsValidRemoteFrontendURL_ChromiumImpl(url);
}
15 changes: 15 additions & 0 deletions chromium_src/chrome/browser/devtools/devtools_ui_bindings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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/.

#ifndef BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_
#define BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_

#define IsValidRemoteFrontendURL \
IsValidRemoteFrontendURL_ChromiumImpl(const GURL& url); \
static bool IsValidRemoteFrontendURL
#include "../../../../../chrome/browser/devtools/devtools_ui_bindings.h"
#undef IsValidRemoteFrontendURL

#endif // BRAVE_CHROMIUM_SRC_CHROME_BROWSER_DEVTOOLS_DEVTOOLS_UI_BINDINGS_H_
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source,
{"p3aEnableTitle",
IDS_BRAVE_P3A_ENABLE_SETTING},
{"p3aEnabledDesc",
IDS_BRAVE_P3A_ENABLE_SETTING_SUBITEM}
IDS_BRAVE_P3A_ENABLE_SETTING_SUBITEM},
{"remoteDebuggingEnabledTitle",
IDS_SETTINGS_REMOTE_DEBUGGING_TITLE}
};
AddLocalizedStringsBulk(html_source, localized_strings,
base::size(localized_strings));
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const char kBraveWalletEncryptedSeed[] = "brave.wallet.encrypted_seed";
const char kBraveWalletEnabled[] = "brave.wallet.enabled";
const char kAlwaysShowBookmarkBarOnNTP[] =
"brave.always_show_bookmark_bar_on_ntp";
const char kRemoteDebuggingEnabled[] = "brave.remote_debugging_enabled";

#if defined(OS_ANDROID)
const char kDesktopModeEnabled[] = "brave.desktop_mode_enabled";
Expand Down
1 change: 1 addition & 0 deletions common/pref_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ extern const char kBraveWalletAES256GCMSivNonce[];
extern const char kBraveWalletEncryptedSeed[];
extern const char kBraveWalletEnabled[];
extern const char kAlwaysShowBookmarkBarOnNTP[];
extern const char kRemoteDebuggingEnabled[];

#if defined(OS_ANDROID)
extern const char kDesktopModeEnabled[];
Expand Down

0 comments on commit e535669

Please sign in to comment.