8000 fix: webRequest module should work with file:// protocol by zcbenz · Pull Request #22903 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: webRequest module should work with file:// protocol #22903

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

Merged
merged 5 commits into from
Apr 1, 2020

Conversation

zcbenz
Copy link
Contributor
@zcbenz zcbenz commented Mar 31, 2020

Description of Change

Fix #22370.

When supporting asar archives in file:// URL, overwrite the default FileURLLoaderFactory directly instead of intercepting the protocol in ProxyingURLLoaderFactory. Otherwise webRequest won't be able to proxy the file:// requests.

This is actually the correct way to override file:// protocol, previous implementation was essentially a hack.

Checklist

Release Notes

Notes: Fix webRequest module not working with file:// protocol.

@zcbenz zcbenz requested a review from deepak1556 March 31, 2020 05:14
@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Mar 31, 2020
@zcbenz zcbenz force-pushed the webrequest-with-file-url branch 2 times, most recently from 40e7a52 to f3f572d Compare March 31, 2020 07:43
//
// Note that |insert| or |emplace| should not be used here, as they do nothing
// if the key already exists, while we would like to overwrite the factory.
(*factories)[url::kFileScheme] = std::make_unique<AsarURLLoaderFactory>();
Copy link
Member

Choose a reason for hiding this comment

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

When extension system is enabled, it also registers a factory for file:// https://github.com/electron/electron/blob/master/shell/browser/electron_browser_client.cc#L1281 , it seems to override this one for sub resources. Will that be okay ?

Copy link
Member
@deepak1556 deepak1556 Mar 31, 2020

Choose a reason for hiding this comment

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

Actually the problem is other way around, the extension system uses emplace to register, so it won't override our factory. But then question, its trying to register a file provider with stricter rules https://github.com/electron/electron/blob/master/shell/browser/electron_browser_client.cc#L1202 and that won't be available, is that okay ? Or can we accommodate that configuration here ?

This problem is unrelated to the changes in this PR, but want to see if we can solve it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The url factory installed by extension system is to support file:// under chrome-extension:// schemes, Chromium only installs file url factory for file:// and about:blank so it is fine for extension system to use emplace.

The problem is we are unconditionally installing asar url factory for all protocols, I have updated the code to only install it when needed.

@zcbenz zcbenz force-pushed the webrequest-with-file-url branch from f3f572d to 656a859 Compare April 1, 2020 01:47
Copy link
Member
@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

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

Thanks! the PR makes things much clear 👍

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Apr 1, 2020
@zcbenz zcbenz merged commit e6f2605 into master Apr 1, 2020
@release-clerk
Copy link
release-clerk bot commented Apr 1, 2020

Release Notes Persisted

Fix webRequest module not working with file:// protocol.

@zcbenz zcbenz deleted the webrequest-with-file-url branch April 1, 2020 07:38
@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

I was unable to backport this PR to "7-2-x" cleanly;
you will need to perform this backport manually.

@trop trop bot removed the target/7-2-x label Apr 1, 2020
@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

I was unable to backport this PR to "9-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

I was unable to backport this PR to "8-x-y" cleanly;
you will need to perform this backport manually.

@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

@zcbenz has manually backported this PR to "9-x-y", please check out #22919

@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

@zcbenz has manually backported this PR to "8-x-y", please check out #22920

@trop
Copy link
Contributor
trop bot commented Apr 1, 2020

@zcbenz has manually backported this PR to "7-2-x", please check out #22921

zcbenz added a commit that referenced this pull request Apr 1, 2020
* fix: override file:// instead of intercepting

* test: webRequest module should work with file://

* fix: service work with file:// url

* fix: original_response_headers can be null

* fix: only register file:// when necessary
sentialx pushed a commit to sentialx/electron that referenced this pull request Apr 7, 2020
)

* fix: override file:// instead of intercepting

* test: webRequest module should work with file://

* fix: service work with file:// url

* fix: original_response_headers can be null

* fix: only register file:// when necessary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webRequest API stopped working with file:// urls since 7.0.0 (and up to 9.0.0-beta.3 at least)
2 participants
0