-
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
Introduced copy text from image feature on macOS #16508
Conversation
|
8e10b4b
to
d951d34
Compare
d951d34
to
3062303
Compare
@diracdeltas Should I have security review for this PR? |
@rmcfadden3 Can you review the newly added sentences? |
thanks for flagging. is this framework local-only? (AKA no network requests are generated in language detection and text extraction). if so it should be fine. if not we should maybe disable in Tor windows also do we need any licensing changes to use the framework? i assume not. |
According to the docs, processing happens on user's device. - https://developer.apple.com/documentation/vision/recognizing_text_in_images?language=objc
I think we don't need another licensing for builtin SDK cc @fmarier |
no concerns from me then! |
If it's an OS feature provided by Apple, then I don't think so either. |
@simonhong — all of your text looks great. However, I would slightly edit the last option to make it grammatically correct:
|
3062303
to
1f145cb
Compare
Updated. Thanks! |
Functionality works great! 😄 This is really cool - will check out the code next |
for (const auto& t : text) { | ||
unified_string += t; | ||
unified_string += '\n'; | ||
} |
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.
The above is fine 😄 But you could use std library:
const char* const delim = "\n";
std::ostringstream unified;
std::copy(text.begin(), text.end(),
std::ostream_iterator<std::string>(unified, delim));
std::string unified_string = unified.str();
Need to include <sstream>
and maybe some others (lint should warn with include what you use)
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.
Pushed a quick update with this - 1d611fe 😄
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.
Inspired from your changes - I found base::JoinString()
api!
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.
Sometimes I don't understand why we don't have basic operation like join string in std 😭
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.
Nice find! 😃 And yes - I completely agree, @sangwoo108 😄
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++
|
|
1 similar comment
|
|
|
2 similar comments
|
|
|
758dfb9
to
9e19f2e
Compare
|
1 similar comment
|
|
|
||
#define TEXT_RECOGNITION_BROWSER_EXPORT | ||
|
||
#endif |
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 use base/component_export.h
instead along with COMPONENT_EXPORT(TEXT_RECOGNITION...)
macro.
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.
Done.
browser/ui/BUILD.gn
Outdated
"//brave/browser/ui", | ||
"//brave/components/constants", | ||
"//chrome/browser", | ||
"//chrome/browser/devtools:test_support", | ||
"//chrome/browser/profiles:profile", | ||
"//chrome/browser/ui", | ||
"//chrome/test:test_support_ui", | ||
"//chrome/test:unit_tests", |
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.
with this line you effectively added browser_tests->unit_tests dependency.
you should definitely not do that. maybe you only need to depend on gtest?
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 picked wrong target for chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h
among below three candidates. //chrome/test:test_support
is picked. Thanks!
ERROR at //brave/browser/ui/text_recognition_browsertest.cc:20:11: Include not allowed.
#include "chrome/browser/renderer_context_menu/render_view_context_menu_test_util.h"
^------------------------------------------------------------------------
It is not in any dependency of
//brave/browser/ui:browser_tests
The include file is in the target(s):
//chrome/test:interactive_ui_tests
//chrome/test:test_support
//chrome/test:unit_tests
at least one of which should somehow be reachable.
fad8041
to
e6c43a1
Compare
|
"//skia", | ||
] | ||
|
||
defines = [ "IS_TEXT_RECOGNITION_BROWSER_IMPL" ] |
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.
Oh, good to know. Updated with verified commit :) !
|
fix brave/brave-browser#27513 "Copy Text From Image" entry is added to render view's context menu. It gets bitmap data from renderer via LocalFrame::GetImage() mojom interface, and then passed it to TextRecognitionDialog to extract and show text from that image.
If renderer is busy or on slow machine, copy image could take some time. In that situation, user could ask copy text menu multiple times. And then, browser would get multiple copied image from renderer. When it happens, use same dialog and show lastly recognized text in dialog instead of creating multiple dialogs.
e6c43a1
to
58374fa
Compare
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 with one more comment.
This test extract "brave" text from test image.
58374fa
to
6855228
Compare
fix brave/brave-browser#27513
"Copy Text From Image" entry is added to render view's context menu.
It gets bitmap data from renderer via LocalFrame::GetImage() mojom interface,
and then passed it to TextRecognitionDialog to extract and show text from the image.
Newly added context meny entry
Dialog shows the copied text from image. Vertical scroll bar can be shown based on the contents.
When text recognition is in-progress:
When text recognition is failed:
Resolves
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 lint
,npm 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:
TextRecognitionBrowserTest.TextRecognitionTest
Copy Text From Image
item from context menu