diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index f1775a20b447..8290585d193d 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -153,7 +153,8 @@ nsHTMLDocument::nsHTMLDocument()
mStyleAttrStyleSheet(nsnull),
mBaseURL(nsnull),
mBaseTarget(nsnull),
- mLastModified(nsnull)
+ mLastModified(nsnull),
+ mReferrer(nsnull)
{
mImages = nsnull;
mApplets = nsnull;
@@ -212,9 +213,13 @@ nsHTMLDocument::~nsHTMLDocument()
mBaseTarget = nsnull;
}
if (nsnull != mLastModified) {
- delete mLastModified;
+ nsString::Recycle(mLastModified);
mLastModified = nsnull;
}
+ if (nsnull != mReferrer) {
+ nsString::Recycle(mReferrer);
+ mReferrer = nsnull;
+ }
NS_IF_RELEASE(mParser);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIDOMHTMLMapElement* map = (nsIDOMHTMLMapElement*)mImageMaps.ElementAt(i);
@@ -399,56 +404,70 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
- nsXPIDLCString header;
+ nsXPIDLCString lastModHeader;
nsAutoString lastModified;
- nsIAtom* key = NS_NewAtom("last-modified");
+ nsIAtom* lastModKey = NS_NewAtom("last-modified");
- rv = httpChannel->GetResponseHeader(key,
- getter_Copies(header));
+ rv = httpChannel->GetResponseHeader(lastModKey,
+ getter_Copies(lastModHeader));
- NS_RELEASE(key);
+ NS_RELEASE(lastModKey);
if (NS_SUCCEEDED(rv)) {
- lastModified = header;
+ lastModified = lastModHeader;
SetLastModified(lastModified);
}
- if(kCharsetFromHTTPHeader > charsetSource)
- {
- nsIAtom* contentTypeKey = NS_NewAtom("content-type");
- nsXPIDLCString contenttypeheader;
- rv = httpChannel->GetResponseHeader(contentTypeKey, getter_Copies(contenttypeheader));
- NS_RELEASE(contentTypeKey);
- if (NS_SUCCEEDED(rv)) {
- nsAutoString contentType;
- contentType = contenttypeheader;
- PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
- if(kNotFound != start)
- {
- start += 8; // 8 = "charset=".length
- PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
- if(kNotFound == end )
- end = contentType.Length();
- nsAutoString theCharset;
- contentType.Mid(theCharset, start, end - start);
- nsICharsetAlias* calias = nsnull;
- rv = nsServiceManager::GetService(
- kCharsetAliasCID,
- nsICharsetAlias::GetIID(),
- (nsISupports**) &calias);
- if(NS_SUCCEEDED(rv) && (nsnull != calias) )
- {
- nsAutoString preferred;
- rv = calias->GetPreferred(theCharset, preferred);
- if(NS_SUCCEEDED(rv))
- {
- charset = preferred;
- charsetSource = kCharsetFromHTTPHeader;
- }
- nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
- }
- }
- }
- }
+ nsXPIDLCString referrerHeader;
+ nsAutoString referrer;
+ // The misspelled key 'referer' is as per the HTTP spec
+ nsIAtom* referrerKey = NS_NewAtom("referer");
+
+ rv = httpChannel->GetRequestHeader(referrerKey,
+ getter_Copies(referrerHeader));
+
+ NS_RELEASE(referrerKey);
+ if (NS_SUCCEEDED(rv)) {
+ referrer = referrerHeader;
+ SetReferrer(referrer);
+ }
+
+ if(kCharsetFromHTTPHeader > charsetSource)
+ {
+ nsIAtom* contentTypeKey = NS_NewAtom("content-type");
+ nsXPIDLCString contenttypeheader;
+ rv = httpChannel->GetResponseHeader(contentTypeKey, getter_Copies(contenttypeheader));
+ NS_RELEASE(contentTypeKey);
+ if (NS_SUCCEEDED(rv)) {
+ nsAutoString contentType;
+ contentType = contenttypeheader;
+ PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
+ if(kNotFound != start)
+ {
+ start += 8; // 8 = "charset=".length
+ PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
+ if(kNotFound == end )
+ end = contentType.Length();
+ nsAutoString theCharset;
+ contentType.Mid(theCharset, start, end - start);
+ nsICharsetAlias* calias = nsnull;
+ rv = nsServiceManager::GetService(
+ kCharsetAliasCID,
+ nsICharsetAlias::GetIID(),
+ (nsISupports**) &calias);
+ if(NS_SUCCEEDED(rv) && (nsnull != calias) )
+ {
+ nsAutoString preferred;
+ rv = calias->GetPreferred(theCharset, preferred);
+ if(NS_SUCCEEDED(rv))
+ {
+ charset = preferred;
+ charsetSource = kCharsetFromHTTPHeader;
+ }
+ nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
+ }
+ }
+ }
+ }
// Don't propogate the result code beyond here, since it
// could just be that the response header wasn't found.
@@ -849,13 +868,32 @@ nsHTMLDocument::SetLastModified(const nsString& aLastModified)
}
}
else if (nsnull != mLastModified) {
- delete mLastModified;
+ nsString::Recycle(mLastModified);
mLastModified = nsnull;
}
return NS_OK;
}
+NS_IMETHODIMP
+nsHTMLDocument::SetReferrer(const nsString& aReferrer)
+{
+ if (0 < aReferrer.Length()) {
+ if (nsnull != mReferrer) {
+ *mReferrer = aReferrer;
+ }
+ else {
+ mReferrer = aReferrer.ToNewString();
+ }
+ }
+ else if (nsnull != mReferrer) {
+ nsString::Recycle(mReferrer);
+ mReferrer = nsnull;
+ }
+
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{
@@ -1264,22 +1302,13 @@ nsHTMLDocument::GetTitle(nsString& aTitle)
NS_IMETHODIMP
nsHTMLDocument::GetReferrer(nsString& aReferrer)
{
- //XXX TBI
- // PCB: How do we know what link was traversed to get here? Until we do, it's legal to
- // return an empty string. Would we have to look in history to get this? Find out.
- aReferrer.SetLength(0);
-#ifdef PCB_USE_PROTOCOL_CONNECTION
- if (nsnull != mDocumentURL) {
- nsIProtocolConnection* protocolConnection = NULL;
- static NS_DEFINE_IID(kIProtocolConnectionIID, NS_IPROTOCOLCONNECTION_IID);
- if (mDocumentURL->QueryInterface(kIProtocolConnectionIID, &protocolConnection) == NS_OK) {
- URL_Struct_* urlInfo = NULL;
- if (protocolConnection->GetURLInfo(&urlInfo) == NS_OK)
- aReferrer.SetString(urlInfo->referer);
- NS_RELEASE(protocolConnection);
- }
+ if (nsnull != mReferrer) {
+ aReferrer = *mReferrer;
}
-#endif
+ else {
+ aReferrer.Truncate();
+ }
+
return NS_OK;
}
@@ -2103,7 +2132,6 @@ nsHTMLDocument::SetFgColor(const nsString& aFgColor)
NS_IMETHODIMP
nsHTMLDocument::GetLastModified(nsString& aLastModified)
{
- //XXX TBImplemented
if (nsnull != mLastModified) {
aLastModified = *mLastModified;
}
diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h
index 2a79762fde60..7cf89831e186 100644
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -88,6 +88,7 @@ public:
NS_IMETHOD SetBaseTarget(const nsString& aTarget);
NS_IMETHOD SetLastModified(const nsString& aLastModified);
+ NS_IMETHOD SetReferrer(const nsString& aReferrer);
NS_IMETHOD GetDTDMode(nsDTDMode& aMode);
NS_IMETHOD SetDTDMode(nsDTDMode aMode);
@@ -210,6 +211,7 @@ protected:
nsIURI* mBaseURL;
nsString* mBaseTarget;
nsString* mLastModified;
+ nsString* mReferrer;
nsDTDMode mDTDMode;
nsVoidArray mImageMaps;
nsICSSLoader* mCSSLoader;
diff --git a/content/html/document/src/nsIHTMLDocument.h b/content/html/document/src/nsIHTMLDocument.h
index af42d45ce20c..1bf1b1f164da 100644
--- a/content/html/document/src/nsIHTMLDocument.h
+++ b/content/html/document/src/nsIHTMLDocument.h
@@ -69,6 +69,7 @@ public:
NS_IMETHOD SetBaseTarget(const nsString& aTarget) = 0;
NS_IMETHOD SetLastModified(const nsString& aLastModified) = 0;
+ NS_IMETHOD SetReferrer(const nsString& aReferrer) = 0;
/**
* Access DTD compatibility mode for this document
diff --git a/layout/html/document/src/nsHTMLDocument.cpp b/layout/html/document/src/nsHTMLDocument.cpp
index f1775a20b447..8290585d193d 100644
--- a/layout/html/document/src/nsHTMLDocument.cpp
+++ b/layout/html/document/src/nsHTMLDocument.cpp
@@ -153,7 +153,8 @@ nsHTMLDocument::nsHTMLDocument()
mStyleAttrStyleSheet(nsnull),
mBaseURL(nsnull),
mBaseTarget(nsnull),
- mLastModified(nsnull)
+ mLastModified(nsnull),
+ mReferrer(nsnull)
{
mImages = nsnull;
mApplets = nsnull;
@@ -212,9 +213,13 @@ nsHTMLDocument::~nsHTMLDocument()
mBaseTarget = nsnull;
}
if (nsnull != mLastModified) {
- delete mLastModified;
+ nsString::Recycle(mLastModified);
mLastModified = nsnull;
}
+ if (nsnull != mReferrer) {
+ nsString::Recycle(mReferrer);
+ mReferrer = nsnull;
+ }
NS_IF_RELEASE(mParser);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIDOMHTMLMapElement* map = (nsIDOMHTMLMapElement*)mImageMaps.ElementAt(i);
@@ -399,56 +404,70 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr httpChannel = do_QueryInterface(aChannel);
if (httpChannel) {
- nsXPIDLCString header;
+ nsXPIDLCString lastModHeader;
nsAutoString lastModified;
- nsIAtom* key = NS_NewAtom("last-modified");
+ nsIAtom* lastModKey = NS_NewAtom("last-modified");
- rv = httpChannel->GetResponseHeader(key,
- getter_Copies(header));
+ rv = httpChannel->GetResponseHeader(lastModKey,
+ getter_Copies(lastModHeader));
- NS_RELEASE(key);
+ NS_RELEASE(lastModKey);
if (NS_SUCCEEDED(rv)) {
- lastModified = header;
+ lastModified = lastModHeader;
SetLastModified(lastModified);
}
- if(kCharsetFromHTTPHeader > charsetSource)
- {
- nsIAtom* contentTypeKey = NS_NewAtom("content-type");
- nsXPIDLCString contenttypeheader;
- rv = httpChannel->GetResponseHeader(contentTypeKey, getter_Copies(contenttypeheader));
- NS_RELEASE(contentTypeKey);
- if (NS_SUCCEEDED(rv)) {
- nsAutoString contentType;
- contentType = contenttypeheader;
- PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
- if(kNotFound != start)
- {
- start += 8; // 8 = "charset=".length
- PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
- if(kNotFound == end )
- end = contentType.Length();
- nsAutoString theCharset;
- contentType.Mid(theCharset, start, end - start);
- nsICharsetAlias* calias = nsnull;
- rv = nsServiceManager::GetService(
- kCharsetAliasCID,
- nsICharsetAlias::GetIID(),
- (nsISupports**) &calias);
- if(NS_SUCCEEDED(rv) && (nsnull != calias) )
- {
- nsAutoString preferred;
- rv = calias->GetPreferred(theCharset, preferred);
- if(NS_SUCCEEDED(rv))
- {
- charset = preferred;
- charsetSource = kCharsetFromHTTPHeader;
- }
- nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
- }
- }
- }
- }
+ nsXPIDLCString referrerHeader;
+ nsAutoString referrer;
+ // The misspelled key 'referer' is as per the HTTP spec
+ nsIAtom* referrerKey = NS_NewAtom("referer");
+
+ rv = httpChannel->GetRequestHeader(referrerKey,
+ getter_Copies(referrerHeader));
+
+ NS_RELEASE(referrerKey);
+ if (NS_SUCCEEDED(rv)) {
+ referrer = referrerHeader;
+ SetReferrer(referrer);
+ }
+
+ if(kCharsetFromHTTPHeader > charsetSource)
+ {
+ nsIAtom* contentTypeKey = NS_NewAtom("content-type");
+ nsXPIDLCString contenttypeheader;
+ rv = httpChannel->GetResponseHeader(contentTypeKey, getter_Copies(contenttypeheader));
+ NS_RELEASE(contentTypeKey);
+ if (NS_SUCCEEDED(rv)) {
+ nsAutoString contentType;
+ contentType = contenttypeheader;
+ PRInt32 start = contentType.RFind("charset=", PR_TRUE ) ;
+ if(kNotFound != start)
+ {
+ start += 8; // 8 = "charset=".length
+ PRInt32 end = contentType.FindCharInSet(";\n\r ", start );
+ if(kNotFound == end )
+ end = contentType.Length();
+ nsAutoString theCharset;
+ contentType.Mid(theCharset, start, end - start);
+ nsICharsetAlias* calias = nsnull;
+ rv = nsServiceManager::GetService(
+ kCharsetAliasCID,
+ nsICharsetAlias::GetIID(),
+ (nsISupports**) &calias);
+ if(NS_SUCCEEDED(rv) && (nsnull != calias) )
+ {
+ nsAutoString preferred;
+ rv = calias->GetPreferred(theCharset, preferred);
+ if(NS_SUCCEEDED(rv))
+ {
+ charset = preferred;
+ charsetSource = kCharsetFromHTTPHeader;
+ }
+ nsServiceManager::ReleaseService(kCharsetAliasCID, calias);
+ }
+ }
+ }
+ }
// Don't propogate the result code beyond here, since it
// could just be that the response header wasn't found.
@@ -849,13 +868,32 @@ nsHTMLDocument::SetLastModified(const nsString& aLastModified)
}
}
else if (nsnull != mLastModified) {
- delete mLastModified;
+ nsString::Recycle(mLastModified);
mLastModified = nsnull;
}
return NS_OK;
}
+NS_IMETHODIMP
+nsHTMLDocument::SetReferrer(const nsString& aReferrer)
+{
+ if (0 < aReferrer.Length()) {
+ if (nsnull != mReferrer) {
+ *mReferrer = aReferrer;
+ }
+ else {
+ mReferrer = aReferrer.ToNewString();
+ }
+ }
+ else if (nsnull != mReferrer) {
+ nsString::Recycle(mReferrer);
+ mReferrer = nsnull;
+ }
+
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsHTMLDocument::GetCSSLoader(nsICSSLoader*& aLoader)
{
@@ -1264,22 +1302,13 @@ nsHTMLDocument::GetTitle(nsString& aTitle)
NS_IMETHODIMP
nsHTMLDocument::GetReferrer(nsString& aReferrer)
{
- //XXX TBI
- // PCB: How do we know what link was traversed to get here? Until we do, it's legal to
- // return an empty string. Would we have to look in history to get this? Find out.
- aReferrer.SetLength(0);
-#ifdef PCB_USE_PROTOCOL_CONNECTION
- if (nsnull != mDocumentURL) {
- nsIProtocolConnection* protocolConnection = NULL;
- static NS_DEFINE_IID(kIProtocolConnectionIID, NS_IPROTOCOLCONNECTION_IID);
- if (mDocumentURL->QueryInterface(kIProtocolConnectionIID, &protocolConnection) == NS_OK) {
- URL_Struct_* urlInfo = NULL;
- if (protocolConnection->GetURLInfo(&urlInfo) == NS_OK)
- aReferrer.SetString(urlInfo->referer);
- NS_RELEASE(protocolConnection);
- }
+ if (nsnull != mReferrer) {
+ aReferrer = *mReferrer;
}
-#endif
+ else {
+ aReferrer.Truncate();
+ }
+
return NS_OK;
}
@@ -2103,7 +2132,6 @@ nsHTMLDocument::SetFgColor(const nsString& aFgColor)
NS_IMETHODIMP
nsHTMLDocument::GetLastModified(nsString& aLastModified)
{
- //XXX TBImplemented
if (nsnull != mLastModified) {
aLastModified = *mLastModified;
}
diff --git a/layout/html/document/src/nsHTMLDocument.h b/layout/html/document/src/nsHTMLDocument.h
index 2a79762fde60..7cf89831e186 100644
--- a/layout/html/document/src/nsHTMLDocument.h
+++ b/layout/html/document/src/nsHTMLDocument.h
@@ -88,6 +88,7 @@ public:
NS_IMETHOD SetBaseTarget(const nsString& aTarget);
NS_IMETHOD SetLastModified(const nsString& aLastModified);
+ NS_IMETHOD SetReferrer(const nsString& aReferrer);
NS_IMETHOD GetDTDMode(nsDTDMode& aMode);
NS_IMETHOD SetDTDMode(nsDTDMode aMode);
@@ -210,6 +211,7 @@ protected:
nsIURI* mBaseURL;
nsString* mBaseTarget;
nsString* mLastModified;
+ nsString* mReferrer;
nsDTDMode mDTDMode;
nsVoidArray mImageMaps;
nsICSSLoader* mCSSLoader;
diff --git a/layout/html/document/src/nsIHTMLDocument.h b/layout/html/document/src/nsIHTMLDocument.h
index af42d45ce20c..1bf1b1f164da 100644
--- a/layout/html/document/src/nsIHTMLDocument.h
+++ b/layout/html/document/src/nsIHTMLDocument.h
@@ -69,6 +69,7 @@ public:
NS_IMETHOD SetBaseTarget(const nsString& aTarget) = 0;
NS_IMETHOD SetLastModified(const nsString& aLastModified) = 0;
+ NS_IMETHOD SetReferrer(const nsString& aReferrer) = 0;
/**
* Access DTD compatibility mode for this document