Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion DOMContentLoaded event from C++
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Martin Lutken  
View profile  
 More options May 17 2011, 11:43 am
Newsgroups: mozilla.dev.tech.xul
From: Martin Lutken <mlut...@gmail.com>
Date: Tue, 17 May 2011 08:43:07 -0700 (PDT)
Local: Tues, May 17 2011 11:43 am
Subject: Re: DOMContentLoaded event from C++
Hi Neil

I'll try your way too. Again Thanks a lot :)
Also found a way myself which seems to work:

I found the solution. Just need to get the Parent windows of the one I
wa using. Except if you want the "unload" event which seems to only
work for the window I was first using. Here goes the complete updated
code for those who might have had the same troubles as I.
Thanks again to Neil for his great help.

void CSpecialThing::getBrowserQuestionForForum()
{
    nsString wsHrefXul      = NS_LITERAL_STRING( "chrome://xulcrawler/
content/main.xul" );
    nsString wsIDBrowser    = NS_LITERAL_STRING( "mybrowser1" );

    // --- A lot of variables ---
    nsresult rv;
    nsCOMPtr<nsIDOMWindowInternal>      pWinInt(0);
    nsCOMPtr<nsISimpleEnumerator>       pWinEnumerator;
    nsCOMPtr<nsIDOMLocation>            pDOMLocation;
    nsCOMPtr<nsIDOMWindowCollection>    pDOMWindowCollection;
    nsCOMPtr<nsIDOMWindow>              pDomWin;
    nsCOMPtr<nsIDOMWindow>              pDomWinBrowser;
    nsCOMPtr<nsIDOMDocument>            pDomDoc;

    // -----------------------------
    // --- Get DomWindowInternal ---
    // -----------------------------

    nsCOMPtr<nsIWindowMediator>
pWindowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));

    nsString sWindowType( NS_LITERAL_STRING("") );
    rv = pWindowMediator->GetEnumerator( sWindowType.get(),
getter_AddRefs(pWinEnumerator));

    PRBool bHasMoreElements;
    rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );

    while ( bHasMoreElements ) {
        nsCOMPtr<nsISupports> pSupportsWin;
        rv = pWinEnumerator->GetNext( getter_AddRefs(pSupportsWin) );
        nsCOMPtr<nsIDOMWindowInternal>
pWinInternal(do_QueryInterface(pSupportsWin));

        rv = pWinInternal-

>GetLocation( getter_AddRefs(pDOMLocation) );

        nsString wsHrefTest;
        rv = pDOMLocation->GetHref( wsHrefTest );

        // See if we have the correct (XUL) URI
        if ( wsHrefXul == wsHrefTest  ) pWinInt = pWinInternal;

        rv = pWinEnumerator->HasMoreElements( &bHasMoreElements );
    }

    // --- Get the "mybrowser1" element ---
    pWinInt->GetFrames( getter_AddRefs(pDOMWindowCollection) );
    pDOMWindowCollection->NamedItem( wsIDBrowser,
getter_AddRefs(pDomWin) );

    pDomWin->GetParent( getter_AddRefs(pDomWinBrowser) );

    // --- Add events ---
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowserWin(do_QueryInterface(pDomWin));
    nsCOMPtr<nsIDOMEventTarget>
pDomEventTargetBrowser(do_QueryInterface(pDomWinBrowser));
    pDomEventTargetBrowser-

>AddEventListener(NS_LITERAL_STRING("DOMContentLoaded"), this,

PR_FALSE);
    pDomEventTargetBrowser-
>AddEventListener(NS_LITERAL_STRING("resize"), this, PR_FALSE);

    pDomEventTargetBrowserWin-

>AddEventListener(NS_LITERAL_STRING("unload"), this, PR_FALSE);

    // ---------------------------------------------------------------
    // --- Bonus example on how to get the current URI of the page ---
    // ---------------------------------------------------------------
    pDomWin->GetDocument( getter_AddRefs(pDomDoc) );
    nsCOMPtr<nsIDOMDocumentView>
pDomDocumentView(do_QueryInterface(pDomDoc));
    nsCOMPtr<nsIDOMAbstractView> domAbstractView =
getDefaultView(pDomDocumentView);
    nsCOMPtr<nsIWebNavigation>
webNavigation(do_GetInterface(domAbstractView));
    printf("webNavigation uri: %s\n",
getCurrentURI(webNavigation).c_str() );
}


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.