Bug 794884. Make SupportImageWithMimeType a static function. r=joe,r=bz
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Wed, 03 Oct 2012 16:17:40 -0400
changeset 115413 bc14486d074234e024f314abe52ecb90e6910a1a
parent 115412 1758b93e29c7c67ca760f61b30615118488034bc
child 115414 9a71c92af5a43c44baf8975e8163b5c170f505d8
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjoe, bz
bugs794884
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 794884. Make SupportImageWithMimeType a static function. r=joe,r=bz This removes supportImageWithMimeType from the idl and makes all the callers call the static function directly. To do this we also need to export imgLoader.h and imgRequest.h. --- content/base/src/nsObjectLoadingContent.cpp | 9 ++------- docshell/base/nsWebNavigationInfo.cpp | 8 +++++--- docshell/base/nsWebNavigationInfo.h | 5 ----- image/public/imgILoader.idl | 9 +-------- image/src/Makefile.in | 4 ++++ image/src/imgLoader.cpp | 2 +- image/src/imgLoader.h | 1 + layout/build/nsContentDLF.cpp | 5 ++--- 8 files changed, 16 insertions(+), 27 deletions(-)
content/base/src/nsObjectLoadingContent.cpp
docshell/base/nsWebNavigationInfo.cpp
docshell/base/nsWebNavigationInfo.h
image/public/imgILoader.idl
image/src/Makefile.in
image/src/imgLoader.cpp
image/src/imgLoader.h
layout/build/nsContentDLF.cpp
--- a/content/base/src/nsObjectLoadingContent.cpp
+++ b/content/base/src/nsObjectLoadingContent.cpp
@@ -6,17 +6,17 @@
 
 /*
  * A base class implementing nsIObjectLoadingContent for use by
  * various content nodes that want to provide plugin/document/image
  * loading functionality (eg <embed>, <object>, <applet>, etc).
  */
 
 // Interface headers
-#include "imgILoader.h"
+#include "imgLoader.h"
 #include "nsEventDispatcher.h"
 #include "nsIContent.h"
 #include "nsIDocShell.h"
 #include "nsIDocument.h"
 #include "nsIDOMDataContainerEvent.h"
 #include "nsIDOMDocument.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIExternalProtocolHandler.h"
@@ -472,23 +472,18 @@ URIEquals(nsIURI *a, nsIURI *b)
 {
   bool equal;
   return (!a && !b) || (a && b && NS_SUCCEEDED(a->Equals(b, &equal)) && equal);
 }
 
 static bool
 IsSupportedImage(const nsCString& aMimeType)
 {
-  nsCOMPtr<imgILoader> loader = nsContentUtils::GetImgLoaderForChannel(nullptr);
-  if (!loader) {
-    return false;
-  }
-
   bool supported;
-  nsresult rv = loader->SupportImageWithMimeType(aMimeType.get(), &supported);
+  nsresult rv = imgLoader::SupportImageWithMimeType(aMimeType.get(), &supported);
   return NS_SUCCEEDED(rv) && supported;
 }
 
 static void
 GetExtensionFromURI(nsIURI* uri, nsCString& ext)
 {
   nsCOMPtr<nsIURL> url(do_QueryInterface(uri));
   if (url) {
--- a/docshell/base/nsWebNavigationInfo.cpp
+++ b/docshell/base/nsWebNavigationInfo.cpp
@@ -5,32 +5,31 @@
 
 #include "nsWebNavigationInfo.h"
 #include "nsIWebNavigation.h"
 #include "nsString.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIDocumentLoaderFactory.h"
 #include "nsIPluginHost.h"
 #include "nsContentUtils.h"
+#include "imgLoader.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 = nsContentUtils::GetImgLoaderForChannel(nullptr);
-
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsWebNavigationInfo::IsTypeSupported(const nsACString& aType,
                                      nsIWebNavigation* aWebNav,
                                      uint32_t* aIsTypeSupported)
 {
@@ -92,18 +91,21 @@ nsWebNavigationInfo::IsTypeSupportedInte
     *aIsSupported = nsIWebNavigationInfo::PLUGIN;
     break;
 
   case nsContentUtils::TYPE_UNKNOWN:
     *aIsSupported = nsIWebNavigationInfo::OTHER;
     break;
 
   case nsContentUtils::TYPE_CONTENT:
+    // XXXbz we only need this because images register for the same
+    // contractid as documents, so we can't tell them apart based on
+    // contractid.
     bool isImage = false;
-    mImgLoader->SupportImageWithMimeType(aType.get(), &isImage);
+    imgLoader::SupportImageWithMimeType(aType.get(), &isImage);
     if (isImage) {
       *aIsSupported = nsIWebNavigationInfo::IMAGE;
     }
     else {
       *aIsSupported = nsIWebNavigationInfo::OTHER;
     }
     break;
   }
--- a/docshell/base/nsWebNavigationInfo.h
+++ b/docshell/base/nsWebNavigationInfo.h
@@ -4,17 +4,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsWebNavigationInfo_h__
 #define nsWebNavigationInfo_h__
 
 #include "nsIWebNavigationInfo.h"
 #include "nsCOMPtr.h"
 #include "nsICategoryManager.h"
-#include "imgILoader.h"
 #include "nsStringFwd.h"
 #include "mozilla/Attributes.h"
 
 // Class ID for webnavigationinfo
 #define NS_WEBNAVIGATION_INFO_CID \
  { 0xf30bc0a2, 0x958b, 0x4287,{0xbf, 0x62, 0xce, 0x38, 0xba, 0x0c, 0x81, 0x1e}}
 
 class nsWebNavigationInfo MOZ_FINAL : public nsIWebNavigationInfo
@@ -32,15 +31,11 @@ private:
   ~nsWebNavigationInfo() {}
   
   // Check whether aType is supported.  If this method throws, the
   // value of aIsSupported is not changed.
   nsresult IsTypeSupportedInternal(const nsCString& aType,
                                    uint32_t* aIsSupported);
   
   nsCOMPtr<nsICategoryManager> mCategoryManager;
-  // XXXbz we only need this because images register for the same
-  // contractid as documents, so we can't tell them apart based on
-  // contractid.
-  nsCOMPtr<imgILoader> mImgLoader;
 };
 
 #endif  // nsWebNavigationInfo_h__
--- a/image/public/imgILoader.idl
+++ b/image/public/imgILoader.idl
@@ -22,17 +22,17 @@ interface nsIChannelPolicy;
 
 /**
  * imgILoader interface
  *
  * @author Stuart Parmenter <pavlov@netscape.com>
  * @version 0.3
  * @see imagelib2
  */
-[scriptable, uuid(20a5e3e9-0d5b-482c-9f41-942b5f19e5a3)]
+[scriptable, uuid(f5a7c016-8caf-460a-b1a1-3fe5534d5c9e)]
 interface imgILoader : nsISupports
 {
   // Extra flags to pass to loadImage if you want a load to use CORS
   // validation.
   const unsigned long LOAD_CORS_ANONYMOUS = 1 << 16;
   const unsigned long LOAD_CORS_USE_CREDENTIALS = 1 << 17;
 
   /**
@@ -84,16 +84,9 @@ interface imgILoader : nsISupports
    * libpr0n does NOT keep a strong ref to the observer; this prevents
    * reference cycles.  This means that callers of loadImageWithChannel should
    * make sure to Cancel() the resulting request before the observer goes away.
    */
   imgIRequest loadImageWithChannel(in nsIChannel aChannel,
                         in imgIDecoderObserver aObserver,
                         in nsISupports cx,
                         out nsIStreamListener aListener);
-
-  /**
-   * Checks if a decoder for the an image with the given mime type is available
-   * @param mimeType The type to find a decoder for
-   * @return true if a decoder is available, false otherwise
-   */
-  boolean supportImageWithMimeType(in string mimeType);
 };
--- a/image/src/Makefile.in
+++ b/image/src/Makefile.in
@@ -13,16 +13,20 @@ include $(DEPTH)/config/autoconf.mk
 MODULE		= imglib2
 LIBRARY_NAME	= imglib2_s
 FORCE_STATIC_LIB = 1
 MODULE_NAME	= nsImageLib2Module
 GRE_MODULE	= 1
 LIBXUL_LIBRARY  = 1
 
 
+EXPORTS		=  imgLoader.h \
+		   imgRequest.h \
+		   $(NULL)
+
 CPPSRCS		= \
 			Image.cpp \
 			Decoder.cpp \
 			DiscardTracker.cpp \
 			RasterImage.cpp \
 			SVGDocumentWrapper.cpp \
 			VectorImage.cpp \
 			imgFrame.cpp \
--- a/image/src/imgLoader.cpp
+++ b/image/src/imgLoader.cpp
@@ -1916,17 +1916,17 @@ NS_IMETHODIMP imgLoader::LoadImageWithCh
     // and we can't make it further asynchronous because observers might rely
     // on imagelib completing its work between the channel's OnStartRequest and
     // OnStopRequest.
   }
 
   return rv;
 }
 
-NS_IMETHODIMP imgLoader::SupportImageWithMimeType(const char* aMimeType, bool *_retval)
+nsresult imgLoader::SupportImageWithMimeType(const char* aMimeType, bool *_retval)
 {
   *_retval = false;
   nsAutoCString mimeType(aMimeType);
   ToLowerCase(mimeType);
   *_retval = (Image::GetDecoderType(mimeType.get()) == Image::eDecoderType_unknown)
     ? false : true;
   return NS_OK;
 }
--- a/image/src/imgLoader.h
+++ b/image/src/imgLoader.h
@@ -221,16 +221,17 @@ public:
   NS_DECL_NSIOBSERVER
 
   imgLoader();
   virtual ~imgLoader();
 
   nsresult Init();
 
   static nsresult GetMimeTypeFromContent(const char* aContents, uint32_t aLength, nsACString& aContentType);
+  static nsresult SupportImageWithMimeType(const char* aMimeType, bool *_retval);
 
   static void GlobalInit(); // for use by the factory
   static void Shutdown(); // for use by the factory
 
   nsresult ClearChromeImageCache();
   nsresult ClearImageCache();
   void MinimizeCaches();
 
--- a/layout/build/nsContentDLF.cpp
+++ b/layout/build/nsContentDLF.cpp
@@ -22,17 +22,17 @@
 #include "prprf.h"
 #include "nsNetUtil.h"
 #include "nsCRT.h"
 #include "nsIViewSourceChannel.h"
 #ifdef MOZ_MEDIA
 #include "nsHTMLMediaElement.h"
 #endif
 #include "nsContentUtils.h"
-#include "imgILoader.h"
+#include "imgLoader.h"
 #include "nsCharsetSource.h"
 #include "nsMimeTypes.h"
 
 
 // plugins
 #include "nsIPluginHost.h"
 #include "nsPluginHost.h"
 static NS_DEFINE_CID(kPluginDocumentCID, NS_PLUGINDOCUMENT_CID);
@@ -457,13 +457,12 @@ nsContentDLF::CreateXULDocument(const ch
    * Bind the document to the Content Viewer...
    */
   rv = contentViewer->LoadStart(doc);
   contentViewer.forget(aContentViewer);
   return rv;
 }
 
 bool nsContentDLF::IsImageContentType(const char* aContentType) {
-  nsCOMPtr<imgILoader> loader(do_CreateInstance("@mozilla.org/image/loader;1"));
   bool isDecoderAvailable = false;
-  loader->SupportImageWithMimeType(aContentType, &isDecoderAvailable);
+  imgLoader::SupportImageWithMimeType(aContentType, &isDecoderAvailable);
   return isDecoderAvailable;
 }