Add a document.contentType attribute to allow getting the MIME type of

the current document from JS.  The rest is moving around stuff to deal
with nsIDocument already declaring GetContentType.  bug 73847, r=peterv,
sr=jst
This commit is contained in:
bzbarsky%mit.edu 2001-09-24 22:43:23 +00:00
parent e3705730b5
commit 5b28996bde
13 changed files with 34 additions and 41 deletions

View File

@ -24,6 +24,7 @@
#include "nsRootAccessible.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
@ -401,8 +402,10 @@ NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
{
if (mDocument)
return mDocument->GetContentType(aMimeType);
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(mDocument));
if (domnsDocument) {
return domnsDocument->GetContentType(aMimeType);
}
return NS_ERROR_FAILURE;
}

View File

@ -24,6 +24,7 @@
#include "nsRootAccessible.h"
#include "nsCOMPtr.h"
#include "nsIDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsIContent.h"
@ -401,8 +402,10 @@ NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
{
if (mDocument)
return mDocument->GetContentType(aMimeType);
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(mDocument));
if (domnsDocument) {
return domnsDocument->GetContentType(aMimeType);
}
return NS_ERROR_FAILURE;
}

View File

@ -137,11 +137,6 @@ public:
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget)=0;
NS_IMETHOD SetBaseTarget(const nsAReadableString &aBaseTarget)=0;
/**
* Return the content (mime) type of this document.
*/
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const = 0;
/**
* Return a standard name for the document's character set. This will
* trigger a startDocumentLoad if necessary to answer the question.

View File

@ -708,6 +708,16 @@ nsDocument::StartDocumentLoad(const char* aCommand,
if (aReset)
rv = Reset(aChannel, aLoadGroup);
nsXPIDLCString contentType;
if (NS_SUCCEEDED(aChannel->GetContentType(getter_Copies(contentType)))) {
nsXPIDLCString::const_iterator start, end, semicolon;
contentType.BeginReading(start);
contentType.EndReading(end);
semicolon = start;
FindCharInReadable(';', semicolon, end);
CopyASCIItoUCS2(Substring(start, semicolon), mContentType);
}
PRBool have_contentLanguage = PR_FALSE;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
@ -791,10 +801,10 @@ nsDocument::AddPrincipal(nsIPrincipal *aNewPrincipal)
}
NS_IMETHODIMP
nsDocument::GetContentType(nsAWritableString& aContentType) const
nsDocument::GetContentType(nsAWritableString& aContentType)
{
// Must be implemented by derived class.
return NS_ERROR_NOT_IMPLEMENTED;
aContentType = mContentType;
return NS_OK;
}
NS_IMETHODIMP

View File

@ -249,11 +249,6 @@ public:
*/
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
/**
* Return the content (mime) type of this document.
*/
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
/**
* Return the content language of this document.
*/
@ -596,6 +591,7 @@ protected:
nsWeakPtr mFocusController;
nsString mContentLanguage;
nsString mContentType;
private:
// These are not implemented and not supported.

View File

@ -29,6 +29,7 @@
#include "nsIDOMNode.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNSDocument.h"
#include "nsIDOMDocumentFragment.h"
#include "nsIContent.h"
#include "nsIDocument.h"
@ -2305,8 +2306,9 @@ nsRange::CreateContextualFragment(const nsAReadableString& aFragment,
result = NS_NewHTMLFragmentContentSink(&sink);
if (NS_SUCCEEDED(result)) {
parser->SetContentSink(sink);
if (document) {
document->GetContentType(contentType);
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(document));
if (domnsDocument) {
domnsDocument->GetContentType(contentType);
}
else {
// Who're we kidding. This only works for html.

View File

@ -361,13 +361,6 @@ nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
return result;
}
NS_IMETHODIMP
nsHTMLDocument::GetContentType(nsAWritableString& aContentType) const
{
aContentType.Assign(NS_LITERAL_STRING("text/html"));
return NS_OK;
}
NS_IMETHODIMP
nsHTMLDocument::CreateShell(nsIPresContext* aContext,
nsIViewManager* aViewManager,

View File

@ -66,8 +66,6 @@ public:
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD CreateShell(nsIPresContext* aContext,
nsIViewManager* aViewManager,
nsIStyleSet* aStyleSet,

View File

@ -246,14 +246,6 @@ nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
return result;
}
NS_IMETHODIMP
nsXMLDocument::GetContentType(nsAWritableString& aContentType) const
{
// XXX Should get document type from incoming stream
aContentType.Assign(NS_LITERAL_STRING("text/xml"));
return NS_OK;
}
NS_IMETHODIMP
nsXMLDocument::GetInterface(const nsIID& aIID, void** aSink)
{

View File

@ -54,8 +54,6 @@ public:
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel* channel,
nsILoadGroup* aLoadGroup,

View File

@ -612,8 +612,11 @@ nsXULDocument::GetArena(nsIArena** aArena)
return NS_OK;
}
// Override the nsDocument.cpp method to keep from returning the
// "cached XUL" type which is completely internal and may confuse
// people
NS_IMETHODIMP
nsXULDocument::GetContentType(nsAWritableString& aContentType) const
nsXULDocument::GetContentType(nsAWritableString& aContentType)
{
aContentType.Assign(NS_LITERAL_STRING("application/vnd.mozilla.xul+xml"));
return NS_OK;

View File

@ -129,8 +129,6 @@ public:
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
NS_IMETHOD StartDocumentLoad(const char* aCommand,
nsIChannel *channel,
nsILoadGroup* aLoadGroup,

View File

@ -39,6 +39,8 @@ interface nsIDOMNSDocument : nsISupports
attribute DOMString title;
readonly attribute DOMString contentType;
nsIBoxObject getBoxObjectFor(in nsIDOMElement elt);
void setBoxObjectFor(in nsIDOMElement elt,
in nsIBoxObject boxObject);