Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/base/BarProps.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
6
7
#include "mozilla/dom/BarProps.h"
8
#include "mozilla/dom/BarPropBinding.h"
9
#include "nsContentUtils.h"
10
#include "nsGlobalWindow.h"
11
#include "nsIDocShell.h"
12
#include "nsIScrollable.h"
13
#include "nsIWebBrowserChrome.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
//
19
//  Basic (virtual) BarProp class implementation
20
//
21
BarProp::BarProp(nsGlobalWindowInner* aWindow)
22
  : mDOMWindow(aWindow)
23
0
{
24
0
}
25
26
BarProp::~BarProp()
27
0
{
28
0
}
29
30
nsPIDOMWindowInner*
31
BarProp::GetParentObject() const
32
0
{
33
0
  return mDOMWindow->AsInner();
34
0
}
35
36
JSObject*
37
BarProp::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
38
0
{
39
0
  return BarProp_Binding::Wrap(aCx, this, aGivenProto);
40
0
}
41
42
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(BarProp, mDOMWindow)
43
NS_IMPL_CYCLE_COLLECTING_ADDREF(BarProp)
44
NS_IMPL_CYCLE_COLLECTING_RELEASE(BarProp)
45
0
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(BarProp)
46
0
  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
47
0
  NS_INTERFACE_MAP_ENTRY(nsISupports)
48
0
NS_INTERFACE_MAP_END
49
50
bool
51
BarProp::GetVisibleByFlag(uint32_t aChromeFlag, ErrorResult& aRv)
52
0
{
53
0
  nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
54
0
  NS_ENSURE_TRUE(browserChrome, false);
55
0
56
0
  uint32_t chromeFlags;
57
0
58
0
  if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
59
0
    aRv.Throw(NS_ERROR_FAILURE);
60
0
    return false;
61
0
  }
62
0
63
0
  return (chromeFlags & aChromeFlag);
64
0
}
65
66
void
67
BarProp::SetVisibleByFlag(bool aVisible, uint32_t aChromeFlag,
68
                          CallerType aCallerType, ErrorResult& aRv)
69
0
{
70
0
  nsCOMPtr<nsIWebBrowserChrome> browserChrome = GetBrowserChrome();
71
0
  NS_ENSURE_TRUE_VOID(browserChrome);
72
0
73
0
  if (aCallerType != CallerType::System) {
74
0
    return;
75
0
  }
76
0
77
0
  uint32_t chromeFlags;
78
0
79
0
  if (NS_FAILED(browserChrome->GetChromeFlags(&chromeFlags))) {
80
0
    aRv.Throw(NS_ERROR_FAILURE);
81
0
    return;
82
0
  }
83
0
84
0
  if (aVisible)
85
0
    chromeFlags |= aChromeFlag;
86
0
  else
87
0
    chromeFlags &= ~aChromeFlag;
88
0
89
0
  if (NS_FAILED(browserChrome->SetChromeFlags(chromeFlags))) {
90
0
    aRv.Throw(NS_ERROR_FAILURE);
91
0
  }
92
0
}
93
94
already_AddRefed<nsIWebBrowserChrome>
95
BarProp::GetBrowserChrome()
96
0
{
97
0
  if (!mDOMWindow) {
98
0
    return nullptr;
99
0
  }
100
0
101
0
  return mDOMWindow->GetWebBrowserChrome();
102
0
}
103
104
//
105
// MenubarProp class implementation
106
//
107
108
MenubarProp::MenubarProp(nsGlobalWindowInner *aWindow)
109
  : BarProp(aWindow)
110
0
{
111
0
}
112
113
MenubarProp::~MenubarProp()
114
{
115
}
116
117
bool
118
MenubarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
119
0
{
120
0
  return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_MENUBAR, aRv);
121
0
}
122
123
void
124
MenubarProp::SetVisible(bool aVisible, CallerType aCallerType, ErrorResult& aRv)
125
0
{
126
0
  BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_MENUBAR,
127
0
                            aCallerType, aRv);
128
0
}
129
130
//
131
// ToolbarProp class implementation
132
//
133
134
ToolbarProp::ToolbarProp(nsGlobalWindowInner *aWindow)
135
  : BarProp(aWindow)
136
0
{
137
0
}
138
139
ToolbarProp::~ToolbarProp()
140
{
141
}
142
143
bool
144
ToolbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
145
0
{
146
0
  return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_TOOLBAR, aRv);
147
0
}
148
149
void
150
ToolbarProp::SetVisible(bool aVisible, CallerType aCallerType, ErrorResult& aRv)
151
0
{
152
0
  BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_TOOLBAR,
153
0
                            aCallerType, aRv);
154
0
}
155
156
//
157
// LocationbarProp class implementation
158
//
159
160
LocationbarProp::LocationbarProp(nsGlobalWindowInner *aWindow)
161
  : BarProp(aWindow)
162
0
{
163
0
}
164
165
LocationbarProp::~LocationbarProp()
166
{
167
}
168
169
bool
170
LocationbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
171
0
{
172
0
  return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_LOCATIONBAR,
173
0
                                   aRv);
174
0
}
175
176
void
177
LocationbarProp::SetVisible(bool aVisible, CallerType aCallerType,
178
                            ErrorResult& aRv)
179
0
{
180
0
  BarProp::SetVisibleByFlag(aVisible, nsIWebBrowserChrome::CHROME_LOCATIONBAR,
181
0
                            aCallerType, aRv);
182
0
}
183
184
//
185
// PersonalbarProp class implementation
186
//
187
188
PersonalbarProp::PersonalbarProp(nsGlobalWindowInner *aWindow)
189
  : BarProp(aWindow)
190
0
{
191
0
}
192
193
PersonalbarProp::~PersonalbarProp()
194
{
195
}
196
197
bool
198
PersonalbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
199
0
{
200
0
  return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
201
0
                                   aRv);
202
0
}
203
204
void
205
PersonalbarProp::SetVisible(bool aVisible, CallerType aCallerType,
206
                            ErrorResult& aRv)
207
0
{
208
0
  BarProp::SetVisibleByFlag(aVisible,
209
0
                            nsIWebBrowserChrome::CHROME_PERSONAL_TOOLBAR,
210
0
                            aCallerType, aRv);
211
0
}
212
213
//
214
// StatusbarProp class implementation
215
//
216
217
StatusbarProp::StatusbarProp(nsGlobalWindowInner *aWindow)
218
  : BarProp(aWindow)
219
0
{
220
0
}
221
222
StatusbarProp::~StatusbarProp()
223
{
224
}
225
226
bool
227
StatusbarProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
228
0
{
229
0
  return BarProp::GetVisibleByFlag(nsIWebBrowserChrome::CHROME_STATUSBAR, aRv);
230
0
}
231
232
void
233
StatusbarProp::SetVisible(bool aVisible, CallerType aCallerType,
234
                          ErrorResult& aRv)
235
0
{
236
0
  return BarProp::SetVisibleByFlag(aVisible,
237
0
                                   nsIWebBrowserChrome::CHROME_STATUSBAR,
238
0
                                   aCallerType, aRv);
239
0
}
240
241
//
242
// ScrollbarsProp class implementation
243
//
244
245
ScrollbarsProp::ScrollbarsProp(nsGlobalWindowInner *aWindow)
246
: BarProp(aWindow)
247
0
{
248
0
}
249
250
ScrollbarsProp::~ScrollbarsProp()
251
{
252
}
253
254
bool
255
ScrollbarsProp::GetVisible(CallerType aCallerType, ErrorResult& aRv)
256
0
{
257
0
  if (!mDOMWindow) {
258
0
    return true;
259
0
  }
260
0
261
0
  nsCOMPtr<nsIScrollable> scroller =
262
0
    do_QueryInterface(mDOMWindow->GetDocShell());
263
0
264
0
  if (!scroller) {
265
0
    return true;
266
0
  }
267
0
268
0
  int32_t prefValue;
269
0
  scroller->GetDefaultScrollbarPreferences(
270
0
              nsIScrollable::ScrollOrientation_Y, &prefValue);
271
0
  if (prefValue != nsIScrollable::Scrollbar_Never) {
272
0
    return true;
273
0
  }
274
0
275
0
  scroller->GetDefaultScrollbarPreferences(
276
0
              nsIScrollable::ScrollOrientation_X, &prefValue);
277
0
  return prefValue != nsIScrollable::Scrollbar_Never;
278
0
}
279
280
void
281
ScrollbarsProp::SetVisible(bool aVisible, CallerType aCallerType,
282
                           ErrorResult& aRv)
283
0
{
284
0
  if (aCallerType != CallerType::System) {
285
0
    return;
286
0
  }
287
0
288
0
  /* Scrollbars, unlike the other barprops, implement visibility directly
289
0
     rather than handing off to the superclass (and from there to the
290
0
     chrome window) because scrollbar visibility uniquely applies only
291
0
     to the window making the change (arguably. it does now, anyway.)
292
0
     and because embedding apps have no interface for implementing this
293
0
     themselves, and therefore the implementation must be internal. */
294
0
295
0
  nsContentUtils::SetScrollbarsVisibility(mDOMWindow->GetDocShell(), aVisible);
296
0
297
0
  /* Notably absent is the part where we notify the chrome window using
298
0
     GetBrowserChrome()->SetChromeFlags(). Given the possibility of multiple
299
0
     DOM windows (multiple top-level windows, even) within a single
300
0
     chrome window, the historical concept of a single "has scrollbars"
301
0
     flag in the chrome is inapplicable, and we can't tell at this level
302
0
     whether we represent the particular DOM window that makes this decision
303
0
     for the chrome.
304
0
305
0
     So only this object (and its corresponding DOM window) knows whether
306
0
     scrollbars are visible. The corresponding chrome window will need to
307
0
     ask (one of) its DOM window(s) when it needs to know about scrollbar
308
0
     visibility, rather than caching its own copy of that information.
309
0
  */
310
0
}
311
312
} // namespace dom
313
} // namespace mozilla
314