Bug 822367 - Since document.open() creates a new channel, set nsDocShell:mMixedContentChannel to the newly created channel if the user has decided to allow mixed content on the page. r=smaug

This commit is contained in:
Tanvi Vyas 2013-01-30 00:04:34 -08:00
Родитель c3eedfc7b5
Коммит 6591455ded
8 изменённых файлов: 54 добавлений и 30 удалений

Просмотреть файл

@ -195,7 +195,8 @@ DocManager::OnStateChange(nsIWebProgress* aWebProgress,
if (loadType == LOAD_RELOAD_NORMAL ||
loadType == LOAD_RELOAD_BYPASS_CACHE ||
loadType == LOAD_RELOAD_BYPASS_PROXY ||
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE) {
loadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
loadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
isReloading = true;
}

Просмотреть файл

@ -273,6 +273,9 @@ LogShellLoadType(nsIDocShell* aDocShell)
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
printf("reload bypass proxy and cache; ");
break;
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
printf("reload allow mixed content; ");
break;
case LOAD_LINK:
printf("link; ");
break;

Просмотреть файл

@ -333,7 +333,8 @@ nsMixedContentBlocker::ShouldLoad(uint32_t aContentType,
NS_ENSURE_TRUE(docShell, NS_OK);
bool rootHasSecureConnection = false;
bool allowMixedContent = false;
rv = docShell->GetAllowMixedContentAndConnectionData(&rootHasSecureConnection, &allowMixedContent);
bool isRootDocShell = false;
rv = docShell->GetAllowMixedContentAndConnectionData(&rootHasSecureConnection, &allowMixedContent, &isRootDocShell);
if (NS_FAILED(rv)) {
return rv;
}

Просмотреть файл

@ -1620,6 +1620,16 @@ nsHTMLDocument::Open(JSContext* cx,
if (rv.Failed()) {
return nullptr;
}
// If the user has allowed mixed content on the rootDoc, then we should propogate it
// down to the new document channel.
bool rootHasSecureConnection = false;
bool allowMixedContent = false;
bool isDocShellRoot = false;
nsresult rvalue = shell->GetAllowMixedContentAndConnectionData(&rootHasSecureConnection, &allowMixedContent, &isDocShellRoot);
if (NS_SUCCEEDED(rvalue) && allowMixedContent && isDocShellRoot) {
shell->SetMixedContentChannel(channel);
}
}
// Before we reset the doc notify the globalwindow of the change,

Просмотреть файл

@ -663,6 +663,7 @@ ConvertLoadTypeToNavigationType(uint32_t aLoadType)
case LOAD_RELOAD_BYPASS_CACHE:
case LOAD_RELOAD_BYPASS_PROXY:
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
result = dom::PerformanceNavigation::TYPE_RELOAD;
break;
case LOAD_STOP_CONTENT_AND_REPLACE:
@ -1148,7 +1149,7 @@ ConvertDocShellLoadInfoToLoadType(nsDocShellInfoLoadType aDocShellLoadType)
loadType = LOAD_REPLACE_BYPASS_CACHE;
break;
case nsIDocShellLoadInfo::loadMixedContent:
loadType = LOAD_MIXED_CONTENT;
loadType = LOAD_RELOAD_ALLOW_MIXED_CONTENT;
break;
default:
NS_NOTREACHED("Unexpected nsDocShellInfoLoadType value");
@ -1221,7 +1222,7 @@ nsDocShell::ConvertLoadTypeToDocShellLoadInfo(uint32_t aLoadType)
case LOAD_REPLACE_BYPASS_CACHE:
docShellLoadType = nsIDocShellLoadInfo::loadReplaceBypassCache;
break;
case LOAD_MIXED_CONTENT:
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
docShellLoadType = nsIDocShellLoadInfo::loadMixedContent;
break;
default:
@ -5330,13 +5331,16 @@ NS_IMETHODIMP
nsDocShell::SetMixedContentChannel(nsIChannel* aMixedContentChannel)
{
#ifdef DEBUG
// Get the root docshell.
nsCOMPtr<nsIDocShellTreeItem> root;
GetSameTypeRootTreeItem(getter_AddRefs(root));
NS_WARN_IF_FALSE(
root.get() == static_cast<nsIDocShellTreeItem *>(this),
"Setting mMixedContentChannel on a docshell that is not the root docshell"
);
// if the channel is non-null
if (aMixedContentChannel) {
// Get the root docshell.
nsCOMPtr<nsIDocShellTreeItem> root;
GetSameTypeRootTreeItem(getter_AddRefs(root));
NS_WARN_IF_FALSE(
root.get() == static_cast<nsIDocShellTreeItem *>(this),
"Setting mMixedContentChannel on a docshell that is not the root docshell"
);
}
#endif
mMixedContentChannel = aMixedContentChannel;
return NS_OK;
@ -5351,31 +5355,33 @@ nsDocShell::GetMixedContentChannel(nsIChannel **aMixedContentChannel)
}
NS_IMETHODIMP
nsDocShell::GetAllowMixedContentAndConnectionData(bool* aRootHasSecureConnection, bool* aAllowMixedContent)
nsDocShell::GetAllowMixedContentAndConnectionData(bool* aRootHasSecureConnection, bool* aAllowMixedContent, bool* aIsRootDocShell)
{
*aRootHasSecureConnection = false;
*aAllowMixedContent = false;
nsCOMPtr<nsIDocShellTreeItem> currentDocShellTreeItem = static_cast<nsIDocShellTreeItem *>(this);
NS_ASSERTION(currentDocShellTreeItem, "No DocShellTreeItem from docshell");
*aIsRootDocShell = false;
nsCOMPtr<nsIDocShellTreeItem> sameTypeRoot;
currentDocShellTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
GetSameTypeRootTreeItem(getter_AddRefs(sameTypeRoot));
NS_ASSERTION(sameTypeRoot, "No document shell root tree item from document shell tree item!");
*aIsRootDocShell = sameTypeRoot.get() == static_cast<nsIDocShellTreeItem *>(this);
// now get the document from sameTypeRoot
nsCOMPtr<nsIDocument> rootDoc = do_GetInterface(sameTypeRoot);
NS_ASSERTION(rootDoc, "No root document from document shell root tree item.");
// nsCOMPtr<nsIScriptObjectPrincipal> prin = do_QueryInterface(rootDoc);
// nsCOMPtr<nsIPrincipal> rootPrincipal = prin->GetPrincipal();
nsCOMPtr<nsIPrincipal> rootPrincipal = rootDoc->NodePrincipal();
NS_ASSERTION(rootPrincipal, "No root principal from root document");
nsCOMPtr<nsIURI> rootUri;
rootPrincipal->GetURI(getter_AddRefs(rootUri));
NS_ASSERTION(rootUri, "No root uri from root principal");
nsresult rv = rootUri->SchemeIs("https", aRootHasSecureConnection);
NS_ENSURE_SUCCESS(rv, rv);
// For things with system principal (e.g. scratchpad) there is no uri
// aRootHasSecureConnection should remain false.
if (!nsContentUtils::IsSystemPrincipal(rootPrincipal)) {
nsCOMPtr<nsIURI> rootUri;
rootPrincipal->GetURI(getter_AddRefs(rootUri));
NS_ASSERTION(rootUri, "No root uri from root principal");
nsresult rv = rootUri->SchemeIs("https", aRootHasSecureConnection);
NS_ENSURE_SUCCESS(rv, rv);
}
// Check the root doc's channel against the root docShell's mMixedContentChannel to see
// if they are the same. If they are the same, the user has overriden
@ -9406,7 +9412,7 @@ nsDocShell::DoURILoad(nsIURI * aURI,
}
}
if (mLoadType == LOAD_MIXED_CONTENT) {
if (mLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT) {
rv = SetMixedContentChannel(channel);
NS_ENSURE_SUCCESS(rv, rv);
} else {
@ -9681,6 +9687,7 @@ nsresult nsDocShell::DoChannelLoad(nsIChannel * aChannel,
case LOAD_RELOAD_BYPASS_CACHE:
case LOAD_RELOAD_BYPASS_PROXY:
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
case LOAD_REPLACE_BYPASS_CACHE:
loadFlags |= nsIRequest::LOAD_BYPASS_CACHE |
nsIRequest::LOAD_FRESH_CONNECTION;
@ -9978,7 +9985,8 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
if (aChannel &&
(aLoadType == LOAD_RELOAD_BYPASS_CACHE ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY ||
aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE)) {
aLoadType == LOAD_RELOAD_BYPASS_PROXY_AND_CACHE ||
aLoadType == LOAD_RELOAD_ALLOW_MIXED_CONTENT)) {
NS_ASSERTION(!updateSHistory,
"We shouldn't be updating session history for forced"
" reloads!");

Просмотреть файл

@ -745,7 +745,7 @@ protected:
nsCOMPtr<nsIChannel> mFailedChannel;
uint32_t mFailedLoadType;
// Set in DoURILoad when the LOAD_MIXED_CONTENT flag is set.
// Set in DoURILoad when the LOAD_RELOAD_ALLOW_MIXED_CONTENT flag is set.
// Checked in nsMixedContentBlocker, to see if the channels match.
nsCOMPtr<nsIChannel> mMixedContentChannel;

Просмотреть файл

@ -51,6 +51,7 @@ enum LoadType {
LOAD_RELOAD_NORMAL = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_NONE),
LOAD_RELOAD_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
LOAD_RELOAD_BYPASS_PROXY = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
LOAD_RELOAD_ALLOW_MIXED_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_ALLOW_MIXED_CONTENT | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
LOAD_RELOAD_BYPASS_PROXY_AND_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_RELOAD, nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY),
LOAD_LINK = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_LINK),
LOAD_REFRESH = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_IS_REFRESH),
@ -60,7 +61,6 @@ enum LoadType {
LOAD_STOP_CONTENT_AND_REPLACE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_STOP_CONTENT | nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY),
LOAD_PUSHSTATE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_PUSHSTATE, nsIWebNavigation::LOAD_FLAGS_NONE),
LOAD_REPLACE_BYPASS_CACHE = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY | nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE),
LOAD_MIXED_CONTENT = MAKE_LOAD_TYPE(nsIDocShell::LOAD_CMD_NORMAL, nsIWebNavigation::LOAD_FLAGS_ALLOW_MIXED_CONTENT),
/**
* Load type for an error page. These loads are never triggered by users of
* Docshell. Instead, Docshell triggers the load itself when a
@ -85,6 +85,7 @@ static inline bool IsValidLoadType(uint32_t aLoadType)
case LOAD_RELOAD_BYPASS_CACHE:
case LOAD_RELOAD_BYPASS_PROXY:
case LOAD_RELOAD_BYPASS_PROXY_AND_CACHE:
case LOAD_RELOAD_ALLOW_MIXED_CONTENT:
case LOAD_LINK:
case LOAD_REFRESH:
case LOAD_RELOAD_CHARSET_CHANGE:
@ -93,7 +94,6 @@ static inline bool IsValidLoadType(uint32_t aLoadType)
case LOAD_STOP_CONTENT_AND_REPLACE:
case LOAD_PUSHSTATE:
case LOAD_REPLACE_BYPASS_CACHE:
case LOAD_MIXED_CONTENT:
case LOAD_ERROR_PAGE:
return true;
}

Просмотреть файл

@ -738,9 +738,10 @@ interface nsIDocShell : nsISupports
* Checks whether the channel associated with the root docShell is equal to
* mMixedContentChannel. If they are the same, allowMixedContent is set to true.
* Checks if the root document has a secure connection. If it is, sets
* rootHasSecureConnection to true.
* rootHasSecureConnection to true. If the docShell is the root doc shell,
* isRootDocShell is set to true.
*/
void GetAllowMixedContentAndConnectionData(out boolean rootHasSecureConnection, out boolean allowMixedContent);
void GetAllowMixedContentAndConnectionData(out boolean rootHasSecureConnection, out boolean allowMixedContent, out boolean isRootDocShell);
/**