From 6591455ded789a004a69bb3ae46135f08d263700 Mon Sep 17 00:00:00 2001 From: Tanvi Vyas Date: Wed, 30 Jan 2013 00:04:34 -0800 Subject: [PATCH] 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 --- accessible/src/base/DocManager.cpp | 3 +- accessible/src/base/Logging.cpp | 3 ++ content/base/src/nsMixedContentBlocker.cpp | 3 +- content/html/document/src/nsHTMLDocument.cpp | 10 ++++ docshell/base/nsDocShell.cpp | 54 +++++++++++--------- docshell/base/nsDocShell.h | 2 +- docshell/base/nsDocShellLoadTypes.h | 4 +- docshell/base/nsIDocShell.idl | 5 +- 8 files changed, 54 insertions(+), 30 deletions(-) diff --git a/accessible/src/base/DocManager.cpp b/accessible/src/base/DocManager.cpp index f9d4a852741f..dfee8c4f51c9 100644 --- a/accessible/src/base/DocManager.cpp +++ b/accessible/src/base/DocManager.cpp @@ -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; } diff --git a/accessible/src/base/Logging.cpp b/accessible/src/base/Logging.cpp index 5cd61a971b76..d19cb39bf1eb 100644 --- a/accessible/src/base/Logging.cpp +++ b/accessible/src/base/Logging.cpp @@ -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; diff --git a/content/base/src/nsMixedContentBlocker.cpp b/content/base/src/nsMixedContentBlocker.cpp index f773a70827c1..2d2870edb604 100644 --- a/content/base/src/nsMixedContentBlocker.cpp +++ b/content/base/src/nsMixedContentBlocker.cpp @@ -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; } diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index b0cb469bc0a6..ae0c88a18981 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -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, diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 2f52b84bad57..3c8cd50cee7f 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -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 root; - GetSameTypeRootTreeItem(getter_AddRefs(root)); - NS_WARN_IF_FALSE( - root.get() == static_cast(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 root; + GetSameTypeRootTreeItem(getter_AddRefs(root)); + NS_WARN_IF_FALSE( + root.get() == static_cast(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 currentDocShellTreeItem = static_cast(this); - NS_ASSERTION(currentDocShellTreeItem, "No DocShellTreeItem from docshell"); + *aIsRootDocShell = false; nsCOMPtr 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(this); // now get the document from sameTypeRoot nsCOMPtr rootDoc = do_GetInterface(sameTypeRoot); NS_ASSERTION(rootDoc, "No root document from document shell root tree item."); -// nsCOMPtr prin = do_QueryInterface(rootDoc); -// nsCOMPtr rootPrincipal = prin->GetPrincipal(); nsCOMPtr rootPrincipal = rootDoc->NodePrincipal(); NS_ASSERTION(rootPrincipal, "No root principal from root document"); - nsCOMPtr 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 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!"); diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index 24d3fe0538f1..1500501e0e4c 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -745,7 +745,7 @@ protected: nsCOMPtr 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 mMixedContentChannel; diff --git a/docshell/base/nsDocShellLoadTypes.h b/docshell/base/nsDocShellLoadTypes.h index 3477e3bdce2f..2cedaa734f7a 100644 --- a/docshell/base/nsDocShellLoadTypes.h +++ b/docshell/base/nsDocShellLoadTypes.h @@ -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; } diff --git a/docshell/base/nsIDocShell.idl b/docshell/base/nsIDocShell.idl index 2009c655b272..72bbe59fc1f4 100644 --- a/docshell/base/nsIDocShell.idl +++ b/docshell/base/nsIDocShell.idl @@ -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); /**