docshell/base/nsWebNavigationInfo.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/base/nsWebNavigationInfo.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsWebNavigationInfo.h"
    1.10 +#include "nsIWebNavigation.h"
    1.11 +#include "nsServiceManagerUtils.h"
    1.12 +#include "nsIDocumentLoaderFactory.h"
    1.13 +#include "nsIPluginHost.h"
    1.14 +#include "nsIDocShell.h"
    1.15 +#include "nsContentUtils.h"
    1.16 +#include "imgLoader.h"
    1.17 +
    1.18 +NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
    1.19 +
    1.20 +#define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1"
    1.21 +#define PLUGIN_DLF_CONTRACT \
    1.22 +    "@mozilla.org/content/plugin/document-loader-factory;1"
    1.23 +
    1.24 +nsresult
    1.25 +nsWebNavigationInfo::Init()
    1.26 +{
    1.27 +  nsresult rv;
    1.28 +  mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
    1.29 +  NS_ENSURE_SUCCESS(rv, rv);
    1.30 +
    1.31 +  return NS_OK;
    1.32 +}
    1.33 +
    1.34 +NS_IMETHODIMP
    1.35 +nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
    1.36 +                                     nsIWebNavigation* aWebNav,
    1.37 +                                     uint32_t* aIsTypeSupported)
    1.38 +{
    1.39 +  NS_PRECONDITION(aIsTypeSupported, "null out param?");
    1.40 +
    1.41 +  // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
    1.42 +  // an nsSHistory, but not much we can do with that).  So if we start using
    1.43 +  // it here, we need to be careful to get to the docshell correctly.
    1.44 +  
    1.45 +  // For now just report what the Gecko-Content-Viewers category has
    1.46 +  // to say for itself.
    1.47 +  *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED;
    1.48 +
    1.49 +  const nsCString& flatType = PromiseFlatCString(aType);
    1.50 +  nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
    1.51 +  NS_ENSURE_SUCCESS(rv, rv);
    1.52 +
    1.53 +  if (*aIsTypeSupported) {
    1.54 +    return rv;
    1.55 +  }
    1.56 +
    1.57 +  // If this request is for a docShell that isn't going to allow plugins,
    1.58 +  // there's no need to try and find a plugin to handle it.
    1.59 +  nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aWebNav));
    1.60 +  bool allowed;
    1.61 +  if (docShell && NS_SUCCEEDED(docShell->GetAllowPlugins(&allowed)) && !allowed) {
    1.62 +    return NS_OK;
    1.63 +  }
    1.64 +
    1.65 +  // Try reloading plugins in case they've changed.
    1.66 +  nsCOMPtr<nsIPluginHost> pluginHost =
    1.67 +    do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
    1.68 +  if (pluginHost) {
    1.69 +    // false will ensure that currently running plugins will not
    1.70 +    // be shut down
    1.71 +    rv = pluginHost->ReloadPlugins();
    1.72 +    if (NS_SUCCEEDED(rv)) {
    1.73 +      // OK, we reloaded plugins and there were new ones
    1.74 +      // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
    1.75 +      // been returned).  Try checking whether we can handle the
    1.76 +      // content now.
    1.77 +      return IsTypeSupportedInternal(flatType, aIsTypeSupported);
    1.78 +    }
    1.79 +  }
    1.80 +
    1.81 +  return NS_OK;
    1.82 +}
    1.83 +
    1.84 +nsresult
    1.85 +nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
    1.86 +                                             uint32_t* aIsSupported)
    1.87 +{
    1.88 +  NS_PRECONDITION(aIsSupported, "Null out param?");
    1.89 +
    1.90 +
    1.91 +  nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
    1.92 +
    1.93 +  nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
    1.94 +    nsContentUtils::FindInternalContentViewer(aType.get(), &vtype);
    1.95 +
    1.96 +  switch (vtype) {
    1.97 +  case nsContentUtils::TYPE_UNSUPPORTED:
    1.98 +    *aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
    1.99 +    break;
   1.100 +
   1.101 +  case nsContentUtils::TYPE_PLUGIN:
   1.102 +    *aIsSupported = nsIWebNavigationInfo::PLUGIN;
   1.103 +    break;
   1.104 +
   1.105 +  case nsContentUtils::TYPE_UNKNOWN:
   1.106 +    *aIsSupported = nsIWebNavigationInfo::OTHER;
   1.107 +    break;
   1.108 +
   1.109 +  case nsContentUtils::TYPE_CONTENT:
   1.110 +    // XXXbz we only need this because images register for the same
   1.111 +    // contractid as documents, so we can't tell them apart based on
   1.112 +    // contractid.
   1.113 +    if (imgLoader::SupportImageWithMimeType(aType.get())) {
   1.114 +      *aIsSupported = nsIWebNavigationInfo::IMAGE;
   1.115 +    }
   1.116 +    else {
   1.117 +      *aIsSupported = nsIWebNavigationInfo::OTHER;
   1.118 +    }
   1.119 +    break;
   1.120 +  }
   1.121 +
   1.122 +  return NS_OK;
   1.123 +}

mercurial