docshell/base/nsWebNavigationInfo.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial