Add delegation back to renderer process for certain webview resource reads#102442
Conversation
…eeds Fixes microsoft#102191 **Problem** Webviews used to load local resources in the renderer process. This gave them access to all of the file system providers registered for that renderer (such as `untitled` and `git`). However, last iteration we moved the webview protocol to the main process. This works fine for file resources, but the main process cannot read fancy uris such as `git:` or `untitled:` **Fix** To fix this, I've added code that delegates resource requests for non-file uris from the main process back to the renderer process. We tried to avoid this as it adds another round trip to each request, but I don't see a better way of doing this. This problem only effects desktop VS Code. Web VS Code uses a service worker which always reads resources through the renderer process
|
I do not like this change so please let me know if there is a better way to read uris such as |
|
I do not have a better solution right now. The window is currently still the exclusive owner of all file service registrations. This might change in the future when we enable sandbox and move file services into some backend, but this is not happening anytime soon. And even then, this backend is likely still a different process than the main process. I glanced at the changes but I am not an expert in that code, so I trust your implementation. |
|
Some more thoughts after gym:
I somehow feel that |
|
@bpasero Thanks for taking a look. I'm not sure I understand the point about |
|
I've merged this to get additional testing in insiders. We can continue iterating on finding a better solution to this |
|
@mjbvz can you please expand on how this is currently handled in the web with service workers, would like to understand the problem model first, custom protocol are limited in capabilities, we might have to explore other options. |
|
So on desktop, we now have this flow for loading On web, we instead have the following flow: It's the same number of hops in both cases, but the webview -> service worker communication should be pretty quick |
|
Thanks Matt! the web solution is certainly elegant. Apart from the hops, the web solution doesn't pressure the main process since service worker gets a direct communication channel with the renderer. In desktop even if we push the logic to a background window that can establish a channel to the webview window, the custom protocol must still be handled by the main process. Maybe we should really invest time getting service worker working for custom protocols. FWIW |
Yes your proposed URI is what I had in mind. As it stands,
So having a consistent URI scheme that forwards requests to the window owning these seems elegant. On the other hand, once sandbox for windows are enabled, the situation will likely look very different. It is possible that the window then is not the one to resolve these resources but some backend process that is privileged. Nevertheless, my point was that |
Fixes #102191
Problem
Webviews used to load local resources in the renderer process. This gave them access to all of the file system providers registered for that renderer (such as
untitledandgit).However, last iteration we moved the webview protocol to the main process. This works fine for file resources, but the main process cannot read fancy uris such as
git:oruntitled:Fix
To fix this, I've added code that delegates resource requests for non-file uris from the main process back to the renderer process. We tried to avoid this as it adds another round trip to each request, but I don't see a better way of doing this.
This problem only effects desktop VS Code. Web VS Code uses a service worker which always reads resources through the renderer process