WebAPI/SettingsAPI: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
m (syntax fixes)
No edit summary
 
(14 intermediate revisions by 6 users not shown)
Line 1: Line 1:
== Status ==
== Status ==


The proposed specification doesn't have a fully working implementation yet. Patches will appear in {{bug|678695}}.
This was implemented for B2G in {{bug|678695}}.


== Proposed API ==
== Proposed API ==
Line 7: Line 7:
There is a readonly mozSettings attribute in ''window.navigator'' that would return an object implementing the ''SettingsManager'' interface.
There is a readonly mozSettings attribute in ''window.navigator'' that would return an object implementing the ''SettingsManager'' interface.


  interface SettingsManager
The implementation keeps a queue of active locks. When a lock is created it's placed at the end of the queue. Calls to get/set places a request against the lock on which it's called. Requests run asynchronously and in the order they are placed against a lock. When the last request for a lock is run, and we've fired the success/error event against it, the lock is removed from the queue and we start processing the next lock.
  {
 
    // List of known settings.
interface SettingsManager : EventTarget
    const DOMString FOOBAR = "foobar";
{
 
  SettingsLock getLock();
    // Setters. SettingsRequest.result is always null.
    SettingsRequest set(DOMString name, DOMString value);
  void addObserver(DOMString name, Function observer);
    SettingsRequest set(DOMString name, long value);
}
    SettingsRequest set(DOMString name, long long value);
    SettingsRequest set(DOMString name, float value);
interface SettingsLock
    
{
    // Getters. SettingsRequest.result will be of the requested type if the success event is sent.
  // Contains a JSON object with name/value pairs to be set.
    SettingsRequest getString(DOMString name);
  DOMRequest set(any settings);
    SettingsRequest getInt(DOMString name);
     SettingsRequest getLong(DOMString name);
   // result contains the value of the setting.
    SettingsRequest getFloat(DOMString name);
  DOMRequest get(DOMString name);
  }
  // XXX not implemented
  // result contains JSON object with name/value pairs.
  DOMRequest get(DOMString[] names);
}
 
/* Same as used in other specs. */
interface DOMRequest
{
  readonly attribute DOMString    readyState; // "processing" or "done"
  readonly attribute DOMError?     error;
            attribute EventListener onsuccess;
            attribute EventListener onerror;
            attribute readonly any? result;
};
 
[Constructor(DOMString type, optional SettingsEventInit settingsEventInitDict)]
interface SettingsEvent : Event
{
  readonly attribute DOMString settingName;
  readonly attribute any      settingValue;
};
dictionary SettingsEventInit : EventInit {
  DOMString settingName;
  any      settingValue;
}
 
''SettingsEvent'' is used for the followings events:
- ''change'' which is dispatched to the SettingsManager object when a setting value changes


== Notes ==
== Notes ==


* SettingsRequest will be similar to SMSRequest described in [[WebAPI/WebSMS|WebSMS specification]].
* SettingsRequest will be similar to SMSRequest described in [[WebAPI/WebSMS|WebSMS specification]].
* As for BatteryAPI, SettingsManager object might be in window.navigator, window.navigator.devices or even could be created with ''new''.
* If a setting is unknown by the platform, it should fail.
* The allowed types are restricted to the type we know we will be using in the first implementation. Those could be extended.
* If a setting is unknown, it should fail.
* But some platforms might not know some settings. Do we want to add a method that checks if the platform knows a specific setting?
* But some platforms might not know some settings. Do we want to add a method that checks if the platform knows a specific setting?
* get('*') returns all settings.
[[Category:Web APIs]]

Latest revision as of 23:56, 1 October 2014

Status

This was implemented for B2G in bug 678695.

Proposed API

There is a readonly mozSettings attribute in window.navigator that would return an object implementing the SettingsManager interface.

The implementation keeps a queue of active locks. When a lock is created it's placed at the end of the queue. Calls to get/set places a request against the lock on which it's called. Requests run asynchronously and in the order they are placed against a lock. When the last request for a lock is run, and we've fired the success/error event against it, the lock is removed from the queue and we start processing the next lock.

interface SettingsManager : EventTarget
{
 SettingsLock getLock();

 void addObserver(DOMString name, Function observer);
}

interface SettingsLock
{
 // Contains a JSON object with name/value pairs to be set.
 DOMRequest set(any settings);

 // result contains the value of the setting.
 DOMRequest get(DOMString name);

 // XXX not implemented
 // result contains JSON object with name/value pairs.
 DOMRequest get(DOMString[] names);
}
/* Same as used in other specs. */
interface DOMRequest
{
  readonly attribute DOMString     readyState; // "processing" or "done"
  readonly attribute DOMError?     error;
           attribute EventListener onsuccess;
           attribute EventListener onerror;
           attribute readonly any? result;
};
[Constructor(DOMString type, optional SettingsEventInit settingsEventInitDict)]
interface SettingsEvent : Event
{
  readonly attribute DOMString settingName;
  readonly attribute any       settingValue;
};

dictionary SettingsEventInit : EventInit {
  DOMString settingName;
  any       settingValue;
}

SettingsEvent is used for the followings events: - change which is dispatched to the SettingsManager object when a setting value changes

Notes

  • SettingsRequest will be similar to SMSRequest described in WebSMS specification.
  • If a setting is unknown by the platform, it should fail.
  • But some platforms might not know some settings. Do we want to add a method that checks if the platform knows a specific setting?
  • get('*') returns all settings.