tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsWebNavigationInfo.cpp (2239B)


      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 
      9 #include "nsServiceManagerUtils.h"
     10 #include "nsIDocumentLoaderFactory.h"
     11 #include "nsContentUtils.h"
     12 #include "imgLoader.h"
     13 
     14 NS_IMPL_ISUPPORTS(nsWebNavigationInfo, nsIWebNavigationInfo)
     15 
     16 NS_IMETHODIMP
     17 nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
     18                                     uint32_t* aIsTypeSupported) {
     19  MOZ_ASSERT(aIsTypeSupported, "null out param?");
     20 
     21  *aIsTypeSupported = IsTypeSupported(aType);
     22  return NS_OK;
     23 }
     24 
     25 uint32_t nsWebNavigationInfo::IsTypeSupported(const nsACString& aType) {
     26  // We want to claim that the type for PDF documents is unsupported,
     27  // so that the internal PDF viewer's stream converted will get used.
     28  if (aType.LowerCaseEqualsLiteral("application/pdf") &&
     29      nsContentUtils::IsPDFJSEnabled()) {
     30    return nsIWebNavigationInfo::UNSUPPORTED;
     31  }
     32 
     33  const nsCString& flatType = PromiseFlatCString(aType);
     34  return IsTypeSupportedInternal(flatType);
     35 }
     36 
     37 uint32_t nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType) {
     38  nsContentUtils::DocumentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
     39 
     40  nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
     41      nsContentUtils::FindInternalDocumentViewer(aType, &vtype);
     42 
     43  switch (vtype) {
     44    case nsContentUtils::TYPE_UNSUPPORTED:
     45      return nsIWebNavigationInfo::UNSUPPORTED;
     46 
     47    case nsContentUtils::TYPE_FALLBACK:
     48      return nsIWebNavigationInfo::FALLBACK;
     49 
     50    case nsContentUtils::TYPE_UNKNOWN:
     51      return nsIWebNavigationInfo::OTHER;
     52 
     53    case nsContentUtils::TYPE_CONTENT:
     54      // XXXbz we only need this because images register for the same
     55      // contractid as documents, so we can't tell them apart based on
     56      // contractid.
     57      if (imgLoader::SupportImageWithMimeType(aType)) {
     58        return nsIWebNavigationInfo::IMAGE;
     59      }
     60      return nsIWebNavigationInfo::OTHER;
     61  }
     62 
     63  return nsIWebNavigationInfo::UNSUPPORTED;
     64 }