Back to index

lightning-sunbird  0.9+nobinonly
EmbedWindow.cpp
Go to the documentation of this file.
00001 /*
00002  * vim:ts=2:et:sw=2
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is mozilla.org code.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00021  * Portions created by the Initial Developer are Copyright (C) 2001
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Christopher Blizzard <blizzard@mozilla.org>
00026  *   Brian Edmond <briane@qnx.com>
00027  *
00028  * Alternatively, the contents of this file may be used under the terms of
00029  * either the GNU General Public License Version 2 or later (the "GPL"), or
00030  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00031  * in which case the provisions of the GPL or the LGPL are applicable instead
00032  * of those above. If you wish to allow use of your version of this file only
00033  * under the terms of either the GPL or the LGPL, and not to allow others to
00034  * use your version of this file under the terms of the MPL, indicate your
00035  * decision by deleting the provisions above and replace them with the notice
00036  * and other provisions required by the GPL or the LGPL. If you do not delete
00037  * the provisions above, a recipient may use your version of this file under
00038  * the terms of any one of the MPL, the GPL or the LGPL.
00039  *
00040  * ***** END LICENSE BLOCK ***** */
00041 #include <nsIDocShell.h>
00042 #include <nsIWebProgress.h>
00043 #include <nsIURI.h>
00044 #include "nsIWidget.h"
00045 
00046 // for do_GetInterface
00047 #include <nsIInterfaceRequestor.h>
00048 #include <nsIInterfaceRequestorUtils.h>
00049 #include <nsIWebBrowserPersist.h>
00050 // for do_CreateInstance
00051 #include <nsIComponentManager.h>
00052 #include "nsIWebProgressListener.h"
00053 #include "nsIDOMHTMLImageElement.h"
00054 
00055 #include <nsCWebBrowser.h>
00056 #include <nsIComponentManager.h>
00057 #include <nsIDocShellTreeItem.h>
00058 #include <nsILocalFile.h>
00059 #include <nsString.h>
00060 #include "nsReadableUtils.h"
00061 
00062 #include "EmbedWindow.h"
00063 #include "EmbedPrivate.h"
00064 
00065 #include "PtMozilla.h"
00066 
00067 PtWidget_t *EmbedWindow::sTipWindow = nsnull;
00068 
00069 EmbedWindow::EmbedWindow(void)
00070 {
00071        NS_INIT_ISUPPORTS();
00072   mOwner       = nsnull;
00073   mVisibility  = PR_FALSE;
00074   mIsModal     = PR_FALSE;
00075 }
00076 
00077 EmbedWindow::~EmbedWindow(void)
00078 {
00079   ExitModalEventLoop(PR_FALSE);
00080 }
00081 
00082 nsresult
00083 EmbedWindow::Init(EmbedPrivate *aOwner)
00084 {
00085   // save our owner for later
00086   mOwner = aOwner;
00087 
00088   // create our nsIWebBrowser object and set up some basic defaults.
00089   mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
00090   if (!mWebBrowser)
00091     return NS_ERROR_FAILURE;
00092 
00093   mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
00094   
00095        // get the doc shel for cut/copy/paste
00096        //mRootDocShell = do_GetInterface(mWebBrowser);
00097 
00098   nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mWebBrowser);
00099   item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
00100 
00101   return NS_OK;
00102 }
00103 
00104 nsresult
00105 EmbedWindow::CreateWindow(void)
00106 {
00107   nsresult rv;
00108   PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
00109 
00110   // Get the base window interface for the web browser object and
00111   // create the window.
00112   mBaseWindow = do_QueryInterface(mWebBrowser);
00113   rv = mBaseWindow->InitWindow(ownerAsWidget,
00114                             nsnull,
00115                             0, 0, 
00116                             ownerAsWidget->area.size.w,
00117                             ownerAsWidget->area.size.h);
00118   if (NS_FAILED(rv))
00119     return rv;
00120 
00121   rv = mBaseWindow->Create();
00122   if (NS_FAILED(rv))
00123     return rv;
00124 
00125   return NS_OK;
00126 }
00127 
00128 void
00129 EmbedWindow::ReleaseChildren(void)
00130 {
00131   ExitModalEventLoop(PR_FALSE);
00132     
00133   mBaseWindow->Destroy();
00134   mBaseWindow = 0;
00135   mWebBrowser = 0;
00136 }
00137 
00138 // nsISupports
00139 
00140 NS_IMPL_ADDREF(EmbedWindow)
00141 NS_IMPL_RELEASE(EmbedWindow)
00142 
00143 NS_INTERFACE_MAP_BEGIN(EmbedWindow)
00144   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
00145   NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
00146   NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
00147   NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
00148   NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
00149   NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
00150   NS_INTERFACE_MAP_ENTRY(nsIDNSListener)
00151   NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
00152 NS_INTERFACE_MAP_END
00153 
00154 // nsIWebBrowserChrome
00155 
00156 NS_IMETHODIMP
00157 EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus)
00158 {
00159   PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00160        PtCallbackList_t     *cb;
00161        PtCallbackInfo_t     cbinfo;
00162        PtMozillaInfoCb_t    info;
00163   nsAutoString Text ( aStatus );
00164   int       type = 0;
00165 
00166   switch (aStatusType)
00167   {
00168       case STATUS_SCRIPT:
00169           type = Pt_MOZ_INFO_JSSTATUS;
00170           break;
00171       case STATUS_SCRIPT_DEFAULT:
00172           return NS_OK;
00173           break;
00174       case STATUS_LINK:
00175           type = Pt_MOZ_INFO_LINK;
00176           break;
00177       default:
00178           return NS_OK;
00179           break;
00180   }
00181 
00182   if (!moz->info_cb)
00183     return NS_OK;
00184 
00185   memset(&cbinfo, 0, sizeof(cbinfo));
00186   cbinfo.cbdata = &info;
00187   cbinfo.reason = Pt_CB_MOZ_INFO;
00188   cb = moz->info_cb;
00189 
00190   info.type = type;
00191   info.status = 0;
00192   const char* status = ToNewCString(Text);
00193   info.data = (char *)status;
00194   PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
00195 
00196   nsMemory::Free( (void*)status );
00197 
00198   return NS_OK;
00199 }
00200 
00201 int
00202 EmbedWindow::SaveAs(char *fname, char *dirname)
00203 {
00204        nsresult rv;
00205 
00206        nsCOMPtr<nsIWebBrowserPersist> persist(do_GetInterface(mWebBrowser, &rv));
00207        if (NS_FAILED(rv)) return rv;
00208 
00209   nsCOMPtr<nsILocalFile> file;
00210   NS_NewNativeLocalFile(nsDependentCString(fname), PR_TRUE, getter_AddRefs(file));
00211 
00212        /* the nsIWebBrowserPersist wants a parent directory where to download images and other items related to the document */
00213        /* we have to provide a directory, otherwise the current SaveDocument is marked as not finished and the next one is aborted */
00214        nsCOMPtr<nsILocalFile> parentDirAsLocal;
00215        rv = NS_NewNativeLocalFile(nsDependentCString( dirname ), PR_TRUE, getter_AddRefs(parentDirAsLocal));
00216        if (NS_FAILED(rv)) return rv;
00217 
00218        PRUint32 flags;
00219        persist->GetPersistFlags( &flags );
00220        if( !(flags & nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES ) ) persist->SetPersistFlags( nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES );
00221 
00222   persist->SaveDocument(nsnull, file, parentDirAsLocal, nsnull, 0, 0);
00223   return 0;
00224 }
00225 
00226 NS_IMETHODIMP
00227 EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser)
00228 {
00229   *aWebBrowser = mWebBrowser;
00230   NS_IF_ADDREF(*aWebBrowser);
00231   return NS_OK;
00232 }
00233 
00234 NS_IMETHODIMP
00235 EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser)
00236 {
00237   mWebBrowser = aWebBrowser;
00238   return NS_OK;
00239 }
00240 
00241 NS_IMETHODIMP
00242 EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags)
00243 {
00244   *aChromeFlags = mOwner->mChromeMask;
00245   return NS_OK;
00246 }
00247 
00248 NS_IMETHODIMP
00249 EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags)
00250 {
00251   mOwner->mChromeMask = aChromeFlags;
00252   return NS_OK;
00253 }
00254 
00255 NS_IMETHODIMP
00256 EmbedWindow::DestroyBrowserWindow(void)
00257 {
00258   PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00259   PtCallbackList_t  *cb;
00260   PtCallbackInfo_t  cbinfo;
00261 
00262   if (!moz->destroy_cb)
00263       return NS_OK;
00264 
00265   cb = moz->destroy_cb;
00266   memset(&cbinfo, 0, sizeof(cbinfo));
00267   cbinfo.reason = Pt_CB_MOZ_DESTROY;
00268   PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
00269 
00270   return NS_OK;
00271 }
00272 
00273 NS_IMETHODIMP
00274 EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
00275 {
00276        PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00277        PtCallbackList_t  *cb;
00278        PtCallbackInfo_t  cbinfo;
00279        PtMozillaNewAreaCb_t resize;
00280 
00281        if (!moz->resize_cb)
00282               return NS_OK;
00283 
00284        cb = moz->resize_cb;
00285        memset(&cbinfo, 0, sizeof(cbinfo));
00286        cbinfo.reason = Pt_CB_MOZ_NEW_AREA;
00287        resize.flags = Pt_MOZ_NEW_AREA_SET_SIZE;
00288        resize.area.size.w = aCX;
00289        resize.area.size.h = aCY;
00290        cbinfo.cbdata = &resize;
00291        PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
00292   return NS_OK;
00293 }
00294 
00295 NS_IMETHODIMP
00296 EmbedWindow::ShowAsModal(void)
00297 {
00298   return NS_ERROR_FAILURE;
00299 }
00300 
00301 NS_IMETHODIMP
00302 EmbedWindow::IsWindowModal(PRBool *_retval)
00303 {
00304   *_retval = PR_FALSE;
00305   return NS_OK;
00306 }
00307 
00308 NS_IMETHODIMP
00309 EmbedWindow::ExitModalEventLoop(nsresult aStatus)
00310 {
00311   return NS_OK;
00312 }
00313 
00314 // nsIWebBrowserChromeFocus
00315 
00316 NS_IMETHODIMP
00317 EmbedWindow::FocusNextElement()
00318 {
00319   PtContainerFocusNext(mOwner->mOwningWidget, NULL);
00320   return NS_OK;
00321 }
00322 
00323 NS_IMETHODIMP
00324 EmbedWindow::FocusPrevElement()
00325 {
00326   PtContainerFocusPrev(mOwner->mOwningWidget, NULL);
00327   return NS_OK;
00328 }
00329 
00330 // nsIEmbeddingSiteWindow
00331 
00332 NS_IMETHODIMP
00333 EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
00334                         PRInt32 aCX, PRInt32 aCY)
00335 {
00336   PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00337   PtCallbackList_t  *cb;
00338   PtCallbackInfo_t  cbinfo;
00339   PtMozillaNewAreaCb_t  resize;
00340 
00341   nsresult  rv = NS_ERROR_INVALID_ARG;
00342   if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
00343       (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
00344      nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
00345     rv =  mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE);
00346   }
00347   else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
00348     //
00349     // This position should never be called because it gets the
00350     // PtRawDrawContainer under the PtMozilla widget out of sync with
00351     // the PtMozilla widget. In the past with mozserver the position
00352     // synchronizing in PtMozilla.cpp's mozilla_extent() function was enough,
00353     // but with kwww it does not wait as long to realize PtMozilla, so we need
00354     // this position setting commented out. This fixes problems when a new win-
00355     // dow is opened and there is a large position offset to the actual content.
00356     //
00357     //rv =  mBaseWindow->SetPosition(aX, aY);
00358   }
00359   else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
00360          nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
00361     rv =  mBaseWindow->SetSize(aCX, aCY, PR_TRUE);
00362   }
00363        return rv;
00364 
00365   if (!moz->resize_cb)
00366       return NS_OK;
00367 
00368   cb = moz->resize_cb;
00369   memset(&cbinfo, 0, sizeof(cbinfo));
00370   cbinfo.reason = Pt_CB_MOZ_NEW_AREA;
00371   cbinfo.cbdata = &resize;
00372 
00373   memset(&resize, 0, sizeof(PtMozillaNewAreaCb_t));
00374 
00375   if( aCX==0 && aCY==0 )
00376     resize.flags = Pt_MOZ_NEW_AREA_SET_POSITION;
00377   else 
00378     resize.flags = Pt_MOZ_NEW_AREA_SET_AREA;
00379 
00380   resize.area.pos.x = aX;
00381   resize.area.pos.y = aY;
00382   resize.area.size.w = aCX;
00383   resize.area.size.h = aCY;
00384 
00385   PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
00386 
00387   return NS_OK;
00388 }
00389 
00390 NS_IMETHODIMP
00391 EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX,
00392                         PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
00393 {
00394   if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
00395       (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
00396                nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
00397     return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY);
00398   }
00399   else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
00400     return mBaseWindow->GetPosition(aX, aY);
00401   }
00402   else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
00403                    nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
00404     return mBaseWindow->GetSize(aCX, aCY);
00405   }
00406   return NS_ERROR_INVALID_ARG;
00407 }
00408 
00409 NS_IMETHODIMP
00410 EmbedWindow::SetFocus(void)
00411 {
00412   // XXX might have to do more here.
00413   return mBaseWindow->SetFocus();
00414 }
00415 
00416 NS_IMETHODIMP
00417 EmbedWindow::GetTitle(PRUnichar **aTitle)
00418 {
00419   *aTitle = ToNewUnicode(mTitle);
00420   return NS_OK;
00421 }
00422 
00423 NS_IMETHODIMP
00424 EmbedWindow::SetTitle(const PRUnichar *aTitle)
00425 {
00426   PtMozillaWidget_t   *moz = (PtMozillaWidget_t *)mOwner->mOwningWidget;
00427   PtCallbackList_t  *cb;
00428   PtCallbackInfo_t  cbinfo;
00429   PtMozillaInfoCb_t   info;
00430   nsString mTitleString(aTitle);
00431   const char *str;
00432        int to_free = 0;
00433 
00434   mTitle = aTitle;
00435 
00436   if (!moz->info_cb)
00437     return NS_OK;
00438 
00439   memset(&cbinfo, 0, sizeof(cbinfo));
00440   cbinfo.cbdata = &info;
00441   cbinfo.reason = Pt_CB_MOZ_INFO;
00442   cb = moz->info_cb;
00443 
00444   info.type = Pt_MOZ_INFO_TITLE;
00445   info.status = 0;
00446 
00447        /* see if the title is empty */
00448        if( mTitleString.Length() == 0 ) {
00449               if( moz->EmbedRef->mURI.Length() > 0 ) {
00450                      str = ToNewCString( moz->EmbedRef->mURI );
00451                      to_free = 1;
00452                      }
00453               else {
00454                      str = " ";
00455                      }
00456               }
00457   else {
00458               NS_ConvertUCS2toUTF8 theUnicodeString( mTitleString );
00459               str = theUnicodeString.get( );
00460               }
00461 
00462   info.data = (char*) str;
00463   PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
00464 
00465   if( to_free ) nsMemory::Free( (void*)str );
00466 
00467   return NS_OK;
00468 }
00469 
00470 NS_IMETHODIMP
00471 EmbedWindow::GetSiteWindow(void **aSiteWindow)
00472 {
00473   PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
00474   *aSiteWindow = NS_STATIC_CAST(void *, ownerAsWidget);
00475   return NS_OK;
00476 }
00477 
00478 NS_IMETHODIMP
00479 EmbedWindow::GetVisibility(PRBool *aVisibility)
00480 {
00481   *aVisibility = mVisibility;
00482   return NS_OK;
00483 }
00484 
00485 NS_IMETHODIMP
00486 EmbedWindow::SetVisibility(PRBool aVisibility)
00487 {
00488   mVisibility = aVisibility;
00489   return NS_OK;
00490 }
00491 
00492 // nsITooltipListener
00493 
00494 NS_IMETHODIMP
00495 EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords,
00496                         const PRUnichar *aTipText)
00497 {
00498   nsAutoString tipText ( aTipText );
00499   const char* tipString = ToNewCString(tipText), *font = "TextFont08";
00500   PtArg_t args[10];
00501   PhRect_t extent;
00502   PhDim_t dim;
00503   PhPoint_t pos = {0, 0};
00504   int n = 0, w, h;
00505 
00506   if (sTipWindow)
00507     PtDestroyWidget(sTipWindow);
00508   
00509   // get the root origin for this content window
00510   nsCOMPtr<nsIWidget> mainWidget;
00511   mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget));
00512   PtWidget_t *window;
00513   window = NS_STATIC_CAST(PtWidget_t *, mainWidget->GetNativeData(NS_NATIVE_WINDOW));
00514 
00515   PgExtentText(&extent, NULL, font, tipString, 0);
00516   w = extent.lr.x - extent.ul.x + 1;
00517   h = extent.lr.y - extent.ul.y + 1;
00518 
00519   n = 0;
00520   if (window)
00521     PtGetAbsPosition( window, &pos.x, &pos.y);
00522   pos.x += aXCoords;
00523   pos.y += aYCoords + 10; /* we add 10 so that we don't position it right under the mouse */
00524        dim.w = w + 6; dim.h = h + 6;
00525   PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
00526   PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
00527        PtSetArg( &args[n++], Pt_ARG_REGION_OPAQUE,   Ph_EV_EXPOSE, Ph_EV_EXPOSE);
00528   sTipWindow = PtCreateWidget(PtRegion, Pt_NO_PARENT, n, args);
00529 
00530   n = 0;
00531   pos.x = pos.y = 0;
00532        dim.w = w; dim.h = h;
00533   PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
00534   PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
00535   PtSetArg(&args[n++], Pt_ARG_FLAGS, Pt_HIGHLIGHTED, -1 );
00536   PtSetArg(&args[n++], Pt_ARG_FILL_COLOR, Pg_BALLOONCOLOR, 0);
00537   PtSetArg(&args[n++], Pt_ARG_TEXT_FONT, font, 0);
00538   PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, tipString, 0);
00539   PtSetArg(&args[n++], Pt_ARG_BASIC_FLAGS, Pt_STATIC_GRADIENT | Pt_TOP_OUTLINE | Pt_LEFT_OUTLINE |
00540       Pt_RIGHT_OUTLINE | Pt_BOTTOM_OUTLINE, -1 );
00541   PtCreateWidget(PtLabel, sTipWindow, n, args);
00542 
00543   // realize the widget
00544   PtRealizeWidget(sTipWindow);
00545 
00546   nsMemory::Free( (void*)tipString );
00547 
00548   return NS_OK;
00549 }
00550 
00551 NS_IMETHODIMP
00552 EmbedWindow::OnHideTooltip(void)
00553 {
00554   if (sTipWindow)
00555     PtDestroyWidget(sTipWindow);
00556   sTipWindow = NULL;
00557   return NS_OK;
00558 }
00559 
00560 
00561 // nsIDNSListener
00562 
00563 #if 0
00564 
00565 /* void OnStartLookup (in nsISupports ctxt, in string hostname); */
00566 NS_IMETHODIMP EmbedWindow::OnStartLookup(nsISupports *ctxt, const char *hostname)
00567 {
00568     PtMozillaWidget_t       *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00569     PtCallbackList_t        *cb = NULL;
00570     PtCallbackInfo_t        cbinfo;
00571     PtMozillaNetStateCb_t   state;
00572     cbinfo.reason = Pt_CB_MOZ_NET_STATE;
00573     cbinfo.cbdata = &state;
00574     state.flags = 0;
00575     state.status = 0;
00576     state.url = (char *)hostname;
00577     char *statusMessage = "Resolving host name:";
00578     state.message = statusMessage;
00579     if( ( cb = moz->net_state_cb ) )
00580         PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
00581 
00582     return NS_OK;
00583 }
00584 
00585 /* [noscript] void OnFound (in nsISupports ctxt, in string hostname, in nsHostEntStar entry); */
00586 NS_IMETHODIMP EmbedWindow::OnFound(nsISupports *ctxt, const char *hostname, nsHostEnt * entry)
00587 {
00588     PtMozillaWidget_t       *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00589     PtCallbackList_t        *cb = NULL;
00590     PtCallbackInfo_t        cbinfo;
00591     PtMozillaNetStateCb_t   state;
00592 
00593     cbinfo.reason = Pt_CB_MOZ_NET_STATE;
00594     cbinfo.cbdata = &state;
00595     state.flags = 0;
00596     state.status = 0;
00597     state.url = (char *)hostname;
00598     char *statusMessage = "Opening connection:";
00599     state.message = statusMessage;
00600     if( ( cb = moz->net_state_cb ) )
00601         PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
00602 
00603     return NS_OK;
00604 }
00605 #endif
00606 
00607 /* void OnStopLookup (in nsISupports ctxt, in string hostname, in nsresult status); */
00608 NS_IMETHODIMP EmbedWindow::OnLookupComplete(nsICancelable *aRequest, nsIDNSRecord *aRecord, nsresult aStatus)
00609 {
00610     return NS_ERROR_NOT_IMPLEMENTED;
00611 }
00612 
00613 // nsIContextMenuListener
00614 
00615 NS_IMETHODIMP EmbedWindow::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
00616 {
00617     PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00618     PtCallbackList_t    *cb;
00619     PtCallbackInfo_t    cbinfo;
00620     PtMozillaContextCb_t    cmenu;
00621 
00622     if (!moz->context_cb)
00623         return NS_OK;
00624 
00625     cb = moz->context_cb;
00626     memset(&cbinfo, 0, sizeof(cbinfo));
00627     cbinfo.reason = Pt_CB_MOZ_CONTEXT;
00628     cbinfo.cbdata = &cmenu;
00629 
00630     memset(&cmenu, 0, sizeof(PtMozillaContextCb_t));
00631     if (aContextFlags & CONTEXT_NONE)
00632         cmenu.flags |= Pt_MOZ_CONTEXT_NONE;
00633     else if (aContextFlags & CONTEXT_LINK)
00634         cmenu.flags |= Pt_MOZ_CONTEXT_LINK;
00635     else if (aContextFlags & CONTEXT_IMAGE)
00636         cmenu.flags |= Pt_MOZ_CONTEXT_IMAGE;
00637     else if (aContextFlags & CONTEXT_DOCUMENT)
00638         cmenu.flags |= Pt_MOZ_CONTEXT_DOCUMENT;
00639     else if (aContextFlags & CONTEXT_TEXT)
00640         cmenu.flags |= Pt_MOZ_CONTEXT_TEXT;
00641     else if (aContextFlags & CONTEXT_INPUT)
00642         cmenu.flags |= Pt_MOZ_CONTEXT_INPUT;
00643 
00644     nsCOMPtr<nsIDOMMouseEvent> mouseEvent (do_QueryInterface( aEvent ));
00645     if(!mouseEvent) return NS_OK;
00646     mouseEvent->GetScreenX( &cmenu.x );
00647     mouseEvent->GetScreenY( &cmenu.y );
00648 
00649     PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
00650 
00651     if( aContextFlags & CONTEXT_IMAGE )
00652     {
00653               /* store the url we clicked on */
00654               nsAutoString rightClickUrl;
00655 
00656         // Get the IMG SRC
00657         nsresult rv = NS_OK;
00658         nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv));
00659         if(NS_FAILED(rv)) return NS_OK;
00660 
00661         rv = imgElement->GetSrc(rightClickUrl);
00662 
00663               if( moz->rightClickUrl_image ) free( moz->rightClickUrl_image );
00664 
00665         if(NS_FAILED(rv))  moz->rightClickUrl_image = NULL;
00666               else moz->rightClickUrl_image = ToNewCString(rightClickUrl);
00667     }
00668 
00669               if( aContextFlags & CONTEXT_LINK )
00670     {
00671                             /* CONTEXT_IMAGE|CONTEXT_LINK is set for an <IMG>  with an <A> as an ancestor */
00672                             if( aContextFlags & CONTEXT_IMAGE ) {
00673                                    nsIDOMNode *parent;
00674                                    aNode->GetParentNode( &parent );
00675                                    if( parent ) aNode = parent;
00676                                    }
00677 
00678               /* store the url we clicked on */
00679               nsAutoString rightClickUrl;
00680 
00681         nsresult rv = NS_OK;
00682         nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv));
00683 
00684         if(NS_FAILED(rv)) return NS_OK;
00685 
00686         // Note that this string is in UCS2 format
00687         rv = linkElement->GetHref( rightClickUrl );
00688 
00689                             if( moz->rightClickUrl_link ) free( moz->rightClickUrl_link );
00690 
00691         if(NS_FAILED(rv)) moz->rightClickUrl_link = NULL;
00692                             else moz->rightClickUrl_link = ToNewCString(rightClickUrl);
00693     }
00694 
00695     return NS_OK;
00696 }
00697 
00698 
00699 // nsIInterfaceRequestor
00700 
00701 NS_IMETHODIMP
00702 EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr)
00703 {
00704   nsresult rv;
00705   
00706   rv = QueryInterface(aIID, aInstancePtr);
00707 
00708   // pass it up to the web browser object
00709   if (NS_FAILED(rv) || !*aInstancePtr) {
00710     nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(mWebBrowser);
00711     return ir->GetInterface(aIID, aInstancePtr);
00712   }
00713 
00714   return rv;
00715 }
00716 
00717