Bug 454558 Null check missing in nsGNOMEShellService::GetShouldCheckDefaultBrowser...
[wine-gecko.git] / embedding / browser / photon / src / EmbedWindow.cpp
blob29edd8cf2304480561d4578725e4150b78c5c56a
1 /*
2 * vim:ts=2:et:sw=2
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Christopher Blizzard.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Christopher Blizzard <blizzard@mozilla.org>
26 * Brian Edmond <briane@qnx.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
41 #include <nsIDocShell.h>
42 #include <nsIWebProgress.h>
43 #include <nsIURI.h>
44 #include "nsIWidget.h"
46 // for do_GetInterface
47 #include <nsIInterfaceRequestor.h>
48 #include <nsIInterfaceRequestorUtils.h>
49 #include <nsIWebBrowserPersist.h>
50 // for do_CreateInstance
51 #include <nsIComponentManager.h>
52 #include "nsIWebProgressListener.h"
53 #include "nsIDOMHTMLImageElement.h"
55 #include <nsCWebBrowser.h>
56 #include <nsIComponentManager.h>
57 #include <nsIDocShellTreeItem.h>
58 #include <nsILocalFile.h>
59 #include <nsString.h>
60 #include "nsReadableUtils.h"
62 #include "EmbedWindow.h"
63 #include "EmbedPrivate.h"
65 #include "PtMozilla.h"
67 PtWidget_t *EmbedWindow::sTipWindow = nsnull;
69 EmbedWindow::EmbedWindow(void)
71 NS_INIT_ISUPPORTS();
72 mOwner = nsnull;
73 mVisibility = PR_FALSE;
74 mIsModal = PR_FALSE;
77 EmbedWindow::~EmbedWindow(void)
79 ExitModalEventLoop(PR_FALSE);
82 nsresult
83 EmbedWindow::Init(EmbedPrivate *aOwner)
85 // save our owner for later
86 mOwner = aOwner;
88 // create our nsIWebBrowser object and set up some basic defaults.
89 mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID);
90 if (!mWebBrowser)
91 return NS_ERROR_FAILURE;
93 mWebBrowser->SetContainerWindow(static_cast<nsIWebBrowserChrome *>(this));
95 // get the doc shel for cut/copy/paste
96 //mRootDocShell = do_GetInterface(mWebBrowser);
98 nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mWebBrowser);
99 item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
101 return NS_OK;
104 nsresult
105 EmbedWindow::CreateWindow(void)
107 nsresult rv;
108 PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
110 // Get the base window interface for the web browser object and
111 // create the window.
112 mBaseWindow = do_QueryInterface(mWebBrowser);
113 rv = mBaseWindow->InitWindow(ownerAsWidget,
114 nsnull,
115 0, 0,
116 ownerAsWidget->area.size.w,
117 ownerAsWidget->area.size.h);
118 if (NS_FAILED(rv))
119 return rv;
121 rv = mBaseWindow->Create();
122 if (NS_FAILED(rv))
123 return rv;
125 return NS_OK;
128 void
129 EmbedWindow::ReleaseChildren(void)
131 ExitModalEventLoop(PR_FALSE);
133 mBaseWindow->Destroy();
134 mBaseWindow = 0;
135 mWebBrowser = 0;
138 // nsISupports
140 NS_IMPL_ADDREF(EmbedWindow)
141 NS_IMPL_RELEASE(EmbedWindow)
143 NS_INTERFACE_MAP_BEGIN(EmbedWindow)
144 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
145 NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
146 NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
147 NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
148 NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
149 NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener)
150 NS_INTERFACE_MAP_ENTRY(nsIDNSListener)
151 NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
152 NS_INTERFACE_MAP_END
154 // nsIWebBrowserChrome
156 NS_IMETHODIMP
157 EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus)
159 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
160 PtCallbackList_t *cb;
161 PtCallbackInfo_t cbinfo;
162 PtMozillaInfoCb_t info;
163 nsAutoString Text ( aStatus );
164 int type = 0;
166 switch (aStatusType)
168 case STATUS_SCRIPT:
169 type = Pt_MOZ_INFO_JSSTATUS;
170 break;
171 case STATUS_SCRIPT_DEFAULT:
172 return NS_OK;
173 break;
174 case STATUS_LINK:
175 type = Pt_MOZ_INFO_LINK;
176 break;
177 default:
178 return NS_OK;
179 break;
182 if (!moz->info_cb)
183 return NS_OK;
185 memset(&cbinfo, 0, sizeof(cbinfo));
186 cbinfo.cbdata = &info;
187 cbinfo.reason = Pt_CB_MOZ_INFO;
188 cb = moz->info_cb;
190 info.type = type;
191 info.status = 0;
192 const char* status = ToNewCString(Text);
193 info.data = (char *)status;
194 PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
196 nsMemory::Free( (void*)status );
198 return NS_OK;
202 EmbedWindow::SaveAs(char *fname, char *dirname)
204 nsresult rv;
206 nsCOMPtr<nsIWebBrowserPersist> persist(do_GetInterface(mWebBrowser, &rv));
207 if (NS_FAILED(rv)) return rv;
209 nsCOMPtr<nsILocalFile> file;
210 NS_NewNativeLocalFile(nsDependentCString(fname), PR_TRUE, getter_AddRefs(file));
212 /* the nsIWebBrowserPersist wants a parent directory where to download images and other items related to the document */
213 /* we have to provide a directory, otherwise the current SaveDocument is marked as not finished and the next one is aborted */
214 nsCOMPtr<nsILocalFile> parentDirAsLocal;
215 rv = NS_NewNativeLocalFile(nsDependentCString( dirname ), PR_TRUE, getter_AddRefs(parentDirAsLocal));
216 if (NS_FAILED(rv)) return rv;
218 PRUint32 flags;
219 persist->GetPersistFlags( &flags );
220 if( !(flags & nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES ) ) persist->SetPersistFlags( nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES );
222 persist->SaveDocument(nsnull, file, parentDirAsLocal, nsnull, 0, 0);
223 return 0;
226 NS_IMETHODIMP
227 EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser)
229 *aWebBrowser = mWebBrowser;
230 NS_IF_ADDREF(*aWebBrowser);
231 return NS_OK;
234 NS_IMETHODIMP
235 EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser)
237 mWebBrowser = aWebBrowser;
238 return NS_OK;
241 NS_IMETHODIMP
242 EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags)
244 *aChromeFlags = mOwner->mChromeMask;
245 return NS_OK;
248 NS_IMETHODIMP
249 EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags)
251 mOwner->mChromeMask = aChromeFlags;
252 return NS_OK;
255 NS_IMETHODIMP
256 EmbedWindow::DestroyBrowserWindow(void)
258 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
259 PtCallbackList_t *cb;
260 PtCallbackInfo_t cbinfo;
262 if (!moz->destroy_cb)
263 return NS_OK;
265 cb = moz->destroy_cb;
266 memset(&cbinfo, 0, sizeof(cbinfo));
267 cbinfo.reason = Pt_CB_MOZ_DESTROY;
268 PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
270 return NS_OK;
273 NS_IMETHODIMP
274 EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
276 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
277 PtCallbackList_t *cb;
278 PtCallbackInfo_t cbinfo;
279 PtMozillaNewAreaCb_t resize;
281 if (!moz->resize_cb)
282 return NS_OK;
284 cb = moz->resize_cb;
285 memset(&cbinfo, 0, sizeof(cbinfo));
286 cbinfo.reason = Pt_CB_MOZ_NEW_AREA;
287 resize.flags = Pt_MOZ_NEW_AREA_SET_SIZE;
288 resize.area.size.w = aCX;
289 resize.area.size.h = aCY;
290 cbinfo.cbdata = &resize;
291 PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
292 return NS_OK;
295 NS_IMETHODIMP
296 EmbedWindow::ShowAsModal(void)
298 return NS_ERROR_FAILURE;
301 NS_IMETHODIMP
302 EmbedWindow::IsWindowModal(PRBool *_retval)
304 *_retval = PR_FALSE;
305 return NS_OK;
308 NS_IMETHODIMP
309 EmbedWindow::ExitModalEventLoop(nsresult aStatus)
311 return NS_OK;
314 // nsIWebBrowserChromeFocus
316 NS_IMETHODIMP
317 EmbedWindow::FocusNextElement()
319 PtContainerFocusNext(mOwner->mOwningWidget, NULL);
320 return NS_OK;
323 NS_IMETHODIMP
324 EmbedWindow::FocusPrevElement()
326 PtContainerFocusPrev(mOwner->mOwningWidget, NULL);
327 return NS_OK;
330 // nsIEmbeddingSiteWindow
332 NS_IMETHODIMP
333 EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY,
334 PRInt32 aCX, PRInt32 aCY)
336 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
337 PtCallbackList_t *cb;
338 PtCallbackInfo_t cbinfo;
339 PtMozillaNewAreaCb_t resize;
341 nsresult rv = NS_ERROR_INVALID_ARG;
342 if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
343 (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
344 nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
345 rv = mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE);
347 else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
348 rv = mBaseWindow->SetPosition(aX, aY);
350 else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
351 nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
352 rv = mBaseWindow->SetSize(aCX, aCY, PR_TRUE);
354 return rv;
356 if (!moz->resize_cb)
357 return NS_OK;
359 cb = moz->resize_cb;
360 memset(&cbinfo, 0, sizeof(cbinfo));
361 cbinfo.reason = Pt_CB_MOZ_NEW_AREA;
362 cbinfo.cbdata = &resize;
364 memset(&resize, 0, sizeof(PtMozillaNewAreaCb_t));
366 if( aCX==0 && aCY==0 )
367 resize.flags = Pt_MOZ_NEW_AREA_SET_POSITION;
368 else
369 resize.flags = Pt_MOZ_NEW_AREA_SET_AREA;
371 resize.area.pos.x = aX;
372 resize.area.pos.y = aY;
373 resize.area.size.w = aCX;
374 resize.area.size.h = aCY;
376 PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
378 return NS_OK;
381 NS_IMETHODIMP
382 EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX,
383 PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY)
385 if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION &&
386 (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
387 nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) {
388 return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY);
390 else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) {
391 return mBaseWindow->GetPosition(aX, aY);
393 else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER |
394 nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) {
395 return mBaseWindow->GetSize(aCX, aCY);
397 return NS_ERROR_INVALID_ARG;
400 NS_IMETHODIMP
401 EmbedWindow::SetFocus(void)
403 // XXX might have to do more here.
404 return mBaseWindow->SetFocus();
407 NS_IMETHODIMP
408 EmbedWindow::GetTitle(PRUnichar **aTitle)
410 *aTitle = ToNewUnicode(mTitle);
411 return NS_OK;
414 NS_IMETHODIMP
415 EmbedWindow::SetTitle(const PRUnichar *aTitle)
417 PtMozillaWidget_t *moz = (PtMozillaWidget_t *)mOwner->mOwningWidget;
418 PtCallbackList_t *cb;
419 PtCallbackInfo_t cbinfo;
420 PtMozillaInfoCb_t info;
421 nsString mTitleString(aTitle);
422 const char *str;
423 int to_free = 0;
425 mTitle = aTitle;
427 if (!moz->info_cb)
428 return NS_OK;
430 memset(&cbinfo, 0, sizeof(cbinfo));
431 cbinfo.cbdata = &info;
432 cbinfo.reason = Pt_CB_MOZ_INFO;
433 cb = moz->info_cb;
435 info.type = Pt_MOZ_INFO_TITLE;
436 info.status = 0;
438 /* see if the title is empty */
439 if( mTitleString.Length() == 0 ) {
440 if( moz->EmbedRef->mURI.Length() > 0 ) {
441 str = ToNewCString( moz->EmbedRef->mURI );
442 to_free = 1;
444 else {
445 str = " ";
448 else {
449 NS_ConvertUTF16toUTF8 theUnicodeString( mTitleString );
450 str = theUnicodeString.get( );
453 info.data = (char*) str;
454 PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
456 if( to_free ) nsMemory::Free( (void*)str );
458 return NS_OK;
461 NS_IMETHODIMP
462 EmbedWindow::GetSiteWindow(void **aSiteWindow)
464 PtWidget_t *ownerAsWidget = (PtWidget_t *)(mOwner->mOwningWidget);
465 *aSiteWindow = static_cast<void *>(ownerAsWidget);
466 return NS_OK;
469 NS_IMETHODIMP
470 EmbedWindow::GetVisibility(PRBool *aVisibility)
472 *aVisibility = mVisibility;
473 return NS_OK;
476 NS_IMETHODIMP
477 EmbedWindow::SetVisibility(PRBool aVisibility)
479 mVisibility = aVisibility;
480 return NS_OK;
483 // nsITooltipListener
485 NS_IMETHODIMP
486 EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords,
487 const PRUnichar *aTipText)
489 nsAutoString tipText ( aTipText );
490 const char* tipString = ToNewCString(tipText), *font = "TextFont08";
491 PtArg_t args[10];
492 PhRect_t extent;
493 PhDim_t dim;
494 PhPoint_t pos = {0, 0};
495 int n = 0, w, h;
497 if (sTipWindow)
498 PtDestroyWidget(sTipWindow);
500 // get the root origin for this content window
501 nsCOMPtr<nsIWidget> mainWidget;
502 mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget));
503 PtWidget_t *window;
504 window = static_cast<PtWidget_t *>(mainWidget->GetNativeData(NS_NATIVE_WINDOW));
506 PgExtentText(&extent, &pos, font, tipString, 0);
507 w = extent.lr.x - extent.ul.x + 1;
508 h = extent.lr.y - extent.ul.y + 1;
510 n = 0;
511 pos.x = aXCoords;
512 pos.y = aYCoords + 10; /* we add 10 so that we don't position it right under the mouse */
513 dim.w = w + 6; dim.h = h + 6;
514 PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
515 PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
516 PtSetArg( &args[n++], Pt_ARG_REGION_OPAQUE, Ph_EV_EXPOSE, Ph_EV_EXPOSE);
517 sTipWindow = PtCreateWidget(PtRegion, Pt_NO_PARENT, n, args);
519 n = 0;
520 pos.x = pos.y = 0;
521 dim.w = w; dim.h = h;
522 PtSetArg(&args[n++], Pt_ARG_POS, &pos, 0);
523 PtSetArg(&args[n++], Pt_ARG_DIM, &dim, 0);
524 PtSetArg(&args[n++], Pt_ARG_FLAGS, Pt_HIGHLIGHTED, -1 );
525 PtSetArg(&args[n++], Pt_ARG_FILL_COLOR, 0xfeffb1, 0);
526 PtSetArg(&args[n++], Pt_ARG_TEXT_FONT, font, 0);
527 PtSetArg(&args[n++], Pt_ARG_TEXT_STRING, tipString, 0);
528 PtSetArg(&args[n++], Pt_ARG_BASIC_FLAGS, Pt_STATIC_GRADIENT | Pt_TOP_OUTLINE | Pt_LEFT_OUTLINE |
529 Pt_RIGHT_OUTLINE | Pt_BOTTOM_OUTLINE, -1 );
530 PtCreateWidget(PtLabel, sTipWindow, n, args);
532 // realize the widget
533 PtRealizeWidget(sTipWindow);
535 nsMemory::Free( (void*)tipString );
537 return NS_OK;
540 NS_IMETHODIMP
541 EmbedWindow::OnHideTooltip(void)
543 if (sTipWindow)
544 PtDestroyWidget(sTipWindow);
545 sTipWindow = NULL;
546 return NS_OK;
550 // nsIDNSListener
552 #if 0
554 /* void OnStartLookup (in nsISupports ctxt, in string hostname); */
555 NS_IMETHODIMP EmbedWindow::OnStartLookup(nsISupports *ctxt, const char *hostname)
557 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
558 PtCallbackList_t *cb = NULL;
559 PtCallbackInfo_t cbinfo;
560 PtMozillaNetStateCb_t state;
561 cbinfo.reason = Pt_CB_MOZ_NET_STATE;
562 cbinfo.cbdata = &state;
563 state.flags = 0;
564 state.status = 0;
565 state.url = (char *)hostname;
566 char *statusMessage = "Resolving host name:";
567 state.message = statusMessage;
568 if( ( cb = moz->net_state_cb ) )
569 PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
571 return NS_OK;
574 /* [noscript] void OnFound (in nsISupports ctxt, in string hostname, in nsHostEntStar entry); */
575 NS_IMETHODIMP EmbedWindow::OnFound(nsISupports *ctxt, const char *hostname, nsHostEnt * entry)
577 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
578 PtCallbackList_t *cb = NULL;
579 PtCallbackInfo_t cbinfo;
580 PtMozillaNetStateCb_t state;
582 cbinfo.reason = Pt_CB_MOZ_NET_STATE;
583 cbinfo.cbdata = &state;
584 state.flags = 0;
585 state.status = 0;
586 state.url = (char *)hostname;
587 char *statusMessage = "Opening connection:";
588 state.message = statusMessage;
589 if( ( cb = moz->net_state_cb ) )
590 PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo);
592 return NS_OK;
594 #endif
596 /* void OnStopLookup (in nsISupports ctxt, in string hostname, in nsresult status); */
597 NS_IMETHODIMP EmbedWindow::OnLookupComplete(nsICancelable *aRequest, nsIDNSRecord *aRecord, nsresult aStatus)
599 return NS_ERROR_NOT_IMPLEMENTED;
602 // nsIContextMenuListener
604 NS_IMETHODIMP EmbedWindow::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode)
606 PtMozillaWidget_t *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
607 PtCallbackList_t *cb;
608 PtCallbackInfo_t cbinfo;
609 PtMozillaContextCb_t cmenu;
611 if (!moz->context_cb)
612 return NS_OK;
614 cb = moz->context_cb;
615 memset(&cbinfo, 0, sizeof(cbinfo));
616 cbinfo.reason = Pt_CB_MOZ_CONTEXT;
617 cbinfo.cbdata = &cmenu;
619 memset(&cmenu, 0, sizeof(PtMozillaContextCb_t));
620 if (aContextFlags & CONTEXT_NONE)
621 cmenu.flags |= Pt_MOZ_CONTEXT_NONE;
622 else if (aContextFlags & CONTEXT_LINK)
623 cmenu.flags |= Pt_MOZ_CONTEXT_LINK;
624 else if (aContextFlags & CONTEXT_IMAGE)
625 cmenu.flags |= Pt_MOZ_CONTEXT_IMAGE;
626 else if (aContextFlags & CONTEXT_DOCUMENT)
627 cmenu.flags |= Pt_MOZ_CONTEXT_DOCUMENT;
628 else if (aContextFlags & CONTEXT_TEXT)
629 cmenu.flags |= Pt_MOZ_CONTEXT_TEXT;
630 else if (aContextFlags & CONTEXT_INPUT)
631 cmenu.flags |= Pt_MOZ_CONTEXT_INPUT;
633 nsCOMPtr<nsIDOMMouseEvent> mouseEvent (do_QueryInterface( aEvent ));
634 if(!mouseEvent) return NS_OK;
635 mouseEvent->GetScreenX( &cmenu.x );
636 mouseEvent->GetScreenY( &cmenu.y );
638 PtInvokeCallbackList(cb, (PtWidget_t *)moz, &cbinfo);
640 if( aContextFlags & CONTEXT_IMAGE )
642 /* store the url we clicked on */
643 nsAutoString rightClickUrl;
645 // Get the IMG SRC
646 nsresult rv = NS_OK;
647 nsCOMPtr<nsIDOMHTMLImageElement> imgElement(do_QueryInterface(aNode, &rv));
648 if(NS_FAILED(rv)) return NS_OK;
650 rv = imgElement->GetSrc(rightClickUrl);
652 if( moz->rightClickUrl_image ) free( moz->rightClickUrl_image );
654 if(NS_FAILED(rv)) moz->rightClickUrl_image = NULL;
655 else moz->rightClickUrl_image = ToNewCString(rightClickUrl);
658 if( aContextFlags & CONTEXT_LINK )
660 /* CONTEXT_IMAGE|CONTEXT_LINK is set for an <IMG> with an <A> as an ancestor */
661 if( aContextFlags & CONTEXT_IMAGE ) {
662 nsIDOMNode *parent;
663 aNode->GetParentNode( &parent );
664 if( parent ) aNode = parent;
667 /* store the url we clicked on */
668 nsAutoString rightClickUrl;
670 nsresult rv = NS_OK;
671 nsCOMPtr<nsIDOMHTMLAnchorElement> linkElement(do_QueryInterface(aNode, &rv));
673 if(NS_FAILED(rv)) return NS_OK;
675 // Note that this string is in UCS2 format
676 rv = linkElement->GetHref( rightClickUrl );
678 if( moz->rightClickUrl_link ) free( moz->rightClickUrl_link );
680 if(NS_FAILED(rv)) moz->rightClickUrl_link = NULL;
681 else moz->rightClickUrl_link = ToNewCString(rightClickUrl);
684 return NS_OK;
688 // nsIInterfaceRequestor
690 NS_IMETHODIMP
691 EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr)
693 nsresult rv;
695 rv = QueryInterface(aIID, aInstancePtr);
697 // pass it up to the web browser object
698 if (NS_FAILED(rv) || !*aInstancePtr) {
699 nsCOMPtr<nsIInterfaceRequestor> ir = do_QueryInterface(mWebBrowser);
700 return ir->GetInterface(aIID, aInstancePtr);
703 return rv;