User:Ehsan/PrivateBrowsingForExtensions: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Populate the code samples)
No edit summary
Line 6: Line 6:


===The Private Browsing service===
===The Private Browsing service===
The Private Browsing service can be used in order to get and set the current status of private browsing.  It supports the nsIPrivateBrowsingService interface:
The Private Browsing service can be used in order to get and set the current status of private browsing.  The contract ID for this service is <tt>@mozilla.org/browser/privatebrowsing;1</tt>.  It supports the nsIPrivateBrowsingService interface:


  [scriptable, uuid(d2943870-c781-11dc-95ff-0800200c9a66)]
  [scriptable, uuid(d2943870-c781-11dc-95ff-0800200c9a66)]
Line 15: Line 15:
  };
  };


The privateBrowsing attribute is key to the functionality of this service.  By setting it to true, private browsing mode will be initiated.  Likewise, by setting it to false, the private browsing mode will be terminated.  The current status of the private browsing mode can be queried by reading the value of this attribute.
The <tt>privateBrowsing</tt> attribute is key to the functionality of this service.  By setting it to true, private browsing mode will be initiated.  Likewise, by setting it to false, the private browsing mode will be terminated.  The current status of the private browsing mode can be queried by reading the value of this attribute.


===Private Browsing notifications===
===Private Browsing notifications===
Extensions can be notified of private browsing status changes, i.e., when the user enters or leaves the private browsing mode.  This is done via standard XPCOM observer service mechanisms.  The notification's name is "browser:private-browsing".  The data parameter can be either "enter" (indicating that the private browsing mode has been initiated) or "exit" (indicating that the private browsing mode has been terminated).
Extensions can be notified of private browsing status changes, i.e., when the user enters or leaves the private browsing mode.  This is done via standard XPCOM observer service mechanisms.  The notification's name is <tt>browser:private-browsing</tt>.  The data parameter can be either <tt>enter</tt> (indicating that the private browsing mode has been initiated) or <tt>exit</tt> (indicating that the private browsing mode has been terminated).


The second code sample below implements a full blown listener for the private browsing mode, which can both be used to query its current status, and set a watcher to watch for entering and/or leaving the private mode.
The second code sample below implements a full blown listener for the private browsing mode, which can both be used to query its current status, and set a watcher to watch for entering and/or leaving the private mode.
Line 26: Line 26:
===Extensions that want to check the status of the Private Browsing mode===
===Extensions that want to check the status of the Private Browsing mode===


  var pbs = Components.classes["@mozilla.org/privatebrowsing-service;1"]
  var pbs = Components.classes["@mozilla.org/browser/privatebrowsing;1"]
                     .getService(Components.interfaces.nsIPrivateBrowsingService);
                     .getService(Components.interfaces.nsIPrivateBrowsingService);
   
   
Line 116: Line 116:
===Extensions that want to initiate or terminate a Private Browsing session===
===Extensions that want to initiate or terminate a Private Browsing session===


  var pbs = Components.classes["@mozilla.org/privatebrowsing-service;1"]
  var pbs = Components.classes["@mozilla.org/browser/privatebrowsing;1"]
                     .getService(Components.interfaces.nsIPrivateBrowsingService);
                     .getService(Components.interfaces.nsIPrivateBrowsingService);
   
   
Confirmed users
657

edits

Navigation menu