-
Notifications
You must be signed in to change notification settings - Fork 965
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
Conversation
Errors from prior merge attempt:
|
2d7b50e
to
889b4bf
Compare
24f1944
to
63cea2e
Compare
As @jumde mentioned, case is still not working due to and @jumde tested it is enabled with below patch.
|
@simonhong - With this patch I checked that the signature check fails in |
@jumde I edited right before your last comment :) |
c292858
to
3d390cd
Compare
common/network_constants.cc
Outdated
@@ -38,6 +42,9 @@ const char kCRLSetPrefix3[] = | |||
const char kCRLSetPrefix4[] = | |||
"*://storage.googleapis.com/update-delta/hfnkpimlhhgieaddgfemjhofmfblmnib" | |||
"/*crxd"; | |||
const char kGoogleAPIPrefix[] = "https://www.googleapis.com/"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why https
instead of *
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was not connecting over http
but I agree, using * would help if the code fallsback to the non-secure url
9ec2881
to
1b13d24
Compare
@bridiver added cause this PR adds new patch file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for making the restart notification persistent. Minor changes requested to the JS api
@@ -63,10 +64,29 @@ void BraveDefaultExtensionsHandler::RegisterMessages() { | |||
flags_ui::kRestartBrowser, | |||
base::BindRepeating(&BraveDefaultExtensionsHandler::HandleRestartBrowser, | |||
base::Unretained(this))); | |||
web_ui()->RegisterMessageCallback( | |||
"showRelaunchToast", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 on the pattern but please can we call the command getRestartNeeded
so that:
- it's about the data, not the UI implementation (toast)
- it's specific about getting data, and not performing an action
|
||
/** @override */ | ||
created: function() { | ||
this.browserProxy_ = settings.BraveDefaultExtensionsBrowserProxyImpl.getInstance(); | ||
this.browserProxy_.showRelaunchToast().then(show => { | ||
this.hideRestartToast = !show; | ||
this.$.needsRestart.hidden = this.hideRestartToast; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a micro-optimization, so consider it a nit: I'd feel more comfortable if this didn't require a DOM change on 99.9% of all Settings page loads (i.e. page loads which don't have the toast showing).
This can be achieved by either:
- Preferred: Wrap the element in an
<if
which testshideRestartToast
(though positive variable name is better, e.g.showRestartToast
- Similar pattern to what you have: Create a css class called something like
pageNeedsRestart
, and only add this class if the variable comes back true.
|
||
bool IsExtensionInstalled(const std::string& extension_id) const; | ||
void OnInstallResult(const std::string& pref_name, | ||
bool success, const std::string& error, | ||
extensions::webstore_install::Result result); | ||
|
||
Profile* profile_ = nullptr; | ||
bool restartNeeded = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: restart_needed_
is the chromium style.
args->GetBoolean(0, &enabled); | ||
|
||
restartNeeded = !restartNeeded; | ||
if (enabled) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to add some comments why this is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
c6c6a27
to
10047e1
Compare
disable_reason::DisableReason* reason, | ||
base::string16* error) const { | ||
CHECK(extension); | ||
+ ReturnFalseIfExtensionShouldSkipSignatureChecking(extension->id()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This happens because for Media Router
the signature fetch and check happens out of order. This is likely a chromium bug, but not seen because chromium uses ENFORCE instead of ENFORCE_STRICT by default.(https://cs.chromium.org/chromium/src/chrome/browser/extensions/chrome_content_verifier_delegate.cc?l=110)
But, ENFORCE_STRICT
(https://cs.chromium.org/chromium/src/extensions/browser/content_verifier_delegate.h?g=0&l=42) is better for security.
We have multiple options here:
- Use
ENFORCE
overENFORCE_STRICT
similar to chromium. - SkipSignatureVerification for MediaRouter as seen in this PR.
- RedoSignature check after the fetch is complete.
Thoughts? @bridiver @diracdeltas @tomlowenthal
cc: @bsclifton @simonhong
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 2 or 3 sound great to me- I'd vote for option 2 as my choice 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i prefer 3 since Google Chrome uses ENFORCE_STRICT (https://cs.chromium.org/chromium/src/chrome/browser/extensions/chrome_content_verifier_delegate.cc?l=68); so IIUC, 3 is the only option that gives us parity with Google Chrome security-wise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diracdeltas - ENFORCE_STRICT
is only used when field trials are enabled, I don't think Chrome has field trials enabled for release builds. Let me know if I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diracdeltas I thought it was the other way around? Chromium uses ENFORCE
so my preference is to follow that and not patch here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diracdeltas @bridiver - ENFORCE_STRICT
works well for the extensions I have tested, but I understand the concern that we might run into web-compat issues with an experimental feature.
I have a patch for 3
but, I'm okay with 1
to avoid any web-compat risk we might run into.
!args->GetString(1, &enable_str)) | ||
return; | ||
|
||
+ SyncFeatureFlagWithBravePrefs(entry_internal_name, Profile::FromWebUI(web_ui())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, I thought we were doing a lazy check to sync with the pref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we need notification at the time this changes then we should add a pref observer for kEnabledLabsExperiments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I could have named it better, the intention of this call is to update the temporary pref kBraveEnabledMediaRouter
that we use in brave://settings
when flags are toggled. So toggling the flag correctly toggles the Media Router
switch in brave://settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this can be done without a patch using a chromium_src override for SetFeatureEntryEnabled
which I thought is what we had before and maybe this is why I'm confused here
@@ -45,13 +45,42 @@ int OnBeforeURLRequest_CommonStaticRedirectWork( | |||
const ResponseCallback& next_callback, | |||
std::shared_ptr<BraveRequestInfo> ctx) { | |||
GURL::Replacements replacements; | |||
static URLPattern googleapis_pattern( | |||
URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS, kGoogleAPIPrefix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lint 4 spaces
base::Value(restart_needed_)); | ||
} | ||
|
||
void BraveDefaultExtensionsHandler::HandleRestartBrowser( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the correct way to handle this is to just link to kChromeUIRestartURL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Navigation to kChromeUIRestartURL
internally calls chrome::AttemptRestart
: https://cs.chromium.org/chromium/src/chrome/browser/browser_about_handler.cc?l=98.
We can link to kChromeUIRestartURL
in javascript directly but I was just trying to avoid chances of regression if kChromeUIRestartURL
changes in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is better to use kChromeUIRestartURL
than to duplicate the logic here. Not sure why kChromeUIRestartURL
would change in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bridiver just noting that the same functionality in chrome://flags
does not link to kChromeUIRestartUI
but sends a message to a message handler via chrome.send
too and calls AttemptRestart
. I wonder what would happen to session restore if the tab was navigated away from the settings page to kChromeUIRestartURL
. The settings page may not restore, which would be unfortunate. Although I did spot comments around this being a non-navigation url, so maybe it would restore... Still, I wonder why the Flags page doesn't use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@petemill because a lot of other things happen in FlagsDOMHandler::HandleRestartBrowser
before the restart. The only thing we're doing here is calling AttemptRestart
so it's functionally equivalent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DCHECK(flags_storage_);
#if defined(OS_CHROMEOS)
// On ChromeOS be less intrusive and restart inside the user session after
// we apply the newly selected flags.
base::CommandLine user_flags(base::CommandLine::NO_PROGRAM);
about_flags::ConvertFlagsToSwitches(flags_storage_.get(),
&user_flags,
flags_ui::kAddSentinels);
// Apply additional switches from policy that should not be dropped when
// applying flags..
chromeos::UserSessionManager::MaybeAppendPolicySwitches(
Profile::FromWebUI(web_ui())->GetPrefs(), &user_flags);
base::CommandLine::StringVector flags;
// argv[0] is the program name |base::CommandLine::NO_PROGRAM|.
flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end());
VLOG(1) << "Restarting to apply per-session flags...";
AccountId account_id =
user_manager::UserManager::Get()->GetActiveUser()->GetAccountId();
chromeos::UserSessionManager::GetInstance()->SetSwitchesForUser(
account_id,
chromeos::UserSessionManager::CommandLineSwitchesType::
kPolicyAndFlagsAndKioskControl,
flags);
#endif
chrome::AttemptRestart();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they need all of that code to run on chromeos before attempting the restart
|
||
|
||
AllowJavascript(); | ||
ResolveJavascriptCallback(args->GetList()[0].Clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you cloning this? Also args->GetList()[0]
is not the correct or safe way to get this value.
std::string callback_id;
args->GetString(0, &callback_id);
and then pass in base::Value(callback_id)
// Adding the media router extension on explicit toggle to prevent | ||
// any suprise connections on upgrade | ||
if (enabled) { | ||
extensions::ExtensionPrefs::Get(profile_)->SetExtensionEnabled( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be directly calling ExtensionPrefs::SetExtensionEnabled
. You should enable/disable using the ExtensionRegistry
9bde2f6
to
40ccf3d
Compare
TEST_F(BraveCommonStaticRedirectNetworkDelegateHelperTest, | ||
RedirectChromecastDownload) { | ||
net::TestDelegate test_delegate; | ||
GURL url( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
#define SetFeatureEntryEnabled SetFeatureEntryEnabled_ChromiumImpl | ||
#include "../../../../chrome/browser/about_flags.cc" // NOLINT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed because SetFeatureEntryEnabled
in about_flags.cc calls, SetFeatureEnabled
in flags_state.cc
14e207c
to
fb00111
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found a minor issue with the restart prompt. Since I've already provided feedback about that which may have led to this issue, I've implemented a proposed change in #2974. Apart from that it all looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cast off! ⚓️
Fixes brave/brave-browser#209
Related brave/brave-browser#4631
Revert "Merge pull request #2119 from brave/revert_enabling_chromecast"
This reverts commit 29ea1df, reversing
changes made to c08710a.
Submitter Checklist:
npm test brave_unit_tests && npm test brave_browser_tests && npm run test-security
) onnpm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
First Launch
udp.port == 1900
and verify that no traffic is generated by Brave.Settings Page
Upgrade
Settings UI
Sync with brave://flags
Load Media Router Component Extension
to enabledLoad Media Router Component Extension
to disabledReviewer Checklist:
After-merge Checklist:
changes has landed on.