This commit is contained in:
Ms2ger 2013-06-01 15:00:46 +02:00
Родитель 4228bfc476 9311b37104
Коммит ebfa207500
37 изменённых файлов: 746 добавлений и 628 удалений

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

@ -1,5 +1,5 @@
<?xml version="1.0"?>
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist" lastupdate="1369429787000">
<blocklist xmlns="http://www.mozilla.org/2006/addons-blocklist" lastupdate="1369693795000">
<emItems>
<emItem blockID="i350" id="sqlmoz@facebook.com">
<versionRange minVersion="0" maxVersion="*" severity="3">
@ -708,14 +708,14 @@
</versionRange>
</pluginItem>
<pluginItem blockID="p178">
<match name="filename" exp="(NPSWF[0-9_]*\.dll)|(Flash\ Player\.plugin)" /> <versionRange minVersion="11.0" maxVersion="11.4.*" severity="0" vulnerabilitystatus="1">
<match name="filename" exp="(NPSWF[0-9_]*\.dll)|(Flash\ Player\.plugin)" /> <versionRange minVersion="11.0" maxVersion="11.6.602.175" severity="0" vulnerabilitystatus="1">
<targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
<versionRange minVersion="19.0a1" maxVersion="*" />
</targetApplication>
</versionRange>
</pluginItem>
<pluginItem blockID="p178">
<match name="filename" exp="(NPSWF[0-9_]*\.dll)|(Flash\ Player\.plugin)" /> <versionRange minVersion="11.0" maxVersion="11.4.*" severity="0" vulnerabilitystatus="1">
<match name="filename" exp="(NPSWF[0-9_]*\.dll)|(Flash\ Player\.plugin)" /> <versionRange minVersion="11.0" maxVersion="11.6.602.175" severity="0" vulnerabilitystatus="1">
<targetApplication id="{ec8030f7-c20a-464f-9b0e-13a3a9e97384}">
<versionRange minVersion="17.0.4" maxVersion="17.0.*" />
</targetApplication>

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

@ -2102,8 +2102,8 @@ nsScriptSecurityManager::old_doGetObjectPrincipal(JS::Handle<JSObject*> aObj,
if (!(~jsClass->flags & (JSCLASS_HAS_PRIVATE |
JSCLASS_PRIVATE_IS_NSISUPPORTS))) {
priv = (nsISupports *) js::GetObjectPrivate(obj);
} else if (!UnwrapDOMObjectToISupports(obj, priv)) {
priv = nullptr;
} else {
priv = UnwrapDOMObjectToISupports(obj);
}
if (aAllowShortCircuit) {

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

@ -0,0 +1 @@
<select><option id="foo"><script>document.querySelector("select").namedItem("foo")</script>

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

@ -52,3 +52,4 @@ load 837033.html
pref(dom.experimental_forms_range,true) load 838256-1.html
load 862084.html
load 865147.html
load 877910.html

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

@ -247,13 +247,12 @@ HTMLOptionsCollection::GetElementAt(uint32_t aIndex)
return ItemAsOption(aIndex);
}
static HTMLOptionElement*
GetNamedItemHelper(nsTArray<nsRefPtr<HTMLOptionElement> > &aElements,
const nsAString& aName)
HTMLOptionElement*
HTMLOptionsCollection::GetNamedItem(const nsAString& aName) const
{
uint32_t count = aElements.Length();
uint32_t count = mElements.Length();
for (uint32_t i = 0; i < count; i++) {
HTMLOptionElement* content = aElements.ElementAt(i);
HTMLOptionElement* content = mElements.ElementAt(i);
if (content &&
(content->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name, aName,
eCaseMatters) ||
@ -276,7 +275,7 @@ NS_IMETHODIMP
HTMLOptionsCollection::NamedItem(const nsAString& aName,
nsIDOMNode** aReturn)
{
NS_IF_ADDREF(*aReturn = GetNamedItemHelper(mElements, aName));
NS_IF_ADDREF(*aReturn = GetNamedItem(aName));
return NS_OK;
}
@ -285,7 +284,7 @@ JSObject*
HTMLOptionsCollection::NamedItem(JSContext* cx, const nsAString& name,
ErrorResult& error)
{
nsINode* item = GetNamedItemHelper(mElements, name);
nsINode* item = GetNamedItem(name);
if (!item) {
return nullptr;
}

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

@ -122,6 +122,7 @@ public:
int32_t aStartIndex, bool aForward,
int32_t* aIndex);
HTMLOptionElement* GetNamedItem(const nsAString& aName) const;
virtual JSObject* NamedItem(JSContext* aCx, const nsAString& aName,
ErrorResult& error) MOZ_OVERRIDE;

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

@ -206,10 +206,9 @@ public:
{
return mOptions->ItemAsOption(aIdx);
}
JSObject* NamedItem(JSContext* aCx, const nsAString& aName,
ErrorResult& aRv) const
HTMLOptionElement* NamedItem(const nsAString& aName) const
{
return mOptions->NamedItem(aCx, aName, aRv);
return mOptions->GetNamedItem(aName);
}
void Add(const HTMLOptionElementOrHTMLOptGroupElement& aElement,
const Nullable<HTMLElementOrLong>& aBefore,

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

@ -199,9 +199,6 @@
// Storage includes
#include "DOMStorage.h"
// Device Storage
#include "nsIDOMDeviceStorage.h"
// Drag and drop
#include "nsIDOMDataTransfer.h"
@ -662,9 +659,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,
@ -674,9 +668,6 @@ static nsDOMClassInfoData sClassInfoData[] = {
DEFAULT_SCRIPTABLE_FLAGS |
WINDOW_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(DeviceStorage, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(GeoPositionCoords, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
@ -908,7 +899,6 @@ jsid nsDOMClassInfo::sDocument_id = JSID_VOID;
jsid nsDOMClassInfo::sFrames_id = JSID_VOID;
jsid nsDOMClassInfo::sSelf_id = JSID_VOID;
jsid nsDOMClassInfo::sAll_id = JSID_VOID;
jsid nsDOMClassInfo::sTags_id = JSID_VOID;
jsid nsDOMClassInfo::sWrappedJSObject_id = JSID_VOID;
jsid nsDOMClassInfo::sURL_id = JSID_VOID;
jsid nsDOMClassInfo::sOnload_id = JSID_VOID;
@ -1165,7 +1155,6 @@ nsDOMClassInfo::DefineStaticJSVals(JSContext *cx)
SET_JSID_TO_STRING(sFrames_id, cx, "frames");
SET_JSID_TO_STRING(sSelf_id, cx, "self");
SET_JSID_TO_STRING(sAll_id, cx, "all");
SET_JSID_TO_STRING(sTags_id, cx, "tags");
SET_JSID_TO_STRING(sWrappedJSObject_id, cx, "wrappedJSObject");
SET_JSID_TO_STRING(sURL_id, cx, "URL");
SET_JSID_TO_STRING(sOnload_id, cx, "onload");
@ -1765,11 +1754,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
@ -1787,11 +1771,6 @@ nsDOMClassInfo::Init()
#endif
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(DeviceStorage, nsIDOMDeviceStorage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDeviceStorage)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(GeoPositionCoords, nsIDOMGeoPositionCoords)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMGeoPositionCoords)
DOM_CLASSINFO_MAP_END
@ -2710,7 +2689,6 @@ nsDOMClassInfo::ShutDown()
sFrames_id = JSID_VOID;
sSelf_id = JSID_VOID;
sAll_id = JSID_VOID;
sTags_id = JSID_VOID;
sWrappedJSObject_id = JSID_VOID;
sOnload_id = JSID_VOID;
sOnerror_id = JSID_VOID;
@ -5756,21 +5734,6 @@ static JSClass sHTMLDocumentAllHelperClass = {
};
static JSClass sHTMLDocumentAllTagsClass = {
"HTML document.all.tags class",
JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE | JSCLASS_PRIVATE_IS_NSISUPPORTS,
JS_PropertyStub, /* addProperty */
JS_DeletePropertyStub, /* delProperty */
JS_PropertyStub, /* getProperty */
JS_StrictPropertyStub, /* setProperty */
JS_EnumerateStub,
(JSResolveOp)nsHTMLDocumentSH::DocumentAllTagsNewResolve,
JS_ConvertStub,
nsHTMLDocumentSH::ReleaseDocument,
nullptr, /* checkAccess */
nsHTMLDocumentSH::CallToGetPropMapper
};
// static
JSBool
nsHTMLDocumentSH::GetDocumentAllNodeList(JSContext *cx,
@ -5894,21 +5857,15 @@ nsHTMLDocumentSH::DocumentAllGetProperty(JSContext *cx, JSHandleObject obj_,
vp.set(INT_TO_JSVAL(length));
return JS_TRUE;
} else if (nsDOMClassInfo::sTags_id != id) {
// For all other strings, look for an element by id or name.
nsDependentJSString str(id);
result = doc->GetDocumentAllResult(str, &cache, &rv);
if (NS_FAILED(rv)) {
xpc::Throw(cx, rv);
return JS_FALSE;
}
}
else {
result = nullptr;
// For all other strings, look for an element by id or name.
nsDependentJSString str(id);
result = doc->GetDocumentAllResult(str, &cache, &rv);
if (NS_FAILED(rv)) {
xpc::Throw(cx, rv);
return JS_FALSE;
}
} else if (JSID_IS_INT(id) && JSID_TO_INT(id) >= 0) {
// Map document.all[n] (where n is a number) to the n:th item in
@ -5964,21 +5921,6 @@ nsHTMLDocumentSH::DocumentAllNewResolve(JSContext *cx, JSHandleObject obj, JSHan
// DocumentAllGetProperty().
v = JSVAL_ONE;
} else if (nsDOMClassInfo::sTags_id == id) {
nsHTMLDocument *doc = GetDocument(obj);
JSObject *tags = ::JS_NewObject(cx, &sHTMLDocumentAllTagsClass, nullptr,
::JS_GetGlobalForObject(cx, obj));
if (!tags) {
return JS_FALSE;
}
::JS_SetPrivate(tags, doc);
// The "tags" JSObject now also owns doc.
NS_ADDREF(doc);
v = OBJECT_TO_JSVAL(tags);
} else {
if (!DocumentAllGetProperty(cx, obj, id, &v)) {
return JS_FALSE;
@ -6125,58 +6067,6 @@ nsHTMLDocumentSH::DocumentAllHelperNewResolve(JSContext *cx, JSHandleObject obj,
}
JSBool
nsHTMLDocumentSH::DocumentAllTagsNewResolve(JSContext *cx, JSHandleObject obj,
JSHandleId id, unsigned flags,
JS::MutableHandle<JSObject*> objp)
{
if (JSID_IS_STRING(id)) {
nsDocument *doc = GetDocument(obj);
JS::Rooted<JSObject*> proto(cx);
if (!::JS_GetPrototype(cx, obj, proto.address())) {
return JS_FALSE;
}
if (MOZ_UNLIKELY(!proto)) {
return JS_TRUE;
}
JSBool found;
if (!::JS_HasPropertyById(cx, proto, id, &found)) {
return JS_FALSE;
}
if (found) {
return JS_TRUE;
}
nsRefPtr<nsContentList> tags =
doc->GetElementsByTagName(nsDependentJSString(id));
if (tags) {
JS::Rooted<JS::Value> v(cx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = WrapNative(cx, JS_GetGlobalForScopeChain(cx),
static_cast<nsINodeList*>(tags), tags, true,
v.address(), getter_AddRefs(holder));
if (NS_FAILED(rv)) {
xpc::Throw(cx, rv);
return JS_FALSE;
}
if (!::JS_DefinePropertyById(cx, obj, id, v, nullptr, nullptr, 0)) {
return JS_FALSE;
}
objp.set(obj);
}
}
return JS_TRUE;
}
static nsresult
ResolveAll(JSContext* cx, nsIDocument* doc, JS::Handle<JSObject*> obj)
{
@ -6979,22 +6869,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;
}

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

@ -218,7 +218,6 @@ public:
static jsid sFrames_id;
static jsid sSelf_id;
static jsid sAll_id;
static jsid sTags_id;
static jsid sJava_id;
static jsid sPackages_id;
static jsid sWrappedJSObject_id;
@ -612,9 +611,6 @@ public:
static JSBool DocumentAllHelperNewResolve(JSContext *cx, JSHandleObject obj,
JSHandleId id, unsigned flags,
JS::MutableHandle<JSObject*> objp);
static JSBool DocumentAllTagsNewResolve(JSContext *cx, JSHandleObject obj,
JSHandleId id, unsigned flags,
JS::MutableHandle<JSObject*> objp);
static nsresult TryResolveAll(JSContext* cx, nsHTMLDocument* doc,
JS::Handle<JSObject*> obj);
@ -1023,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,16 +109,12 @@ DOMCI_CLASS(XPathResult)
// WhatWG WebApps Objects
DOMCI_CLASS(Storage)
DOMCI_CLASS(OfflineResourceList)
DOMCI_CLASS(Blob)
DOMCI_CLASS(File)
// DOM modal content window class, almost identical to Window
DOMCI_CLASS(ModalContentWindow)
DOMCI_CLASS(DeviceStorage)
// Geolocation
DOMCI_CLASS(GeoPositionCoords)

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

@ -13,13 +13,14 @@
#include "BindingUtils.h"
#include "AccessCheck.h"
#include "jsfriendapi.h"
#include "nsContentUtils.h"
#include "nsIDOMGlobalPropertyInitializer.h"
#include "nsIXPConnect.h"
#include "WrapperFactory.h"
#include "xpcprivate.h"
#include "XPCQuickStubs.h"
#include "XrayWrapper.h"
#include "jsfriendapi.h"
#include "mozilla/dom/HTMLObjectElement.h"
#include "mozilla/dom/HTMLObjectElementBinding.h"
@ -600,8 +601,7 @@ NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx,
bool
TryPreserveWrapper(JSObject* obj)
{
nsISupports* native;
if (UnwrapDOMObjectToISupports(obj, native)) {
if (nsISupports* native = UnwrapDOMObjectToISupports(obj)) {
nsWrapperCache* cache = nullptr;
CallQueryInterface(native, &cache);
if (cache) {
@ -683,8 +683,8 @@ QueryInterface(JSContext* cx, unsigned argc, JS::Value* vp)
return false;
}
nsISupports* native;
if (!UnwrapDOMObjectToISupports(obj, native)) {
nsISupports* native = UnwrapDOMObjectToISupports(obj);
if (!native) {
return Throw<true>(cx, NS_ERROR_FAILURE);
}
@ -1469,8 +1469,8 @@ ReparentWrapper(JSContext* aCx, JS::HandleObject aObjArg)
return NS_OK;
}
nsISupports* native;
if (!UnwrapDOMObjectToISupports(aObj, native)) {
nsISupports* native = UnwrapDOMObjectToISupports(aObj);
if (!native) {
return NS_OK;
}
@ -1830,5 +1830,62 @@ GetWindowForJSImplementedObject(JSContext* cx, JS::Handle<JSObject*> obj,
return true;
}
already_AddRefed<nsPIDOMWindow>
ConstructJSImplementation(JSContext* aCx, const char* aContractId,
const GlobalObject& aGlobal,
JS::MutableHandle<JSObject*> aObject,
ErrorResult& aRv)
{
// Get the window to use as a parent and for initialization.
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.Get());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Make sure to have nothing on the JS context stack while creating and
// initializing the object, so exceptions from that will get reported
// properly, since those are never exceptions that a spec wants to be thrown.
{ // Scope for the nsCxPusher
nsCxPusher pusher;
pusher.PushNull();
// Get the XPCOM component containing the JS implementation.
nsCOMPtr<nsISupports> implISupports = do_CreateInstance(aContractId);
if (!implISupports) {
NS_WARNING("Failed to get JS implementation for contract");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Initialize the object, if it implements nsIDOMGlobalPropertyInitializer.
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi =
do_QueryInterface(implISupports);
if (gpi) {
JS::Rooted<JS::Value> initReturn(aCx);
nsresult rv = gpi->Init(window, initReturn.address());
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
MOZ_ASSERT(initReturn.isUndefined(),
"nsIDOMGlobalPropertyInitializer should return undefined");
}
// Extract the JS implementation from the XPCOM object.
nsCOMPtr<nsIXPConnectWrappedJS> implWrapped =
do_QueryInterface(implISupports);
MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component.");
if (!implWrapped) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
aObject.set(implWrapped->GetJSObject());
if (!aObject) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
}
return window.forget();
}
} // namespace dom
} // namespace mozilla

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

@ -153,16 +153,15 @@ GetDOMClass(JSObject* obj)
return nullptr;
}
inline bool
UnwrapDOMObjectToISupports(JSObject* obj, nsISupports*& result)
inline nsISupports*
UnwrapDOMObjectToISupports(JSObject* aObject)
{
const DOMClass* clasp = GetDOMClass(obj);
const DOMClass* clasp = GetDOMClass(aObject);
if (!clasp || !clasp->mDOMObjectIsISupports) {
return false;
return nullptr;
}
result = UnwrapDOMObject<nsISupports>(obj);
return true;
return UnwrapDOMObject<nsISupports>(aObject);
}
inline bool
@ -2041,6 +2040,12 @@ bool
GetWindowForJSImplementedObject(JSContext* cx, JS::Handle<JSObject*> obj,
nsPIDOMWindow** window);
already_AddRefed<nsPIDOMWindow>
ConstructJSImplementation(JSContext* aCx, const char* aContractId,
const GlobalObject& aGlobal,
JS::MutableHandle<JSObject*> aObject,
ErrorResult& aRv);
bool
RegisterForDeferredFinalization(DeferredFinalizeStartFunction start,
DeferredFinalizeFunction run);

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

@ -248,6 +248,11 @@ DOMInterfaces = {
'nativeType': 'nsDOMDeviceMotionEvent',
},
'DeviceStorage': {
'nativeType': 'nsDOMDeviceStorage',
'headerFile': 'DeviceStorage.h',
},
'Document': [
{
'nativeType': 'nsIDocument',
@ -693,6 +698,10 @@ DOMInterfaces = {
'resultNotAddRefed': [ 'destination', 'listener' ],
},
'OfflineResourceList': {
'nativeType': 'nsDOMOfflineResourceList',
},
'PaintRequest': {
'nativeType': 'nsPaintRequest',
},

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

@ -7640,7 +7640,15 @@ class CGDictionary(CGThing):
"// Per spec, we init the parent's members first\n"
"if (!%s::Init(cx, val)) {\n"
" return false;\n"
"}\n") % self.makeClassName(self.dictionary.parent)
"}\n"
"MOZ_ASSERT(IsConvertibleToDictionary(cx, val));\n"
"\n") % self.makeClassName(self.dictionary.parent)
else:
body += (
"if (!IsConvertibleToDictionary(cx, val)) {\n"
" return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY);\n"
"}\n"
"\n")
memberInits = [self.getMemberConversion(m).define()
for m in self.memberInfo]
@ -7649,14 +7657,6 @@ class CGDictionary(CGThing):
"JSBool found;\n"
"JS::Rooted<JS::Value> temp(cx);\n"
"bool isNull = val.isNullOrUndefined();\n")
body += (
"if (!IsConvertibleToDictionary(cx, val)) {\n"
" return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY);\n"
"}\n"
"\n")
if memberInits:
body += "\n\n".join(memberInits) + "\n"
body += "return true;"
@ -9053,60 +9053,24 @@ class CGJSImplMethod(CGNativeMember):
return genConstructorBody(self.descriptor, initCall)
def genConstructorBody(descriptor, initCall=""):
return string.Template(
""" // Get the window to use as a parent and for initialization.
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(global.Get());
if (!window) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
template = (
"JS::Rooted<JSObject*> jsImplObj(cx);\n"
"nsCOMPtr<nsPIDOMWindow> window =\n"
' ConstructJSImplementation(cx, "${contractId}", global, &jsImplObj, aRv);\n'
"if (aRv.Failed()) {\n"
" return nullptr;\n"
"}\n"
"// Build the C++ implementation.\n"
# Leave off the newline in case initCall is empty.
"nsRefPtr<${implClass}> impl = new ${implClass}(jsImplObj, window);"
"${initCall}\n"
"return impl.forget();")
JS::Rooted<JSObject*> jsImplObj(cx);
// Make sure to have nothing on the JS context stack while creating and
// initializing the object, so exceptions from that will get reported
// properly, since those are never exceptions that a spec wants to be thrown.
{ // Scope for the nsCxPusher
nsCxPusher pusher;
pusher.PushNull();
// Get the XPCOM component containing the JS implementation.
nsCOMPtr<nsISupports> implISupports = do_CreateInstance("${contractId}");
if (!implISupports) {
NS_WARNING("Failed to get JS implementation for contract \\"${contractId}\\"");
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// Initialize the object, if it implements nsIDOMGlobalPropertyInitializer.
nsCOMPtr<nsIDOMGlobalPropertyInitializer> gpi = do_QueryInterface(implISupports);
if (gpi) {
JS::Rooted<JS::Value> initReturn(cx);
nsresult rv = gpi->Init(window, initReturn.address());
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
MOZ_ASSERT(initReturn.isUndefined(),
"Expected nsIDOMGlobalPropertyInitializer to return undefined");
}
// Extract the JS implementation from the XPCOM object.
nsCOMPtr<nsIXPConnectWrappedJS> implWrapped = do_QueryInterface(implISupports);
MOZ_ASSERT(implWrapped, "Failed to get wrapped JS from XPCOM component.");
if (!implWrapped) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
jsImplObj = implWrapped->GetJSObject();
if (!jsImplObj) {
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
}
// Build the C++ implementation.
nsRefPtr<${implClass}> impl = new ${implClass}(jsImplObj, window);${initCall}
return impl.forget();""").substitute({"implClass" : descriptor.name,
"contractId" : descriptor.interface.getJSImplementation(),
"initCall" : initCall
})
return string.Template(template).substitute({
"implClass" : descriptor.name,
"contractId" : descriptor.interface.getJSImplementation(),
"initCall" : initCall
})
# We're always fallible
def callbackGetterName(attr):

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

@ -22,6 +22,14 @@
#define DEVICESTORAGE_APPS "apps"
#define DEVICESTORAGE_SDCARD "sdcard"
namespace mozilla {
namespace dom {
class DeviceStorageEnumerationParameters;
class DOMCursor;
class DOMRequest;
} // namespace dom
} // namespace mozilla
class DeviceStorageFile MOZ_FINAL
: public nsISupports {
public:
@ -132,6 +140,11 @@ class nsDOMDeviceStorage MOZ_FINAL
, public nsIDOMDeviceStorage
, public nsIObserver
{
typedef mozilla::ErrorResult ErrorResult;
typedef mozilla::dom::DeviceStorageEnumerationParameters
EnumerationParameters;
typedef mozilla::dom::DOMCursor DOMCursor;
typedef mozilla::dom::DOMRequest DOMRequest;
public:
typedef nsTArray<nsString> VolumeNameArray;
@ -144,11 +157,11 @@ public:
nsIDOMEventListener* aListener,
bool aUseCapture,
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
ErrorResult& aRv) MOZ_OVERRIDE;
virtual void RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,
bool aUseCapture,
mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
ErrorResult& aRv) MOZ_OVERRIDE;
nsDOMDeviceStorage();
@ -161,6 +174,58 @@ public:
void SetRootDirectoryForType(const nsAString& aType, const nsAString& aVolName);
// WebIDL
nsPIDOMWindow*
GetParentObject() const
{
return GetOwner();
}
virtual JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
IMPL_EVENT_HANDLER(change)
already_AddRefed<DOMRequest>
Add(nsIDOMBlob* aBlob, ErrorResult& aRv);
already_AddRefed<DOMRequest>
AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath, ErrorResult& aRv);
already_AddRefed<DOMRequest>
Get(const nsAString& aPath, ErrorResult& aRv)
{
return GetInternal(aPath, false, aRv);
}
already_AddRefed<DOMRequest>
GetEditable(const nsAString& aPath, ErrorResult& aRv)
{
return GetInternal(aPath, true, aRv);
}
already_AddRefed<DOMRequest>
Delete(const nsAString& aPath, ErrorResult& aRv);
already_AddRefed<DOMCursor>
Enumerate(const EnumerationParameters& aOptions, ErrorResult& aRv)
{
return Enumerate(NullString(), aOptions, aRv);
}
already_AddRefed<DOMCursor>
Enumerate(const nsAString& aPath, const EnumerationParameters& aOptions,
ErrorResult& aRv);
already_AddRefed<DOMCursor>
EnumerateEditable(const EnumerationParameters& aOptions, ErrorResult& aRv)
{
return EnumerateEditable(NullString(), aOptions, aRv);
}
already_AddRefed<DOMCursor>
EnumerateEditable(const nsAString& aPath,
const EnumerationParameters& aOptions, ErrorResult& aRv);
already_AddRefed<DOMRequest> FreeSpace(ErrorResult& aRv);
already_AddRefed<DOMRequest> UsedSpace(ErrorResult& aRv);
already_AddRefed<DOMRequest> Available(ErrorResult& aRv);
// Uses XPCOM GetStorageName
static void CreateDeviceStorageFor(nsPIDOMWindow* aWin,
const nsAString& aType,
nsDOMDeviceStorage** aStore);
@ -182,26 +247,21 @@ public:
private:
~nsDOMDeviceStorage();
nsresult GetInternal(const JS::Value & aName,
JSContext* aCx,
nsIDOMDOMRequest** aRetval,
bool aEditable);
already_AddRefed<DOMRequest>
GetInternal(const nsAString& aPath, bool aEditable, ErrorResult& aRv);
nsresult GetInternal(nsPIDOMWindow* aWin,
const nsAString& aPath,
mozilla::dom::DOMRequest* aRequest,
bool aEditable);
void
GetInternal(nsPIDOMWindow* aWin, const nsAString& aPath, DOMRequest* aRequest,
bool aEditable);
nsresult DeleteInternal(nsPIDOMWindow* aWin,
const nsAString& aPath,
mozilla::dom::DOMRequest* aRequest);
void
DeleteInternal(nsPIDOMWindow* aWin, const nsAString& aPath,
DOMRequest* aRequest);
nsresult EnumerateInternal(const JS::Value& aName,
const JS::Value& aOptions,
JSContext* aCx,
uint8_t aArgc,
bool aEditable,
nsIDOMDOMCursor** aRetval);
already_AddRefed<DOMCursor>
EnumerateInternal(const nsAString& aName,
const EnumerationParameters& aOptions, bool aEditable,
ErrorResult& aRv);
nsString mStorageType;
nsCOMPtr<nsIFile> mRootDirectory;

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

@ -10,14 +10,15 @@
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/DeviceStorageBinding.h"
#include "mozilla/dom/devicestorage/PDeviceStorageRequestChild.h"
#include "mozilla/dom/ipc/Blob.h"
#include "mozilla/dom/PBrowserChild.h"
#include "mozilla/dom/PContentPermissionRequestChild.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/LazyIdleThread.h"
#include "mozilla/Preferences.h"
#include "mozilla/Services.h"
#include "mozilla/LazyIdleThread.h"
#include "nsAutoPtr.h"
#include "nsDOMEvent.h"
@ -624,7 +625,7 @@ bool DeviceStorageFile::IsComposite()
void
DeviceStorageFile::GetCompositePath(nsAString &aCompositePath)
{
aCompositePath.AssignLiteral("");
aCompositePath.Truncate();
if (!mStorageName.EqualsLiteral("")) {
aCompositePath.AppendLiteral("/");
aCompositePath.Append(mStorageName);
@ -1018,7 +1019,7 @@ DeviceStorageFile::CollectFiles(nsTArray<nsRefPtr<DeviceStorageFile> > &aFiles,
nsDOMDeviceStorage::VolumeNameArray::size_type numVolumes = volNames.Length();
nsDOMDeviceStorage::VolumeNameArray::index_type i;
for (i = 0; i < numVolumes; i++) {
DeviceStorageFile dsf(mStorageType, volNames[i], mRootDir, NS_LITERAL_STRING(""));
DeviceStorageFile dsf(mStorageType, volNames[i], mRootDir, EmptyString());
dsf.mFile->GetPath(fullRootPath);
dsf.collectFilesInternal(aFiles, aSince, fullRootPath);
}
@ -1484,9 +1485,9 @@ NS_IMPL_CYCLE_COLLECTION_1(DeviceStorageCursorRequest,
class PostErrorEvent : public nsRunnable
{
public:
PostErrorEvent(nsRefPtr<DOMRequest>& aRequest, const char* aMessage)
PostErrorEvent(already_AddRefed<DOMRequest> aRequest, const char* aMessage)
: mRequest(aRequest)
{
mRequest.swap(aRequest);
CopyASCIItoUTF16(aMessage, mError);
}
@ -1511,9 +1512,9 @@ private:
nsString mError;
};
ContinueCursorEvent::ContinueCursorEvent(nsRefPtr<DOMRequest>& aRequest)
ContinueCursorEvent::ContinueCursorEvent(already_AddRefed<DOMRequest> aRequest)
: mRequest(aRequest)
{
mRequest.swap(aRequest);
}
ContinueCursorEvent::ContinueCursorEvent(DOMRequest* aRequest)
@ -1619,7 +1620,8 @@ public:
bool check;
mFile->mFile->IsDirectory(&check);
if (!check) {
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_NOT_ENUMERABLE);
nsCOMPtr<PostErrorEvent> event =
new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_NOT_ENUMERABLE);
NS_DispatchToMainThread(event);
return NS_OK;
}
@ -1628,7 +1630,7 @@ public:
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
mFile->CollectFiles(cursor->mFiles, cursor->mSince);
nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(mRequest);
nsCOMPtr<ContinueCursorEvent> event = new ContinueCursorEvent(mRequest.forget());
event->Continue();
return NS_OK;
@ -1821,23 +1823,20 @@ private:
class PostResultEvent : public nsRunnable
{
public:
PostResultEvent(nsRefPtr<DOMRequest>& aRequest, DeviceStorageFile* aFile)
PostResultEvent(already_AddRefed<DOMRequest> aRequest, DeviceStorageFile* aFile)
: mFile(aFile)
{
mRequest.swap(aRequest);
}
, mRequest(aRequest)
{}
PostResultEvent(nsRefPtr<DOMRequest>& aRequest, const nsAString & aPath)
PostResultEvent(already_AddRefed<DOMRequest> aRequest, const nsAString & aPath)
: mPath(aPath)
{
mRequest.swap(aRequest);
}
, mRequest(aRequest)
{}
PostResultEvent(nsRefPtr<DOMRequest>& aRequest, const uint64_t aValue)
PostResultEvent(already_AddRefed<DOMRequest> aRequest, const uint64_t aValue)
: mValue(aValue)
{
mRequest.swap(aRequest);
}
, mRequest(aRequest)
{}
~PostResultEvent() {}
@ -1875,12 +1874,11 @@ class WriteFileEvent : public nsRunnable
public:
WriteFileEvent(nsIDOMBlob* aBlob,
DeviceStorageFile *aFile,
nsRefPtr<DOMRequest>& aRequest)
: mBlob(aBlob)
, mFile(aFile)
{
mRequest.swap(aRequest);
}
already_AddRefed<DOMRequest> aRequest)
: mBlob(aBlob)
, mFile(aFile)
, mRequest(aRequest)
{}
~WriteFileEvent() {}
@ -1894,7 +1892,7 @@ public:
bool check = false;
mFile->mFile->Exists(&check);
if (check) {
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_EXISTS);
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_EXISTS);
NS_DispatchToMainThread(event);
return NS_OK;
}
@ -1904,12 +1902,12 @@ public:
if (NS_FAILED(rv)) {
mFile->mFile->Remove(false);
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_UNKNOWN);
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(event);
return NS_OK;
}
nsCOMPtr<PostResultEvent> event = new PostResultEvent(mRequest, mFile->mPath);
nsCOMPtr<PostResultEvent> event = new PostResultEvent(mRequest.forget(), mFile->mPath);
NS_DispatchToMainThread(event);
return NS_OK;
}
@ -1923,13 +1921,13 @@ private:
class ReadFileEvent : public nsRunnable
{
public:
ReadFileEvent(DeviceStorageFile* aFile,
nsRefPtr<DOMRequest>& aRequest)
: mFile(aFile)
{
mRequest.swap(aRequest);
mFile->CalculateMimeType();
}
ReadFileEvent(DeviceStorageFile* aFile,
already_AddRefed<DOMRequest> aRequest)
: mFile(aFile)
, mRequest(aRequest)
{
mFile->CalculateMimeType();
}
~ReadFileEvent() {}
@ -1942,19 +1940,19 @@ public:
bool check = false;
mFile->mFile->Exists(&check);
if (!check) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
}
}
if (!r) {
nsresult rv = mFile->CalculateSizeAndModifiedDate();
if (NS_FAILED(rv)) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_UNKNOWN);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_UNKNOWN);
}
}
if (!r) {
r = new PostResultEvent(mRequest, mFile);
r = new PostResultEvent(mRequest.forget(), mFile);
}
NS_DispatchToMainThread(r);
return NS_OK;
@ -1969,11 +1967,10 @@ class DeleteFileEvent : public nsRunnable
{
public:
DeleteFileEvent(DeviceStorageFile* aFile,
nsRefPtr<DOMRequest>& aRequest)
: mFile(aFile)
{
mRequest.swap(aRequest);
}
already_AddRefed<DOMRequest> aRequest)
: mFile(aFile)
, mRequest(aRequest)
{}
~DeleteFileEvent() {}
@ -1986,10 +1983,10 @@ public:
bool check = false;
mFile->mFile->Exists(&check);
if (check) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_FILE_DOES_NOT_EXIST);
}
else {
r = new PostResultEvent(mRequest, mFile->mPath);
r = new PostResultEvent(mRequest.forget(), mFile->mPath);
}
NS_DispatchToMainThread(r);
return NS_OK;
@ -2003,11 +2000,11 @@ private:
class UsedSpaceFileEvent : public nsRunnable
{
public:
UsedSpaceFileEvent(DeviceStorageFile* aFile, nsRefPtr<DOMRequest>& aRequest)
: mFile(aFile)
{
mRequest.swap(aRequest);
}
UsedSpaceFileEvent(DeviceStorageFile* aFile,
already_AddRefed<DOMRequest> aRequest)
: mFile(aFile)
, mRequest(aRequest)
{}
~UsedSpaceFileEvent() {}
@ -2020,15 +2017,15 @@ public:
&musicUsage, &totalUsage);
nsCOMPtr<nsIRunnable> r;
if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_PICTURES)) {
r = new PostResultEvent(mRequest, picturesUsage);
r = new PostResultEvent(mRequest.forget(), picturesUsage);
}
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_VIDEOS)) {
r = new PostResultEvent(mRequest, videosUsage);
r = new PostResultEvent(mRequest.forget(), videosUsage);
}
else if (mFile->mStorageType.EqualsLiteral(DEVICESTORAGE_MUSIC)) {
r = new PostResultEvent(mRequest, musicUsage);
r = new PostResultEvent(mRequest.forget(), musicUsage);
} else {
r = new PostResultEvent(mRequest, totalUsage);
r = new PostResultEvent(mRequest.forget(), totalUsage);
}
NS_DispatchToMainThread(r);
return NS_OK;
@ -2042,11 +2039,11 @@ private:
class FreeSpaceFileEvent : public nsRunnable
{
public:
FreeSpaceFileEvent(DeviceStorageFile* aFile, nsRefPtr<DOMRequest>& aRequest)
: mFile(aFile)
{
mRequest.swap(aRequest);
}
FreeSpaceFileEvent(DeviceStorageFile* aFile,
already_AddRefed<DOMRequest> aRequest)
: mFile(aFile)
, mRequest(aRequest)
{}
~FreeSpaceFileEvent() {}
@ -2060,7 +2057,7 @@ public:
}
nsCOMPtr<nsIRunnable> r;
r = new PostResultEvent(mRequest, static_cast<uint64_t>(freeSpace));
r = new PostResultEvent(mRequest.forget(), static_cast<uint64_t>(freeSpace));
NS_DispatchToMainThread(r);
return NS_OK;
}
@ -2189,7 +2186,7 @@ public:
NS_IMETHOD Cancel()
{
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest, POST_ERROR_EVENT_PERMISSION_DENIED);
nsCOMPtr<PostErrorEvent> event = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_PERMISSION_DENIED);
NS_DispatchToMainThread(event);
return NS_OK;
}
@ -2216,7 +2213,7 @@ public:
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile) ||
!typeChecker->Check(mFile->mStorageType, mBlob)) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_ILLEGAL_TYPE);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE);
NS_DispatchToMainThread(r);
return NS_OK;
}
@ -2238,7 +2235,7 @@ public:
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
return NS_OK;
}
r = new WriteFileEvent(mBlob, mFile, mRequest);
r = new WriteFileEvent(mBlob, mFile, mRequest.forget());
break;
}
@ -2255,7 +2252,7 @@ public:
}
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_ILLEGAL_TYPE);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE);
NS_DispatchToMainThread(r);
return NS_OK;
}
@ -2270,7 +2267,7 @@ public:
return NS_OK;
}
r = new ReadFileEvent(mFile, mRequest);
r = new ReadFileEvent(mFile, mRequest.forget());
break;
}
@ -2286,7 +2283,7 @@ public:
}
if (!typeChecker->Check(mFile->mStorageType, mFile->mFile)) {
r = new PostErrorEvent(mRequest, POST_ERROR_EVENT_ILLEGAL_TYPE);
r = new PostErrorEvent(mRequest.forget(), POST_ERROR_EVENT_ILLEGAL_TYPE);
NS_DispatchToMainThread(r);
return NS_OK;
}
@ -2299,7 +2296,7 @@ public:
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
return NS_OK;
}
r = new DeleteFileEvent(mFile, mRequest);
r = new DeleteFileEvent(mFile, mRequest.forget());
break;
}
@ -2312,7 +2309,7 @@ public:
ContentChild::GetSingleton()->SendPDeviceStorageRequestConstructor(child, params);
return NS_OK;
}
r = new FreeSpaceFileEvent(mFile, mRequest);
r = new FreeSpaceFileEvent(mFile, mRequest.forget());
break;
}
@ -2329,7 +2326,7 @@ public:
// thread or we will do more work than required.
DeviceStorageUsedSpaceCache* usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
r = new UsedSpaceFileEvent(mFile, mRequest);
r = new UsedSpaceFileEvent(mFile, mRequest.forget());
usedSpaceCache->Dispatch(r);
return NS_OK;
}
@ -2407,12 +2404,9 @@ NS_IMPL_CYCLE_COLLECTION_4(DeviceStorageRequest,
mDeviceStorage)
DOMCI_DATA(DeviceStorage, nsDOMDeviceStorage)
NS_INTERFACE_MAP_BEGIN(nsDOMDeviceStorage)
NS_INTERFACE_MAP_ENTRY(nsIDOMDeviceStorage)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DeviceStorage)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetHelper)
NS_IMPL_ADDREF_INHERITED(nsDOMDeviceStorage, nsDOMEventTargetHelper)
@ -2422,14 +2416,22 @@ nsDOMDeviceStorage::nsDOMDeviceStorage()
: mCompositeComponent(false),
mIsWatchingFile(false)
, mAllowedToWatchFile(false)
{ }
{
SetIsDOMBinding();
}
/* virtual */ JSObject*
nsDOMDeviceStorage::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{
return DeviceStorageBinding::Wrap(aCx, aScope, this);
}
nsresult
nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType,
nsTArray<nsRefPtr<nsDOMDeviceStorage> > &aStores)
{
mStores.AppendElements(aStores);
nsresult rv = Init(aWindow, aType, NS_LITERAL_STRING(""));
nsresult rv = Init(aWindow, aType, EmptyString());
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -2458,9 +2460,7 @@ nsDOMDeviceStorage::Init(nsPIDOMWindow* aWindow, const nsAString &aType, const n
BindToOwner(aWindow);
// Grab the principal of the document
nsCOMPtr<nsIDOMDocument> domdoc;
aWindow->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
nsCOMPtr<nsIDocument> doc = aWindow->GetDoc();
if (!doc) {
return NS_ERROR_FAILURE;
}
@ -2522,15 +2522,14 @@ nsDOMDeviceStorage::GetOrderedVolumeNames(nsDOMDeviceStorage::VolumeNameArray &a
VolumeNameArray::index_type sdcardIndex;
sdcardIndex = aVolumeNames.IndexOf(NS_LITERAL_STRING("sdcard"));
if ((sdcardIndex != VolumeNameArray::NoIndex)
&& (sdcardIndex > 0)) {
if (sdcardIndex != VolumeNameArray::NoIndex && sdcardIndex > 0) {
aVolumeNames.RemoveElementAt(sdcardIndex);
aVolumeNames.InsertElementAt(0, NS_LITERAL_STRING("sdcard"));
}
}
#endif
if (aVolumeNames.Length() == 0) {
aVolumeNames.AppendElement(NS_LITERAL_STRING(""));
if (aVolumeNames.IsEmpty()) {
aVolumeNames.AppendElement(EmptyString());
}
sVolumeNameCache = new VolumeNameCache;
sVolumeNameCache->mVolumeNames.AppendElements(aVolumeNames);
@ -2545,7 +2544,7 @@ nsDOMDeviceStorage::CreateDeviceStorageFor(nsPIDOMWindow* aWin,
// Create the underlying non-composite device storage objects
nsTArray<nsRefPtr<nsDOMDeviceStorage> > stores;
CreateDeviceStoragesFor(aWin, aType, stores, true);
if (stores.Length() == 0) {
if (stores.IsEmpty()) {
*aStore = nullptr;
return;
}
@ -2578,7 +2577,7 @@ nsDOMDeviceStorage::CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
if (!DeviceStorageTypeChecker::IsVolumeBased(aType)) {
nsRefPtr<nsDOMDeviceStorage> storage = new nsDOMDeviceStorage();
rv = storage->Init(aWin, aType, NS_LITERAL_STRING(""));
rv = storage->Init(aWin, aType, EmptyString());
if (NS_SUCCEEDED(rv)) {
aStores.AppendElement(storage);
}
@ -2605,8 +2604,8 @@ nsDOMDeviceStorage::ParseCompositePath(const nsAString& aCompositePath,
nsAString& aOutStorageName,
nsAString& aOutStoragePath)
{
aOutStorageName.AssignLiteral("");
aOutStoragePath.AssignLiteral("");
aOutStorageName.Truncate();
aOutStoragePath.Truncate();
NS_NAMED_LITERAL_STRING(slash, "/");
@ -2624,7 +2623,7 @@ nsDOMDeviceStorage::ParseCompositePath(const nsAString& aCompositePath,
aOutStoragePath = aCompositePath;
}
if (!storageName.EqualsLiteral("")) {
if (!storageName.IsEmpty()) {
aOutStorageName = storageName;
return true;
}
@ -2636,7 +2635,7 @@ nsDOMDeviceStorage::ParseCompositePath(const nsAString& aCompositePath,
nsString defStorageName;
GetWritableStorageName(storageType, defStorageName);
if (defStorageName.EqualsLiteral("")) {
if (defStorageName.IsEmpty()) {
return false;
}
aOutStorageName = defStorageName;
@ -2714,14 +2713,24 @@ nsDOMDeviceStorage::IsAvailable()
NS_IMETHODIMP
nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = Add(aBlob, rv);
request.forget(_retval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::Add(nsIDOMBlob* aBlob, ErrorResult& aRv)
{
if (!aBlob) {
return NS_OK;
return nullptr;
}
nsCOMPtr<nsIMIMEService> mimeSvc = do_GetService(NS_MIMESERVICE_CONTRACTID);
if (!mimeSvc) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
// if mimeType isn't set, we will not get a correct
@ -2745,26 +2754,39 @@ nsDOMDeviceStorage::Add(nsIDOMBlob *aBlob, nsIDOMDOMRequest * *_retval)
path.Append(".");
path.Append(extension);
return AddNamed(aBlob, NS_ConvertASCIItoUTF16(path), _retval);
return AddNamed(aBlob, NS_ConvertASCIItoUTF16(path), aRv);
}
NS_IMETHODIMP
nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
const nsAString & aPath,
nsIDOMDOMRequest * *_retval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = AddNamed(aBlob, aPath, rv);
request.forget(_retval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::AddNamed(nsIDOMBlob* aBlob, const nsAString& aPath,
ErrorResult& aRv)
{
// if the blob is null here, bail
if (aBlob == nullptr)
return NS_OK;
if (!aBlob) {
return nullptr;
}
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
DeviceStorageTypeChecker* typeChecker = DeviceStorageTypeChecker::CreateOrGet();
if (!typeChecker) {
return NS_ERROR_FAILURE;
aRv.Throw(NS_ERROR_FAILURE);
return nullptr;
}
nsCOMPtr<nsIRunnable> r;
@ -2774,16 +2796,14 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(aPath, storagePath);
if (!ds) {
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*_retval = request);
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
return ds->AddNamed(aBlob, storagePath, _retval);
return ds->AddNamed(aBlob, storagePath, aRv);
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*_retval = request);
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName,
@ -2793,80 +2813,74 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
} else if (!typeChecker->Check(mStorageType, dsf->mFile) ||
!typeChecker->Check(mStorageType, aBlob)) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_ILLEGAL_TYPE);
}
else {
} else {
r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_CREATE,
win, mPrincipal, dsf, request, aBlob);
}
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
nsDOMDeviceStorage::Get(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval)
nsDOMDeviceStorage::Get(const nsAString& aPath, nsIDOMDOMRequest** aRetval)
{
return GetInternal(aPath, aCx, _retval, false);
ErrorResult rv;
nsRefPtr<DOMRequest> request = Get(aPath, rv);
request.forget(aRetval);
return rv.ErrorCode();
}
NS_IMETHODIMP
nsDOMDeviceStorage::GetEditable(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval)
nsDOMDeviceStorage::GetEditable(const nsAString& aPath,
nsIDOMDOMRequest** aRetval)
{
return GetInternal(aPath, aCx, _retval, true);
ErrorResult rv;
nsRefPtr<DOMRequest> request = GetEditable(aPath, rv);
request.forget(aRetval);
return rv.ErrorCode();
}
nsresult
nsDOMDeviceStorage::GetInternal(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval,
bool aEditable)
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::GetInternal(const nsAString& aPath, bool aEditable,
ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*_retval = request);
nsCOMPtr<nsIRunnable> r;
JSString* jsstr = JS_ValueToString(aCx, aPath);
nsDependentJSString path;
if (!path.init(aCx, jsstr)) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
}
if (IsComposite()) {
nsString storagePath;
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(path, storagePath);
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(aPath, storagePath);
if (!ds) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
nsCOMPtr<nsIRunnable> r =
new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
return ds->GetInternal(win, storagePath, request.get(), aEditable);
ds->GetInternal(win, storagePath, request, aEditable);
return request.forget();
}
return GetInternal(win, path, request.get(), aEditable);
GetInternal(win, aPath, request, aEditable);
return request.forget();
}
nsresult
void
nsDOMDeviceStorage::GetInternal(nsPIDOMWindow *aWin,
const nsAString& aPath,
DOMRequest* aRequest,
bool aEditable)
{
nsCOMPtr<nsIRunnable> r;
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName,
aPath);
dsf->SetEditable(aEditable);
nsCOMPtr<nsIRunnable> r;
if (!dsf->IsSafePath()) {
r = new PostErrorEvent(aRequest, POST_ERROR_EVENT_PERMISSION_DENIED);
} else {
@ -2874,47 +2888,48 @@ nsDOMDeviceStorage::GetInternal(nsPIDOMWindow *aWin,
aWin, mPrincipal, dsf, aRequest);
}
NS_DispatchToMainThread(r);
return NS_OK;
}
NS_IMETHODIMP
nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMRequest * *_retval)
nsDOMDeviceStorage::Delete(const nsAString& aPath, nsIDOMDOMRequest** aRetval)
{
nsCOMPtr<nsIRunnable> r;
ErrorResult rv;
nsRefPtr<DOMRequest> request = Delete(aPath, rv);
request.forget(aRetval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::Delete(const nsAString& aPath, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*_retval = request);
JSString* jsstr = JS_ValueToString(aCx, aPath);
nsDependentJSString path;
if (!path.init(aCx, jsstr)) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
}
if (IsComposite()) {
nsString storagePath;
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(path, storagePath);
nsRefPtr<nsDOMDeviceStorage> ds = GetStorage(aPath, storagePath);
if (!ds) {
r = new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
nsCOMPtr<nsIRunnable> r =
new PostErrorEvent(request, POST_ERROR_EVENT_UNKNOWN);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
return ds->DeleteInternal(win, storagePath, request.get());
ds->DeleteInternal(win, storagePath, request);
return request.forget();
}
return DeleteInternal(win, path, request.get());
DeleteInternal(win, aPath, request);
return request.forget();
}
nsresult
void
nsDOMDeviceStorage::DeleteInternal(nsPIDOMWindow *aWin,
const nsAString& aPath,
mozilla::dom::DOMRequest* aRequest)
const nsAString& aPath,
DOMRequest* aRequest)
{
nsCOMPtr<nsIRunnable> r;
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
@ -2922,25 +2937,32 @@ nsDOMDeviceStorage::DeleteInternal(nsPIDOMWindow *aWin,
aPath);
if (!dsf->IsSafePath()) {
r = new PostErrorEvent(aRequest, POST_ERROR_EVENT_PERMISSION_DENIED);
}
else {
} else {
r = new DeviceStorageRequest(DEVICE_STORAGE_REQUEST_DELETE,
aWin, mPrincipal, dsf, aRequest);
}
NS_DispatchToMainThread(r);
return NS_OK;
}
NS_IMETHODIMP
nsDOMDeviceStorage::FreeSpace(nsIDOMDOMRequest** aRetval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = FreeSpace(rv);
request.forget(aRetval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::FreeSpace(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*aRetval = request);
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName);
@ -2950,22 +2972,31 @@ nsDOMDeviceStorage::FreeSpace(nsIDOMDOMRequest** aRetval)
dsf,
request);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
nsDOMDeviceStorage::UsedSpace(nsIDOMDOMRequest** aRetval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = UsedSpace(rv);
request.forget(aRetval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::UsedSpace(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
DebugOnly<DeviceStorageUsedSpaceCache*> usedSpaceCache = DeviceStorageUsedSpaceCache::CreateOrGet();
NS_ASSERTION(usedSpaceCache, "DeviceStorageUsedSpaceCache is null");
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*aRetval = request);
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName);
@ -2975,19 +3006,28 @@ nsDOMDeviceStorage::UsedSpace(nsIDOMDOMRequest** aRetval)
dsf,
request);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
nsDOMDeviceStorage::Available(nsIDOMDOMRequest** aRetval)
{
ErrorResult rv;
nsRefPtr<DOMRequest> request = Available(rv);
request.forget(aRetval);
return rv.ErrorCode();
}
already_AddRefed<DOMRequest>
nsDOMDeviceStorage::Available(ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win) {
return NS_ERROR_UNEXPECTED;
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
nsRefPtr<DOMRequest> request = new DOMRequest(win);
NS_ADDREF(*aRetval = request);
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName);
@ -2997,7 +3037,7 @@ nsDOMDeviceStorage::Available(nsIDOMDOMRequest** aRetval)
dsf,
request);
NS_DispatchToMainThread(r);
return NS_OK;
return request.forget();
}
NS_IMETHODIMP
@ -3024,121 +3064,76 @@ nsDOMDeviceStorage::GetStorageName(nsAString& aStorageName)
return NS_OK;
}
NS_IMETHODIMP
nsDOMDeviceStorage::Enumerate(const JS::Value & aName,
const JS::Value & aOptions,
JSContext* aCx,
uint8_t aArgc,
nsIDOMDOMCursor** aRetval)
already_AddRefed<DOMCursor>
nsDOMDeviceStorage::Enumerate(const nsAString& aPath,
const EnumerationParameters& aOptions,
ErrorResult& aRv)
{
return EnumerateInternal(aName, aOptions, aCx, aArgc, false, aRetval);
return EnumerateInternal(aPath, aOptions, false, aRv);
}
NS_IMETHODIMP
nsDOMDeviceStorage::EnumerateEditable(const JS::Value & aName,
const JS::Value & aOptions,
JSContext* aCx,
uint8_t aArgc,
nsIDOMDOMCursor** aRetval)
already_AddRefed<DOMCursor>
nsDOMDeviceStorage::EnumerateEditable(const nsAString& aPath,
const EnumerationParameters& aOptions,
ErrorResult& aRv)
{
return EnumerateInternal(aName, aOptions, aCx, aArgc, true, aRetval);
return EnumerateInternal(aPath, aOptions, true, aRv);
}
static bool
ExtractDateFromOptions(JSContext* aCx, const JS::Value& aOptions, PRTime* aTime)
{
JS::Rooted<JS::Value> options(aCx, aOptions);
RootedDictionary<DeviceStorageEnumerationParameters> params(aCx);
if (!params.Init(aCx, options)) {
return false;
}
if (params.mSince.WasPassed() && !params.mSince.Value().IsUndefined()) {
*aTime = params.mSince.Value().TimeStamp();
} else {
*aTime = 0;
}
return true;
}
nsresult
nsDOMDeviceStorage::EnumerateInternal(const JS::Value & aName,
const JS::Value & aOptions,
JSContext* aCx,
uint8_t aArgc,
bool aEditable,
nsIDOMDOMCursor** aRetval)
already_AddRefed<DOMCursor>
nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath,
const EnumerationParameters& aOptions,
bool aEditable, ErrorResult& aRv)
{
nsCOMPtr<nsPIDOMWindow> win = GetOwner();
if (!win)
return NS_ERROR_UNEXPECTED;
if (!win) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
PRTime since = 0;
nsString path;
path.SetIsVoid(true);
if (aArgc > 0) {
// inspect the first value to see if it is a string
if (JSVAL_IS_STRING(aName)) {
JSString* jsstr = JS_ValueToString(aCx, aName);
nsDependentJSString jspath;
jspath.init(aCx, jsstr);
path.Assign(jspath);
} else if (!JSVAL_IS_PRIMITIVE(aName)) {
// it also might be an options object
if (!ExtractDateFromOptions(aCx, aName, &since)) {
return NS_ERROR_FAILURE;
}
} else {
return NS_ERROR_FAILURE;
}
if (aArgc == 2 && (JSVAL_IS_VOID(aOptions) || aOptions.isNull() || !aOptions.isObject())) {
return NS_ERROR_FAILURE;
}
if (!ExtractDateFromOptions(aCx, aOptions, &since)) {
return NS_ERROR_FAILURE;
}
if (aOptions.mSince.WasPassed() && !aOptions.mSince.Value().IsUndefined()) {
since = PRTime(aOptions.mSince.Value().TimeStamp());
}
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mStorageType,
mStorageName,
path,
NS_LITERAL_STRING(""));
aPath,
EmptyString());
dsf->SetEditable(aEditable);
nsRefPtr<nsDOMDeviceStorageCursor> cursor = new nsDOMDeviceStorageCursor(win, mPrincipal,
dsf, since);
nsRefPtr<DeviceStorageCursorRequest> r = new DeviceStorageCursorRequest(cursor);
NS_ADDREF(*aRetval = cursor);
if (mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) {
r->Allow();
return NS_OK;
return cursor.forget();
}
if (XRE_GetProcessType() == GeckoProcessType_Content) {
// because owner implements nsITabChild, we can assume that it is
// the one and only TabChild.
TabChild* child = GetTabChildFrom(win->GetDocShell());
if (!child)
return NS_OK;
if (!child) {
return cursor.forget();
}
// Retain a reference so the object isn't deleted without IPDL's knowledge.
// Corresponding release occurs in DeallocPContentPermissionRequest.
r->AddRef();
nsCString type;
nsresult rv = DeviceStorageTypeChecker::GetPermissionForType(mStorageType, type);
if (NS_FAILED(rv)) {
return rv;
aRv = DeviceStorageTypeChecker::GetPermissionForType(mStorageType, type);
if (aRv.Failed()) {
return nullptr;
}
child->SendPContentPermissionRequestConstructor(r, type, NS_LITERAL_CSTRING("read"), IPC::Principal(mPrincipal));
r->Sendprompt();
return NS_OK;
return cursor.forget();
}
nsCOMPtr<nsIContentPermissionPrompt> prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID);
@ -3146,7 +3141,7 @@ nsDOMDeviceStorage::EnumerateInternal(const JS::Value & aName,
prompt->Prompt(r);
}
return NS_OK;
return cursor.forget();
}
#ifdef MOZ_WIDGET_GONK

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

@ -166,7 +166,7 @@ private:
class ContinueCursorEvent MOZ_FINAL : public nsRunnable
{
public:
ContinueCursorEvent(nsRefPtr<mozilla::dom::DOMRequest>& aRequest);
ContinueCursorEvent(already_AddRefed<mozilla::dom::DOMRequest> aRequest);
ContinueCursorEvent(mozilla::dom::DOMRequest* aRequest);
~ContinueCursorEvent();
void Continue();

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

@ -11,32 +11,19 @@ interface nsIDOMDeviceStorageChangeEvent;
interface nsIDOMEventListener;
interface nsIFile;
[scriptable, uuid(be690a9b-f0b4-4cde-a505-0b442abe2109), builtinclass]
[scriptable, uuid(7cef14d4-d767-4da7-a18e-32c5e009a8e4), builtinclass]
interface nsIDOMDeviceStorage : nsIDOMEventTarget
{
[implicit_jscontext] attribute jsval onchange;
nsIDOMDOMRequest add(in nsIDOMBlob aBlob);
nsIDOMDOMRequest addNamed(in nsIDOMBlob aBlob, in DOMString aName);
[implicit_jscontext]
nsIDOMDOMRequest get(in jsval aName);
[implicit_jscontext]
nsIDOMDOMRequest getEditable(in jsval aName);
[implicit_jscontext]
nsIDOMDOMRequest delete(in jsval aName);
[optional_argc, implicit_jscontext]
nsIDOMDOMCursor enumerate([optional] in jsval aName, /* DeviceStorageEnumerationParameters */ [optional] in jsval options);
[optional_argc, implicit_jscontext]
nsIDOMDOMCursor enumerateEditable([optional] in jsval aName, /* DeviceStorageEnumerationParameters */ [optional] in jsval options);
nsIDOMDOMRequest get([Null(Stringify)] in DOMString aName);
nsIDOMDOMRequest getEditable([Null(Stringify)] in DOMString aName);
nsIDOMDOMRequest delete([Null(Stringify)] in DOMString aName);
nsIDOMDOMRequest freeSpace();
nsIDOMDOMRequest usedSpace();
nsIDOMDOMRequest available();
// Note that the storageName is just a name (like sdcard), and doesn't

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

@ -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);

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

@ -1,5 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
@ -312,24 +312,11 @@ Telephony::SetSpeakerEnabled(bool aSpeakerEnabled)
}
NS_IMETHODIMP
Telephony::GetActive(JS::Value* aActive)
Telephony::GetActive(nsIDOMTelephonyCall** aActive)
{
if (!mActiveCall) {
aActive->setNull();
return NS_OK;
}
nsresult rv;
nsIScriptContext* sc = GetContextForEventHandlers(&rv);
NS_ENSURE_SUCCESS(rv, rv);
if (!sc) {
return NS_OK;
}
AutoPushJSContext cx(sc->GetNativeContext());
JS::Rooted<JSObject*> global(cx, sc->GetNativeGlobal());
return nsContentUtils::WrapNative(cx, global, mActiveCall->ToISupports(),
aActive);
nsCOMPtr<nsIDOMTelephonyCall> activeCall = mActiveCall;
activeCall.forget(aActive);
return NS_OK;
}
NS_IMETHODIMP

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

@ -1,5 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

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

@ -1,5 +1,5 @@
/* -*- Mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40 -*- */
/* vim: set ts=2 et sw=2 tw=40: */
/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
@ -9,7 +9,7 @@
interface nsIDOMEventListener;
interface nsIDOMTelephonyCall;
[scriptable, builtinclass, uuid(0e7bc85e-7e88-43fa-b349-6ea348bda2df)]
[scriptable, builtinclass, uuid(dd9f3957-b0fe-4d3d-b738-79782f76f05d)]
interface nsIDOMTelephony : nsIDOMEventTarget
{
nsIDOMTelephonyCall dial(in DOMString number);
@ -20,7 +20,7 @@ interface nsIDOMTelephony : nsIDOMEventTarget
// The call that is "active", i.e. receives microphone input and tones
// generated via startTone.
readonly attribute jsval active;
readonly attribute nsIDOMTelephonyCall active;
// Array of all calls that are currently connected.
readonly attribute jsval calls;

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

@ -1,12 +1,47 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
*/
* 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/. */
dictionary DeviceStorageEnumerationParameters {
Date since;
};
// If we start using DeviceStorageEnumerationParameters here, remove
// it from DummyBinding.
interface DeviceStorage : EventTarget {
[SetterThrows]
attribute EventHandler onchange;
[Throws]
DOMRequest? add(Blob? aBlob);
[Throws]
DOMRequest? addNamed(Blob? aBlob, DOMString aName);
[Throws]
DOMRequest get(DOMString aName);
[Throws]
DOMRequest getEditable(DOMString aName);
[Throws]
DOMRequest delete(DOMString aName);
[Throws]
DOMCursor enumerate(optional DeviceStorageEnumerationParameters options);
[Throws]
DOMCursor enumerate(DOMString path,
optional DeviceStorageEnumerationParameters options);
[Throws]
DOMCursor enumerateEditable(optional DeviceStorageEnumerationParameters options);
[Throws]
DOMCursor enumerateEditable(DOMString path,
optional DeviceStorageEnumerationParameters options);
[Throws]
DOMRequest freeSpace();
[Throws]
DOMRequest usedSpace();
[Throws]
DOMRequest available();
// Note that the storageName is just a name (like sdcard), and doesn't
// include any path information.
readonly attribute DOMString storageName;
};

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

@ -20,7 +20,6 @@ interface DummyInterface {
void funcDNSCacheDict(optional DNSCacheDict arg);
void frameRequestCallback(FrameRequestCallback arg);
void idbObjectStoreParams(optional IDBObjectStoreParameters arg);
void DeviceStorageEnumerationParameters(optional DeviceStorageEnumerationParameters arg);
void CameraPictureOptions(optional CameraPictureOptions arg);
void MmsParameters(optional MmsParameters arg);
void MmsAttachment(optional MmsAttachment arg);

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

@ -31,8 +31,7 @@ interface HTMLSelectElement : HTMLElement {
[SetterThrows, Pure]
attribute unsigned long length;
getter Element? item(unsigned long index);
[Throws]
object? namedItem(DOMString name);
HTMLOptionElement? namedItem(DOMString name);
[Throws]
void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
void remove(long index);

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

@ -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 \

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

@ -801,7 +801,6 @@ class ProgressEvent : public Event
{
static JSClass sClass;
static const JSPropertySpec sProperties[];
static const JSFunctionSpec sFunctions[];
public:
static JSClass*
@ -814,7 +813,7 @@ public:
InitClass(JSContext* aCx, JSObject* aObj, JSObject* aParentProto)
{
return JS_InitClass(aCx, aObj, aParentProto, &sClass, Construct, 0,
sProperties, sFunctions, NULL, NULL);
sProperties, NULL, NULL, NULL);
}
static JSObject*
@ -920,33 +919,6 @@ private:
aVp.set(JS_GetReservedSlot(aObj, slot));
return true;
}
static JSBool
InitProgressEvent(JSContext* aCx, unsigned aArgc, jsval* aVp)
{
JS::Rooted<JSObject*> obj(aCx, JS_THIS_OBJECT(aCx, aVp));
if (!obj) {
return false;
}
ProgressEvent* event = GetInstancePrivate(aCx, obj, sFunctions[0].name);
if (!event) {
return false;
}
JS::Rooted<JSString*> type(aCx);
JSBool bubbles, cancelable, lengthComputable;
double loaded, total;
if (!JS_ConvertArguments(aCx, aArgc, JS_ARGV(aCx, aVp), "Sbbbdd", type.address(),
&bubbles, &cancelable, &lengthComputable, &loaded,
&total)) {
return false;
}
InitProgressEventCommon(obj, event, type, bubbles, cancelable,
lengthComputable, loaded, total, false);
return true;
}
};
JSClass ProgressEvent::sClass = {
@ -966,11 +938,6 @@ const JSPropertySpec ProgressEvent::sProperties[] = {
{ 0, 0, 0, JSOP_NULLWRAPPER, JSOP_NULLWRAPPER }
};
const JSFunctionSpec ProgressEvent::sFunctions[] = {
JS_FN("initProgressEvent", InitProgressEvent, 6, FUNCTION_FLAGS),
JS_FS_END
};
Event*
Event::GetPrivate(JSObject* aObj)
{

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

@ -76,7 +76,8 @@ XPCConvert::GetISupportsFromJSObject(JSObject* obj, nsISupports** iface)
*iface = (nsISupports*) xpc_GetJSPrivate(obj);
return true;
}
return UnwrapDOMObjectToISupports(obj, *iface);
*iface = UnwrapDOMObjectToISupports(obj);
return !!*iface;
}
/***************************************************************************/

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

@ -531,8 +531,9 @@ nsJSIID::HasInstance(nsIXPConnectWrappedNative *wrapper,
} else if (IsDOMObject(obj)) {
// Not all DOM objects implement nsISupports. But if they don't,
// there's nothing to do in this HasInstance hook.
if (!UnwrapDOMObjectToISupports(obj, identity))
return NS_OK;;
identity = UnwrapDOMObjectToISupports(obj);
if (!identity)
return NS_OK;
nsCOMPtr<nsISupports> supp;
identity->QueryInterface(*iid, getter_AddRefs(supp));
*bp = supp;

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

@ -633,7 +633,7 @@ castNative(JSContext *cx,
} else if (cur) {
nsISupports *native;
QITableEntry *entries;
if (mozilla::dom::UnwrapDOMObjectToISupports(cur, native)) {
if ((native = mozilla::dom::UnwrapDOMObjectToISupports(cur))) {
entries = nullptr;
} else if (IS_SLIM_WRAPPER(cur)) {
native = static_cast<nsISupports*>(xpc_GetJSPrivate(cur));

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

@ -1328,9 +1328,8 @@ nsXPConnect::GetNativeOfWrapper(JSContext * aJSContext,
return nullptr;
}
nsISupports* supports = nullptr;
mozilla::dom::UnwrapDOMObjectToISupports(aJSObj, supports);
nsCOMPtr<nsISupports> canonical = do_QueryInterface(supports);
nsCOMPtr<nsISupports> canonical =
do_QueryInterface(mozilla::dom::UnwrapDOMObjectToISupports(aJSObj));
return canonical;
}

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

@ -1278,8 +1278,8 @@ DOMXrayTraits::construct(JSContext *cx, HandleObject wrapper,
void
DOMXrayTraits::preserveWrapper(JSObject *target)
{
nsISupports *identity;
if (!mozilla::dom::UnwrapDOMObjectToISupports(target, identity))
nsISupports *identity = mozilla::dom::UnwrapDOMObjectToISupports(target);
if (!identity)
return;
nsWrapperCache* cache = nullptr;
CallQueryInterface(identity, &cache);
@ -1941,9 +1941,7 @@ do_QueryInterfaceNative(JSContext* cx, HandleObject wrapper)
if (IsWrapper(wrapper) && WrapperFactory::IsXrayWrapper(wrapper)) {
RootedObject target(cx, XrayTraits::getTargetObject(wrapper));
if (GetXrayType(target) == XrayForDOMObject) {
if (!UnwrapDOMObjectToISupports(target, nativeSupports)) {
nativeSupports = nullptr;
}
nativeSupports = UnwrapDOMObjectToISupports(target);
} else {
XPCWrappedNative *wn = GetWrappedNative(target);
nativeSupports = wn->Native();

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

@ -20,8 +20,6 @@ codereview.appspot.com: did not receive HSTS header
codereview.chromium.org: did not receive HSTS header
crypto.is: did not receive HSTS header
dl.google.com: did not receive HSTS header
dm.lookout.com: did not receive HSTS header
dm.mylookout.com: did not receive HSTS header
docs.google.com: did not receive HSTS header
drive.google.com: did not receive HSTS header
dropcam.com: did not receive HSTS header

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

@ -8,7 +8,7 @@
/*****************************************************************************/
#include "mozilla/StandardInteger.h"
const PRTime gPreloadListExpirationTime = INT64_C(1380363248599000);
const PRTime gPreloadListExpirationTime = INT64_C(1380968184244000);
class nsSTSPreload
{
@ -23,6 +23,7 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "app.recurly.com", false },
{ "arivo.com.br", true },
{ "bassh.net", true },
{ "blog.linode.com", false },
{ "blog.torproject.org", false },
{ "bugzilla.mozilla.org", true },
{ "business.medbank.com.mt", true },
@ -35,11 +36,14 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "csawctf.poly.edu", true },
{ "developer.mydigipass.com", false },
{ "dist.torproject.org", false },
{ "dm.lookout.com", false },
{ "dm.mylookout.com", false },
{ "download.jitsi.org", false },
{ "ebanking.indovinabank.com.vn", false },
{ "entropia.de", false },
{ "espra.com", true },
{ "factor.cc", false },
{ "forum.linode.com", false },
{ "gocardless.com", true },
{ "grc.com", false },
{ "howrandom.org", true },
@ -48,6 +52,8 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "itriskltd.com", true },
{ "keyerror.com", true },
{ "lastpass.com", false },
{ "library.linode.com", false },
{ "linode.com", false },
{ "lockify.com", true },
{ "logentries.com", false },
{ "login.persona.org", true },
@ -55,6 +61,7 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "lookout.com", false },
{ "luneta.nearbuysystems.com", false },
{ "makeyourlaws.org", false },
{ "manager.linode.com", false },
{ "mattmccutchen.net", true },
{ "mega.co.nz", false },
{ "members.mayfirst.org", false },
@ -62,7 +69,10 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "my.onlime.ch", false },
{ "mylookout.com", false },
{ "neg9.org", false },
{ "p.linode.com", false },
{ "passwd.io", true },
{ "paste.linode.com", false },
{ "pastebin.linode.com", false },
{ "pay.gigahost.dk", true },
{ "paymill.com", true },
{ "paymill.de", true },
@ -94,6 +104,7 @@ static const nsSTSPreload kSTSPreloadList[] = {
{ "www.grc.com", false },
{ "www.intercom.io", false },
{ "www.irccloud.com", false },
{ "www.linode.com", false },
{ "www.lookout.com", false },
{ "www.mydigipass.com", false },
{ "www.mylookout.com", false },