Bug 673586 - Implement lastModifiedDate property for the File interface. r=mounir
authorDoug Turner <dougt@dougt.org>
Mon, 21 May 2012 15:11:56 -0700
changeset 94525 877e541590c2f894372f6c877342920dad2b106c
parent 94524 1738e189377f892bc60da69b0317a355b58c4b1e
child 94526 09b1b0fe568a9ce472cbaa88b0a371ae6745a3ac
push id9658
push userdougt@mozilla.com
push dateMon, 21 May 2012 22:12:44 +0000
treeherdermozilla-inbound@877e541590c2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs673586
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 673586 - Implement lastModifiedDate property for the File interface. r=mounir
content/base/public/nsDOMFile.h
content/base/public/nsIDOMFile.idl
content/base/src/nsDOMFile.cpp
content/base/test/test_bug403852.html
--- a/content/base/public/nsDOMFile.h
+++ b/content/base/public/nsDOMFile.h
@@ -178,16 +178,17 @@ public:
                         JSContext* aCx,
                         JSObject* aObj,
                         PRUint32 aArgc,
                         jsval* aArgv);
 
   // Overrides
   NS_IMETHOD GetSize(PRUint64* aSize);
   NS_IMETHOD GetType(nsAString& aType);
+  NS_IMETHOD GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate);
   NS_IMETHOD GetMozFullPathInternal(nsAString& aFullPath);
   NS_IMETHOD GetInternalStream(nsIInputStream**);
 
   // DOMClassInfo constructor (for File("foo"))
   static nsresult
   NewFile(nsISupports* *aNewObject);
 
 protected:
--- a/content/base/public/nsIDOMFile.idl
+++ b/content/base/public/nsIDOMFile.idl
@@ -51,20 +51,24 @@ interface nsIDOMBlob : nsISupports
   // the blob is initialized from a database. It can be called on any thread.
   [notxpcom] void addFileInfo(in FileInfo aFileInfo);
 
   // Called before the blob is stored in a database to decide if it can be
   // shared or needs to be copied. It can be called on any thread.
   [notxpcom] FileInfo getFileInfo(in FileManager aFileManager);
 };
 
-[scriptable, builtinclass, uuid(b096ef67-7b77-47f8-8e70-5d8ee36416bf)]
+[scriptable, builtinclass, uuid(eee028d1-8ce9-4c6c-b9ce-d89b656e1e17)]
 interface nsIDOMFile : nsIDOMBlob
 {
   readonly attribute DOMString name;
+
+  [implicit_jscontext]
+  readonly attribute jsval lastModifiedDate;
+
   readonly attribute DOMString mozFullPath;
 
   // This performs no security checks!
   [noscript] readonly attribute DOMString mozFullPathInternal;
 };
 
 [scriptable, builtinclass, uuid(57195950-edd9-496b-9b45-e4893a9ffca9)]
 interface nsIDOMMozBlobBuilder : nsISupports
--- a/content/base/src/nsDOMFile.cpp
+++ b/content/base/src/nsDOMFile.cpp
@@ -124,16 +124,23 @@ NS_IMETHODIMP
 nsDOMFileBase::GetName(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   aFileName = mName;
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsDOMFileBase::GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate)
+{
+  aLastModifiedDate->setNull();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMFileBase::GetMozFullPath(nsAString &aFileName)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
 
   // It is unsafe to call CallerHasUniversalXPConnect on a non-main thread. If
   // you hit the following assertion you need to figure out some other way to
   // determine privileges and call GetMozFullPathInternal.
   NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
@@ -413,16 +420,32 @@ nsDOMFileFile::NewFile(nsISupports* *aNe
 NS_IMETHODIMP
 nsDOMFileFile::GetMozFullPathInternal(nsAString &aFilename)
 {
   NS_ASSERTION(mIsFile, "Should only be called on files");
   return mFile->GetPath(aFilename);
 }
 
 NS_IMETHODIMP
+nsDOMFileFile::GetLastModifiedDate(JSContext* cx, JS::Value *aLastModifiedDate)
+{
+  PRTime msecs;
+  mFile->GetLastModifiedTime(&msecs);
+  JSObject* date = JS_NewDateObjectMsec(cx, msecs);
+  if (date) {
+    aLastModifiedDate->setObject(*date);
+  }
+  else {
+    aLastModifiedDate->setNull();
+  }
+
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsDOMFileFile::GetSize(PRUint64 *aFileSize)
 {
   if (IsSizeUnknown()) {
     NS_ASSERTION(mWholeFile,
                  "Should only use lazy size when using the whole file");
     PRInt64 fileSize;
     nsresult rv = mFile->GetFileSize(&fileSize);
     NS_ENSURE_SUCCESS(rv, rv);
--- a/content/base/test/test_bug403852.html
+++ b/content/base/test/test_bug403852.html
@@ -29,11 +29,16 @@ testFile.append("prefs.js");
 var fileList = document.getElementById('fileList');
 fileList.value = testFile.path;
 
 // Make sure the file is accessible with indexed notation
 var domFile = fileList.files[0];
 
 is(domFile.name, "prefs.js", "fileName should be prefs.js");
 
+ok("lastModifiedDate" in domFile, "lastModifiedDate must be present");
+
+var d = new Date(testFile.lastModifiedTime);
+ok(d.getTime() == domFile.lastModifiedDate.getTime(), "lastModifiedDate should be the same.");
+
 </script>
 </pre>
 </body> </html>