Skip to content

Conversation

@codebytere
Copy link
Member

@codebytere codebytere commented Feb 22, 2024

Description of Change

Closes #28422.

Implements support for the File System API, with permissions brokered through session.setPermissionRequestHandler. When file or directory functions require permissions, setPermissionRequestHandler will be called with details.

Example:

const [fileHandle] = await window.showOpenFilePicker();
const writable = await fileHandle.createWritable();

session.defaultSession.setPermissionRequestHandler((webContents, permission, callback, details) => {
      console.log(permission) // 'fileSystem'
      console.log(details) 
      /*
      {
          accessType: 'writable',
          isDirectory: false,
          isMainFrame: true,
          path: '/path/to/my/file',
          requestingUrl: 'some_url.html'
        }
      */
      callback(true);
    }
);

In the above example, if callback is called with true, the following would be logged to console:

FileSystemWritableFileStream {mode: 'siloed', locked: false}

otherwise, the following error would be logged:

NotAllowedError: The request is not allowed by the user agent or the platform in the current context.

Checklist

Release Notes

Notes: Implemented support for the File System API.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Feb 22, 2024
@codebytere codebytere force-pushed the native-filesystem-permissions branch 3 times, most recently from 87057d5 to eef9839 Compare February 23, 2024 13:55
@codebytere codebytere added the semver/minor backwards-compatible functionality label Feb 23, 2024
@codebytere codebytere marked this pull request as ready for review February 23, 2024 13:56
@RangerMauve
Copy link

The general API looks great. TY for taking this on. 🙇

Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

Thinking about how to do the details object better

Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

There seems to be some other discussion about the API itself, so I've avoided that for this review and just focused on some more basic C++ code review

@codebytere codebytere force-pushed the native-filesystem-permissions branch 2 times, most recently from a88b1b9 to 2dd2753 Compare February 29, 2024 11:46
Copy link
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

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

More C++ review

@ckerr
Copy link
Member

ckerr commented Feb 29, 2024

@codebytere ooooh I see now a lot of this is copied from upstream. Matching the upstream impl is a higher priority than some of my C++ suggestions; feel free to mark as resolved any suggestions that would cause code shear compared to the upstream code!!

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened recently label Mar 1, 2024
@codebytere codebytere force-pushed the native-filesystem-permissions branch 2 times, most recently from 99b4a36 to 5165697 Compare March 4, 2024 13:23
@codebytere codebytere force-pushed the native-filesystem-permissions branch from 5165697 to 1c41cb9 Compare March 18, 2024 19:45
@codebytere codebytere force-pushed the native-filesystem-permissions branch from 1c41cb9 to 21ec92d Compare March 18, 2024 22:52
@codebytere codebytere added the target/30-x-y PR should also be added to the "30-x-y" branch. label Mar 25, 2024
@codebytere codebytere requested a review from a team March 25, 2024 11:43
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

Docs / types seem good. Question about drift from upstream and the block list

@codebytere codebytere force-pushed the native-filesystem-permissions branch 2 times, most recently from d9e1c1c to 0338431 Compare March 26, 2024 11:26
@codebytere codebytere requested a review from a team as a code owner March 27, 2024 09:49
@codebytere codebytere force-pushed the native-filesystem-permissions branch from 81ab428 to 511b705 Compare March 28, 2024 10:51
@codebytere codebytere force-pushed the native-filesystem-permissions branch from 31ab84c to adbbfaa Compare April 10, 2024 08:03
Copy link
Member

@jkleinsc jkleinsc left a comment

Choose a reason for hiding this comment

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

API LGTM

@codebytere codebytere requested a review from ckerr April 10, 2024 15:19
@codebytere codebytere force-pushed the native-filesystem-permissions branch from 3fa54d1 to 28db4db Compare April 10, 2024 17:22
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

API LGTM

@codebytere codebytere merged commit 344aba0 into main Apr 10, 2024
@codebytere codebytere deleted the native-filesystem-permissions branch April 10, 2024 20:06
@release-clerk
Copy link

release-clerk bot commented Apr 10, 2024

Release Notes Persisted

Implemented support for the File System API.

@trop
Copy link
Contributor

trop bot commented Apr 10, 2024

I have automatically backported this PR to "30-x-y", please check out #41827

@trop trop bot added in-flight/30-x-y merged/30-x-y PR was merged to the "30-x-y" branch. and removed target/30-x-y PR should also be added to the "30-x-y" branch. in-flight/30-x-y labels Apr 10, 2024
@erickzhao erickzhao added the needs-docs An API or larger change that needs expanded documentation label Jul 29, 2024
BlackHole1 added a commit to BlackHole1/electron that referenced this pull request Aug 6, 2025
Chromium implemented the ability to copy files to the clipboard and read file paths from the clipboard in 2021. See: https://chromium-review.googlesource.com/c/chromium/src/+/2651770.
In electron#41419, @codebytere has already implemented a partial API (WriteFilesForTesting).
In the current PR, I renamed the previous `WriteFilesForTesting` to `WriteFiles` and added a `ReadFiles` method to match it.
Additionally, I improved the Write method, and now `clipboard.write` also supports the `files` parameter.

Signed-off-by: Kevin Cui <[email protected]>
BlackHole1 added a commit to BlackHole1/electron that referenced this pull request Aug 6, 2025
Chromium implemented the ability to copy files to the clipboard and read file paths from the clipboard in 2021. See: https://chromium-review.googlesource.com/c/chromium/src/+/2651770.
In electron#41419, @codebytere has already implemented a partial API (WriteFilesForTesting).
In the current PR, I renamed the previous `WriteFilesForTesting` to `WriteFiles` and added a `ReadFiles` method to match it.
Additionally, I improved the Write method, and now `clipboard.write` also supports the `files` parameter.

fix: electron#9035 electron#26377

Signed-off-by: Kevin Cui <[email protected]>
BlackHole1 added a commit to BlackHole1/electron that referenced this pull request Aug 6, 2025
Chromium implemented the ability to copy files to the clipboard and read file paths from the clipboard in 2021. See: https://chromium-review.googlesource.com/c/chromium/src/+/2651770.
In electron#41419, @codebytere has already implemented a partial API (WriteFilesForTesting).
In the current PR, I renamed the previous `WriteFilesForTesting` to `WriteFiles` and added a `ReadFiles` method to match it.
Additionally, I improved the Write method, and now `clipboard.write` also supports the `files` parameter.

fix: electron#9035 electron#26377

Signed-off-by: Kevin Cui <[email protected]>
BlackHole1 added a commit to BlackHole1/electron that referenced this pull request Aug 6, 2025
Chromium implemented the ability to copy files to the clipboard and read file paths from the clipboard in 2021. See: https://chromium-review.googlesource.com/c/chromium/src/+/2651770.
In electron#41419, @codebytere has already implemented a partial API (WriteFilesForTesting).
In the current PR, I renamed the previous `WriteFilesForTesting` to `WriteFiles` and added a `ReadFiles` method to match it.
Additionally, I improved the Write method, and now `clipboard.write` also supports the `files` parameter.

fix: electron#9035 electron#26377

Signed-off-by: Kevin Cui <[email protected]>
BlackHole1 added a commit to BlackHole1/electron that referenced this pull request Aug 6, 2025
Chromium implemented the ability to copy files to the clipboard and read file paths from the clipboard in 2021. See: https://chromium-review.googlesource.com/c/chromium/src/+/2651770.
In electron#41419, @codebytere has already implemented a partial API (WriteFilesForTesting).
In the current PR, I renamed the previous `WriteFilesForTesting` to `WriteFiles` and added a `ReadFiles` method to match it.
Additionally, I improved the Write method, and now `clipboard.write` also supports the `files` parameter.

fix: electron#9035 electron#26377

Signed-off-by: Kevin Cui <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ merged/30-x-y PR was merged to the "30-x-y" branch. needs-docs An API or larger change that needs expanded documentation semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing permissions dialog for FileSystem API.

8 participants