Skip to content

Re-add support for Chromecast #2493

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

Merged
merged 1 commit into from
Jul 23, 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
9 changes: 9 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ By installing this extension, you are agreeing to the Google Widevine Terms of U
<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_MEDIA_ROUTER_ENABLED_DESC" desc="The description for Media Router switch in settings">
Uses Media Router component to enable Chromecast in the browser.
</message>
<message name="IDS_SETTINGS_RESTART_NOTICE" desc="Notifies the user that they need to relaunch Brave">
Your changes will take effect the next time you relaunch Brave.
</message>
<message name="IDS_SETTINGS_RELAUNCH_BUTTON_LABEL" desc="Notifies the user that they need to relaunch Brave">
Relaunch Now
</message>
<message name="IDS_SETTINGS_IPFS_COMPANION_ENABLED_DESC" desc="The description for IPFS companion switch in settings">
Uses IPFS companion extension to support IPFS in the browser.
</message>
Expand Down
8 changes: 7 additions & 1 deletion app/brave_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,14 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {
command_line.AppendSwitch(switches::kDisableDomainReliability);
command_line.AppendSwitch(switches::kDisableChromeGoogleURLTrackingClient);
command_line.AppendSwitch(switches::kNoPings);
command_line.AppendSwitchASCII(switches::kExtensionsInstallVerification,

// Setting these to default values in Chromium to maintain parity
// See: ChromeContentVerifierDelegate::GetDefaultMode for ContentVerification
// See: GetStatus in install_verifier.cc for InstallVerification
command_line.AppendSwitchASCII(switches::kExtensionContentVerification,
switches::kExtensionContentVerificationEnforceStrict);
command_line.AppendSwitchASCII(switches::kExtensionsInstallVerification,
"enforce");

// Enabled features.
const std::unordered_set<const char*> enabled_features = {
Expand Down
13 changes: 13 additions & 0 deletions browser/brave_profile_prefs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "components/signin/core/browser/signin_pref_names.h"
#include "components/spellcheck/browser/pref_names.h"
#include "components/sync/base/pref_names.h"
#include "extensions/buildflags/buildflags.h"
#include "extensions/common/feature_switch.h"
#include "third_party/widevine/cdm/buildflags.h"

#if BUILDFLAG(BUNDLE_WIDEVINE_CDM)
Expand All @@ -34,6 +36,8 @@
#include "brave/browser/tor/tor_profile_service.h"
#endif

using extensions::FeatureSwitch;

namespace brave {

void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
Expand Down Expand Up @@ -82,6 +86,15 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
// Media Router
registry->SetDefaultPrefValue(prefs::kEnableMediaRouter, base::Value(false));

// 1. We do not want to enable the MediaRouter pref directly, so
// using a proxy pref to handle Media Router setting
// 2. On upgrade users might have enabled Media Router and the pref should
// be set correctly, so we use feature switch to set the initial value
#if BUILDFLAG(ENABLE_EXTENSIONS)
registry->RegisterBooleanPref(kBraveEnabledMediaRouter,
FeatureSwitch::load_media_router_component_extension()->IsEnabled());
#endif

// No sign into Brave functionality
registry->SetDefaultPrefValue(prefs::kSigninAllowed, base::Value(false));

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 @@ -83,6 +83,9 @@ const PrefsUtil::TypedPrefMap& BravePrefsUtil::GetWhitelistedKeys() {
// IPFS Companion pref
(*s_brave_whitelist)[kIPFSCompanionEnabled] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
// Media Router Pref
(*s_brave_whitelist)[kBraveEnabledMediaRouter] =
settings_api::PrefType::PREF_TYPE_BOOLEAN;
return *s_brave_whitelist;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,33 @@ int OnBeforeURLRequest_CommonStaticRedirectWork(
const ResponseCallback& next_callback,
std::shared_ptr<BraveRequestInfo> ctx) {
GURL::Replacements replacements;
static URLPattern chromecast_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kChromeCastPrefix);
static URLPattern clients4_pattern(
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kClients4Prefix);

if (IsUpdaterURL(ctx->request_url)) {
replacements.SetQueryStr(ctx->request_url.query_piece());
ctx->new_url_spec = GURL(kBraveUpdatesExtensionsEndpoint)
.ReplaceComponents(replacements)
.spec();
return net::OK;
}

if (chromecast_pattern.MatchesURL(ctx->request_url)) {
replacements.SetSchemeStr("https");
replacements.SetHostStr(kBraveRedirectorProxy);
ctx->new_url_spec = ctx->request_url.ReplaceComponents(replacements).spec();
return net::OK;
}

if (clients4_pattern.MatchesHost(ctx->request_url)) {
replacements.SetSchemeStr("https");
replacements.SetHostStr(kBraveClients4Proxy);
ctx->new_url_spec = ctx->request_url.ReplaceComponents(replacements).spec();
return net::OK;
}

return net::OK;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,51 @@ TEST_F(BraveCommonStaticRedirectNetworkDelegateHelperTest,
EXPECT_EQ(ret, net::OK);
}

TEST_F(BraveCommonStaticRedirectNetworkDelegateHelperTest,
RedirectChromecastDownload) {
net::TestDelegate test_delegate;
GURL url(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we know this still works if the extension version changes?

Copy link
Contributor

@jumde jumde Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to random_hash and random_version, the pattern https://github.com/brave/brave-core/pull/2493/files#diff-6337bc2627a3b8782b369e66dc193cb9R47 should catch all changes to hash and version

"http://redirector.gvt1.com/edgedl/chromewebstore/"
"random_hash/random_version_pkedcjkdefgpdelpbcmbmeomcjbeemfm.crx");
std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
url, net::IDLE, &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS);

std::shared_ptr<brave::BraveRequestInfo> before_url_context(
new brave::BraveRequestInfo());
brave::BraveRequestInfo::FillCTXFromRequest(request.get(),
before_url_context);
brave::ResponseCallback callback;

int ret = OnBeforeURLRequest_CommonStaticRedirectWork(callback,
before_url_context);
GURL redirect = GURL(before_url_context->new_url_spec);
EXPECT_EQ(redirect.host(), kBraveRedirectorProxy);
EXPECT_TRUE(redirect.SchemeIs(url::kHttpsScheme));
EXPECT_EQ(redirect.path(), url.path());
EXPECT_EQ(ret, net::OK);
}

TEST_F(BraveCommonStaticRedirectNetworkDelegateHelperTest,
RedirectGoogleClients4) {
net::TestDelegate test_delegate;
GURL url(
"https://clients4.google.com/chrome-sync/dev");
std::unique_ptr<net::URLRequest> request = context()->CreateRequest(
url, net::IDLE, &test_delegate, TRAFFIC_ANNOTATION_FOR_TESTS);

std::shared_ptr<brave::BraveRequestInfo> before_url_context(
new brave::BraveRequestInfo());
brave::BraveRequestInfo::FillCTXFromRequest(request.get(),
before_url_context);
brave::ResponseCallback callback;

int ret = OnBeforeURLRequest_CommonStaticRedirectWork(callback,
before_url_context);
GURL redirect = GURL(before_url_context->new_url_spec);
EXPECT_EQ(redirect.host(), kBraveClients4Proxy);
EXPECT_TRUE(redirect.SchemeIs(url::kHttpsScheme));
EXPECT_EQ(redirect.path(), url.path());
EXPECT_EQ(ret, net::OK);
}

} // namespace
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ cr.define('settings', function() {
setWebTorrentEnabled(value) {}
setHangoutsEnabled(value) {}
setIPFSCompanionEnabled(value) {}
getRestartNeeded() {}
}

/**
Expand All @@ -27,6 +28,12 @@ cr.define('settings', function() {
setIPFSCompanionEnabled(value) {
chrome.send('setIPFSCompanionEnabled', [value]);
}
setMediaRouterEnabled(value) {
chrome.send('setMediaRouterEnabled', [value]);
}
getRestartNeeded() {
return cr.sendWithPromise('getRestartNeeded');
}
}

cr.addSingletonGetter(BraveDefaultExtensionsBrowserProxyImpl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

<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="brave_default_extensions_browser_proxy.html">
<link rel="import" href="../settings_page/settings_section.html">
<link rel="import" href="../settings_shared_css.html">
Expand All @@ -14,6 +15,53 @@
.settings-row:not(:first-child) {
border-top: var(--cr-separator-line);
}

#needsRestart {
background-color: #fff;
bottom: 0;
box-shadow: 0 -2px 2px 0 var(--shadow-color);
box-sizing: border-box;
left: 0;
opacity: 1;
padding: 16px;
position: fixed;
transform: translate(0);
transition: all 225ms var(--ease-in-out);
width: 100%;
z-index: 10;
}

:host-context([dark]) #needsRestart {
background-color: #161719;
}

#needsRestart .flex:last-child {
text-align: right; /* csschecker-disable-line left-right */
}

.flex {
align-self: center;
flex: 1 1 auto;
}

.flex-container {
display: flex;
padding: 8px 1em;
}

.restart-notice {
font-size: .9375rem;
line-height: 1.4;
}

button.primary {
background: var(--interactive-color);
border: 0;
border-radius: 3px;
color: white;
font-size: .875rem;
padding: 14px 38px;
}
</style>
<settings-toggle-button id="webTorrentEnabled"
class="first"
Expand All @@ -34,11 +82,30 @@
sub-label="$i18n{ipfsCompanionEnabledDesc}"
on-settings-boolean-control-change="onIPFSCompanionEnabledChange_">
</settings-toggle-button>
<settings-toggle-button id="mediaRouterEnabled"
pref="{{prefs.brave.enable_media_router}}"
label="Media Router"
sub-label="$i18n{mediaRouterEnabledDesc}"
on-settings-boolean-control-change="onMediaRouterEnabledChange_">
</settings-toggle-button>
<div class="settings-row" id="manageExtensionsRow">
<cr-link-row icon-class="icon-external"
label="$i18n{manageExtensionsLabel}" on-click="openExtensionsPage_">
</cr-link-row>
</div>
<template is="dom-if" if="{{ showRestartToast }}">
<div id="needsRestart">
<div class="flex-container">
<div class="flex restart-notice" jstcache="0">$i18n{restartNotice}</div>
<div class="flex">
<button id="restartButton" class="primary" tabindex="9" on-click="restartBrowser_">
$i18n{relaunchButtonLabel}
</button>
</div>
</div>
</div>
</div>
</template>
</template>
<script src="brave_default_extensions_page.js"></script>
</dom-module>
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,23 @@
Polymer({
is: 'settings-brave-default-extensions-page',

behaviors: [
WebUIListenerBehavior,
],

/** @private {?settings.BraveDefaultExtensionsBrowserProxy} */
browserProxy_: null,
showRestartToast: false,

/** @override */
created: function() {
this.browserProxy_ = settings.BraveDefaultExtensionsBrowserProxyImpl.getInstance();
this.browserProxy_.getRestartNeeded().then(show => {
this.showRestartToast = show;
});
this.addWebUIListener('brave-needs-restart-changed', (needsRestart) => {
this.showRestartToast = needsRestart
})
},

/** @override */
Expand All @@ -26,6 +37,7 @@ Polymer({
this.onHangoutsEnabledChange_ = this.onHangoutsEnabledChange_.bind(this)
this.onIPFSCompanionEnabledChange_ = this.onIPFSCompanionEnabledChange_.bind(this)
this.openExtensionsPage_ = this.openExtensionsPage_.bind(this)
this.restartBrowser_ = this.restartBrowser_.bind(this)
},

onWebTorrentEnabledChange_: function() {
Expand All @@ -40,6 +52,14 @@ Polymer({
this.browserProxy_.setIPFSCompanionEnabled(this.$.ipfsCompanionEnabled.checked);
},

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

onMediaRouterEnabledChange_: function() {
this.browserProxy_.setMediaRouterEnabled(this.$.mediaRouterEnabled.checked);
},

openExtensionsPage_: function() {
window.open("chrome://extensions", "_self");
},
Expand Down
Loading