Bug 964239 - Docshell and session history changes to add baseURI information to srcdoc loads. r=bz

This commit is contained in:
James Kitchener 2014-02-06 09:46:29 -05:00
parent 5abf783d0c
commit 54858feac0
9 changed files with 86 additions and 12 deletions

View File

@ -1337,6 +1337,7 @@ nsDocShell::LoadURI(nsIURI * aURI,
nsXPIDLString target; nsXPIDLString target;
nsAutoString srcdoc; nsAutoString srcdoc;
nsCOMPtr<nsIDocShell> sourceDocShell; nsCOMPtr<nsIDocShell> sourceDocShell;
nsCOMPtr<nsIURI> baseURI;
uint32_t loadType = MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags); uint32_t loadType = MAKE_LOAD_TYPE(LOAD_NORMAL, aLoadFlags);
@ -1367,6 +1368,7 @@ nsDocShell::LoadURI(nsIURI * aURI,
aLoadInfo->GetIsSrcdocLoad(&isSrcdoc); aLoadInfo->GetIsSrcdocLoad(&isSrcdoc);
aLoadInfo->GetSrcdocData(srcdoc); aLoadInfo->GetSrcdocData(srcdoc);
aLoadInfo->GetSourceDocShell(getter_AddRefs(sourceDocShell)); aLoadInfo->GetSourceDocShell(getter_AddRefs(sourceDocShell));
aLoadInfo->GetBaseURI(getter_AddRefs(baseURI));
} }
#if defined(PR_LOGGING) && defined(DEBUG) #if defined(PR_LOGGING) && defined(DEBUG)
@ -1613,6 +1615,7 @@ nsDocShell::LoadURI(nsIURI * aURI,
aFirstParty, aFirstParty,
srcdoc, srcdoc,
sourceDocShell, sourceDocShell,
baseURI,
nullptr, // No nsIDocShell nullptr, // No nsIDocShell
nullptr); // No nsIRequest nullptr); // No nsIRequest
} }
@ -4809,7 +4812,8 @@ nsDocShell::LoadErrorPage(nsIURI *aURI, const char16_t *aURL,
return InternalLoad(errorPageURI, nullptr, nullptr, return InternalLoad(errorPageURI, nullptr, nullptr,
INTERNAL_LOAD_FLAGS_INHERIT_OWNER, nullptr, nullptr, INTERNAL_LOAD_FLAGS_INHERIT_OWNER, nullptr, nullptr,
NullString(), nullptr, nullptr, LOAD_ERROR_PAGE, NullString(), nullptr, nullptr, LOAD_ERROR_PAGE,
nullptr, true, NullString(), this, nullptr, nullptr); nullptr, true, NullString(), this, nullptr, nullptr,
nullptr);
} }
@ -4855,6 +4859,7 @@ nsDocShell::Reload(uint32_t aReloadFlags)
nsAutoString srcdoc; nsAutoString srcdoc;
nsIPrincipal* principal = nullptr; nsIPrincipal* principal = nullptr;
nsAutoString contentTypeHint; nsAutoString contentTypeHint;
nsCOMPtr<nsIURI> baseURI;
if (doc) { if (doc) {
principal = doc->NodePrincipal(); principal = doc->NodePrincipal();
doc->GetContentType(contentTypeHint); doc->GetContentType(contentTypeHint);
@ -4862,6 +4867,7 @@ nsDocShell::Reload(uint32_t aReloadFlags)
if (doc->IsSrcdocDocument()) { if (doc->IsSrcdocDocument()) {
doc->GetSrcdocData(srcdoc); doc->GetSrcdocData(srcdoc);
flags |= INTERNAL_LOAD_FLAGS_IS_SRCDOC; flags |= INTERNAL_LOAD_FLAGS_IS_SRCDOC;
baseURI = doc->GetBaseURI();
} }
} }
rv = InternalLoad(mCurrentURI, rv = InternalLoad(mCurrentURI,
@ -4878,6 +4884,7 @@ nsDocShell::Reload(uint32_t aReloadFlags)
true, true,
srcdoc, // srcdoc argument for iframe srcdoc, // srcdoc argument for iframe
this, // For reloads we are the source this, // For reloads we are the source
baseURI,
nullptr, // No nsIDocShell nullptr, // No nsIDocShell
nullptr); // No nsIRequest nullptr); // No nsIRequest
} }
@ -8683,7 +8690,8 @@ public:
const char* aTypeHint, nsIInputStream * aPostData, const char* aTypeHint, nsIInputStream * aPostData,
nsIInputStream * aHeadersData, uint32_t aLoadType, nsIInputStream * aHeadersData, uint32_t aLoadType,
nsISHEntry * aSHEntry, bool aFirstParty, nsISHEntry * aSHEntry, bool aFirstParty,
const nsAString &aSrcdoc, nsIDocShell* aSourceDocShell) : const nsAString &aSrcdoc, nsIDocShell* aSourceDocShell,
nsIURI * aBaseURI) :
mSrcdoc(aSrcdoc), mSrcdoc(aSrcdoc),
mDocShell(aDocShell), mDocShell(aDocShell),
mURI(aURI), mURI(aURI),
@ -8695,7 +8703,8 @@ public:
mFlags(aFlags), mFlags(aFlags),
mLoadType(aLoadType), mLoadType(aLoadType),
mFirstParty(aFirstParty), mFirstParty(aFirstParty),
mSourceDocShell(aSourceDocShell) mSourceDocShell(aSourceDocShell),
mBaseURI(aBaseURI)
{ {
// Make sure to keep null things null as needed // Make sure to keep null things null as needed
if (aTypeHint) { if (aTypeHint) {
@ -8708,7 +8717,8 @@ public:
nullptr, mTypeHint.get(), nullptr, mTypeHint.get(),
NullString(), mPostData, mHeadersData, NullString(), mPostData, mHeadersData,
mLoadType, mSHEntry, mFirstParty, mLoadType, mSHEntry, mFirstParty,
mSrcdoc, mSourceDocShell, nullptr, nullptr); mSrcdoc, mSourceDocShell, mBaseURI,
nullptr, nullptr);
} }
private: private:
@ -8729,6 +8739,7 @@ private:
uint32_t mLoadType; uint32_t mLoadType;
bool mFirstParty; bool mFirstParty;
nsCOMPtr<nsIDocShell> mSourceDocShell; nsCOMPtr<nsIDocShell> mSourceDocShell;
nsCOMPtr<nsIURI> mBaseURI;
}; };
/** /**
@ -8763,6 +8774,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
bool aFirstParty, bool aFirstParty,
const nsAString &aSrcdoc, const nsAString &aSrcdoc,
nsIDocShell* aSourceDocShell, nsIDocShell* aSourceDocShell,
nsIURI* aBaseURI,
nsIDocShell** aDocShell, nsIDocShell** aDocShell,
nsIRequest** aRequest) nsIRequest** aRequest)
{ {
@ -9018,6 +9030,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
aFirstParty, aFirstParty,
aSrcdoc, aSrcdoc,
aSourceDocShell, aSourceDocShell,
aBaseURI,
aDocShell, aDocShell,
aRequest); aRequest);
if (rv == NS_ERROR_NO_CONTENT) { if (rv == NS_ERROR_NO_CONTENT) {
@ -9089,7 +9102,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
new InternalLoadEvent(this, aURI, aReferrer, aOwner, aFlags, new InternalLoadEvent(this, aURI, aReferrer, aOwner, aFlags,
aTypeHint, aPostData, aHeadersData, aTypeHint, aPostData, aHeadersData,
aLoadType, aSHEntry, aFirstParty, aSrcdoc, aLoadType, aSHEntry, aFirstParty, aSrcdoc,
aSourceDocShell); aSourceDocShell, aBaseURI);
return NS_DispatchToCurrentThread(ev); return NS_DispatchToCurrentThread(ev);
} }
@ -9538,7 +9551,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
(aFlags & INTERNAL_LOAD_FLAGS_FIRST_LOAD) != 0, (aFlags & INTERNAL_LOAD_FLAGS_FIRST_LOAD) != 0,
(aFlags & INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER) != 0, (aFlags & INTERNAL_LOAD_FLAGS_BYPASS_CLASSIFIER) != 0,
(aFlags & INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES) != 0, (aFlags & INTERNAL_LOAD_FLAGS_FORCE_ALLOW_COOKIES) != 0,
srcdoc); srcdoc, aBaseURI);
if (req && aRequest) if (req && aRequest)
NS_ADDREF(*aRequest = req); NS_ADDREF(*aRequest = req);
@ -9617,7 +9630,8 @@ nsDocShell::DoURILoad(nsIURI * aURI,
bool aIsNewWindowTarget, bool aIsNewWindowTarget,
bool aBypassClassifier, bool aBypassClassifier,
bool aForceAllowCookies, bool aForceAllowCookies,
const nsAString &aSrcdoc) const nsAString &aSrcdoc,
nsIURI * aBaseURI)
{ {
#ifdef MOZ_VISUAL_EVENT_TRACER #ifdef MOZ_VISUAL_EVENT_TRACER
nsAutoCString urlSpec; nsAutoCString urlSpec;
@ -9702,7 +9716,8 @@ nsDocShell::DoURILoad(nsIURI * aURI,
nsViewSourceHandler *vsh = nsViewSourceHandler::GetInstance(); nsViewSourceHandler *vsh = nsViewSourceHandler::GetInstance();
NS_ENSURE_TRUE(vsh,NS_ERROR_FAILURE); NS_ENSURE_TRUE(vsh,NS_ERROR_FAILURE);
rv = vsh->NewSrcdocChannel(aURI, aSrcdoc,getter_AddRefs(channel)); rv = vsh->NewSrcdocChannel(aURI, aSrcdoc, aBaseURI,
getter_AddRefs(channel));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
else { else {
@ -9711,6 +9726,9 @@ nsDocShell::DoURILoad(nsIURI * aURI,
NS_LITERAL_CSTRING("text/html"), NS_LITERAL_CSTRING("text/html"),
true); true);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStreamChannel> isc = do_QueryInterface(channel);
MOZ_ASSERT(isc);
isc->SetBaseURI(aBaseURI);
} }
} }
@ -10969,6 +10987,9 @@ nsDocShell::AddToSessionHistory(nsIURI * aURI, nsIChannel * aChannel,
nsAutoString srcdoc; nsAutoString srcdoc;
inStrmChan->GetSrcdocData(srcdoc); inStrmChan->GetSrcdocData(srcdoc);
entry->SetSrcdocData(srcdoc); entry->SetSrcdocData(srcdoc);
nsCOMPtr<nsIURI> baseURI;
inStrmChan->GetBaseURI(getter_AddRefs(baseURI));
entry->SetBaseURI(baseURI);
} }
} }
/* If cache got a 'no-store', ask SH not to store /* If cache got a 'no-store', ask SH not to store
@ -11122,9 +11143,11 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, uint32_t aLoadType)
nsAutoString srcdoc; nsAutoString srcdoc;
bool isSrcdoc; bool isSrcdoc;
nsCOMPtr<nsIURI> baseURI;
aEntry->GetIsSrcdocEntry(&isSrcdoc); aEntry->GetIsSrcdocEntry(&isSrcdoc);
if (isSrcdoc) { if (isSrcdoc) {
aEntry->GetSrcdocData(srcdoc); aEntry->GetSrcdocData(srcdoc);
aEntry->GetBaseURI(getter_AddRefs(baseURI));
flags |= INTERNAL_LOAD_FLAGS_IS_SRCDOC; flags |= INTERNAL_LOAD_FLAGS_IS_SRCDOC;
} }
else { else {
@ -11149,6 +11172,7 @@ nsDocShell::LoadHistoryEntry(nsISHEntry * aEntry, uint32_t aLoadType)
true, true,
srcdoc, srcdoc,
nullptr, // Source docshell, see comment above nullptr, // Source docshell, see comment above
baseURI,
nullptr, // No nsIDocShell nullptr, // No nsIDocShell
nullptr); // No nsIRequest nullptr); // No nsIRequest
return rv; return rv;
@ -12564,6 +12588,7 @@ nsDocShell::OnLinkClickSync(nsIContent *aContent,
true, // first party site true, // first party site
NullString(), // No srcdoc NullString(), // No srcdoc
this, // We are the source this, // We are the source
nullptr, // baseURI not needed
aDocShell, // DocShell out-param aDocShell, // DocShell out-param
aRequest); // Request out-param aRequest); // Request out-param
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {

View File

@ -287,7 +287,8 @@ protected:
bool aIsNewWindowTarget, bool aIsNewWindowTarget,
bool aBypassClassifier, bool aBypassClassifier,
bool aForceAllowCookies, bool aForceAllowCookies,
const nsAString &aSrcdoc); const nsAString &aSrcdoc,
nsIURI * baseURI);
NS_IMETHOD AddHeadersToChannel(nsIInputStream * aHeadersData, NS_IMETHOD AddHeadersToChannel(nsIInputStream * aHeadersData,
nsIChannel * aChannel); nsIChannel * aChannel);
virtual nsresult DoChannelLoad(nsIChannel * aChannel, virtual nsresult DoChannelLoad(nsIChannel * aChannel,

View File

@ -225,6 +225,21 @@ NS_IMETHODIMP nsDocShellLoadInfo::SetSourceDocShell(nsIDocShell* aSourceDocShell
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP nsDocShellLoadInfo::GetBaseURI(nsIURI** aBaseURI)
{
NS_ENSURE_ARG_POINTER(aBaseURI);
*aBaseURI = mBaseURI;
NS_IF_ADDREF(*aBaseURI);
return NS_OK;
}
NS_IMETHODIMP nsDocShellLoadInfo::SetBaseURI(nsIURI* aBaseURI)
{
mBaseURI = aBaseURI;
return NS_OK;
}
//***************************************************************************** //*****************************************************************************
// nsDocShellLoadInfo: Helpers // nsDocShellLoadInfo: Helpers
//***************************************************************************** //*****************************************************************************

View File

@ -45,6 +45,7 @@ protected:
bool mIsSrcdocLoad; bool mIsSrcdocLoad;
nsString mSrcdocData; nsString mSrcdocData;
nsCOMPtr<nsIDocShell> mSourceDocShell; nsCOMPtr<nsIDocShell> mSourceDocShell;
nsCOMPtr<nsIURI> mBaseURI;
}; };
#endif /* nsDocShellLoadInfo_h__ */ #endif /* nsDocShellLoadInfo_h__ */

View File

@ -44,7 +44,7 @@ interface nsIReflowObserver;
typedef unsigned long nsLoadFlags; typedef unsigned long nsLoadFlags;
[scriptable, builtinclass, uuid(af035c67-1690-431b-9c4d-d38e3cc3137a)] [scriptable, builtinclass, uuid(d0eaef67-4234-47de-b05a-9c7b324eb4f4)]
interface nsIDocShell : nsIDocShellTreeItem interface nsIDocShell : nsIDocShellTreeItem
{ {
/** /**
@ -139,6 +139,9 @@ interface nsIDocShell : nsIDocShellTreeItem
* contents of this parameter will be loaded instead * contents of this parameter will be loaded instead
* of aURI. * of aURI.
* @param aSourceDocShell - The source browsing context for the navigation. * @param aSourceDocShell - The source browsing context for the navigation.
* @param aBaseURI - The base URI to be used for the load. Set in
* srcdoc loads as it cannot otherwise be inferred
* in certain situations such as view-source.
*/ */
[noscript]void internalLoad(in nsIURI aURI, [noscript]void internalLoad(in nsIURI aURI,
in nsIURI aReferrer, in nsIURI aReferrer,
@ -154,6 +157,7 @@ interface nsIDocShell : nsIDocShellTreeItem
in boolean firstParty, in boolean firstParty,
in AString aSrcdoc, in AString aSrcdoc,
in nsIDocShell aSourceDocShell, in nsIDocShell aSourceDocShell,
in nsIURI aBaseURI,
out nsIDocShell aDocShell, out nsIDocShell aDocShell,
out nsIRequest aRequest); out nsIRequest aRequest);

View File

@ -18,7 +18,7 @@ interface nsIDocShell;
typedef long nsDocShellInfoLoadType; typedef long nsDocShellInfoLoadType;
[scriptable, uuid(c6b15de3-2f4f-4e80-bb20-95f43b5598c7)] [scriptable, uuid(c8d3b1e1-565a-427e-9d68-b109910ce9b7)]
interface nsIDocShellLoadInfo : nsISupports interface nsIDocShellLoadInfo : nsISupports
{ {
/** This is the referrer for the load. */ /** This is the referrer for the load. */
@ -98,4 +98,10 @@ interface nsIDocShellLoadInfo : nsISupports
/** When set, this is the Source Browsing Context for the navigation. */ /** When set, this is the Source Browsing Context for the navigation. */
attribute nsIDocShell sourceDocShell; attribute nsIDocShell sourceDocShell;
/**
* Used for srcdoc loads to give view-source knowledge of the load's base
* URI as this information isn't embedded in the load's URI.
*/
attribute nsIURI baseURI;
}; };

View File

@ -30,7 +30,7 @@ class nsSHEntryShared;
[ptr] native nsDocShellEditorDataPtr(nsDocShellEditorData); [ptr] native nsDocShellEditorDataPtr(nsDocShellEditorData);
[ptr] native nsSHEntryShared(nsSHEntryShared); [ptr] native nsSHEntryShared(nsSHEntryShared);
[scriptable, uuid(c2a5827e-0fc0-11e3-bb95-59e799890b3c)] [scriptable, uuid(9eed7e92-1121-46f2-95e5-2f5c0dca46f0)]
interface nsISHEntry : nsISupports interface nsISHEntry : nsISupports
{ {
/** /**
@ -277,6 +277,13 @@ interface nsISHEntry : nsISupports
* Setting this sets isSrcdocEntry to true * Setting this sets isSrcdocEntry to true
*/ */
attribute AString srcdocData; attribute AString srcdocData;
/**
* When isSrcdocEntry is true, this contains the baseURI of the srcdoc
* document for use in situations where it cannot otherwise be determined,
* for example with view-source.
*/
attribute nsIURI baseURI;
}; };
[scriptable, uuid(bb66ac35-253b-471f-a317-3ece940f04c5)] [scriptable, uuid(bb66ac35-253b-471f-a317-3ece940f04c5)]

View File

@ -53,6 +53,7 @@ nsSHEntry::nsSHEntry(const nsSHEntry &other)
, mStateData(other.mStateData) , mStateData(other.mStateData)
, mIsSrcdocEntry(other.mIsSrcdocEntry) , mIsSrcdocEntry(other.mIsSrcdocEntry)
, mSrcdocData(other.mSrcdocData) , mSrcdocData(other.mSrcdocData)
, mBaseURI(other.mBaseURI)
{ {
} }
@ -516,7 +517,20 @@ nsSHEntry::SetSrcdocData(const nsAString &aSrcdocData)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsSHEntry::GetBaseURI(nsIURI **aBaseURI)
{
*aBaseURI = mBaseURI;
NS_IF_ADDREF(*aBaseURI);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetBaseURI(nsIURI *aBaseURI)
{
mBaseURI = aBaseURI;
return NS_OK;
}
//***************************************************************************** //*****************************************************************************
// nsSHEntry: nsISHContainer // nsSHEntry: nsISHContainer

View File

@ -62,6 +62,7 @@ private:
nsCOMPtr<nsIStructuredCloneContainer> mStateData; nsCOMPtr<nsIStructuredCloneContainer> mStateData;
bool mIsSrcdocEntry; bool mIsSrcdocEntry;
nsString mSrcdocData; nsString mSrcdocData;
nsCOMPtr<nsIURI> mBaseURI;
}; };
#endif /* nsSHEntry_h */ #endif /* nsSHEntry_h */