dom/base/nsGlobalWindow.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim: set ts=2 sw=2 et tw=80: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef nsGlobalWindow_h___
michael@0 8 #define nsGlobalWindow_h___
michael@0 9
michael@0 10 #include "nsPIDOMWindow.h"
michael@0 11
michael@0 12 #include "nsTHashtable.h"
michael@0 13 #include "nsHashKeys.h"
michael@0 14 #include "nsRefPtrHashtable.h"
michael@0 15
michael@0 16 // Local Includes
michael@0 17 // Helper Classes
michael@0 18 #include "nsCOMPtr.h"
michael@0 19 #include "nsAutoPtr.h"
michael@0 20 #include "nsWeakReference.h"
michael@0 21 #include "nsDataHashtable.h"
michael@0 22 #include "nsJSThingHashtable.h"
michael@0 23 #include "nsCycleCollectionParticipant.h"
michael@0 24
michael@0 25 // Interfaces Needed
michael@0 26 #include "nsIBrowserDOMWindow.h"
michael@0 27 #include "nsIDOMEventTarget.h"
michael@0 28 #include "nsIInterfaceRequestor.h"
michael@0 29 #include "nsIDOMJSWindow.h"
michael@0 30 #include "nsIDOMChromeWindow.h"
michael@0 31 #include "nsIScriptGlobalObject.h"
michael@0 32 #include "nsIScriptObjectPrincipal.h"
michael@0 33 #include "nsITimer.h"
michael@0 34 #include "nsIDOMModalContentWindow.h"
michael@0 35 #include "mozilla/EventListenerManager.h"
michael@0 36 #include "nsIPrincipal.h"
michael@0 37 #include "nsSize.h"
michael@0 38 #include "mozFlushType.h"
michael@0 39 #include "prclist.h"
michael@0 40 #include "nsIDOMStorageEvent.h"
michael@0 41 #include "nsFrameMessageManager.h"
michael@0 42 #include "mozilla/LinkedList.h"
michael@0 43 #include "mozilla/TimeStamp.h"
michael@0 44 #include "nsIInlineEventHandlers.h"
michael@0 45 #include "nsWrapperCacheInlines.h"
michael@0 46 #include "nsIIdleObserver.h"
michael@0 47 #include "nsIDocument.h"
michael@0 48 #include "nsIDOMTouchEvent.h"
michael@0 49 #include "mozilla/dom/EventTarget.h"
michael@0 50 #include "Units.h"
michael@0 51 #include "nsComponentManagerUtils.h"
michael@0 52
michael@0 53 #ifdef MOZ_B2G
michael@0 54 #include "nsIDOMWindowB2G.h"
michael@0 55 #endif // MOZ_B2G
michael@0 56
michael@0 57 #ifdef MOZ_WEBSPEECH
michael@0 58 #include "nsISpeechSynthesisGetter.h"
michael@0 59 #endif // MOZ_WEBSPEECH
michael@0 60
michael@0 61 #define DEFAULT_HOME_PAGE "www.mozilla.org"
michael@0 62 #define PREF_BROWSER_STARTUP_HOMEPAGE "browser.startup.homepage"
michael@0 63
michael@0 64 // Amount of time allowed between alert/prompt/confirm before enabling
michael@0 65 // the stop dialog checkbox.
michael@0 66 #define DEFAULT_SUCCESSIVE_DIALOG_TIME_LIMIT 3 // 3 sec
michael@0 67
michael@0 68 // Maximum number of successive dialogs before we prompt users to disable
michael@0 69 // dialogs for this window.
michael@0 70 #define MAX_SUCCESSIVE_DIALOG_COUNT 5
michael@0 71
michael@0 72 // Idle fuzz time upper limit
michael@0 73 #define MAX_IDLE_FUZZ_TIME_MS 90000
michael@0 74
michael@0 75 // Min idle notification time in seconds.
michael@0 76 #define MIN_IDLE_NOTIFICATION_TIME_S 1
michael@0 77
michael@0 78 class nsIArray;
michael@0 79 class nsIBaseWindow;
michael@0 80 class nsIContent;
michael@0 81 class nsICSSDeclaration;
michael@0 82 class nsIDocShellTreeOwner;
michael@0 83 class nsIDOMCrypto;
michael@0 84 class nsIDOMOfflineResourceList;
michael@0 85 class nsIScrollableFrame;
michael@0 86 class nsIControllers;
michael@0 87 class nsIJSID;
michael@0 88 class nsIScriptContext;
michael@0 89 class nsIScriptTimeoutHandler;
michael@0 90 class nsIWebBrowserChrome;
michael@0 91
michael@0 92 class nsDOMWindowList;
michael@0 93 class nsLocation;
michael@0 94 class nsScreen;
michael@0 95 class nsHistory;
michael@0 96 class nsGlobalWindowObserver;
michael@0 97 class nsGlobalWindow;
michael@0 98 class nsDOMWindowUtils;
michael@0 99 class nsIIdleService;
michael@0 100 struct nsIntSize;
michael@0 101 struct nsRect;
michael@0 102
michael@0 103 class nsWindowSizes;
michael@0 104
michael@0 105 namespace mozilla {
michael@0 106 class DOMEventTargetHelper;
michael@0 107 namespace dom {
michael@0 108 class BarProp;
michael@0 109 class Console;
michael@0 110 class External;
michael@0 111 class Function;
michael@0 112 class Gamepad;
michael@0 113 class MediaQueryList;
michael@0 114 class Navigator;
michael@0 115 class OwningExternalOrWindowProxy;
michael@0 116 class Selection;
michael@0 117 class SpeechSynthesis;
michael@0 118 class WakeLock;
michael@0 119 namespace indexedDB {
michael@0 120 class IDBFactory;
michael@0 121 } // namespace indexedDB
michael@0 122 } // namespace dom
michael@0 123 } // namespace mozilla
michael@0 124
michael@0 125 extern nsresult
michael@0 126 NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
michael@0 127 bool *aIsInterval,
michael@0 128 int32_t *aInterval,
michael@0 129 nsIScriptTimeoutHandler **aRet);
michael@0 130
michael@0 131 extern already_AddRefed<nsIScriptTimeoutHandler>
michael@0 132 NS_CreateJSTimeoutHandler(nsGlobalWindow *aWindow,
michael@0 133 mozilla::dom::Function& aFunction,
michael@0 134 const mozilla::dom::Sequence<JS::Value>& aArguments,
michael@0 135 mozilla::ErrorResult& aError);
michael@0 136
michael@0 137 extern already_AddRefed<nsIScriptTimeoutHandler>
michael@0 138 NS_CreateJSTimeoutHandler(JSContext* aCx, nsGlobalWindow *aWindow,
michael@0 139 const nsAString& aExpression,
michael@0 140 mozilla::ErrorResult& aError);
michael@0 141
michael@0 142 /*
michael@0 143 * Timeout struct that holds information about each script
michael@0 144 * timeout. Holds a strong reference to an nsIScriptTimeoutHandler, which
michael@0 145 * abstracts the language specific cruft.
michael@0 146 */
michael@0 147 struct nsTimeout : mozilla::LinkedListElement<nsTimeout>
michael@0 148 {
michael@0 149 nsTimeout();
michael@0 150 ~nsTimeout();
michael@0 151
michael@0 152 NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsTimeout)
michael@0 153 NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsTimeout)
michael@0 154
michael@0 155 nsresult InitTimer(nsTimerCallbackFunc aFunc, uint32_t aDelay)
michael@0 156 {
michael@0 157 return mTimer->InitWithFuncCallback(aFunc, this, aDelay,
michael@0 158 nsITimer::TYPE_ONE_SHOT);
michael@0 159 }
michael@0 160
michael@0 161 bool HasRefCntOne();
michael@0 162
michael@0 163 // Window for which this timeout fires
michael@0 164 nsRefPtr<nsGlobalWindow> mWindow;
michael@0 165
michael@0 166 // The actual timer object
michael@0 167 nsCOMPtr<nsITimer> mTimer;
michael@0 168
michael@0 169 // True if the timeout was cleared
michael@0 170 bool mCleared;
michael@0 171
michael@0 172 // True if this is one of the timeouts that are currently running
michael@0 173 bool mRunning;
michael@0 174
michael@0 175 // True if this is a repeating/interval timer
michael@0 176 bool mIsInterval;
michael@0 177
michael@0 178 // Returned as value of setTimeout()
michael@0 179 uint32_t mPublicId;
michael@0 180
michael@0 181 // Interval in milliseconds
michael@0 182 uint32_t mInterval;
michael@0 183
michael@0 184 // mWhen and mTimeRemaining can't be in a union, sadly, because they
michael@0 185 // have constructors.
michael@0 186 // Nominal time to run this timeout. Use only when timeouts are not
michael@0 187 // suspended.
michael@0 188 mozilla::TimeStamp mWhen;
michael@0 189 // Remaining time to wait. Used only when timeouts are suspended.
michael@0 190 mozilla::TimeDuration mTimeRemaining;
michael@0 191
michael@0 192 // Principal with which to execute
michael@0 193 nsCOMPtr<nsIPrincipal> mPrincipal;
michael@0 194
michael@0 195 // stack depth at which timeout is firing
michael@0 196 uint32_t mFiringDepth;
michael@0 197
michael@0 198 //
michael@0 199 uint32_t mNestingLevel;
michael@0 200
michael@0 201 // The popup state at timeout creation time if not created from
michael@0 202 // another timeout
michael@0 203 PopupControlState mPopupState;
michael@0 204
michael@0 205 // The language-specific information about the callback.
michael@0 206 nsCOMPtr<nsIScriptTimeoutHandler> mScriptHandler;
michael@0 207 };
michael@0 208
michael@0 209 struct IdleObserverHolder
michael@0 210 {
michael@0 211 nsCOMPtr<nsIIdleObserver> mIdleObserver;
michael@0 212 uint32_t mTimeInS;
michael@0 213 bool mPrevNotificationIdle;
michael@0 214
michael@0 215 IdleObserverHolder()
michael@0 216 : mTimeInS(0), mPrevNotificationIdle(false)
michael@0 217 {
michael@0 218 MOZ_COUNT_CTOR(IdleObserverHolder);
michael@0 219 }
michael@0 220
michael@0 221 IdleObserverHolder(const IdleObserverHolder& aOther)
michael@0 222 : mIdleObserver(aOther.mIdleObserver), mTimeInS(aOther.mTimeInS),
michael@0 223 mPrevNotificationIdle(aOther.mPrevNotificationIdle)
michael@0 224 {
michael@0 225 MOZ_COUNT_CTOR(IdleObserverHolder);
michael@0 226 }
michael@0 227
michael@0 228 bool operator==(const IdleObserverHolder& aOther) const {
michael@0 229 return
michael@0 230 mIdleObserver == aOther.mIdleObserver &&
michael@0 231 mTimeInS == aOther.mTimeInS;
michael@0 232 }
michael@0 233
michael@0 234 ~IdleObserverHolder()
michael@0 235 {
michael@0 236 MOZ_COUNT_DTOR(IdleObserverHolder);
michael@0 237 }
michael@0 238 };
michael@0 239
michael@0 240 static inline already_AddRefed<nsIVariant>
michael@0 241 CreateVoidVariant()
michael@0 242 {
michael@0 243 nsCOMPtr<nsIWritableVariant> writable =
michael@0 244 do_CreateInstance(NS_VARIANT_CONTRACTID);
michael@0 245 writable->SetAsVoid();
michael@0 246 return writable.forget();
michael@0 247 }
michael@0 248
michael@0 249 // Helper class to manage modal dialog arguments and all their quirks.
michael@0 250 //
michael@0 251 // Given our clunky embedding APIs, modal dialog arguments need to be passed
michael@0 252 // as an nsISupports parameter to WindowWatcher, get stuck inside an array of
michael@0 253 // length 1, and then passed back to the newly-created dialog.
michael@0 254 //
michael@0 255 // However, we need to track both the caller-passed value as well as the
michael@0 256 // caller's, so that we can do an origin check (even for primitives) when the
michael@0 257 // value is accessed. This class encapsulates that magic.
michael@0 258 //
michael@0 259 // We also use the same machinery for |returnValue|, which needs similar origin
michael@0 260 // checks.
michael@0 261 class DialogValueHolder : public nsISupports
michael@0 262 {
michael@0 263 public:
michael@0 264 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 265 NS_DECL_CYCLE_COLLECTION_CLASS(DialogValueHolder)
michael@0 266
michael@0 267 DialogValueHolder(nsIPrincipal* aSubject, nsIVariant* aValue)
michael@0 268 : mOrigin(aSubject)
michael@0 269 , mValue(aValue) {}
michael@0 270 nsresult Get(nsIPrincipal* aSubject, nsIVariant** aResult)
michael@0 271 {
michael@0 272 nsCOMPtr<nsIVariant> result;
michael@0 273 if (aSubject->SubsumesConsideringDomain(mOrigin)) {
michael@0 274 result = mValue;
michael@0 275 } else {
michael@0 276 result = CreateVoidVariant();
michael@0 277 }
michael@0 278 result.forget(aResult);
michael@0 279 return NS_OK;
michael@0 280 }
michael@0 281 void Get(JSContext* aCx, JS::Handle<JSObject*> aScope, nsIPrincipal* aSubject,
michael@0 282 JS::MutableHandle<JS::Value> aResult, mozilla::ErrorResult& aError)
michael@0 283 {
michael@0 284 if (aSubject->Subsumes(mOrigin)) {
michael@0 285 aError = nsContentUtils::XPConnect()->VariantToJS(aCx, aScope,
michael@0 286 mValue, aResult);
michael@0 287 } else {
michael@0 288 aResult.setUndefined();
michael@0 289 }
michael@0 290 }
michael@0 291 virtual ~DialogValueHolder() {}
michael@0 292 private:
michael@0 293 nsCOMPtr<nsIPrincipal> mOrigin;
michael@0 294 nsCOMPtr<nsIVariant> mValue;
michael@0 295 };
michael@0 296
michael@0 297 //*****************************************************************************
michael@0 298 // nsGlobalWindow: Global Object for Scripting
michael@0 299 //*****************************************************************************
michael@0 300 // Beware that all scriptable interfaces implemented by
michael@0 301 // nsGlobalWindow will be reachable from JS, if you make this class
michael@0 302 // implement new interfaces you better know what you're
michael@0 303 // doing. Security wise this is very sensitive code. --
michael@0 304 // jst@netscape.com
michael@0 305
michael@0 306 // nsGlobalWindow inherits PRCList for maintaining a list of all inner
michael@0 307 // windows still in memory for any given outer window. This list is
michael@0 308 // needed to ensure that mOuterWindow doesn't end up dangling. The
michael@0 309 // nature of PRCList means that the window itself is always in the
michael@0 310 // list, and an outer window's list will also contain all inner window
michael@0 311 // objects that are still in memory (and in reality all inner window
michael@0 312 // object's lists also contain its outer and all other inner windows
michael@0 313 // belonging to the same outer window, but that's an unimportant
michael@0 314 // side effect of inheriting PRCList).
michael@0 315
michael@0 316 class nsGlobalWindow : public mozilla::dom::EventTarget,
michael@0 317 public nsPIDOMWindow,
michael@0 318 public nsIScriptGlobalObject,
michael@0 319 public nsIScriptObjectPrincipal,
michael@0 320 public nsIDOMJSWindow,
michael@0 321 public nsSupportsWeakReference,
michael@0 322 public nsIInterfaceRequestor,
michael@0 323 public PRCListStr,
michael@0 324 public nsIDOMWindowPerformance,
michael@0 325 public nsITouchEventReceiver,
michael@0 326 public nsIInlineEventHandlers
michael@0 327 #ifdef MOZ_B2G
michael@0 328 , public nsIDOMWindowB2G
michael@0 329 #endif // MOZ_B2G
michael@0 330 #ifdef MOZ_WEBSPEECH
michael@0 331 , public nsISpeechSynthesisGetter
michael@0 332 #endif // MOZ_WEBSPEECH
michael@0 333 {
michael@0 334 public:
michael@0 335 typedef mozilla::TimeStamp TimeStamp;
michael@0 336 typedef mozilla::TimeDuration TimeDuration;
michael@0 337 typedef nsDataHashtable<nsUint64HashKey, nsGlobalWindow*> WindowByIdTable;
michael@0 338
michael@0 339 // public methods
michael@0 340 nsPIDOMWindow* GetPrivateParent();
michael@0 341 // callback for close event
michael@0 342 void ReallyCloseWindow();
michael@0 343
michael@0 344 // nsISupports
michael@0 345 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
michael@0 346
michael@0 347 // nsWrapperCache
michael@0 348 virtual JSObject *WrapObject(JSContext *cx) MOZ_OVERRIDE
michael@0 349 {
michael@0 350 NS_ASSERTION(IsOuterWindow(),
michael@0 351 "Inner window supports nsWrapperCache, fix WrapObject!");
michael@0 352 return EnsureInnerWindow() ? GetWrapper() : nullptr;
michael@0 353 }
michael@0 354
michael@0 355 // nsIGlobalJSObjectHolder
michael@0 356 virtual JSObject *GetGlobalJSObject();
michael@0 357
michael@0 358 // nsIScriptGlobalObject
michael@0 359 JSObject *FastGetGlobalJSObject() const
michael@0 360 {
michael@0 361 return GetWrapperPreserveColor();
michael@0 362 }
michael@0 363
michael@0 364 void TraceGlobalJSObject(JSTracer* aTrc);
michael@0 365
michael@0 366 virtual nsresult EnsureScriptEnvironment();
michael@0 367
michael@0 368 virtual nsIScriptContext *GetScriptContext();
michael@0 369
michael@0 370 void PoisonOuterWindowProxy(JSObject *aObject);
michael@0 371
michael@0 372 virtual bool IsBlackForCC(bool aTracingNeeded = true);
michael@0 373
michael@0 374 static JSObject* OuterObject(JSContext* aCx, JS::Handle<JSObject*> aObj);
michael@0 375
michael@0 376 // nsIScriptObjectPrincipal
michael@0 377 virtual nsIPrincipal* GetPrincipal();
michael@0 378
michael@0 379 // nsIDOMWindow
michael@0 380 NS_DECL_NSIDOMWINDOW
michael@0 381
michael@0 382 #ifdef MOZ_B2G
michael@0 383 // nsIDOMWindowB2G
michael@0 384 NS_DECL_NSIDOMWINDOWB2G
michael@0 385 #endif // MOZ_B2G
michael@0 386
michael@0 387 #ifdef MOZ_WEBSPEECH
michael@0 388 // nsISpeechSynthesisGetter
michael@0 389 NS_DECL_NSISPEECHSYNTHESISGETTER
michael@0 390 #endif // MOZ_WEBSPEECH
michael@0 391
michael@0 392 // nsIDOMWindowPerformance
michael@0 393 NS_DECL_NSIDOMWINDOWPERFORMANCE
michael@0 394
michael@0 395 // nsIDOMJSWindow
michael@0 396 NS_DECL_NSIDOMJSWINDOW
michael@0 397
michael@0 398 // nsIDOMEventTarget
michael@0 399 NS_DECL_NSIDOMEVENTTARGET
michael@0 400
michael@0 401 virtual mozilla::EventListenerManager*
michael@0 402 GetExistingListenerManager() const MOZ_OVERRIDE;
michael@0 403
michael@0 404 virtual mozilla::EventListenerManager*
michael@0 405 GetOrCreateListenerManager() MOZ_OVERRIDE;
michael@0 406
michael@0 407 using mozilla::dom::EventTarget::RemoveEventListener;
michael@0 408 virtual void AddEventListener(const nsAString& aType,
michael@0 409 mozilla::dom::EventListener* aListener,
michael@0 410 bool aUseCapture,
michael@0 411 const mozilla::dom::Nullable<bool>& aWantsUntrusted,
michael@0 412 mozilla::ErrorResult& aRv) MOZ_OVERRIDE;
michael@0 413 virtual nsIDOMWindow* GetOwnerGlobal() MOZ_OVERRIDE
michael@0 414 {
michael@0 415 if (IsOuterWindow()) {
michael@0 416 return this;
michael@0 417 }
michael@0 418
michael@0 419 return GetOuterFromCurrentInner(this);
michael@0 420 }
michael@0 421
michael@0 422 // nsITouchEventReceiver
michael@0 423 NS_DECL_NSITOUCHEVENTRECEIVER
michael@0 424
michael@0 425 // nsIInlineEventHandlers
michael@0 426 NS_DECL_NSIINLINEEVENTHANDLERS
michael@0 427
michael@0 428 // nsPIDOMWindow
michael@0 429 virtual NS_HIDDEN_(nsPIDOMWindow*) GetPrivateRoot();
michael@0 430
michael@0 431 // Outer windows only.
michael@0 432 virtual NS_HIDDEN_(void) ActivateOrDeactivate(bool aActivate);
michael@0 433 virtual NS_HIDDEN_(void) SetActive(bool aActive);
michael@0 434 virtual NS_HIDDEN_(void) SetIsBackground(bool aIsBackground);
michael@0 435 virtual NS_HIDDEN_(void) SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler);
michael@0 436
michael@0 437 virtual NS_HIDDEN_(void) SetInitialPrincipalToSubject();
michael@0 438
michael@0 439 virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state, bool aForce) const;
michael@0 440 virtual NS_HIDDEN_(void) PopPopupControlState(PopupControlState state) const;
michael@0 441 virtual NS_HIDDEN_(PopupControlState) GetPopupControlState() const;
michael@0 442
michael@0 443 virtual already_AddRefed<nsISupports> SaveWindowState();
michael@0 444 virtual NS_HIDDEN_(nsresult) RestoreWindowState(nsISupports *aState);
michael@0 445 virtual NS_HIDDEN_(void) SuspendTimeouts(uint32_t aIncrease = 1,
michael@0 446 bool aFreezeChildren = true);
michael@0 447 virtual NS_HIDDEN_(nsresult) ResumeTimeouts(bool aThawChildren = true);
michael@0 448 virtual NS_HIDDEN_(uint32_t) TimeoutSuspendCount();
michael@0 449 virtual NS_HIDDEN_(nsresult) FireDelayedDOMEvents();
michael@0 450 virtual NS_HIDDEN_(bool) IsFrozen() const
michael@0 451 {
michael@0 452 return mIsFrozen;
michael@0 453 }
michael@0 454 virtual NS_HIDDEN_(bool) IsRunningTimeout() { return mTimeoutFiringDepth > 0; }
michael@0 455
michael@0 456 virtual NS_HIDDEN_(bool) WouldReuseInnerWindow(nsIDocument *aNewDocument);
michael@0 457
michael@0 458 virtual NS_HIDDEN_(void) SetDocShell(nsIDocShell* aDocShell);
michael@0 459 virtual void DetachFromDocShell();
michael@0 460 virtual NS_HIDDEN_(nsresult) SetNewDocument(nsIDocument *aDocument,
michael@0 461 nsISupports *aState,
michael@0 462 bool aForceReuseInnerWindow);
michael@0 463 void DispatchDOMWindowCreated();
michael@0 464 virtual NS_HIDDEN_(void) SetOpenerWindow(nsIDOMWindow* aOpener,
michael@0 465 bool aOriginalOpener);
michael@0 466
michael@0 467 // Outer windows only.
michael@0 468 virtual NS_HIDDEN_(void) EnsureSizeUpToDate();
michael@0 469
michael@0 470 virtual NS_HIDDEN_(void) EnterModalState();
michael@0 471 virtual NS_HIDDEN_(void) LeaveModalState();
michael@0 472
michael@0 473 virtual NS_HIDDEN_(bool) CanClose();
michael@0 474 virtual NS_HIDDEN_(nsresult) ForceClose();
michael@0 475
michael@0 476 virtual NS_HIDDEN_(void) MaybeUpdateTouchState();
michael@0 477 virtual NS_HIDDEN_(void) UpdateTouchState();
michael@0 478 virtual NS_HIDDEN_(bool) DispatchCustomEvent(const char *aEventName);
michael@0 479 virtual NS_HIDDEN_(bool) DispatchResizeEvent(const nsIntSize& aSize);
michael@0 480 virtual NS_HIDDEN_(void) RefreshCompartmentPrincipal();
michael@0 481 virtual NS_HIDDEN_(nsresult) SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust);
michael@0 482
michael@0 483 virtual NS_HIDDEN_(void) SetHasGamepadEventListener(bool aHasGamepad = true);
michael@0 484
michael@0 485 // nsIInterfaceRequestor
michael@0 486 NS_DECL_NSIINTERFACEREQUESTOR
michael@0 487
michael@0 488 // WebIDL interface.
michael@0 489 already_AddRefed<nsIDOMWindow> IndexedGetter(uint32_t aIndex, bool& aFound);
michael@0 490
michael@0 491 void GetSupportedNames(nsTArray<nsString>& aNames);
michael@0 492
michael@0 493 static bool IsChromeWindow(JSContext* /* unused */, JSObject* aObj);
michael@0 494
michael@0 495 bool IsChrome() const;
michael@0 496
michael@0 497 bool DoNewResolve(JSContext* aCx, JS::Handle<JSObject*> aObj,
michael@0 498 JS::Handle<jsid> aId,
michael@0 499 JS::MutableHandle<JSPropertyDescriptor> aDesc);
michael@0 500
michael@0 501 void GetOwnPropertyNames(JSContext* aCx, nsTArray<nsString>& aNames,
michael@0 502 mozilla::ErrorResult& aRv);
michael@0 503
michael@0 504 // Object Management
michael@0 505 nsGlobalWindow(nsGlobalWindow *aOuterWindow);
michael@0 506
michael@0 507 static nsGlobalWindow *FromSupports(nsISupports *supports)
michael@0 508 {
michael@0 509 // Make sure this matches the casts we do in QueryInterface().
michael@0 510 return (nsGlobalWindow *)(mozilla::dom::EventTarget *)supports;
michael@0 511 }
michael@0 512 static nsGlobalWindow *FromWrapper(nsIXPConnectWrappedNative *wrapper)
michael@0 513 {
michael@0 514 return FromSupports(wrapper->Native());
michael@0 515 }
michael@0 516
michael@0 517 /**
michael@0 518 * Wrap nsIDOMWindow::GetTop so we can overload the inline GetTop()
michael@0 519 * implementation below. (nsIDOMWindow::GetTop simply calls
michael@0 520 * nsIDOMWindow::GetRealTop().)
michael@0 521 */
michael@0 522 nsresult GetTop(nsIDOMWindow **aWindow)
michael@0 523 {
michael@0 524 return nsIDOMWindow::GetTop(aWindow);
michael@0 525 }
michael@0 526
michael@0 527 inline nsGlobalWindow *GetTop()
michael@0 528 {
michael@0 529 nsCOMPtr<nsIDOMWindow> top;
michael@0 530 GetTop(getter_AddRefs(top));
michael@0 531 if (top)
michael@0 532 return static_cast<nsGlobalWindow *>(top.get());
michael@0 533 return nullptr;
michael@0 534 }
michael@0 535
michael@0 536 inline nsGlobalWindow* GetScriptableTop()
michael@0 537 {
michael@0 538 nsCOMPtr<nsIDOMWindow> top;
michael@0 539 GetScriptableTop(getter_AddRefs(top));
michael@0 540 return static_cast<nsGlobalWindow *>(top.get());
michael@0 541 }
michael@0 542
michael@0 543 already_AddRefed<nsIDOMWindow> GetChildWindow(const nsAString& aName);
michael@0 544
michael@0 545 // These return true if we've reached the state in this top level window
michael@0 546 // where we ask the user if further dialogs should be blocked.
michael@0 547 //
michael@0 548 // DialogsAreBeingAbused must be called on the scriptable top inner window.
michael@0 549 //
michael@0 550 // ShouldPromptToBlockDialogs is implemented in terms of
michael@0 551 // DialogsAreBeingAbused, and will get the scriptable top inner window
michael@0 552 // automatically.
michael@0 553 // Outer windows only.
michael@0 554 bool ShouldPromptToBlockDialogs();
michael@0 555 // Inner windows only.
michael@0 556 bool DialogsAreBeingAbused();
michael@0 557
michael@0 558 // These functions are used for controlling and determining whether dialogs
michael@0 559 // (alert, prompt, confirm) are currently allowed in this window.
michael@0 560 void EnableDialogs();
michael@0 561 void DisableDialogs();
michael@0 562 bool AreDialogsEnabled();
michael@0 563
michael@0 564 nsIScriptContext *GetContextInternal()
michael@0 565 {
michael@0 566 if (mOuterWindow) {
michael@0 567 return GetOuterWindowInternal()->mContext;
michael@0 568 }
michael@0 569
michael@0 570 return mContext;
michael@0 571 }
michael@0 572
michael@0 573 nsGlobalWindow *GetOuterWindowInternal()
michael@0 574 {
michael@0 575 return static_cast<nsGlobalWindow *>(GetOuterWindow());
michael@0 576 }
michael@0 577
michael@0 578 nsGlobalWindow *GetCurrentInnerWindowInternal() const
michael@0 579 {
michael@0 580 return static_cast<nsGlobalWindow *>(mInnerWindow);
michael@0 581 }
michael@0 582
michael@0 583 nsGlobalWindow *EnsureInnerWindowInternal()
michael@0 584 {
michael@0 585 return static_cast<nsGlobalWindow *>(EnsureInnerWindow());
michael@0 586 }
michael@0 587
michael@0 588 bool IsCreatingInnerWindow() const
michael@0 589 {
michael@0 590 return mCreatingInnerWindow;
michael@0 591 }
michael@0 592
michael@0 593 bool IsChromeWindow() const
michael@0 594 {
michael@0 595 return mIsChrome;
michael@0 596 }
michael@0 597
michael@0 598 using nsPIDOMWindow::IsModalContentWindow;
michael@0 599 static bool IsModalContentWindow(JSContext* aCx, JSObject* aGlobal);
michael@0 600
michael@0 601 // GetScrollFrame does not flush. Callers should do it themselves as needed,
michael@0 602 // depending on which info they actually want off the scrollable frame.
michael@0 603 nsIScrollableFrame *GetScrollFrame();
michael@0 604
michael@0 605 nsresult Observe(nsISupports* aSubject, const char* aTopic,
michael@0 606 const char16_t* aData);
michael@0 607
michael@0 608 // Outer windows only.
michael@0 609 void UnblockScriptedClosing();
michael@0 610
michael@0 611 static void Init();
michael@0 612 static void ShutDown();
michael@0 613 static void CleanupCachedXBLHandlers(nsGlobalWindow* aWindow);
michael@0 614 static bool IsCallerChrome();
michael@0 615
michael@0 616 static void RunPendingTimeoutsRecursive(nsGlobalWindow *aTopWindow,
michael@0 617 nsGlobalWindow *aWindow);
michael@0 618
michael@0 619 friend class WindowStateHolder;
michael@0 620
michael@0 621 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(nsGlobalWindow,
michael@0 622 nsIDOMEventTarget)
michael@0 623
michael@0 624 #ifdef DEBUG
michael@0 625 // Call Unlink on this window. This may cause bad things to happen, so use
michael@0 626 // with caution.
michael@0 627 void RiskyUnlink();
michael@0 628 #endif
michael@0 629
michael@0 630 virtual NS_HIDDEN_(JSObject*)
michael@0 631 GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey);
michael@0 632
michael@0 633 virtual NS_HIDDEN_(void)
michael@0 634 CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey,
michael@0 635 JS::Handle<JSObject*> aHandler);
michael@0 636
michael@0 637 virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod);
michael@0 638 virtual void SetReadyForFocus();
michael@0 639 virtual void PageHidden();
michael@0 640 virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, nsIURI *aNewURI);
michael@0 641 virtual nsresult DispatchSyncPopState();
michael@0 642
michael@0 643 // Inner windows only.
michael@0 644 virtual void EnableDeviceSensor(uint32_t aType);
michael@0 645 virtual void DisableDeviceSensor(uint32_t aType);
michael@0 646
michael@0 647 virtual void EnableTimeChangeNotifications();
michael@0 648 virtual void DisableTimeChangeNotifications();
michael@0 649
michael@0 650 #ifdef MOZ_B2G
michael@0 651 // Inner windows only.
michael@0 652 virtual void EnableNetworkEvent(uint32_t aType);
michael@0 653 virtual void DisableNetworkEvent(uint32_t aType);
michael@0 654 #endif // MOZ_B2G
michael@0 655
michael@0 656 virtual nsresult SetArguments(nsIArray *aArguments);
michael@0 657
michael@0 658 void MaybeForgiveSpamCount();
michael@0 659 bool IsClosedOrClosing() {
michael@0 660 return (mIsClosed ||
michael@0 661 mInClose ||
michael@0 662 mHavePendingClose ||
michael@0 663 mCleanedUp);
michael@0 664 }
michael@0 665
michael@0 666 static void FirePopupBlockedEvent(nsIDocument* aDoc,
michael@0 667 nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI,
michael@0 668 const nsAString &aPopupWindowName,
michael@0 669 const nsAString &aPopupWindowFeatures);
michael@0 670
michael@0 671 virtual uint32_t GetSerial() {
michael@0 672 return mSerial;
michael@0 673 }
michael@0 674
michael@0 675 static nsGlobalWindow* GetOuterWindowWithId(uint64_t aWindowID) {
michael@0 676 if (!sWindowsById) {
michael@0 677 return nullptr;
michael@0 678 }
michael@0 679
michael@0 680 nsGlobalWindow* outerWindow = sWindowsById->Get(aWindowID);
michael@0 681 return outerWindow && !outerWindow->IsInnerWindow() ? outerWindow : nullptr;
michael@0 682 }
michael@0 683
michael@0 684 static nsGlobalWindow* GetInnerWindowWithId(uint64_t aInnerWindowID) {
michael@0 685 if (!sWindowsById) {
michael@0 686 return nullptr;
michael@0 687 }
michael@0 688
michael@0 689 nsGlobalWindow* innerWindow = sWindowsById->Get(aInnerWindowID);
michael@0 690 return innerWindow && innerWindow->IsInnerWindow() ? innerWindow : nullptr;
michael@0 691 }
michael@0 692
michael@0 693 static WindowByIdTable* GetWindowsTable() {
michael@0 694 return sWindowsById;
michael@0 695 }
michael@0 696
michael@0 697 void AddSizeOfIncludingThis(nsWindowSizes* aWindowSizes) const;
michael@0 698
michael@0 699 void UnmarkGrayTimers();
michael@0 700
michael@0 701 void AddEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
michael@0 702 void RemoveEventTargetObject(mozilla::DOMEventTargetHelper* aObject);
michael@0 703
michael@0 704 void NotifyIdleObserver(IdleObserverHolder* aIdleObserverHolder,
michael@0 705 bool aCallOnidle);
michael@0 706 nsresult HandleIdleActiveEvent();
michael@0 707 bool ContainsIdleObserver(nsIIdleObserver* aIdleObserver, uint32_t timeInS);
michael@0 708 void HandleIdleObserverCallback();
michael@0 709
michael@0 710 void AllowScriptsToClose()
michael@0 711 {
michael@0 712 mAllowScriptsToClose = true;
michael@0 713 }
michael@0 714
michael@0 715 enum SlowScriptResponse {
michael@0 716 ContinueSlowScript = 0,
michael@0 717 AlwaysContinueSlowScript,
michael@0 718 KillSlowScript
michael@0 719 };
michael@0 720 SlowScriptResponse ShowSlowScriptDialog();
michael@0 721
michael@0 722 #ifdef MOZ_GAMEPAD
michael@0 723 void AddGamepad(uint32_t aIndex, mozilla::dom::Gamepad* aGamepad);
michael@0 724 void RemoveGamepad(uint32_t aIndex);
michael@0 725 void GetGamepads(nsTArray<nsRefPtr<mozilla::dom::Gamepad> >& aGamepads);
michael@0 726 already_AddRefed<mozilla::dom::Gamepad> GetGamepad(uint32_t aIndex);
michael@0 727 void SetHasSeenGamepadInput(bool aHasSeen);
michael@0 728 bool HasSeenGamepadInput();
michael@0 729 void SyncGamepadState();
michael@0 730 static PLDHashOperator EnumGamepadsForSync(const uint32_t& aKey,
michael@0 731 mozilla::dom::Gamepad* aData,
michael@0 732 void* aUserArg);
michael@0 733 static PLDHashOperator EnumGamepadsForGet(const uint32_t& aKey,
michael@0 734 mozilla::dom::Gamepad* aData,
michael@0 735 void* aUserArg);
michael@0 736 #endif
michael@0 737
michael@0 738 // Enable/disable updates for gamepad input.
michael@0 739 void EnableGamepadUpdates();
michael@0 740 void DisableGamepadUpdates();
michael@0 741
michael@0 742
michael@0 743 #define EVENT(name_, id_, type_, struct_) \
michael@0 744 mozilla::dom::EventHandlerNonNull* GetOn##name_() \
michael@0 745 { \
michael@0 746 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
michael@0 747 return elm ? elm->GetEventHandler(nsGkAtoms::on##name_, EmptyString()) \
michael@0 748 : nullptr; \
michael@0 749 } \
michael@0 750 void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler) \
michael@0 751 { \
michael@0 752 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
michael@0 753 if (elm) { \
michael@0 754 elm->SetEventHandler(nsGkAtoms::on##name_, EmptyString(), handler); \
michael@0 755 } \
michael@0 756 }
michael@0 757 #define ERROR_EVENT(name_, id_, type_, struct_) \
michael@0 758 mozilla::dom::OnErrorEventHandlerNonNull* GetOn##name_() \
michael@0 759 { \
michael@0 760 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
michael@0 761 return elm ? elm->GetOnErrorEventHandler() : nullptr; \
michael@0 762 } \
michael@0 763 void SetOn##name_(mozilla::dom::OnErrorEventHandlerNonNull* handler) \
michael@0 764 { \
michael@0 765 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
michael@0 766 if (elm) { \
michael@0 767 elm->SetEventHandler(handler); \
michael@0 768 } \
michael@0 769 }
michael@0 770 #define BEFOREUNLOAD_EVENT(name_, id_, type_, struct_) \
michael@0 771 mozilla::dom::OnBeforeUnloadEventHandlerNonNull* GetOn##name_() \
michael@0 772 { \
michael@0 773 mozilla::EventListenerManager* elm = GetExistingListenerManager(); \
michael@0 774 return elm ? elm->GetOnBeforeUnloadEventHandler() : nullptr; \
michael@0 775 } \
michael@0 776 void SetOn##name_(mozilla::dom::OnBeforeUnloadEventHandlerNonNull* handler) \
michael@0 777 { \
michael@0 778 mozilla::EventListenerManager* elm = GetOrCreateListenerManager(); \
michael@0 779 if (elm) { \
michael@0 780 elm->SetEventHandler(handler); \
michael@0 781 } \
michael@0 782 }
michael@0 783 #define WINDOW_ONLY_EVENT EVENT
michael@0 784 #define TOUCH_EVENT EVENT
michael@0 785 #include "mozilla/EventNameList.h"
michael@0 786 #undef TOUCH_EVENT
michael@0 787 #undef WINDOW_ONLY_EVENT
michael@0 788 #undef BEFOREUNLOAD_EVENT
michael@0 789 #undef ERROR_EVENT
michael@0 790 #undef EVENT
michael@0 791
michael@0 792 nsISupports* GetParentObject()
michael@0 793 {
michael@0 794 return nullptr;
michael@0 795 }
michael@0 796
michael@0 797 static bool WindowOnWebIDL(JSContext* /* unused */, JSObject* aObj);
michael@0 798
michael@0 799 nsIDOMWindow* GetWindow(mozilla::ErrorResult& aError);
michael@0 800 nsIDOMWindow* GetSelf(mozilla::ErrorResult& aError);
michael@0 801 nsIDocument* GetDocument()
michael@0 802 {
michael@0 803 return GetDoc();
michael@0 804 }
michael@0 805 void GetName(nsAString& aName, mozilla::ErrorResult& aError);
michael@0 806 void SetName(const nsAString& aName, mozilla::ErrorResult& aError);
michael@0 807 nsIDOMLocation* GetLocation(mozilla::ErrorResult& aError);
michael@0 808 nsHistory* GetHistory(mozilla::ErrorResult& aError);
michael@0 809 mozilla::dom::BarProp* GetLocationbar(mozilla::ErrorResult& aError);
michael@0 810 mozilla::dom::BarProp* GetMenubar(mozilla::ErrorResult& aError);
michael@0 811 mozilla::dom::BarProp* GetPersonalbar(mozilla::ErrorResult& aError);
michael@0 812 mozilla::dom::BarProp* GetScrollbars(mozilla::ErrorResult& aError);
michael@0 813 mozilla::dom::BarProp* GetStatusbar(mozilla::ErrorResult& aError);
michael@0 814 mozilla::dom::BarProp* GetToolbar(mozilla::ErrorResult& aError);
michael@0 815 void GetStatus(nsAString& aStatus, mozilla::ErrorResult& aError);
michael@0 816 void SetStatus(const nsAString& aStatus, mozilla::ErrorResult& aError);
michael@0 817 void Close(mozilla::ErrorResult& aError);
michael@0 818 bool GetClosed(mozilla::ErrorResult& aError);
michael@0 819 void Stop(mozilla::ErrorResult& aError);
michael@0 820 void Focus(mozilla::ErrorResult& aError);
michael@0 821 void Blur(mozilla::ErrorResult& aError);
michael@0 822 already_AddRefed<nsIDOMWindow> GetFrames(mozilla::ErrorResult& aError);
michael@0 823 uint32_t Length();
michael@0 824 already_AddRefed<nsIDOMWindow> GetTop(mozilla::ErrorResult& aError)
michael@0 825 {
michael@0 826 nsCOMPtr<nsIDOMWindow> top;
michael@0 827 aError = GetScriptableTop(getter_AddRefs(top));
michael@0 828 return top.forget();
michael@0 829 }
michael@0 830 protected:
michael@0 831 nsIDOMWindow* GetOpenerWindow(mozilla::ErrorResult& aError);
michael@0 832 public:
michael@0 833 void GetOpener(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
michael@0 834 mozilla::ErrorResult& aError);
michael@0 835 void SetOpener(JSContext* aCx, JS::Handle<JS::Value> aOpener,
michael@0 836 mozilla::ErrorResult& aError);
michael@0 837 using nsIDOMWindow::GetParent;
michael@0 838 already_AddRefed<nsIDOMWindow> GetParent(mozilla::ErrorResult& aError);
michael@0 839 mozilla::dom::Element* GetFrameElement(mozilla::ErrorResult& aError);
michael@0 840 already_AddRefed<nsIDOMWindow> Open(const nsAString& aUrl,
michael@0 841 const nsAString& aName,
michael@0 842 const nsAString& aOptions,
michael@0 843 mozilla::ErrorResult& aError);
michael@0 844 mozilla::dom::Navigator* GetNavigator(mozilla::ErrorResult& aError);
michael@0 845 nsIDOMOfflineResourceList* GetApplicationCache(mozilla::ErrorResult& aError);
michael@0 846
michael@0 847 mozilla::dom::Console* GetConsole(mozilla::ErrorResult& aRv);
michael@0 848
michael@0 849 void GetSidebar(mozilla::dom::OwningExternalOrWindowProxy& aResult,
michael@0 850 mozilla::ErrorResult& aRv);
michael@0 851 already_AddRefed<mozilla::dom::External> GetExternal(mozilla::ErrorResult& aRv);
michael@0 852
michael@0 853 protected:
michael@0 854 bool AlertOrConfirm(bool aAlert, const nsAString& aMessage,
michael@0 855 mozilla::ErrorResult& aError);
michael@0 856
michael@0 857 public:
michael@0 858 void Alert(const nsAString& aMessage, mozilla::ErrorResult& aError);
michael@0 859 bool Confirm(const nsAString& aMessage, mozilla::ErrorResult& aError);
michael@0 860 void Prompt(const nsAString& aMessage, const nsAString& aInitial,
michael@0 861 nsAString& aReturn, mozilla::ErrorResult& aError);
michael@0 862 void Print(mozilla::ErrorResult& aError);
michael@0 863 void ShowModalDialog(JSContext* aCx, const nsAString& aUrl,
michael@0 864 JS::Handle<JS::Value> aArgument,
michael@0 865 const nsAString& aOptions,
michael@0 866 JS::MutableHandle<JS::Value> aRetval,
michael@0 867 mozilla::ErrorResult& aError);
michael@0 868 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
michael@0 869 const nsAString& aTargetOrigin,
michael@0 870 const mozilla::dom::Optional<mozilla::dom::Sequence<JS::Value > >& aTransfer,
michael@0 871 mozilla::ErrorResult& aError);
michael@0 872 int32_t SetTimeout(JSContext* aCx, mozilla::dom::Function& aFunction,
michael@0 873 int32_t aTimeout,
michael@0 874 const mozilla::dom::Sequence<JS::Value>& aArguments,
michael@0 875 mozilla::ErrorResult& aError);
michael@0 876 int32_t SetTimeout(JSContext* aCx, const nsAString& aHandler,
michael@0 877 int32_t aTimeout,
michael@0 878 const mozilla::dom::Sequence<JS::Value>& /* unused */,
michael@0 879 mozilla::ErrorResult& aError);
michael@0 880 void ClearTimeout(int32_t aHandle, mozilla::ErrorResult& aError);
michael@0 881 int32_t SetInterval(JSContext* aCx, mozilla::dom::Function& aFunction,
michael@0 882 const mozilla::dom::Optional<int32_t>& aTimeout,
michael@0 883 const mozilla::dom::Sequence<JS::Value>& aArguments,
michael@0 884 mozilla::ErrorResult& aError);
michael@0 885 int32_t SetInterval(JSContext* aCx, const nsAString& aHandler,
michael@0 886 const mozilla::dom::Optional<int32_t>& aTimeout,
michael@0 887 const mozilla::dom::Sequence<JS::Value>& /* unused */,
michael@0 888 mozilla::ErrorResult& aError);
michael@0 889 void ClearInterval(int32_t aHandle, mozilla::ErrorResult& aError);
michael@0 890 void Atob(const nsAString& aAsciiBase64String, nsAString& aBinaryData,
michael@0 891 mozilla::ErrorResult& aError);
michael@0 892 void Btoa(const nsAString& aBinaryData, nsAString& aAsciiBase64String,
michael@0 893 mozilla::ErrorResult& aError);
michael@0 894 nsIDOMStorage* GetSessionStorage(mozilla::ErrorResult& aError);
michael@0 895 nsIDOMStorage* GetLocalStorage(mozilla::ErrorResult& aError);
michael@0 896 mozilla::dom::Selection* GetSelection(mozilla::ErrorResult& aError);
michael@0 897 mozilla::dom::indexedDB::IDBFactory* GetIndexedDB(mozilla::ErrorResult& aError);
michael@0 898 already_AddRefed<nsICSSDeclaration>
michael@0 899 GetComputedStyle(mozilla::dom::Element& aElt, const nsAString& aPseudoElt,
michael@0 900 mozilla::ErrorResult& aError);
michael@0 901 already_AddRefed<mozilla::dom::MediaQueryList> MatchMedia(const nsAString& aQuery,
michael@0 902 mozilla::ErrorResult& aError);
michael@0 903 nsScreen* GetScreen(mozilla::ErrorResult& aError);
michael@0 904 void MoveTo(int32_t aXPos, int32_t aYPos, mozilla::ErrorResult& aError);
michael@0 905 void MoveBy(int32_t aXDif, int32_t aYDif, mozilla::ErrorResult& aError);
michael@0 906 void ResizeTo(int32_t aWidth, int32_t aHeight,
michael@0 907 mozilla::ErrorResult& aError);
michael@0 908 void ResizeBy(int32_t aWidthDif, int32_t aHeightDif,
michael@0 909 mozilla::ErrorResult& aError);
michael@0 910 int32_t GetInnerWidth(mozilla::ErrorResult& aError);
michael@0 911 void SetInnerWidth(int32_t aInnerWidth, mozilla::ErrorResult& aError);
michael@0 912 int32_t GetInnerHeight(mozilla::ErrorResult& aError);
michael@0 913 void SetInnerHeight(int32_t aInnerHeight, mozilla::ErrorResult& aError);
michael@0 914 int32_t GetScrollX(mozilla::ErrorResult& aError);
michael@0 915 int32_t GetPageXOffset(mozilla::ErrorResult& aError)
michael@0 916 {
michael@0 917 return GetScrollX(aError);
michael@0 918 }
michael@0 919 int32_t GetScrollY(mozilla::ErrorResult& aError);
michael@0 920 int32_t GetPageYOffset(mozilla::ErrorResult& aError)
michael@0 921 {
michael@0 922 return GetScrollY(aError);
michael@0 923 }
michael@0 924 int32_t GetScreenX(mozilla::ErrorResult& aError);
michael@0 925 void SetScreenX(int32_t aScreenX, mozilla::ErrorResult& aError);
michael@0 926 int32_t GetScreenY(mozilla::ErrorResult& aError);
michael@0 927 void SetScreenY(int32_t aScreenY, mozilla::ErrorResult& aError);
michael@0 928 int32_t GetOuterWidth(mozilla::ErrorResult& aError);
michael@0 929 void SetOuterWidth(int32_t aOuterWidth, mozilla::ErrorResult& aError);
michael@0 930 int32_t GetOuterHeight(mozilla::ErrorResult& aError);
michael@0 931 void SetOuterHeight(int32_t aOuterHeight, mozilla::ErrorResult& aError);
michael@0 932 int32_t RequestAnimationFrame(mozilla::dom::FrameRequestCallback& aCallback,
michael@0 933 mozilla::ErrorResult& aError);
michael@0 934 void CancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError);
michael@0 935 nsPerformance* GetPerformance(mozilla::ErrorResult& aError);
michael@0 936 nsresult GetFirstPartyIsolationURI(nsIURI** aFirstPartyIsolationURI);
michael@0 937
michael@0 938 #ifdef MOZ_WEBSPEECH
michael@0 939 mozilla::dom::SpeechSynthesis*
michael@0 940 GetSpeechSynthesis(mozilla::ErrorResult& aError);
michael@0 941 #endif
michael@0 942 already_AddRefed<nsICSSDeclaration>
michael@0 943 GetDefaultComputedStyle(mozilla::dom::Element& aElt,
michael@0 944 const nsAString& aPseudoElt,
michael@0 945 mozilla::ErrorResult& aError);
michael@0 946 mozilla::dom::indexedDB::IDBFactory*
michael@0 947 GetMozIndexedDB(mozilla::ErrorResult& aError)
michael@0 948 {
michael@0 949 return GetIndexedDB(aError);
michael@0 950 }
michael@0 951 int32_t MozRequestAnimationFrame(nsIFrameRequestCallback* aRequestCallback,
michael@0 952 mozilla::ErrorResult& aError);
michael@0 953 void MozCancelAnimationFrame(int32_t aHandle, mozilla::ErrorResult& aError)
michael@0 954 {
michael@0 955 return CancelAnimationFrame(aHandle, aError);
michael@0 956 }
michael@0 957 void MozCancelRequestAnimationFrame(int32_t aHandle,
michael@0 958 mozilla::ErrorResult& aError)
michael@0 959 {
michael@0 960 return CancelAnimationFrame(aHandle, aError);
michael@0 961 }
michael@0 962 int64_t GetMozAnimationStartTime(mozilla::ErrorResult& aError);
michael@0 963 void SizeToContent(mozilla::ErrorResult& aError);
michael@0 964 nsIDOMCrypto* GetCrypto(mozilla::ErrorResult& aError);
michael@0 965 nsIControllers* GetControllers(mozilla::ErrorResult& aError);
michael@0 966 float GetMozInnerScreenX(mozilla::ErrorResult& aError);
michael@0 967 float GetMozInnerScreenY(mozilla::ErrorResult& aError);
michael@0 968 float GetDevicePixelRatio(mozilla::ErrorResult& aError);
michael@0 969 int32_t GetScrollMaxX(mozilla::ErrorResult& aError);
michael@0 970 int32_t GetScrollMaxY(mozilla::ErrorResult& aError);
michael@0 971 bool GetFullScreen(mozilla::ErrorResult& aError);
michael@0 972 void SetFullScreen(bool aFullScreen, mozilla::ErrorResult& aError);
michael@0 973 void Back(mozilla::ErrorResult& aError);
michael@0 974 void Forward(mozilla::ErrorResult& aError);
michael@0 975 void Home(mozilla::ErrorResult& aError);
michael@0 976 bool Find(const nsAString& aString, bool aCaseSensitive, bool aBackwards,
michael@0 977 bool aWrapAround, bool aWholeWord, bool aSearchInFrames,
michael@0 978 bool aShowDialog, mozilla::ErrorResult& aError);
michael@0 979 uint64_t GetMozPaintCount(mozilla::ErrorResult& aError);
michael@0 980 already_AddRefed<nsIDOMWindow> OpenDialog(JSContext* aCx,
michael@0 981 const nsAString& aUrl,
michael@0 982 const nsAString& aName,
michael@0 983 const nsAString& aOptions,
michael@0 984 const mozilla::dom::Sequence<JS::Value>& aExtraArgument,
michael@0 985 mozilla::ErrorResult& aError);
michael@0 986 void GetContent(JSContext* aCx,
michael@0 987 JS::MutableHandle<JSObject*> aRetval,
michael@0 988 mozilla::ErrorResult& aError);
michael@0 989 void Get_content(JSContext* aCx,
michael@0 990 JS::MutableHandle<JSObject*> aRetval,
michael@0 991 mozilla::ErrorResult& aError)
michael@0 992 {
michael@0 993 if (mDoc) {
michael@0 994 mDoc->WarnOnceAbout(nsIDocument::eWindow_Content);
michael@0 995 }
michael@0 996 GetContent(aCx, aRetval, aError);
michael@0 997 }
michael@0 998
michael@0 999 // ChromeWindow bits. Do NOT call these unless your window is in
michael@0 1000 // fact an nsGlobalChromeWindow.
michael@0 1001 uint16_t WindowState();
michael@0 1002 nsIBrowserDOMWindow* GetBrowserDOMWindow(mozilla::ErrorResult& aError);
michael@0 1003 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserWindow,
michael@0 1004 mozilla::ErrorResult& aError);
michael@0 1005 void GetAttention(mozilla::ErrorResult& aError);
michael@0 1006 void GetAttentionWithCycleCount(int32_t aCycleCount,
michael@0 1007 mozilla::ErrorResult& aError);
michael@0 1008 void SetCursor(const nsAString& aCursor, mozilla::ErrorResult& aError);
michael@0 1009 void Maximize(mozilla::ErrorResult& aError);
michael@0 1010 void Minimize(mozilla::ErrorResult& aError);
michael@0 1011 void Restore(mozilla::ErrorResult& aError);
michael@0 1012 void NotifyDefaultButtonLoaded(mozilla::dom::Element& aDefaultButton,
michael@0 1013 mozilla::ErrorResult& aError);
michael@0 1014 nsIMessageBroadcaster* GetMessageManager(mozilla::ErrorResult& aError);
michael@0 1015 void BeginWindowMove(mozilla::dom::Event& aMouseDownEvent,
michael@0 1016 mozilla::dom::Element* aPanel,
michael@0 1017 mozilla::ErrorResult& aError);
michael@0 1018
michael@0 1019 void GetDialogArguments(JSContext* aCx, JS::MutableHandle<JS::Value> aRetval,
michael@0 1020 mozilla::ErrorResult& aError);
michael@0 1021 void GetReturnValue(JSContext* aCx, JS::MutableHandle<JS::Value> aReturnValue,
michael@0 1022 mozilla::ErrorResult& aError);
michael@0 1023 void SetReturnValue(JSContext* aCx, JS::Handle<JS::Value> aReturnValue,
michael@0 1024 mozilla::ErrorResult& aError);
michael@0 1025
michael@0 1026 void GetInterface(JSContext* aCx, nsIJSID* aIID,
michael@0 1027 JS::MutableHandle<JS::Value> aRetval,
michael@0 1028 mozilla::ErrorResult& aError);
michael@0 1029
michael@0 1030 protected:
michael@0 1031 // Array of idle observers that are notified of idle events.
michael@0 1032 nsTObserverArray<IdleObserverHolder> mIdleObservers;
michael@0 1033
michael@0 1034 // Idle timer used for function callbacks to notify idle observers.
michael@0 1035 nsCOMPtr<nsITimer> mIdleTimer;
michael@0 1036
michael@0 1037 // Idle fuzz time added to idle timer callbacks.
michael@0 1038 uint32_t mIdleFuzzFactor;
michael@0 1039
michael@0 1040 // Index in mArrayIdleObservers
michael@0 1041 // Next idle observer to notify user idle status
michael@0 1042 int32_t mIdleCallbackIndex;
michael@0 1043
michael@0 1044 // If false then the topic is "active"
michael@0 1045 // If true then the topic is "idle"
michael@0 1046 bool mCurrentlyIdle;
michael@0 1047
michael@0 1048 // Set to true when a fuzz time needs to be applied
michael@0 1049 // to active notifications to the idle observer.
michael@0 1050 bool mAddActiveEventFuzzTime;
michael@0 1051
michael@0 1052 nsCOMPtr <nsIIdleService> mIdleService;
michael@0 1053
michael@0 1054 nsRefPtr<mozilla::dom::WakeLock> mWakeLock;
michael@0 1055
michael@0 1056 static bool sIdleObserversAPIFuzzTimeDisabled;
michael@0 1057
michael@0 1058 friend class HashchangeCallback;
michael@0 1059 friend class mozilla::dom::BarProp;
michael@0 1060
michael@0 1061 // Object Management
michael@0 1062 virtual ~nsGlobalWindow();
michael@0 1063 void DropOuterWindowDocs();
michael@0 1064 void CleanUp();
michael@0 1065 void ClearControllers();
michael@0 1066 nsresult FinalClose();
michael@0 1067
michael@0 1068 inline void MaybeClearInnerWindow(nsGlobalWindow* aExpectedInner)
michael@0 1069 {
michael@0 1070 if(mInnerWindow == aExpectedInner) {
michael@0 1071 mInnerWindow = nullptr;
michael@0 1072 }
michael@0 1073 }
michael@0 1074
michael@0 1075 void FreeInnerObjects();
michael@0 1076 JSObject *CallerGlobal();
michael@0 1077 nsGlobalWindow *CallerInnerWindow();
michael@0 1078
michael@0 1079 // Only to be called on an inner window.
michael@0 1080 // aDocument must not be null.
michael@0 1081 void InnerSetNewDocument(JSContext* aCx, nsIDocument* aDocument);
michael@0 1082
michael@0 1083 nsresult DefineArgumentsProperty(nsIArray *aArguments);
michael@0 1084
michael@0 1085 // Get the parent, returns null if this is a toplevel window
michael@0 1086 nsIDOMWindow* GetParentInternal();
michael@0 1087
michael@0 1088 // popup tracking
michael@0 1089 bool IsPopupSpamWindow()
michael@0 1090 {
michael@0 1091 if (IsInnerWindow() && !mOuterWindow) {
michael@0 1092 return false;
michael@0 1093 }
michael@0 1094
michael@0 1095 return GetOuterWindowInternal()->mIsPopupSpam;
michael@0 1096 }
michael@0 1097
michael@0 1098 void SetPopupSpamWindow(bool aPopup)
michael@0 1099 {
michael@0 1100 if (IsInnerWindow() && !mOuterWindow) {
michael@0 1101 NS_ERROR("SetPopupSpamWindow() called on inner window w/o an outer!");
michael@0 1102
michael@0 1103 return;
michael@0 1104 }
michael@0 1105
michael@0 1106 GetOuterWindowInternal()->mIsPopupSpam = aPopup;
michael@0 1107 }
michael@0 1108
michael@0 1109 // Window Control Functions
michael@0 1110
michael@0 1111 virtual nsresult
michael@0 1112 OpenNoNavigate(const nsAString& aUrl,
michael@0 1113 const nsAString& aName,
michael@0 1114 const nsAString& aOptions,
michael@0 1115 nsIDOMWindow **_retval);
michael@0 1116
michael@0 1117 /**
michael@0 1118 * @param aUrl the URL we intend to load into the window. If aNavigate is
michael@0 1119 * true, we'll actually load this URL into the window. Otherwise,
michael@0 1120 * aUrl is advisory; OpenInternal will not load the URL into the
michael@0 1121 * new window.
michael@0 1122 *
michael@0 1123 * @param aName the name to use for the new window
michael@0 1124 *
michael@0 1125 * @param aOptions the window options to use for the new window
michael@0 1126 *
michael@0 1127 * @param aDialog true when called from variants of OpenDialog. If this is
michael@0 1128 * true, this method will skip popup blocking checks. The aDialog
michael@0 1129 * argument is passed on to the window watcher.
michael@0 1130 *
michael@0 1131 * @param aCalledNoScript true when called via the [noscript] open()
michael@0 1132 * and openDialog() methods. When this is true, we do NOT want to use
michael@0 1133 * the JS stack for things like caller determination.
michael@0 1134 *
michael@0 1135 * @param aDoJSFixups true when this is the content-accessible JS version of
michael@0 1136 * window opening. When true, popups do not cause us to throw, we save
michael@0 1137 * the caller's principal in the new window for later consumption, and
michael@0 1138 * we make sure that there is a document in the newly-opened window.
michael@0 1139 * Note that this last will only be done if the newly-opened window is
michael@0 1140 * non-chrome.
michael@0 1141 *
michael@0 1142 * @param aNavigate true if we should navigate to the provided URL, false
michael@0 1143 * otherwise. When aNavigate is false, we also skip our can-load
michael@0 1144 * security check, on the assumption that whoever *actually* loads this
michael@0 1145 * page will do their own security check.
michael@0 1146 *
michael@0 1147 * @param argv The arguments to pass to the new window. The first
michael@0 1148 * three args, if present, will be aUrl, aName, and aOptions. So this
michael@0 1149 * param only matters if there are more than 3 arguments.
michael@0 1150 *
michael@0 1151 * @param argc The number of arguments in argv.
michael@0 1152 *
michael@0 1153 * @param aExtraArgument Another way to pass arguments in. This is mutually
michael@0 1154 * exclusive with the argv/argc approach.
michael@0 1155 *
michael@0 1156 * @param aJSCallerContext The calling script's context. This must be null
michael@0 1157 * when aCalledNoScript is true.
michael@0 1158 *
michael@0 1159 * @param aReturn [out] The window that was opened, if any.
michael@0 1160 */
michael@0 1161 NS_HIDDEN_(nsresult) OpenInternal(const nsAString& aUrl,
michael@0 1162 const nsAString& aName,
michael@0 1163 const nsAString& aOptions,
michael@0 1164 bool aDialog,
michael@0 1165 bool aContentModal,
michael@0 1166 bool aCalledNoScript,
michael@0 1167 bool aDoJSFixups,
michael@0 1168 bool aNavigate,
michael@0 1169 nsIArray *argv,
michael@0 1170 nsISupports *aExtraArgument,
michael@0 1171 nsIPrincipal *aCalleePrincipal,
michael@0 1172 JSContext *aJSCallerContext,
michael@0 1173 nsIDOMWindow **aReturn);
michael@0 1174
michael@0 1175 // Timeout Functions
michael@0 1176 // Language agnostic timeout function (all args passed).
michael@0 1177 // |interval| is in milliseconds.
michael@0 1178 nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler,
michael@0 1179 int32_t interval,
michael@0 1180 bool aIsInterval, int32_t *aReturn);
michael@0 1181 int32_t SetTimeoutOrInterval(mozilla::dom::Function& aFunction,
michael@0 1182 int32_t aTimeout,
michael@0 1183 const mozilla::dom::Sequence<JS::Value>& aArguments,
michael@0 1184 bool aIsInterval, mozilla::ErrorResult& aError);
michael@0 1185 int32_t SetTimeoutOrInterval(JSContext* aCx, const nsAString& aHandler,
michael@0 1186 int32_t aTimeout, bool aIsInterval,
michael@0 1187 mozilla::ErrorResult& aError);
michael@0 1188 void ClearTimeoutOrInterval(int32_t aTimerID,
michael@0 1189 mozilla::ErrorResult& aError);
michael@0 1190 nsresult ClearTimeoutOrInterval(int32_t aTimerID)
michael@0 1191 {
michael@0 1192 mozilla::ErrorResult rv;
michael@0 1193 ClearTimeoutOrInterval(aTimerID, rv);
michael@0 1194 return rv.ErrorCode();
michael@0 1195 }
michael@0 1196
michael@0 1197 // JS specific timeout functions (JS args grabbed from context).
michael@0 1198 nsresult SetTimeoutOrInterval(bool aIsInterval, int32_t* aReturn);
michael@0 1199 nsresult ResetTimersForNonBackgroundWindow();
michael@0 1200
michael@0 1201 // The timeout implementation functions.
michael@0 1202 void RunTimeout(nsTimeout *aTimeout);
michael@0 1203 void RunTimeout() { RunTimeout(nullptr); }
michael@0 1204 // Return true if |aTimeout| was cleared while its handler ran.
michael@0 1205 bool RunTimeoutHandler(nsTimeout* aTimeout, nsIScriptContext* aScx);
michael@0 1206 // Return true if |aTimeout| needs to be reinserted into the timeout list.
michael@0 1207 bool RescheduleTimeout(nsTimeout* aTimeout, const TimeStamp& now,
michael@0 1208 bool aRunningPendingTimeouts);
michael@0 1209
michael@0 1210 void ClearAllTimeouts();
michael@0 1211 // Insert aTimeout into the list, before all timeouts that would
michael@0 1212 // fire after it, but no earlier than mTimeoutInsertionPoint, if any.
michael@0 1213 void InsertTimeoutIntoList(nsTimeout *aTimeout);
michael@0 1214 static void TimerCallback(nsITimer *aTimer, void *aClosure);
michael@0 1215
michael@0 1216 // Helper Functions
michael@0 1217 already_AddRefed<nsIDocShellTreeOwner> GetTreeOwner();
michael@0 1218 already_AddRefed<nsIBaseWindow> GetTreeOwnerWindow();
michael@0 1219 already_AddRefed<nsIWebBrowserChrome> GetWebBrowserChrome();
michael@0 1220 nsresult SecurityCheckURL(const char *aURL);
michael@0 1221
michael@0 1222 bool PopupWhitelisted();
michael@0 1223 PopupControlState RevisePopupAbuseLevel(PopupControlState);
michael@0 1224 void FireAbuseEvents(bool aBlocked, bool aWindow,
michael@0 1225 const nsAString &aPopupURL,
michael@0 1226 const nsAString &aPopupWindowName,
michael@0 1227 const nsAString &aPopupWindowFeatures);
michael@0 1228 void FireOfflineStatusEvent();
michael@0 1229
michael@0 1230 // Inner windows only.
michael@0 1231 nsresult ScheduleNextIdleObserverCallback();
michael@0 1232 uint32_t GetFuzzTimeMS();
michael@0 1233 nsresult ScheduleActiveTimerCallback();
michael@0 1234 uint32_t FindInsertionIndex(IdleObserverHolder* aIdleObserver);
michael@0 1235 virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserverPtr);
michael@0 1236 nsresult FindIndexOfElementToRemove(nsIIdleObserver* aIdleObserver,
michael@0 1237 int32_t* aRemoveElementIndex);
michael@0 1238 virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserverPtr);
michael@0 1239
michael@0 1240 // Inner windows only.
michael@0 1241 nsresult FireHashchange(const nsAString &aOldURL, const nsAString &aNewURL);
michael@0 1242
michael@0 1243 void FlushPendingNotifications(mozFlushType aType);
michael@0 1244
michael@0 1245 // Outer windows only.
michael@0 1246 void EnsureReflowFlushAndPaint();
michael@0 1247 void CheckSecurityWidthAndHeight(int32_t* width, int32_t* height);
michael@0 1248 void CheckSecurityLeftAndTop(int32_t* left, int32_t* top);
michael@0 1249
michael@0 1250 // Outer windows only.
michael@0 1251 // Arguments to this function should have values in app units
michael@0 1252 void SetCSSViewportWidthAndHeight(nscoord width, nscoord height);
michael@0 1253 // Arguments to this function should have values in device pixels
michael@0 1254 nsresult SetDocShellWidthAndHeight(int32_t width, int32_t height);
michael@0 1255
michael@0 1256 static bool CanSetProperty(const char *aPrefName);
michael@0 1257
michael@0 1258 static void MakeScriptDialogTitle(nsAString &aOutTitle);
michael@0 1259
michael@0 1260 // Outer windows only.
michael@0 1261 bool CanMoveResizeWindows();
michael@0 1262
michael@0 1263 // If aDoFlush is true, we'll flush our own layout; otherwise we'll try to
michael@0 1264 // just flush our parent and only flush ourselves if we think we need to.
michael@0 1265 mozilla::CSSIntPoint GetScrollXY(bool aDoFlush, mozilla::ErrorResult& aError);
michael@0 1266 nsresult GetScrollXY(int32_t* aScrollX, int32_t* aScrollY, bool aDoFlush);
michael@0 1267 void GetScrollMaxXY(int32_t* aScrollMaxX, int32_t* aScrollMaxY,
michael@0 1268 mozilla::ErrorResult& aError);
michael@0 1269
michael@0 1270 // Outer windows only.
michael@0 1271 nsresult GetInnerSize(mozilla::CSSIntSize& aSize);
michael@0 1272 nsIntSize GetOuterSize(mozilla::ErrorResult& aError);
michael@0 1273 void SetOuterSize(int32_t aLengthCSSPixels, bool aIsWidth,
michael@0 1274 mozilla::ErrorResult& aError);
michael@0 1275 nsRect GetInnerScreenRect();
michael@0 1276
michael@0 1277 void ScrollTo(const mozilla::CSSIntPoint& aScroll);
michael@0 1278
michael@0 1279 bool IsFrame()
michael@0 1280 {
michael@0 1281 return GetParentInternal() != nullptr;
michael@0 1282 }
michael@0 1283
michael@0 1284 // Outer windows only.
michael@0 1285 // If aLookForCallerOnJSStack is true, this method will look at the JS stack
michael@0 1286 // to determine who the caller is. If it's false, it'll use |this| as the
michael@0 1287 // caller.
michael@0 1288 bool WindowExists(const nsAString& aName, bool aLookForCallerOnJSStack);
michael@0 1289
michael@0 1290 already_AddRefed<nsIWidget> GetMainWidget();
michael@0 1291 nsIWidget* GetNearestWidget();
michael@0 1292
michael@0 1293 void Freeze()
michael@0 1294 {
michael@0 1295 NS_ASSERTION(!IsFrozen(), "Double-freezing?");
michael@0 1296 mIsFrozen = true;
michael@0 1297 NotifyDOMWindowFrozen(this);
michael@0 1298 }
michael@0 1299
michael@0 1300 void Thaw()
michael@0 1301 {
michael@0 1302 mIsFrozen = false;
michael@0 1303 NotifyDOMWindowThawed(this);
michael@0 1304 }
michael@0 1305
michael@0 1306 bool IsInModalState();
michael@0 1307
michael@0 1308 // Convenience functions for the many methods that need to scale
michael@0 1309 // from device to CSS pixels or vice versa. Note: if a presentation
michael@0 1310 // context is not available, they will assume a 1:1 ratio.
michael@0 1311 int32_t DevToCSSIntPixels(int32_t px);
michael@0 1312 int32_t CSSToDevIntPixels(int32_t px);
michael@0 1313 nsIntSize DevToCSSIntPixels(nsIntSize px);
michael@0 1314 nsIntSize CSSToDevIntPixels(nsIntSize px);
michael@0 1315
michael@0 1316 virtual void SetFocusedNode(nsIContent* aNode,
michael@0 1317 uint32_t aFocusMethod = 0,
michael@0 1318 bool aNeedsFocus = false);
michael@0 1319
michael@0 1320 virtual uint32_t GetFocusMethod();
michael@0 1321
michael@0 1322 virtual bool ShouldShowFocusRing();
michael@0 1323
michael@0 1324 virtual void SetKeyboardIndicators(UIStateChangeType aShowAccelerators,
michael@0 1325 UIStateChangeType aShowFocusRings);
michael@0 1326 virtual void GetKeyboardIndicators(bool* aShowAccelerators,
michael@0 1327 bool* aShowFocusRings);
michael@0 1328
michael@0 1329 // Inner windows only.
michael@0 1330 void UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent);
michael@0 1331
michael@0 1332 public:
michael@0 1333 virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() MOZ_OVERRIDE;
michael@0 1334
michael@0 1335 protected:
michael@0 1336 static void NotifyDOMWindowDestroyed(nsGlobalWindow* aWindow);
michael@0 1337 void NotifyWindowIDDestroyed(const char* aTopic);
michael@0 1338
michael@0 1339 static void NotifyDOMWindowFrozen(nsGlobalWindow* aWindow);
michael@0 1340 static void NotifyDOMWindowThawed(nsGlobalWindow* aWindow);
michael@0 1341
michael@0 1342 void ClearStatus();
michael@0 1343
michael@0 1344 virtual void UpdateParentTarget();
michael@0 1345
michael@0 1346 inline int32_t DOMMinTimeoutValue() const;
michael@0 1347
michael@0 1348 nsresult CloneStorageEvent(const nsAString& aType,
michael@0 1349 nsCOMPtr<nsIDOMStorageEvent>& aEvent);
michael@0 1350
michael@0 1351 // Outer windows only.
michael@0 1352 nsDOMWindowList* GetWindowList();
michael@0 1353
michael@0 1354 // Helper for getComputedStyle and getDefaultComputedStyle
michael@0 1355 already_AddRefed<nsICSSDeclaration>
michael@0 1356 GetComputedStyleHelper(mozilla::dom::Element& aElt,
michael@0 1357 const nsAString& aPseudoElt,
michael@0 1358 bool aDefaultStylesOnly,
michael@0 1359 mozilla::ErrorResult& aError);
michael@0 1360 nsresult GetComputedStyleHelper(nsIDOMElement* aElt,
michael@0 1361 const nsAString& aPseudoElt,
michael@0 1362 bool aDefaultStylesOnly,
michael@0 1363 nsIDOMCSSStyleDeclaration** aReturn);
michael@0 1364
michael@0 1365 void PreloadLocalStorage();
michael@0 1366
michael@0 1367 // Returns device pixels. Outer windows only.
michael@0 1368 nsIntPoint GetScreenXY(mozilla::ErrorResult& aError);
michael@0 1369
michael@0 1370 int32_t RequestAnimationFrame(const nsIDocument::FrameRequestCallbackHolder& aCallback,
michael@0 1371 mozilla::ErrorResult& aError);
michael@0 1372
michael@0 1373 nsGlobalWindow* InnerForSetTimeoutOrInterval(mozilla::ErrorResult& aError);
michael@0 1374
michael@0 1375 mozilla::dom::Element* GetRealFrameElement(mozilla::ErrorResult& aError);
michael@0 1376
michael@0 1377 void PostMessageMoz(JSContext* aCx, JS::Handle<JS::Value> aMessage,
michael@0 1378 const nsAString& aTargetOrigin,
michael@0 1379 JS::Handle<JS::Value> aTransfer,
michael@0 1380 mozilla::ErrorResult& aError);
michael@0 1381
michael@0 1382 already_AddRefed<nsIVariant>
michael@0 1383 ShowModalDialog(const nsAString& aUrl, nsIVariant* aArgument,
michael@0 1384 const nsAString& aOptions, mozilla::ErrorResult& aError);
michael@0 1385
michael@0 1386 already_AddRefed<nsIDOMWindow>
michael@0 1387 GetContentInternal(mozilla::ErrorResult& aError);
michael@0 1388
michael@0 1389 // Ask the user if further dialogs should be blocked, if dialogs are currently
michael@0 1390 // being abused. This is used in the cases where we have no modifiable UI to
michael@0 1391 // show, in that case we show a separate dialog to ask this question.
michael@0 1392 bool ConfirmDialogIfNeeded();
michael@0 1393
michael@0 1394 // When adding new member variables, be careful not to create cycles
michael@0 1395 // through JavaScript. If there is any chance that a member variable
michael@0 1396 // could own objects that are implemented in JavaScript, then those
michael@0 1397 // objects will keep the global object (this object) alive. To prevent
michael@0 1398 // these cycles, ownership of such members must be released in
michael@0 1399 // |CleanUp| and |DetachFromDocShell|.
michael@0 1400
michael@0 1401 // This member is also used on both inner and outer windows, but
michael@0 1402 // for slightly different purposes. On inner windows it means the
michael@0 1403 // inner window is held onto by session history and should not
michael@0 1404 // change. On outer windows it means that the window is in a state
michael@0 1405 // where we don't want to force creation of a new inner window since
michael@0 1406 // we're in the middle of doing just that.
michael@0 1407 bool mIsFrozen : 1;
michael@0 1408
michael@0 1409 // These members are only used on outer window objects. Make sure
michael@0 1410 // you never set any of these on an inner object!
michael@0 1411 bool mFullScreen : 1;
michael@0 1412 bool mIsClosed : 1;
michael@0 1413 bool mInClose : 1;
michael@0 1414 // mHavePendingClose means we've got a termination function set to
michael@0 1415 // close us when the JS stops executing or that we have a close
michael@0 1416 // event posted. If this is set, just ignore window.close() calls.
michael@0 1417 bool mHavePendingClose : 1;
michael@0 1418 bool mHadOriginalOpener : 1;
michael@0 1419 bool mIsPopupSpam : 1;
michael@0 1420
michael@0 1421 // Indicates whether scripts are allowed to close this window.
michael@0 1422 bool mBlockScriptedClosingFlag : 1;
michael@0 1423
michael@0 1424 // Track what sorts of events we need to fire when thawed
michael@0 1425 bool mFireOfflineStatusChangeEventOnThaw : 1;
michael@0 1426 bool mNotifyIdleObserversIdleOnThaw : 1;
michael@0 1427 bool mNotifyIdleObserversActiveOnThaw : 1;
michael@0 1428
michael@0 1429 // Indicates whether we're in the middle of creating an initializing
michael@0 1430 // a new inner window object.
michael@0 1431 bool mCreatingInnerWindow : 1;
michael@0 1432
michael@0 1433 // Fast way to tell if this is a chrome window (without having to QI).
michael@0 1434 bool mIsChrome : 1;
michael@0 1435
michael@0 1436 // Hack to indicate whether a chrome window needs its message manager
michael@0 1437 // to be disconnected, since clean up code is shared in the global
michael@0 1438 // window superclass.
michael@0 1439 bool mCleanMessageManager : 1;
michael@0 1440
michael@0 1441 // Indicates that the current document has never received a document focus
michael@0 1442 // event.
michael@0 1443 bool mNeedsFocus : 1;
michael@0 1444 bool mHasFocus : 1;
michael@0 1445
michael@0 1446 // whether to show keyboard accelerators
michael@0 1447 bool mShowAccelerators : 1;
michael@0 1448
michael@0 1449 // whether to show focus rings
michael@0 1450 bool mShowFocusRings : 1;
michael@0 1451
michael@0 1452 // when true, show focus rings for the current focused content only.
michael@0 1453 // This will be reset when another element is focused
michael@0 1454 bool mShowFocusRingForContent : 1;
michael@0 1455
michael@0 1456 // true if tab navigation has occurred for this window. Focus rings
michael@0 1457 // should be displayed.
michael@0 1458 bool mFocusByKeyOccurred : 1;
michael@0 1459
michael@0 1460 // Ensure that a call to ResumeTimeouts() after FreeInnerObjects() does nothing.
michael@0 1461 // This member is only used by inner windows.
michael@0 1462 bool mInnerObjectsFreed : 1;
michael@0 1463
michael@0 1464 // Indicates whether this window wants gamepad input events
michael@0 1465 bool mHasGamepad : 1;
michael@0 1466 #ifdef MOZ_GAMEPAD
michael@0 1467 nsRefPtrHashtable<nsUint32HashKey, mozilla::dom::Gamepad> mGamepads;
michael@0 1468 bool mHasSeenGamepadInput;
michael@0 1469 #endif
michael@0 1470
michael@0 1471 // whether we've sent the destroy notification for our window id
michael@0 1472 bool mNotifiedIDDestroyed : 1;
michael@0 1473 // whether scripts may close the window,
michael@0 1474 // even if "dom.allow_scripts_to_close_windows" is false.
michael@0 1475 bool mAllowScriptsToClose : 1;
michael@0 1476
michael@0 1477 nsCOMPtr<nsIScriptContext> mContext;
michael@0 1478 nsWeakPtr mOpener;
michael@0 1479 nsCOMPtr<nsIControllers> mControllers;
michael@0 1480
michael@0 1481 // For |window.arguments|, via |openDialog|.
michael@0 1482 nsCOMPtr<nsIArray> mArguments;
michael@0 1483
michael@0 1484 // For |window.dialogArguments|, via |showModalDialog|.
michael@0 1485 nsRefPtr<DialogValueHolder> mDialogArguments;
michael@0 1486
michael@0 1487 // Only used in the outer.
michael@0 1488 nsRefPtr<DialogValueHolder> mReturnValue;
michael@0 1489
michael@0 1490 nsRefPtr<mozilla::dom::Navigator> mNavigator;
michael@0 1491 nsRefPtr<nsScreen> mScreen;
michael@0 1492 nsRefPtr<nsDOMWindowList> mFrames;
michael@0 1493 nsRefPtr<mozilla::dom::BarProp> mMenubar;
michael@0 1494 nsRefPtr<mozilla::dom::BarProp> mToolbar;
michael@0 1495 nsRefPtr<mozilla::dom::BarProp> mLocationbar;
michael@0 1496 nsRefPtr<mozilla::dom::BarProp> mPersonalbar;
michael@0 1497 nsRefPtr<mozilla::dom::BarProp> mStatusbar;
michael@0 1498 nsRefPtr<mozilla::dom::BarProp> mScrollbars;
michael@0 1499 nsRefPtr<nsDOMWindowUtils> mWindowUtils;
michael@0 1500 nsString mStatus;
michael@0 1501 nsString mDefaultStatus;
michael@0 1502 nsGlobalWindowObserver* mObserver; // Inner windows only.
michael@0 1503 nsCOMPtr<nsIDOMCrypto> mCrypto;
michael@0 1504 nsRefPtr<mozilla::dom::Console> mConsole;
michael@0 1505 // We need to store an nsISupports pointer to this object because the
michael@0 1506 // mozilla::dom::External class doesn't exist on b2g and using the type
michael@0 1507 // forward declared here means that ~nsGlobalWindow wouldn't compile because
michael@0 1508 // it wouldn't see the ~External function's declaration.
michael@0 1509 nsCOMPtr<nsISupports> mExternal;
michael@0 1510
michael@0 1511 nsCOMPtr<nsIDOMStorage> mLocalStorage;
michael@0 1512 nsCOMPtr<nsIDOMStorage> mSessionStorage;
michael@0 1513
michael@0 1514 // These member variable are used only on inner windows.
michael@0 1515 nsRefPtr<mozilla::EventListenerManager> mListenerManager;
michael@0 1516 // mTimeouts is generally sorted by mWhen, unless mTimeoutInsertionPoint is
michael@0 1517 // non-null. In that case, the dummy timeout pointed to by
michael@0 1518 // mTimeoutInsertionPoint may have a later mWhen than some of the timeouts
michael@0 1519 // that come after it.
michael@0 1520 mozilla::LinkedList<nsTimeout> mTimeouts;
michael@0 1521 // If mTimeoutInsertionPoint is non-null, insertions should happen after it.
michael@0 1522 // This is a dummy timeout at the moment; if that ever changes, the logic in
michael@0 1523 // ResetTimersForNonBackgroundWindow needs to change.
michael@0 1524 nsTimeout* mTimeoutInsertionPoint;
michael@0 1525 uint32_t mTimeoutPublicIdCounter;
michael@0 1526 uint32_t mTimeoutFiringDepth;
michael@0 1527 nsRefPtr<nsLocation> mLocation;
michael@0 1528 nsRefPtr<nsHistory> mHistory;
michael@0 1529
michael@0 1530 // These member variables are used on both inner and the outer windows.
michael@0 1531 nsCOMPtr<nsIPrincipal> mDocumentPrincipal;
michael@0 1532
michael@0 1533 typedef nsCOMArray<nsIDOMStorageEvent> nsDOMStorageEventArray;
michael@0 1534 nsDOMStorageEventArray mPendingStorageEvents;
michael@0 1535
michael@0 1536 uint32_t mTimeoutsSuspendDepth;
michael@0 1537
michael@0 1538 // the method that was used to focus mFocusedNode
michael@0 1539 uint32_t mFocusMethod;
michael@0 1540
michael@0 1541 uint32_t mSerial;
michael@0 1542
michael@0 1543 #ifdef DEBUG
michael@0 1544 bool mSetOpenerWindowCalled;
michael@0 1545 nsCOMPtr<nsIURI> mLastOpenedURI;
michael@0 1546 #endif
michael@0 1547
michael@0 1548 #ifdef MOZ_B2G
michael@0 1549 bool mNetworkUploadObserverEnabled;
michael@0 1550 bool mNetworkDownloadObserverEnabled;
michael@0 1551 #endif // MOZ_B2G
michael@0 1552
michael@0 1553 bool mCleanedUp;
michael@0 1554
michael@0 1555 nsCOMPtr<nsIDOMOfflineResourceList> mApplicationCache;
michael@0 1556
michael@0 1557 nsAutoPtr<nsJSThingHashtable<nsPtrHashKey<nsXBLPrototypeHandler>, JSObject*> > mCachedXBLPrototypeHandlers;
michael@0 1558
michael@0 1559 // mSuspendedDoc is only set on outer windows. It's useful when we get matched
michael@0 1560 // EnterModalState/LeaveModalState calls, in which case the outer window is
michael@0 1561 // responsible for unsuspending events on the document. If we don't (for
michael@0 1562 // example, if the outer window is closed before the LeaveModalState call),
michael@0 1563 // then the inner window whose mDoc is our mSuspendedDoc is responsible for
michael@0 1564 // unsuspending it.
michael@0 1565 nsCOMPtr<nsIDocument> mSuspendedDoc;
michael@0 1566
michael@0 1567 nsRefPtr<mozilla::dom::indexedDB::IDBFactory> mIndexedDB;
michael@0 1568
michael@0 1569 // This counts the number of windows that have been opened in rapid succession
michael@0 1570 // (i.e. within dom.successive_dialog_time_limit of each other). It is reset
michael@0 1571 // to 0 once a dialog is opened after dom.successive_dialog_time_limit seconds
michael@0 1572 // have elapsed without any other dialogs.
michael@0 1573 uint32_t mDialogAbuseCount;
michael@0 1574
michael@0 1575 // This holds the time when the last modal dialog was shown. If more than
michael@0 1576 // MAX_DIALOG_LIMIT dialogs are shown within the time span defined by
michael@0 1577 // dom.successive_dialog_time_limit, we show a checkbox or confirmation prompt
michael@0 1578 // to allow disabling of further dialogs from this window.
michael@0 1579 TimeStamp mLastDialogQuitTime;
michael@0 1580
michael@0 1581 // This flag keeps track of whether dialogs are
michael@0 1582 // currently enabled on this window.
michael@0 1583 bool mAreDialogsEnabled;
michael@0 1584
michael@0 1585 nsTHashtable<nsPtrHashKey<mozilla::DOMEventTargetHelper> > mEventTargetObjects;
michael@0 1586
michael@0 1587 nsTArray<uint32_t> mEnabledSensors;
michael@0 1588
michael@0 1589 #ifdef MOZ_WEBSPEECH
michael@0 1590 // mSpeechSynthesis is only used on inner windows.
michael@0 1591 nsRefPtr<mozilla::dom::SpeechSynthesis> mSpeechSynthesis;
michael@0 1592 #endif
michael@0 1593
michael@0 1594 friend class nsDOMScriptableHelper;
michael@0 1595 friend class nsDOMWindowUtils;
michael@0 1596 friend class PostMessageEvent;
michael@0 1597 friend class DesktopNotification;
michael@0 1598
michael@0 1599 static WindowByIdTable* sWindowsById;
michael@0 1600 static bool sWarnedAboutWindowInternal;
michael@0 1601 };
michael@0 1602
michael@0 1603 inline nsISupports*
michael@0 1604 ToSupports(nsGlobalWindow *p)
michael@0 1605 {
michael@0 1606 return static_cast<nsIDOMEventTarget*>(p);
michael@0 1607 }
michael@0 1608
michael@0 1609 inline nsISupports*
michael@0 1610 ToCanonicalSupports(nsGlobalWindow *p)
michael@0 1611 {
michael@0 1612 return static_cast<nsIDOMEventTarget*>(p);
michael@0 1613 }
michael@0 1614
michael@0 1615 /*
michael@0 1616 * nsGlobalChromeWindow inherits from nsGlobalWindow. It is the global
michael@0 1617 * object created for a Chrome Window only.
michael@0 1618 */
michael@0 1619 class nsGlobalChromeWindow : public nsGlobalWindow,
michael@0 1620 public nsIDOMChromeWindow
michael@0 1621 {
michael@0 1622 public:
michael@0 1623 // nsISupports
michael@0 1624 NS_DECL_ISUPPORTS_INHERITED
michael@0 1625
michael@0 1626 // nsIDOMChromeWindow interface
michael@0 1627 NS_DECL_NSIDOMCHROMEWINDOW
michael@0 1628
michael@0 1629 nsGlobalChromeWindow(nsGlobalWindow *aOuterWindow)
michael@0 1630 : nsGlobalWindow(aOuterWindow)
michael@0 1631 {
michael@0 1632 mIsChrome = true;
michael@0 1633 mCleanMessageManager = true;
michael@0 1634 }
michael@0 1635
michael@0 1636 ~nsGlobalChromeWindow()
michael@0 1637 {
michael@0 1638 NS_ABORT_IF_FALSE(mCleanMessageManager,
michael@0 1639 "chrome windows may always disconnect the msg manager");
michael@0 1640 if (mMessageManager) {
michael@0 1641 static_cast<nsFrameMessageManager *>(
michael@0 1642 mMessageManager.get())->Disconnect();
michael@0 1643 }
michael@0 1644
michael@0 1645 mCleanMessageManager = false;
michael@0 1646 }
michael@0 1647
michael@0 1648 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsGlobalChromeWindow,
michael@0 1649 nsGlobalWindow)
michael@0 1650
michael@0 1651 using nsGlobalWindow::GetBrowserDOMWindow;
michael@0 1652 using nsGlobalWindow::SetBrowserDOMWindow;
michael@0 1653 using nsGlobalWindow::GetAttention;
michael@0 1654 using nsGlobalWindow::GetAttentionWithCycleCount;
michael@0 1655 using nsGlobalWindow::SetCursor;
michael@0 1656 using nsGlobalWindow::Maximize;
michael@0 1657 using nsGlobalWindow::Minimize;
michael@0 1658 using nsGlobalWindow::Restore;
michael@0 1659 using nsGlobalWindow::NotifyDefaultButtonLoaded;
michael@0 1660 using nsGlobalWindow::GetMessageManager;
michael@0 1661 using nsGlobalWindow::BeginWindowMove;
michael@0 1662
michael@0 1663 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
michael@0 1664 nsCOMPtr<nsIMessageBroadcaster> mMessageManager;
michael@0 1665 };
michael@0 1666
michael@0 1667 /*
michael@0 1668 * nsGlobalModalWindow inherits from nsGlobalWindow. It is the global
michael@0 1669 * object created for a modal content windows only (i.e. not modal
michael@0 1670 * chrome dialogs).
michael@0 1671 */
michael@0 1672 class nsGlobalModalWindow : public nsGlobalWindow,
michael@0 1673 public nsIDOMModalContentWindow
michael@0 1674 {
michael@0 1675 public:
michael@0 1676 nsGlobalModalWindow(nsGlobalWindow *aOuterWindow)
michael@0 1677 : nsGlobalWindow(aOuterWindow)
michael@0 1678 {
michael@0 1679 mIsModalContentWindow = true;
michael@0 1680 }
michael@0 1681
michael@0 1682 NS_DECL_ISUPPORTS_INHERITED
michael@0 1683 NS_DECL_NSIDOMMODALCONTENTWINDOW
michael@0 1684 };
michael@0 1685
michael@0 1686 /* factory function */
michael@0 1687 inline already_AddRefed<nsGlobalWindow>
michael@0 1688 NS_NewScriptGlobalObject(bool aIsChrome, bool aIsModalContentWindow)
michael@0 1689 {
michael@0 1690 nsRefPtr<nsGlobalWindow> global;
michael@0 1691
michael@0 1692 if (aIsChrome) {
michael@0 1693 global = new nsGlobalChromeWindow(nullptr);
michael@0 1694 } else if (aIsModalContentWindow) {
michael@0 1695 global = new nsGlobalModalWindow(nullptr);
michael@0 1696 } else {
michael@0 1697 global = new nsGlobalWindow(nullptr);
michael@0 1698 }
michael@0 1699
michael@0 1700 return global.forget();
michael@0 1701 }
michael@0 1702
michael@0 1703 #endif /* nsGlobalWindow_h___ */

mercurial