Skip to content

Commit 5d60c08

Browse files
author
Maura Winstanley
committed
Update .net sample
1 parent 73f3d73 commit 5d60c08

File tree

1 file changed

+66
-67
lines changed

1 file changed

+66
-67
lines changed

specs/LaunchingExternalUriScheme.md

Lines changed: 66 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -131,77 +131,76 @@ void RegisterLaunchingExternalUriSchemeHandler()
131131
private WebView2 webView;
132132
void RegisterLaunchingExternalUriSchemeHandler()
133133
{
134-
webView.CoreWebView2.LaunchingExternalUriScheme += (sender, args) {
135-
{
136-
// A deferral may be taken for the event so that the CoreWebView2
137-
// doesn't examine the properties we set on the event args until
138-
// after we call the Complete method asynchronously later.
139-
// This will give the user more time to decide whether to launch
140-
// the external URI scheme or not.
141-
// CoreWebView2Deferral deferral = args.GetDeferral();
142-
// System.Threading.SynchronizationContext.Current.Post((_) =>
143-
// {
144-
// using (deferral)
145-
// {
146-
if (String.Equals(args.Uri, "calculator:///", StringComparison.OrdinalIgnoreCase))
134+
webView.CoreWebView2.LaunchingExternalUriScheme += (sender, args)
135+
{
136+
// A deferral may be taken for the event so that the CoreWebView2
137+
// doesn't examine the properties we set on the event args until
138+
// after we call the Complete method asynchronously later.
139+
// This will give the user more time to decide whether to launch
140+
// the external URI scheme or not.
141+
// CoreWebView2Deferral deferral = args.GetDeferral();
142+
// System.Threading.SynchronizationContext.Current.Post((_) =>
143+
// {
144+
// using (deferral)
145+
// {
146+
if (String.Equals(args.Uri, "calculator:///", StringComparison.OrdinalIgnoreCase))
147+
{
148+
// Set the event args to cancel the event and launch the
149+
// calculator app. This will always allow the external URI scheme launch.
150+
args.Cancel = true;
151+
ProcessStartInfo info = new ProcessStartInfo
147152
{
148-
// Set the event args to cancel the event and launch the
149-
// calculator app. This will always allow the external URI scheme launch.
150-
args.Cancel = true;
151-
ProcessStartInfo info = new ProcessStartInfo
152-
{
153-
FileName = args.Uri,
154-
UseShellExecute = true
155-
};
156-
Process.Start(info);
157-
}
158-
else if (String.Equals(args.Uri, "malicious:///", StringComparison.OrdinalIgnoreCase)) {
159-
// Always block the request in this case by cancelling the event.
160-
args.Cancel = true;
161-
}
162-
else if (String.Equals(args.Uri, "contoso:///", StringComparison.OrdinalIgnoreCase))
153+
FileName = args.Uri,
154+
UseShellExecute = true
155+
};
156+
Process.Start(info);
157+
}
158+
else if (String.Equals(args.Uri, "malicious:///", StringComparison.OrdinalIgnoreCase)) {
159+
// Always block the request in this case by cancelling the event.
160+
args.Cancel = true;
161+
}
162+
else if (String.Equals(args.Uri, "contoso:///", StringComparison.OrdinalIgnoreCase))
163+
{
164+
// To display a custom dialog we cancel the launch, display
165+
// a custom dialog, and then manually launch the external URI scheme
166+
// depending on the user's selection.
167+
args.Cancel = true;
168+
string text = "Launching External URI Scheme";
169+
if (args.InitiatingOrigin != "")
163170
{
164-
// To display a custom dialog we cancel the launch, display
165-
// a custom dialog, and then manually launch the external URI scheme
166-
// depending on the user's selection.
167-
args.Cancel = true;
168-
string text = "Launching External URI Scheme";
169-
if (args.InitiatingOrigin != "")
170-
{
171-
text += "from ";
172-
text += args.InitiatingOrigin;
173-
}
174-
text += " to ";
175-
text += args.Uri;
176-
text += "\n";
177-
text += "Do you want to grant permission?";
178-
string caption = "Launching External URI Scheme request";
179-
MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
180-
MessageBoxImage icnMessageBox = MessageBoxImage.None;
181-
MessageBoxResult resultbox = MessageBox.Show(text, caption, btnMessageBox, icnMessageBox);
182-
switch (resultbox)
183-
{
184-
case MessageBoxResult.Yes:
185-
ProcessStartInfo info = new ProcessStartInfo
186-
{
187-
FileName = args.Uri,
188-
UseShellExecute = true
189-
};
190-
Process.Start(info);
191-
break;
192-
193-
case MessageBoxResult.No:
194-
break;
195-
}
196-
197-
}
198-
else
171+
text += "from ";
172+
text += args.InitiatingOrigin;
173+
}
174+
text += " to ";
175+
text += args.Uri;
176+
text += "\n";
177+
text += "Do you want to grant permission?";
178+
string caption = "Launching External URI Scheme request";
179+
MessageBoxButton btnMessageBox = MessageBoxButton.YesNo;
180+
MessageBoxImage icnMessageBox = MessageBoxImage.None;
181+
MessageBoxResult resultbox = MessageBox.Show(text, caption, btnMessageBox, icnMessageBox);
182+
switch (resultbox)
199183
{
200-
// Do not cancel the event, allowing the request to use the default dialog.
184+
case MessageBoxResult.Yes:
185+
ProcessStartInfo info = new ProcessStartInfo
186+
{
187+
FileName = args.Uri,
188+
UseShellExecute = true
189+
};
190+
Process.Start(info);
191+
break;
192+
193+
case MessageBoxResult.No:
194+
break;
201195
}
202-
// }
203-
// }, null);
204-
}
196+
197+
}
198+
else
199+
{
200+
// Do not cancel the event, allowing the request to use the default dialog.
201+
}
202+
// }
203+
// }, null);
205204
};
206205
}
207206

0 commit comments

Comments
 (0)