Bug 224209 - Correct filename on title when viewing an image from a PHP file. r=bz
authorAkshendra Pratap <akshendra521994@gmail.com>
Thu, 30 Oct 2014 06:08:00 +0100
changeset 213265 1a8f290db545038eb80fe0a9b6e6ef187926e535
parent 213264 77052db0876656441c526e266f71f42776708e25
child 213266 5fb2f466209883231e78e1b6e0d6a1d0833c0ea9
push id51187
push usercbook@mozilla.com
push dateFri, 31 Oct 2014 08:33:21 +0000
treeherdermozilla-inbound@2c7ca0dc4155 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs224209
milestone36.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 224209 - Correct filename on title when viewing an image from a PHP file. r=bz
dom/html/ImageDocument.cpp
dom/html/MediaDocument.cpp
dom/html/MediaDocument.h
dom/html/PluginDocument.cpp
dom/html/VideoDocument.cpp
--- a/dom/html/ImageDocument.cpp
+++ b/dom/html/ImageDocument.cpp
@@ -776,17 +776,17 @@ ImageDocument::UpdateTitleAndCharset()
   static const char* const formatNames[4] = 
   {
     "ImageTitleWithNeitherDimensionsNorFile",
     "ImageTitleWithoutDimensions",
     "ImageTitleWithDimensions2",
     "ImageTitleWithDimensions2AndFile",
   };
 
-  MediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
+  MediaDocument::UpdateTitleAndCharset(typeStr, mChannel, formatNames,
                                        mImageWidth, mImageHeight, status);
 }
 
 void
 ImageDocument::ResetZoomLevel()
 {
   nsCOMPtr<nsIDocShell> docShell(mDocumentContainer);
   if (docShell) {
--- a/dom/html/MediaDocument.cpp
+++ b/dom/html/MediaDocument.cpp
@@ -273,20 +273,26 @@ MediaDocument::StartLayout()
     nsresult rv = shell->Initialize(visibleArea.width, visibleArea.height);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   return NS_OK;
 }
 
 void
-MediaDocument::GetFileName(nsAString& aResult)
+MediaDocument::GetFileName(nsAString& aResult, nsIChannel* aChannel)
 {
   aResult.Truncate();
 
+  if (aChannel) {
+    aChannel->GetContentDispositionFilename(aResult);
+    if (!aResult.IsEmpty())
+      return;
+  }
+
   nsCOMPtr<nsIURL> url = do_QueryInterface(mDocumentURI);
   if (!url)
     return;
 
   nsAutoCString fileName;
   url->GetFileName(fileName);
   if (fileName.IsEmpty())
     return;
@@ -334,22 +340,23 @@ MediaDocument::LinkStylesheet(const nsAS
   link->SetAttr(kNameSpaceID_None, nsGkAtoms::href, aStylesheet, true);
 
   Element* head = GetHeadElement();
   return head->AppendChildTo(link, false);
 }
 
 void 
 MediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
+                                     nsIChannel* aChannel,
                                      const char* const* aFormatNames,
                                      int32_t aWidth, int32_t aHeight,
                                      const nsAString& aStatus)
 {
   nsXPIDLString fileStr;
-  GetFileName(fileStr);
+  GetFileName(fileStr, aChannel);
 
   NS_ConvertASCIItoUTF16 typeStr(aTypeStr);
   nsXPIDLString title;
 
   if (mStringBundle) {
     // if we got a valid size (not all media have a size)
     if (aWidth != 0 && aHeight != 0) {
       nsAutoString widthStr;
--- a/dom/html/MediaDocument.h
+++ b/dom/html/MediaDocument.h
@@ -43,32 +43,33 @@ public:
 protected:
   void BecomeInteractive();
 
   virtual nsresult CreateSyntheticDocument();
 
   friend class MediaDocumentStreamListener;
   nsresult StartLayout();
 
-  void GetFileName(nsAString& aResult);
+  void GetFileName(nsAString& aResult, nsIChannel* aChannel);
 
   nsresult LinkStylesheet(const nsAString& aStylesheet);
 
   // |aFormatNames[]| needs to have four elements in the following order: 
   // a format name with neither dimension nor file, a format name with
   // filename but w/o dimension, a format name with dimension but w/o filename,
   // a format name with both of them.  For instance, it can have
   // "ImageTitleWithNeitherDimensionsNorFile", "ImageTitleWithoutDimensions",
   // "ImageTitleWithDimesions2",  "ImageTitleWithDimensions2AndFile".
   //
   // Also see MediaDocument.properties if you want to define format names
   // for a new subclass. aWidth and aHeight are pixels for |ImageDocument|,
   // but could be in other units for other 'media', in which case you have to 
   // define format names accordingly. 
   void UpdateTitleAndCharset(const nsACString&  aTypeStr,
+                             nsIChannel* aChannel,
                              const char* const* aFormatNames = sFormatNames,
                              int32_t            aWidth = 0,
                              int32_t            aHeight = 0,
                              const nsAString&   aStatus = EmptyString());
 
   nsCOMPtr<nsIStringBundle>     mStringBundle;
   static const char* const      sFormatNames[4];
   
--- a/dom/html/PluginDocument.cpp
+++ b/dom/html/PluginDocument.cpp
@@ -180,17 +180,17 @@ PluginDocument::StartDocumentLoad(const 
     return rv;
   }
 
   rv = aChannel->GetContentType(mMimeType);
   if (NS_FAILED(rv)) {
     return rv;
   }
 
-  MediaDocument::UpdateTitleAndCharset(mMimeType);
+  MediaDocument::UpdateTitleAndCharset(mMimeType, aChannel);
 
   mStreamListener = new PluginStreamListener(this);
   NS_ASSERTION(aDocListener, "null aDocListener");
   NS_ADDREF(*aDocListener = mStreamListener);
 
   return rv;
 }
 
--- a/dom/html/VideoDocument.cpp
+++ b/dom/html/VideoDocument.cpp
@@ -123,17 +123,17 @@ VideoDocument::CreateSyntheticVideoDocum
 
 void
 VideoDocument::UpdateTitle(nsIChannel* aChannel)
 {
   if (!aChannel)
     return;
 
   nsAutoString fileName;
-  GetFileName(fileName);
+  GetFileName(fileName, aChannel);
   SetTitle(fileName);
 }
 
 } // namespace dom
 } // namespace mozilla
 
 nsresult
 NS_NewVideoDocument(nsIDocument** aResult)