diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp
index a78c1303246..b75118da8c9 100644
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -840,6 +840,8 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
SetReferrer(referrer);
}
+ mHttpChannel = httpChannel;
+
nsCOMPtr cachingChan = do_QueryInterface(httpChannel);
if (cachingChan) {
nsCOMPtr cacheToken;
@@ -2187,7 +2189,7 @@ nsHTMLDocument::SetCookie(const nsAReadableString& aCookie)
result = NS_ERROR_OUT_OF_MEMORY;
char* cookie = ToNewCString(aCookie);
if (cookie) {
- result = service->SetCookieString(mDocumentURL, prompt, cookie, 0);
+ result = service->SetCookieString(mDocumentURL, prompt, cookie, mHttpChannel);
nsCRT::free(cookie);
}
}
diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h
index 6eb4c028a78..38d10a42f0a 100644
--- a/content/html/document/src/nsHTMLDocument.h
+++ b/content/html/document/src/nsHTMLDocument.h
@@ -50,6 +50,7 @@
#include "nsRDFCID.h"
#include "nsIRDFService.h"
#include "pldhash.h"
+#include "nsIHttpChannel.h"
// Document.Write() related
#include "nsIWyciwygChannel.h"
@@ -227,6 +228,7 @@ protected:
nsString* mBaseTarget;
nsString* mLastModified;
nsString* mReferrer;
+ nsCOMPtr mHttpChannel;
nsDTDMode mDTDMode;
nsCOMPtr mImageMaps;
diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp
index 3a8ad625005..3ed3bec1c0e 100644
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -484,7 +484,8 @@ nsDocShell::ConvertLoadTypeToDocShellLoadInfo(PRUint32 aLoadType)
NS_IMETHODIMP
nsDocShell::LoadURI(nsIURI * aURI,
nsIDocShellLoadInfo * aLoadInfo,
- PRUint32 aLoadFlags)
+ PRUint32 aLoadFlags,
+ PRBool firstParty)
{
nsresult rv;
nsCOMPtr referrer;
@@ -646,7 +647,8 @@ nsDocShell::LoadURI(nsIURI * aURI,
postStream,
nsnull, // No headers stream
loadType,
- nsnull); // No SHEntry
+ nsnull, // No SHEntry
+ firstParty);
}
return rv;
@@ -2366,7 +2368,7 @@ nsDocShell::LoadURI(const PRUnichar * aURI,
// XXX: Need to pass in the extra headers stream too...
- rv = LoadURI(uri, loadInfo, 0);
+ rv = LoadURI(uri, loadInfo, 0, PR_TRUE);
return rv;
}
@@ -2415,7 +2417,8 @@ nsDocShell::Reload(PRUint32 aReloadFlags)
nsnull, // No post data
nsnull, // No headers data
type, // Load type
- nsnull); // No SHEntry
+ nsnull, // No SHEntry
+ PR_TRUE);
return rv;
}
@@ -4281,7 +4284,8 @@ nsDocShell::InternalLoad(nsIURI * aURI,
nsIInputStream * aPostData,
nsIInputStream * aHeadersData,
PRUint32 aLoadType,
- nsISHEntry * aSHEntry)
+ nsISHEntry * aSHEntry,
+ PRBool firstParty)
{
nsresult rv;
@@ -4392,7 +4396,8 @@ nsDocShell::InternalLoad(nsIURI * aURI,
aPostData,
aHeadersData,
aLoadType,
- aSHEntry);
+ aSHEntry,
+ firstParty);
if (rv == NS_ERROR_NO_CONTENT) {
if (bIsNewWindow) {
//
@@ -4507,7 +4512,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
// been called.
mLSHE = aSHEntry;
- rv = DoURILoad(aURI, aReferrer, owner, aPostData, aHeadersData);
+ rv = DoURILoad(aURI, aReferrer, owner, aPostData, aHeadersData, firstParty);
return rv;
}
@@ -4582,7 +4587,8 @@ nsresult nsDocShell::DoURILoad(nsIURI * aURI,
nsIURI * aReferrerURI,
nsISupports * aOwner,
nsIInputStream * aPostData,
- nsIInputStream * aHeadersData)
+ nsIInputStream * aHeadersData,
+ PRBool firstParty)
{
nsresult rv;
nsCOMPtr uriLoader;
@@ -4611,6 +4617,15 @@ nsresult nsDocShell::DoURILoad(nsIURI * aURI,
channel->SetOriginalURI(aURI);
nsCOMPtr httpChannel(do_QueryInterface(channel));
+
+ if (httpChannel) {
+ if (firstParty) {
+ httpChannel->SetDocumentURI(aURI);
+ } else {
+ httpChannel->SetDocumentURI(aReferrerURI);
+ }
+ }
+
//
// If this is a HTTP channel, then set up the HTTP specific information
// (ie. POST data, referrer, ...)
@@ -5484,7 +5499,8 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, PRUint32 aLoadType)
postData, // Post data stream
nsnull, // No headers stream
aLoadType, // Load type
- aEntry); // SHEntry
+ aEntry, // SHEntry
+ PR_TRUE);
return rv;
}
@@ -6193,13 +6209,13 @@ nsRefreshTimer::Notify(nsITimer * aTimer)
* its refreshData instance to be released...
*/
mDocShell->LoadURI(mURI, loadInfo,
- nsIWebNavigation::LOAD_FLAGS_NONE);
+ nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
return;
}
else
loadInfo->SetLoadType(nsIDocShellLoadInfo::loadRefresh);
- mDocShell->LoadURI(mURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE);
+ mDocShell->LoadURI(mURI, loadInfo, nsIWebNavigation::LOAD_FLAGS_NONE, PR_TRUE);
}
}
diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h
index d94a93e4fd0..2c21a9216ff 100644
--- a/docshell/base/nsDocShell.h
+++ b/docshell/base/nsDocShell.h
@@ -208,7 +208,8 @@ protected:
nsIURI * aReferrer,
nsISupports * aOwner,
nsIInputStream * aPostData,
- nsIInputStream * aHeadersData);
+ nsIInputStream * aHeadersData,
+ PRBool firstParty);
NS_IMETHOD AddHeadersToChannel(nsIInputStream * aHeadersData,
nsIChannel * aChannel);
virtual nsresult DoChannelLoad(nsIChannel * aChannel,
diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl
index 5e84ee77ea1..a762b8e8df1 100644
--- a/docshell/base/nsIDocShell.idl
+++ b/docshell/base/nsIDocShell.idl
@@ -67,7 +67,8 @@ interface nsIDocShell : nsISupports
*/
[noscript]void loadURI(in nsIURI uri,
in nsIDocShellLoadInfo loadInfo,
- in unsigned long aLoadFlags);
+ in unsigned long aLoadFlags,
+ in boolean firstParty);
/**
* Loads a given stream. This will give priority to loading the requested
@@ -121,7 +122,8 @@ interface nsIDocShell : nsISupports
in nsIInputStream aPostDataStream,
in nsIInputStream aHeadersStream,
in unsigned long aLoadFlags,
- in nsISHEntry aSHEntry);
+ in nsISHEntry aSHEntry,
+ in boolean firstParty);
/**
* Creates a DocShellLoadInfo object that you can manipulate and then pass
diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp
index 49b8fe361b5..e27263763b9 100644
--- a/docshell/base/nsWebShell.cpp
+++ b/docshell/base/nsWebShell.cpp
@@ -610,7 +610,8 @@ nsWebShell::HandleLinkClickEvent(nsIContent *aContent,
aPostDataStream, // Post data stream
aHeadersDataStream, // Headers stream
LOAD_LINK, // Load type
- nsnull); // No SHEntry
+ nsnull, // No SHEntry
+ PR_TRUE); // first party site
}
break;
case eLinkVerb_Embed:
@@ -1005,8 +1006,8 @@ nsresult nsWebShell::EndPageLoad(nsIWebProgress *aProgress,
inputStream, // Post data stream
nsnull, // No headers stream
LOAD_RELOAD_BYPASS_PROXY_AND_CACHE,// Load type
- nsnull); // No SHEntry
-
+ nsnull, // No SHEntry
+ PR_TRUE); // first party site
}
}
}
diff --git a/layout/generic/nsBulletFrame.cpp b/layout/generic/nsBulletFrame.cpp
index 52339beda4d..da6a368b4d6 100644
--- a/layout/generic/nsBulletFrame.cpp
+++ b/layout/generic/nsBulletFrame.cpp
@@ -145,7 +145,7 @@ nsBulletFrame::Init(nsIPresContext* aPresContext,
NS_RELEASE(listener);
}
- il->LoadImage(imgURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
+ il->LoadImage(imgURI, nsnull, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
}
return NS_OK;
@@ -1472,7 +1472,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext,
nsCOMPtr loadGroup;
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
- il->LoadImage(newURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
+ il->LoadImage(newURI, nsnull, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
}
}
}
diff --git a/layout/generic/nsImageFrame.cpp b/layout/generic/nsImageFrame.cpp
index 66abfae1108..43ae934312f 100644
--- a/layout/generic/nsImageFrame.cpp
+++ b/layout/generic/nsImageFrame.cpp
@@ -1909,8 +1909,10 @@ nsImageFrame::RealLoadImage(const nsAReadableString& aSpec, nsIPresContext *aPre
/* set this back to FALSE before we do the real load */
mInitialLoadCompleted = PR_FALSE;
+ nsCOMPtr baseURI;
+ rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI));
nsCOMPtr tempRequest;
- return il->LoadImage(uri, loadGroup, mListener, aPresContext, loadFlags, nsnull, aRequest, getter_AddRefs(tempRequest));
+ return il->LoadImage(uri, baseURI, loadGroup, mListener, aPresContext, loadFlags, nsnull, aRequest, getter_AddRefs(tempRequest));
}
#define INTERNAL_GOPHER_LENGTH 16 /* "internal-gopher-" length */
diff --git a/layout/html/base/src/nsBulletFrame.cpp b/layout/html/base/src/nsBulletFrame.cpp
index 52339beda4d..da6a368b4d6 100644
--- a/layout/html/base/src/nsBulletFrame.cpp
+++ b/layout/html/base/src/nsBulletFrame.cpp
@@ -145,7 +145,7 @@ nsBulletFrame::Init(nsIPresContext* aPresContext,
NS_RELEASE(listener);
}
- il->LoadImage(imgURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
+ il->LoadImage(imgURI, nsnull, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
}
return NS_OK;
@@ -1472,7 +1472,7 @@ nsBulletFrame::Reflow(nsIPresContext* aPresContext,
nsCOMPtr loadGroup;
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
- il->LoadImage(newURI, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
+ il->LoadImage(newURI, nsnull, loadGroup, mListener, aPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(mImageRequest));
}
}
}
diff --git a/layout/html/base/src/nsImageFrame.cpp b/layout/html/base/src/nsImageFrame.cpp
index 66abfae1108..43ae934312f 100644
--- a/layout/html/base/src/nsImageFrame.cpp
+++ b/layout/html/base/src/nsImageFrame.cpp
@@ -1909,8 +1909,10 @@ nsImageFrame::RealLoadImage(const nsAReadableString& aSpec, nsIPresContext *aPre
/* set this back to FALSE before we do the real load */
mInitialLoadCompleted = PR_FALSE;
+ nsCOMPtr baseURI;
+ rv = aPresContext->GetBaseURL(getter_AddRefs(baseURI));
nsCOMPtr tempRequest;
- return il->LoadImage(uri, loadGroup, mListener, aPresContext, loadFlags, nsnull, aRequest, getter_AddRefs(tempRequest));
+ return il->LoadImage(uri, baseURI, loadGroup, mListener, aPresContext, loadFlags, nsnull, aRequest, getter_AddRefs(tempRequest));
}
#define INTERNAL_GOPHER_LENGTH 16 /* "internal-gopher-" length */
diff --git a/layout/xul/base/src/nsImageBoxFrame.cpp b/layout/xul/base/src/nsImageBoxFrame.cpp
index d8372e90c6b..0966f855367 100644
--- a/layout/xul/base/src/nsImageBoxFrame.cpp
+++ b/layout/xul/base/src/nsImageBoxFrame.cpp
@@ -457,7 +457,7 @@ nsImageBoxFrame::UpdateImage(nsIPresContext* aPresContext, PRBool& aResize)
nsCOMPtr loadGroup;
GetLoadGroup(aPresContext, getter_AddRefs(loadGroup));
- il->LoadImage(srcURI, loadGroup, mListener, aPresContext, mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest));
+ il->LoadImage(srcURI, nsnull, loadGroup, mListener, aPresContext, mLoadFlags, nsnull, nsnull, getter_AddRefs(mImageRequest));
aResize = PR_TRUE;
}
diff --git a/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp b/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp
index a40bfb1254d..a789e87daa0 100644
--- a/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp
+++ b/layout/xul/base/src/outliner/src/nsOutlinerBodyFrame.cpp
@@ -1668,7 +1668,7 @@ nsOutlinerBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID,
nsresult rv;
nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv));
mImageGuard = PR_TRUE;
- il->LoadImage(srcURI, nsnull, listener, mPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(imageRequest));
+ il->LoadImage(srcURI, nsnull, nsnull, listener, mPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(imageRequest));
mImageGuard = PR_FALSE;
// In a case it was already cached.
diff --git a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
index a40bfb1254d..a789e87daa0 100644
--- a/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
+++ b/layout/xul/base/src/tree/src/nsTreeBodyFrame.cpp
@@ -1668,7 +1668,7 @@ nsOutlinerBodyFrame::GetImage(PRInt32 aRowIndex, const PRUnichar* aColID,
nsresult rv;
nsCOMPtr il(do_GetService("@mozilla.org/image/loader;1", &rv));
mImageGuard = PR_TRUE;
- il->LoadImage(srcURI, nsnull, listener, mPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(imageRequest));
+ il->LoadImage(srcURI, nsnull, nsnull, listener, mPresContext, nsIRequest::LOAD_NORMAL, nsnull, nsnull, getter_AddRefs(imageRequest));
mImageGuard = PR_FALSE;
// In a case it was already cached.
diff --git a/modules/libpr0n/public/imgILoader.idl b/modules/libpr0n/public/imgILoader.idl
index 69cf55cc895..d94c8862402 100644
--- a/modules/libpr0n/public/imgILoader.idl
+++ b/modules/libpr0n/public/imgILoader.idl
@@ -58,7 +58,7 @@ interface imgILoader : nsISupports
* @param aRequest A newly created, unused imgIRequest object or NULL for one to
be created for you.
*/
- imgIRequest loadImage(in nsIURI aURI, in nsILoadGroup aLoadGroup,
+ imgIRequest loadImage(in nsIURI aURI, in nsIURI parentURL, in nsILoadGroup aLoadGroup,
in imgIDecoderObserver aObserver, in nsISupports aCX,
in nsLoadFlags aLoadFlags, in nsISupports cacheKey,
in imgIRequest aRequest);
diff --git a/netwerk/protocol/http/public/nsIHttpChannel.idl b/netwerk/protocol/http/public/nsIHttpChannel.idl
index 48a84b8ec13..20722a2053d 100644
--- a/netwerk/protocol/http/public/nsIHttpChannel.idl
+++ b/netwerk/protocol/http/public/nsIHttpChannel.idl
@@ -53,6 +53,12 @@ interface nsIHttpChannel : nsIChannel
const unsigned long REFERRER_INLINES = 2; // images and other inlines
const unsigned long REFERRER_NON_HTTP = 3; // e.g. news or FTP clicks
+ /**
+ * An http channel can own a reference to the document URI
+ */
+ attribute nsIURI documentURI;
+
+
/**
* Header strings are case insensitive
*/
diff --git a/netwerk/protocol/http/src/nsHttpChannel.cpp b/netwerk/protocol/http/src/nsHttpChannel.cpp
index 1bc1a343a02..2990d8548a3 100644
--- a/netwerk/protocol/http/src/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/src/nsHttpChannel.cpp
@@ -116,6 +116,7 @@ nsHttpChannel::Init(nsIURI *uri,
mURI = uri;
mOriginalURI = uri;
+ mDocumentURI = nsnull;
mCapabilities = caps;
//
@@ -199,10 +200,6 @@ nsHttpChannel::Init(nsIURI *uri,
// check to see if authorization headers should be included
AddAuthorizationHeaders();
- // Notify nsIHttpNotify implementations
- rv = nsHttpHandler::get()->OnModifyRequest(this);
- NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed");
-
return NS_OK;
}
@@ -1217,6 +1214,7 @@ nsHttpChannel::ProcessRedirection(PRUint32 redirectType)
nsresult rv;
nsCOMPtr newChannel;
+ nsCOMPtr newURI;
if (redirectType == 305) {
// we must repeat the request via the proxy specified by location
@@ -1246,7 +1244,6 @@ nsHttpChannel::ProcessRedirection(PRUint32 redirectType)
nsCOMPtr ioService;
rv = nsHttpHandler::get()->GetIOService(getter_AddRefs(ioService));
- nsCOMPtr newURI;
rv = ioService->NewURI(location, mURI, getter_AddRefs(newURI));
if (NS_FAILED(rv)) return rv;
@@ -1278,6 +1275,9 @@ nsHttpChannel::ProcessRedirection(PRUint32 redirectType)
nsCOMPtr httpChannel = do_QueryInterface(newChannel);
if (httpChannel) {
+ // update the DocumentURI indicator since we were just redirected
+ if (newURI && (mURI == mDocumentURI))
+ httpChannel->SetDocumentURI(newURI);
// convey the referrer if one was used for this channel to the next one
if (mReferrer)
httpChannel->SetReferrer(mReferrer, mReferrerType);
@@ -2069,6 +2069,10 @@ nsHttpChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *context)
rv = NS_CheckPortSafety(port, "http", ioService); // this works for https
if (NS_FAILED(rv))
return rv;
+
+ // Notify nsIHttpNotify implementations
+ rv = nsHttpHandler::get()->OnModifyRequest(this);
+ NS_ASSERTION(NS_SUCCEEDED(rv), "OnModifyRequest failed");
mIsPending = PR_TRUE;
@@ -2110,6 +2114,22 @@ nsHttpChannel::SetRequestMethod(const char *method)
return NS_OK;
}
+NS_IMETHODIMP
+nsHttpChannel::GetDocumentURI(nsIURI **aDocumentURI)
+{
+ NS_ENSURE_ARG_POINTER(aDocumentURI);
+ *aDocumentURI = mDocumentURI;
+ NS_IF_ADDREF(*aDocumentURI);
+ return NS_OK;
+}
+
+NS_IMETHODIMP
+nsHttpChannel::SetDocumentURI(nsIURI *aDocumentURI)
+{
+ mDocumentURI = aDocumentURI;
+ return NS_OK;
+}
+
NS_IMETHODIMP
nsHttpChannel::GetReferrer(nsIURI **referrer)
{
diff --git a/netwerk/protocol/http/src/nsHttpChannel.h b/netwerk/protocol/http/src/nsHttpChannel.h
index 92db00df82d..1363a19cedd 100644
--- a/netwerk/protocol/http/src/nsHttpChannel.h
+++ b/netwerk/protocol/http/src/nsHttpChannel.h
@@ -125,6 +125,7 @@ private:
private:
nsCOMPtr mOriginalURI;
nsCOMPtr mURI;
+ nsCOMPtr mDocumentURI;
nsCOMPtr mListener;
nsCOMPtr mListenerContext;
nsCOMPtr mLoadGroup;