WebAPI/ProposedDeviceStorageAPIWithNotifications: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
 
(7 intermediate revisions by one other user not shown)
Line 19: Line 19:
  };
  };
   
   
  interface DeviceStorage {
  interface DeviceStorage : EventTarget {
   // Name will be generated by the implementation and returned as result of request
   // Name will be generated by the implementation and returned as result of request
   DOMRequest add(Blob blob);
   DOMRequest add(Blob blob);
Line 35: Line 35:
   DOMRequest delete(DOMString name);
   DOMRequest delete(DOMString name);
   
   
   // Create a watcher which will call the callback function every time files are updated
   // Adds a listener for a file update event.
   // callback will take the DeviceStorage, the file's name, and the update type, which will be one of "created", "deleted", or "modified"
   // The type determines what type of event to listen for: one of "created","deleted", and "modified".
   // If name is passed, the file watcher will only watch the file with the specified name.
  // The listener recieves notification when an event occurs
   boolean addFileWatcher(Function callback, optional DOMstring name);
   // If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
   void addEventListener(DOMString type, EventListener listener, optional boolean useCapture);
   
   
   // returns true if there was a watcher with this id, and false otherwise.
   // Removes the listener for the given file update event
   boolean removeFileWatcher(Function callback, optional DOMstring name);
  // the listener will stop receiving notifications after this call.
  void removeEventListener(DOMString type, EventListener listener);
  // Sends an event to the event listeners the same as if it was delivered directly.
   boolean dispatchEvent(DeviceStorageChangeEvent event);
   
   
   // See interface below for how to use this
   // See interface below for how to use this
Line 53: Line 58:
   void continue();
   void continue();
  };
  };
interface DeviceStorageChangeEvent : Event{
  //.type is "devicestoragechange"
  //.target is the DeviceStorage object that caused this
  DOMString change; //one of "created","modified", or "deleted"
  DOMString path; //absolute path to the file that updated
}
[[Category:Web APIs]]

Latest revision as of 23:54, 1 October 2014

This page contains a draft of the proposed modification to the DeviceStorage API to include onchanged notifications.

API

partial interface Navigator {
  /**
   * type is an arbitrary string. On OSs with predefined directories (pictures,
   * music, etc) we can match certain type names to certain folders.
   * To be figured out.
   *
   * Note that each value for the type represents a different directory.
   * I.e. passing "pictures" as type will yield a completely different set
   * of files from passing "movies" as the type.
   *
   * In other words, the type argument is not some sort of filter, but rather
   * simply a destination directory.
   */
  DeviceStorage getDeviceStorage(DOMString type);
};

interface DeviceStorage : EventTarget {
  // Name will be generated by the implementation and returned as result of request
  DOMRequest add(Blob blob);

  // Fails if a file with the given name already exists.
  DOMRequest addNamed(Blob blob, DOMString name);

  // Returns the result as a File object
  DOMRequest get(DOMString name);

  // Returns the result as a FileHandle object which enables writing
  DOMRequest getEditable(DOMString name);

  // Deletes a file
  DOMRequest delete(DOMString name);

  // Adds a listener for a file update event.
  // The type determines what type of event to listen for: one of "created","deleted", and "modified".
  // The listener recieves notification when an event occurs
  // If true, useCapture indicates that the user wishes to initiate capture. After initiating capture, all events of the specified type will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
  void addEventListener(DOMString type, EventListener listener, optional boolean useCapture);

  // Removes the listener for the given file update event
  // the listener will stop receiving notifications after this call.
  void removeEventListener(DOMString type, EventListener listener);

  // Sends an event to the event listeners the same as if it was delivered directly.
  boolean dispatchEvent(DeviceStorageChangeEvent event);

  // See interface below for how to use this
  DeviceStorageCursor enumerate(optional DOMString directory)
  DeviceStorageCursor enumerateEditable(optional DOMString directory)
};

interface DeviceStorageCursor : DOMRequest {
  // .result is either a File or a FileHandle
  
  void continue();
};

interface DeviceStorageChangeEvent : Event{
  //.type is "devicestoragechange"
  //.target is the DeviceStorage object that caused this
  DOMString change; //one of "created","modified", or "deleted"
  DOMString path; //absolute path to the file that updated
}