Bug 1486932 part 1. Stop using nsIDOMStorage in xpidl APIs. r=mccr8

This commit is contained in:
Boris Zbarsky 2018-08-31 13:56:54 -04:00
Родитель b1bedbb3e3
Коммит 1fcc87c931
9 изменённых файлов: 46 добавлений и 49 удалений

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

@ -4308,14 +4308,13 @@ nsDOMWindowUtils::RemoveManuallyManagedState(Element* aElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDOMWindowUtils::GetStorageUsage(nsIDOMStorage* aStorage, int64_t* aRetval) nsDOMWindowUtils::GetStorageUsage(Storage* aStorage, int64_t* aRetval)
{ {
RefPtr<Storage> storage = static_cast<Storage*>(aStorage); if (!aStorage) {
if (!storage) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
*aRetval = storage->GetOriginQuotaUsage(); *aRetval = aStorage->GetOriginQuotaUsage();
return NS_OK; return NS_OK;
} }

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

@ -4795,7 +4795,7 @@ nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError)
return nullptr; return nullptr;
} }
nsCOMPtr<nsIDOMStorage> storage; RefPtr<Storage> storage;
aError = storageManager->CreateStorage(this, principal, documentURI, aError = storageManager->CreateStorage(this, principal, documentURI,
IsPrivateBrowsing(), IsPrivateBrowsing(),
getter_AddRefs(storage)); getter_AddRefs(storage));
@ -4803,7 +4803,7 @@ nsGlobalWindowInner::GetSessionStorage(ErrorResult& aError)
return nullptr; return nullptr;
} }
mSessionStorage = static_cast<Storage*>(storage.get()); mSessionStorage = storage;
MOZ_ASSERT(mSessionStorage); MOZ_ASSERT(mSessionStorage);
MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug, MOZ_LOG(gDOMLeakPRLogInner, LogLevel::Debug,
@ -4856,7 +4856,7 @@ nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError)
} }
} }
nsCOMPtr<nsIDOMStorage> storage; RefPtr<Storage> storage;
aError = storageManager->CreateStorage(this, principal, documentURI, aError = storageManager->CreateStorage(this, principal, documentURI,
IsPrivateBrowsing(), IsPrivateBrowsing(),
getter_AddRefs(storage)); getter_AddRefs(storage));
@ -4864,7 +4864,7 @@ nsGlobalWindowInner::GetLocalStorage(ErrorResult& aError)
return nullptr; return nullptr;
} }
mLocalStorage = static_cast<Storage*>(storage.get()); mLocalStorage = storage;
MOZ_ASSERT(mLocalStorage); MOZ_ASSERT(mLocalStorage);
} }
@ -5684,7 +5684,7 @@ nsGlobalWindowInner::ObserveStorageNotification(StorageEvent* aEvent,
eventType.AssignLiteral("storage"); eventType.AssignLiteral("storage");
if (!NS_strcmp(aStorageType, u"sessionStorage")) { if (!NS_strcmp(aStorageType, u"sessionStorage")) {
nsCOMPtr<nsIDOMStorage> changingStorage = aEvent->GetStorageArea(); RefPtr<Storage> changingStorage = aEvent->GetStorageArea();
MOZ_ASSERT(changingStorage); MOZ_ASSERT(changingStorage);
bool check = false; bool check = false;

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

@ -2046,10 +2046,10 @@ nsGlobalWindowOuter::PreloadLocalStorage()
// private browsing windows do not persist local storage to disk so we should // private browsing windows do not persist local storage to disk so we should
// only try to precache storage when we're not a private browsing window. // only try to precache storage when we're not a private browsing window.
if (principal->GetPrivateBrowsingId() == 0) { if (principal->GetPrivateBrowsingId() == 0) {
nsCOMPtr<nsIDOMStorage> storage; RefPtr<Storage> storage;
rv = storageManager->PrecacheStorage(principal, getter_AddRefs(storage)); rv = storageManager->PrecacheStorage(principal, getter_AddRefs(storage));
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
mLocalStorage = static_cast<Storage*>(storage.get()); mLocalStorage = storage;
} }
} }
} }

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

@ -42,7 +42,6 @@ interface nsITranslationNodeList;
interface nsIJSRAIIHelper; interface nsIJSRAIIHelper;
interface nsIContentPermissionRequest; interface nsIContentPermissionRequest;
interface nsIObserver; interface nsIObserver;
interface nsIDOMStorage;
webidl Animation; webidl Animation;
webidl DOMRect; webidl DOMRect;
@ -51,6 +50,7 @@ webidl EventTarget;
webidl Event; webidl Event;
webidl Node; webidl Node;
webidl NodeList; webidl NodeList;
webidl Storage;
[scriptable, uuid(4d6732ca-9da7-4176-b8a1-8dde15cd0bf9)] [scriptable, uuid(4d6732ca-9da7-4176-b8a1-8dde15cd0bf9)]
interface nsIDOMWindowUtils : nsISupports { interface nsIDOMWindowUtils : nsISupports {
@ -1901,7 +1901,7 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aStorage * @param aStorage
* The storage object to get usage data for. * The storage object to get usage data for.
*/ */
int64_t getStorageUsage(in nsIDOMStorage aStorage); int64_t getStorageUsage(in Storage aStorage);
/** /**
* Returns the directionality of a string using the first-strong character * Returns the directionality of a string using the first-strong character

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

@ -5,10 +5,11 @@
#include "nsISupports.idl" #include "nsISupports.idl"
interface nsIDOMStorage;
interface nsIPrincipal; interface nsIPrincipal;
interface mozIDOMWindow; interface mozIDOMWindow;
webidl Storage;
/** /**
* General purpose interface that has two implementations, for localStorage * General purpose interface that has two implementations, for localStorage
* resp. sessionStorage with "@mozilla.org/dom/localStorage-manager;1" resp. * resp. sessionStorage with "@mozilla.org/dom/localStorage-manager;1" resp.
@ -28,7 +29,7 @@ interface nsIDOMStorageManager : nsISupports
* existence and kept alive by the timer so that it could be returned if a * existence and kept alive by the timer so that it could be returned if a
* call to createStorage was made due to a request by the page.) * call to createStorage was made due to a request by the page.)
*/ */
nsIDOMStorage precacheStorage(in nsIPrincipal aPrincipal); Storage precacheStorage(in nsIPrincipal aPrincipal);
/** /**
* Returns instance of DOM storage object for given principal. * Returns instance of DOM storage object for given principal.
@ -44,7 +45,7 @@ interface nsIDOMStorageManager : nsISupports
* @param aPrivate * @param aPrivate
* Whether the demanding document is running in Private Browsing mode or not. * Whether the demanding document is running in Private Browsing mode or not.
*/ */
nsIDOMStorage createStorage(in mozIDOMWindow aWindow, Storage createStorage(in mozIDOMWindow aWindow,
in nsIPrincipal aPrincipal, in nsIPrincipal aPrincipal,
in DOMString aDocumentURI, in DOMString aDocumentURI,
[optional] in bool aPrivate); [optional] in bool aPrivate);
@ -61,7 +62,7 @@ interface nsIDOMStorageManager : nsISupports
* @param aPrivate * @param aPrivate
* Whether the demanding document is running in Private Browsing mode or not. * Whether the demanding document is running in Private Browsing mode or not.
*/ */
nsIDOMStorage getStorage(in mozIDOMWindow aWindow, Storage getStorage(in mozIDOMWindow aWindow,
in nsIPrincipal aPrincipal, in nsIPrincipal aPrincipal,
[optional] in bool aPrivate); [optional] in bool aPrivate);
@ -74,7 +75,7 @@ interface nsIDOMStorageManager : nsISupports
* the moment this method was called. Modification to this new object will * the moment this method was called. Modification to this new object will
* not affect the original storage content we cloned from and vice versa. * not affect the original storage content we cloned from and vice versa.
*/ */
void cloneStorage(in nsIDOMStorage aStorageToCloneFrom); void cloneStorage(in Storage aStorageToCloneFrom);
/** /**
* Returns true if the storage belongs to the given principal and is managed * Returns true if the storage belongs to the given principal and is managed
@ -91,5 +92,5 @@ interface nsIDOMStorageManager : nsISupports
* false otherwise * false otherwise
*/ */
bool checkStorage(in nsIPrincipal aPrincipal, bool checkStorage(in nsIPrincipal aPrincipal,
in nsIDOMStorage aStorage); in Storage aStorage);
}; };

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

@ -212,7 +212,7 @@ LocalStorageManager::GetStorageInternal(CreateMode aCreateMode,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
const nsAString& aDocumentURI, const nsAString& aDocumentURI,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
nsAutoCString originAttrSuffix; nsAutoCString originAttrSuffix;
nsAutoCString originKey; nsAutoCString originKey;
@ -287,7 +287,7 @@ LocalStorageManager::GetStorageInternal(CreateMode aCreateMode,
if (aRetval) { if (aRetval) {
nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow); nsCOMPtr<nsPIDOMWindowInner> inner = nsPIDOMWindowInner::From(aWindow);
nsCOMPtr<nsIDOMStorage> storage = new LocalStorage( RefPtr<Storage> storage = new LocalStorage(
inner, this, cache, aDocumentURI, aPrincipal, aPrivate); inner, this, cache, aDocumentURI, aPrincipal, aPrivate);
storage.forget(aRetval); storage.forget(aRetval);
} }
@ -297,7 +297,7 @@ LocalStorageManager::GetStorageInternal(CreateMode aCreateMode,
NS_IMETHODIMP NS_IMETHODIMP
LocalStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal, LocalStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
return GetStorageInternal(CreateMode::CreateIfShouldPreload, nullptr, return GetStorageInternal(CreateMode::CreateIfShouldPreload, nullptr,
aPrincipal, EmptyString(), false, aRetval); aPrincipal, EmptyString(), false, aRetval);
@ -308,7 +308,7 @@ LocalStorageManager::CreateStorage(mozIDOMWindow* aWindow,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
const nsAString& aDocumentURI, const nsAString& aDocumentURI,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
return GetStorageInternal(CreateMode::CreateAlways, aWindow, aPrincipal, return GetStorageInternal(CreateMode::CreateAlways, aWindow, aPrincipal,
aDocumentURI, aPrivate, aRetval); aDocumentURI, aPrivate, aRetval);
@ -318,14 +318,14 @@ NS_IMETHODIMP
LocalStorageManager::GetStorage(mozIDOMWindow* aWindow, LocalStorageManager::GetStorage(mozIDOMWindow* aWindow,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
return GetStorageInternal(CreateMode::UseIfExistsNeverCreate, aWindow, return GetStorageInternal(CreateMode::UseIfExistsNeverCreate, aWindow,
aPrincipal, EmptyString(), aPrivate, aRetval); aPrincipal, EmptyString(), aPrivate, aRetval);
} }
NS_IMETHODIMP NS_IMETHODIMP
LocalStorageManager::CloneStorage(nsIDOMStorage* aStorage) LocalStorageManager::CloneStorage(Storage* aStorage)
{ {
// Cloning is supported only for sessionStorage // Cloning is supported only for sessionStorage
return NS_ERROR_NOT_IMPLEMENTED; return NS_ERROR_NOT_IMPLEMENTED;
@ -333,16 +333,15 @@ LocalStorageManager::CloneStorage(nsIDOMStorage* aStorage)
NS_IMETHODIMP NS_IMETHODIMP
LocalStorageManager::CheckStorage(nsIPrincipal* aPrincipal, LocalStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
nsIDOMStorage* aStorage, Storage* aStorage,
bool* aRetval) bool* aRetval)
{ {
nsresult rv; if (!aStorage || aStorage->Type() != Storage::eLocalStorage) {
RefPtr<LocalStorage> storage = static_cast<LocalStorage*>(aStorage);
if (!storage) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
RefPtr<LocalStorage> storage = static_cast<LocalStorage*>(aStorage);
*aRetval = false; *aRetval = false;
if (!aPrincipal) { if (!aPrincipal) {
@ -351,7 +350,7 @@ LocalStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
nsAutoCString suffix; nsAutoCString suffix;
nsAutoCString origin; nsAutoCString origin;
rv = GenerateOriginKey(aPrincipal, suffix, origin); nsresult rv = GenerateOriginKey(aPrincipal, suffix, origin);
if (NS_WARN_IF(NS_FAILED(rv))) { if (NS_WARN_IF(NS_FAILED(rv))) {
return rv; return rv;
} }

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

@ -104,7 +104,7 @@ private:
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
const nsAString& aDocumentURI, const nsAString& aDocumentURI,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval); Storage** aRetval);
// Suffix->origin->cache map // Suffix->origin->cache map
typedef nsTHashtable<LocalStorageCacheHashKey> CacheOriginHashtable; typedef nsTHashtable<LocalStorageCacheHashKey> CacheOriginHashtable;

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

@ -37,7 +37,7 @@ SessionStorageManager::~SessionStorageManager()
NS_IMETHODIMP NS_IMETHODIMP
SessionStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal, SessionStorageManager::PrecacheStorage(nsIPrincipal* aPrincipal,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
// Nothing to preload. // Nothing to preload.
return NS_OK; return NS_OK;
@ -48,7 +48,7 @@ SessionStorageManager::CreateStorage(mozIDOMWindow* aWindow,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
const nsAString& aDocumentURI, const nsAString& aDocumentURI,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
nsAutoCString originKey; nsAutoCString originKey;
nsAutoCString originAttributes; nsAutoCString originAttributes;
@ -82,7 +82,7 @@ NS_IMETHODIMP
SessionStorageManager::GetStorage(mozIDOMWindow* aWindow, SessionStorageManager::GetStorage(mozIDOMWindow* aWindow,
nsIPrincipal* aPrincipal, nsIPrincipal* aPrincipal,
bool aPrivate, bool aPrivate,
nsIDOMStorage** aRetval) Storage** aRetval)
{ {
*aRetval = nullptr; *aRetval = nullptr;
@ -113,20 +113,19 @@ SessionStorageManager::GetStorage(mozIDOMWindow* aWindow,
} }
NS_IMETHODIMP NS_IMETHODIMP
SessionStorageManager::CloneStorage(nsIDOMStorage* aStorage) SessionStorageManager::CloneStorage(Storage* aStorage)
{ {
if (NS_WARN_IF(!aStorage)) { if (NS_WARN_IF(!aStorage)) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
RefPtr<Storage> storage = static_cast<Storage*>(aStorage); if (aStorage->Type() != Storage::eSessionStorage) {
if (storage->Type() != Storage::eSessionStorage) {
return NS_ERROR_UNEXPECTED; return NS_ERROR_UNEXPECTED;
} }
nsAutoCString originKey; nsAutoCString originKey;
nsAutoCString originAttributes; nsAutoCString originAttributes;
nsresult rv = GenerateOriginKey(storage->Principal(), originAttributes, nsresult rv = GenerateOriginKey(aStorage->Principal(), originAttributes,
originKey); originKey);
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
return rv; return rv;
@ -153,7 +152,7 @@ SessionStorageManager::CloneStorage(nsIDOMStorage* aStorage)
NS_IMETHODIMP NS_IMETHODIMP
SessionStorageManager::CheckStorage(nsIPrincipal* aPrincipal, SessionStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
nsIDOMStorage* aStorage, Storage* aStorage,
bool* aRetval) bool* aRetval)
{ {
if (NS_WARN_IF(!aStorage)) { if (NS_WARN_IF(!aStorage)) {
@ -183,8 +182,7 @@ SessionStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
return NS_OK; return NS_OK;
} }
RefPtr<Storage> storage = static_cast<Storage*>(aStorage); if (aStorage->Type() != Storage::eSessionStorage) {
if (storage->Type() != Storage::eSessionStorage) {
return NS_OK; return NS_OK;
} }
@ -194,7 +192,7 @@ SessionStorageManager::CheckStorage(nsIPrincipal* aPrincipal,
return NS_OK; return NS_OK;
} }
if (!StorageUtils::PrincipalsEqual(storage->Principal(), aPrincipal)) { if (!StorageUtils::PrincipalsEqual(aStorage->Principal(), aPrincipal)) {
return NS_OK; return NS_OK;
} }

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

@ -1199,7 +1199,7 @@ nsWindowWatcher::OpenWindowInternal(mozIDOMWindowProxy* aParent,
do_QueryInterface(newDocShell); do_QueryInterface(newDocShell);
if (parentStorageManager && newStorageManager) { if (parentStorageManager && newStorageManager) {
nsCOMPtr<nsIDOMStorage> storage; RefPtr<Storage> storage;
nsCOMPtr<nsPIDOMWindowInner> pInnerWin = parentWindow->GetCurrentInnerWindow(); nsCOMPtr<nsPIDOMWindowInner> pInnerWin = parentWindow->GetCurrentInnerWindow();
parentStorageManager->GetStorage(pInnerWin, subjectPrincipal, parentStorageManager->GetStorage(pInnerWin, subjectPrincipal,
isPrivateBrowsingWindow, isPrivateBrowsingWindow,