2007-05-29 09:45:30 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Corporation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dave Camp <dcamp@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsDOMOfflineResourceList.h"
|
|
|
|
#include "nsDOMClassInfo.h"
|
|
|
|
#include "nsDOMError.h"
|
2008-11-04 18:59:13 +00:00
|
|
|
#include "nsDOMLists.h"
|
2007-05-29 09:45:30 +00:00
|
|
|
#include "nsIPrefetchService.h"
|
|
|
|
#include "nsCPrefetchService.h"
|
|
|
|
#include "nsNetUtil.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsICacheSession.h"
|
|
|
|
#include "nsICacheService.h"
|
2007-07-25 05:35:39 +00:00
|
|
|
#include "nsIOfflineCacheUpdate.h"
|
|
|
|
#include "nsIDOMLoadStatus.h"
|
2007-05-29 09:45:30 +00:00
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
2008-01-16 21:54:33 +00:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsEventDispatcher.h"
|
|
|
|
#include "nsIPrivateDOMEvent.h"
|
|
|
|
#include "nsIObserverService.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2008-08-26 23:09:02 +00:00
|
|
|
#include "nsIWebNavigation.h"
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
#include "nsXULAppAPI.h"
|
|
|
|
#define IS_CHILD_PROCESS() \
|
|
|
|
(GeckoProcessType_Default != XRE_GetProcessType())
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
// Event names
|
|
|
|
|
|
|
|
#define CHECKING_STR "checking"
|
|
|
|
#define ERROR_STR "error"
|
|
|
|
#define NOUPDATE_STR "noupdate"
|
|
|
|
#define DOWNLOADING_STR "downloading"
|
|
|
|
#define PROGRESS_STR "progress"
|
|
|
|
#define CACHED_STR "cached"
|
|
|
|
#define UPDATEREADY_STR "updateready"
|
2008-11-04 18:59:12 +00:00
|
|
|
#define OBSOLETE_STR "obsolete"
|
2007-05-29 09:45:30 +00:00
|
|
|
|
|
|
|
// To prevent abuse of the resource list for data storage, the number
|
|
|
|
// of offline urls and their length are limited.
|
|
|
|
|
|
|
|
static const char kMaxEntriesPref[] = "offline.max_site_resources";
|
|
|
|
#define DEFAULT_MAX_ENTRIES 100
|
|
|
|
#define MAX_URI_LENGTH 2048
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsDOMOfflineResourceList
|
|
|
|
//
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(nsDOMOfflineResourceList)
|
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsDOMOfflineResourceList,
|
|
|
|
nsDOMEventTargetHelper)
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mCacheUpdate)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCheckingListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnErrorListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnNoUpdateListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnDownloadingListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnProgressListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnCachedListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnUpdateReadyListener)
|
2008-11-04 18:59:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mOnObsoleteListener)
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMARRAY(mPendingEvents);
|
2008-01-16 21:54:33 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsDOMOfflineResourceList,
|
|
|
|
nsDOMEventTargetHelper)
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mCacheUpdate)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCheckingListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnErrorListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnNoUpdateListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnDownloadingListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnProgressListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnCachedListener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnUpdateReadyListener)
|
2008-11-04 18:59:12 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mOnObsoleteListener)
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMARRAY(mPendingEvents)
|
2008-01-16 21:54:33 +00:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
2010-01-12 13:08:43 +00:00
|
|
|
DOMCI_DATA(OfflineResourceList, nsDOMOfflineResourceList)
|
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMOfflineResourceList)
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMOfflineResourceList)
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIOfflineCacheUpdateObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(OfflineResourceList)
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
2007-05-29 09:45:30 +00:00
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDOMOfflineResourceList, nsDOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDOMOfflineResourceList, nsDOMEventTargetHelper)
|
2007-05-29 09:45:30 +00:00
|
|
|
|
2008-11-06 00:01:07 +00:00
|
|
|
nsDOMOfflineResourceList::nsDOMOfflineResourceList(nsIURI *aManifestURI,
|
2008-01-16 21:54:33 +00:00
|
|
|
nsIURI *aDocumentURI,
|
2009-06-15 08:27:29 +00:00
|
|
|
nsPIDOMWindow *aWindow,
|
|
|
|
nsIScriptContext* aScriptContext)
|
2007-06-27 04:40:24 +00:00
|
|
|
: mInitialized(PR_FALSE)
|
2008-01-16 21:54:33 +00:00
|
|
|
, mManifestURI(aManifestURI)
|
|
|
|
, mDocumentURI(aDocumentURI)
|
2010-10-20 17:12:32 +00:00
|
|
|
, mExposeCacheUpdateStatus(true)
|
|
|
|
, mStatus(nsIDOMOfflineResourceList::IDLE)
|
2011-03-22 20:42:56 +00:00
|
|
|
, mCachedKeys(nsnull)
|
|
|
|
, mCachedKeysCount(0)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
mOwner = aWindow;
|
|
|
|
mScriptContext = aScriptContext;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
|
|
|
|
{
|
2008-08-26 20:31:48 +00:00
|
|
|
ClearCachedKeys();
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2007-06-27 04:40:24 +00:00
|
|
|
nsDOMOfflineResourceList::Init()
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2007-06-27 04:40:24 +00:00
|
|
|
if (mInitialized) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-05-29 09:45:30 +00:00
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
if (!mManifestURI) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
mManifestURI->GetAsciiSpec(mManifestSpec);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
nsresult rv = nsContentUtils::GetSecurityManager()->
|
|
|
|
CheckSameOriginURI(mManifestURI, mDocumentURI, PR_TRUE);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Dynamically-managed resources are stored as a separate ownership list
|
|
|
|
// from the manifest.
|
|
|
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(mDocumentURI);
|
2007-05-29 09:45:30 +00:00
|
|
|
if (!innerURI)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
if (!IS_CHILD_PROCESS())
|
|
|
|
{
|
|
|
|
mApplicationCacheService =
|
|
|
|
do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
// Check for in-progress cache updates
|
|
|
|
nsCOMPtr<nsIOfflineCacheUpdateService> cacheUpdateService =
|
|
|
|
do_GetService(NS_OFFLINECACHEUPDATESERVICE_CONTRACTID, &rv);
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
PRUint32 numUpdates;
|
|
|
|
rv = cacheUpdateService->GetNumUpdates(&numUpdates);
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-10-20 17:12:32 +00:00
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < numUpdates; i++) {
|
|
|
|
nsCOMPtr<nsIOfflineCacheUpdate> cacheUpdate;
|
|
|
|
rv = cacheUpdateService->GetUpdate(i, getter_AddRefs(cacheUpdate));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
UpdateAdded(cacheUpdate);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// watch for new offline cache updates
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
nsCOMPtr<nsIObserverService> observerService =
|
|
|
|
mozilla::services::GetObserverService();
|
|
|
|
if (!observerService)
|
|
|
|
return NS_ERROR_FAILURE;
|
2008-01-16 21:54:33 +00:00
|
|
|
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
rv = observerService->AddObserver(this, "offline-cache-update-added", PR_TRUE);
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
Bug 560095 - Use mozilla::services::GetObserverService(). r=biesi,dveditz,gavin,josh,jst,mrbkap,roc,sdwilsh,shaver,sicking,smontagu,surkov
2010-04-29 16:59:13 +00:00
|
|
|
rv = observerService->AddObserver(this, "offline-cache-update-completed", PR_TRUE);
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
mInitialized = PR_TRUE;
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
void
|
|
|
|
nsDOMOfflineResourceList::Disconnect()
|
|
|
|
{
|
|
|
|
mOnCheckingListener = nsnull;
|
|
|
|
mOnErrorListener = nsnull;
|
|
|
|
mOnNoUpdateListener = nsnull;
|
|
|
|
mOnDownloadingListener = nsnull;
|
|
|
|
mOnProgressListener = nsnull;
|
|
|
|
mOnCachedListener = nsnull;
|
|
|
|
mOnUpdateReadyListener = nsnull;
|
2008-11-04 18:59:12 +00:00
|
|
|
mOnObsoleteListener = nsnull;
|
2008-01-16 21:54:33 +00:00
|
|
|
|
|
|
|
mPendingEvents.Clear();
|
2009-06-15 08:27:29 +00:00
|
|
|
|
|
|
|
if (mListenerManager) {
|
|
|
|
mListenerManager->Disconnect();
|
|
|
|
mListenerManager = nsnull;
|
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
//
|
|
|
|
// nsDOMOfflineResourceList::nsIDOMOfflineResourceList
|
|
|
|
//
|
|
|
|
|
2008-11-04 18:59:13 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::GetMozItems(nsIDOMDOMStringList **aItems)
|
2008-11-04 18:59:13 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2008-11-04 18:59:13 +00:00
|
|
|
*aItems = nsnull;
|
|
|
|
|
|
|
|
nsRefPtr<nsDOMStringList> items = new nsDOMStringList();
|
|
|
|
NS_ENSURE_TRUE(items, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
// If we are not associated with an application cache, return an
|
|
|
|
// empty list.
|
|
|
|
nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
|
|
|
|
if (!appCache) {
|
|
|
|
NS_ADDREF(*aItems = items);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRUint32 length;
|
|
|
|
char **keys;
|
|
|
|
rv = appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC,
|
|
|
|
&length, &keys);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < length; i++) {
|
|
|
|
items->Add(NS_ConvertUTF8toUTF16(keys[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(length, keys);
|
|
|
|
|
|
|
|
NS_ADDREF(*aItems = items);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::MozHasItem(const nsAString& aURI, PRBool* aExists)
|
2008-11-04 18:59:13 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2008-11-04 18:59:13 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
|
|
|
|
if (!appCache) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString key;
|
|
|
|
rv = GetCacheKey(aURI, key);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRUint32 types;
|
|
|
|
rv = appCache->GetTypes(key, &types);
|
|
|
|
if (rv == NS_ERROR_CACHE_KEY_NOT_FOUND) {
|
|
|
|
*aExists = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aExists = ((types & nsIApplicationCache::ITEM_DYNAMIC) != 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::GetMozLength(PRUint32 *aLength)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2008-06-28 00:22:16 +00:00
|
|
|
if (!mManifestURI) {
|
|
|
|
*aLength = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = CacheKeys();
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-26 20:31:48 +00:00
|
|
|
*aLength = mCachedKeysCount;
|
2007-05-29 09:45:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::MozItem(PRUint32 aIndex, nsAString& aURI)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
SetDOMStringToNull(aURI);
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
rv = CacheKeys();
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-26 20:31:48 +00:00
|
|
|
if (aIndex >= mCachedKeysCount)
|
2007-05-29 09:45:30 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2008-08-26 20:31:48 +00:00
|
|
|
CopyUTF8toUTF16(mCachedKeys[aIndex], aURI);
|
2007-05-29 09:45:30 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::MozAdd(const nsAString& aURI)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
|
|
|
|
if (!appCache) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
if (aURI.Length() > MAX_URI_LENGTH) return NS_ERROR_DOM_BAD_URI;
|
|
|
|
|
|
|
|
// this will fail if the URI is not absolute
|
|
|
|
nsCOMPtr<nsIURI> requestedURI;
|
2007-06-27 04:40:24 +00:00
|
|
|
rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
nsCAutoString scheme;
|
|
|
|
rv = requestedURI->GetScheme(scheme);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool match;
|
|
|
|
rv = mManifestURI->SchemeIs(scheme.get(), &match);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
PRUint32 length;
|
2009-01-26 06:50:44 +00:00
|
|
|
rv = GetMozLength(&length);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
PRUint32 maxEntries = nsContentUtils::GetIntPref(kMaxEntriesPref,
|
|
|
|
DEFAULT_MAX_ENTRIES);
|
|
|
|
|
|
|
|
if (length > maxEntries) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
ClearCachedKeys();
|
|
|
|
|
2007-07-25 05:35:39 +00:00
|
|
|
nsCOMPtr<nsIOfflineCacheUpdate> update =
|
|
|
|
do_CreateInstance(NS_OFFLINECACHEUPDATE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-28 01:15:32 +00:00
|
|
|
nsCAutoString clientID;
|
|
|
|
rv = appCache->GetClientID(clientID);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = update->InitPartial(mManifestURI, clientID, mDocumentURI);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
rv = update->AddDynamicURI(requestedURI);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-25 05:35:39 +00:00
|
|
|
rv = update->Schedule();
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2007-07-25 05:35:39 +00:00
|
|
|
return NS_OK;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2009-01-26 06:50:44 +00:00
|
|
|
nsDOMOfflineResourceList::MozRemove(const nsAString& aURI)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
|
|
|
|
if (!appCache) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
nsCAutoString key;
|
2007-06-27 04:40:24 +00:00
|
|
|
rv = GetCacheKey(aURI, key);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
ClearCachedKeys();
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
// XXX: This is a race condition. remove() is specced to remove
|
|
|
|
// from the currently associated application cache, but if this
|
|
|
|
// happens during an update (or after an update, if we haven't
|
|
|
|
// swapped yet), that remove() will be lost when the next update is
|
|
|
|
// finished. Need to bring this issue up.
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
rv = appCache->UnmarkEntry(key, nsIApplicationCache::ITEM_DYNAMIC);
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-01-16 21:54:33 +00:00
|
|
|
nsDOMOfflineResourceList::GetStatus(PRUint16 *aStatus)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
2008-01-16 21:54:33 +00:00
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
// Init may fail with INVALID_STATE_ERR if there is no manifest URI.
|
|
|
|
// The status attribute should not throw that exception, convert it
|
|
|
|
// to an UNCACHED.
|
|
|
|
if (rv == NS_ERROR_DOM_INVALID_STATE_ERR ||
|
|
|
|
!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
|
2008-01-16 21:54:33 +00:00
|
|
|
*aStatus = nsIDOMOfflineResourceList::UNCACHED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-27 04:40:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2009-03-04 21:37:29 +00:00
|
|
|
// If this object is not associated with a cache, return UNCACHED
|
|
|
|
nsCOMPtr<nsIApplicationCache> appCache = GetDocumentAppCache();
|
|
|
|
if (!appCache) {
|
|
|
|
*aStatus = nsIDOMOfflineResourceList::UNCACHED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
// If there is an update in process, use its status.
|
2010-10-20 17:12:32 +00:00
|
|
|
if (mCacheUpdate && mExposeCacheUpdateStatus) {
|
2008-08-26 23:09:02 +00:00
|
|
|
rv = mCacheUpdate->GetStatus(aStatus);
|
|
|
|
if (NS_SUCCEEDED(rv) && *aStatus != nsIDOMOfflineResourceList::IDLE) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
*aStatus = mStatus;
|
2008-01-16 21:54:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::Update()
|
|
|
|
{
|
|
|
|
nsresult rv = Init();
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIOfflineCacheUpdateService> updateService =
|
|
|
|
do_GetService(NS_OFFLINECACHEUPDATESERVICE_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
nsCOMPtr<nsIDOMWindow> window =
|
|
|
|
do_QueryInterface(mOwner);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
nsCOMPtr<nsIOfflineCacheUpdate> update;
|
|
|
|
rv = updateService->ScheduleUpdate(mManifestURI, mDocumentURI,
|
2010-10-20 17:12:32 +00:00
|
|
|
window, getter_AddRefs(update));
|
2008-01-16 21:54:33 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2008-01-16 21:54:33 +00:00
|
|
|
nsDOMOfflineResourceList::SwapCache()
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2007-06-27 04:40:24 +00:00
|
|
|
nsresult rv = Init();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
if (!nsContentUtils::OfflineAppAllowed(mDocumentURI)) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
2007-05-29 09:45:30 +00:00
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<nsIApplicationCache> currentAppCache = GetDocumentAppCache();
|
2010-10-20 17:12:32 +00:00
|
|
|
if (!currentAppCache) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
2008-08-26 23:09:02 +00:00
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
// Check the current and potentially newly available cache are not identical.
|
|
|
|
if (mAvailableApplicationCache == currentAppCache) {
|
2008-08-26 23:09:02 +00:00
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
if (mAvailableApplicationCache) {
|
|
|
|
nsCString currClientId, availClientId;
|
|
|
|
currentAppCache->GetClientID(currClientId);
|
|
|
|
mAvailableApplicationCache->GetClientID(availClientId);
|
|
|
|
if (availClientId == currClientId)
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
ClearCachedKeys();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
|
|
|
|
GetDocumentAppCacheContainer();
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
// In the case of an obsolete cache group, newAppCache might be null.
|
|
|
|
// We will disassociate from the cache in that case.
|
2008-08-26 23:09:02 +00:00
|
|
|
if (appCacheContainer) {
|
2010-10-20 17:12:32 +00:00
|
|
|
rv = appCacheContainer->SetApplicationCache(mAvailableApplicationCache);
|
2008-08-26 23:09:02 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-10-20 17:12:32 +00:00
|
|
|
mAvailableApplicationCache = nsnull;
|
|
|
|
mStatus = nsIDOMOfflineResourceList::IDLE;
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
return NS_OK;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
//
|
|
|
|
// nsDOMOfflineResourceList::nsIDOMEventTarget
|
|
|
|
//
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_IMETHODIMP
|
2008-01-16 21:54:33 +00:00
|
|
|
nsDOMOfflineResourceList::GetOnchecking(nsIDOMEventListener **aOnchecking)
|
2007-05-29 09:45:30 +00:00
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnCheckingListener, aOnchecking);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnchecking(nsIDOMEventListener *aOnchecking)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(CHECKING_STR),
|
|
|
|
mOnCheckingListener, aOnchecking);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOnerror(nsIDOMEventListener **aOnerror)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnErrorListener, aOnerror);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnerror(nsIDOMEventListener *aOnerror)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(ERROR_STR), mOnErrorListener,
|
|
|
|
aOnerror);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOnnoupdate(nsIDOMEventListener **aOnnoupdate)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnNoUpdateListener, aOnnoupdate);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnnoupdate(nsIDOMEventListener *aOnnoupdate)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(NOUPDATE_STR),
|
|
|
|
mOnNoUpdateListener, aOnnoupdate);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOndownloading(nsIDOMEventListener **aOndownloading)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnDownloadingListener, aOndownloading);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOndownloading(nsIDOMEventListener *aOndownloading)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(DOWNLOADING_STR),
|
|
|
|
mOnDownloadingListener, aOndownloading);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOnprogress(nsIDOMEventListener **aOnprogress)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnProgressListener, aOnprogress);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnprogress(nsIDOMEventListener *aOnprogress)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(PROGRESS_STR),
|
|
|
|
mOnProgressListener, aOnprogress);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOnupdateready(nsIDOMEventListener **aOnupdateready)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnUpdateReadyListener, aOnupdateready);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOncached(nsIDOMEventListener *aOncached)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(CACHED_STR),
|
|
|
|
mOnCachedListener, aOncached);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOncached(nsIDOMEventListener **aOncached)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnCachedListener, aOncached);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnupdateready(nsIDOMEventListener *aOnupdateready)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(UPDATEREADY_STR),
|
|
|
|
mOnUpdateReadyListener, aOnupdateready);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 18:59:12 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::GetOnobsolete(nsIDOMEventListener **aOnobsolete)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return GetInnerEventListener(mOnObsoleteListener, aOnobsolete);
|
2008-11-04 18:59:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::SetOnobsolete(nsIDOMEventListener *aOnobsolete)
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
return RemoveAddEventListener(NS_LITERAL_STRING(OBSOLETE_STR),
|
|
|
|
mOnObsoleteListener, aOnobsolete);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMOfflineResourceList::FirePendingEvents()
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
for (PRInt32 i = 0; i < mPendingEvents.Count(); ++i) {
|
|
|
|
PRBool dummy;
|
|
|
|
nsCOMPtr<nsIDOMEvent> event = mPendingEvents[i];
|
|
|
|
DispatchEvent(event, &dummy);
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
mPendingEvents.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2009-06-15 08:27:29 +00:00
|
|
|
nsDOMOfflineResourceList::SendEvent(const nsAString &aEventName)
|
2008-01-16 21:54:33 +00:00
|
|
|
{
|
|
|
|
// Don't send events to closed windows
|
2009-06-15 08:27:29 +00:00
|
|
|
if (!mOwner) {
|
2008-01-16 21:54:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
if (!mOwner->GetDocShell()) {
|
2008-01-16 21:54:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEvent> event;
|
|
|
|
nsresult rv = nsEventDispatcher::CreateEvent(nsnull, nsnull,
|
|
|
|
NS_LITERAL_STRING("Events"),
|
|
|
|
getter_AddRefs(event));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrivateDOMEvent> privevent = do_QueryInterface(event);
|
|
|
|
if (!privevent) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
event->InitEvent(aEventName, PR_FALSE, PR_TRUE);
|
|
|
|
|
|
|
|
// We assume anyone that managed to call SendEvent is trusted
|
|
|
|
privevent->SetTrusted(PR_TRUE);
|
|
|
|
|
|
|
|
// If the window is frozen or we're still catching up on events that were
|
|
|
|
// queued while frozen, save the event for later.
|
2009-06-15 08:27:29 +00:00
|
|
|
if (mOwner->IsFrozen() || mPendingEvents.Count() > 0) {
|
|
|
|
mPendingEvents.AppendObject(event);
|
2008-01-16 21:54:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-06-15 08:27:29 +00:00
|
|
|
PRBool dummy;
|
|
|
|
DispatchEvent(event, &dummy);
|
2008-01-16 21:54:33 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsDOMOfflineResourceList::nsIObserver
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDOMOfflineResourceList::Observe(nsISupports *aSubject,
|
|
|
|
const char *aTopic,
|
|
|
|
const PRUnichar *aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "offline-cache-update-added")) {
|
|
|
|
nsCOMPtr<nsIOfflineCacheUpdate> update = do_QueryInterface(aSubject);
|
|
|
|
if (update) {
|
|
|
|
UpdateAdded(update);
|
|
|
|
}
|
|
|
|
} else if (!strcmp(aTopic, "offline-cache-update-completed")) {
|
|
|
|
nsCOMPtr<nsIOfflineCacheUpdate> update = do_QueryInterface(aSubject);
|
|
|
|
if (update) {
|
|
|
|
UpdateCompleted(update);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsDOMOfflineResourceList::nsIOfflineCacheUpdateObserver
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2010-10-20 17:12:32 +00:00
|
|
|
nsDOMOfflineResourceList::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate,
|
|
|
|
PRUint32 event)
|
|
|
|
{
|
|
|
|
mExposeCacheUpdateStatus =
|
|
|
|
(event == STATE_CHECKING) ||
|
|
|
|
(event == STATE_DOWNLOADING) ||
|
|
|
|
(event == STATE_ITEMSTARTED) ||
|
|
|
|
(event == STATE_ITEMCOMPLETED) ||
|
|
|
|
// During notification of "obsolete" we must expose state of the update
|
|
|
|
(event == STATE_OBSOLETE);
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
case STATE_ERROR:
|
|
|
|
SendEvent(NS_LITERAL_STRING(ERROR_STR));
|
|
|
|
break;
|
|
|
|
case STATE_CHECKING:
|
|
|
|
SendEvent(NS_LITERAL_STRING(CHECKING_STR));
|
|
|
|
break;
|
|
|
|
case STATE_NOUPDATE:
|
|
|
|
SendEvent(NS_LITERAL_STRING(NOUPDATE_STR));
|
|
|
|
break;
|
|
|
|
case STATE_OBSOLETE:
|
|
|
|
mStatus = nsIDOMOfflineResourceList::OBSOLETE;
|
|
|
|
mAvailableApplicationCache = nsnull;
|
|
|
|
SendEvent(NS_LITERAL_STRING(OBSOLETE_STR));
|
|
|
|
break;
|
|
|
|
case STATE_DOWNLOADING:
|
|
|
|
SendEvent(NS_LITERAL_STRING(DOWNLOADING_STR));
|
|
|
|
break;
|
|
|
|
case STATE_ITEMSTARTED:
|
|
|
|
SendEvent(NS_LITERAL_STRING(PROGRESS_STR));
|
|
|
|
break;
|
|
|
|
case STATE_ITEMCOMPLETED:
|
|
|
|
// Nothing to do here...
|
|
|
|
break;
|
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
2008-11-04 18:59:12 +00:00
|
|
|
NS_IMETHODIMP
|
2010-10-20 17:12:32 +00:00
|
|
|
nsDOMOfflineResourceList::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
|
2008-11-04 18:59:12 +00:00
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
mAvailableApplicationCache = aApplicationCache;
|
2008-11-04 18:59:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
nsresult
|
|
|
|
nsDOMOfflineResourceList::GetCacheKey(const nsAString &aURI, nsCString &aKey)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> requestedURI;
|
|
|
|
nsresult rv = NS_NewURI(getter_AddRefs(requestedURI), aURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return GetCacheKey(requestedURI, aKey);
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
nsresult
|
|
|
|
nsDOMOfflineResourceList::UpdateAdded(nsIOfflineCacheUpdate *aUpdate)
|
|
|
|
{
|
|
|
|
// Ignore partial updates.
|
|
|
|
PRBool partial;
|
|
|
|
nsresult rv = aUpdate->GetPartial(&partial);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (partial) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> updateURI;
|
|
|
|
rv = aUpdate->GetManifestURI(getter_AddRefs(updateURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
PRBool equals;
|
|
|
|
rv = updateURI->Equals(mManifestURI, &equals);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!equals) {
|
|
|
|
// This update doesn't belong to us
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(!mCacheUpdate, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// We don't need to emit signals here. Updates are either added
|
|
|
|
// when they are scheduled (in which case they are always IDLE) or
|
|
|
|
// they are added when the applicationCache object is initialized, so there
|
|
|
|
// are no listeners to accept signals anyway.
|
|
|
|
|
|
|
|
mCacheUpdate = aUpdate;
|
|
|
|
mCacheUpdate->AddObserver(this, PR_TRUE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
already_AddRefed<nsIApplicationCacheContainer>
|
|
|
|
nsDOMOfflineResourceList::GetDocumentAppCacheContainer()
|
|
|
|
{
|
2009-06-15 08:27:29 +00:00
|
|
|
nsCOMPtr<nsIWebNavigation> webnav = do_GetInterface(mOwner);
|
2008-08-26 23:09:02 +00:00
|
|
|
if (!webnav) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
|
|
|
|
do_GetInterface(webnav);
|
|
|
|
return appCacheContainer.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIApplicationCache>
|
|
|
|
nsDOMOfflineResourceList::GetDocumentAppCache()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIApplicationCacheContainer> appCacheContainer =
|
|
|
|
GetDocumentAppCacheContainer();
|
|
|
|
|
|
|
|
if (appCacheContainer) {
|
|
|
|
nsCOMPtr<nsIApplicationCache> applicationCache;
|
|
|
|
appCacheContainer->GetApplicationCache(
|
|
|
|
getter_AddRefs(applicationCache));
|
|
|
|
return applicationCache.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
nsresult
|
|
|
|
nsDOMOfflineResourceList::UpdateCompleted(nsIOfflineCacheUpdate *aUpdate)
|
|
|
|
{
|
|
|
|
if (aUpdate != mCacheUpdate) {
|
|
|
|
// This isn't the update we're watching.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
PRBool partial;
|
|
|
|
mCacheUpdate->GetPartial(&partial);
|
|
|
|
PRBool isUpgrade;
|
|
|
|
mCacheUpdate->GetIsUpgrade(&isUpgrade);
|
|
|
|
|
2008-01-16 21:54:33 +00:00
|
|
|
PRBool succeeded;
|
|
|
|
nsresult rv = mCacheUpdate->GetSucceeded(&succeeded);
|
|
|
|
|
|
|
|
mCacheUpdate->RemoveObserver(this);
|
|
|
|
mCacheUpdate = nsnull;
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && succeeded && !partial) {
|
|
|
|
if (isUpgrade) {
|
2010-10-20 17:12:32 +00:00
|
|
|
mStatus = nsIDOMOfflineResourceList::UPDATEREADY;
|
2009-06-15 08:27:29 +00:00
|
|
|
SendEvent(NS_LITERAL_STRING(UPDATEREADY_STR));
|
2008-08-26 23:09:02 +00:00
|
|
|
} else {
|
2010-10-20 17:12:32 +00:00
|
|
|
mStatus = nsIDOMOfflineResourceList::IDLE;
|
2009-06-15 08:27:29 +00:00
|
|
|
SendEvent(NS_LITERAL_STRING(CACHED_STR));
|
2008-08-26 23:09:02 +00:00
|
|
|
}
|
2008-01-16 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-29 09:45:30 +00:00
|
|
|
nsresult
|
|
|
|
nsDOMOfflineResourceList::GetCacheKey(nsIURI *aURI, nsCString &aKey)
|
|
|
|
{
|
2008-01-23 04:31:50 +00:00
|
|
|
nsresult rv = aURI->GetAsciiSpec(aKey);
|
2007-05-29 09:45:30 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// url fragments aren't used in cache keys
|
|
|
|
nsCAutoString::const_iterator specStart, specEnd;
|
|
|
|
aKey.BeginReading(specStart);
|
|
|
|
aKey.EndReading(specEnd);
|
|
|
|
if (FindCharInReadable('#', specStart, specEnd)) {
|
|
|
|
aKey.BeginReading(specEnd);
|
|
|
|
aKey = Substring(specEnd, specStart);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsDOMOfflineResourceList::CacheKeys()
|
|
|
|
{
|
2010-10-20 17:12:32 +00:00
|
|
|
if (IS_CHILD_PROCESS())
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
2008-08-26 20:31:48 +00:00
|
|
|
if (mCachedKeys)
|
2007-05-29 09:45:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
|
2008-08-26 23:09:02 +00:00
|
|
|
nsCOMPtr<nsIApplicationCache> appCache;
|
|
|
|
mApplicationCacheService->GetActiveCache(mManifestSpec,
|
|
|
|
getter_AddRefs(appCache));
|
|
|
|
|
|
|
|
if (!appCache) {
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
2008-08-27 23:20:45 +00:00
|
|
|
return appCache->GatherEntries(nsIApplicationCache::ITEM_DYNAMIC,
|
|
|
|
&mCachedKeysCount, &mCachedKeys);
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDOMOfflineResourceList::ClearCachedKeys()
|
|
|
|
{
|
2008-08-26 20:31:48 +00:00
|
|
|
if (mCachedKeys) {
|
|
|
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(mCachedKeysCount, mCachedKeys);
|
|
|
|
mCachedKeys = nsnull;
|
|
|
|
mCachedKeysCount = 0;
|
2007-05-29 09:45:30 +00:00
|
|
|
}
|
|
|
|
}
|