Bug 444641 part 1. Factor out IsAboutBlank into nsNetUtil.h. r=jduell,jst

This commit is contained in:
Boris Zbarsky 2011-09-20 17:00:41 -04:00
Родитель bdfb5248f3
Коммит 73cb28130e
5 изменённых файлов: 26 добавлений и 62 удалений

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

@ -1130,23 +1130,6 @@ nsObjectLoadingContent::LoadObject(const nsAString& aURI,
return LoadObject(uri, aNotify, aTypeHint, aForceLoad);
}
static PRBool
IsAboutBlank(nsIURI* aURI)
{
// XXXbz this duplicates an nsDocShell function, sadly
NS_PRECONDITION(aURI, "Must have URI");
// GetSpec can be expensive for some URIs, so check the scheme first.
PRBool isAbout = PR_FALSE;
if (NS_FAILED(aURI->SchemeIs("about", &isAbout)) || !isAbout) {
return PR_FALSE;
}
nsCAutoString str;
aURI->GetSpec(str);
return str.EqualsLiteral("about:blank");
}
void
nsObjectLoadingContent::UpdateFallbackState(nsIContent* aContent,
AutoFallback& fallback,
@ -1465,7 +1448,7 @@ nsObjectLoadingContent::LoadObject(nsIURI* aURI,
nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
&inheritPrincipal);
NS_ENSURE_SUCCESS(rv, rv);
if (inheritPrincipal || IsAboutBlank(aURI) ||
if (inheritPrincipal || NS_IsAboutBlank(aURI) ||
(nsContentUtils::URIIsLocalFile(aURI) &&
NS_SUCCEEDED(thisContent->NodePrincipal()->CheckMayLoad(aURI,
PR_FALSE)))) {

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

@ -8186,7 +8186,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
// Except we reverse the rv check to be safe in case
// URIInheritsSecurityContext fails here and succeeds there.
rv = URIInheritsSecurityContext(aURI, &willInherit);
if (NS_FAILED(rv) || willInherit || IsAboutBlank(aURI)) {
if (NS_FAILED(rv) || willInherit || NS_IsAboutBlank(aURI)) {
nsCOMPtr<nsIDocShellTreeItem> treeItem = this;
do {
nsCOMPtr<nsIDocShell> itemDocShell =
@ -9020,11 +9020,11 @@ nsDocShell::DoURILoad(nsIURI * aURI,
// accordingly.
PRBool inherit;
// We expect URIInheritsSecurityContext to return success for an
// about:blank URI, so don't call IsAboutBlank() if this call fails.
// about:blank URI, so don't call NS_IsAboutBlank() if this call fails.
// This condition needs to match the one in InternalLoad where
// we're checking for things that will use the owner.
rv = URIInheritsSecurityContext(aURI, &inherit);
if (NS_SUCCEEDED(rv) && (inherit || IsAboutBlank(aURI))) {
if (NS_SUCCEEDED(rv) && (inherit || NS_IsAboutBlank(aURI))) {
channel->SetOwner(aOwner);
}
@ -9452,7 +9452,7 @@ nsDocShell::OnNewURI(nsIURI * aURI, nsIChannel * aChannel, nsISupports* aOwner,
shAvailable, updateHistory, equalUri));
if (shAvailable && mCurrentURI && !mOSHE && aLoadType != LOAD_ERROR_PAGE) {
NS_ASSERTION(IsAboutBlank(mCurrentURI), "no SHEntry for a non-transient viewer?");
NS_ASSERTION(NS_IsAboutBlank(mCurrentURI), "no SHEntry for a non-transient viewer?");
}
#endif
@ -11275,23 +11275,6 @@ nsDocShell::URIIsLocalFile(nsIURI *aURI)
isFile;
}
/* static */
PRBool
nsDocShell::IsAboutBlank(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Must have URI");
// GetSpec can be expensive for some URIs, so check the scheme first.
PRBool isAbout = PR_FALSE;
if (NS_FAILED(aURI->SchemeIs("about", &isAbout)) || !isAbout) {
return PR_FALSE;
}
nsCAutoString str;
aURI->GetSpec(str);
return str.EqualsLiteral("about:blank");
}
PRBool
nsDocShell::IsOKToLoadURI(nsIURI* aURI)
{

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

@ -656,9 +656,6 @@ protected:
// Check whether aURI is a URI_IS_LOCAL_FILE or not
static PRBool URIIsLocalFile(nsIURI *aURI);
// Check whether aURI is about:blank
static PRBool IsAboutBlank(nsIURI* aURI);
// Call this when a URI load is handed to us (via OnLinkClick or
// InternalLoad). This makes sure that we're not inside unload, or that if
// we are it's still OK to load this URI.

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

@ -433,22 +433,6 @@ static const char kPkcs11ContractID[] = NS_PKCS11_CONTRACTID;
#endif
static const char sPopStatePrefStr[] = "browser.history.allowPopState";
static PRBool
IsAboutBlank(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Must have URI");
// GetSpec can be expensive for some URIs, so check the scheme first.
PRBool isAbout = PR_FALSE;
if (NS_FAILED(aURI->SchemeIs("about", &isAbout)) || !isAbout) {
return PR_FALSE;
}
nsCAutoString str;
aURI->GetSpec(str);
return str.EqualsLiteral("about:blank");
}
class nsDummyJavaPluginOwner : public nsIPluginInstanceOwner
{
public:
@ -1615,7 +1599,7 @@ nsGlobalWindow::WouldReuseInnerWindow(nsIDocument *aNewDocument)
return PR_FALSE;
}
NS_ASSERTION(IsAboutBlank(mDoc->GetDocumentURI()),
NS_ASSERTION(NS_IsAboutBlank(mDoc->GetDocumentURI()),
"How'd this happen?");
// Great, we're the original document, check for one of the other
@ -1664,8 +1648,8 @@ nsGlobalWindow::SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal)
// something is really weird.
nsCOMPtr<nsIURI> uri;
mDoc->NodePrincipal()->GetURI(getter_AddRefs(uri));
NS_ASSERTION(uri && IsAboutBlank(uri) &&
IsAboutBlank(mDoc->GetDocumentURI()),
NS_ASSERTION(uri && NS_IsAboutBlank(uri) &&
NS_IsAboutBlank(mDoc->GetDocumentURI()),
"Unexpected original document");
#endif
@ -5013,7 +4997,7 @@ nsGlobalWindow::Focus()
NS_ASSERTION(doc, "Bogus doc?");
nsIURI* ourURI = doc->GetDocumentURI();
if (ourURI) {
lookForPresShell = !IsAboutBlank(ourURI);
lookForPresShell = !NS_IsAboutBlank(ourURI);
}
}

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

@ -2013,4 +2013,21 @@ net_EnsurePSMInit()
}
}
/**
* Test whether a URI is "about:blank". |uri| must not be null
*/
inline bool
NS_IsAboutBlank(nsIURI *uri)
{
// GetSpec can be expensive for some URIs, so check the scheme first.
PRBool isAbout = PR_FALSE;
if (NS_FAILED(uri->SchemeIs("about", &isAbout)) || !isAbout) {
return false;
}
nsCAutoString str;
uri->GetSpec(str);
return str.EqualsLiteral("about:blank");
}
#endif // !nsNetUtil_h__