Repository navigation
refactor(net): removes direct ui invocation from filemgr thread - #20480
Conversation
|
Heads up! This PR modifies the following files:
|
|
☔ The latest upstream changes (presumably #20391) made this pull request unmergeable. Please resolve the merge conflicts. |
|
I see you call |
b758fd0 to
1d4287c
Compare
|
@paulrouget I just give a quick try (open tfd for single / multiple dialog, check if it unblocks main) on linux / windows / macOS, and all platform seems working as expected. (Does not block / no immediate panic or unexpected behavior). |
| LoadComplete(TopLevelBrowsingContextId), | ||
| /// A pipeline panicked. First string is the reason, second one is the backtrace. | ||
| Panic(TopLevelBrowsingContextId, String, Option<String>), | ||
| /// Open file dialog to select files |
There was a problem hiding this comment.
Can you add a comment about what that boolean is for?
| ui: &UI) | ||
| where UI: UIProvider, | ||
| { | ||
| #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))] |
There was a problem hiding this comment.
I don't think we have to make a distinction between the platforms here. Let send a message to the embedder no matter the platform, and let the embedder decide what to do depending on the platform.
| FromCompositorMsg::SetCursor(cursor) => { | ||
| self.handle_set_cursor_msg(cursor) | ||
| } | ||
| FromCompositorMsg::OpenFileSelectDialog(patterns, multiple_files, sender) => { |
There was a problem hiding this comment.
Having to use FromCompositorMsg is unfortunate. Maybe a Request::Script might be better? Or even its own type of request.
@paulrouget I haven't tried but it may possible, mostly I tried follow steps in original issue #20428 's |
|
So far, only the constellation talks to the embedder via EmbedderMsg. So maybe let's keep it the way you did. |
1d4287c to
2c38b48
Compare
|
@paulrouget appreciate for feedback, I tried to update PR as suggested
If there are things need to be corrected, I'll update per suggestions. |
c45873d to
61a2b73
Compare
61a2b73 to
3b2a71c
Compare
|
Sorry. Was away for a while. I'll look at this again soon. |
|
no worries. 👍 |
|
I had a quick chat with @cbrewster and we agree that it's fine if the script thread has access to the EmbedderProxy. We could short-circuit the constellation. |
| /// A pipeline panicked. First string is the reason, second one is the backtrace. | ||
| Panic(TopLevelBrowsingContextId, String, Option<String>), | ||
| /// Open file dialog to select files. Set boolean flag to true allows to select multiple files. | ||
| GetSelectedFiles(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>), |
There was a problem hiding this comment.
Maybe rename that to PickFiles, RequestFiles or SelectFiles?
| self.embedder_proxy.send(msg); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
If we are forwarding a message, maybe we want to keep the same name.
Also, I talked to @cbrewster and we agree that maybe it's better to give access to the EmbedderProxy to each script thread.
| fn platform_get_selected_files(_patterns: Vec<FilterPattern>, | ||
| _multiple_files: bool, | ||
| sender: IpcSender<Option<Vec<String>>>) { | ||
| sender.send(None); |
There was a problem hiding this comment.
Maybe warn!("File picker not implemented") first?
|
I'll try to update short-curcuit as suggested. Due to personal schedules I may need some time to wrap things up, once done will ping via @-mention here. |
fcb7bcc to
c9b656f
Compare
|
@paulrouget Updated PR as suggested,
|
c9b656f to
62dd3dc
Compare
paulrouget
left a comment
There was a problem hiding this comment.
This feels a lot better! I think we made the right decision to use the embedder proxy.
A few neats and then I think we good to go.
Thank you.
| /// Create a new constellation thread. | ||
| pub fn start(state: InitialConstellationState) -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) { | ||
| pub fn start(state: InitialConstellationState) | ||
| -> (Sender<FromCompositorMsg>, IpcSender<SWManagerMsg>) { |
| let embedder = self.embedder_proxy.clone(); | ||
| thread::Builder::new().name("select files".to_owned()).spawn(move || { | ||
| store.select_files(filter, sender, origin, opt_test_paths, ui); | ||
| store.select_files(filter, sender, origin, opt_test_paths, embedder ); |
| embedder_proxy: EmbedderProxy) -> Option<Vec<String>> { | ||
| if opts::get().headless { | ||
| return None; | ||
| } |
There was a problem hiding this comment.
Can you let the embedder take the decision to return None when we run in headless mode?
There was a problem hiding this comment.
Guess so, will try for it.
| ui: &UI) | ||
| where UI: UIProvider, | ||
| { | ||
| fn get_selected_files(&self, |
There was a problem hiding this comment.
Neat: Maybe rename get_selected_files to query_files_from_embedder.
| [[test]] | ||
| name = "main" | ||
| path = "tests/main.rs" | ||
|
|
| use net_traits::blob_url_store::BlobBuf; | ||
|
|
||
| let context = new_fetch_context(None); | ||
| //let (sender, _receiver) = ipc::channel().unwrap(); |
| fn test_filemanager() { | ||
| let filemanager = FileManager::new(); | ||
| let filemanager = FileManager::new(create_embedder_proxy()); | ||
| PREFS.set("dom.testing.htmlinputelement.select_files.enabled", PrefValue::Boolean(true)); |
There was a problem hiding this comment.
I'm wondering why this was not necessary before?
There was a problem hiding this comment.
Previously there was mock UI provider in filemanager thread does inject test files instead (https://github.com/servo/servo/pull/20480/files#diff-5a65a0caa6da8aa6e23da0a4101c6a86L19) regardless of testing prefs. Now changed code path removes UI provider from thread and always asks to embedder message, so setting up test to mock fixture for file selection.
| pub enum FileManagerMsg { | ||
| /// Requesting to open file select dialog | ||
| OpenFileSelectDialog(Vec<FilterPattern>, bool, IpcSender<Option<Vec<String>>>) | ||
| } |
There was a problem hiding this comment.
I might have missed something, but is that message actually used somewhere?
There was a problem hiding this comment.
No, I guess it's my mistake leftover while refactoring. Thanks for catching.
| let msg = EmbedderMsg::SelectFiles(patterns, multiple_files, ipc_sender); | ||
|
|
||
| embedder_proxy.send(msg); | ||
| ipc_receiver.recv().unwrap() |
There was a problem hiding this comment.
Catch the error here:
match ipc_receiver.recv() {
Err(e) => warn!("Failed to receive files from emebdder ({}).", e),
...
}
62dd3dc to
2db008e
Compare
|
@bors-servo retry clean force |
|
@bors-servo r=paulrouget |
|
📌 Commit e98c4ff has been approved by |
refactor(net): removes direct ui invocation from filemgr thread <!-- Please describe your changes on the following line: --> - relates to #20428. This PR tries to refactor `net::filemanager_thread` implementation, removes direct ui-related code invocation but ask constellation. I believe overall organization might need to be refactored still as I took my own liberty to wire up dots and dots between components, which could be non-recommended practices. Probably point of review / need to be updated are 1. Communication between components Currently it's wired as like below: ``` +----------------+ +---------------+ +---------+ | | constellationMsg | | embedderMsg | | | filemgr_thread +------------------->+ constellation +------------->+ browser | | | | | | | +-----+----------+ +---------------+ +----+----+ ^ | +-------------------------------------------------------------------+ filelist: Vec(String) ``` - is this feasible approach? - does organization of message / fn (where to put consteallation / embedder msg & fns) are legit? 2. Removal of `filemanger_thread::UIProvider` - As filemanager_thread no longer need to aware actual ui, this PR removes `UIProvider` completely and let invoke tinyfiledialog directly in message listener. Maybe UIProvider itself still being needed? 3. Overall fn organization - To reduce duplicated code it takes single msg with boolean flag to distinguish selecting multiple files, may feasible / or better to create explicit paths between two. 4. Invoking tfd in a separate thread - This was mainly to align behavior to previous implentation, where tfd was invoked inside of filemanager_thread so does not block main. It may possibly just let block instead. and of course, a lot of other codes need to follow better practices. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #20428 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ - Manually verified file picker `<input type=files>` can pick up files. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20480) <!-- Reviewable:end -->
|
💔 Test failed - mac-rel-wpt4 |
|
@bors-servo retry
|
refactor(net): removes direct ui invocation from filemgr thread <!-- Please describe your changes on the following line: --> - relates to #20428. This PR tries to refactor `net::filemanager_thread` implementation, removes direct ui-related code invocation but ask constellation. I believe overall organization might need to be refactored still as I took my own liberty to wire up dots and dots between components, which could be non-recommended practices. Probably point of review / need to be updated are 1. Communication between components Currently it's wired as like below: ``` +----------------+ +---------------+ +---------+ | | constellationMsg | | embedderMsg | | | filemgr_thread +------------------->+ constellation +------------->+ browser | | | | | | | +-----+----------+ +---------------+ +----+----+ ^ | +-------------------------------------------------------------------+ filelist: Vec(String) ``` - is this feasible approach? - does organization of message / fn (where to put consteallation / embedder msg & fns) are legit? 2. Removal of `filemanger_thread::UIProvider` - As filemanager_thread no longer need to aware actual ui, this PR removes `UIProvider` completely and let invoke tinyfiledialog directly in message listener. Maybe UIProvider itself still being needed? 3. Overall fn organization - To reduce duplicated code it takes single msg with boolean flag to distinguish selecting multiple files, may feasible / or better to create explicit paths between two. 4. Invoking tfd in a separate thread - This was mainly to align behavior to previous implentation, where tfd was invoked inside of filemanager_thread so does not block main. It may possibly just let block instead. and of course, a lot of other codes need to follow better practices. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #20428 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ - Manually verified file picker `<input type=files>` can pick up files. <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20480) <!-- Reviewable:end -->
|
💔 Test failed - mac-rel-wpt3 |
|
☔ The latest upstream changes (presumably #20533) made this pull request unmergeable. Please resolve the merge conflicts. |
|
@bors-servo r=paulrouget |
|
📌 Commit d94def6 has been approved by |
|
☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev |
This PR tries to refactor
net::filemanager_threadimplementation, removes direct ui-related code invocation but ask constellation. I believe overall organization might need to be refactored still as I took my own liberty to wire up dots and dots between components, which could be non-recommended practices.Probably point of review / need to be updated are
Currently it's wired as like below:
filemanger_thread::UIProviderUIProvidercompletely and let invoke tinyfiledialog directly in message listener. Maybe UIProvider itself still being needed?and of course, a lot of other codes need to follow better practices.
./mach build -ddoes not report any errors./mach test-tidydoes not report any errors<input type=files>can pick up files.This change is