User:Ehsan/PrivateBrowsingForExtensions

From MozillaWiki
< User:Ehsan
Revision as of 10:33, 9 September 2008 by Ehsan (talk | contribs) (Document the Private Browsing service)
Jump to navigation Jump to search

Introduction

Many extensions may store data which can reveal information about user's browsing history. For example, and extension may record the last visit date for all the websites that the user visits. There is currently no reliable way for us to disable storing such data by extensions, therefore it is very important to provide simple to use APIs as well as code samples which extension developers can use to integrate the Private Browsing mode with their extensions.

APIs for Extensions

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:

[scriptable, uuid(d2943870-c781-11dc-95ff-0800200c9a66)]
interface nsIPrivateBrowsingService : nsISupports
{
    // Whether or not the private browsing mode is currently active.
    attribute boolean privateBrowsing;
};

You can use the following code sample in order to get the current status of the private browsing mode, or change it.

var pbs = Components.classes["@mozilla.org/privatebrowsing-service;1"]
                    .getService(Components.interfaces.nsIPrivateBrowsingService);
// are we currently in the Private Browsing mode?
var inPrivateBrowsingMode = pbs.privateBrowsing;

// enter the Private Browsing mode
pbs.privateBrowsing = true;

// now, whatever we do remains private!

// exit the Private Browsing mode
pbs.privateBrowsing = false;

Code Samples

Extensions that want to check the status of the Private Browsing mode

Extensions that want to listen to the Private Browsing mode changes

Extensions that want to initiate or terminate a Private Browsing session