Hmm, yes this is a little tricky given the lack of weak references (/ weak listeners) in JS...   The FileEntry will probably be a lot less permanent than the DocumentManager singleton this code used to listen to, but nonetheless we probably still do need to clean up the listener.

How about this -- on the first addRef() we add this listener, and on the last releaseRef() we clean it up.  Anyone keeping a Document around for an asynchronous length of time is required to addRef() it, so the listener only matters when the refcount is non-zero.