diff options
author | Oliver Wolff <[email protected]> | 2018-01-10 10:16:56 +0100 |
---|---|---|
committer | Oliver Wolff <[email protected]> | 2018-01-10 13:38:46 +0000 |
commit | 4fab9eb042fc3c3728d926f6b10620d1895cb9dd (patch) | |
tree | 97bd5257e8742d1265b3fbd12dec6d9d4eecba56 | |
parent | 75dfd208e0f5797cdb562a8e733790292b52a56e (diff) |
winrt: Handle setting of URL with unsupported scheme
While the webview handles clicks on links with unsupported schemes (like
mailto or sms) internally and opens the default program/asks the user
what to do, calling the url directly resulted in an assert.
We try to mimic the webview's behavior as closely as possible by
launching the default program for the given URI. If no default program
is set, the user is asked, what to do.
Change-Id: I4b5220f3de76ebecb50643110944056a60c3b3b6
Reviewed-by: Maurice Kalinowski <[email protected]>
-rw-r--r-- | src/webview/qwebview_winrt.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/webview/qwebview_winrt.cpp b/src/webview/qwebview_winrt.cpp index 64150ed..d6ec493 100644 --- a/src/webview/qwebview_winrt.cpp +++ b/src/webview/qwebview_winrt.cpp @@ -49,6 +49,7 @@ #include <wrl.h> #include <windows.graphics.display.h> +#include <windows.system.h> #include <windows.ui.xaml.h> #include <windows.ui.xaml.controls.h> #include <windows.ui.xaml.markup.h> @@ -59,6 +60,7 @@ using namespace Microsoft::WRL::Wrappers; using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Foundation::Collections; using namespace ABI::Windows::Graphics::Display; +using namespace ABI::Windows::System; using namespace ABI::Windows::UI; using namespace ABI::Windows::UI::Xaml; using namespace ABI::Windows::UI::Xaml::Controls; @@ -275,6 +277,7 @@ struct WinRTWebView ComPtr<ICanvasStatics> canvas; ComPtr<IUriRuntimeClassFactory> uriFactory; ComPtr<IDisplayInformation> displayInformation; + ComPtr<ILauncherStatics> launcherStatics; QPointer<QWindow> window; QHash<IAsyncOperation<HSTRING> *, int> callbacks; @@ -310,6 +313,9 @@ QWinRTWebViewPrivate::QWinRTWebViewPrivate(QObject *parent) Q_ASSERT_SUCCEEDED(hr); hr = d->base.As(&d->ext); Q_ASSERT_SUCCEEDED(hr); + hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_System_Launcher).Get(), + IID_PPV_ARGS(&d->launcherStatics)); + Q_ASSERT_SUCCEEDED(hr); hr = d->ext->add_NavigationStarting( Callback<ITypedEventHandler<WebView *, WebViewNavigationStartingEventArgs *>>(this, &QWinRTWebViewPrivate::onNavigationStarted).Get(), @@ -383,6 +389,11 @@ void QWinRTWebViewPrivate::setUrl(const QUrl &url) hr = d->uriFactory->CreateUri(uriString.Get(), &uri); Q_ASSERT_SUCCEEDED(hr); hr = d->base->Navigate(uri.Get()); + // Directly running into an abort means, that the URI is not supported. Ask the user what to do + if (hr == E_ABORT) { + ComPtr<IAsyncOperation<bool>> op; + hr = d->launcherStatics->LaunchUriAsync(uri.Get(), &op); + } Q_ASSERT_SUCCEEDED(hr); return hr; }); |