зеркало из https://github.com/mozilla/gecko-dev.git
Bug 372970. Implement navigator.offlineResources. patch by Dave Camp, r+sr=jst
This commit is contained in:
Родитель
c29b01e71c
Коммит
1e64c60d76
|
@ -849,8 +849,12 @@ nsContentSink::AddOfflineResource(const nsAString &aHref)
|
||||||
PRBool match;
|
PRBool match;
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(mDocumentURI);
|
||||||
|
if (!innerURI)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
nsCAutoString ownerHost;
|
nsCAutoString ownerHost;
|
||||||
rv = mDocumentURI->GetHostPort(ownerHost);
|
rv = innerURI->GetHostPort(ownerHost);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCAutoString ownerSpec;
|
nsCAutoString ownerSpec;
|
||||||
|
@ -862,11 +866,11 @@ nsContentSink::AddOfflineResource(const nsAString &aHref)
|
||||||
mSaveOfflineResources = PR_FALSE;
|
mSaveOfflineResources = PR_FALSE;
|
||||||
|
|
||||||
// only let http and https urls add offline resources
|
// only let http and https urls add offline resources
|
||||||
nsresult rv = mDocumentURI->SchemeIs("http", &match);
|
nsresult rv = innerURI->SchemeIs("http", &match);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (!match) {
|
if (!match) {
|
||||||
rv = mDocumentURI->SchemeIs("https", &match);
|
rv = innerURI->SchemeIs("https", &match);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
if (!match)
|
if (!match)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
|
@ -57,7 +57,8 @@ DIRS = \
|
||||||
xpath \
|
xpath \
|
||||||
ls \
|
ls \
|
||||||
xul \
|
xul \
|
||||||
storage
|
storage \
|
||||||
|
offline
|
||||||
|
|
||||||
ifdef MOZ_SVG
|
ifdef MOZ_SVG
|
||||||
DIRS += svg
|
DIRS += svg
|
||||||
|
|
|
@ -37,7 +37,9 @@
|
||||||
|
|
||||||
#include "domstubs.idl"
|
#include "domstubs.idl"
|
||||||
|
|
||||||
[scriptable, uuid(abbb51a4-be75-4d7f-bd4c-373fd7b52f85)]
|
interface nsIDOMOfflineResourceList;
|
||||||
|
|
||||||
|
[scriptable, uuid(609439fa-63e4-4f71-9512-904867f154e7)]
|
||||||
interface nsIDOMClientInformation : nsISupports
|
interface nsIDOMClientInformation : nsISupports
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +50,8 @@ interface nsIDOMClientInformation : nsISupports
|
||||||
*/
|
*/
|
||||||
void registerContentHandler(in DOMString mimeType, in DOMString uri, in DOMString title);
|
void registerContentHandler(in DOMString mimeType, in DOMString uri, in DOMString title);
|
||||||
void registerProtocolHandler(in DOMString protocol, in DOMString uri, in DOMString title);
|
void registerProtocolHandler(in DOMString protocol, in DOMString uri, in DOMString title);
|
||||||
|
|
||||||
|
readonly attribute nsIDOMOfflineResourceList offlineResources;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
#
|
||||||
|
# ***** 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) 2006
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
|
# either of 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 *****
|
||||||
|
|
||||||
|
DEPTH = ../../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = dom
|
||||||
|
XPIDL_MODULE = dom_offline
|
||||||
|
GRE_MODULE = 1
|
||||||
|
|
||||||
|
SDK_XPIDLSRCS = \
|
||||||
|
nsIDOMOfflineResourceList.idl \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,53 @@
|
||||||
|
/* -*- Mode: IDL; 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 of 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 "domstubs.idl"
|
||||||
|
|
||||||
|
[scriptable, uuid(8449bce2-0d8c-4c74-ab79-b41b8d81f1c4)]
|
||||||
|
interface nsIDOMOfflineResourceList : nsISupports
|
||||||
|
{
|
||||||
|
readonly attribute unsigned long length;
|
||||||
|
DOMString item(in unsigned long index);
|
||||||
|
|
||||||
|
void add(in DOMString uri);
|
||||||
|
void remove(in DOMString uri);
|
||||||
|
boolean has(in DOMString uri);
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
void refresh();
|
||||||
|
};
|
|
@ -392,6 +392,8 @@ enum nsDOMClassInfoID {
|
||||||
eDOMClassInfo_XULCommandEvent_id,
|
eDOMClassInfo_XULCommandEvent_id,
|
||||||
eDOMClassInfo_CommandEvent_id,
|
eDOMClassInfo_CommandEvent_id,
|
||||||
|
|
||||||
|
eDOMClassInfo_OfflineResourceList_id,
|
||||||
|
|
||||||
// This one better be the last one in this list
|
// This one better be the last one in this list
|
||||||
eDOMClassInfoIDCount
|
eDOMClassInfoIDCount
|
||||||
};
|
};
|
||||||
|
|
|
@ -42,7 +42,7 @@ VPATH = @srcdir@
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
DIRS = base jsurl events storage
|
DIRS = base jsurl events storage offline
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,7 @@ REQUIRES = xpcom \
|
||||||
pref \
|
pref \
|
||||||
oji \
|
oji \
|
||||||
necko \
|
necko \
|
||||||
|
nkcache \
|
||||||
mimetype \
|
mimetype \
|
||||||
java \
|
java \
|
||||||
locale \
|
locale \
|
||||||
|
@ -120,6 +121,7 @@ FORCE_STATIC_LIB = 1
|
||||||
LOCAL_INCLUDES = \
|
LOCAL_INCLUDES = \
|
||||||
-I$(srcdir)/../events \
|
-I$(srcdir)/../events \
|
||||||
-I$(srcdir)/../storage \
|
-I$(srcdir)/../storage \
|
||||||
|
-I$(srcdir)/../offline \
|
||||||
-I$(topsrcdir)/content/xbl/src \
|
-I$(topsrcdir)/content/xbl/src \
|
||||||
-I$(topsrcdir)/content/xul/document/src \
|
-I$(topsrcdir)/content/xul/document/src \
|
||||||
-I$(topsrcdir)/content/events/src \
|
-I$(topsrcdir)/content/events/src \
|
||||||
|
|
|
@ -1162,6 +1162,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||||
|
|
||||||
NS_DEFINE_CLASSINFO_DATA(CommandEvent, nsDOMGenericSH,
|
NS_DEFINE_CLASSINFO_DATA(CommandEvent, nsDOMGenericSH,
|
||||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||||
|
|
||||||
|
NS_DEFINE_CLASSINFO_DATA(OfflineResourceList, nsOfflineResourceListSH,
|
||||||
|
ARRAY_SCRIPTABLE_FLAGS)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Objects that shuld be constructable through |new Name();|
|
// Objects that shuld be constructable through |new Name();|
|
||||||
|
@ -3168,6 +3171,10 @@ nsDOMClassInfo::Init()
|
||||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||||
DOM_CLASSINFO_MAP_END
|
DOM_CLASSINFO_MAP_END
|
||||||
|
|
||||||
|
DOM_CLASSINFO_MAP_BEGIN(OfflineResourceList, nsIDOMOfflineResourceList)
|
||||||
|
DOM_CLASSINFO_MAP_ENTRY(nsIDOMOfflineResourceList)
|
||||||
|
DOM_CLASSINFO_MAP_END
|
||||||
|
|
||||||
#ifdef NS_DEBUG
|
#ifdef NS_DEBUG
|
||||||
{
|
{
|
||||||
PRUint32 i = NS_ARRAY_LENGTH(sClassInfoData);
|
PRUint32 i = NS_ARRAY_LENGTH(sClassInfoData);
|
||||||
|
@ -10006,3 +10013,14 @@ nsAttributeSH::GetFlags(PRUint32 *aFlags)
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nsOfflineResourceListSH
|
||||||
|
nsresult
|
||||||
|
nsOfflineResourceListSH::GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||||
|
nsAString& aResult)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIDOMOfflineResourceList> list(do_QueryInterface(aNative));
|
||||||
|
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
|
||||||
|
|
||||||
|
return list->Item(aIndex, aResult);
|
||||||
|
}
|
||||||
|
|
|
@ -1579,6 +1579,29 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class nsOfflineResourceListSH : public nsStringArraySH
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
nsOfflineResourceListSH(nsDOMClassInfoData* aData) : nsStringArraySH(aData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~nsOfflineResourceListSH()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual nsresult GetStringAt(nsISupports *aNative, PRInt32 aIndex,
|
||||||
|
nsAString& aResult);
|
||||||
|
|
||||||
|
public:
|
||||||
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
||||||
|
{
|
||||||
|
return new nsOfflineResourceListSH(aData);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void InvalidateContextAndWrapperCache();
|
void InvalidateContextAndWrapperCache();
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
#include "nsHistory.h"
|
#include "nsHistory.h"
|
||||||
#include "nsBarProps.h"
|
#include "nsBarProps.h"
|
||||||
#include "nsDOMStorage.h"
|
#include "nsDOMStorage.h"
|
||||||
|
#include "nsDOMOfflineResourceList.h"
|
||||||
#include "nsDOMError.h"
|
#include "nsDOMError.h"
|
||||||
|
|
||||||
// Helper Classes
|
// Helper Classes
|
||||||
|
@ -104,6 +105,7 @@
|
||||||
#include "nsIDOMKeyEvent.h"
|
#include "nsIDOMKeyEvent.h"
|
||||||
#include "nsIDOMPopupBlockedEvent.h"
|
#include "nsIDOMPopupBlockedEvent.h"
|
||||||
#include "nsIDOMPkcs11.h"
|
#include "nsIDOMPkcs11.h"
|
||||||
|
#include "nsIDOMOfflineResourceList.h"
|
||||||
#include "nsDOMString.h"
|
#include "nsDOMString.h"
|
||||||
#include "nsIEmbeddingSiteWindow2.h"
|
#include "nsIEmbeddingSiteWindow2.h"
|
||||||
#include "nsThreadUtils.h"
|
#include "nsThreadUtils.h"
|
||||||
|
@ -8415,6 +8417,7 @@ nsNavigator::LoadingNewDocument()
|
||||||
// arrays may have changed. See bug 150087.
|
// arrays may have changed. See bug 150087.
|
||||||
mMimeTypes = nsnull;
|
mMimeTypes = nsnull;
|
||||||
mPlugins = nsnull;
|
mPlugins = nsnull;
|
||||||
|
mOfflineResources = nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -8463,3 +8466,34 @@ nsNavigator::RegisterProtocolHandler(const nsAString& aProtocol,
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsNavigator::GetOfflineResources(nsIDOMOfflineResourceList **aList)
|
||||||
|
{
|
||||||
|
NS_ENSURE_ARG_POINTER(aList);
|
||||||
|
|
||||||
|
if (!mOfflineResources) {
|
||||||
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(GetDocShell()));
|
||||||
|
if (!webNav) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> uri;
|
||||||
|
nsresult rv = webNav->GetCurrentURI(getter_AddRefs(uri));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
mOfflineResources = new nsDOMOfflineResourceList();
|
||||||
|
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);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
#include "nsIDOMStorage.h"
|
#include "nsIDOMStorage.h"
|
||||||
#include "nsIDOMStorageList.h"
|
#include "nsIDOMStorageList.h"
|
||||||
#include "nsIDOMStorageWindow.h"
|
#include "nsIDOMStorageWindow.h"
|
||||||
|
#include "nsIDOMOfflineResourceList.h"
|
||||||
#include "nsPIDOMEventTarget.h"
|
#include "nsPIDOMEventTarget.h"
|
||||||
|
|
||||||
#define DEFAULT_HOME_PAGE "www.mozilla.org"
|
#define DEFAULT_HOME_PAGE "www.mozilla.org"
|
||||||
|
@ -117,6 +118,8 @@ class WindowStateHolder;
|
||||||
class nsGlobalWindowObserver;
|
class nsGlobalWindowObserver;
|
||||||
class nsGlobalWindow;
|
class nsGlobalWindow;
|
||||||
|
|
||||||
|
class nsDOMOfflineResourceList;
|
||||||
|
|
||||||
// permissible values for CheckOpenAllow
|
// permissible values for CheckOpenAllow
|
||||||
enum OpenAllowValue {
|
enum OpenAllowValue {
|
||||||
allowNot = 0, // the window opening is denied
|
allowNot = 0, // the window opening is denied
|
||||||
|
@ -754,6 +757,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
nsRefPtr<nsMimeTypeArray> mMimeTypes;
|
nsRefPtr<nsMimeTypeArray> mMimeTypes;
|
||||||
nsRefPtr<nsPluginArray> mPlugins;
|
nsRefPtr<nsPluginArray> mPlugins;
|
||||||
|
nsRefPtr<nsDOMOfflineResourceList> mOfflineResources;
|
||||||
nsIDocShell* mDocShell; // weak reference
|
nsIDocShell* mDocShell; // weak reference
|
||||||
|
|
||||||
static jsval sPrefInternal_id;
|
static jsval sPrefInternal_id;
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
#
|
||||||
|
# ***** 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):
|
||||||
|
#
|
||||||
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
|
# either of 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 *****
|
||||||
|
|
||||||
|
DEPTH = ../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
MODULE = dom
|
||||||
|
LIBRARY_NAME = jsdomoffline_s
|
||||||
|
LIBXUL_LIBRARY = 1
|
||||||
|
|
||||||
|
REQUIRES = xpcom \
|
||||||
|
string \
|
||||||
|
content \
|
||||||
|
caps \
|
||||||
|
js \
|
||||||
|
layout \
|
||||||
|
necko \
|
||||||
|
nkcache \
|
||||||
|
pref \
|
||||||
|
prefetch \
|
||||||
|
widget \
|
||||||
|
xpconnect \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
CPPSRCS = \
|
||||||
|
nsDOMOfflineResourceList.cpp \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||||
|
FORCE_STATIC_LIB = 1
|
||||||
|
|
||||||
|
LOCAL_INCLUDES = \
|
||||||
|
-I$(srcdir)/../base \
|
||||||
|
-I$(topsrcdir)/content/events/src
|
||||||
|
|
||||||
|
DEFINES += -D_IMPL_NS_LAYOUT
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,310 @@
|
||||||
|
/* -*- 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"
|
||||||
|
#include "nsIPrefetchService.h"
|
||||||
|
#include "nsCPrefetchService.h"
|
||||||
|
#include "nsNetUtil.h"
|
||||||
|
#include "nsNetCID.h"
|
||||||
|
#include "nsICacheSession.h"
|
||||||
|
#include "nsICacheService.h"
|
||||||
|
#include "nsIOfflineCacheSession.h"
|
||||||
|
#include "nsAutoPtr.h"
|
||||||
|
#include "nsContentUtils.h"
|
||||||
|
|
||||||
|
// 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
|
||||||
|
|
||||||
|
static nsCAutoString gCachedHostPort;
|
||||||
|
static char **gCachedKeys = nsnull;
|
||||||
|
static PRUint32 gCachedKeysCount = 0;
|
||||||
|
|
||||||
|
//
|
||||||
|
// nsDOMOfflineResourceList
|
||||||
|
//
|
||||||
|
|
||||||
|
NS_INTERFACE_MAP_BEGIN(nsDOMOfflineResourceList)
|
||||||
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMOfflineResourceList)
|
||||||
|
NS_INTERFACE_MAP_ENTRY(nsIDOMOfflineResourceList)
|
||||||
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(OfflineResourceList)
|
||||||
|
NS_INTERFACE_MAP_END
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsDOMOfflineResourceList)
|
||||||
|
NS_IMPL_RELEASE(nsDOMOfflineResourceList)
|
||||||
|
|
||||||
|
nsDOMOfflineResourceList::nsDOMOfflineResourceList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsDOMOfflineResourceList::Init(nsIURI *aURI)
|
||||||
|
{
|
||||||
|
mURI = aURI;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
|
||||||
|
if (!innerURI)
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
nsresult rv = innerURI->GetHostPort(mHostPort);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsICacheService> serv = do_GetService(NS_CACHESERVICE_CONTRACTID,
|
||||||
|
&rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsICacheSession> session;
|
||||||
|
rv = serv->CreateSession("HTTP-offline",
|
||||||
|
nsICache::STORE_OFFLINE,
|
||||||
|
nsICache::STREAM_BASED,
|
||||||
|
getter_AddRefs(session));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
mCacheSession = do_QueryInterface(session, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// nsDOMOfflineResourceList::nsIDOMOfflineResourceList
|
||||||
|
//
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::GetLength(PRUint32 *aLength)
|
||||||
|
{
|
||||||
|
nsresult rv = CacheKeys();
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
*aLength = gCachedKeysCount;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Item(PRUint32 aIndex, nsAString& aURI)
|
||||||
|
{
|
||||||
|
SetDOMStringToNull(aURI);
|
||||||
|
|
||||||
|
nsresult rv = CacheKeys();
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
if (aIndex >= gCachedKeysCount)
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
CopyUTF8toUTF16(gCachedKeys[aIndex], aURI);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Add(const nsAString& aURI)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// only http/https urls will work offline
|
||||||
|
PRBool match;
|
||||||
|
rv = requestedURI->SchemeIs("http", &match);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
if (!match) {
|
||||||
|
rv = requestedURI->SchemeIs("https", &match);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
if (!match) return NS_ERROR_DOM_BAD_URI;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 length;
|
||||||
|
rv = GetLength(&length);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
PRUint32 maxEntries = nsContentUtils::GetIntPref(kMaxEntriesPref,
|
||||||
|
DEFAULT_MAX_ENTRIES);
|
||||||
|
|
||||||
|
if (length > maxEntries) return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
|
||||||
|
ClearCachedKeys();
|
||||||
|
|
||||||
|
nsCAutoString key;
|
||||||
|
rv = GetCacheKey(requestedURI, key);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = mCacheSession->AddOwnedKey(mHostPort,
|
||||||
|
NS_LITERAL_CSTRING(""),
|
||||||
|
key);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPrefetchService> prefetchService =
|
||||||
|
do_GetService(NS_PREFETCHSERVICE_CONTRACTID, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
return prefetchService->PrefetchURIForOfflineUse(requestedURI,
|
||||||
|
mURI,
|
||||||
|
PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Remove(const nsAString& aURI)
|
||||||
|
{
|
||||||
|
nsCAutoString key;
|
||||||
|
nsresult rv = GetCacheKey(aURI, key);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
ClearCachedKeys();
|
||||||
|
|
||||||
|
return mCacheSession->RemoveOwnedKey(mHostPort,
|
||||||
|
NS_LITERAL_CSTRING(""),
|
||||||
|
key);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Has(const nsAString& aURI, PRBool *aExists)
|
||||||
|
{
|
||||||
|
nsCAutoString key;
|
||||||
|
nsresult rv = GetCacheKey(aURI, key);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
return mCacheSession->KeyIsOwned(mHostPort, NS_LITERAL_CSTRING(""),
|
||||||
|
key, aExists);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Clear()
|
||||||
|
{
|
||||||
|
ClearCachedKeys();
|
||||||
|
|
||||||
|
return mCacheSession->SetOwnedKeys(mHostPort,
|
||||||
|
NS_LITERAL_CSTRING(""),
|
||||||
|
0, nsnull);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsDOMOfflineResourceList::Refresh()
|
||||||
|
{
|
||||||
|
nsresult rv = CacheKeys();
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// try to start fetching it now, but it's not fatal if it fails
|
||||||
|
nsCOMPtr<nsIPrefetchService> prefetchService =
|
||||||
|
do_GetService(NS_PREFETCHSERVICE_CONTRACTID, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
for (PRUint32 i = 0; i < gCachedKeysCount; i++) {
|
||||||
|
// this will fail if the URI is not absolute
|
||||||
|
nsCOMPtr<nsIURI> requestedURI;
|
||||||
|
nsresult rv = NS_NewURI(getter_AddRefs(requestedURI), gCachedKeys[i]);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = prefetchService->PrefetchURIForOfflineUse(requestedURI,
|
||||||
|
mURI,
|
||||||
|
PR_TRUE);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsDOMOfflineResourceList::GetCacheKey(nsIURI *aURI, nsCString &aKey)
|
||||||
|
{
|
||||||
|
nsresult rv = aURI->GetSpec(aKey);
|
||||||
|
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()
|
||||||
|
{
|
||||||
|
if (gCachedKeys && mHostPort == gCachedHostPort)
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
ClearCachedKeys();
|
||||||
|
|
||||||
|
nsresult rv = mCacheSession->GetOwnedKeys(mHostPort, NS_LITERAL_CSTRING(""),
|
||||||
|
&gCachedKeysCount, &gCachedKeys);
|
||||||
|
|
||||||
|
if (NS_SUCCEEDED(rv))
|
||||||
|
gCachedHostPort = mHostPort;
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsDOMOfflineResourceList::ClearCachedKeys()
|
||||||
|
{
|
||||||
|
if (gCachedKeys) {
|
||||||
|
NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(gCachedKeysCount, gCachedKeys);
|
||||||
|
gCachedKeys = nsnull;
|
||||||
|
gCachedKeysCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
gCachedHostPort = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/* -*- 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 ***** */
|
||||||
|
|
||||||
|
#ifndef nsDOMOfflineResourceList_h___
|
||||||
|
#define nsDOMOfflineResourceList_h___
|
||||||
|
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "nsIDOMOfflineResourceList.h"
|
||||||
|
#include "nsIOfflineCacheSession.h"
|
||||||
|
#include "nsTArray.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsIURI.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
class nsDOMOfflineResourceList : public nsIDOMOfflineResourceList
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIDOMOFFLINERESOURCELIST
|
||||||
|
|
||||||
|
nsDOMOfflineResourceList();
|
||||||
|
virtual ~nsDOMOfflineResourceList();
|
||||||
|
|
||||||
|
nsresult Init(nsIURI *aURI);
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsresult GetCacheKey(const nsAString &aURI, nsCString &aKey);
|
||||||
|
nsresult GetCacheKey(nsIURI *aURI, nsCString &aKey);
|
||||||
|
|
||||||
|
nsresult CacheKeys();
|
||||||
|
void ClearCachedKeys();
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> mURI;
|
||||||
|
nsCOMPtr<nsIOfflineCacheSession> mCacheSession;
|
||||||
|
nsCAutoString mHostPort;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -44,6 +44,7 @@ include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
DIRS = lib \
|
DIRS = lib \
|
||||||
prototype \
|
prototype \
|
||||||
|
offline \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,53 @@
|
||||||
|
#
|
||||||
|
# ***** 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 Foundation.
|
||||||
|
# Portions created by the Initial Developer are Copyright (C) 2007
|
||||||
|
# the Initial Developer. All Rights Reserved.
|
||||||
|
#
|
||||||
|
# Contributor(s):
|
||||||
|
#
|
||||||
|
# Alternatively, the contents of this file may be used under the terms of
|
||||||
|
# either of 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 *****
|
||||||
|
|
||||||
|
DEPTH = ../../../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
relativesrcdir = dom/tests/mochitest/ajax/offline
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
_TEST_FILES = \
|
||||||
|
test_offlineResources.html \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
libs:: $(_TEST_FILES)
|
||||||
|
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
|
|
@ -0,0 +1,150 @@
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>navigator.offlineResources Test</title>
|
||||||
|
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||||
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
|
||||||
|
var nsICache = Components.interfaces.nsICache;
|
||||||
|
var base = window.location.protocol + "//" + window.location.host;
|
||||||
|
var packedURL = base + "/MochiKit/packed.js";
|
||||||
|
var simpleTestURL = base + "/tests/SimpleTest/SimpleTest.js";
|
||||||
|
var thisURL = base + window.location.pathname;
|
||||||
|
|
||||||
|
function check_cache(url, expectEntry)
|
||||||
|
{
|
||||||
|
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
|
||||||
|
.getService(Components.interfaces.nsICacheService);
|
||||||
|
var cacheSession = cacheService.createSession("HTTP-offline",
|
||||||
|
nsICache.STORE_OFFLINE,
|
||||||
|
true);
|
||||||
|
try {
|
||||||
|
var entry = cacheSession.openCacheEntry(url, nsICache.ACCESS_READ, true);
|
||||||
|
ok(expectEntry == true, url + " should exist in the offline cache");
|
||||||
|
entry.close();
|
||||||
|
} catch (e) {
|
||||||
|
// this constant isn't in Components.results
|
||||||
|
const kNetBase = 2152398848; // 0x804B0000
|
||||||
|
var NS_ERROR_CACHE_KEY_NOT_FOUND = kNetBase + 61
|
||||||
|
if (e.result == NS_ERROR_CACHE_KEY_NOT_FOUND) {
|
||||||
|
ok(expectEntry == false, url + " should not exist in the offline cache");
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_list(array)
|
||||||
|
{
|
||||||
|
var checkObj = {};
|
||||||
|
for (var i = 0; i < array.length; i++) {
|
||||||
|
checkObj[array[i]] = true;
|
||||||
|
}
|
||||||
|
for (var i = 0; i < navigator.offlineResources.length; i++) {
|
||||||
|
ok (navigator.offlineResources[i] in checkObj,
|
||||||
|
navigator.offlineResources[i] + " should not be in offlineResources");
|
||||||
|
delete checkObj[navigator.offlineResources[i]];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var key in checkObj) {
|
||||||
|
ok(false, key + " was not in navigator.offlineResources");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_eviction()
|
||||||
|
{
|
||||||
|
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
|
||||||
|
.getService(Components.interfaces.nsICacheService);
|
||||||
|
var cacheSession = cacheService.createSession("HTTP-offline",
|
||||||
|
nsICache.STORE_OFFLINE,
|
||||||
|
true)
|
||||||
|
.QueryInterface(Components.interfaces.nsIOfflineCacheSession);
|
||||||
|
cacheSession.evictUnownedEntries();
|
||||||
|
}
|
||||||
|
|
||||||
|
function clear_cache()
|
||||||
|
{
|
||||||
|
var cacheService = Components.classes["@mozilla.org/network/cache-service;1"]
|
||||||
|
.getService(Components.interfaces.nsICacheService);
|
||||||
|
|
||||||
|
cacheService.evictEntries(nsICache.STORE_OFFLINE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function load_done() {
|
||||||
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||||
|
check_list([packedURL, simpleTestURL, thisURL]);
|
||||||
|
|
||||||
|
check_cache(packedURL, true);
|
||||||
|
check_cache(simpleTestURL, true);
|
||||||
|
check_cache(thisURL, true);
|
||||||
|
|
||||||
|
navigator.offlineResources.remove(packedURL);
|
||||||
|
run_eviction();
|
||||||
|
|
||||||
|
check_list([simpleTestURL, thisURL]);
|
||||||
|
|
||||||
|
// Make sure the removed entry was evicted but the others weren't
|
||||||
|
check_cache(packedURL, false);
|
||||||
|
check_cache(simpleTestURL, true);
|
||||||
|
check_cache(thisURL, true);
|
||||||
|
|
||||||
|
navigator.offlineResources.clear();
|
||||||
|
run_eviction();
|
||||||
|
|
||||||
|
check_list([]);
|
||||||
|
|
||||||
|
check_cache(packedURL, false);
|
||||||
|
check_cache(simpleTestURL, false);
|
||||||
|
check_cache(thisURL, false);
|
||||||
|
|
||||||
|
// Clear out the offline cache on the way out
|
||||||
|
clear_cache();
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
function run_test()
|
||||||
|
{
|
||||||
|
// Clear the offline cache to make sure we're the one adding to it
|
||||||
|
clear_cache();
|
||||||
|
|
||||||
|
// Check invalid urls
|
||||||
|
try {
|
||||||
|
navigator.offlineResources.add("/blah/blah");
|
||||||
|
ok(false, "relative URLs cannot be added");
|
||||||
|
} catch(e) {
|
||||||
|
ok(true, "relative URLs should throw an error");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
navigator.offlineResources.add("ftp://localhost/blah/blah");
|
||||||
|
ok(false, "urls must be http or https");
|
||||||
|
} catch(e) {
|
||||||
|
ok(true, "urls must be http or https");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the correct resources
|
||||||
|
navigator.offlineResources.add(packedURL);
|
||||||
|
navigator.offlineResources.add(simpleTestURL);
|
||||||
|
navigator.offlineResources.add(thisURL);
|
||||||
|
|
||||||
|
// Give the offline resources some time to load; Once pendingOfflineLoads
|
||||||
|
// is implemented, we can use that instead.
|
||||||
|
setTimeout("load_done()", 1000);
|
||||||
|
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
run_test();
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -148,6 +148,7 @@ SHARED_LIBRARY_LIBS = \
|
||||||
$(DEPTH)/dom/src/events/$(LIB_PREFIX)jsdomevents_s.$(LIB_SUFFIX) \
|
$(DEPTH)/dom/src/events/$(LIB_PREFIX)jsdomevents_s.$(LIB_SUFFIX) \
|
||||||
$(DEPTH)/dom/src/jsurl/$(LIB_PREFIX)jsurl_s.$(LIB_SUFFIX) \
|
$(DEPTH)/dom/src/jsurl/$(LIB_PREFIX)jsurl_s.$(LIB_SUFFIX) \
|
||||||
$(DEPTH)/dom/src/storage/$(LIB_PREFIX)jsdomstorage_s.$(LIB_SUFFIX) \
|
$(DEPTH)/dom/src/storage/$(LIB_PREFIX)jsdomstorage_s.$(LIB_SUFFIX) \
|
||||||
|
$(DEPTH)/dom/src/offline/$(LIB_PREFIX)jsdomoffline_s.$(LIB_SUFFIX) \
|
||||||
$(DEPTH)/editor/libeditor/text/$(LIB_PREFIX)texteditor_s.$(LIB_SUFFIX) \
|
$(DEPTH)/editor/libeditor/text/$(LIB_PREFIX)texteditor_s.$(LIB_SUFFIX) \
|
||||||
$(DEPTH)/editor/libeditor/base/$(LIB_PREFIX)editorbase_s.$(LIB_SUFFIX) \
|
$(DEPTH)/editor/libeditor/base/$(LIB_PREFIX)editorbase_s.$(LIB_SUFFIX) \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
@ -278,6 +279,7 @@ LOCAL_INCLUDES += -I$(srcdir)/../base \
|
||||||
-I$(topsrcdir)/dom/src/base \
|
-I$(topsrcdir)/dom/src/base \
|
||||||
-I$(topsrcdir)/dom/src/jsurl \
|
-I$(topsrcdir)/dom/src/jsurl \
|
||||||
-I$(topsrcdir)/dom/src/storage \
|
-I$(topsrcdir)/dom/src/storage \
|
||||||
|
-I$(topsrcdir)/dom/src/offline \
|
||||||
-I. \
|
-I. \
|
||||||
-I$(topsrcdir)/editor/libeditor/base \
|
-I$(topsrcdir)/editor/libeditor/base \
|
||||||
-I$(topsrcdir)/editor/libeditor/text \
|
-I$(topsrcdir)/editor/libeditor/text \
|
||||||
|
|
|
@ -284,6 +284,7 @@ nsPrefetchService::nsPrefetchService()
|
||||||
: mQueueHead(nsnull)
|
: mQueueHead(nsnull)
|
||||||
, mQueueTail(nsnull)
|
, mQueueTail(nsnull)
|
||||||
, mStopCount(0)
|
, mStopCount(0)
|
||||||
|
, mHaveProcessed(PR_FALSE)
|
||||||
, mDisabled(PR_TRUE)
|
, mDisabled(PR_TRUE)
|
||||||
, mFetchedOffline(PR_FALSE)
|
, mFetchedOffline(PR_FALSE)
|
||||||
{
|
{
|
||||||
|
@ -539,8 +540,10 @@ nsPrefetchService::StartPrefetching()
|
||||||
// only start prefetching after we've received enough DOCUMENT
|
// only start prefetching after we've received enough DOCUMENT
|
||||||
// STOP notifications. we do this inorder to defer prefetching
|
// STOP notifications. we do this inorder to defer prefetching
|
||||||
// until after all sub-frames have finished loading.
|
// until after all sub-frames have finished loading.
|
||||||
if (mStopCount == 0 && !mCurrentChannel)
|
if (mStopCount == 0 && !mCurrentChannel) {
|
||||||
|
mHaveProcessed = PR_TRUE;
|
||||||
ProcessNextURI();
|
ProcessNextURI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -716,7 +719,14 @@ nsPrefetchService::Prefetch(nsIURI *aURI,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return EnqueueURI(aURI, aReferrerURI, aOffline);
|
rv = EnqueueURI(aURI, aReferrerURI, aOffline);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// if there are no pages loading, kick off the request immediately
|
||||||
|
if (mStopCount == 0 && mHaveProcessed)
|
||||||
|
ProcessNextURI();
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
|
|
@ -102,6 +102,8 @@ private:
|
||||||
nsPrefetchNode *mQueueTail;
|
nsPrefetchNode *mQueueTail;
|
||||||
nsCOMPtr<nsIChannel> mCurrentChannel;
|
nsCOMPtr<nsIChannel> mCurrentChannel;
|
||||||
PRInt32 mStopCount;
|
PRInt32 mStopCount;
|
||||||
|
// true if pending document loads have ever reached zero.
|
||||||
|
PRInt32 mHaveProcessed;
|
||||||
PRBool mDisabled;
|
PRBool mDisabled;
|
||||||
PRBool mFetchedOffline;
|
PRBool mFetchedOffline;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче