diff --git a/mozilla/content/html/document/src/MANIFEST_PROPERTIES b/mozilla/content/html/document/src/MANIFEST_PROPERTIES
new file mode 100644
index 00000000000..199f79d50d6
--- /dev/null
+++ b/mozilla/content/html/document/src/MANIFEST_PROPERTIES
@@ -0,0 +1 @@
+MediaDocument.properties
diff --git a/mozilla/layout/html/forms/src/ImageDocument.properties b/mozilla/content/html/document/src/MediaDocument.properties
similarity index 88%
rename from mozilla/layout/html/forms/src/ImageDocument.properties
rename to mozilla/content/html/document/src/MediaDocument.properties
index f78f7f3335c..b9da8282231 100644
--- a/mozilla/layout/html/forms/src/ImageDocument.properties
+++ b/mozilla/content/html/document/src/MediaDocument.properties
@@ -24,9 +24,13 @@
#LOCALIZATION NOTE (ImageTitleWithoutDimensions): first %S is filename, second %S is type
#LOCALIZATION NOTE (ImageTitleWithDimensions): first %S is type, second %S is width and third %S is height
#LOCALIZATION NOTE (ImageTitleWithNeitherDimensionsNorFile): first %S is type
+#LOCALIZATION NOTE (MediaTitleWithFile): first %S is filename, second %S is type
+#LOCALIZATION NOTE (MediaTitleWithNoInfo): first %S is type
ImageTitleWithDimensionsAndFile=%S (%S Image, %Sx%S pixels)
ImageTitleWithoutDimensions=%S (%S Image)
ImageTitleWithDimensions=(%S Image, %Sx%S pixels)
ImageTitleWithNeitherDimensionsNorFile=(%S Image)
+MediaTitleWithFile=%S (%S Object)
+MediaTitleWithNoInfo=(%S Object)
InvalidImage=The image \u201c%S\u201d cannot be displayed, because it contains errors.
diff --git a/mozilla/content/html/document/src/jar.mn b/mozilla/content/html/document/src/jar.mn
new file mode 100644
index 00000000000..b47ada60808
--- /dev/null
+++ b/mozilla/content/html/document/src/jar.mn
@@ -0,0 +1,2 @@
+en-US.jar:
+ locale/en-US/communicator/layout/MediaDocument.properties
diff --git a/mozilla/content/html/document/src/nsImageDocument.cpp b/mozilla/content/html/document/src/nsImageDocument.cpp
index f9e21b4ee9b..5592393818d 100644
--- a/mozilla/content/html/document/src/nsImageDocument.cpp
+++ b/mozilla/content/html/document/src/nsImageDocument.cpp
@@ -52,17 +52,13 @@
#include "imgILoader.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
-#include "nsIURL.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsStyleContext.h"
-#include "nsIStringBundle.h"
#include "nsIPrefService.h"
-#include "nsITextToSubURI.h"
#include "nsAutoPtr.h"
#include "nsMediaDocument.h"
-#define NSIMAGEDOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/ImageDocument.properties"
#define AUTOMATIC_IMAGE_RESIZING_PREF "browser.enable_automatic_image_resizing"
class nsImageDocument;
@@ -89,8 +85,7 @@ public:
NS_DECL_ISUPPORTS
- // nsIHTMLDocument
- nsresult Init();
+ virtual nsresult Init();
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@@ -117,15 +112,14 @@ protected:
nsresult CheckOverflowing();
- nsresult UpdateTitle();
+ void UpdateTitleAndCharset();
- nsCOMPtr mStringBundle;
nsCOMPtr mImageElement;
- nscoord mVisibleWidth;
- nscoord mVisibleHeight;
- nscoord mImageWidth;
- nscoord mImageHeight;
+ PRInt32 mVisibleWidth;
+ PRInt32 mVisibleHeight;
+ PRInt32 mImageWidth;
+ PRInt32 mImageHeight;
PRPackedBool mImageResizingEnabled;
PRPackedBool mImageIsOverflowing;
@@ -174,7 +168,7 @@ ImageListener::OnStopRequest(nsIRequest* request, nsISupports *ctxt,
{
NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE);
nsImageDocument *imgDoc = (nsImageDocument*)mDocument.get();
- imgDoc->UpdateTitle();
+ imgDoc->UpdateTitleAndCharset();
nsCOMPtr imageLoader = do_QueryInterface(imgDoc->mImageElement);
NS_ENSURE_TRUE(imageLoader, NS_ERROR_UNEXPECTED);
@@ -215,7 +209,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsMediaDocument)
nsresult
nsImageDocument::Init()
{
- nsresult rv = nsHTMLDocument::Init();
+ nsresult rv = nsMediaDocument::Init();
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
@@ -225,13 +219,6 @@ nsImageDocument::Init()
mImageResizingEnabled = temp;
}
- // Create a bundle for the localization
- nsCOMPtr stringService(
- do_GetService(NS_STRINGBUNDLE_CONTRACTID));
- if (stringService) {
- stringService->CreateBundle(NSIMAGEDOCUMENT_PROPERTIES_URI,
- getter_AddRefs(mStringBundle));
- }
return NS_OK;
}
@@ -574,127 +561,55 @@ nsImageDocument::CheckOverflowing()
return NS_OK;
}
-nsresult
-nsImageDocument::UpdateTitle()
+void
+nsImageDocument::UpdateTitleAndCharset()
{
- if (mStringBundle) {
- nsXPIDLString fileStr;
- nsAutoString widthStr;
- nsAutoString heightStr;
- nsAutoString typeStr;
- nsXPIDLString valUni;
-
- nsCOMPtr url = do_QueryInterface(mDocumentURL);
- if (url) {
- nsresult rv;
- nsCAutoString fileName;
- url->GetFileName(fileName);
- nsCOMPtr textToSubURI =
- do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
- if (NS_SUCCEEDED(rv))
- {
- nsCAutoString originCharset;
- rv = url->GetOriginCharset(originCharset);
- if (NS_SUCCEEDED(rv))
- rv = textToSubURI->UnEscapeURIForUI(originCharset, fileName, fileStr);
- }
- if (NS_FAILED(rv))
- fileStr.Assign(NS_ConvertUTF8toUCS2(fileName));
- }
-
- widthStr.AppendInt(mImageWidth);
- heightStr.AppendInt(mImageHeight);
-
- nsCOMPtr imageRequest;
- nsCOMPtr imageLoader = do_QueryInterface(mImageElement);
- if (imageLoader) {
- imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
- getter_AddRefs(imageRequest));
- }
+ nsCAutoString typeStr;
+ nsCOMPtr imageRequest;
+ nsCOMPtr imageLoader = do_QueryInterface(mImageElement);
+ if (imageLoader) {
+ imageLoader->GetRequest(nsIImageLoadingContent::CURRENT_REQUEST,
+ getter_AddRefs(imageRequest));
+ }
- if (imageRequest) {
- nsXPIDLCString mimeType;
- imageRequest->GetMimeType(getter_Copies(mimeType));
- ToUpperCase(mimeType);
- nsXPIDLCString::const_iterator start, end;
- mimeType.BeginReading(start);
- mimeType.EndReading(end);
- nsXPIDLCString::const_iterator iter = end;
- if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) &&
- iter != end) {
- // strip out "X-" if any
- if (*iter == 'X') {
+ if (imageRequest) {
+ nsXPIDLCString mimeType;
+ imageRequest->GetMimeType(getter_Copies(mimeType));
+ ToUpperCase(mimeType);
+ nsXPIDLCString::const_iterator start, end;
+ mimeType.BeginReading(start);
+ mimeType.EndReading(end);
+ nsXPIDLCString::const_iterator iter = end;
+ if (FindInReadable(NS_LITERAL_CSTRING("IMAGE/"), start, iter) &&
+ iter != end) {
+ // strip out "X-" if any
+ if (*iter == 'X') {
+ ++iter;
+ if (iter != end && *iter == '-') {
++iter;
- if (iter != end && *iter == '-') {
- ++iter;
- if (iter == end) {
- // looks like "IMAGE/X-" is the type?? Bail out of here.
- mimeType.BeginReading(iter);
- }
- } else {
- --iter;
+ if (iter == end) {
+ // looks like "IMAGE/X-" is the type?? Bail out of here.
+ mimeType.BeginReading(iter);
}
+ } else {
+ --iter;
}
- CopyASCIItoUCS2(Substring(iter, end), typeStr);
- } else {
- CopyASCIItoUCS2(mimeType, typeStr);
- }
- }
-
- // If we got a filename, display it
- if (!fileStr.IsEmpty()) {
- // if we got a valid size (sometimes we do not) then display it
- if (mImageWidth != 0 && mImageHeight != 0){
- const PRUnichar *formatStrings[4] =
- {
- fileStr.get(),
- typeStr.get(),
- widthStr.get(),
- heightStr.get()
- };
- NS_NAMED_LITERAL_STRING(str, "ImageTitleWithDimensionsAndFile");
- mStringBundle->FormatStringFromName(str.get(), formatStrings, 4,
- getter_Copies(valUni));
- } else {
- const PRUnichar *formatStrings[2] =
- {
- fileStr.get(),
- typeStr.get()
- };
- NS_NAMED_LITERAL_STRING(str, "ImageTitleWithoutDimensions");
- mStringBundle->FormatStringFromName(str.get(), formatStrings, 2,
- getter_Copies(valUni));
}
+ typeStr = Substring(iter, end);
} else {
- // if we got a valid size (sometimes we do not) then display it
- if (mImageWidth != 0 && mImageHeight != 0){
- const PRUnichar *formatStrings[3] =
- {
- typeStr.get(),
- widthStr.get(),
- heightStr.get()
- };
- NS_NAMED_LITERAL_STRING(str, "ImageTitleWithDimensions");
- mStringBundle->FormatStringFromName(str.get(), formatStrings, 3,
- getter_Copies(valUni));
- } else {
- const PRUnichar *formatStrings[1] =
- {
- typeStr.get()
- };
- NS_NAMED_LITERAL_STRING(str, "ImageTitleWithNeitherDimensionsNorFile");
- mStringBundle->FormatStringFromName(str.get(), formatStrings, 1,
- getter_Copies(valUni));
- }
- }
-
- if (valUni) {
- // set it on the document
- SetTitle(valUni);
+ typeStr = mimeType;
}
}
+ static const char* const formatNames[4] =
+ {
+ "ImageTitleWithNeitherDimensionsNorFile",
+ "ImageTitleWithoutDimensions",
+ "ImageTitleWithDimesions",
+ "ImageTitleWithDimensionsAndFile",
+ };
- return NS_OK;
+ nsMediaDocument::UpdateTitleAndCharset(typeStr, formatNames,
+ mImageWidth, mImageHeight);
}
diff --git a/mozilla/content/html/document/src/nsMediaDocument.cpp b/mozilla/content/html/document/src/nsMediaDocument.cpp
index 0caad798a23..c4863171531 100644
--- a/mozilla/content/html/document/src/nsMediaDocument.cpp
+++ b/mozilla/content/html/document/src/nsMediaDocument.cpp
@@ -20,6 +20,7 @@
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
+ * Jungshik Shin
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@@ -42,6 +43,9 @@
#include "nsIPresShell.h"
#include "nsIScrollable.h"
#include "nsIViewManager.h"
+#include "nsITextToSubURI.h"
+#include "nsIURL.h"
+#include "nsPrintfCString.h"
nsMediaDocumentStreamListener::nsMediaDocumentStreamListener(nsMediaDocument *aDocument)
{
@@ -108,6 +112,15 @@ nsMediaDocumentStreamListener::OnDataAvailable(nsIRequest* request,
return NS_OK;
}
+// default format names for nsMediaDocument.
+const char* const nsMediaDocument::sFormatNames[4] =
+{
+ "MediaTitleWithNoInfo", // eWithNoInfo
+ "MediaTitleWithFile", // eWithFile
+ "", // eWithDim
+ "" // eWithDimAndFile
+};
+
nsMediaDocument::nsMediaDocument()
{
}
@@ -115,6 +128,23 @@ nsMediaDocument::~nsMediaDocument()
{
}
+nsresult
+nsMediaDocument::Init()
+{
+ nsresult rv = nsHTMLDocument::Init();
+ NS_ENSURE_SUCCESS(rv, rv);
+
+ // Create a bundle for the localization
+ nsCOMPtr stringService(
+ do_GetService(NS_STRINGBUNDLE_CONTRACTID));
+ if (stringService) {
+ stringService->CreateBundle(NSMEDIADOCUMENT_PROPERTIES_URI,
+ getter_AddRefs(mStringBundle));
+ }
+
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsMediaDocument::StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
@@ -210,3 +240,81 @@ nsMediaDocument::StartLayout()
return NS_OK;
}
+
+void
+nsMediaDocument::UpdateTitleAndCharset(const nsACString& aTypeStr,
+ const char* const* aFormatNames,
+ PRInt32 aWidth, PRInt32 aHeight)
+{
+ nsXPIDLString fileStr;
+ nsCOMPtr uri = do_QueryInterface(mDocumentURL);
+ if (uri) {
+ nsCAutoString originCharset;
+ uri->GetOriginCharset(originCharset);
+ nsCAutoString fileName;
+ nsCOMPtr url = do_QueryInterface(uri);
+ if (url)
+ url->GetFileName(fileName);
+ if (!originCharset.IsEmpty()) {
+ // set doc. charset to that of the referring document if known so that
+ // filepicker comes up with the correct non-ascii filename.
+ SetDocumentCharacterSet(NS_ConvertASCIItoUCS2(originCharset));
+ if (!fileName.IsEmpty()) {
+ nsresult rv;
+ nsCOMPtr textToSubURI =
+ do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
+ if (NS_SUCCEEDED(rv))
+ rv = textToSubURI->UnEscapeURIForUI(originCharset, fileName, fileStr);
+ }
+ }
+ if (fileStr.IsEmpty())
+ fileStr.Assign(NS_ConvertUTF8toUCS2(fileName));
+ }
+
+
+ NS_ConvertASCIItoUCS2 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;
+ nsAutoString heightStr;
+ widthStr.AppendInt(aWidth);
+ heightStr.AppendInt(aHeight);
+ // If we got a filename, display it
+ if (!fileStr.IsEmpty()) {
+ const PRUnichar *formatStrings[4] = {fileStr.get(), typeStr.get(),
+ widthStr.get(), heightStr.get()};
+ NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithDimAndFile]);
+ mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 4,
+ getter_Copies(title));
+ }
+ else {
+ const PRUnichar *formatStrings[3] = {typeStr.get(), widthStr.get(),
+ heightStr.get()};
+ NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithDim]);
+ mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 3,
+ getter_Copies(title));
+ }
+ }
+ else {
+ // If we got a filename, display it
+ if (!fileStr.IsEmpty()) {
+ const PRUnichar *formatStrings[2] = {fileStr.get(), typeStr.get()};
+ NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithFile]);
+ mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 2,
+ getter_Copies(title));
+ }
+ else {
+ const PRUnichar *formatStrings[1] = {typeStr.get()};
+ NS_ConvertASCIItoUCS2 fmtName(aFormatNames[eWithNoInfo]);
+ mStringBundle->FormatStringFromName(fmtName.get(), formatStrings, 1,
+ getter_Copies(title));
+ }
+ }
+ }
+
+ // set it on the document
+ SetTitle(title);
+}
diff --git a/mozilla/content/html/document/src/nsMediaDocument.h b/mozilla/content/html/document/src/nsMediaDocument.h
index 97c1fa8f062..dcf7d5fff58 100644
--- a/mozilla/content/html/document/src/nsMediaDocument.h
+++ b/mozilla/content/html/document/src/nsMediaDocument.h
@@ -41,6 +41,9 @@
#include "nsHTMLDocument.h"
#include "nsGenericHTMLElement.h"
#include "nsAutoPtr.h"
+#include "nsIStringBundle.h"
+
+#define NSMEDIADOCUMENT_PROPERTIES_URI "chrome://communicator/locale/layout/MediaDocument.properties"
class nsMediaDocument : public nsHTMLDocument
{
@@ -48,6 +51,8 @@ public:
nsMediaDocument();
virtual ~nsMediaDocument();
+ virtual nsresult Init();
+
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@@ -61,6 +66,28 @@ protected:
friend class nsMediaDocumentStreamListener;
nsresult StartLayout();
+
+ // |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",
+ // "ImageTitleWithDimesions", "ImageTitleWithDimensionsAndFile".
+ //
+ // Also see MediaDocument.properties if you want to define format names
+ // for a new subclass. aWidth and aHeight are pixels for |nsImageDocument|,
+ // but could be in other units for other 'media', in which case you have to
+ // define format names accordingly.
+ void UpdateTitleAndCharset(const nsACString& aTypeStr,
+ const char* const* aFormatNames = sFormatNames,
+ PRInt32 aWidth = 0,
+ PRInt32 aHeight = 0);
+
+ nsCOMPtr mStringBundle;
+ static const char* const sFormatNames[4];
+
+private:
+ enum {eWithNoInfo, eWithFile, eWithDim, eWithDimAndFile};
};
diff --git a/mozilla/content/html/document/src/nsPluginDocument.cpp b/mozilla/content/html/document/src/nsPluginDocument.cpp
index 17f1dc56d6c..a307ce594eb 100644
--- a/mozilla/content/html/document/src/nsPluginDocument.cpp
+++ b/mozilla/content/html/document/src/nsPluginDocument.cpp
@@ -64,10 +64,11 @@ public:
NS_IMETHOD SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject);
protected:
- nsresult CreateSyntheticPluginDocument(nsACString &aMimeType);
+ nsresult CreateSyntheticPluginDocument();
nsCOMPtr mPluginContent;
nsRefPtr mStreamListener;
+ nsCString mMimeType;
};
@@ -76,10 +77,6 @@ protected:
nsPluginDocument::nsPluginDocument()
{
-
- // NOTE! nsDocument::operator new() zeroes out all members, so don't
- // bother initializing members to 0.
-
}
nsPluginDocument::~nsPluginDocument()
@@ -121,14 +118,13 @@ nsPluginDocument::StartDocumentLoad(const char* aCommand,
return rv;
}
- nsCAutoString mimeType;
- rv = aChannel->GetContentType(mimeType);
+ rv = aChannel->GetContentType(mMimeType);
if (NS_FAILED(rv)) {
return rv;
}
// Create synthetic document
- rv = CreateSyntheticPluginDocument(mimeType);
+ rv = CreateSyntheticPluginDocument();
if (NS_FAILED(rv)) {
return rv;
}
@@ -143,7 +139,7 @@ nsPluginDocument::StartDocumentLoad(const char* aCommand,
}
nsresult
-nsPluginDocument::CreateSyntheticPluginDocument(nsACString &aMimeType)
+nsPluginDocument::CreateSyntheticPluginDocument()
{
// do not allow message panes to host full-page plugins
// returning an error causes helper apps to take over
@@ -202,7 +198,7 @@ nsPluginDocument::CreateSyntheticPluginDocument(nsACString &aMimeType)
mPluginContent->SetHTMLAttribute(nsHTMLAtoms::src, val, PR_FALSE);
// set mime type
- val.SetStringValue(NS_ConvertUTF8toUCS2(aMimeType));
+ val.SetStringValue(NS_ConvertUTF8toUCS2(mMimeType));
mPluginContent->SetHTMLAttribute(nsHTMLAtoms::type, val, PR_FALSE);
body->AppendChildTo(mPluginContent, PR_FALSE, PR_FALSE);
@@ -218,8 +214,7 @@ nsPluginDocument::SetStreamListener(nsIStreamListener *aListener)
if (mStreamListener)
mStreamListener->SetStreamListener(aListener);
- nsAutoString title;
- SetTitle(title);
+ nsMediaDocument::UpdateTitleAndCharset(mMimeType);
return NS_OK;
}
diff --git a/mozilla/layout/html/forms/src/MANIFEST_PROPERTIES b/mozilla/layout/html/forms/src/MANIFEST_PROPERTIES
index 70a42c47e80..864c402a7f3 100644
--- a/mozilla/layout/html/forms/src/MANIFEST_PROPERTIES
+++ b/mozilla/layout/html/forms/src/MANIFEST_PROPERTIES
@@ -1,2 +1 @@
HtmlForm.properties
-ImageDocument.properties
diff --git a/mozilla/layout/html/forms/src/jar.mn b/mozilla/layout/html/forms/src/jar.mn
index 0e43b270805..91cfc72de1f 100644
--- a/mozilla/layout/html/forms/src/jar.mn
+++ b/mozilla/layout/html/forms/src/jar.mn
@@ -1,5 +1,4 @@
en-US.jar:
locale/en-US/communicator/layout/HtmlForm.properties
- locale/en-US/communicator/layout/ImageDocument.properties