Skip to content

Commit aafc24c

Browse files
API Review: CustomDefaultDownloadLocation.md (#1977)
* Add spec for CustomDefaultDownloadLocation.md (#1947) * Revert "switch design to corner enum + offset" This reverts commit 4520cc7. * API Review: DefaultDownloadDialog.md (#1770) * (Draft) API Review: DefaultDownloadDialog.md * switch to enum + offset design * change method to two properties and offset to padding * add event for IsDefaultDownloadDialogOpenChanged * use point for margin and renaming Co-authored-by: Viktoria Zlatinova <vizlatin@microsoft.com> * API review updates * use ShowDownloadsToggleButton * Api review: Custom default download location (draft) * update docs * update docs * Update specs/CustomDefaultDownloadLocation.md Co-authored-by: David Risney <dave@deletethis.net> * indent and move block to end * update docs Co-authored-by: Viktoria Zlatinova <vizlatin@microsoft.com> Co-authored-by: David Risney <dave@deletethis.net> * rename and document timing * update docs on how user can override path * delete old spec copy * matching sample code Co-authored-by: Viktoria Zlatinova <vizlatin@microsoft.com> Co-authored-by: David Risney <dave@deletethis.net>
1 parent a56f59d commit aafc24c

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Custom Default Download Location
2+
===
3+
4+
# Background
5+
This API allows you to set a custom default download location per profile. The
6+
user can still change the path through the Save As dialog.
7+
8+
In this document we describe the updated API. We'd appreciate your feedback.
9+
10+
# Examples
11+
```cpp
12+
HRESULT AppWindow::OnCreateCoreWebView2ControllerCompleted(
13+
HRESULT result, ICoreWebView2Controller* controller)
14+
{
15+
if (result == S_OK)
16+
{
17+
if (!m_webviewOption.downloadPath.empty())
18+
{
19+
Microsoft::WRL::ComPtr<ICoreWebView2Profile2> profile2;
20+
CHECK_FAILURE(m_profile->QueryInterface(IID_PPV_ARGS(
21+
&profile2)));
22+
CHECK_FAILURE(profile2->put_DefaultDownloadFolderPath(
23+
m_webviewOption.downloadPath.c_str()));
24+
}
25+
}
26+
}
27+
```
28+
```c#
29+
void WebView_CoreWebView2InitializationCompleted(object sender,
30+
CoreWebView2InitializationCompletedEventArgs e)
31+
{
32+
if (e.IsSuccess)
33+
{
34+
if (!string.IsNullOrEmpty(_downloadPath))
35+
{
36+
WebViewProfile.DefaultDownloadFolderPath = _downloadPath;
37+
}
38+
}
39+
}
40+
```
41+
# API Details
42+
```c#
43+
/// This is a continuation of the `ICoreWebView2Profile` interface.
44+
[uuid(DAF8B1F9-276D-410C-B481-58CBADF85C9C), object, pointer_default(unique)]
45+
interface ICoreWebView2Profile2 : ICoreWebView2Profile {
46+
/// Gets the `DefaultDownloadFolderPath` property. The default value is the
47+
/// system default download folder path for the user.
48+
[propget] HRESULT DefaultDownloadFolderPath([out, retval] LPWSTR* value);
49+
50+
/// Sets the `DefaultDownloadFolderPath` property. The default download folder
51+
/// path is persisted in the user data folder across sessions. The value
52+
/// should be an absolute path to a folder that the user and application can
53+
/// write to. Returns `E_INVALIDARG` if the value is invalid, and the default
54+
/// download folder path is not changed. Otherwise the path is changed
55+
/// immediately. If the directory does not yet exist, it is created at the
56+
/// time of the next download. If the host application does not have
57+
/// permission to create the directory, then the user is prompted to provide a
58+
/// new path through the Save As dialog. The user can override the default
59+
/// download folder path for a given download by choosing a different path in
60+
/// the Save As dialog.
61+
[propput] HRESULT DefaultDownloadFolderPath([in] LPCWSTR value);
62+
}
63+
```
64+
```c#
65+
namespace Microsoft.Web.WebView2.Core
66+
{
67+
runtimeclass CoreWebView2Profile
68+
{
69+
// The following properties already exist.
70+
// String ProfileName { get; };
71+
// Boolean IsInPrivateModeEnabled { get; };
72+
// String ProfilePath { get; };
73+
74+
// The following method already exists.
75+
// Windows.Foundation.IAsyncOperation<Boolean> ClearBrowsingDataAsync(
76+
// UInt64 dataKinds, Double startTime, Double endTime);
77+
78+
[interface_name("Microsoft.Web.WebView2.Core.ICoreWebView2Profile2")]
79+
{
80+
String DefaultDownloadFolderPath { get; set; };
81+
}
82+
}
83+
}
84+
```

0 commit comments

Comments
 (0)