1 /* -*- Mode: C++; tab-width: 3; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "nsChromeTreeOwner.h"
13 #include "nsIEmbeddingSiteWindow.h"
14 #include "nsIDocShellTreeItem.h"
16 // Interfaces needed to include
17 #include "nsIPrompt.h"
18 #include "nsIAuthPrompt.h"
19 #include "nsIWebProgress.h"
20 #include "nsIWidget.h"
21 #include "mozilla/dom/Element.h"
23 using namespace mozilla
;
25 //*****************************************************************************
26 // nsChromeTreeOwner string literals
27 //*****************************************************************************
29 const nsLiteralString
kPersist(u
"persist");
30 const nsLiteralString
kScreenX(u
"screenX");
31 const nsLiteralString
kScreenY(u
"screenY");
32 const nsLiteralString
kWidth(u
"width");
33 const nsLiteralString
kHeight(u
"height");
34 const nsLiteralString
kSizemode(u
"sizemode");
35 const nsLiteralString
kSpace(u
" ");
37 //*****************************************************************************
38 //*** nsChromeTreeOwner: Object Management
39 //*****************************************************************************
41 nsChromeTreeOwner::nsChromeTreeOwner() : mAppWindow(nullptr) {}
43 nsChromeTreeOwner::~nsChromeTreeOwner() {}
45 //*****************************************************************************
46 // nsChromeTreeOwner::nsISupports
47 //*****************************************************************************
49 NS_IMPL_ADDREF(nsChromeTreeOwner
)
50 NS_IMPL_RELEASE(nsChromeTreeOwner
)
52 NS_INTERFACE_MAP_BEGIN(nsChromeTreeOwner
)
53 NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports
, nsIDocShellTreeOwner
)
54 NS_INTERFACE_MAP_ENTRY(nsIDocShellTreeOwner
)
55 NS_INTERFACE_MAP_ENTRY(nsIBaseWindow
)
56 NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener
)
57 NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor
)
58 NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference
)
61 //*****************************************************************************
62 // nsChromeTreeOwner::nsIInterfaceRequestor
63 //*****************************************************************************
65 NS_IMETHODIMP
nsChromeTreeOwner::GetInterface(const nsIID
& aIID
, void** aSink
) {
66 NS_ENSURE_ARG_POINTER(aSink
);
68 if (aIID
.Equals(NS_GET_IID(nsIPrompt
))) {
69 NS_ENSURE_STATE(mAppWindow
);
70 return mAppWindow
->GetInterface(aIID
, aSink
);
72 if (aIID
.Equals(NS_GET_IID(nsIAuthPrompt
))) {
73 NS_ENSURE_STATE(mAppWindow
);
74 return mAppWindow
->GetInterface(aIID
, aSink
);
76 if (aIID
.Equals(NS_GET_IID(nsIWebBrowserChrome
))) {
77 NS_ENSURE_STATE(mAppWindow
);
78 return mAppWindow
->GetInterface(aIID
, aSink
);
80 if (aIID
.Equals(NS_GET_IID(nsIEmbeddingSiteWindow
))) {
81 NS_ENSURE_STATE(mAppWindow
);
82 return mAppWindow
->GetInterface(aIID
, aSink
);
84 if (aIID
.Equals(NS_GET_IID(nsIAppWindow
))) {
85 NS_ENSURE_STATE(mAppWindow
);
86 return mAppWindow
->QueryInterface(aIID
, aSink
);
89 return QueryInterface(aIID
, aSink
);
92 //*****************************************************************************
93 // nsChromeTreeOwner::nsIDocShellTreeOwner
94 //*****************************************************************************
97 nsChromeTreeOwner::ContentShellAdded(nsIDocShellTreeItem
* aContentShell
,
99 NS_ENSURE_STATE(mAppWindow
);
100 return mAppWindow
->ContentShellAdded(aContentShell
, aPrimary
);
104 nsChromeTreeOwner::ContentShellRemoved(nsIDocShellTreeItem
* aContentShell
) {
105 NS_ENSURE_STATE(mAppWindow
);
106 return mAppWindow
->ContentShellRemoved(aContentShell
);
109 NS_IMETHODIMP
nsChromeTreeOwner::GetPrimaryContentShell(
110 nsIDocShellTreeItem
** aShell
) {
111 NS_ENSURE_STATE(mAppWindow
);
112 return mAppWindow
->GetPrimaryContentShell(aShell
);
116 nsChromeTreeOwner::RemoteTabAdded(nsIRemoteTab
* aTab
, bool aPrimary
) {
117 NS_ENSURE_STATE(mAppWindow
);
118 return mAppWindow
->RemoteTabAdded(aTab
, aPrimary
);
122 nsChromeTreeOwner::RemoteTabRemoved(nsIRemoteTab
* aTab
) {
123 NS_ENSURE_STATE(mAppWindow
);
124 return mAppWindow
->RemoteTabRemoved(aTab
);
128 nsChromeTreeOwner::GetPrimaryRemoteTab(nsIRemoteTab
** aTab
) {
129 NS_ENSURE_STATE(mAppWindow
);
130 return mAppWindow
->GetPrimaryRemoteTab(aTab
);
134 nsChromeTreeOwner::GetPrimaryContentSize(int32_t* aWidth
, int32_t* aHeight
) {
135 NS_ENSURE_STATE(mAppWindow
);
136 return mAppWindow
->GetPrimaryContentSize(aWidth
, aHeight
);
140 nsChromeTreeOwner::SetPrimaryContentSize(int32_t aWidth
, int32_t aHeight
) {
141 NS_ENSURE_STATE(mAppWindow
);
142 return mAppWindow
->SetPrimaryContentSize(aWidth
, aHeight
);
146 nsChromeTreeOwner::GetRootShellSize(int32_t* aWidth
, int32_t* aHeight
) {
147 NS_ENSURE_STATE(mAppWindow
);
148 return mAppWindow
->GetRootShellSize(aWidth
, aHeight
);
152 nsChromeTreeOwner::SetRootShellSize(int32_t aWidth
, int32_t aHeight
) {
153 NS_ENSURE_STATE(mAppWindow
);
154 return mAppWindow
->SetRootShellSize(aWidth
, aHeight
);
157 NS_IMETHODIMP
nsChromeTreeOwner::SizeShellTo(nsIDocShellTreeItem
* aShellItem
,
158 int32_t aCX
, int32_t aCY
) {
159 NS_ENSURE_STATE(mAppWindow
);
160 return mAppWindow
->SizeShellTo(aShellItem
, aCX
, aCY
);
164 nsChromeTreeOwner::SetPersistence(bool aPersistPosition
, bool aPersistSize
,
165 bool aPersistSizeMode
) {
166 NS_ENSURE_STATE(mAppWindow
);
167 nsCOMPtr
<dom::Element
> docShellElement
= mAppWindow
->GetWindowDOMElement();
168 if (!docShellElement
) return NS_ERROR_FAILURE
;
170 nsAutoString persistString
;
171 docShellElement
->GetAttribute(kPersist
, persistString
);
173 bool saveString
= false;
176 #define FIND_PERSIST_STRING(aString, aCond) \
177 index = persistString.Find(aString); \
178 if (!aCond && index > kNotFound) { \
179 persistString.Cut(index, aString.Length()); \
181 } else if (aCond && index == kNotFound) { \
182 persistString.Append(kSpace + aString); \
185 FIND_PERSIST_STRING(kScreenX
, aPersistPosition
);
186 FIND_PERSIST_STRING(kScreenY
, aPersistPosition
);
187 FIND_PERSIST_STRING(kWidth
, aPersistSize
);
188 FIND_PERSIST_STRING(kHeight
, aPersistSize
);
189 FIND_PERSIST_STRING(kSizemode
, aPersistSizeMode
);
193 docShellElement
->SetAttribute(kPersist
, persistString
, rv
);
200 nsChromeTreeOwner::GetPersistence(bool* aPersistPosition
, bool* aPersistSize
,
201 bool* aPersistSizeMode
) {
202 NS_ENSURE_STATE(mAppWindow
);
203 nsCOMPtr
<dom::Element
> docShellElement
= mAppWindow
->GetWindowDOMElement();
204 if (!docShellElement
) return NS_ERROR_FAILURE
;
206 nsAutoString persistString
;
207 docShellElement
->GetAttribute(kPersist
, persistString
);
209 // data structure doesn't quite match the question, but it's close enough
210 // for what we want (since this method is never actually called...)
211 if (aPersistPosition
)
212 *aPersistPosition
= persistString
.Find(kScreenX
) > kNotFound
||
213 persistString
.Find(kScreenY
) > kNotFound
;
215 *aPersistSize
= persistString
.Find(kWidth
) > kNotFound
||
216 persistString
.Find(kHeight
) > kNotFound
;
217 if (aPersistSizeMode
)
218 *aPersistSizeMode
= persistString
.Find(kSizemode
) > kNotFound
;
224 nsChromeTreeOwner::GetTabCount(uint32_t* aResult
) {
226 return mAppWindow
->GetTabCount(aResult
);
234 nsChromeTreeOwner::GetHasPrimaryContent(bool* aResult
) {
235 NS_ENSURE_STATE(mAppWindow
);
236 return mAppWindow
->GetHasPrimaryContent(aResult
);
239 //*****************************************************************************
240 // nsChromeTreeOwner::nsIBaseWindow
241 //*****************************************************************************
243 NS_IMETHODIMP
nsChromeTreeOwner::InitWindow(nativeWindow aParentNativeWindow
,
244 nsIWidget
* parentWidget
, int32_t x
,
245 int32_t y
, int32_t cx
, int32_t cy
) {
246 // Ignore widget parents for now. Don't think those are a vaild thing to
248 NS_ENSURE_SUCCESS(SetPositionAndSize(x
, y
, cx
, cy
, 0), NS_ERROR_FAILURE
);
253 NS_IMETHODIMP
nsChromeTreeOwner::Destroy() {
254 NS_ENSURE_STATE(mAppWindow
);
255 return mAppWindow
->Destroy();
258 NS_IMETHODIMP
nsChromeTreeOwner::GetUnscaledDevicePixelsPerCSSPixel(
260 NS_ENSURE_STATE(mAppWindow
);
261 return mAppWindow
->GetUnscaledDevicePixelsPerCSSPixel(aScale
);
264 NS_IMETHODIMP
nsChromeTreeOwner::GetDevicePixelsPerDesktopPixel(
266 NS_ENSURE_STATE(mAppWindow
);
267 return mAppWindow
->GetDevicePixelsPerDesktopPixel(aScale
);
270 NS_IMETHODIMP
nsChromeTreeOwner::SetPositionDesktopPix(int32_t x
, int32_t y
) {
271 NS_ENSURE_STATE(mAppWindow
);
272 return mAppWindow
->SetPositionDesktopPix(x
, y
);
275 NS_IMETHODIMP
nsChromeTreeOwner::SetPosition(int32_t x
, int32_t y
) {
276 NS_ENSURE_STATE(mAppWindow
);
277 return mAppWindow
->SetPosition(x
, y
);
280 NS_IMETHODIMP
nsChromeTreeOwner::GetPosition(int32_t* x
, int32_t* y
) {
281 NS_ENSURE_STATE(mAppWindow
);
282 return mAppWindow
->GetPosition(x
, y
);
285 NS_IMETHODIMP
nsChromeTreeOwner::SetSize(int32_t cx
, int32_t cy
,
287 NS_ENSURE_STATE(mAppWindow
);
288 return mAppWindow
->SetSize(cx
, cy
, fRepaint
);
291 NS_IMETHODIMP
nsChromeTreeOwner::GetSize(int32_t* cx
, int32_t* cy
) {
292 NS_ENSURE_STATE(mAppWindow
);
293 return mAppWindow
->GetSize(cx
, cy
);
296 NS_IMETHODIMP
nsChromeTreeOwner::SetPositionAndSize(int32_t x
, int32_t y
,
297 int32_t cx
, int32_t cy
,
299 NS_ENSURE_STATE(mAppWindow
);
300 return mAppWindow
->SetPositionAndSize(x
, y
, cx
, cy
, aFlags
);
303 NS_IMETHODIMP
nsChromeTreeOwner::GetPositionAndSize(int32_t* x
, int32_t* y
,
304 int32_t* cx
, int32_t* cy
) {
305 NS_ENSURE_STATE(mAppWindow
);
306 return mAppWindow
->GetPositionAndSize(x
, y
, cx
, cy
);
309 NS_IMETHODIMP
nsChromeTreeOwner::Repaint(bool aForce
) {
310 NS_ENSURE_STATE(mAppWindow
);
311 return mAppWindow
->Repaint(aForce
);
314 NS_IMETHODIMP
nsChromeTreeOwner::GetParentWidget(nsIWidget
** aParentWidget
) {
315 NS_ENSURE_STATE(mAppWindow
);
316 return mAppWindow
->GetParentWidget(aParentWidget
);
319 NS_IMETHODIMP
nsChromeTreeOwner::SetParentWidget(nsIWidget
* aParentWidget
) {
320 NS_ASSERTION(false, "You can't call this");
321 return NS_ERROR_NOT_IMPLEMENTED
;
324 NS_IMETHODIMP
nsChromeTreeOwner::GetParentNativeWindow(
325 nativeWindow
* aParentNativeWindow
) {
326 NS_ENSURE_STATE(mAppWindow
);
327 return mAppWindow
->GetParentNativeWindow(aParentNativeWindow
);
330 NS_IMETHODIMP
nsChromeTreeOwner::SetParentNativeWindow(
331 nativeWindow aParentNativeWindow
) {
332 NS_ASSERTION(false, "You can't call this");
333 return NS_ERROR_NOT_IMPLEMENTED
;
336 NS_IMETHODIMP
nsChromeTreeOwner::GetNativeHandle(nsAString
& aNativeHandle
) {
337 NS_ENSURE_STATE(mAppWindow
);
338 return mAppWindow
->GetNativeHandle(aNativeHandle
);
341 NS_IMETHODIMP
nsChromeTreeOwner::GetVisibility(bool* aVisibility
) {
342 NS_ENSURE_STATE(mAppWindow
);
343 return mAppWindow
->GetVisibility(aVisibility
);
346 NS_IMETHODIMP
nsChromeTreeOwner::SetVisibility(bool aVisibility
) {
347 NS_ENSURE_STATE(mAppWindow
);
348 return mAppWindow
->SetVisibility(aVisibility
);
351 NS_IMETHODIMP
nsChromeTreeOwner::GetEnabled(bool* aEnabled
) {
352 NS_ENSURE_STATE(mAppWindow
);
353 return mAppWindow
->GetEnabled(aEnabled
);
356 NS_IMETHODIMP
nsChromeTreeOwner::SetEnabled(bool aEnable
) {
357 NS_ENSURE_STATE(mAppWindow
);
358 return mAppWindow
->SetEnabled(aEnable
);
361 NS_IMETHODIMP
nsChromeTreeOwner::GetMainWidget(nsIWidget
** aMainWidget
) {
362 NS_ENSURE_ARG_POINTER(aMainWidget
);
363 NS_ENSURE_STATE(mAppWindow
);
365 *aMainWidget
= mAppWindow
->mWindow
;
366 NS_IF_ADDREF(*aMainWidget
);
371 NS_IMETHODIMP
nsChromeTreeOwner::GetTitle(nsAString
& aTitle
) {
372 NS_ENSURE_STATE(mAppWindow
);
373 return mAppWindow
->GetTitle(aTitle
);
376 NS_IMETHODIMP
nsChromeTreeOwner::SetTitle(const nsAString
& aTitle
) {
377 NS_ENSURE_STATE(mAppWindow
);
378 return mAppWindow
->SetTitle(aTitle
);
381 //*****************************************************************************
382 // nsChromeTreeOwner::nsIWebProgressListener
383 //*****************************************************************************
386 nsChromeTreeOwner::OnProgressChange(nsIWebProgress
* aWebProgress
,
387 nsIRequest
* aRequest
,
388 int32_t aCurSelfProgress
,
389 int32_t aMaxSelfProgress
,
390 int32_t aCurTotalProgress
,
391 int32_t aMaxTotalProgress
) {
396 nsChromeTreeOwner::OnStateChange(nsIWebProgress
* aWebProgress
,
397 nsIRequest
* aRequest
,
398 uint32_t aProgressStateFlags
,
404 nsChromeTreeOwner::OnLocationChange(nsIWebProgress
* aWebProgress
,
405 nsIRequest
* aRequest
, nsIURI
* aLocation
,
407 NS_ENSURE_STATE(mAppWindow
);
409 // If loading a new root .xul document, then redo chrome.
411 nsCOMPtr
<nsIDocShell
> docshell
;
412 mAppWindow
->GetDocShell(getter_AddRefs(docshell
));
414 nsCOMPtr
<nsIWebProgress
> webProgress(do_QueryInterface(docshell
));
415 if (webProgress
!= aWebProgress
) {
420 mAppWindow
->mChromeLoaded
= false;
425 nsChromeTreeOwner::OnStatusChange(nsIWebProgress
* aWebProgress
,
426 nsIRequest
* aRequest
, nsresult aStatus
,
427 const char16_t
* aMessage
) {
432 nsChromeTreeOwner::OnSecurityChange(nsIWebProgress
* aWebProgress
,
433 nsIRequest
* aRequest
, uint32_t aState
) {
438 nsChromeTreeOwner::OnContentBlockingEvent(nsIWebProgress
* aWebProgress
,
439 nsIRequest
* aRequest
,
444 //*****************************************************************************
445 // nsChromeTreeOwner: Helpers
446 //*****************************************************************************
448 //*****************************************************************************
449 // nsChromeTreeOwner: Accessors
450 //*****************************************************************************
452 void nsChromeTreeOwner::AppWindow(mozilla::AppWindow
* aAppWindow
) {
453 mAppWindow
= aAppWindow
;
456 mozilla::AppWindow
* nsChromeTreeOwner::AppWindow() { return mAppWindow
; }