From 2b39cc7aa42e4177d783f11faa8529fa31743bf8 Mon Sep 17 00:00:00 2001 From: "mvl%exedo.nl" Date: Fri, 10 Oct 2003 15:08:43 +0000 Subject: [PATCH] Try the scheme if no host is found when showing a cookie dialog. bug 209689, r=dwitte, sr=darin git-svn-id: svn://10.0.0.236/trunk@147838 18797224-902f-48f8-a5cc-f745e15eee43 --- .../extensions/cookie/nsCookiePermission.cpp | 16 +++++++- .../extensions/cookie/nsPermissionManager.cpp | 37 +++++++++++++------ .../extensions/cookie/nsPermissionManager.h | 1 + 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/mozilla/extensions/cookie/nsCookiePermission.cpp b/mozilla/extensions/cookie/nsCookiePermission.cpp index 238b5e4c27b..2f780391b0d 100644 --- a/mozilla/extensions/cookie/nsCookiePermission.cpp +++ b/mozilla/extensions/cookie/nsCookiePermission.cpp @@ -89,8 +89,20 @@ nsCookiePermission::TestPermission(nsIURI *aURI, nsCAutoString hostPort; aURI->GetHostPort(hostPort); - if (!aCookie || hostPort.IsEmpty()) { - return NS_ERROR_UNEXPECTED; + if (!aCookie) { + return NS_ERROR_UNEXPECTED; + } + // If there is no host, use the scheme, and append "://", + // to make sure it isn't a host or something. + // This is done to make the dialog appear for javascript cookies from + // file:// urls, and make the text on it not too weird. (bug 209689) + if (hostPort.IsEmpty()) { + aURI->GetScheme(hostPort); + if (hostPort.IsEmpty()) { + // still empty. Just return the default. + return NS_OK; + } + hostPort = hostPort + NS_LITERAL_CSTRING("://"); } // we don't cache the cookiePromptService - it's not used often, so not diff --git a/mozilla/extensions/cookie/nsPermissionManager.cpp b/mozilla/extensions/cookie/nsPermissionManager.cpp index 604b590ae7b..b27314e0f5a 100644 --- a/mozilla/extensions/cookie/nsPermissionManager.cpp +++ b/mozilla/extensions/cookie/nsPermissionManager.cpp @@ -155,7 +155,7 @@ nsPermissionEnumerator::Prefetch() if (entry) { // see if we've found it permission = entry->GetPermission(mTypeIndex); - if (permission != nsIPermissionManager::UNKNOWN_ACTION) { + if (permission != nsIPermissionManager::UNKNOWN_ACTION && mTypeArray[mTypeIndex]) { mNextPermission = new nsPermission(entry->GetHost(), nsDependentCString(mTypeArray[mTypeIndex]), permission); @@ -229,11 +229,9 @@ nsPermissionManager::Add(nsIURI *aURI, nsresult rv; nsCAutoString hostPort; - aURI->GetHostPort(hostPort); - if (hostPort.IsEmpty()) { - // Nothing to add - return NS_OK; - } + rv = GetHostPort(aURI, hostPort); + // no host doesn't mean an error. just return the default + if (NS_FAILED(rv)) return NS_OK; PRInt32 typeIndex = GetTypeIndex(aType, PR_TRUE); if (typeIndex == -1 || aPermission >= NUMBER_OF_PERMISSIONS) @@ -329,11 +327,9 @@ nsPermissionManager::TestPermission(nsIURI *aURI, *aPermission = nsIPermissionManager::UNKNOWN_ACTION; nsCAutoString hostPort; - aURI->GetHostPort(hostPort); - // Don't error on no host. Just return UNKNOWN_ACTION as permission. - if (hostPort.IsEmpty()) { - return NS_OK; - } + nsresult rv = GetHostPort(aURI, hostPort); + // no host doesn't mean an error. just return the default + if (NS_FAILED(rv)) return NS_OK; PRInt32 typeIndex = GetTypeIndex(aType, PR_FALSE); // If type == -1, the type isn't known, @@ -781,3 +777,22 @@ nsPermissionManager::Write() return NS_OK; } +nsresult +nsPermissionManager::GetHostPort(nsIURI *aURI, nsACString &aResult) +{ + NS_ASSERTION(aURI, "could not get uri"); + + aURI->GetHostPort(aResult); + + // If there is no host, use the scheme, and prepend "scheme:", + // to make sure it isn't a host or something. + if (aResult.IsEmpty()) { + aURI->GetScheme(aResult); + if (aResult.IsEmpty()) { + // still empty. Return error. + return NS_ERROR_FAILURE; + } + aResult = NS_LITERAL_CSTRING("scheme:") + aResult; + } + return NS_OK; +} diff --git a/mozilla/extensions/cookie/nsPermissionManager.h b/mozilla/extensions/cookie/nsPermissionManager.h index 13a357e37e8..5eec4a3ed7d 100644 --- a/mozilla/extensions/cookie/nsPermissionManager.h +++ b/mozilla/extensions/cookie/nsPermissionManager.h @@ -168,6 +168,7 @@ private: nsresult Write(); nsresult NotifyObservers(const nsACString &aHost); nsresult RemoveAllFromMemory(); + nsresult GetHostPort(nsIURI *aURI, nsACString &aResult); void RemoveTypeStrings(); nsCOMPtr mObserverService;