-
Notifications
You must be signed in to change notification settings - Fork 896
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
base: master
Are you sure you want to change the base?
Conversation
0e69a8a
to
4b7451d
Compare
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! |
22868e1
to
fdd6104
Compare
chromium_src/chrome/browser/renderer_context_menu/render_view_context_menu.cc
Outdated
Show resolved
Hide resolved
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 % nits
Remove general "NotifyUser" method and use explicit methods. Remove redundancy in tab feature logic, now passing a callback to the fullscreen page method so that all methods call a single OnComplete when they finish.
By using a browser reference we can avoid the reliance on global methods to look up a window from a given webcontents instance.
Removed the helper "TakeScreenshot" method which originally existed to stand up and instance of the helper. Now that the helper is a proper tab feature, we can use it as such from context menu commands and elsewhere.
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.
f8c8d02
to
6d39b1e
Compare
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.
[puLL-Merge] - brave/brave-core@27083 DescriptionThis PR introduces a new screenshot feature for the Brave browser. It adds functionality to capture screenshots of selected regions, the viewport, or full pages, and copy them to the clipboard. The feature is implemented as a set of new commands in the browser's context menu and is controlled by a feature flag. ChangesChanges
sequenceDiagram
participant User
participant ContextMenu
participant BraveScreenshotsTabFeature
participant ScreenshotStrategy
participant WebContents
participant Clipboard
User->>ContextMenu: Select screenshot option
ContextMenu->>BraveScreenshotsTabFeature: StartScreenshot
BraveScreenshotsTabFeature->>ScreenshotStrategy: Create strategy
ScreenshotStrategy->>WebContents: Capture screenshot
WebContents-->>ScreenshotStrategy: Return image
ScreenshotStrategy-->>BraveScreenshotsTabFeature: OnCaptureComplete
BraveScreenshotsTabFeature->>Clipboard: Copy image
BraveScreenshotsTabFeature->>User: Display screenshot bubble
Possible Issues
Security Hotspots
|
] | ||
|
||
deps = [ | ||
"//chrome/browser/image_editor:image_editor", |
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 just //chrome/browser/image_editor
same as "//chrome/browser/ui
and //ui/base/clipboard
~BraveScreenshotsTabFeature(); | ||
|
||
void StartScreenshot(Browser* browser, ScreenshotType type); | ||
void OnCaptureComplete(const image_editor::ScreenshotCaptureResult& result); |
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 doesn't need to be public.
// Some screenshots may need to be clipped to avoid the GPU limit. | ||
// See https://crbug.com/1260828. When this happens, we may wish to notify the | ||
// user that only a portion of their page could be captured. | ||
void DisplayScreenshotClippedNotification(base::WeakPtr<Browser> browser) { | ||
NOTIMPLEMENTED(); | ||
} |
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.
can we create an GitHub issue as follow-up so we don't forget?
if (strategy_) { | ||
strategy_.reset(); | ||
} |
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 won't be necessary, it will get destructed along with destructor.
if (strategy_) { | ||
strategy_.reset(); | ||
} |
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.
When the new unique_ptr gets move into it in the next few lines, the old one will be destroyed so we don't need to explicitly reset it here.
if (!strategy_) { | ||
OnCaptureComplete({}); | ||
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.
This won't happen because there is no nullptr returned in CreateStrategy
base::Value::Dict params; // No parameters needed | ||
SendDevToolsCommand("Page.getLayoutMetrics", std::move(params), next_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 can be inlined in function call as base::Value::Dict()
content::ContextMenuParams params; | ||
params.page_url = GURL("devtools://devtools"); | ||
|
||
auto context_menu = CreateContextMenu(GetWebContents(), params, 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.
why is is_pwa_browser
true in this case?
Resolves brave/brave-browser#25816
Security/Privacy Review: https://github.com/brave/reviews/issues/1831
screenshot-context-menu.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:
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.