MozillaZine

getBrowserIndexForDocument and ajax modified docs

Talk about add-ons and extension development.
AngelaLloyd
 
Posts: 20
Joined: April 23rd, 2009, 3:40 am

Post Posted June 23rd, 2009, 7:59 am

If a document is modified via xmlhttpreq. calls, then getBrowserIndexForDocument fails with the document retrieved from aWebProgress.DOMWindow.document.

Would this be considered a bug?

If not, how do I retrieve the browser index for a document that has been modified via xmlhttpreq?

Thanks

max1million
 
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post Posted June 24th, 2009, 1:11 am

Modified or replaced? They are different. If the document was replaced you need reference to the new document. Also I believe it's only the top level document not those in frames and only for those in gBrowser.

Might consider getting before replacing
Code: Select all
var doc = content.document; // set original document
var browser = gBrowser.getBrowserForDocument(doc);
var index = gBrowser.getBrowserIndexForDocument(doc); // may change such as moving tab
var tab = gBrowser.mTabs[index];

// do somthing that replaces doc then get new doc from browser
doc = browser.contentDocument;
// move tab then get new index
index =  tab._tPos;// or gBrowser.getBrowserIndexForDocument(doc);

AngelaLloyd
 
Posts: 20
Joined: April 23rd, 2009, 3:40 am

Post Posted June 24th, 2009, 12:41 pm

I'm trying to getBrowserIndexForDocument(doc) with the new doc, and it returns -1

AngelaLloyd
 
Posts: 20
Joined: April 23rd, 2009, 3:40 am

Post Posted June 24th, 2009, 2:26 pm

i've been looking through the code for adblockerplus, and what that seems to do is assign a 'ghetto_guid' to the browser for the tab, then enumerates through all the browsers looking for this guid - i think!

i think this may be the only way?

max1million
 
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post Posted June 25th, 2009, 12:57 am

It seems that the object you're trying to get the index for is not a page's window.top.document, in a tab's browser element, in the chrome window. Assuming your not trying this on a different chrome window, sidebar, or some other added browser or iframe element. You might check the document's location just to know for sure what page it is for troubleshooting.
try aWebProgress.DOMWindow.top.document

AngelaLloyd
 
Posts: 20
Joined: April 23rd, 2009, 3:40 am

Post Posted June 25th, 2009, 2:54 am

Once again, that's amazing, thanks, and definitely something I didn't know or take note of in the nsiDOMWindow docs.

So DOMWindow.top points to the topmost 'frame', and if the xmlhttpreq adds a frameset, then the browser wouldn't be found for that doc?

The document that doesn't work adds an iframe, but I don't see any framesets?

max1million
 
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post Posted June 26th, 2009, 12:34 pm

.top of a window is topmost window in the hierarchy, even if it is already topmost window in the hierarchy (content is limited to content, ie. web page)

A window of a frame/iframe is not topmost window in the hierarchy, makes it's own request, and gBrowser methods should work using it's .top.document (document of topmost window in the hierarchy) if that document is loaded in the browser of a tab in gBrowser

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests