forked from cefsharp/CefSharp.OutOfProcess
-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/file dialog handler #1
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
Open
yy-2020
wants to merge
5
commits into
master
Choose a base branch
from
feat/fileDialogHandler
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
CefSharp.OutOfProcess.BrowserProcess/CallbackProxies/CallbackProxyBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using CefSharp.OutOfProcess.Interface; | ||
|
|
||
| namespace CefSharp.OutOfProcess.BrowserProcess.CallbackProxies | ||
| { | ||
| internal class CallbackProxyBase<T> : IDisposable | ||
| { | ||
| private int id = 0; | ||
| private readonly Dictionary<int, T> callbacks = new Dictionary<int, T>(); | ||
| private protected readonly IOutOfProcessHostRpc host; | ||
|
|
||
| public CallbackProxyBase(IOutOfProcessHostRpc host) | ||
| { | ||
| this.host = host ?? throw new ArgumentNullException(nameof(host)); | ||
| } | ||
|
|
||
| protected int CreateCallback(T callback) | ||
| { | ||
| int lid = id++; | ||
| callbacks.Add(lid, callback); | ||
| return lid; | ||
| } | ||
|
|
||
| protected T GetCallback(int id) | ||
| { | ||
| T cb = callbacks[id]; | ||
| callbacks.Remove(id); | ||
| return cb; | ||
| } | ||
|
|
||
| public void Dispose() | ||
| { | ||
| foreach (var cbs in callbacks) | ||
| { | ||
| if (cbs.Value is IDisposable d) | ||
| { | ||
| d.Dispose(); | ||
| } | ||
| } | ||
|
|
||
| callbacks.Clear(); | ||
| } | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
CefSharp.OutOfProcess.BrowserProcess/CallbackProxies/DialogHandlerProxy.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| using System.Collections.Generic; | ||
| using CefSharp.OutOfProcess.Interface; | ||
| using CefSharp.Handler; | ||
| using System.Linq; | ||
| using CefSharp.OutOfProcess.Interface.Callbacks; | ||
| using System; | ||
|
|
||
| namespace CefSharp.OutOfProcess.BrowserProcess.CallbackProxies | ||
| { | ||
|
|
||
| internal sealed class DialogHandlerProxy : CallbackProxyBase<IFileDialogCallback>, IDialogHandler | ||
| { | ||
| public DialogHandlerProxy(IOutOfProcessHostRpc host) | ||
| : base(host) | ||
| { | ||
|
|
||
| } | ||
|
|
||
| public void Callback(FileDialogCallbackDetails details) | ||
| { | ||
| if (details == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(details)); | ||
| } | ||
|
|
||
| if (details.Files == null) | ||
| { | ||
| throw new ArgumentNullException(nameof(details.Files)); | ||
| } | ||
|
|
||
| var cb = GetCallback(details.CallbackId); | ||
|
|
||
| if (details.Continue) | ||
| { | ||
| cb.Continue(details.Files.ToList()); | ||
| } | ||
| else | ||
| { | ||
| cb.Cancel(); | ||
| } | ||
| } | ||
|
|
||
| bool IDialogHandler.OnFileDialog(IWebBrowser chromiumWebBrowser, IBrowser browser, CefFileDialogMode mode, string title, string defaultFilePath, List<string> acceptFilters, IFileDialogCallback callback) | ||
| { | ||
| var result = host.OnFileDialog(((OutOfProcessChromiumWebBrowser)chromiumWebBrowser).Id, mode.ToString(), title, defaultFilePath, acceptFilters.ToArray(), CreateCallback(callback)); | ||
| return result.Result; | ||
| } | ||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
CefSharp.OutOfProcess.Core/CallbackProxies/CallbackProxyBase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| namespace CefSharp.OutOfProcess | ||
| { | ||
| using System; | ||
| using CefSharp.OutOfProcess.Internal; | ||
|
|
||
| internal class CallbackProxyBase : IDisposable | ||
| { | ||
| private protected readonly OutOfProcessHost outOfProcessHost; | ||
| private protected readonly int callback; | ||
| private protected readonly IChromiumWebBrowserInternal chromiumWebBrowser; | ||
| private bool disposedValue; | ||
|
|
||
| public CallbackProxyBase(OutOfProcessHost outOfProcessHost, int callback, IChromiumWebBrowserInternal chromiumWebBrowser) | ||
| { | ||
| this.chromiumWebBrowser = chromiumWebBrowser; | ||
| this.outOfProcessHost = outOfProcessHost; | ||
| this.callback = callback; | ||
| } | ||
|
|
||
| public bool IsDisposed => disposedValue; | ||
|
|
||
| protected virtual void Dispose(bool disposing) | ||
| { | ||
| if (!disposedValue) | ||
| { | ||
| if (disposing) | ||
| { | ||
| } | ||
|
|
||
| disposedValue = true; | ||
| } | ||
| } | ||
|
|
||
| void IDisposable.Dispose() | ||
| { | ||
| Dispose(disposing: true); | ||
| GC.SuppressFinalize(this); | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
CefSharp.OutOfProcess.Core/CallbackProxies/FileDialogCallbackProxy.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| namespace CefSharp.OutOfProcess | ||
| { | ||
| using System.Collections.Generic; | ||
| using CefSharp.OutOfProcess.Interface.Callbacks; | ||
| using CefSharp.OutOfProcess.Internal; | ||
|
|
||
| internal sealed class FileDialogCallbackProxy : CallbackProxyBase, IFileDialogCallback | ||
| { | ||
| public FileDialogCallbackProxy(OutOfProcessHost outOfProcessHost, int callback, IChromiumWebBrowserInternal chromiumWebBrowser) | ||
| : base(outOfProcessHost, callback, chromiumWebBrowser) | ||
| { | ||
| } | ||
|
|
||
| public void Cancel() | ||
| { | ||
| outOfProcessHost.InvokeFileDialogCallback(new FileDialogCallbackDetails() | ||
| { | ||
| CallbackId = callback, | ||
| BrowserId = chromiumWebBrowser.Id, | ||
| Continue = false, | ||
| }); | ||
| } | ||
|
|
||
| public void Continue(List<string> filePaths) | ||
| { | ||
| outOfProcessHost.InvokeFileDialogCallback(new FileDialogCallbackDetails() | ||
| { | ||
| CallbackId = callback, | ||
| BrowserId = chromiumWebBrowser.Id, | ||
| Continue = true, | ||
| Files = filePaths.ToArray(), | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| <PackageReference Include="PInvoke.User32" Version="0.7.104" /> | ||
| <PackageReference Include="StreamJsonRpc" Version="2.11.35" /> | ||
| <ProjectReference Include="..\CefSharp.OutOfProcess.Interface\CefSharp.OutOfProcess.Interface.csproj" /> | ||
|
|
||
| <ProjectReference Include="..\CefSharp.Dom\lib\PuppeteerSharp\CefSharp.Dom.OutOfProcess.csproj" /> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing line :) |
||
| </ItemGroup> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| namespace CefSharp.OutOfProcess.Handler | ||
| { | ||
| using System.Collections.Generic; | ||
| using CefSharp.OutOfProcess.Interface.Callbacks; | ||
|
|
||
| public interface IDialogHandler | ||
| { | ||
| // | ||
| // Summary: | ||
| // Runs a file chooser dialog. | ||
| // | ||
| // Parameters: | ||
| // chromiumWebBrowser: | ||
| // the ChromiumWebBrowser control | ||
| // | ||
| // browser: | ||
| // the browser object | ||
| // | ||
| // mode: | ||
| // represents the type of dialog to display | ||
| // | ||
| // title: | ||
| // the title to be used for the dialog. It may be empty to show the default title | ||
| // ("Open" or "Save" depending on the mode). | ||
| // | ||
| // defaultFilePath: | ||
| // is the path with optional directory and/or file name component that should be | ||
| // initially selected in the dialog. | ||
| // | ||
| // acceptFilters: | ||
| // are used to restrict the selectable file types and may any combination of (a) | ||
| // valid lower-cased MIME types (e.g. "text/*" or "image/*"), (b) individual file | ||
| // extensions (e.g. ".txt" or ".png"), (c) combined description and file extension | ||
| // delimited using "|" and ";" (e.g. "Image Types|.png;.gif;.jpg"). | ||
| // | ||
| // callback: | ||
| // Callback interface for asynchronous continuation of file dialog requests. | ||
| // | ||
| // Returns: | ||
| // To display a custom dialog return true. To display the default dialog return | ||
| // false. | ||
| bool OnFileDialog(IChromiumWebBrowser chromiumWebBrowser, string mode, string title, string defaultFilePath, IEnumerable<string> acceptFilters, IFileDialogCallback callback); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace CefSharp.OutOfProcess.Interface.Callbacks | ||
| { | ||
| public class CallbackDetails | ||
| { | ||
| public int BrowserId { get; set; } | ||
|
|
||
| public int CallbackId { get; set; } | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
CefSharp.OutOfProcess.Interface/Callbacks/FileDialogCallbackDetails.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| namespace CefSharp.OutOfProcess.Interface.Callbacks | ||
| { | ||
| public class FileDialogCallbackDetails : CallbackDetails | ||
| { | ||
| public string[] Files { get; set; } | ||
|
|
||
| public bool Continue { get; set; } | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
CefSharp.OutOfProcess.Interface/Callbacks/IFileDialogCallback.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| namespace CefSharp.OutOfProcess.Interface.Callbacks | ||
| { | ||
| using System.Collections.Generic; | ||
|
|
||
| public interface IFileDialogCallback | ||
| { | ||
| bool IsDisposed { get; } | ||
| void Cancel(); | ||
| void Continue(List<string> filePaths); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.