Bug 1807268 - Fix verifyOpenAllInNewTabsOptionTest UI test r=ohorvath
[gecko.git] / docshell / base / nsWebNavigationInfo.cpp
blobcb989a33f18819388ee1abab098e86b57a5d3c65
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 http://mozilla.org/MPL/2.0/. */
7 #include "nsWebNavigationInfo.h"
9 #include "nsServiceManagerUtils.h"
10 #include "nsIDocumentLoaderFactory.h"
11 #include "nsContentUtils.h"
12 #include "imgLoader.h"
14 NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
16 NS_IMETHODIMP
17 nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
18 uint32_t* aIsTypeSupported) {
19 MOZ_ASSERT(aIsTypeSupported, "null out param?");
21 *aIsTypeSupported = IsTypeSupported(aType);
22 return NS_OK;
25 uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType) {
26 // We want to claim that the type for PDF documents is unsupported,
27 // so that the internal PDF viewer's stream converted will get used.
28 if (aType.LowerCaseEqualsLiteral("application/pdf") &&
29 nsContentUtils::IsPDFJSEnabled()) {
30 return nsIWebNavigationInfo::UNSUPPORTED;
33 const nsCString& flatType = PromiseFlatCString(aType);
34 return IsTypeSupportedInternal(flatType);
37 uint32_t nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType) {
38 nsContentUtils::DocumentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
40 nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
41 nsContentUtils::FindInternalDocumentViewer(aType, &vtype);
43 switch (vtype) {
44 case nsContentUtils::TYPE_UNSUPPORTED:
45 return nsIWebNavigationInfo::UNSUPPORTED;
47 case nsContentUtils::TYPE_FALLBACK:
48 return nsIWebNavigationInfo::FALLBACK;
50 case nsContentUtils::TYPE_UNKNOWN:
51 return nsIWebNavigationInfo::OTHER;
53 case nsContentUtils::TYPE_CONTENT:
54 // XXXbz we only need this because images register for the same
55 // contractid as documents, so we can't tell them apart based on
56 // contractid.
57 if (imgLoader::SupportImageWithMimeType(aType)) {
58 return nsIWebNavigationInfo::IMAGE;
60 return nsIWebNavigationInfo::OTHER;
63 return nsIWebNavigationInfo::UNSUPPORTED;