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