-
Notifications
You must be signed in to change notification settings - Fork 893
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
Element Picker on Android #26725
Element Picker on Android #26725
Conversation
A Storybook has been deployed to preview UI for the latest push |
Chromium major version is behind target branch (131.0.6778.69 vs 132.0.6834.15). Please rebase. |
0b29960
to
50b3c88
Compare
android:id="@+id/brave_shields_block_element_text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="48dp" | ||
android:paddingStart="16dp" |
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.
as paddingStart
and paddingEnd
are the same, so it is possible to use a single android:paddingHorizontal
</div> | ||
</section> | ||
</section> | ||
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.
probably the last line should be empty
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.
Android and native changes 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.
Lgtm
@@ -1620,6 +1622,20 @@ public void openBraveContentFilteringSettings() { | |||
settingsLauncher.startSettings(this, ContentFilteringFragment.class); | |||
} | |||
|
|||
public boolean isNightlyModeEnabled() { |
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: NightlyMode
sounds like it has to do with the release channel, maybe NightMode
instead?
} | ||
|
||
@CalledByNative | ||
public static boolean isNightlyModeEnabled() { |
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.
same
@@ -6,23 +6,18 @@ const NSSVG = 'http://www.w3.org/2000/svg' | |||
|
|||
let pickerDiv: HTMLDivElement | null | |||
let shadowRoot: ShadowRoot | null | |||
const isAndroid = /(android)/i.test(navigator.userAgent) |
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.
is this best practice? Not a big deal, just a bit suprising, imo
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 use initialization call which returns the platform
if (isAndroid) { | ||
return | ||
} |
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 it's as easy as removing early returns, I'd leave this kind of mouse-specific logic in on Android since some folks would e.g. use a keyboard/mouse combo on a tablet
Perhaps it's worth using pointer
/hover
media queries rather than UA inspection? ref
blink::WebLocalFrame* web_frame = render_frame_->GetWebFrame(); | ||
std::string new_selectors_script = base::StringPrintf( | ||
kSePickerThemeInfoScript, is_dark_mode_enabled, background_color); | ||
web_frame->ExecuteScriptInIsolatedWorld( |
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 is possible to pass the result via getElementPickerThemeInfo(callback)
instead of using ExecuteScriptInIsolatedWorld()
?
|
||
mojo::AssociatedRemote<cosmetic_filters::mojom::CosmeticFiltersHandler>& | ||
CosmeticFiltersJSHandler::GetElementPickerRemoteHandler() { | ||
if (!element_picker_actions_handler_ || |
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.
Looks like we should just check is_connected()
:
https://source.chromium.org/chromium/chromium/src/+/main:mojo/public/cpp/bindings/associated_remote.h;l=94-114
int OnEventBegin(const std::string& event_name); | ||
void OnEventEnd(const std::string& event_name, int); | ||
|
||
void InjectStylesheet(const std::string& stylesheet); | ||
|
||
bool generichide_ = false; | ||
|
||
mojo::AssociatedRemote<cosmetic_filters::mojom::CosmeticFiltersHandler>& | ||
GetElementPickerRemoteHandler(); | ||
void OnRemoteHandlerDisconnect(); |
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: move the methods above.
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
++
d83dbdf
to
064dbbf
Compare
#if !BUILDFLAG(IS_ANDROID) | ||
mojom::RunningPlatform::kDesktop | ||
#else // !BUILDFLAG(IS_ANDROID) | ||
mojom::RunningPlatform::kAndroid |
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 looks a bit unusual. You should know at compile time that you're on Android. I don't think mojom::RunningPlatform
is necessary. Just check BUILDFLAG(IS_ANDROID)
where you need to.
declare_args() { | ||
enable_block_elements_feature = | ||
(brave_channel == "development" || brave_channel == "nightly" || | ||
brave_channel == "beta" || (is_official_build && !is_android)) && !is_ios |
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.
pls don't introduce a buildflag that's configured like this (a combination of channel, platform and official_build). This may lead to a broken build when the branch migration happens, because the flag in false
state is never checked on android
builds until we start building release builds in the branch with these changes.
Instead pls make the feature DISABLED by default on Android and enable it via Griffin on beta/nightly. Everything will be simpler this way. You can add it into brave://flags
so anyone can enable it manually in any branch.
|
||
bool IsDarkModeEnabled() { | ||
JNIEnv* env = base::android::AttachCurrentThread(); | ||
return Java_BraveCosmeticFiltersUtils_isNightModeEnabled(env); |
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.
is there really no existing way to check if dark mode is enabled on Android from C++ code?
what about GetDarkModeState()
from chrome/browser/flags/android/chrome_session_state.h
?
if you really need these values from BraveActivity
, please consider making it as browser-wide util, not bound to cosmetic_filters
.
@@ -128,6 +129,14 @@ BASE_FEATURE(kCosmeticFilteringSyncLoad, | |||
BASE_FEATURE(kBlockAllCookiesToggle, | |||
"BlockAllCookiesToggle", | |||
base::FEATURE_DISABLED_BY_DEFAULT); | |||
// when enabled, allow to select and block HTML elements | |||
BASE_FEATURE(kBlockElementFeature, |
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.
maybe BraveShieldsElementPicker
?
} | ||
|
||
const active = document.getElementById('brave-element-picker') | ||
if (!active) { | ||
launchElementPicker(attachElementPicker()) | ||
api.initElementPicker((platform: number) => { |
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'd go something like platform: 'desktop' | 'android'
@@ -24,6 +24,9 @@ interface CosmeticFiltersHandler { | |||
|
|||
// Opens the custom filter section in Shields settings . | |||
ManageCustomFilters(); | |||
|
|||
GetElementPickerThemeInfo() => ( | |||
bool is_nightly_mode_enabled, int32 background_color); |
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.
is_nightly_mode_enabled
-> is_dark_mode_enabled
color_provider.GetColor(kColorSidePanelBadgeBackground)); | ||
#else // !BUILDFLAG(IS_ANDROID) | ||
std::move(callback).Run(chrome::android::GetDarkModeState() == | ||
chrome::android::DarkModeState::kDarkModeSystem, |
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 we should check both kDarkModeSystem
and kDarkModeApp
.
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
Signed-off-by: Vadym Struts <[email protected]>
382878a
to
828afc3
Compare
[puLL-Merge] - brave/brave-core@26725 DescriptionThis PR introduces a new feature for element picking and blocking in the Brave browser, primarily focusing on the Android platform. It adds functionality to select and block specific HTML elements on web pages, enhancing the user's ability to customize their browsing experience. ChangesChanges
sequenceDiagram
participant User
participant BraveShieldsUI
participant CosmeticFiltersUtils
participant ElementPicker
participant WebContent
User->>BraveShieldsUI: Tap "Block element"
BraveShieldsUI->>CosmeticFiltersUtils: launchContentPickerForWebContent()
CosmeticFiltersUtils->>ElementPicker: Inject and initialize
ElementPicker->>WebContent: Attach to DOM
User->>ElementPicker: Select element
ElementPicker->>CosmeticFiltersUtils: Create filter
CosmeticFiltersUtils->>WebContent: Apply filter
ElementPicker->>User: Show confirmation
User->>ElementPicker: Confirm or cancel
ElementPicker->>CosmeticFiltersUtils: Save or discard filter
CosmeticFiltersUtils->>BraveShieldsUI: Update UI
Possible Issues
Security Hotspots
|
Released in v1.75.104 |
Resolves brave/brave-browser#33241
2024-12-04.13-44-36.mp4
Submitter Checklist:
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:
Brave Shields menu
->Advanced controls
Block elements
item is absent (It means thatbrave://flags/#block-element-feature
flag is disabled)Block elements
item is present in theBrave Shields menu
->Advanced controls
menuBlock elements
and make sure thatElement Picker
appearsBlock Element
, and make sure element blockedElement picker
has the same color