/src/mozilla-central/docshell/base/nsWebNavigationInfo.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "nsWebNavigationInfo.h" |
8 | | #include "nsIWebNavigation.h" |
9 | | #include "nsServiceManagerUtils.h" |
10 | | #include "nsIDocumentLoaderFactory.h" |
11 | | #include "nsIPluginHost.h" |
12 | | #include "nsIDocShell.h" |
13 | | #include "nsContentUtils.h" |
14 | | #include "imgLoader.h" |
15 | | #include "nsPluginHost.h" |
16 | | |
17 | | NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo) |
18 | | |
19 | | nsresult |
20 | | nsWebNavigationInfo::Init() |
21 | 0 | { |
22 | 0 | nsresult rv; |
23 | 0 | mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); |
24 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
25 | 0 |
|
26 | 0 | return NS_OK; |
27 | 0 | } |
28 | | |
29 | | NS_IMETHODIMP |
30 | | nsWebNavigationInfo::IsTypeSupported(const nsACString& aType, |
31 | | nsIWebNavigation* aWebNav, |
32 | | uint32_t* aIsTypeSupported) |
33 | 0 | { |
34 | 0 | MOZ_ASSERT(aIsTypeSupported, "null out param?"); |
35 | 0 |
|
36 | 0 | // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or |
37 | 0 | // an nsSHistory, but not much we can do with that). So if we start using |
38 | 0 | // it here, we need to be careful to get to the docshell correctly. |
39 | 0 |
|
40 | 0 | // For now just report what the Gecko-Content-Viewers category has |
41 | 0 | // to say for itself. |
42 | 0 | *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED; |
43 | 0 |
|
44 | 0 | // We want to claim that the type for PDF documents is unsupported, |
45 | 0 | // so that the internal PDF viewer's stream converted will get used. |
46 | 0 | if (aType.LowerCaseEqualsLiteral("application/pdf") && |
47 | 0 | nsContentUtils::IsPDFJSEnabled()) { |
48 | 0 | return NS_OK; |
49 | 0 | } |
50 | 0 | |
51 | 0 | const nsCString& flatType = PromiseFlatCString(aType); |
52 | 0 | nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported); |
53 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
54 | 0 |
|
55 | 0 | if (*aIsTypeSupported) { |
56 | 0 | return rv; |
57 | 0 | } |
58 | 0 | |
59 | 0 | // As of FF 52, we only support flash and test plugins, so if the mime types |
60 | 0 | // don't match for that, exit before we start loading plugins. |
61 | 0 | if (!nsPluginHost::CanUsePluginForMIMEType(aType)) { |
62 | 0 | return NS_OK; |
63 | 0 | } |
64 | 0 | |
65 | 0 | // If this request is for a docShell that isn't going to allow plugins, |
66 | 0 | // there's no need to try and find a plugin to handle it. |
67 | 0 | nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav)); |
68 | 0 | bool allowed; |
69 | 0 | if (docShell && |
70 | 0 | NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) { |
71 | 0 | return NS_OK; |
72 | 0 | } |
73 | 0 | |
74 | 0 | // Try reloading plugins in case they've changed. |
75 | 0 | nsCOMPtr<nsIPluginHost> pluginHost = |
76 | 0 | do_GetService(MOZ_PLUGIN_HOST_CONTRACTID); |
77 | 0 | if (pluginHost) { |
78 | 0 | // false will ensure that currently running plugins will not |
79 | 0 | // be shut down |
80 | 0 | rv = pluginHost->ReloadPlugins(); |
81 | 0 | if (NS_SUCCEEDED(rv)) { |
82 | 0 | // OK, we reloaded plugins and there were new ones |
83 | 0 | // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have |
84 | 0 | // been returned). Try checking whether we can handle the |
85 | 0 | // content now. |
86 | 0 | return IsTypeSupportedInternal(flatType, aIsTypeSupported); |
87 | 0 | } |
88 | 0 | } |
89 | 0 | |
90 | 0 | return NS_OK; |
91 | 0 | } |
92 | | |
93 | | nsresult |
94 | | nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType, |
95 | | uint32_t* aIsSupported) |
96 | 0 | { |
97 | 0 | MOZ_ASSERT(aIsSupported, "Null out param?"); |
98 | 0 |
|
99 | 0 | nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED; |
100 | 0 |
|
101 | 0 | nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory = |
102 | 0 | nsContentUtils::FindInternalContentViewer(aType, &vtype); |
103 | 0 |
|
104 | 0 | switch (vtype) { |
105 | 0 | case nsContentUtils::TYPE_UNSUPPORTED: |
106 | 0 | *aIsSupported = nsIWebNavigationInfo::UNSUPPORTED; |
107 | 0 | break; |
108 | 0 |
|
109 | 0 | case nsContentUtils::TYPE_PLUGIN: |
110 | 0 | *aIsSupported = nsIWebNavigationInfo::PLUGIN; |
111 | 0 | break; |
112 | 0 |
|
113 | 0 | case nsContentUtils::TYPE_UNKNOWN: |
114 | 0 | *aIsSupported = nsIWebNavigationInfo::OTHER; |
115 | 0 | break; |
116 | 0 |
|
117 | 0 | case nsContentUtils::TYPE_CONTENT: |
118 | 0 | // XXXbz we only need this because images register for the same |
119 | 0 | // contractid as documents, so we can't tell them apart based on |
120 | 0 | // contractid. |
121 | 0 | if (imgLoader::SupportImageWithMimeType(aType.get())) { |
122 | 0 | *aIsSupported = nsIWebNavigationInfo::IMAGE; |
123 | 0 | } else { |
124 | 0 | *aIsSupported = nsIWebNavigationInfo::OTHER; |
125 | 0 | } |
126 | 0 | break; |
127 | 0 | } |
128 | 0 |
|
129 | 0 | return NS_OK; |
130 | 0 | } |