Open Bug 301746 Opened 19 years ago Updated 2 years ago

Session history entries should implement property bag

Categories

(Core :: DOM: Navigation, enhancement)

x86
All
enhancement

Tracking

()

UNCONFIRMED

People

(Reporter: brettw, Unassigned)

Details

Attachments

(2 files, 1 obsolete file)

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.9) Gecko/20050711 Firefox/1.0.5
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.9) Gecko/20050711 Firefox/1.0.5

It would be useful for some extensions to be able to associate data with session
history. This can be provided by implementing the (writable)property bag
interface on session history entries.

Reproducible: Always
Assignee: nobody → brettw
Testcase for the soon-to-be-submitted patch. Install the XPI and restart. Here
is the basic code to save you from opening the XPI:

var historyEntry = THM_contentArea.sessionHistory.getEntryAtIndex(0, false);
var wiface = historyEntry.QueryInterface(
  Components.interfaces.nsIWritablePropertyBag);
var riface = historyEntry.QueryInterface(
  Components.interfaces.nsIPropertyBag);
wiface.setProperty("testprop", "The bag tester worked")
alert(riface.getProperty("testprop"));

If it works, it will display "The bag tester worked" on page transitions (and
some other times, too).
This extension will fire on page transition events and set a string into the
history's property bag interface (to be implemented in a soon-to-be-submitted
patch). It will then display this string, which should be "The bag tester
worked". Here's the main part of the code

var historyEntry = THM_contentArea.sessionHistory.getEntryAtIndex(0, false);
var wiface = historyEntry.QueryInterface(
  Components.interfaces.nsIWritablePropertyBag);
var riface = historyEntry.QueryInterface(
  Components.interfaces.nsIPropertyBag);

wiface.setProperty("testprop", "The bag tester worked")
alert(riface.getProperty("testprop"));
Attachment #190206 - Attachment is obsolete: true
This patch derives nsSHEntry from a nsHashPropertyBag so arbitrary data can be
associated with session history.

The nsHashPropertyBag interface was changed to lazy initialization of the hash
table. This minimizes overhead when the interface is never used (common case).
Checks are done whenever a property is set of get to see if the hash table is
initialized.

The previous behavior of using Init to force initialization of the interfaces
was kept for previously written components that derive from this class and
therefore may bypass the property bag getter/setter interface (and, hence,
initialization of the hash table). I could not find any components that do
this, however. This just adds the ability to not call Init if you only use the
interface.
I don't think extensions should be depending on our session history APIs, actually.  Those APIs need to be redone (together with the actual impl) to work in the modern world...
Assignee: brettw → nobody
Component: History: Session → Document Navigation
QA Contact: history.session → docshell
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: