-
Notifications
You must be signed in to change notification settings - Fork 871
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
[Android] youtube quality settings #24164
base: master
Are you sure you want to change the base?
Conversation
7ded4f2
to
739ad8f
Compare
@Override | ||
public void setDefaultQuality(@YTVideoQuality int defaultQuality) { | ||
UserPrefs.get(getProfile()).setInteger(BravePref.YT_VIDEO_QUALITY_PREF, defaultQuality); | ||
BraveRelaunchUtils.askForRelaunch(getActivity()); |
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.
do we really need to ask for relaunch? I think as a max we should reload a current tab or even don't do anything at all.
rbAllowWifi.setChecked(true); | ||
} else if (mQuality == YTVideoQuality.OFF) { | ||
rbOff.setChecked(true); | ||
} |
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's probably a good idea to setChecked to false for all 3 before the if or make default values in xml
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.
++
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.
LGTM
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.
strings
++
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.
security lgtm. cc @bridiver for the JS inject
4cb41ff
to
10e92bd
Compare
10e92bd
to
1e219a2
Compare
@stoletheminerals implementation changed so I have created new security/privacy review: https://github.com/brave/reviews/issues/1720 |
PrefService* pref_service) { | ||
#if BUILDFLAG(IS_ANDROID) | ||
int qualityPref = pref_service->GetInteger(kYTVideoQualityPref); | ||
return qualityPref == static_cast<int>(settings::YTVideoQuality::kOn) || |
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 is not something BraveRendererUpdater
should have to understand. You should send the raw pref value and also this is not going to correctly update when the connection type 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.
we have to send value based on preference set by user in the settings and connection type and for that we need connection type only when site starts loading. we are not listening for connection type changes.
@@ -47,7 +47,7 @@ const char kObservingScriptletEntryPoint[] = | |||
|
|||
const char kScriptletInitScript[] = | |||
R"((function() { | |||
let text = '(function() {\nconst scriptletGlobals = (() => {\nconst forwardedMapMethods = ["has", "get", "set"];\nconst handler = {\nget(target, prop) { if (forwardedMapMethods.includes(prop)) { return Map.prototype[prop].bind(target) } return target.get(prop); },\nset(target, prop, value) { if (!forwardedMapMethods.includes(prop)) { target.set(prop, value); } }\n};\nreturn new Proxy(new Map(%s), handler);\n})();\nlet deAmpEnabled = %s;\n' + %s + '})()'; | |||
let text = '(function() {\nconst scriptletGlobals = (() => {\nconst forwardedMapMethods = ["has", "get", "set"];\nconst handler = {\nget(target, prop) { if (forwardedMapMethods.includes(prop)) { return Map.prototype[prop].bind(target) } return target.get(prop); },\nset(target, prop, value) { if (!forwardedMapMethods.includes(prop)) { target.set(prop, value); } }\n};\nreturn new Proxy(new Map(%s), handler);\n})();\nlet deAmpEnabled = %s;\nlet isYtHdQualityPlaybackEnabled = %s;\n' + %s + '})()'; |
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 don't think this makes sense as part of cosmetic filter or adblock. Either this class should be made into a more generic handler and renamed or we should create something new here. wdyt @antonok-edm
@@ -9,6 +9,7 @@ | |||
|
|||
#include "base/check_is_test.h" | |||
#include "base/functional/bind.h" | |||
#include "brave/browser/android/constants.h" |
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.
missing android guard
browser/android/constants.h
Outdated
namespace settings { | ||
|
||
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.settings | ||
enum class YTVideoQuality { kOn, kAllowOverWifi, kOff }; |
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.
youtube_constants.h or youtube/constants.h and also please don't abbreviate. Use Youtube/youtube instead of YT in general for clarity
android/BUILD.gn
Outdated
@@ -14,6 +14,7 @@ declare_args() { | |||
|
|||
java_cpp_enum("brave_android_java_enums_srcjar") { | |||
sources = [ | |||
"//brave/browser/android/constants.h", |
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 file should have it's own java_cpp_enum
in https://github.com/brave/brave-core/pull/24164/files#diff-c528ac841614c7466a1d915247b27506c4318d8bea37e40f0c63b186e24b28a0
The decentralized_dns one should also be fixed in a follow-up.
components/constants/pref_names.h
Outdated
@@ -115,6 +115,7 @@ inline constexpr char kPlayYTVideoInBrowserEnabled[] = | |||
"brave.play_yt_video_in_browser_enabled"; | |||
inline constexpr char kBackgroundVideoPlaybackEnabled[] = | |||
"brave.background_video_playback"; | |||
inline constexpr char kYTVideoQualityPref[] = "brave.yt_video_quality"; |
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.
please move this into pref_names.h in the same directory as the enum along with its own java_cpp_strings
target
The existing java_pref_names_srcjar
has the same problem as https://github.com/brave/brave-core/pull/24164/files#r1708392864 above
if (chromeTabbedActivity != null && chromeTabbedActivity.getActivityTab() != null) { | ||
Tab currentTab = chromeTabbedActivity.getActivityTab(); | ||
if (currentTab.getUrl().domainIs(BraveConstants.YOUTUBE_DOMAIN)) { | ||
currentTab.reload(); |
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 do we need to reload the tab?
new cosmetic_filters::CosmeticFiltersJsRenderFrameObserver( | ||
render_frame, ISOLATED_WORLD_ID_BRAVE_INTERNAL, dynamic_params_closure); | ||
render_frame, ISOLATED_WORLD_ID_BRAVE_INTERNAL, dynamic_params_closure, |
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.
reported by reviewdog 🐶
[semgrep] Security hotspot found (ISOLATED_WORLD
). A security-team member should analyze the code security for possible vulnerabilities.
Source: https://github.com/brave/security-action/blob/main/assets/semgrep_rules/client/brave-isolated-world.yaml
Cc @thypon @diracdeltas @bridiver
9bbe6f4
to
108cabb
Compare
108cabb
to
c136310
Compare
[puLL-Merge] - brave/brave-core@24164 DescriptionThis PR introduces a new feature for YouTube video quality settings on Android devices. It adds a preference to control HD video playback on YouTube, allowing users to choose between always enabling HD quality, enabling it only on Wi-Fi, or disabling it. ChangesChanges
Possible Issues
Security HotspotsNo significant security hotspots were identified in this change. The new feature primarily deals with user preferences and does not introduce new attack surfaces or handle sensitive data. |
@@ -39,7 +39,8 @@ class CosmeticFiltersJSHandler { | |||
// filtering is enabled, and returns whether or not to proceed with cosmetic | |||
// filtering. | |||
bool ProcessURL(const GURL& url, std::optional<base::OnceClosure> callback); | |||
void ApplyRules(bool de_amp_enabled); | |||
void ApplyRules(bool de_amp_enabled, | |||
bool is_youtube_hd_quality_playback_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.
this is definitely not what we want to do here, we should selectively enable these scripts on the browser side by using different data sources, but also right now this is going to be disabled when adblock is disabled which is clearly not what we want 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.
Removing from |
Resolves brave/brave-browser#32842
Submitter Checklist:
https://github.com/brave/reviews/issues/1720
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
On
Go to Settings -> Media -> High Definition Playback -> Select On
Restart brave
Play any youtube video which has 720p resolution then it will play video with 720p resolution
Allow over Wi-Fi
Go to Settings -> Media -> High Definition Playback -> Select Allow over Wi-Fi
Restart brave
Mobile data: Youtube video play with default resolution decided by youtube.com player
On Wi-Fi: Play any youtube video which has 720p resolution then it will play video with 720p resolution
Off
Youtube video play with default resolution decided by youtube.com player