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

Adds screenshot options to context menu and commands #27083

Open
wants to merge 56 commits into
base: master
Choose a base branch
from

Conversation

jonathansampson
Copy link
Contributor

@jonathansampson jonathansampson commented Dec 21, 2024

Resolves brave/brave-browser#25816
Security/Privacy Review: https://github.com/brave/reviews/issues/1831

screenshot-context-menu.mp4

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:

  1. Right-click on a page
  2. Click Screenshot Tools from the context menu
  3. Select an option (i.e., Selection, Viewport, Full page) from the submenu

Once a screenshot has been taken, you should see a UI element (with a preview of your screenshot) informing you that the screenshot has been copied to your device's clipboard.

@jonathansampson jonathansampson added enhancement CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS labels Dec 21, 2024
@jonathansampson jonathansampson self-assigned this Dec 21, 2024
@github-actions github-actions bot added the CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) label Dec 21, 2024
@jonathansampson jonathansampson marked this pull request as ready for review December 23, 2024 04:48
@jonathansampson jonathansampson requested review from a team and bridiver as code owners December 23, 2024 04:48
@jonathansampson jonathansampson marked this pull request as draft December 26, 2024 22:48
@jonathansampson jonathansampson marked this pull request as draft December 26, 2024 22:48
@jonathansampson jonathansampson marked this pull request as draft December 26, 2024 22:48
@jonathansampson jonathansampson force-pushed the sampson-brave-screenshots branch 2 times, most recently from 0e69a8a to 4b7451d Compare December 28, 2024 23:18
@jonathansampson jonathansampson marked this pull request as ready for review December 29, 2024 02:58
@jonathansampson
Copy link
Contributor Author

I've refactored this into a TabHelper pattern, with deferred attachment (until user requests a screenshot). Commits landing here in a bit.

@bridiver
Copy link
Collaborator

bridiver commented Jan 2, 2025

I've refactored this into a TabHelper pattern, with deferred attachment (until user requests a screenshot). Commits landing here in a bit.

Make sure you follow the latest updates using TabInterface and not WebContentsUserData

@jonathansampson
Copy link
Contributor Author

I've refactored this into a TabHelper pattern, with deferred attachment (until user requests a screenshot). Commits landing here in a bit.

Make sure you follow the latest updates using TabInterface and not WebContentsUserData

Looking into that now. Thanks!

@jonathansampson jonathansampson marked this pull request as draft January 2, 2025 21:17
@jonathansampson jonathansampson force-pushed the sampson-brave-screenshots branch 2 times, most recently from 22868e1 to fdd6104 Compare January 4, 2025 17:34
@github-actions github-actions bot added the CI/run-network-audit Run network-audit label Jan 4, 2025
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

lgtm % nits

@jonathansampson jonathansampson marked this pull request as ready for review January 7, 2025 14:04
If there is nothing selected, we shouldn't attempt to construct an autocomplete match, run the autocomplete classifier, etc. Furthermore, this enables us to simplify tests involving the context menu due to reduced setup.
After rebasing, there is now a failure in this PR unrelated to the contents or changes introduced by the PR itself. A fresh build from scratch will resolve this, but a component build will proceed if any change is made to the policy template file. As such, a typo has been found and fixed so as to 1) Improve the comments, and importantly 2) Fix the build 😀 See https://bravesoftware.slack.com/archives/C7VLGSR55/p1736928018175489?thread_ts=1736911378.517619&cid=C7VLGSR55 for more info.
Removes unused parameters and prefers simpler constructor pattern
@jonathansampson jonathansampson force-pushed the sampson-brave-screenshots branch from 4bf06f9 to 1862009 Compare January 22, 2025 20:20
Copy link
Contributor

[puLL-Merge] - brave/brave-core@27083

Description

This PR introduces screenshot functionality to the Brave browser, allowing users to capture full-page screenshots, viewport screenshots, and selected regions. The implementation includes context menu integration and clipboard support.

Changes

Changes

  1. Command IDs and Strings (app/)
  • Added new command IDs for screenshot tools
  • Added localized strings for screenshot menu items
  1. Screenshots Feature Implementation (browser/brave_screenshots/)
  • Implemented three screenshot strategies:
    • FullPageStrategy: Captures entire webpage
    • ViewportStrategy: Captures visible portion
    • SelectionStrategy: Captures user-selected region
  • Added feature flag control (kBraveScreenshots)
  • Implemented clipboard integration for captured screenshots
  1. UI Integration
  • Added screenshot options to context menu
  • Added command handling in BraveBrowserCommandController
  • Integrated with browser commands system
  1. Build System
  • Added new GN build files for screenshots feature
  • Added conditional compilation based on platform
sequenceDiagram
    participant User
    participant ContextMenu
    participant BraveScreenshotsTabFeature
    participant ScreenshotStrategy
    participant Clipboard

    User->>ContextMenu: Right-click
    ContextMenu->>ContextMenu: MaybeBuildBraveScreenshotsMenu()
    User->>ContextMenu: Select Screenshot Option
    ContextMenu->>BraveScreenshotsTabFeature: StartScreenshot()
    BraveScreenshotsTabFeature->>ScreenshotStrategy: CreateStrategy()
    ScreenshotStrategy->>ScreenshotStrategy: Capture()
    ScreenshotStrategy-->>BraveScreenshotsTabFeature: OnCaptureComplete()
    BraveScreenshotsTabFeature->>Clipboard: CopyImageToClipboard()
    BraveScreenshotsTabFeature->>User: DisplayScreenshotBubble()
Loading

Possible Issues

  1. Large screenshots may be clipped due to GPU texture size limits (16384x16384)
  2. Screenshot notification for clipped images is not yet implemented (marked as NOTIMPLEMENTED)

Security Hotspots

  1. DevTools Protocol usage in FullPageStrategy could potentially expose sensitive information if not properly sanitized
  2. Clipboard operations need proper validation to prevent memory/resource exhaustion

@@ -103,6 +104,18 @@ source_set("ui") {
"webui/skus_internals_ui.h",
]

if (enable_brave_screenshots) {
sources += [
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should have it's on BUILD.gn and these sources definitely do not belong in browser/ui/BUILD.gn because they aren't even in browser/ui

Copy link
Collaborator

Choose a reason for hiding this comment

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

not sure yet if they should be in browser/ui instead, but either way there should be a BUILD.gn for the directory

Copy link
Collaborator

Choose a reason for hiding this comment

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

also these sources exist in multiple places so something is definitely weird here if you're not getting any errors

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh, there are no errors because they are .h files, but you should not be adding files like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/run-network-audit Run network-audit CI/run-upstream-tests Run upstream unit and browser tests on Linux and Windows (otherwise only on Linux) CI/skip-android Do not run CI builds for Android CI/skip-ios Do not run CI builds for iOS enhancement puLL-Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Include "Capture Screenshot" option in the context menu
4 participants