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.

     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"
    21 nsresult
    22 nsWebNavigationInfo::Init()
    23 {
    24   nsresult rv;
    25   mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
    26   NS_ENSURE_SUCCESS(rv, rv);
    28   return NS_OK;
    29 }
    31 NS_IMETHODIMP
    32 nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
    33                                      nsIWebNavigation* aWebNav,
    34                                      uint32_t* aIsTypeSupported)
    35 {
    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
    43   // to say for itself.
    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) {
    51     return rv;
    52   }
    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));
    57   bool allowed;
    58   if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) {
    59     return NS_OK;
    60   }
    62   // Try reloading plugins in case they've changed.
    63   nsCOMPtr<nsIPluginHost> pluginHost =
    64     do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
    65   if (pluginHost) {
    66     // false will ensure that currently running plugins will not
    67     // be shut down
    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
    73       // content now.
    74       return IsTypeSupportedInternal(flatType, aIsTypeSupported);
    75     }
    76   }
    78   return NS_OK;
    79 }
    81 nsresult
    82 nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
    83                                              uint32_t* aIsSupported)
    84 {
    85   NS_PRECONDITION(aIsSupported, "Null out param?");
    88   nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
    90   nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
    91     nsContentUtils::FindInternalContentViewer(aType.get(), &vtype);
    93   switch (vtype) {
    94   case nsContentUtils::TYPE_UNSUPPORTED:
    95     *aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
    96     break;
    98   case nsContentUtils::TYPE_PLUGIN:
    99     *aIsSupported = nsIWebNavigationInfo::PLUGIN;
   100     break;
   102   case nsContentUtils::TYPE_UNKNOWN:
   103     *aIsSupported = nsIWebNavigationInfo::OTHER;
   104     break;
   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
   109     // contractid.
   110     if (imgLoader::SupportImageWithMimeType(aType.get())) {
   111       *aIsSupported = nsIWebNavigationInfo::IMAGE;
   112     }
   113     else {
   114       *aIsSupported = nsIWebNavigationInfo::OTHER;
   115     }
   116     break;
   117   }
   119   return NS_OK;
   120 }

mercurial