WebAPI/SettingsAPI: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
Line 9: Line 9:
   interface SettingsManager : EventTarget
   interface SettingsManager : EventTarget
   {
   {
    // List of known settings.
    const DOMString FOOBAR = "foobar";
 
     // SettingsRequest.result contains the new value of the setting.
     // SettingsRequest.result contains the new value of the setting.
     SettingsRequest set(DOMString name, DOMString value);
     DOMRequest set(any settings);
    
    
     // SettingsRequest.result contains the value of the setting.
     // SettingsRequest.result contains the value of the setting.
     SettingsRequest get(DOMString name);
     DOMRequest get(DOMString name);
 
    // SettingsRequest.result contains JSON object with name/value pairs.
    DOMRequest get(DOMString[] names);
    
    
     attribute Function? onchange;
     attribute Function? onchange;
   }
   }


   /* Similar to SmsRequest. */
   /* Same as used in other specs. */
   interface SettingsRequest
   interface DOMRequest
   {
   {
     readonly attribute DOMString    readyState; // "processing" or "done"
     readonly attribute DOMString    readyState; // "processing" or "done"
Line 35: Line 35:
   {
   {
     readonly attribute DOMString settingName;
     readonly attribute DOMString settingName;
     readonly attribute DOMString settingValue;
     readonly attribute any      settingValue;
   };
   };
   
   
   dictionary SettingsEventInit : EventInit {
   dictionary SettingsEventInit : EventInit {
     DOMString settingName;
     DOMString settingName;
     DOMString settingValue;
     any      settingValue;
   }
   }



Revision as of 02:37, 4 February 2012

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?