WebAPI/SettingsAPI

From MozillaWiki
< WebAPI
Revision as of 00:53, 10 February 2012 by Sicking (talk | contribs)
Jump to navigation Jump to search

Status

The proposed specification doesn't have a fully working implementation yet. Patches will appear in bug 678695.

Proposed API

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

 interface SettingsManager : EventTarget
 {
   // SettingsRequest.result contains the new value of the setting.
   DOMRequest set(any settings);
 
   // SettingsRequest.result contains the value of the setting.
   DOMRequest get(DOMString name);
 
   // SettingsRequest.result contains JSON object with name/value pairs.
   DOMRequest get(DOMString[] names);
 
   attribute Function? onchange;
 }
 /* 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?