Bug 455070 - Make sessionStorage object conform the WHATWG spec, r+sr=jst
This commit is contained in:
@@ -54,6 +54,7 @@
|
||||
#include "nsIDOMNSDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMStorageObsolete.h"
|
||||
#include "nsIDOMStorage.h"
|
||||
#include "nsPIDOMStorage.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIDocumentLoaderFactory.h"
|
||||
@@ -853,7 +854,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsILoadContext)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDocShell_MOZILLA_1_9_1)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
||||
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIClipboardCommands)
|
||||
@@ -2143,7 +2143,7 @@ nsDocShell::HistoryPurged(PRInt32 aNumEntries)
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetSessionStorageForPrincipal(nsIPrincipal* aPrincipal,
|
||||
PRBool aCreate,
|
||||
nsIDOMStorageObsolete** aStorage)
|
||||
nsIDOMStorage** aStorage)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aStorage);
|
||||
*aStorage = nsnull;
|
||||
@@ -2151,19 +2151,46 @@ nsDocShell::GetSessionStorageForPrincipal(nsIPrincipal* aPrincipal,
|
||||
if (!aPrincipal)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> codebaseURI;
|
||||
nsresult rv = aPrincipal->GetDomain(getter_AddRefs(codebaseURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (!codebaseURI) {
|
||||
rv = aPrincipal->GetURI(getter_AddRefs(codebaseURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
nsresult rv;
|
||||
|
||||
if (!codebaseURI)
|
||||
nsCOMPtr<nsIDocShellTreeItem> topItem;
|
||||
rv = GetSameTypeRootTreeItem(getter_AddRefs(topItem));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!topItem)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDocShell* topDocShell = static_cast<nsDocShell*>(topItem.get());
|
||||
if (topDocShell != this)
|
||||
return topDocShell->GetSessionStorageForPrincipal(aPrincipal, aCreate,
|
||||
aStorage);
|
||||
|
||||
nsXPIDLCString origin;
|
||||
rv = aPrincipal->GetOrigin(getter_Copies(origin));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (origin.IsEmpty())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if (!mStorages.Get(origin, aStorage) && aCreate) {
|
||||
nsCOMPtr<nsIDOMStorage> newstorage =
|
||||
do_CreateInstance("@mozilla.org/dom/storage;2");
|
||||
if (!newstorage)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsPIDOMStorage> pistorage = do_QueryInterface(newstorage);
|
||||
if (!pistorage)
|
||||
return NS_ERROR_FAILURE;
|
||||
pistorage->InitAsSessionStorage(aPrincipal);
|
||||
|
||||
if (!mStorages.Put(origin, newstorage))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
newstorage.swap(*aStorage);
|
||||
return NS_OK;
|
||||
|
||||
rv = GetSessionStorageForURI(codebaseURI, aCreate, aStorage);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMStorage> piStorage = do_QueryInterface(*aStorage);
|
||||
if (piStorage) {
|
||||
@@ -2182,7 +2209,7 @@ nsDocShell::GetSessionStorageForPrincipal(nsIPrincipal* aPrincipal,
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetSessionStorageForURI(nsIURI* aURI,
|
||||
nsIDOMStorageObsolete** aStorage)
|
||||
nsIDOMStorage** aStorage)
|
||||
{
|
||||
return GetSessionStorageForURI(aURI, PR_TRUE, aStorage);
|
||||
}
|
||||
@@ -2190,64 +2217,35 @@ nsDocShell::GetSessionStorageForURI(nsIURI* aURI,
|
||||
nsresult
|
||||
nsDocShell::GetSessionStorageForURI(nsIURI* aURI,
|
||||
PRBool aCreate,
|
||||
nsIDOMStorageObsolete** aStorage)
|
||||
nsIDOMStorage** aStorage)
|
||||
{
|
||||
NS_ENSURE_ARG(aURI);
|
||||
NS_ENSURE_ARG_POINTER(aStorage);
|
||||
|
||||
*aStorage = nsnull;
|
||||
|
||||
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
||||
NS_ASSERTION(innerURI, "Failed to get innermost URI");
|
||||
if (!innerURI)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> topItem;
|
||||
nsresult rv = GetSameTypeRootTreeItem(getter_AddRefs(topItem));
|
||||
nsCOMPtr<nsIScriptSecurityManager> securityManager =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// This is terrible hack and should go away along with this whole method.
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
rv = securityManager->GetCodebasePrincipal(aURI, getter_AddRefs(principal));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!topItem)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsDocShell* topDocShell = static_cast<nsDocShell*>(topItem.get());
|
||||
if (topDocShell != this)
|
||||
return topDocShell->GetSessionStorageForURI(aURI, aCreate, aStorage);
|
||||
|
||||
nsCAutoString currentDomain;
|
||||
rv = innerURI->GetAsciiHost(currentDomain);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (currentDomain.IsEmpty())
|
||||
return NS_OK;
|
||||
|
||||
if (!mStorages.Get(currentDomain, aStorage) && aCreate) {
|
||||
nsCOMPtr<nsIDOMStorageObsolete> newstorage =
|
||||
do_CreateInstance("@mozilla.org/dom/storage;1");
|
||||
if (!newstorage)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsPIDOMStorage> pistorage = do_QueryInterface(newstorage);
|
||||
if (!pistorage)
|
||||
return NS_ERROR_FAILURE;
|
||||
pistorage->InitAsSessionStorage(aURI);
|
||||
|
||||
if (!mStorages.Put(currentDomain, newstorage))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
newstorage.swap(*aStorage);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
return GetSessionStorageForPrincipal(principal, aCreate, aStorage);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocShell::AddSessionStorage(const nsACString& aDomain,
|
||||
nsIDOMStorageObsolete* aStorage)
|
||||
nsDocShell::AddSessionStorage(nsIPrincipal* aPrincipal,
|
||||
nsIDOMStorage* aStorage)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aStorage);
|
||||
|
||||
if (aDomain.IsEmpty())
|
||||
if (!aPrincipal)
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIDocShellTreeItem> topItem;
|
||||
@@ -2258,15 +2256,23 @@ nsDocShell::AddSessionStorage(const nsACString& aDomain,
|
||||
if (topItem) {
|
||||
nsCOMPtr<nsIDocShell> topDocShell = do_QueryInterface(topItem);
|
||||
if (topDocShell == this) {
|
||||
nsXPIDLCString origin;
|
||||
rv = aPrincipal->GetOrigin(getter_Copies(origin));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (origin.IsEmpty())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
// Do not replace an existing session storage.
|
||||
if (mStorages.GetWeak(aDomain))
|
||||
if (mStorages.GetWeak(origin))
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!mStorages.Put(aDomain, aStorage))
|
||||
if (!mStorages.Put(origin, aStorage))
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
return topDocShell->AddSessionStorage(aDomain, aStorage);
|
||||
return topDocShell->AddSessionStorage(aPrincipal, aStorage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user