Backed out changeset 401edab3831f - Bug 758273.

--HG--
extra : rebase_source : 8ce201cd3fe6a2d6405be2548927f65dab5cbb39
This commit is contained in:
Doug Turner 2012-06-08 21:33:16 -07:00
Родитель 9acb961a0b
Коммит fc28fe58ff
9 изменённых файлов: 38 добавлений и 314 удалений

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

@ -16,7 +16,6 @@
#include "nsIPrincipal.h"
#include "mozilla/Preferences.h"
#include "nsJSUtils.h"
#include "DictionaryHelpers.h"
using namespace mozilla::dom;
@ -308,8 +307,7 @@ public:
nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow,
nsIURI* aURI,
DeviceStorageFile* aFile,
bool aEditable,
PRUint64 aSince);
bool aEditable);
private:
~nsDOMDeviceStorageCursor();
@ -321,7 +319,6 @@ protected:
nsRefPtr<DeviceStorageFile> mFile;
nsCOMPtr<nsIURI> mURI;
bool mEditable;
PRUint64 mSince;
// to access mFiles
friend class InitCursorEvent;
@ -511,15 +508,6 @@ public:
nsCOMPtr<nsIFile> f;
while (NS_SUCCEEDED(files->GetNextFile(getter_AddRefs(f))) && f) {
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
PRInt64 msecs;
f->GetLastModifiedTime(&msecs);
if (msecs < (PRInt64) cursor->mSince) {
continue;
}
bool isDir;
f->IsDirectory(&isDir);
@ -546,6 +534,7 @@ public:
collectFiles(dsf);
}
else if (isFile) {
nsDOMDeviceStorageCursor* cursor = static_cast<nsDOMDeviceStorageCursor*>(mRequest.get());
cursor->mFiles.AppendElement(dsf);
}
}
@ -572,14 +561,12 @@ NS_IMPL_RELEASE_INHERITED(nsDOMDeviceStorageCursor, DOMRequest)
nsDOMDeviceStorageCursor::nsDOMDeviceStorageCursor(nsIDOMWindow* aWindow,
nsIURI* aURI,
DeviceStorageFile* aFile,
bool aEditable,
PRUint64 aSince)
bool aEditable)
: DOMRequest(aWindow)
, mOkToCallContinue(false)
, mFile(aFile)
, mURI(aURI)
, mEditable(aEditable)
, mSince(aSince)
{
}
@ -1166,7 +1153,7 @@ nsDOMDeviceStorage::AddNamed(nsIDOMBlob *aBlob,
}
NS_IMETHODIMP
nsDOMDeviceStorage::Get(const JS::Value& aPath,
nsDOMDeviceStorage::Get(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval NS_OUTPARAM)
{
@ -1174,7 +1161,7 @@ nsDOMDeviceStorage::Get(const JS::Value& aPath,
}
NS_IMETHODIMP
nsDOMDeviceStorage::GetEditable(const JS::Value& aPath,
nsDOMDeviceStorage::GetEditable(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval NS_OUTPARAM)
{
@ -1182,7 +1169,7 @@ nsDOMDeviceStorage::GetEditable(const JS::Value& aPath,
}
nsresult
nsDOMDeviceStorage::GetInternal(const JS::Value& aPath,
nsDOMDeviceStorage::GetInternal(const JS::Value & aPath,
JSContext* aCx,
nsIDOMDOMRequest * *_retval NS_OUTPARAM,
bool aEditable)
@ -1221,7 +1208,7 @@ nsDOMDeviceStorage::GetInternal(const JS::Value& aPath,
}
NS_IMETHODIMP
nsDOMDeviceStorage::Delete(const JS::Value& aPath, JSContext* aCx, nsIDOMDOMRequest * *_retval NS_OUTPARAM)
nsDOMDeviceStorage::Delete(const JS::Value & aPath, JSContext* aCx, nsIDOMDOMRequest * *_retval NS_OUTPARAM)
{
nsCOMPtr<nsIRunnable> r;
@ -1256,85 +1243,35 @@ nsDOMDeviceStorage::Delete(const JS::Value& aPath, JSContext* aCx, nsIDOMDOMRequ
}
NS_IMETHODIMP
nsDOMDeviceStorage::Enumerate(const JS::Value& aName,
const JS::Value& aOptions,
JSContext* aCx,
PRUint8 aArgc,
nsIDOMDeviceStorageCursor** aRetval)
nsDOMDeviceStorage::Enumerate(const nsAString & aPath,
nsIDOMDeviceStorageCursor * *_retval NS_OUTPARAM)
{
return EnumerateInternal(aName, aOptions, aCx, aArgc, false, aRetval);
return EnumerateInternal(aPath, _retval, false);
}
NS_IMETHODIMP
nsDOMDeviceStorage::EnumerateEditable(const JS::Value& aName,
const JS::Value& aOptions,
JSContext* aCx,
PRUint8 aArgc,
nsIDOMDeviceStorageCursor** aRetval)
nsDOMDeviceStorage::EnumerateEditable(const nsAString & aPath,
nsIDOMDeviceStorageCursor * *_retval NS_OUTPARAM)
{
return EnumerateInternal(aName, aOptions, aCx, aArgc, true, aRetval);
}
static PRTime
ExtractDateFromOptions(JSContext* aCx, const JS::Value& aOptions)
{
PRTime result = 0;
DeviceStorageEnumerationParameters params;
if (!JSVAL_IS_VOID(aOptions) && !aOptions.isNull()) {
nsresult rv = params.Init(aCx, &aOptions);
if (NS_SUCCEEDED(rv) && !JSVAL_IS_VOID(params.since) && !params.since.isNull() && params.since.isObject()) {
JSObject* obj = JSVAL_TO_OBJECT(params.since);
if (JS_ObjectIsDate(aCx, obj) && js_DateIsValid(aCx, obj)) {
result = js_DateGetMsecSinceEpoch(aCx, obj);
}
}
}
return result;
return EnumerateInternal(aPath, _retval, true);
}
nsresult
nsDOMDeviceStorage::EnumerateInternal(const JS::Value& aName,
const JS::Value& aOptions,
JSContext* aCx,
PRUint8 aArgc,
bool aEditable,
nsIDOMDeviceStorageCursor** aRetval)
nsDOMDeviceStorage::EnumerateInternal(const nsAString & aPath,
nsIDOMDeviceStorageCursor * *_retval NS_OUTPARAM,
bool aEditable)
{
nsCOMPtr<nsPIDOMWindow> win = do_QueryReferent(mOwner);
if (!win)
return NS_ERROR_UNEXPECTED;
PRTime since = 0;
nsString path;
path.SetIsVoid(true);
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mFile, aPath);
nsRefPtr<nsDOMDeviceStorageCursor> cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, aEditable);
NS_ADDREF(*_retval = cursor);
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
since = ExtractDateFromOptions(aCx, aName);
} else {
return NS_ERROR_FAILURE;
}
if (aArgc == 2 && (JSVAL_IS_VOID(aOptions) || aOptions.isNull() || !aOptions.isObject())) {
return NS_ERROR_FAILURE;
}
since = ExtractDateFromOptions(aCx, aOptions);
}
nsRefPtr<DeviceStorageFile> dsf = new DeviceStorageFile(mFile, path);
nsRefPtr<nsDOMDeviceStorageCursor> cursor = new nsDOMDeviceStorageCursor(win, mURI, dsf, aEditable, 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;

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

@ -28,29 +28,18 @@ public:
nsDOMDeviceStorage();
nsresult Init(nsPIDOMWindow* aWindow, const nsAString&aType, const PRInt32 aIndex);
nsresult Init(nsPIDOMWindow* aWindow, const nsAString &aType, const PRInt32 aIndex);
PRInt32 SetRootFileForType(const nsAString& aType, const PRInt32 aIndex);
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin,
const nsAString& aType,
nsIVariant** aRetval);
static void CreateDeviceStoragesFor(nsPIDOMWindow* aWin, const nsAString &aType, nsIVariant** _retval);
private:
~nsDOMDeviceStorage();
nsresult GetInternal(const JS::Value& aName,
JSContext* aCx,
nsIDOMDOMRequest** aRetval,
bool aEditable);
nsresult EnumerateInternal(const JS::Value& aName,
const JS::Value& aOptions,
JSContext* aCx,
PRUint8 aArgc,
bool aEditable,
nsIDOMDeviceStorageCursor** aRetval);
nsresult GetInternal(const JS::Value & aName, JSContext* aCx, nsIDOMDOMRequest * *_retval NS_OUTPARAM, bool aEditable);
nsresult EnumerateInternal(const nsAString & aName, nsIDOMDeviceStorageCursor * *_retval NS_OUTPARAM, bool aEditable);
PRInt32 mStorageType;
nsCOMPtr<nsIFile> mFile;

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

@ -7,12 +7,7 @@ interface nsIDOMBlob;
interface nsIDOMDOMRequest;
interface nsIDOMDeviceStorageCursor;
dictionary DeviceStorageEnumerationParameters
{
jsval since;
};
[scriptable, uuid(6cdf3d8e-4a9f-4582-9d99-769bf9922cfb)]
[scriptable, uuid(05C0D0C8-D698-4CCD-899C-7198A33BD7EC)]
interface nsIDOMDeviceStorage : nsISupports
{
/*
@ -33,9 +28,7 @@ interface nsIDOMDeviceStorage : nsISupports
[implicit_jscontext]
nsIDOMDOMRequest delete(in jsval aName);
[optional_argc, implicit_jscontext]
nsIDOMDeviceStorageCursor enumerate([optional] in jsval aName, /* DeviceStorageEnumerationParameters */ [optional] in jsval options);
nsIDOMDeviceStorageCursor enumerate([optional] in DOMString directory);
[optional_argc, implicit_jscontext]
nsIDOMDeviceStorageCursor enumerateEditable([optional] in jsval aName, /* DeviceStorageEnumerationParameters */ [optional] in jsval options);
nsIDOMDeviceStorageCursor enumerateEditable([optional] in DOMString directory);
};

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

@ -19,8 +19,6 @@ _TEST_FILES = \
test_enumerateMultipleContinue.html \
test_overwrite.html \
test_dotdot.html \
test_enumerateOptions.html \
test_lastModificationFilter.html \
devicestorage_common.js \
$(NULL)

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

@ -5,13 +5,6 @@
var oldVal = false;
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
function devicestorage_setup() {
SimpleTest.waitForExplicitFinish();
try {
@ -53,7 +46,3 @@ function randomFilename(l) {
return result;
}
function reportErrorAndQuit(e) {
ok(false, "handleError was called : " + e.target.error.name);
devicestorage_cleanup();
}

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

@ -22,16 +22,27 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=717103
<pre id="test">
<script class="testbody" type="text/javascript">
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
devicestorage_setup();
function enumerateSuccess(e) {
if (e.target.result == null) {
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
dump("We still have length = " + files.length);
devicestorage_cleanup();
return;
}
dump("asdfasdf"+ e.target.result + "\n");
dump("asdfasdf"+ e.target.result.name + "\n");
var filename = e.target.result.name;
var index = files.indexOf(filename);

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

@ -1,81 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=717103
-->
<head>
<title>Test for basic sanity of the device storage API </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="devicestorage_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
devicestorage_setup()
storage = navigator.getDeviceStorage("profile");
throws = false;
try {
var cursor = storage[0].enumerate();
} catch(e) {throws = true}
ok(!throws, "enumerate no parameter");
throws = false;
try {
var cursor = storage[0].enumerate("string");
} catch(e) {throws = true}
ok(!throws, "enumerate one string parameter");
throws = false;
try {
var cursor = storage[0].enumerate("string", "string2");
} catch(e) {throws = true}
ok(throws, "enumerate two string parameter");
throws = false;
try {
var cursor = storage[0].enumerate("string", {"since": 1});
} catch(e) {throws = true}
ok(!throws, "enumerate a string and object parameter");
throws = false;
try {
var cursor = storage[0].enumerate({"path": "a"});
} catch(e) {throws = true}
ok(!throws, "enumerate object parameter with path");
throws = false;
try {
var cursor = storage[0].enumerate({}, "string");
} catch(e) {throws = true}
ok(throws, "enumerate object then a string");
throws = false;
try {
var cursor = storage[0].enumerate({"path": "a", "since": 0});
} catch(e) {throws = true}
ok(!throws, "enumerate object parameter with path");
devicestorage_cleanup()
</script>
</pre>
</body>
</html>

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

@ -1,111 +0,0 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html> <!--
https://bugzilla.mozilla.org/show_bug.cgi?id=717103
-->
<head>
<title>Test for the device storage API </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="devicestorage_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=717103">Mozilla Bug 717103</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
function verifyAndDelete(prefix, files, e) {
if (e.target.result == null) {
ok(files.length == 0, "when the enumeration is done, we shouldn't have any files in this array")
dump("We still have length = " + files.length + "\n");
dump(files + "\n");
devicestorage_cleanup();
return;
}
var filename = e.target.result.name;
var index = files.indexOf(filename);
ok(index > -1, "filename should be in the enumeration : " + e.target.result.name);
if (index == -1)
return;
files.remove(index);
// clean up
var storage = navigator.getDeviceStorage("profile");
var cleanup = storage[0].delete(prefix + "/" + filename);
cleanup.onsuccess = function(e) {}
}
function addFiles(prefix, files, date, callback) {
const Cc = SpecialPowers.wrap(Components).classes;
const Ci = Components.interfaces;
var directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
for (var i=0; i<files.length; i++) {
var f = directoryService.get("ProfD", Components.interfaces.nsIFile);
var path = prefix + '/' + files[i];
path.split("/").forEach(function(p) {
f.appendRelativePath(p);
});
f.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0644);
f.lastModifiedTime = date;
}
callback();
}
devicestorage_setup();
var prefix = "devicestorage/" + randomFilename(12)
var oldFiles = ["a", "b", "c"];
var newFiles = ["d", "e", "f"];
// 157795200 is a long long time ago.
addFiles(prefix, oldFiles, 157795200, addNewFiles);
function enumerateNew() {
var storage = navigator.getDeviceStorage("profile");
ok(navigator.getDeviceStorage, "Should have getDeviceStorage");
// 836031600 is a long time ago
var cursor = storage[0].enumerate(prefix, {"since": new Date(836031600)});
cursor.onsuccess = function(e) {
verifyAndDelete(prefix, newFiles, e);
if (e.target.result) {
e.target.continue();
}
}
cursor.onerror = function (e) {
ok(false, "handleError was called : " + e.target.error.name);
devicestorage_cleanup();
}
}
function addNewFiles() {
addFiles(prefix, newFiles, Date.now(), enumerateNew);
}
</script>
</pre>
</body>
</html>

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

@ -24,7 +24,6 @@ dictionaries = [
[ 'DeviceLightEventInit', 'nsIDOMDeviceLightEvent.idl' ],
[ 'DOMFileMetadataParameters', 'nsIDOMLockedFile.idl' ],
[ 'XMLHttpRequestParameters', 'nsIXMLHttpRequest.idl' ],
[ 'DeviceStorageEnumerationParameters', 'nsIDOMDeviceStorage.idl' ]
]
# include file names