Defer initialization of navigator.offlineResources. b=383421, r+sr=jst

This commit is contained in:
dcamp@mozilla.com 2007-06-26 21:40:24 -07:00
Родитель 39cef56602
Коммит 1b6631188a
3 изменённых файлов: 42 добавлений и 20 удалений

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

@ -8499,14 +8499,8 @@ nsNavigator::GetOfflineResources(nsIDOMOfflineResourceList **aList)
nsresult rv = webNav->GetCurrentURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, rv);
mOfflineResources = new nsDOMOfflineResourceList();
mOfflineResources = new nsDOMOfflineResourceList(uri);
if (!mOfflineResources) return NS_ERROR_OUT_OF_MEMORY;
rv = mOfflineResources->Init(uri);
if (NS_FAILED(rv)) {
mOfflineResources = nsnull;
return rv;
}
}
NS_IF_ADDREF(*aList = mOfflineResources);

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

@ -73,7 +73,9 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(nsDOMOfflineResourceList)
NS_IMPL_RELEASE(nsDOMOfflineResourceList)
nsDOMOfflineResourceList::nsDOMOfflineResourceList()
nsDOMOfflineResourceList::nsDOMOfflineResourceList(nsIURI *aURI)
: mInitialized(PR_FALSE)
, mURI(aURI)
{
}
@ -82,11 +84,13 @@ nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
}
nsresult
nsDOMOfflineResourceList::Init(nsIURI *aURI)
nsDOMOfflineResourceList::Init()
{
mURI = aURI;
if (mInitialized) {
return NS_OK;
}
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(mURI);
if (!innerURI)
return NS_ERROR_FAILURE;
@ -107,6 +111,8 @@ nsDOMOfflineResourceList::Init(nsIURI *aURI)
mCacheSession = do_QueryInterface(session, &rv);
NS_ENSURE_SUCCESS(rv, rv);
mInitialized = PR_TRUE;
return NS_OK;
}
@ -117,7 +123,10 @@ nsDOMOfflineResourceList::Init(nsIURI *aURI)
NS_IMETHODIMP
nsDOMOfflineResourceList::GetLength(PRUint32 *aLength)
{
nsresult rv = CacheKeys();
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
rv = CacheKeys();
NS_ENSURE_SUCCESS(rv, rv);
*aLength = gCachedKeysCount;
@ -127,9 +136,12 @@ nsDOMOfflineResourceList::GetLength(PRUint32 *aLength)
NS_IMETHODIMP
nsDOMOfflineResourceList::Item(PRUint32 aIndex, nsAString& aURI)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
SetDOMStringToNull(aURI);
nsresult rv = CacheKeys();
rv = CacheKeys();
NS_ENSURE_SUCCESS(rv, rv);
if (aIndex >= gCachedKeysCount)
@ -143,11 +155,14 @@ nsDOMOfflineResourceList::Item(PRUint32 aIndex, nsAString& aURI)
NS_IMETHODIMP
nsDOMOfflineResourceList::Add(const nsAString& aURI)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
if (aURI.Length() > MAX_URI_LENGTH) return NS_ERROR_DOM_BAD_URI;
// this will fail if the URI is not absolute
nsCOMPtr<nsIURI> requestedURI;
nsresult rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
NS_ENSURE_SUCCESS(rv, rv);
// only http/https urls will work offline
@ -191,8 +206,11 @@ nsDOMOfflineResourceList::Add(const nsAString& aURI)
NS_IMETHODIMP
nsDOMOfflineResourceList::Remove(const nsAString& aURI)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString key;
nsresult rv = GetCacheKey(aURI, key);
rv = GetCacheKey(aURI, key);
NS_ENSURE_SUCCESS(rv, rv);
ClearCachedKeys();
@ -205,8 +223,11 @@ nsDOMOfflineResourceList::Remove(const nsAString& aURI)
NS_IMETHODIMP
nsDOMOfflineResourceList::Has(const nsAString& aURI, PRBool *aExists)
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString key;
nsresult rv = GetCacheKey(aURI, key);
rv = GetCacheKey(aURI, key);
NS_ENSURE_SUCCESS(rv, rv);
return mCacheSession->KeyIsOwned(mHostPort, NS_LITERAL_CSTRING(""),
@ -216,6 +237,9 @@ nsDOMOfflineResourceList::Has(const nsAString& aURI, PRBool *aExists)
NS_IMETHODIMP
nsDOMOfflineResourceList::Clear()
{
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
ClearCachedKeys();
return mCacheSession->SetOwnedKeys(mHostPort,
@ -226,7 +250,10 @@ nsDOMOfflineResourceList::Clear()
NS_IMETHODIMP
nsDOMOfflineResourceList::Refresh()
{
nsresult rv = CacheKeys();
nsresult rv = Init();
NS_ENSURE_SUCCESS(rv, rv);
rv = CacheKeys();
NS_ENSURE_SUCCESS(rv, rv);
// try to start fetching it now, but it's not fatal if it fails

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

@ -53,18 +53,19 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIDOMOFFLINERESOURCELIST
nsDOMOfflineResourceList();
nsDOMOfflineResourceList(nsIURI* aURI);
virtual ~nsDOMOfflineResourceList();
nsresult Init(nsIURI *aURI);
private:
nsresult Init();
nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);
nsresult CacheKeys();
void ClearCachedKeys();
PRBool mInitialized;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIOfflineCacheSession> mCacheSession;
nsCAutoString mHostPort;