1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsWebNavigationInfo.h"
7 #include "nsIWebNavigation.h"
8 #include "nsServiceManagerUtils.h"
9 #include "nsIDocumentLoaderFactory.h"
10 #include "nsIPluginHost.h"
11 #include "nsIDocShell.h"
12 #include "nsContentUtils.h"
13 #include "imgLoader.h"
15 NS_IMPL_ISUPPORTS(nsWebNavigationInfo
, nsIWebNavigationInfo
)
17 #define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1"
18 #define PLUGIN_DLF_CONTRACT \
19 "@mozilla.org/content/plugin/document-loader-factory;1"
22 nsWebNavigationInfo::Init()
25 mCategoryManager
= do_GetService(NS_CATEGORYMANAGER_CONTRACTID
, &rv
);
26 NS_ENSURE_SUCCESS(rv
, rv
);
32 nsWebNavigationInfo::IsTypeSupported(const nsACString
& aType
,
33 nsIWebNavigation
* aWebNav
,
34 uint32_t* aIsTypeSupported
)
36 NS_PRECONDITION(aIsTypeSupported
, "null out param?");
38 // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
39 // an nsSHistory, but not much we can do with that). So if we start using
40 // it here, we need to be careful to get to the docshell correctly.
42 // For now just report what the Gecko-Content-Viewers category has
44 *aIsTypeSupported
= nsIWebNavigationInfo::UNSUPPORTED
;
46 const nsCString
& flatType
= PromiseFlatCString(aType
);
47 nsresult rv
= IsTypeSupportedInternal(flatType
, aIsTypeSupported
);
48 NS_ENSURE_SUCCESS(rv
, rv
);
50 if (*aIsTypeSupported
) {
54 // If this request is for a docShell that isn't going to allow plugins,
55 // there's no need to try and find a plugin to handle it.
56 nsCOMPtr
<nsIDocShell
> docShell(do_QueryInterface(aWebNav
));
58 if (docShell
&& NS_SUCCEEDED(docShell
->GetAllowPlugins(&allowed
)) && !allowed
) {
62 // Try reloading plugins in case they've changed.
63 nsCOMPtr
<nsIPluginHost
> pluginHost
=
64 do_GetService(MOZ_PLUGIN_HOST_CONTRACTID
);
66 // false will ensure that currently running plugins will not
68 rv
= pluginHost
->ReloadPlugins();
69 if (NS_SUCCEEDED(rv
)) {
70 // OK, we reloaded plugins and there were new ones
71 // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
72 // been returned). Try checking whether we can handle the
74 return IsTypeSupportedInternal(flatType
, aIsTypeSupported
);
82 nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString
& aType
,
83 uint32_t* aIsSupported
)
85 NS_PRECONDITION(aIsSupported
, "Null out param?");
88 nsContentUtils::ContentViewerType vtype
= nsContentUtils::TYPE_UNSUPPORTED
;
90 nsCOMPtr
<nsIDocumentLoaderFactory
> docLoaderFactory
=
91 nsContentUtils::FindInternalContentViewer(aType
.get(), &vtype
);
94 case nsContentUtils::TYPE_UNSUPPORTED
:
95 *aIsSupported
= nsIWebNavigationInfo::UNSUPPORTED
;
98 case nsContentUtils::TYPE_PLUGIN
:
99 *aIsSupported
= nsIWebNavigationInfo::PLUGIN
;
102 case nsContentUtils::TYPE_UNKNOWN
:
103 *aIsSupported
= nsIWebNavigationInfo::OTHER
;
106 case nsContentUtils::TYPE_CONTENT
:
107 // XXXbz we only need this because images register for the same
108 // contractid as documents, so we can't tell them apart based on
110 if (imgLoader::SupportImageWithMimeType(aType
.get())) {
111 *aIsSupported
= nsIWebNavigationInfo::IMAGE
;
114 *aIsSupported
= nsIWebNavigationInfo::OTHER
;