зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
e3705730b5
Коммит
5b28996bde
|
@ -24,6 +24,7 @@
|
||||||
#include "nsRootAccessible.h"
|
#include "nsRootAccessible.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
|
#include "nsIDOMNSDocument.h"
|
||||||
#include "nsIPresShell.h"
|
#include "nsIPresShell.h"
|
||||||
#include "nsIPresContext.h"
|
#include "nsIPresContext.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
|
@ -401,8 +402,10 @@ NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
|
||||||
|
|
||||||
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
|
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
|
||||||
{
|
{
|
||||||
if (mDocument)
|
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(mDocument));
|
||||||
return mDocument->GetContentType(aMimeType);
|
if (domnsDocument) {
|
||||||
|
return domnsDocument->GetContentType(aMimeType);
|
||||||
|
}
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "nsRootAccessible.h"
|
#include "nsRootAccessible.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
|
#include "nsIDOMNSDocument.h"
|
||||||
#include "nsIPresShell.h"
|
#include "nsIPresShell.h"
|
||||||
#include "nsIPresContext.h"
|
#include "nsIPresContext.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
|
@ -401,8 +402,10 @@ NS_IMETHODIMP nsDocAccessibleMixin::GetTitle(nsAWritableString& aTitle)
|
||||||
|
|
||||||
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
|
NS_IMETHODIMP nsDocAccessibleMixin::GetMimeType(nsAWritableString& aMimeType)
|
||||||
{
|
{
|
||||||
if (mDocument)
|
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(mDocument));
|
||||||
return mDocument->GetContentType(aMimeType);
|
if (domnsDocument) {
|
||||||
|
return domnsDocument->GetContentType(aMimeType);
|
||||||
|
}
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,6 @@ public:
|
||||||
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget)=0;
|
NS_IMETHOD GetBaseTarget(nsAWritableString &aBaseTarget)=0;
|
||||||
NS_IMETHOD SetBaseTarget(const nsAReadableString &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
|
* Return a standard name for the document's character set. This will
|
||||||
* trigger a startDocumentLoad if necessary to answer the question.
|
* trigger a startDocumentLoad if necessary to answer the question.
|
||||||
|
|
|
@ -708,6 +708,16 @@ nsDocument::StartDocumentLoad(const char* aCommand,
|
||||||
if (aReset)
|
if (aReset)
|
||||||
rv = Reset(aChannel, aLoadGroup);
|
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;
|
PRBool have_contentLanguage = PR_FALSE;
|
||||||
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
|
||||||
if (httpChannel) {
|
if (httpChannel) {
|
||||||
|
@ -791,10 +801,10 @@ nsDocument::AddPrincipal(nsIPrincipal *aNewPrincipal)
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocument::GetContentType(nsAWritableString& aContentType) const
|
nsDocument::GetContentType(nsAWritableString& aContentType)
|
||||||
{
|
{
|
||||||
// Must be implemented by derived class.
|
aContentType = mContentType;
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -249,11 +249,6 @@ public:
|
||||||
*/
|
*/
|
||||||
NS_IMETHOD AddPrincipal(nsIPrincipal *aPrincipal);
|
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.
|
* Return the content language of this document.
|
||||||
*/
|
*/
|
||||||
|
@ -596,6 +591,7 @@ protected:
|
||||||
nsWeakPtr mFocusController;
|
nsWeakPtr mFocusController;
|
||||||
|
|
||||||
nsString mContentLanguage;
|
nsString mContentLanguage;
|
||||||
|
nsString mContentType;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// These are not implemented and not supported.
|
// These are not implemented and not supported.
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include "nsIDOMNode.h"
|
#include "nsIDOMNode.h"
|
||||||
#include "nsIDOMDocument.h"
|
#include "nsIDOMDocument.h"
|
||||||
|
#include "nsIDOMNSDocument.h"
|
||||||
#include "nsIDOMDocumentFragment.h"
|
#include "nsIDOMDocumentFragment.h"
|
||||||
#include "nsIContent.h"
|
#include "nsIContent.h"
|
||||||
#include "nsIDocument.h"
|
#include "nsIDocument.h"
|
||||||
|
@ -2305,8 +2306,9 @@ nsRange::CreateContextualFragment(const nsAReadableString& aFragment,
|
||||||
result = NS_NewHTMLFragmentContentSink(&sink);
|
result = NS_NewHTMLFragmentContentSink(&sink);
|
||||||
if (NS_SUCCEEDED(result)) {
|
if (NS_SUCCEEDED(result)) {
|
||||||
parser->SetContentSink(sink);
|
parser->SetContentSink(sink);
|
||||||
if (document) {
|
nsCOMPtr<nsIDOMNSDocument> domnsDocument(do_QueryInterface(document));
|
||||||
document->GetContentType(contentType);
|
if (domnsDocument) {
|
||||||
|
domnsDocument->GetContentType(contentType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Who're we kidding. This only works for html.
|
// Who're we kidding. This only works for html.
|
||||||
|
|
|
@ -361,13 +361,6 @@ nsHTMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsHTMLDocument::GetContentType(nsAWritableString& aContentType) const
|
|
||||||
{
|
|
||||||
aContentType.Assign(NS_LITERAL_STRING("text/html"));
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsHTMLDocument::CreateShell(nsIPresContext* aContext,
|
nsHTMLDocument::CreateShell(nsIPresContext* aContext,
|
||||||
nsIViewManager* aViewManager,
|
nsIViewManager* aViewManager,
|
||||||
|
|
|
@ -66,8 +66,6 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
||||||
|
|
||||||
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
|
|
||||||
|
|
||||||
NS_IMETHOD CreateShell(nsIPresContext* aContext,
|
NS_IMETHOD CreateShell(nsIPresContext* aContext,
|
||||||
nsIViewManager* aViewManager,
|
nsIViewManager* aViewManager,
|
||||||
nsIStyleSet* aStyleSet,
|
nsIStyleSet* aStyleSet,
|
||||||
|
|
|
@ -246,14 +246,6 @@ nsXMLDocument::Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup)
|
||||||
return result;
|
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
|
NS_IMETHODIMP
|
||||||
nsXMLDocument::GetInterface(const nsIID& aIID, void** aSink)
|
nsXMLDocument::GetInterface(const nsIID& aIID, void** aSink)
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,8 +54,6 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
||||||
|
|
||||||
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
|
|
||||||
|
|
||||||
NS_IMETHOD StartDocumentLoad(const char* aCommand,
|
NS_IMETHOD StartDocumentLoad(const char* aCommand,
|
||||||
nsIChannel* channel,
|
nsIChannel* channel,
|
||||||
nsILoadGroup* aLoadGroup,
|
nsILoadGroup* aLoadGroup,
|
||||||
|
|
|
@ -612,8 +612,11 @@ nsXULDocument::GetArena(nsIArena** aArena)
|
||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
nsXULDocument::GetContentType(nsAWritableString& aContentType) const
|
nsXULDocument::GetContentType(nsAWritableString& aContentType)
|
||||||
{
|
{
|
||||||
aContentType.Assign(NS_LITERAL_STRING("application/vnd.mozilla.xul+xml"));
|
aContentType.Assign(NS_LITERAL_STRING("application/vnd.mozilla.xul+xml"));
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -129,8 +129,6 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
NS_IMETHOD Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup);
|
||||||
|
|
||||||
NS_IMETHOD GetContentType(nsAWritableString& aContentType) const;
|
|
||||||
|
|
||||||
NS_IMETHOD StartDocumentLoad(const char* aCommand,
|
NS_IMETHOD StartDocumentLoad(const char* aCommand,
|
||||||
nsIChannel *channel,
|
nsIChannel *channel,
|
||||||
nsILoadGroup* aLoadGroup,
|
nsILoadGroup* aLoadGroup,
|
||||||
|
|
|
@ -39,6 +39,8 @@ interface nsIDOMNSDocument : nsISupports
|
||||||
|
|
||||||
attribute DOMString title;
|
attribute DOMString title;
|
||||||
|
|
||||||
|
readonly attribute DOMString contentType;
|
||||||
|
|
||||||
nsIBoxObject getBoxObjectFor(in nsIDOMElement elt);
|
nsIBoxObject getBoxObjectFor(in nsIDOMElement elt);
|
||||||
void setBoxObjectFor(in nsIDOMElement elt,
|
void setBoxObjectFor(in nsIDOMElement elt,
|
||||||
in nsIBoxObject boxObject);
|
in nsIBoxObject boxObject);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче