User:Ehsan/PrivateBrowsingForExtensions: Difference between revisions

→‎Code Samples: Add a sample for private-browsing-query
(→‎Private Browsing notifications: Add a description of private-browsing-query)
(→‎Code Samples: Add a sample for private-browsing-query)
Line 128: Line 128:
  // exit the Private Browsing mode
  // exit the Private Browsing mode
  pbs.privateBrowsing = false;
  pbs.privateBrowsing = false;
===Extensions that want get the Private Browsing mode without depending on nsIPrivateBrowsingService===
var os = Components.classes["@mozilla.org/observer-service;1"]
                    .getService(Components.interfaces.nsIObserverService);
var inPrivate = Components.classes["@mozilla.org/supports-PRBool;1"]
                          .createInstance(Components.interfaces.nsISupportsPRBool);
os.notifyObservers(inPrivate, "private-browsing-query", null);
if (inPrivate.data) {
  // in private browsing mode
} else {
  // not in private browsing mode
}
Confirmed users
657

edits