1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: Mozilla-sample-code 1.0
4
* Copyright (c) 2002 Netscape Communications Corporation and
7
* Permission is hereby granted, free of charge, to any person obtaining a
8
* copy of this Mozilla sample software and associated documentation files
9
* (the "Software"), to deal in the Software without restriction, including
10
* without limitation the rights to use, copy, modify, merge, publish,
11
* distribute, sublicense, and/or sell copies of the Software, and to permit
12
* persons to whom the Software is furnished to do so, subject to the
13
* following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
* DEALINGS IN THE SOFTWARE.
28
* Adam Lock <adamlock@netscape.com>
30
* ***** END LICENSE BLOCK ***** */
33
//#include "nsIGenericFactory.h"
34
#include "nsIComponentManager.h"
35
#include "nsXPIDLString.h"
37
#include "nsIWebProgress.h"
38
#include "nsIDocShellTreeItem.h"
39
#include "nsIDOMWindow.h"
40
#include "nsIDOMWindowInternal.h"
41
#include "nsIInterfaceRequestor.h"
42
#include "nsIInterfaceRequestorUtils.h"
43
#include "nsIURIContentListener.h"
44
#include "nsCWebBrowser.h"
47
#include "GeckoContainer.h"
51
GeckoContainer::GeckoContainer(GeckoContainerUI *pUI, const char *aRole) :
53
mNativeWindow(nsnull),
55
mIsChromeContainer(PR_FALSE),
56
mIsURIContentListener(PR_TRUE)
58
NS_ASSERTION(mUI, "No GeckoContainerUI! How do you expect this to work???");
63
GeckoContainer::~GeckoContainer()
68
nsresult GeckoContainer::CreateBrowser(PRInt32 aX, PRInt32 aY,
69
PRInt32 aCX, PRInt32 aCY, nativeWindow aParent,
70
nsIWebBrowser **aBrowser)
72
NS_ENSURE_ARG_POINTER(aBrowser);
76
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
77
if (!mWebBrowser || NS_FAILED(rv))
78
return NS_ERROR_FAILURE;
80
mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this));
82
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
85
nsIDocShellTreeItem::typeChromeWrapper :
86
nsIDocShellTreeItem::typeContentWrapper);
88
nsCOMPtr<nsIBaseWindow> browserBaseWindow = do_QueryInterface(mWebBrowser);
90
mNativeWindow = aParent;
93
return NS_ERROR_FAILURE;
95
browserBaseWindow->InitWindow( mNativeWindow,
98
browserBaseWindow->Create();
100
nsCOMPtr<nsIWebProgressListener> listener(NS_STATIC_CAST(nsIWebProgressListener*, this));
101
nsCOMPtr<nsIWeakReference> thisListener(do_GetWeakReference(listener));
102
(void)mWebBrowser->AddWebBrowserListener(thisListener,
103
NS_GET_IID(nsIWebProgressListener));
105
if (mIsURIContentListener)
106
mWebBrowser->SetParentURIContentListener(NS_STATIC_CAST(nsIURIContentListener *, this));
109
// The window has been created. Now register for history notifications
110
// mWebBrowser->AddWebBrowserListener(thisListener, NS_GET_IID(nsISHistoryListener));
114
*aBrowser = mWebBrowser;
115
NS_ADDREF(*aBrowser);
118
return NS_ERROR_FAILURE;
122
void GeckoContainer::ContentFinishedLoading()
124
// if it was a chrome window and no one has already specified a size,
126
if (mWebBrowser && !mSizeSet &&
127
(mChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)) {
128
nsCOMPtr<nsIDOMWindow> contentWin;
129
mWebBrowser->GetContentDOMWindow(getter_AddRefs(contentWin));
131
contentWin->SizeToContent();
132
mUI->ShowWindow(PR_TRUE);
136
//*****************************************************************************
137
// GeckoContainer::nsISupports
138
//*****************************************************************************
140
NS_IMPL_ADDREF(GeckoContainer)
141
NS_IMPL_RELEASE(GeckoContainer)
143
NS_INTERFACE_MAP_BEGIN(GeckoContainer)
144
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome)
145
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
146
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
147
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus)
148
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow)
149
NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow2)
150
NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener) // optional
151
NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
152
NS_INTERFACE_MAP_ENTRY(nsIObserver)
153
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
154
NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener2)
155
NS_INTERFACE_MAP_ENTRY(nsITooltipListener)
156
NS_INTERFACE_MAP_ENTRY(nsIGeckoContainer)
160
//*****************************************************************************
161
// GeckoContainer::nsIGeckoContainer
162
//*****************************************************************************
164
NS_IMETHODIMP GeckoContainer::GetRole(nsACString &aRole)
170
NS_IMETHODIMP GeckoContainer::GetContainerUI(GeckoContainerUI **pUI)
176
//*****************************************************************************
177
// GeckoContainer::nsIInterfaceRequestor
178
//*****************************************************************************
180
NS_IMETHODIMP GeckoContainer::GetInterface(const nsIID &aIID, void** aInstancePtr)
182
NS_ENSURE_ARG_POINTER(aInstancePtr);
185
if (aIID.Equals(NS_GET_IID(nsIDOMWindow)))
189
return mWebBrowser->GetContentDOMWindow((nsIDOMWindow **) aInstancePtr);
191
return NS_ERROR_NOT_INITIALIZED;
193
return QueryInterface(aIID, aInstancePtr);
196
//*****************************************************************************
197
// GeckoContainer::nsIWebBrowserChrome
198
//*****************************************************************************
200
NS_IMETHODIMP GeckoContainer::SetStatus(PRUint32 aType, const PRUnichar* aStatus)
202
mUI->UpdateStatusBarText(aStatus);
206
NS_IMETHODIMP GeckoContainer::GetWebBrowser(nsIWebBrowser** aWebBrowser)
208
NS_ENSURE_ARG_POINTER(aWebBrowser);
209
*aWebBrowser = mWebBrowser;
210
NS_IF_ADDREF(*aWebBrowser);
214
NS_IMETHODIMP GeckoContainer::SetWebBrowser(nsIWebBrowser* aWebBrowser)
216
mWebBrowser = aWebBrowser;
220
NS_IMETHODIMP GeckoContainer::GetChromeFlags(PRUint32* aChromeMask)
222
*aChromeMask = mChromeFlags;
226
NS_IMETHODIMP GeckoContainer::SetChromeFlags(PRUint32 aChromeMask)
228
mChromeFlags = aChromeMask;
232
NS_IMETHODIMP GeckoContainer::DestroyBrowserWindow(void)
239
// IN: The desired browser client area dimensions.
240
NS_IMETHODIMP GeckoContainer::SizeBrowserTo(PRInt32 aWidth, PRInt32 aHeight)
242
/* This isn't exactly correct: we're setting the whole window to
243
the size requested for the browser. At time of writing, though,
244
it's fine and useful for winEmbed's purposes. */
245
mUI->SizeTo(aWidth, aHeight);
251
NS_IMETHODIMP GeckoContainer::ShowAsModal(void)
253
/* if (mDependentParent)
254
mUI->EnableChromeWindow(mDependentParent, PR_FALSE);
256
mContinueModalLoop = PR_TRUE;
257
mUI->RunEventLoop(mContinueModalLoop);
259
if (mDependentParent)
260
mUI->EnableChromeWindow(mDependentParent, PR_TRUE);
265
NS_IMETHODIMP GeckoContainer::IsWindowModal(PRBool *_retval)
268
return NS_ERROR_NOT_IMPLEMENTED;
271
NS_IMETHODIMP GeckoContainer::ExitModalEventLoop(nsresult aStatus)
273
mContinueModalLoop = PR_FALSE;
277
//*****************************************************************************
278
// GeckoContainer::nsIWebBrowserChromeFocus
279
//*****************************************************************************
281
NS_IMETHODIMP GeckoContainer::FocusNextElement()
283
return NS_ERROR_NOT_IMPLEMENTED;
286
NS_IMETHODIMP GeckoContainer::FocusPrevElement()
288
return NS_ERROR_NOT_IMPLEMENTED;
291
//*****************************************************************************
292
// GeckoContainer::nsIWebProgressListener
293
//*****************************************************************************
295
NS_IMETHODIMP GeckoContainer::OnProgressChange(nsIWebProgress *progress, nsIRequest *request,
296
PRInt32 curSelfProgress, PRInt32 maxSelfProgress,
297
PRInt32 curTotalProgress, PRInt32 maxTotalProgress)
299
mUI->UpdateProgress(curTotalProgress, maxTotalProgress);
303
NS_IMETHODIMP GeckoContainer::OnStateChange(nsIWebProgress *progress, nsIRequest *request,
304
PRUint32 progressStateFlags, nsresult status)
306
if ((progressStateFlags & STATE_START) && (progressStateFlags & STATE_IS_DOCUMENT))
308
mUI->UpdateBusyState(PR_TRUE);
311
if ((progressStateFlags & STATE_STOP) && (progressStateFlags & STATE_IS_DOCUMENT))
313
mUI->UpdateBusyState(PR_FALSE);
314
mUI->UpdateProgress(0, 100);
315
mUI->UpdateStatusBarText(nsnull);
316
ContentFinishedLoading();
323
NS_IMETHODIMP GeckoContainer::OnLocationChange(nsIWebProgress* aWebProgress,
324
nsIRequest* aRequest,
327
PRBool isSubFrameLoad = PR_FALSE; // Is this a subframe load
330
nsCOMPtr<nsIDOMWindow> domWindow;
331
nsCOMPtr<nsIDOMWindow> topDomWindow;
332
aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
335
// Get root domWindow
336
domWindow->GetTop(getter_AddRefs(topDomWindow));
338
if (domWindow != topDomWindow)
339
isSubFrameLoad = PR_TRUE;
342
mUI->UpdateCurrentURI();
347
GeckoContainer::OnStatusChange(nsIWebProgress* aWebProgress,
348
nsIRequest* aRequest,
350
const PRUnichar* aMessage)
352
mUI->UpdateStatusBarText(aMessage);
359
GeckoContainer::OnSecurityChange(nsIWebProgress *aWebProgress,
360
nsIRequest *aRequest,
367
//*****************************************************************************
368
// GeckoContainer::nsIEmbeddingSiteWindow
369
//*****************************************************************************
371
NS_IMETHODIMP GeckoContainer::SetDimensions(PRUint32 aFlags, PRInt32 x, PRInt32 y, PRInt32 cx, PRInt32 cy)
373
return NS_ERROR_NOT_IMPLEMENTED;
376
NS_IMETHODIMP GeckoContainer::GetDimensions(PRUint32 aFlags, PRInt32 *x, PRInt32 *y, PRInt32 *cx, PRInt32 *cy)
378
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION)
383
if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER ||
384
aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)
389
return NS_ERROR_NOT_IMPLEMENTED;
392
/* void setFocus (); */
393
NS_IMETHODIMP GeckoContainer::SetFocus()
399
/* attribute wstring title; */
400
NS_IMETHODIMP GeckoContainer::GetTitle(PRUnichar * *aTitle)
402
NS_ENSURE_ARG_POINTER(aTitle);
406
return NS_ERROR_NOT_IMPLEMENTED;
408
NS_IMETHODIMP GeckoContainer::SetTitle(const PRUnichar * aTitle)
410
return NS_ERROR_NOT_IMPLEMENTED;
413
/* attribute boolean visibility; */
414
NS_IMETHODIMP GeckoContainer::GetVisibility(PRBool * aVisibility)
416
NS_ENSURE_ARG_POINTER(aVisibility);
417
*aVisibility = PR_TRUE;
420
NS_IMETHODIMP GeckoContainer::SetVisibility(PRBool aVisibility)
425
/* attribute nativeSiteWindow siteWindow */
426
NS_IMETHODIMP GeckoContainer::GetSiteWindow(void * *aSiteWindow)
428
NS_ENSURE_ARG_POINTER(aSiteWindow);
430
*aSiteWindow = mNativeWindow;
434
//*****************************************************************************
435
// GeckoContainer::nsIEmbeddingSiteWindow2
436
//*****************************************************************************
438
NS_IMETHODIMP GeckoContainer::Blur()
444
//*****************************************************************************
445
// GeckoContainer::nsIObserver
446
//*****************************************************************************
448
NS_IMETHODIMP GeckoContainer::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
451
if (nsCRT::strcmp(aTopic, "profile-change-teardown") == 0)
453
// A profile change means death for this window
459
//*****************************************************************************
460
// GeckoContainer::nsIURIContentListener
461
//*****************************************************************************
463
/* boolean onStartURIOpen (in nsIURI aURI); */
464
NS_IMETHODIMP GeckoContainer::OnStartURIOpen(nsIURI *aURI, PRBool *_retval)
466
return NS_ERROR_NOT_IMPLEMENTED;
469
/* boolean doContent (in string aContentType, in boolean aIsContentPreferred, in nsIRequest aRequest, out nsIStreamListener aContentHandler); */
470
NS_IMETHODIMP GeckoContainer::DoContent(const char *aContentType, PRBool aIsContentPreferred, nsIRequest *aRequest, nsIStreamListener **aContentHandler, PRBool *_retval)
472
return NS_ERROR_NOT_IMPLEMENTED;
475
/* boolean isPreferred (in string aContentType, out string aDesiredContentType); */
476
NS_IMETHODIMP GeckoContainer::IsPreferred(const char *aContentType, char **aDesiredContentType, PRBool *_retval)
478
return NS_ERROR_NOT_IMPLEMENTED;
481
/* boolean canHandleContent (in string aContentType, in boolean aIsContentPreferred, out string aDesiredContentType); */
482
NS_IMETHODIMP GeckoContainer::CanHandleContent(const char *aContentType, PRBool aIsContentPreferred, char **aDesiredContentType, PRBool *_retval)
484
return NS_ERROR_NOT_IMPLEMENTED;
487
/* attribute nsISupports loadCookie; */
488
NS_IMETHODIMP GeckoContainer::GetLoadCookie(nsISupports * *aLoadCookie)
490
return NS_ERROR_NOT_IMPLEMENTED;
492
NS_IMETHODIMP GeckoContainer::SetLoadCookie(nsISupports * aLoadCookie)
494
return NS_ERROR_NOT_IMPLEMENTED;
497
/* attribute nsIURIContentListener parentContentListener; */
498
NS_IMETHODIMP GeckoContainer::GetParentContentListener(nsIURIContentListener * *aParentContentListener)
500
return NS_ERROR_NOT_IMPLEMENTED;
502
NS_IMETHODIMP GeckoContainer::SetParentContentListener(nsIURIContentListener * aParentContentListener)
504
return NS_ERROR_NOT_IMPLEMENTED;
507
//*****************************************************************************
508
// GeckoContainer::nsIContextMenuListener2
509
//*****************************************************************************
511
/* void onShowContextMenu (in unsigned long aContextFlags, in nsIContextMenuInfo aUtils); */
512
NS_IMETHODIMP GeckoContainer::OnShowContextMenu(PRUint32 aContextFlags, nsIContextMenuInfo *aContextMenuInfo)
514
mUI->ShowContextMenu(aContextFlags, aContextMenuInfo);
519
//*****************************************************************************
520
// GeckoContainer::nsITooltipListener
521
//*****************************************************************************
523
/* void OnShowTooltip (in long aXCoords, in long aYCoords, in wstring aTipText); */
524
NS_IMETHODIMP GeckoContainer::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText)
526
mUI->ShowTooltip(aXCoords, aYCoords, aTipText);
530
/* void OnHideTooltip (); */
531
NS_IMETHODIMP GeckoContainer::OnHideTooltip()