Bug 1728955: part 8) Refactor `DisplayErrCode` in Windows' `nsClipboard`. r=masayuki
[gecko.git] / xpfe / appshell / nsContentTreeOwner.cpp
blob9402cd75a4de79df88d7d15e140114e6bb1eb391
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/. */
8 // Local Includes
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"
35 #include "nsIURI.h"
36 #include "mozilla/dom/Document.h"
37 #if defined(XP_MACOSX)
38 # include "nsThreadUtils.h"
39 #endif
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;
60 public:
61 explicit nsSiteWindow(nsContentTreeOwner* aAggregator);
63 NS_DECL_ISUPPORTS_INHERITED
64 NS_DECL_NSIEMBEDDINGSITEWINDOW
66 private:
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)
106 NS_INTERFACE_MAP_END
108 //*****************************************************************************
109 // nsContentTreeOwner::nsIInterfaceRequestor
110 //*****************************************************************************
112 NS_IMETHODIMP nsContentTreeOwner::GetInterface(const nsIID& aIID,
113 void** aSink) {
114 NS_ENSURE_ARG_POINTER(aSink);
115 *aSink = 0;
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));
138 if (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 //*****************************************************************************
157 NS_IMETHODIMP
158 nsContentTreeOwner::ContentShellAdded(nsIDocShellTreeItem* aContentShell,
159 bool aPrimary) {
160 NS_ENSURE_STATE(mAppWindow);
161 return mAppWindow->ContentShellAdded(aContentShell, aPrimary);
164 NS_IMETHODIMP
165 nsContentTreeOwner::ContentShellRemoved(nsIDocShellTreeItem* aContentShell) {
166 NS_ENSURE_STATE(mAppWindow);
167 return mAppWindow->ContentShellRemoved(aContentShell);
170 NS_IMETHODIMP
171 nsContentTreeOwner::GetPrimaryContentShell(nsIDocShellTreeItem** aShell) {
172 NS_ENSURE_STATE(mAppWindow);
173 return mAppWindow->GetPrimaryContentShell(aShell);
176 NS_IMETHODIMP
177 nsContentTreeOwner::RemoteTabAdded(nsIRemoteTab* aTab, bool aPrimary) {
178 NS_ENSURE_STATE(mAppWindow);
179 return mAppWindow->RemoteTabAdded(aTab, aPrimary);
182 NS_IMETHODIMP
183 nsContentTreeOwner::RemoteTabRemoved(nsIRemoteTab* aTab) {
184 NS_ENSURE_STATE(mAppWindow);
185 return mAppWindow->RemoteTabRemoved(aTab);
188 NS_IMETHODIMP
189 nsContentTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab** aTab) {
190 NS_ENSURE_STATE(mAppWindow);
191 return mAppWindow->GetPrimaryRemoteTab(aTab);
194 NS_IMETHODIMP
195 nsContentTreeOwner::GetPrimaryContentSize(int32_t* aWidth, int32_t* aHeight) {
196 NS_ENSURE_STATE(mAppWindow);
197 return mAppWindow->GetPrimaryContentSize(aWidth, aHeight);
200 NS_IMETHODIMP
201 nsContentTreeOwner::SetPrimaryContentSize(int32_t aWidth, int32_t aHeight) {
202 NS_ENSURE_STATE(mAppWindow);
203 return mAppWindow->SetPrimaryContentSize(aWidth, aHeight);
206 NS_IMETHODIMP
207 nsContentTreeOwner::GetRootShellSize(int32_t* aWidth, int32_t* aHeight) {
208 NS_ENSURE_STATE(mAppWindow);
209 return mAppWindow->GetRootShellSize(aWidth, aHeight);
212 NS_IMETHODIMP
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);
224 NS_IMETHODIMP
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;
235 int32_t index;
237 // Set X
238 index = persistString.Find("screenX");
239 if (!aPersistPosition && index >= 0) {
240 persistString.Cut(index, 7);
241 saveString = true;
242 } else if (aPersistPosition && index < 0) {
243 persistString.AppendLiteral(" screenX");
244 saveString = true;
246 // Set Y
247 index = persistString.Find("screenY");
248 if (!aPersistPosition && index >= 0) {
249 persistString.Cut(index, 7);
250 saveString = true;
251 } else if (aPersistPosition && index < 0) {
252 persistString.AppendLiteral(" screenY");
253 saveString = true;
255 // Set CX
256 index = persistString.Find("width");
257 if (!aPersistSize && index >= 0) {
258 persistString.Cut(index, 5);
259 saveString = true;
260 } else if (aPersistSize && index < 0) {
261 persistString.AppendLiteral(" width");
262 saveString = true;
264 // Set CY
265 index = persistString.Find("height");
266 if (!aPersistSize && index >= 0) {
267 persistString.Cut(index, 6);
268 saveString = true;
269 } else if (aPersistSize && index < 0) {
270 persistString.AppendLiteral(" height");
271 saveString = true;
273 // Set SizeMode
274 index = persistString.Find("sizemode");
275 if (!aPersistSizeMode && (index >= 0)) {
276 persistString.Cut(index, 8);
277 saveString = true;
278 } else if (aPersistSizeMode && (index < 0)) {
279 persistString.AppendLiteral(" sizemode");
280 saveString = true;
283 ErrorResult rv;
284 if (saveString) {
285 docShellElement->SetAttribute(u"persist"_ns, persistString, rv);
288 return NS_OK;
291 NS_IMETHODIMP
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)
304 *aPersistPosition =
305 persistString.Find("screenX") >= 0 || persistString.Find("screenY") >= 0
306 ? true
307 : false;
308 if (aPersistSize)
309 *aPersistSize =
310 persistString.Find("width") >= 0 || persistString.Find("height") >= 0
311 ? true
312 : false;
313 if (aPersistSizeMode)
314 *aPersistSizeMode = persistString.Find("sizemode") >= 0 ? true : false;
316 return NS_OK;
319 NS_IMETHODIMP
320 nsContentTreeOwner::GetTabCount(uint32_t* aResult) {
321 if (mAppWindow) {
322 return mAppWindow->GetTabCount(aResult);
325 *aResult = 0;
326 return NS_OK;
329 NS_IMETHODIMP
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);
349 return NS_OK;
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;
370 return NS_OK;
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,
380 int32_t cy) {
381 // Ignore wigdet parents for now. Don't think those are a vaild thing to
382 // call.
383 NS_ENSURE_SUCCESS(SetPositionAndSize(x, y, cx, cy, 0), NS_ERROR_FAILURE);
385 return NS_OK;
388 NS_IMETHODIMP nsContentTreeOwner::Destroy() {
389 NS_ENSURE_STATE(mAppWindow);
390 return mAppWindow->Destroy();
393 NS_IMETHODIMP nsContentTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(
394 double* aScale) {
395 NS_ENSURE_STATE(mAppWindow);
396 return mAppWindow->GetUnscaledDevicePixelsPerCSSPixel(aScale);
399 NS_IMETHODIMP nsContentTreeOwner::GetDevicePixelsPerDesktopPixel(
400 double* aScale) {
401 NS_ENSURE_STATE(mAppWindow);
402 return mAppWindow->GetDevicePixelsPerDesktopPixel(aScale);
405 NS_IMETHODIMP nsContentTreeOwner::SetPositionDesktopPix(int32_t aX,
406 int32_t aY) {
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,
422 bool aRepaint) {
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,
434 uint32_t aFlags) {
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,
440 int32_t* aCX,
441 int32_t* aCY) {
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);
505 return NS_OK;
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) {
515 return NS_OK;
518 //*****************************************************************************
519 // nsContentTreeOwner: nsIWindowProvider
520 //*****************************************************************************
521 NS_IMETHODIMP
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();
532 *aReturn = nullptr;
534 if (!mAppWindow) {
535 // Nothing to do here
536 return NS_OK;
539 #ifdef DEBUG
540 nsCOMPtr<nsIDocShell> docshell = parent->GetDocShell();
541 nsCOMPtr<nsIDocShellTreeOwner> parentOwner = do_GetInterface(docshell);
542 NS_ASSERTION(
543 SameCOMIdentity(parentOwner, static_cast<nsIDocShellTreeOwner*>(this)),
544 "Parent from wrong docshell tree?");
545 #endif
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
555 return NS_OK;
558 nsCOMPtr<mozIDOMWindowProxy> domWin;
559 mAppWindow->GetWindowDOMWindow(getter_AddRefs(domWin));
560 nsCOMPtr<nsIDOMChromeWindow> chromeWin = do_QueryInterface(domWin);
561 if (!chromeWin) {
562 // Really odd... but whatever
563 NS_WARNING("AppWindow's DOMWindow is not a chrome window");
564 return NS_OK;
567 nsCOMPtr<nsIBrowserDOMWindow> browserDOMWin;
568 chromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
569 if (!browserDOMWin) {
570 return NS_OK;
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
591 // ourselves.
592 RefPtr<NullPrincipal> nullPrincipal =
593 NullPrincipal::CreateWithoutOriginAttributes();
594 return browserDOMWin->CreateContentWindow(aURI, aOpenWindowInfo,
595 openLocation, flags,
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)
628 NS_IMETHODIMP
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);
636 NS_IMETHODIMP
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. */
645 NS_IMETHODIMP
646 nsSiteWindow::Blur(void) {
647 NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID);
649 nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
650 nsCOMPtr<nsIAppWindow> appWindow;
651 bool more, foundUs;
652 AppWindow* ourWindow = mAggregator->AppWindow();
655 nsCOMPtr<nsIWindowMediator> windowMediator(
656 do_GetService(kWindowMediatorCID));
657 if (windowMediator)
658 windowMediator->GetZOrderAppWindowEnumerator(
659 0, true, getter_AddRefs(windowEnumerator));
662 if (!windowEnumerator) return NS_ERROR_FAILURE;
664 // step through the top-level windows
665 foundUs = false;
666 windowEnumerator->HasMoreElements(&more);
667 while (more) {
668 nsCOMPtr<nsISupports> nextWindow;
669 nsCOMPtr<nsIAppWindow> nextAppWindow;
671 windowEnumerator->GetNext(getter_AddRefs(nextWindow));
672 nextAppWindow = do_QueryInterface(nextWindow);
674 // got it!(?)
675 if (foundUs) {
676 appWindow = nextAppWindow;
677 break;
680 // remember the very first one, in case we have to wrap
681 if (!appWindow) appWindow = nextAppWindow;
683 // look for us
684 if (nextAppWindow == ourWindow) foundUs = true;
686 windowEnumerator->HasMoreElements(&more);
689 // change focus to the window we just found
690 if (appWindow) {
691 nsCOMPtr<nsIDocShell> docshell;
692 appWindow->GetDocShell(getter_AddRefs(docshell));
693 if (!docshell) {
694 return NS_OK;
697 nsCOMPtr<nsPIDOMWindowOuter> domWindow = docshell->GetWindow();
698 if (domWindow) domWindow->Focus(mozilla::dom::CallerType::System);
700 return NS_OK;
703 NS_IMETHODIMP
704 nsSiteWindow::GetVisibility(bool* aVisibility) {
705 return mAggregator->GetVisibility(aVisibility);
708 NS_IMETHODIMP
709 nsSiteWindow::SetVisibility(bool aVisibility) {
710 return mAggregator->SetVisibility(aVisibility);
713 NS_IMETHODIMP
714 nsSiteWindow::GetTitle(nsAString& aTitle) {
715 return mAggregator->GetTitle(aTitle);
718 NS_IMETHODIMP
719 nsSiteWindow::SetTitle(const nsAString& aTitle) {
720 return mAggregator->SetTitle(aTitle);
723 NS_IMETHODIMP
724 nsSiteWindow::GetSiteWindow(void** aSiteWindow) {
725 return mAggregator->GetParentNativeWindow(aSiteWindow);