Skip to content
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

Content picker native inject #25411

Merged
merged 27 commits into from
Sep 12, 2024
Merged

Content picker native inject #25411

merged 27 commits into from
Sep 12, 2024

Conversation

atuchin-m
Copy link
Collaborator

@atuchin-m atuchin-m commented Sep 3, 2024

Resolves brave/brave-browser#40821
For brave/brave-browser#40994

UPD: the PR is updated to match the new product requirements. The brave/browser code to communicated with frames moved to a dedicated tab helper created on demand.

The PR:

  1. replaces an extension-based picker context menu to a native one;
  2. drops using Brave Extension background page to inject the bundle. Now it's done via: context menu => tab_helper =(mojo)=> a frame agent(CosmeticFiltersJSHandler) => execute JS in a isolated world. The same world as for cosmetic filters is used.
  3. provides a native function instead of chrome.braveShields to add a new rule. The pipeline: JS => the frame agent =(mojo)=> CosmeticFiltersResources(task_runner) => AdblockService(task_runner) => AdblockService(UI)
  4. adds browser tests to cover these pipelines + opening brave://settings/shields/filters.
  5. makes the context menu is enabled iif blocking ads&trackers is on. Otherwise it can't efficiently hide elements.
  6. chrome.braveShields impl are removed.

A product-related questions:
brave/brave-browser#40821 (comment)

before after
image image

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

brave/brave-browser#40821 (comment)

@atuchin-m atuchin-m self-assigned this Sep 3, 2024
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Sep 3, 2024
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

app/brave_generated_resources.grd Outdated Show resolved Hide resolved
Comment on lines 353 to 357
<message name="IDS_ADBLOCK_CONTEXT_BLOCK_ELEMENT" desc="Message for context menu that enables the element picker UI to apply cosmetic filter rules to the page (was 'elementPickerMode' from Brave Extension)">
Block element
</message>
<message name="IDS_ADBLOCK_CONTEXT_MANAGE_CUSTOM_FILTERS" desc="Message for context menu that opens a page for adding, editing, and removing custom cosmetic filters (was 'manageCustomFilters' from Brave Extension)">
Manage custom filters
Copy link
Collaborator

Choose a reason for hiding this comment

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

The parenthesized parts probably aren't relevant to translators

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok, I will remove it.
My intention was to reuse the current locale keys in the brave extension.
I suppose we can do it another way by tagging a right person.

Comment on lines 793 to 795
menu_model_.InsertSubMenuWithStringIdAt(
*print_index + 1, IDC_ADBLOCK_CONTEXT_TOOLS, IDS_ADBLOCK_CONTEXT_TOOLS,
&adblock_submenu_model_);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have you tried SetIcon and/or SetMinorIcon here? I assume one of those should work if we want to restore the Brave logo

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I haven't tried because normally the menu has icons only in the extension block.
No problem to restore it if we really need.

@atuchin-m atuchin-m changed the title [Draft] Content picker native inject Content picker native inject Sep 4, 2024
@atuchin-m atuchin-m force-pushed the content-picker-native-inject branch 3 times, most recently from 124a67f to 78de4da Compare September 4, 2024 13:12
@github-actions github-actions bot removed the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Sep 11, 2024
Copy link
Collaborator

@mkarolin mkarolin left a comment

Choose a reason for hiding this comment

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

strings++

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Asked in DM about the benefits of RenderFrameHostReceiverSet over AssociatedReceiverSet but assume it's ok. JS / HTML changes look good.

@@ -1,12 +1,23 @@
# Copyright (c) 2020 The Brave Authors. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit strange that these files are in resources/data since it's not data but is executed scripts / UI. How about resources/ui?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Your point makes sense.
But that dir also has content_cosmetic.ts that don't have UI and also injected by cosmetic_filters_js_handler.
So making a separate dir and BUILD.gn make the code more sophisticated without extra benefits.

@atuchin-m
Copy link
Collaborator Author

About RenderFrameHostReceiverSet:
AssociatedReceiverSet is a basic container, you have to add/remove receivers by yourself.
RenderFrameHostReceiverSet uses AssociatedReceiverSet internally. It uses RFH as a key. It also has a logic to remove the (key,value) for deleted frames.

P.S. A single (Associated)Receiver also could be used for that particular task. But adding more methods in the interface can result in issues: a one tab helper matches to multiple RFH (even the main ones).

@atuchin-m atuchin-m merged commit 76a5a49 into master Sep 12, 2024
18 of 19 checks passed
@atuchin-m atuchin-m deleted the content-picker-native-inject branch September 12, 2024 08:24
@github-actions github-actions bot added this to the 1.72.x - Nightly milestone Sep 12, 2024
brave-builds added a commit that referenced this pull request Sep 16, 2024
@kjozwiak
Copy link
Member

kjozwiak commented Sep 23, 2024

Verification PASSED on Win 11 x64 using the following build(s):

Brave | 1.72.31 Chromium: 129.0.6668.59 (Official Build) nightly (64-bit)
-- | --
Revision | 1b4e6c1e2eec55b17718e8a1b44845afc773c20c
OS | Windows 11 Version 23H2 (Build 22631.4169)

Using the STR/Cases outlined via brave/brave-browser#40821 (comment), went through the following:

Test Case #1 - General & Manage Filters

  • ensured that clicking on Block elements initiates the element picker on the particular page you're currently viewing
  • ensured that clicking on an element on the page correctly writes/displays the rule without any issues
  • ensured that clicking on Create writes the rule into brave://settings/shields/filters without any issues
  • ensured that clicking on Manage opens brave://settings/shields/filters without any issues
Example Example Example Example
1 2 3 4

Test Case #1 - Menu Positions/Block Trackers disabled

  • ensured that Block element is always above Inspect via the context menu
  • ensured that Block element is not being displayed when viewing the context menu when selecting text
  • ensured that Block element is being displayed via the context menu for links
  • ensured that Block element is not being displayed for NTP & brave:// pages
  • ensured that Block element is not being displayed when Allow all trackers & ads
    • ensured that Block element is being displayed when Block trackers & ads & Aggressive is selected
Example Example Example Example
text links mnu ntp
Example Example Example
shields1 shields2 shields3

kjozwiak pushed a commit that referenced this pull request Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build needs-security-review puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A native menu and a native inject for adblock content picker