1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_UrlmonHeaderOnlyUtils_h
8 #define mozilla_UrlmonHeaderOnlyUtils_h
10 #include "mozilla/ShellHeaderOnlyUtils.h"
15 * We used to validate a uri with SHParseDisplayName to mitigate the Windows
16 * bug (Bug 394974). However, Bug 1573051 revealed an issue that a fragment,
17 * a string following a hash mark (#), is dropped when we extract a string
18 * from PIDL. This is the intended behavior of Windows.
20 * To deal with the fragment issue as well as keeping our mitigation, we
21 * decided to use CreateUri to validate a uri string, but we also keep using
22 * SHParseDisplayName as a pre-check. This is because there are several
23 * cases where CreateUri succeeds while SHParseDisplayName fails such as
24 * a non-existent file: uri.
26 * To minimize the impact of introducing CreateUri into the validation logic,
27 * we try to mimic the logic of windows_storage!IUriToPidl (ieframe!IUriToPidl
28 * in Win7) which is executed behind SHParseDisplayName.
29 * What IUriToPidl does is:
30 * 1) If a given uri has a fragment, removes a fragment.
31 * 2) Takes an absolute uri if it's available in the given uri, otherwise
34 * As we need to get a full uri including a fragment, this function does 2).
36 inline LauncherResult
<_bstr_t
> UrlmonValidateUri(const wchar_t* aUri
) {
37 LauncherResult
<UniqueAbsolutePidl
> pidlResult
= ShellParseDisplayName(aUri
);
38 if (pidlResult
.isErr()) {
39 return pidlResult
.propagateErr();
42 // The value of |flags| is the same value as used in ieframe!_EnsureIUri in
43 // Win7, which is called behind SHParseDisplayName. In Win10, on the other
44 // hand, an flag 0x03000000 is also passed to CreateUri, but we don't
45 // specify it because it's undocumented and unknown.
46 constexpr DWORD flags
=
47 Uri_CREATE_NO_DECODE_EXTRA_INFO
| Uri_CREATE_CANONICALIZE
|
48 Uri_CREATE_CRACK_UNKNOWN_SCHEMES
| Uri_CREATE_PRE_PROCESS_HTML_URI
|
49 Uri_CREATE_IE_SETTINGS
;
52 SAFECALL_URLMON_FUNC(CreateUri
, aUri
, flags
, 0, getter_AddRefs(uri
));
54 return LAUNCHER_ERROR_FROM_HRESULT(hr
);
59 hr
= uri
->GetAbsoluteUri(bstrUri
.GetAddress());
61 return LAUNCHER_ERROR_FROM_HRESULT(hr
);
65 hr
= uri
->GetRawUri(bstrUri
.GetAddress());
67 return LAUNCHER_ERROR_FROM_HRESULT(hr
);
74 } // namespace mozilla
76 #endif // mozilla_UrlmonHeaderOnlyUtils_h