1 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=2 sw=2 et tw=80:
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
9 #include "nsContentTreeOwner.h"
10 #include "AppWindow.h"
12 // Interfaces needed to be included
13 #include "nsIDOMWindow.h"
14 #include "nsIDOMChromeWindow.h"
15 #include "nsIBrowserDOMWindow.h"
16 #include "nsIEmbeddingSiteWindow.h"
17 #include "nsIOpenWindowInfo.h"
18 #include "nsIPrompt.h"
19 #include "nsIAuthPrompt.h"
20 #include "nsIXULBrowserWindow.h"
21 #include "nsIPrincipal.h"
22 #include "nsIURIFixup.h"
23 #include "nsIWebNavigation.h"
24 #include "nsDocShellCID.h"
25 #include "nsIMIMEInfo.h"
26 #include "nsIWidget.h"
27 #include "nsWindowWatcher.h"
28 #include "mozilla/Components.h"
29 #include "mozilla/NullPrincipal.h"
30 #include "nsDocShell.h"
31 #include "nsDocShellLoadState.h"
32 #include "nsQueryActor.h"
34 #include "nsIScriptObjectPrincipal.h"
36 #include "mozilla/dom/Document.h"
37 #if defined(XP_MACOSX)
38 # include "nsThreadUtils.h"
41 #include "mozilla/Preferences.h"
42 #include "mozilla/dom/Element.h"
43 #include "mozilla/dom/ScriptSettings.h"
45 using namespace mozilla
;
47 //*****************************************************************************
48 //*** nsSiteWindow declaration
49 //*****************************************************************************
51 class nsSiteWindow
: public nsIEmbeddingSiteWindow
{
52 // nsSiteWindow shares a lifetime with nsContentTreeOwner, and proxies it's
53 // AddRef and Release calls to said object.
54 // When nsContentTreeOwner is destroyed, nsSiteWindow will be destroyed as
55 // well. nsContentTreeOwner is a friend class of nsSiteWindow such that it can
56 // call nsSiteWindow's destructor, which is private, as public destructors on
57 // reference counted classes are generally unsafe.
58 friend class nsContentTreeOwner
;
61 explicit nsSiteWindow(nsContentTreeOwner
* aAggregator
);
63 NS_DECL_ISUPPORTS_INHERITED
64 NS_DECL_NSIEMBEDDINGSITEWINDOW
67 virtual ~nsSiteWindow();
68 nsContentTreeOwner
* mAggregator
;
71 //*****************************************************************************
72 //*** nsContentTreeOwner: Object Management
73 //*****************************************************************************
75 nsContentTreeOwner::nsContentTreeOwner(bool fPrimary
)
76 : mAppWindow(nullptr), mPrimary(fPrimary
) {
77 // note if this fails, QI on nsIEmbeddingSiteWindow(2) will simply fail
78 mSiteWindow
= new nsSiteWindow(this);
81 nsContentTreeOwner::~nsContentTreeOwner() { delete mSiteWindow
; }
83 //*****************************************************************************
84 // nsContentTreeOwner::nsISupports
85 //*****************************************************************************
87 NS_IMPL_ADDREF(nsContentTreeOwner
)
88 NS_IMPL_RELEASE(nsContentTreeOwner
)
90 NS_INTERFACE_MAP_BEGIN(nsContentTreeOwner
)
91 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDocShellTreeOwner
)
92 NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner
)
93 NS_INTERFACE_MAP_ENTRY(nsIBaseWindow
)
94 NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome
)
95 NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor
)
96 NS_INTERFACE_MAP_ENTRY(nsIWindowProvider
)
97 // NOTE: This is using aggregation because there are some properties and
98 // method on nsIBaseWindow (which we implement) and on
99 // nsIEmbeddingSiteWindow (which we also implement) that have the same name.
100 // And it just so happens that we want different behavior for these methods
101 // and properties depending on the interface through which they're called
102 // (SetFocus() is a good example here). If it were not for that, we could
103 // ditch the aggregation and just deal with not being able to use NS_DECL_*
104 // macros for this stuff....
105 NS_INTERFACE_MAP_ENTRY_AGGREGATED(nsIEmbeddingSiteWindow
, mSiteWindow
)
108 //*****************************************************************************
109 // nsContentTreeOwner::nsIInterfaceRequestor
110 //*****************************************************************************
112 NS_IMETHODIMP
nsContentTreeOwner::GetInterface(const nsIID
& aIID
,
114 NS_ENSURE_ARG_POINTER(aSink
);
117 if (aIID
.Equals(NS_GET_IID(nsIPrompt
))) {
118 NS_ENSURE_STATE(mAppWindow
);
119 return mAppWindow
->GetInterface(aIID
, aSink
);
121 if (aIID
.Equals(NS_GET_IID(nsIAuthPrompt
))) {
122 NS_ENSURE_STATE(mAppWindow
);
123 return mAppWindow
->GetInterface(aIID
, aSink
);
125 if (aIID
.Equals(NS_GET_IID(nsIDocShellTreeItem
))) {
126 NS_ENSURE_STATE(mAppWindow
);
127 nsCOMPtr
<nsIDocShell
> shell
;
128 mAppWindow
->GetDocShell(getter_AddRefs(shell
));
129 if (shell
) return shell
->QueryInterface(aIID
, aSink
);
130 return NS_ERROR_FAILURE
;
133 if (aIID
.Equals(NS_GET_IID(nsIDOMWindow
)) ||
134 aIID
.Equals(NS_GET_IID(nsPIDOMWindowOuter
))) {
135 NS_ENSURE_STATE(mAppWindow
);
136 nsCOMPtr
<nsIDocShellTreeItem
> shell
;
137 mAppWindow
->GetPrimaryContentShell(getter_AddRefs(shell
));
139 nsCOMPtr
<nsIInterfaceRequestor
> thing(do_QueryInterface(shell
));
140 if (thing
) return thing
->GetInterface(aIID
, aSink
);
142 return NS_ERROR_FAILURE
;
145 if (aIID
.Equals(NS_GET_IID(nsIAppWindow
))) {
146 NS_ENSURE_STATE(mAppWindow
);
147 return mAppWindow
->QueryInterface(aIID
, aSink
);
150 return QueryInterface(aIID
, aSink
);
153 //*****************************************************************************
154 // nsContentTreeOwner::nsIDocShellTreeOwner
155 //*****************************************************************************
158 nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem
* aContentShell
,
160 NS_ENSURE_STATE(mAppWindow
);
161 return mAppWindow
->ContentShellAdded(aContentShell
, aPrimary
);
165 nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem
* aContentShell
) {
166 NS_ENSURE_STATE(mAppWindow
);
167 return mAppWindow
->ContentShellRemoved(aContentShell
);
171 nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem
** aShell
) {
172 NS_ENSURE_STATE(mAppWindow
);
173 return mAppWindow
->GetPrimaryContentShell(aShell
);
177 nsContentTreeOwner::RemoteTabAdded(nsIRemoteTab
* aTab
, bool aPrimary
) {
178 NS_ENSURE_STATE(mAppWindow
);
179 return mAppWindow
->RemoteTabAdded(aTab
, aPrimary
);
183 nsContentTreeOwner::RemoteTabRemoved(nsIRemoteTab
* aTab
) {
184 NS_ENSURE_STATE(mAppWindow
);
185 return mAppWindow
->RemoteTabRemoved(aTab
);
189 nsContentTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab
** aTab
) {
190 NS_ENSURE_STATE(mAppWindow
);
191 return mAppWindow
->GetPrimaryRemoteTab(aTab
);
195 nsContentTreeOwner::GetPrimaryContentSize(int32_t* aWidth
, int32_t* aHeight
) {
196 NS_ENSURE_STATE(mAppWindow
);
197 return mAppWindow
->GetPrimaryContentSize(aWidth
, aHeight
);
201 nsContentTreeOwner::SetPrimaryContentSize(int32_t aWidth
, int32_t aHeight
) {
202 NS_ENSURE_STATE(mAppWindow
);
203 return mAppWindow
->SetPrimaryContentSize(aWidth
, aHeight
);
207 nsContentTreeOwner::GetRootShellSize(int32_t* aWidth
, int32_t* aHeight
) {
208 NS_ENSURE_STATE(mAppWindow
);
209 return mAppWindow
->GetRootShellSize(aWidth
, aHeight
);
213 nsContentTreeOwner::SetRootShellSize(int32_t aWidth
, int32_t aHeight
) {
214 NS_ENSURE_STATE(mAppWindow
);
215 return mAppWindow
->SetRootShellSize(aWidth
, aHeight
);
218 NS_IMETHODIMP
nsContentTreeOwner::SizeShellTo(nsIDocShellTreeItem
* aShellItem
,
219 int32_t aCX
, int32_t aCY
) {
220 NS_ENSURE_STATE(mAppWindow
);
221 return mAppWindow
->SizeShellTo(aShellItem
, aCX
, aCY
);
225 nsContentTreeOwner::SetPersistence(bool aPersistPosition
, bool aPersistSize
,
226 bool aPersistSizeMode
) {
227 NS_ENSURE_STATE(mAppWindow
);
228 nsCOMPtr
<dom::Element
> docShellElement
= mAppWindow
->GetWindowDOMElement();
229 if (!docShellElement
) return NS_ERROR_FAILURE
;
231 nsAutoString persistString
;
232 docShellElement
->GetAttr(nsGkAtoms::persist
, persistString
);
234 bool saveString
= false;
238 index
= persistString
.Find("screenX");
239 if (!aPersistPosition
&& index
>= 0) {
240 persistString
.Cut(index
, 7);
242 } else if (aPersistPosition
&& index
< 0) {
243 persistString
.AppendLiteral(" screenX");
247 index
= persistString
.Find("screenY");
248 if (!aPersistPosition
&& index
>= 0) {
249 persistString
.Cut(index
, 7);
251 } else if (aPersistPosition
&& index
< 0) {
252 persistString
.AppendLiteral(" screenY");
256 index
= persistString
.Find("width");
257 if (!aPersistSize
&& index
>= 0) {
258 persistString
.Cut(index
, 5);
260 } else if (aPersistSize
&& index
< 0) {
261 persistString
.AppendLiteral(" width");
265 index
= persistString
.Find("height");
266 if (!aPersistSize
&& index
>= 0) {
267 persistString
.Cut(index
, 6);
269 } else if (aPersistSize
&& index
< 0) {
270 persistString
.AppendLiteral(" height");
274 index
= persistString
.Find("sizemode");
275 if (!aPersistSizeMode
&& (index
>= 0)) {
276 persistString
.Cut(index
, 8);
278 } else if (aPersistSizeMode
&& (index
< 0)) {
279 persistString
.AppendLiteral(" sizemode");
285 docShellElement
->SetAttribute(u
"persist"_ns
, persistString
, rv
);
292 nsContentTreeOwner::GetPersistence(bool* aPersistPosition
, bool* aPersistSize
,
293 bool* aPersistSizeMode
) {
294 NS_ENSURE_STATE(mAppWindow
);
295 nsCOMPtr
<dom::Element
> docShellElement
= mAppWindow
->GetWindowDOMElement();
296 if (!docShellElement
) return NS_ERROR_FAILURE
;
298 nsAutoString persistString
;
299 docShellElement
->GetAttr(nsGkAtoms::persist
, persistString
);
301 // data structure doesn't quite match the question, but it's close enough
302 // for what we want (since this method is never actually called...)
303 if (aPersistPosition
)
305 persistString
.Find("screenX") >= 0 || persistString
.Find("screenY") >= 0
310 persistString
.Find("width") >= 0 || persistString
.Find("height") >= 0
313 if (aPersistSizeMode
)
314 *aPersistSizeMode
= persistString
.Find("sizemode") >= 0 ? true : false;
320 nsContentTreeOwner::GetTabCount(uint32_t* aResult
) {
322 return mAppWindow
->GetTabCount(aResult
);
330 nsContentTreeOwner::GetHasPrimaryContent(bool* aResult
) {
331 NS_ENSURE_STATE(mAppWindow
);
332 return mAppWindow
->GetHasPrimaryContent(aResult
);
335 //*****************************************************************************
336 // nsContentTreeOwner::nsIWebBrowserChrome
337 //*****************************************************************************
339 NS_IMETHODIMP
nsContentTreeOwner::SetLinkStatus(const nsAString
& aStatusText
) {
340 NS_ENSURE_STATE(mAppWindow
);
342 nsCOMPtr
<nsIXULBrowserWindow
> xulBrowserWindow
;
343 mAppWindow
->GetXULBrowserWindow(getter_AddRefs(xulBrowserWindow
));
345 if (xulBrowserWindow
) {
346 xulBrowserWindow
->SetOverLink(aStatusText
);
352 NS_IMETHODIMP
nsContentTreeOwner::SetChromeFlags(uint32_t aChromeFlags
) {
353 NS_ENSURE_STATE(mAppWindow
);
354 return mAppWindow
->SetChromeFlags(aChromeFlags
);
357 NS_IMETHODIMP
nsContentTreeOwner::GetChromeFlags(uint32_t* aChromeFlags
) {
358 NS_ENSURE_STATE(mAppWindow
);
359 return mAppWindow
->GetChromeFlags(aChromeFlags
);
362 NS_IMETHODIMP
nsContentTreeOwner::ShowAsModal() {
363 NS_ENSURE_STATE(mAppWindow
);
364 return mAppWindow
->ShowModal();
367 NS_IMETHODIMP
nsContentTreeOwner::IsWindowModal(bool* _retval
) {
368 NS_ENSURE_STATE(mAppWindow
);
369 *_retval
= mAppWindow
->mContinueModalLoop
;
373 //*****************************************************************************
374 // nsContentTreeOwner::nsIBaseWindow
375 //*****************************************************************************
377 NS_IMETHODIMP
nsContentTreeOwner::InitWindow(nativeWindow aParentNativeWindow
,
378 nsIWidget
* parentWidget
, int32_t x
,
379 int32_t y
, int32_t cx
,
381 // Ignore wigdet parents for now. Don't think those are a vaild thing to
383 NS_ENSURE_SUCCESS(SetPositionAndSize(x
, y
, cx
, cy
, 0), NS_ERROR_FAILURE
);
388 NS_IMETHODIMP
nsContentTreeOwner::Destroy() {
389 NS_ENSURE_STATE(mAppWindow
);
390 return mAppWindow
->Destroy();
393 NS_IMETHODIMP
nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(
395 NS_ENSURE_STATE(mAppWindow
);
396 return mAppWindow
->GetUnscaledDevicePixelsPerCSSPixel(aScale
);
399 NS_IMETHODIMP
nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(
401 NS_ENSURE_STATE(mAppWindow
);
402 return mAppWindow
->GetDevicePixelsPerDesktopPixel(aScale
);
405 NS_IMETHODIMP
nsContentTreeOwner::SetPositionDesktopPix(int32_t aX
,
407 NS_ENSURE_STATE(mAppWindow
);
408 return mAppWindow
->SetPositionDesktopPix(aX
, aY
);
411 NS_IMETHODIMP
nsContentTreeOwner::SetPosition(int32_t aX
, int32_t aY
) {
412 NS_ENSURE_STATE(mAppWindow
);
413 return mAppWindow
->SetPosition(aX
, aY
);
416 NS_IMETHODIMP
nsContentTreeOwner::GetPosition(int32_t* aX
, int32_t* aY
) {
417 NS_ENSURE_STATE(mAppWindow
);
418 return mAppWindow
->GetPosition(aX
, aY
);
421 NS_IMETHODIMP
nsContentTreeOwner::SetSize(int32_t aCX
, int32_t aCY
,
423 NS_ENSURE_STATE(mAppWindow
);
424 return mAppWindow
->SetSize(aCX
, aCY
, aRepaint
);
427 NS_IMETHODIMP
nsContentTreeOwner::GetSize(int32_t* aCX
, int32_t* aCY
) {
428 NS_ENSURE_STATE(mAppWindow
);
429 return mAppWindow
->GetSize(aCX
, aCY
);
432 NS_IMETHODIMP
nsContentTreeOwner::SetPositionAndSize(int32_t aX
, int32_t aY
,
433 int32_t aCX
, int32_t aCY
,
435 NS_ENSURE_STATE(mAppWindow
);
436 return mAppWindow
->SetPositionAndSize(aX
, aY
, aCX
, aCY
, aFlags
);
439 NS_IMETHODIMP
nsContentTreeOwner::GetPositionAndSize(int32_t* aX
, int32_t* aY
,
442 NS_ENSURE_STATE(mAppWindow
);
443 return mAppWindow
->GetPositionAndSize(aX
, aY
, aCX
, aCY
);
446 NS_IMETHODIMP
nsContentTreeOwner::Repaint(bool aForce
) {
447 NS_ENSURE_STATE(mAppWindow
);
448 return mAppWindow
->Repaint(aForce
);
451 NS_IMETHODIMP
nsContentTreeOwner::GetParentWidget(nsIWidget
** aParentWidget
) {
452 NS_ENSURE_STATE(mAppWindow
);
453 return mAppWindow
->GetParentWidget(aParentWidget
);
456 NS_IMETHODIMP
nsContentTreeOwner::SetParentWidget(nsIWidget
* aParentWidget
) {
457 NS_ASSERTION(false, "You can't call this");
458 return NS_ERROR_NOT_IMPLEMENTED
;
461 NS_IMETHODIMP
nsContentTreeOwner::GetParentNativeWindow(
462 nativeWindow
* aParentNativeWindow
) {
463 NS_ENSURE_STATE(mAppWindow
);
464 return mAppWindow
->GetParentNativeWindow(aParentNativeWindow
);
467 NS_IMETHODIMP
nsContentTreeOwner::SetParentNativeWindow(
468 nativeWindow aParentNativeWindow
) {
469 NS_ASSERTION(false, "You can't call this");
470 return NS_ERROR_NOT_IMPLEMENTED
;
473 NS_IMETHODIMP
nsContentTreeOwner::GetNativeHandle(nsAString
& aNativeHandle
) {
474 NS_ENSURE_STATE(mAppWindow
);
475 return mAppWindow
->GetNativeHandle(aNativeHandle
);
478 NS_IMETHODIMP
nsContentTreeOwner::GetVisibility(bool* aVisibility
) {
479 NS_ENSURE_STATE(mAppWindow
);
480 return mAppWindow
->GetVisibility(aVisibility
);
483 NS_IMETHODIMP
nsContentTreeOwner::SetVisibility(bool aVisibility
) {
484 NS_ENSURE_STATE(mAppWindow
);
485 return mAppWindow
->SetVisibility(aVisibility
);
488 NS_IMETHODIMP
nsContentTreeOwner::GetEnabled(bool* aEnabled
) {
489 NS_ENSURE_STATE(mAppWindow
);
490 return mAppWindow
->GetEnabled(aEnabled
);
493 NS_IMETHODIMP
nsContentTreeOwner::SetEnabled(bool aEnable
) {
494 NS_ENSURE_STATE(mAppWindow
);
495 return mAppWindow
->SetEnabled(aEnable
);
498 NS_IMETHODIMP
nsContentTreeOwner::GetMainWidget(nsIWidget
** aMainWidget
) {
499 NS_ENSURE_ARG_POINTER(aMainWidget
);
500 NS_ENSURE_STATE(mAppWindow
);
502 *aMainWidget
= mAppWindow
->mWindow
;
503 NS_IF_ADDREF(*aMainWidget
);
508 NS_IMETHODIMP
nsContentTreeOwner::GetTitle(nsAString
& aTitle
) {
509 NS_ENSURE_STATE(mAppWindow
);
511 return mAppWindow
->GetTitle(aTitle
);
514 NS_IMETHODIMP
nsContentTreeOwner::SetTitle(const nsAString
& aTitle
) {
518 //*****************************************************************************
519 // nsContentTreeOwner: nsIWindowProvider
520 //*****************************************************************************
522 nsContentTreeOwner::ProvideWindow(
523 nsIOpenWindowInfo
* aOpenWindowInfo
, uint32_t aChromeFlags
,
524 bool aCalledFromJS
, bool aWidthSpecified
, nsIURI
* aURI
,
525 const nsAString
& aName
, const nsACString
& aFeatures
, bool aForceNoOpener
,
526 bool aForceNoReferrer
, nsDocShellLoadState
* aLoadState
, bool* aWindowIsNew
,
527 dom::BrowsingContext
** aReturn
) {
528 NS_ENSURE_ARG_POINTER(aOpenWindowInfo
);
530 RefPtr
<dom::BrowsingContext
> parent
= aOpenWindowInfo
->GetParent();
535 // Nothing to do here
540 nsCOMPtr
<nsIDocShell
> docshell
= parent
->GetDocShell();
541 nsCOMPtr
<nsIDocShellTreeOwner
> parentOwner
= do_GetInterface(docshell
);
543 SameCOMIdentity(parentOwner
, static_cast<nsIDocShellTreeOwner
*>(this)),
544 "Parent from wrong docshell tree?");
547 int32_t openLocation
= nsWindowWatcher::GetWindowOpenLocation(
548 parent
->GetDOMWindow(), aChromeFlags
, aCalledFromJS
, aWidthSpecified
,
549 aOpenWindowInfo
->GetIsForPrinting());
551 if (openLocation
!= nsIBrowserDOMWindow::OPEN_NEWTAB
&&
552 openLocation
!= nsIBrowserDOMWindow::OPEN_CURRENTWINDOW
&&
553 openLocation
!= nsIBrowserDOMWindow::OPEN_PRINT_BROWSER
) {
554 // Just open a window normally
558 nsCOMPtr
<mozIDOMWindowProxy
> domWin
;
559 mAppWindow
->GetWindowDOMWindow(getter_AddRefs(domWin
));
560 nsCOMPtr
<nsIDOMChromeWindow
> chromeWin
= do_QueryInterface(domWin
);
562 // Really odd... but whatever
563 NS_WARNING("AppWindow's DOMWindow is not a chrome window");
567 nsCOMPtr
<nsIBrowserDOMWindow
> browserDOMWin
;
568 chromeWin
->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin
));
569 if (!browserDOMWin
) {
573 *aWindowIsNew
= (openLocation
!= nsIBrowserDOMWindow::OPEN_CURRENTWINDOW
);
576 dom::AutoNoJSAPI nojsapi
;
578 uint32_t flags
= nsIBrowserDOMWindow::OPEN_NEW
;
579 if (aForceNoOpener
) {
580 flags
|= nsIBrowserDOMWindow::OPEN_NO_OPENER
;
582 if (aForceNoReferrer
) {
583 flags
|= nsIBrowserDOMWindow::OPEN_NO_REFERRER
;
586 // Get a new rendering area from the browserDOMWin.
587 // Since we are not loading any URI, we follow the principle of least
588 // privilege and use a nullPrincipal as the triggeringPrincipal.
590 // This method handles setting the opener for us, so we don't need to set it
592 RefPtr
<NullPrincipal
> nullPrincipal
=
593 NullPrincipal::CreateWithoutOriginAttributes();
594 return browserDOMWin
->CreateContentWindow(aURI
, aOpenWindowInfo
,
596 nullPrincipal
, nullptr, aReturn
);
600 //*****************************************************************************
601 // nsContentTreeOwner: Accessors
602 //*****************************************************************************
604 void nsContentTreeOwner::AppWindow(mozilla::AppWindow
* aAppWindow
) {
605 mAppWindow
= aAppWindow
;
608 mozilla::AppWindow
* nsContentTreeOwner::AppWindow() { return mAppWindow
; }
610 //*****************************************************************************
611 //*** nsSiteWindow implementation
612 //*****************************************************************************
614 nsSiteWindow::nsSiteWindow(nsContentTreeOwner
* aAggregator
) {
615 mAggregator
= aAggregator
;
618 nsSiteWindow::~nsSiteWindow() {}
620 NS_IMPL_ADDREF_USING_AGGREGATOR(nsSiteWindow
, mAggregator
)
621 NS_IMPL_RELEASE_USING_AGGREGATOR(nsSiteWindow
, mAggregator
)
623 NS_INTERFACE_MAP_BEGIN(nsSiteWindow
)
624 NS_INTERFACE_MAP_ENTRY(nsISupports
)
625 NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow
)
626 NS_INTERFACE_MAP_END_AGGREGATED(mAggregator
)
629 nsSiteWindow::SetDimensions(uint32_t aFlags
, int32_t aX
, int32_t aY
,
630 int32_t aCX
, int32_t aCY
) {
631 // XXX we're ignoring aFlags
632 return mAggregator
->SetPositionAndSize(aX
, aY
, aCX
, aCY
,
633 nsIBaseWindow::eRepaint
);
637 nsSiteWindow::GetDimensions(uint32_t aFlags
, int32_t* aX
, int32_t* aY
,
638 int32_t* aCX
, int32_t* aCY
) {
639 // XXX we're ignoring aFlags
640 return mAggregator
->GetPositionAndSize(aX
, aY
, aCX
, aCY
);
643 /* this implementation focuses another window. if there isn't another
644 window to focus, we do nothing. */
646 nsSiteWindow::Blur(void) {
647 NS_DEFINE_CID(kWindowMediatorCID
, NS_WINDOWMEDIATOR_CID
);
649 nsCOMPtr
<nsISimpleEnumerator
> windowEnumerator
;
650 nsCOMPtr
<nsIAppWindow
> appWindow
;
652 AppWindow
* ourWindow
= mAggregator
->AppWindow();
655 nsCOMPtr
<nsIWindowMediator
> windowMediator(
656 do_GetService(kWindowMediatorCID
));
658 windowMediator
->GetZOrderAppWindowEnumerator(
659 0, true, getter_AddRefs(windowEnumerator
));
662 if (!windowEnumerator
) return NS_ERROR_FAILURE
;
664 // step through the top-level windows
666 windowEnumerator
->HasMoreElements(&more
);
668 nsCOMPtr
<nsISupports
> nextWindow
;
669 nsCOMPtr
<nsIAppWindow
> nextAppWindow
;
671 windowEnumerator
->GetNext(getter_AddRefs(nextWindow
));
672 nextAppWindow
= do_QueryInterface(nextWindow
);
676 appWindow
= nextAppWindow
;
680 // remember the very first one, in case we have to wrap
681 if (!appWindow
) appWindow
= nextAppWindow
;
684 if (nextAppWindow
== ourWindow
) foundUs
= true;
686 windowEnumerator
->HasMoreElements(&more
);
689 // change focus to the window we just found
691 nsCOMPtr
<nsIDocShell
> docshell
;
692 appWindow
->GetDocShell(getter_AddRefs(docshell
));
697 nsCOMPtr
<nsPIDOMWindowOuter
> domWindow
= docshell
->GetWindow();
698 if (domWindow
) domWindow
->Focus(mozilla::dom::CallerType::System
);
704 nsSiteWindow::GetVisibility(bool* aVisibility
) {
705 return mAggregator
->GetVisibility(aVisibility
);
709 nsSiteWindow::SetVisibility(bool aVisibility
) {
710 return mAggregator
->SetVisibility(aVisibility
);
714 nsSiteWindow::GetTitle(nsAString
& aTitle
) {
715 return mAggregator
->GetTitle(aTitle
);
719 nsSiteWindow::SetTitle(const nsAString
& aTitle
) {
720 return mAggregator
->SetTitle(aTitle
);
724 nsSiteWindow::GetSiteWindow(void** aSiteWindow
) {
725 return mAggregator
->GetParentNativeWindow(aSiteWindow
);