Closed Bug 332774 Opened 18 years ago Closed 18 years ago

Create API allowing extensions to hook into the session-restore service

Categories

(Firefox :: Tabbed Browser, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
Firefox 2 beta1

People

(Reporter: dietrich, Assigned: dietrich)

References

Details

(Keywords: dev-doc-complete, fixed1.8.1, Whiteboard: 181b1+)

Attachments

(1 file)

From http://wiki.mozilla.org/Firefox2/Requirements:

"API allowing extensions to contribute items to be saved/restored across sessions"
Assignee: nobody → dietrich
Flags: blocking-firefox2+
Status: NEW → ASSIGNED
Blocks: 328154
Depends on: 328159
No longer depends on: 328159
What sort of API is planned here? I'm visualizing something like this:

var gSession = Components.classes["@mozilla.org/browser/sessionstore;1"]
                             .getService(nsCI.nsISessionStore);
var newAttr = gSession.newAttribute('example-number-list');
newAttr.spec = "0,1,2,3,4,5,6,7,8,9";
gSession.addAttribute(newAttr);

// or
var newAttr2 = Components.classes["@mozilla.org/browser/sessionstore;1"]
                             .createInstance(nsCI.nsISessionAttribute);
for (i = 0; i < 10; ++i) {
   newAttr2.append(i);
}

// later
gSession.removeAttribute(newAttr);

where newAttr is a new instance of an nsISessionAttribute, with a spec member similar to nsIURI as well as other accessor functions that can take a string or a number and parse it into the format used by the backing code.
It seems to me this API will be used to store attributes/objects both per tab and per session.

Per tab requirements might be done by allowing extensions to register the names of attributes (and perhaps js objects) to be stored if present on tab nodes.

As for per session data, a similar approach might be possible where the API is given an object reference (or several) which it backs up whenever it saves a session, though for maximum flexibility some kind of SessionSave 'event' letting you execute a little code whenever a session is saved, would be very powerful.

Either way some kind of SessionRestore 'event' would be useful to help extensions resume a session.
Whiteboard: [swag: 4d]
Anything happening with this?  Trying to figure out if there'll be an API to document in the Fx2 timeframe.
I've updated the wiki with some information about this:

http://wiki.mozilla.org/SessionRestoreAPI

I'd like to get this in for Fx2, but as freeze is next week, whether I can get to it really depends on how the next couple of days go.
swag 2 days to get basic session storage per the requirement.
Whiteboard: [swag: 4d] → [swag: 2d]
This exposes the ability to store strings by key for windows and tabs.

(I'll move the tests into a separate tests directory whenever this gets checked in.)
Attachment #227190 - Flags: review?(mconnor)
Whiteboard: [swag: 2d] → [swag: 2d] 181b1+
Whiteboard: [swag: 2d] 181b1+ → [needs review mconnor] 181b1+
Comment on attachment 227190 [details] [diff] [review]
exposes the window/tab data APIs, w/ some tests

mmm, tests.  Is this a framework davel is pushing, or something you just cooked up?
Attachment #227190 - Flags: review?(mconnor) → review+
Hey Dietrich,

I took a quick look at the tests - is there a reason other than running with chrome privs that you need this to be a xul doc? 
(In reply to comment #7)
> (From update of attachment 227190 [details] [diff] [review] [edit])
> mmm, tests.  Is this a framework davel is pushing, or something you just cooked
> up?
> 

i wrote this, but it should be easy enough to convert to davel's format, once it's finalized.

(In reply to comment #8)
> Hey Dietrich,
> 
> I took a quick look at the tests - is there a reason other than running with
> chrome privs that you need this to be a xul doc? 
> 

i need chrome privs, and to be able to open windows, tabs, and inspect menus, etc, basically a full browser environment.
Can we get this landed on trunk ASAP and smoketested? Then nominate for approval1.8.1?
i had to manually merge, due to conflicts w/ recent changes. should be on trunk pretty soon, once i test the updated patch.
Whiteboard: [needs review mconnor] 181b1+ → 181b1+ [checkin needed]
Comment on attachment 227190 [details] [diff] [review]
exposes the window/tab data APIs, w/ some tests

Low risk, no UI, no l10n impact.
Attachment #227190 - Flags: approval1.8.1?
Attachment #227190 - Flags: approval1.8.1? → approval1.8.1+
Keywords: fixed1.8.1
Whiteboard: 181b1+ [checkin needed] → 181b1+
Looks like this is making the beta?  Where do I look to dig up all the juicy details on the API so I can write a doc about it?
(In reply to comment #13)
> Looks like this is making the beta?  Where do I look to dig up all the juicy
> details on the API so I can write a doc about it?
> 

Howdy, I'll try to add API details on the wiki today:

http://wiki.mozilla.org/SessionRestoreAPI

Also, there's example usage in the tests here:

http://lxr.mozilla.org/mozilla/source/browser/components/sessionstore/test/nsSessionStoreTest.xul
Status: ASSIGNED → RESOLVED
Closed: 18 years ago
Resolution: --- → FIXED
(In reply to comment #6)
> Created an attachment (id=227190)

>+      Components.returnCode = -1; //zeniko: or should we rather fail silently?

Instead of copy/pasting (and mis-quoting me ;-)), it would've been better to do the same thing you already did for undoCloseTab:

+       Components.returnCode = Cr.NS_ERROR_INVALID_ARG;

Apart of that, one relevant part of the API is still missing: allowing extensions to retrieve/restore complete session states.

Dietrich: Are there any bugs pending on these issues already?
Blocks: 344640
Blocks: 344642
RE: dev-doc-needed

As an extension developer currently using the session store api, I find the documentation on developer.mozilla.org sufficient, if not perfect.

http://developer.mozilla.org/en/docs/Session_store_API
http://developer.mozilla.org/en/docs/nsISessionStore

Though it would be quite be nice to have official documentation on the format of the json object returned, rather than having to work it out manually.
Blocks: 360408
Do we want to document the JSON object?  If so, I'll have to poke around and figure out where it's built so I can do so.
Since there seems not to be any interest in documenting the JSON format, I'm marking this as dev-doc-complete.  Please re-tag it if this is in error.
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: