LCOV - code coverage report
Current view: directory - docshell/base - nsWebNavigationInfo.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 38 0 0.0 %
Date: 2012-06-02 Functions: 6 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Boris Zbarsky <bzbarsky@mit.edu>.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2005
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #include "nsWebNavigationInfo.h"
      39                 : #include "nsIWebNavigation.h"
      40                 : #include "nsString.h"
      41                 : #include "nsServiceManagerUtils.h"
      42                 : #include "nsIDocumentLoaderFactory.h"
      43                 : #include "nsIPluginHost.h"
      44                 : #include "nsContentUtils.h"
      45                 : 
      46               0 : NS_IMPL_ISUPPORTS1(nsWebNavigationInfo, nsIWebNavigationInfo)
      47                 : 
      48                 : #define CONTENT_DLF_CONTRACT "@mozilla.org/content/document-loader-factory;1"
      49                 : #define PLUGIN_DLF_CONTRACT \
      50                 :     "@mozilla.org/content/plugin/document-loader-factory;1"
      51                 : 
      52                 : nsresult
      53               0 : nsWebNavigationInfo::Init()
      54                 : {
      55                 :   nsresult rv;
      56               0 :   mCategoryManager = do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
      57               0 :   NS_ENSURE_SUCCESS(rv, rv);
      58                 : 
      59               0 :   mImgLoader = do_GetService("@mozilla.org/image/loader;1", &rv);
      60                 : 
      61               0 :   return rv;
      62                 : }
      63                 : 
      64                 : NS_IMETHODIMP
      65               0 : nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
      66                 :                                      nsIWebNavigation* aWebNav,
      67                 :                                      PRUint32* aIsTypeSupported)
      68                 : {
      69               0 :   NS_PRECONDITION(aIsTypeSupported, "null out param?");
      70                 : 
      71                 :   // Note to self: aWebNav could be an nsWebBrowser or an nsDocShell here (or
      72                 :   // an nsSHistory, but not much we can do with that).  So if we start using
      73                 :   // it here, we need to be careful to get to the docshell correctly.
      74                 :   
      75                 :   // For now just report what the Gecko-Content-Viewers category has
      76                 :   // to say for itself.
      77               0 :   *aIsTypeSupported = nsIWebNavigationInfo::UNSUPPORTED;
      78                 : 
      79               0 :   const nsCString& flatType = PromiseFlatCString(aType);
      80               0 :   nsresult rv = IsTypeSupportedInternal(flatType, aIsTypeSupported);
      81               0 :   NS_ENSURE_SUCCESS(rv, rv);
      82                 : 
      83               0 :   if (*aIsTypeSupported) {
      84               0 :     return rv;
      85                 :   }
      86                 :   
      87                 :   // Try reloading plugins in case they've changed.
      88                 :   nsCOMPtr<nsIPluginHost> pluginHost =
      89               0 :     do_GetService(MOZ_PLUGIN_HOST_CONTRACTID);
      90               0 :   if (pluginHost) {
      91                 :     // false will ensure that currently running plugins will not
      92                 :     // be shut down
      93               0 :     rv = pluginHost->ReloadPlugins(false);
      94               0 :     if (NS_SUCCEEDED(rv)) {
      95                 :       // OK, we reloaded plugins and there were new ones
      96                 :       // (otherwise NS_ERROR_PLUGINS_PLUGINSNOTCHANGED would have
      97                 :       // been returned).  Try checking whether we can handle the
      98                 :       // content now.
      99               0 :       return IsTypeSupportedInternal(flatType, aIsTypeSupported);
     100                 :     }
     101                 :   }
     102                 : 
     103               0 :   return NS_OK;
     104                 : }
     105                 : 
     106                 : nsresult
     107               0 : nsWebNavigationInfo::IsTypeSupportedInternal(const nsCString& aType,
     108                 :                                              PRUint32* aIsSupported)
     109                 : {
     110               0 :   NS_PRECONDITION(aIsSupported, "Null out param?");
     111                 : 
     112                 : 
     113               0 :   nsContentUtils::ContentViewerType vtype = nsContentUtils::TYPE_UNSUPPORTED;
     114                 : 
     115                 :   nsCOMPtr<nsIDocumentLoaderFactory> docLoaderFactory =
     116               0 :     nsContentUtils::FindInternalContentViewer(aType.get(), &vtype);
     117                 : 
     118               0 :   switch (vtype) {
     119                 :   case nsContentUtils::TYPE_UNSUPPORTED:
     120               0 :     *aIsSupported = nsIWebNavigationInfo::UNSUPPORTED;
     121               0 :     break;
     122                 : 
     123                 :   case nsContentUtils::TYPE_PLUGIN:
     124               0 :     *aIsSupported = nsIWebNavigationInfo::PLUGIN;
     125               0 :     break;
     126                 : 
     127                 :   case nsContentUtils::TYPE_UNKNOWN:
     128               0 :     *aIsSupported = nsIWebNavigationInfo::OTHER;
     129               0 :     break;
     130                 : 
     131                 :   case nsContentUtils::TYPE_CONTENT:
     132               0 :     bool isImage = false;
     133               0 :     mImgLoader->SupportImageWithMimeType(aType.get(), &isImage);
     134               0 :     if (isImage) {
     135               0 :       *aIsSupported = nsIWebNavigationInfo::IMAGE;
     136                 :     }
     137                 :     else {
     138               0 :       *aIsSupported = nsIWebNavigationInfo::OTHER;
     139                 :     }
     140               0 :     break;
     141                 :   }
     142                 : 
     143               0 :   return NS_OK;
     144                 : }

Generated by: LCOV version 1.7