mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 03:45:46 +00:00
Bug 876240 - Move OfflineResourceList to WebIDL; r=mounir
This commit is contained in:
parent
26a2156b34
commit
4b6bac58fd
@ -662,9 +662,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
nsIXPCScriptable::DONT_ENUM_STATIC_PROPS |
|
||||
nsIXPCScriptable::WANT_NEWENUMERATE)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(OfflineResourceList, nsOfflineResourceListSH,
|
||||
ARRAY_SCRIPTABLE_FLAGS)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(Blob, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
NS_DEFINE_CLASSINFO_DATA(File, nsDOMGenericSH,
|
||||
@ -1763,11 +1760,6 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMStorage)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(OfflineResourceList, nsIDOMOfflineResourceList)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMOfflineResourceList)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(Blob, nsIDOMBlob)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMBlob)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
@ -6888,22 +6880,3 @@ nsNonDOMObjectSH::GetFlags(uint32_t *aFlags)
|
||||
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY | nsIClassInfo::SINGLETON_CLASSINFO;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsOfflineResourceListSH
|
||||
nsresult
|
||||
nsOfflineResourceListSH::GetStringAt(nsISupports *aNative, int32_t aIndex,
|
||||
nsAString& aResult)
|
||||
{
|
||||
nsCOMPtr<nsIDOMOfflineResourceList> list(do_QueryInterface(aNative));
|
||||
NS_ENSURE_TRUE(list, NS_ERROR_UNEXPECTED);
|
||||
|
||||
nsresult rv = list->MozItem(aIndex, aResult);
|
||||
#ifdef DEBUG
|
||||
if (DOMStringIsNull(aResult)) {
|
||||
uint32_t length = 0;
|
||||
list->GetMozLength(&length);
|
||||
NS_ASSERTION(uint32_t(aIndex) >= length, "MozItem should only return null for out-of-bounds access");
|
||||
}
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
@ -1019,25 +1019,4 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class nsOfflineResourceListSH : public nsStringArraySH
|
||||
{
|
||||
protected:
|
||||
nsOfflineResourceListSH(nsDOMClassInfoData* aData) : nsStringArraySH(aData)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~nsOfflineResourceListSH()
|
||||
{
|
||||
}
|
||||
|
||||
virtual nsresult GetStringAt(nsISupports *aNative, int32_t aIndex,
|
||||
nsAString& aResult);
|
||||
|
||||
public:
|
||||
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
||||
{
|
||||
return new nsOfflineResourceListSH(aData);
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* nsDOMClassInfo_h___ */
|
||||
|
@ -109,8 +109,6 @@ DOMCI_CLASS(XPathResult)
|
||||
// WhatWG WebApps Objects
|
||||
DOMCI_CLASS(Storage)
|
||||
|
||||
DOMCI_CLASS(OfflineResourceList)
|
||||
|
||||
DOMCI_CLASS(Blob)
|
||||
DOMCI_CLASS(File)
|
||||
|
||||
|
@ -693,6 +693,10 @@ DOMInterfaces = {
|
||||
'resultNotAddRefed': [ 'destination', 'listener' ],
|
||||
},
|
||||
|
||||
'OfflineResourceList': {
|
||||
'nativeType': 'nsDOMOfflineResourceList',
|
||||
},
|
||||
|
||||
'PaintRequest': {
|
||||
'nativeType': 'nsPaintRequest',
|
||||
},
|
||||
|
@ -6,6 +6,9 @@
|
||||
|
||||
MODULE = 'dom'
|
||||
|
||||
EXPORTS += [
|
||||
'nsDOMOfflineResourceList.h',
|
||||
]
|
||||
CPP_SOURCES += [
|
||||
'nsDOMOfflineResourceList.cpp',
|
||||
]
|
||||
|
@ -4,7 +4,6 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "nsDOMOfflineResourceList.h"
|
||||
#include "nsDOMClassInfoID.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsError.h"
|
||||
#include "nsDOMLists.h"
|
||||
@ -22,6 +21,7 @@
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "mozilla/dom/OfflineResourceListBinding.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
#include "nsXULAppAPI.h"
|
||||
@ -29,6 +29,7 @@
|
||||
(GeckoProcessType_Default != XRE_GetProcessType())
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
// Event names
|
||||
|
||||
@ -57,14 +58,11 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED_2(nsDOMOfflineResourceList,
|
||||
mCacheUpdate,
|
||||
mPendingEvents)
|
||||
|
||||
DOMCI_DATA(OfflineResourceList, nsDOMOfflineResourceList)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsDOMOfflineResourceList)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMOfflineResourceList)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIOfflineCacheUpdateObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(OfflineResourceList)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMOfflineResourceList, nsDOMEventTargetHelper)
|
||||
@ -92,6 +90,7 @@ nsDOMOfflineResourceList::nsDOMOfflineResourceList(nsIURI *aManifestURI,
|
||||
, mCachedKeysCount(0)
|
||||
{
|
||||
BindToOwner(aWindow);
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
|
||||
@ -99,6 +98,13 @@ nsDOMOfflineResourceList::~nsDOMOfflineResourceList()
|
||||
ClearCachedKeys();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
nsDOMOfflineResourceList::WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aScope)
|
||||
{
|
||||
return OfflineResourceListBinding::Wrap(aCx, aScope, this);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMOfflineResourceList::Init()
|
||||
{
|
||||
@ -187,7 +193,6 @@ nsDOMOfflineResourceList::GetMozItems(nsIDOMDOMStringList **aItems)
|
||||
*aItems = nullptr;
|
||||
|
||||
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.
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsDOMEventTargetHelper.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsIDOMDOMStringList.h"
|
||||
|
||||
class nsIDOMWindow;
|
||||
|
||||
@ -34,6 +36,8 @@ class nsDOMOfflineResourceList : public nsDOMEventTargetHelper,
|
||||
public nsIOfflineCacheUpdateObserver,
|
||||
public nsSupportsWeakReference
|
||||
{
|
||||
typedef mozilla::ErrorResult ErrorResult;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIDOMOFFLINERESOURCELIST
|
||||
@ -53,6 +57,80 @@ public:
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsPIDOMWindow* GetParentObject() const
|
||||
{
|
||||
return GetOwner();
|
||||
}
|
||||
virtual JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
|
||||
|
||||
uint16_t GetStatus(ErrorResult& aRv)
|
||||
{
|
||||
uint16_t status = 0;
|
||||
aRv = GetStatus(&status);
|
||||
return status;
|
||||
}
|
||||
void Update(ErrorResult& aRv)
|
||||
{
|
||||
aRv = Update();
|
||||
}
|
||||
void SwapCache(ErrorResult& aRv)
|
||||
{
|
||||
aRv = SwapCache();
|
||||
}
|
||||
|
||||
IMPL_EVENT_HANDLER(checking)
|
||||
IMPL_EVENT_HANDLER(error)
|
||||
IMPL_EVENT_HANDLER(noupdate)
|
||||
IMPL_EVENT_HANDLER(downloading)
|
||||
IMPL_EVENT_HANDLER(progress)
|
||||
IMPL_EVENT_HANDLER(cached)
|
||||
IMPL_EVENT_HANDLER(updateready)
|
||||
IMPL_EVENT_HANDLER(obsolete)
|
||||
|
||||
already_AddRefed<nsIDOMDOMStringList> GetMozItems(ErrorResult& aRv)
|
||||
{
|
||||
nsCOMPtr<nsIDOMDOMStringList> items;
|
||||
aRv = GetMozItems(getter_AddRefs(items));
|
||||
return items.forget();
|
||||
}
|
||||
bool MozHasItem(const nsAString& aURI, ErrorResult& aRv)
|
||||
{
|
||||
bool hasItem = false;
|
||||
aRv = MozHasItem(aURI, &hasItem);
|
||||
return hasItem;
|
||||
}
|
||||
uint32_t GetMozLength(ErrorResult& aRv)
|
||||
{
|
||||
uint32_t length = 0;
|
||||
aRv = GetMozLength(&length);
|
||||
return length;
|
||||
}
|
||||
void MozItem(uint32_t aIndex, nsAString& aURI, ErrorResult& aRv)
|
||||
{
|
||||
aRv = MozItem(aIndex, aURI);
|
||||
}
|
||||
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aURI,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MozItem(aIndex, aURI, aRv);
|
||||
aFound = !aURI.IsVoid();
|
||||
}
|
||||
uint32_t Length()
|
||||
{
|
||||
ErrorResult rv;
|
||||
uint32_t length = GetMozLength(rv);
|
||||
return rv.Failed() ? 0 : length;
|
||||
}
|
||||
void MozAdd(const nsAString& aURI, ErrorResult& aRv)
|
||||
{
|
||||
aRv = MozAdd(aURI);
|
||||
}
|
||||
void MozRemove(const nsAString& aURI, ErrorResult& aRv)
|
||||
{
|
||||
aRv = MozRemove(aURI);
|
||||
}
|
||||
|
||||
private:
|
||||
nsresult SendEvent(const nsAString &aEventName);
|
||||
|
||||
|
116
dom/webidl/OfflineResourceList.webidl
Normal file
116
dom/webidl/OfflineResourceList.webidl
Normal file
@ -0,0 +1,116 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
interface OfflineResourceList : EventTarget {
|
||||
/**
|
||||
* State of the application cache this object is associated with.
|
||||
*/
|
||||
|
||||
/* This object is not associated with an application cache. */
|
||||
const unsigned short UNCACHED = 0;
|
||||
|
||||
/* The application cache is not being updated. */
|
||||
const unsigned short IDLE = 1;
|
||||
|
||||
/* The manifest is being fetched and checked for updates */
|
||||
const unsigned short CHECKING = 2;
|
||||
|
||||
/* Resources are being downloaded to be added to the cache */
|
||||
const unsigned short DOWNLOADING = 3;
|
||||
|
||||
/* There is a new version of the application cache available */
|
||||
const unsigned short UPDATEREADY = 4;
|
||||
|
||||
/* The application cache group is now obsolete. */
|
||||
const unsigned short OBSOLETE = 5;
|
||||
|
||||
[Throws]
|
||||
readonly attribute unsigned short status;
|
||||
|
||||
/**
|
||||
* Begin the application update process on the associated application cache.
|
||||
*/
|
||||
[Throws]
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Swap in the newest version of the application cache, or disassociate
|
||||
* from the cache if the cache group is obsolete.
|
||||
*/
|
||||
[Throws]
|
||||
void swapCache();
|
||||
|
||||
/* Events */
|
||||
[SetterThrows]
|
||||
attribute EventHandler onchecking;
|
||||
[SetterThrows]
|
||||
attribute EventHandler onerror;
|
||||
[SetterThrows]
|
||||
attribute EventHandler onnoupdate;
|
||||
[SetterThrows]
|
||||
attribute EventHandler ondownloading;
|
||||
[SetterThrows]
|
||||
attribute EventHandler onprogress;
|
||||
[SetterThrows]
|
||||
attribute EventHandler onupdateready;
|
||||
[SetterThrows]
|
||||
attribute EventHandler oncached;
|
||||
[SetterThrows]
|
||||
attribute EventHandler onobsolete;
|
||||
};
|
||||
|
||||
// Mozilla extensions.
|
||||
partial interface OfflineResourceList {
|
||||
/**
|
||||
* Get the list of dynamically-managed entries.
|
||||
*/
|
||||
[Throws]
|
||||
readonly attribute DOMStringList mozItems;
|
||||
|
||||
/**
|
||||
* Check that an entry exists in the list of dynamically-managed entries.
|
||||
*
|
||||
* @param uri
|
||||
* The resource to check.
|
||||
*/
|
||||
[Throws]
|
||||
boolean mozHasItem(DOMString uri);
|
||||
|
||||
/**
|
||||
* Get the number of dynamically-managed entries.
|
||||
* @status DEPRECATED
|
||||
* Clients should use the "items" attribute.
|
||||
*/
|
||||
[Throws]
|
||||
readonly attribute unsigned long mozLength;
|
||||
|
||||
/**
|
||||
* Get the URI of a dynamically-managed entry.
|
||||
* @status DEPRECATED
|
||||
* Clients should use the "items" attribute.
|
||||
*/
|
||||
[Throws]
|
||||
getter DOMString mozItem(unsigned long index);
|
||||
|
||||
/**
|
||||
* Add an item to the list of dynamically-managed entries. The resource
|
||||
* will be fetched into the application cache.
|
||||
*
|
||||
* @param uri
|
||||
* The resource to add.
|
||||
*/
|
||||
[Throws]
|
||||
void mozAdd(DOMString uri);
|
||||
|
||||
/**
|
||||
* Remove an item from the list of dynamically-managed entries. If this
|
||||
* was the last reference to a URI in the application cache, the cache
|
||||
* entry will be removed.
|
||||
*
|
||||
* @param uri
|
||||
* The resource to remove.
|
||||
*/
|
||||
[Throws]
|
||||
void mozRemove(DOMString uri);
|
||||
};
|
@ -189,6 +189,7 @@ webidl_files = \
|
||||
NotifyPaintEvent.webidl \
|
||||
OfflineAudioCompletionEvent.webidl \
|
||||
OfflineAudioContext.webidl \
|
||||
OfflineResourceList.webidl \
|
||||
PaintRequest.webidl \
|
||||
PaintRequestList.webidl \
|
||||
PannerNode.webidl \
|
||||
|
Loading…
Reference in New Issue
Block a user