gecko/docshell/base/nsWebNavigationInfo.cpp
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

113 lines
3.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsWebNavigationInfo.h"
#include "nsIWebNavigation.h"
#include "nsString.h"
#include "nsServiceManagerUtils.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIPluginHost.h"
#include "nsContentUtils.h"
NS_IMPL_ISUPPORTS1(nsWebNavigationInfo, nsIWebNavigationInfo)
#define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1"
#define PLUGIN_DLF_CONTRACT \
"@mozilla.org/content/plugin/document-loader-factory;1"
nsresult
nsWebNavigationInfo::Init()
{
nsresult rv;
mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mImgLoader = do_GetService("@mozilla.org/image/loader;1", &rv);
return rv;
}
NS_IMETHODIMP
nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
nsIWebNavigation* aWebNav,
uint32_t* aIsTypeSupported)
{
NS_PRECONDITION(aIsTypeSupported, "null out param?");
// Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
// an nsSHistory, but not much we can do with that). So if we start using
// it here, we need to be careful to get to the docshell correctly.
// For now just report what the Gecko-Content-Viewers category has
// to say for itself.
*aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED;
const nsCString& flatType = PromiseFlatCString(aType);
nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
NS_ENSURE_SUCCESS(rv, rv);
if (*aIsTypeSupported) {
return rv;
}
// Try reloading plugins in case they've changed.
nsCOMPtr<nsIPluginHost> pluginHost =
do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
if (pluginHost) {
// false will ensure that currently running plugins will not
// be shut down
rv = pluginHost->ReloadPlugins(false);
if (NS_SUCCEEDED(rv)) {
// OK, we reloaded plugins and there were new ones
// (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
// been returned). Try checking whether we can handle the
// content now.
return IsTypeSupportedInternal(flatType, aIsTypeSupported);
}
}
return NS_OK;
}
nsresult
nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
uint32_t* aIsSupported)
{
NS_PRECONDITION(aIsSupported, "Null out param?");
nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
nsContentUtils::FindInternalContentViewer(aType.get(), &vtype);
switch (vtype) {
case nsContentUtils::TYPE_UNSUPPORTED:
*aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
break;
case nsContentUtils::TYPE_PLUGIN:
*aIsSupported = nsIWebNavigationInfo::PLUGIN;
break;
case nsContentUtils::TYPE_UNKNOWN:
*aIsSupported = nsIWebNavigationInfo::OTHER;
break;
case nsContentUtils::TYPE_CONTENT:
bool isImage = false;
mImgLoader->SupportImageWithMimeType(aType.get(), &isImage);
if (isImage) {
*aIsSupported = nsIWebNavigationInfo::IMAGE;
}
else {
*aIsSupported = nsIWebNavigationInfo::OTHER;
}
break;
}
return NS_OK;
}