1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/nsPIDOMWindow.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,867 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 sw=2 et tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +#ifndef nsPIDOMWindow_h__ 1.12 +#define nsPIDOMWindow_h__ 1.13 + 1.14 +#include "nsIDOMWindow.h" 1.15 + 1.16 +#include "nsCOMPtr.h" 1.17 +#include "nsAutoPtr.h" 1.18 +#include "nsTArray.h" 1.19 +#include "mozilla/dom/EventTarget.h" 1.20 +#include "js/TypeDecls.h" 1.21 + 1.22 +#define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed" 1.23 +#define DOM_WINDOW_FROZEN_TOPIC "dom-window-frozen" 1.24 +#define DOM_WINDOW_THAWED_TOPIC "dom-window-thawed" 1.25 + 1.26 +class nsIArray; 1.27 +class nsIContent; 1.28 +class nsIDocShell; 1.29 +class nsIDocument; 1.30 +class nsIIdleObserver; 1.31 +class nsIPrincipal; 1.32 +class nsIScriptTimeoutHandler; 1.33 +class nsIURI; 1.34 +class nsPerformance; 1.35 +class nsPIWindowRoot; 1.36 +class nsXBLPrototypeHandler; 1.37 +struct nsTimeout; 1.38 + 1.39 +namespace mozilla { 1.40 +namespace dom { 1.41 +class AudioContext; 1.42 +class Element; 1.43 +} 1.44 +} 1.45 + 1.46 +// Popup control state enum. The values in this enum must go from most 1.47 +// permissive to least permissive so that it's safe to push state in 1.48 +// all situations. Pushing popup state onto the stack never makes the 1.49 +// current popup state less permissive (see 1.50 +// nsGlobalWindow::PushPopupControlState()). 1.51 +enum PopupControlState { 1.52 + openAllowed = 0, // open that window without worries 1.53 + openControlled, // it's a popup, but allow it 1.54 + openAbused, // it's a popup. disallow it, but allow domain override. 1.55 + openOverridden // disallow window open 1.56 +}; 1.57 + 1.58 +enum UIStateChangeType 1.59 +{ 1.60 + UIStateChangeType_NoChange, 1.61 + UIStateChangeType_Set, 1.62 + UIStateChangeType_Clear 1.63 +}; 1.64 + 1.65 +#define NS_PIDOMWINDOW_IID \ 1.66 +{ 0xf26953de, 0xa799, 0x4a92, \ 1.67 + { 0x87, 0x49, 0x7c, 0x37, 0xe5, 0x90, 0x3f, 0x37 } } 1.68 + 1.69 +class nsPIDOMWindow : public nsIDOMWindowInternal 1.70 +{ 1.71 +public: 1.72 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOW_IID) 1.73 + 1.74 + virtual nsPIDOMWindow* GetPrivateRoot() = 0; 1.75 + 1.76 + // Outer windows only. 1.77 + virtual void ActivateOrDeactivate(bool aActivate) = 0; 1.78 + 1.79 + // this is called GetTopWindowRoot to avoid conflicts with nsIDOMWindow::GetWindowRoot 1.80 + virtual already_AddRefed<nsPIWindowRoot> GetTopWindowRoot() = 0; 1.81 + 1.82 + // Inner windows only. 1.83 + virtual nsresult RegisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0; 1.84 + virtual nsresult UnregisterIdleObserver(nsIIdleObserver* aIdleObserver) = 0; 1.85 + 1.86 + // Outer windows only. 1.87 + virtual void SetActive(bool aActive) 1.88 + { 1.89 + MOZ_ASSERT(IsOuterWindow()); 1.90 + mIsActive = aActive; 1.91 + } 1.92 + bool IsActive() 1.93 + { 1.94 + MOZ_ASSERT(IsOuterWindow()); 1.95 + return mIsActive; 1.96 + } 1.97 + 1.98 + // Outer windows only. 1.99 + virtual void SetIsBackground(bool aIsBackground) 1.100 + { 1.101 + MOZ_ASSERT(IsOuterWindow()); 1.102 + mIsBackground = aIsBackground; 1.103 + } 1.104 + bool IsBackground() 1.105 + { 1.106 + MOZ_ASSERT(IsOuterWindow()); 1.107 + return mIsBackground; 1.108 + } 1.109 + 1.110 + mozilla::dom::EventTarget* GetChromeEventHandler() const 1.111 + { 1.112 + return mChromeEventHandler; 1.113 + } 1.114 + 1.115 + // Outer windows only. 1.116 + virtual void SetChromeEventHandler(mozilla::dom::EventTarget* aChromeEventHandler) = 0; 1.117 + 1.118 + mozilla::dom::EventTarget* GetParentTarget() 1.119 + { 1.120 + if (!mParentTarget) { 1.121 + UpdateParentTarget(); 1.122 + } 1.123 + return mParentTarget; 1.124 + } 1.125 + 1.126 + bool HasMutationListeners(uint32_t aMutationEventType) const 1.127 + { 1.128 + const nsPIDOMWindow *win; 1.129 + 1.130 + if (IsOuterWindow()) { 1.131 + win = GetCurrentInnerWindow(); 1.132 + 1.133 + if (!win) { 1.134 + NS_ERROR("No current inner window available!"); 1.135 + 1.136 + return false; 1.137 + } 1.138 + } else { 1.139 + if (!mOuterWindow) { 1.140 + NS_ERROR("HasMutationListeners() called on orphan inner window!"); 1.141 + 1.142 + return false; 1.143 + } 1.144 + 1.145 + win = this; 1.146 + } 1.147 + 1.148 + return (win->mMutationBits & aMutationEventType) != 0; 1.149 + } 1.150 + 1.151 + void SetMutationListeners(uint32_t aType) 1.152 + { 1.153 + nsPIDOMWindow *win; 1.154 + 1.155 + if (IsOuterWindow()) { 1.156 + win = GetCurrentInnerWindow(); 1.157 + 1.158 + if (!win) { 1.159 + NS_ERROR("No inner window available to set mutation bits on!"); 1.160 + 1.161 + return; 1.162 + } 1.163 + } else { 1.164 + if (!mOuterWindow) { 1.165 + NS_ERROR("HasMutationListeners() called on orphan inner window!"); 1.166 + 1.167 + return; 1.168 + } 1.169 + 1.170 + win = this; 1.171 + } 1.172 + 1.173 + win->mMutationBits |= aType; 1.174 + } 1.175 + 1.176 + virtual void MaybeUpdateTouchState() {} 1.177 + virtual void UpdateTouchState() {} 1.178 + 1.179 + nsIDocument* GetExtantDoc() const 1.180 + { 1.181 + return mDoc; 1.182 + } 1.183 + nsIURI* GetDocumentURI() const; 1.184 + nsIURI* GetDocBaseURI() const; 1.185 + 1.186 + nsIDocument* GetDoc() 1.187 + { 1.188 + if (!mDoc) { 1.189 + MaybeCreateDoc(); 1.190 + } 1.191 + return mDoc; 1.192 + } 1.193 + 1.194 + virtual NS_HIDDEN_(bool) IsRunningTimeout() = 0; 1.195 + 1.196 + // Audio API 1.197 + bool GetAudioMuted() const; 1.198 + void SetAudioMuted(bool aMuted); 1.199 + 1.200 + float GetAudioVolume() const; 1.201 + nsresult SetAudioVolume(float aVolume); 1.202 + 1.203 + float GetAudioGlobalVolume(); 1.204 + 1.205 +protected: 1.206 + // Lazily instantiate an about:blank document if necessary, and if 1.207 + // we have what it takes to do so. 1.208 + void MaybeCreateDoc(); 1.209 + 1.210 + float GetAudioGlobalVolumeInternal(float aVolume); 1.211 + void RefreshMediaElements(); 1.212 + 1.213 +public: 1.214 + // Internal getter/setter for the frame element, this version of the 1.215 + // getter crosses chrome boundaries whereas the public scriptable 1.216 + // one doesn't for security reasons. 1.217 + mozilla::dom::Element* GetFrameElementInternal() const; 1.218 + void SetFrameElementInternal(mozilla::dom::Element* aFrameElement); 1.219 + 1.220 + bool IsLoadingOrRunningTimeout() const 1.221 + { 1.222 + const nsPIDOMWindow *win = GetCurrentInnerWindow(); 1.223 + 1.224 + if (!win) { 1.225 + win = this; 1.226 + } 1.227 + 1.228 + return !win->mIsDocumentLoaded || win->mRunningTimeout; 1.229 + } 1.230 + 1.231 + // Check whether a document is currently loading 1.232 + bool IsLoading() const 1.233 + { 1.234 + const nsPIDOMWindow *win; 1.235 + 1.236 + if (IsOuterWindow()) { 1.237 + win = GetCurrentInnerWindow(); 1.238 + 1.239 + if (!win) { 1.240 + NS_ERROR("No current inner window available!"); 1.241 + 1.242 + return false; 1.243 + } 1.244 + } else { 1.245 + if (!mOuterWindow) { 1.246 + NS_ERROR("IsLoading() called on orphan inner window!"); 1.247 + 1.248 + return false; 1.249 + } 1.250 + 1.251 + win = this; 1.252 + } 1.253 + 1.254 + return !win->mIsDocumentLoaded; 1.255 + } 1.256 + 1.257 + bool IsHandlingResizeEvent() const 1.258 + { 1.259 + const nsPIDOMWindow *win; 1.260 + 1.261 + if (IsOuterWindow()) { 1.262 + win = GetCurrentInnerWindow(); 1.263 + 1.264 + if (!win) { 1.265 + NS_ERROR("No current inner window available!"); 1.266 + 1.267 + return false; 1.268 + } 1.269 + } else { 1.270 + if (!mOuterWindow) { 1.271 + NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!"); 1.272 + 1.273 + return false; 1.274 + } 1.275 + 1.276 + win = this; 1.277 + } 1.278 + 1.279 + return win->mIsHandlingResizeEvent; 1.280 + } 1.281 + 1.282 + // Set the window up with an about:blank document with the current subject 1.283 + // principal. 1.284 + virtual void SetInitialPrincipalToSubject() = 0; 1.285 + 1.286 + virtual PopupControlState PushPopupControlState(PopupControlState aState, 1.287 + bool aForce) const = 0; 1.288 + virtual void PopPopupControlState(PopupControlState state) const = 0; 1.289 + virtual PopupControlState GetPopupControlState() const = 0; 1.290 + 1.291 + // Returns an object containing the window's state. This also suspends 1.292 + // all running timeouts in the window. 1.293 + virtual already_AddRefed<nsISupports> SaveWindowState() = 0; 1.294 + 1.295 + // Restore the window state from aState. 1.296 + virtual nsresult RestoreWindowState(nsISupports *aState) = 0; 1.297 + 1.298 + // Suspend timeouts in this window and in child windows. 1.299 + virtual void SuspendTimeouts(uint32_t aIncrease = 1, 1.300 + bool aFreezeChildren = true) = 0; 1.301 + 1.302 + // Resume suspended timeouts in this window and in child windows. 1.303 + virtual nsresult ResumeTimeouts(bool aThawChildren = true) = 0; 1.304 + 1.305 + virtual uint32_t TimeoutSuspendCount() = 0; 1.306 + 1.307 + // Fire any DOM notification events related to things that happened while 1.308 + // the window was frozen. 1.309 + virtual nsresult FireDelayedDOMEvents() = 0; 1.310 + 1.311 + virtual bool IsFrozen() const = 0; 1.312 + 1.313 + // Add a timeout to this window. 1.314 + virtual nsresult SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, 1.315 + int32_t interval, 1.316 + bool aIsInterval, int32_t *aReturn) = 0; 1.317 + 1.318 + // Clear a timeout from this window. 1.319 + virtual nsresult ClearTimeoutOrInterval(int32_t aTimerID) = 0; 1.320 + 1.321 + nsPIDOMWindow *GetOuterWindow() 1.322 + { 1.323 + return mIsInnerWindow ? mOuterWindow.get() : this; 1.324 + } 1.325 + 1.326 + nsPIDOMWindow *GetCurrentInnerWindow() const 1.327 + { 1.328 + return mInnerWindow; 1.329 + } 1.330 + 1.331 + nsPIDOMWindow *EnsureInnerWindow() 1.332 + { 1.333 + NS_ASSERTION(IsOuterWindow(), "EnsureInnerWindow called on inner window"); 1.334 + // GetDoc forces inner window creation if there isn't one already 1.335 + GetDoc(); 1.336 + return GetCurrentInnerWindow(); 1.337 + } 1.338 + 1.339 + bool IsInnerWindow() const 1.340 + { 1.341 + return mIsInnerWindow; 1.342 + } 1.343 + 1.344 + // Returns true if this object has an outer window and it is the current inner 1.345 + // window of that outer. Only call this on inner windows. 1.346 + bool IsCurrentInnerWindow() const 1.347 + { 1.348 + MOZ_ASSERT(IsInnerWindow(), 1.349 + "It doesn't make sense to call this on outer windows."); 1.350 + return mOuterWindow && mOuterWindow->GetCurrentInnerWindow() == this; 1.351 + } 1.352 + 1.353 + // Returns true if the document of this window is the active document. This 1.354 + // is not identical to IsCurrentInnerWindow() because document.open() will 1.355 + // keep the same document active but create a new window. 1.356 + bool HasActiveDocument() 1.357 + { 1.358 + MOZ_ASSERT(IsInnerWindow()); 1.359 + return IsCurrentInnerWindow() || 1.360 + (mOuterWindow && 1.361 + mOuterWindow->GetCurrentInnerWindow() && 1.362 + mOuterWindow->GetCurrentInnerWindow()->GetDoc() == mDoc); 1.363 + } 1.364 + 1.365 + bool IsOuterWindow() const 1.366 + { 1.367 + return !IsInnerWindow(); 1.368 + } 1.369 + 1.370 + virtual bool WouldReuseInnerWindow(nsIDocument *aNewDocument) = 0; 1.371 + 1.372 + /** 1.373 + * Get the docshell in this window. 1.374 + */ 1.375 + nsIDocShell *GetDocShell() 1.376 + { 1.377 + if (mOuterWindow) { 1.378 + return mOuterWindow->mDocShell; 1.379 + } 1.380 + 1.381 + return mDocShell; 1.382 + } 1.383 + 1.384 + /** 1.385 + * Set the docshell in the window. Must not be called with a null docshell 1.386 + * (use DetachFromDocShell for that). 1.387 + */ 1.388 + virtual void SetDocShell(nsIDocShell *aDocShell) = 0; 1.389 + 1.390 + /** 1.391 + * Detach an outer window from its docshell. 1.392 + */ 1.393 + virtual void DetachFromDocShell() = 0; 1.394 + 1.395 + /** 1.396 + * Set a new document in the window. Calling this method will in 1.397 + * most cases create a new inner window. If this method is called on 1.398 + * an inner window the call will be forewarded to the outer window, 1.399 + * if the inner window is not the current inner window an 1.400 + * NS_ERROR_NOT_AVAILABLE error code will be returned. This may be 1.401 + * called with a pointer to the current document, in that case the 1.402 + * document remains unchanged, but a new inner window will be 1.403 + * created. 1.404 + * 1.405 + * aDocument must not be null. 1.406 + */ 1.407 + virtual nsresult SetNewDocument(nsIDocument *aDocument, 1.408 + nsISupports *aState, 1.409 + bool aForceReuseInnerWindow) = 0; 1.410 + 1.411 + /** 1.412 + * Set the opener window. aOriginalOpener is true if and only if this is the 1.413 + * original opener for the window. That is, it can only be true at most once 1.414 + * during the life cycle of a window, and then only the first time 1.415 + * SetOpenerWindow is called. It might never be true, of course, if the 1.416 + * window does not have an opener when it's created. 1.417 + */ 1.418 + virtual void SetOpenerWindow(nsIDOMWindow* aOpener, 1.419 + bool aOriginalOpener) = 0; 1.420 + 1.421 + virtual void EnsureSizeUpToDate() = 0; 1.422 + 1.423 + /** 1.424 + * Callback for notifying a window about a modal dialog being 1.425 + * opened/closed with the window as a parent. 1.426 + */ 1.427 + virtual void EnterModalState() = 0; 1.428 + virtual void LeaveModalState() = 0; 1.429 + 1.430 + virtual bool CanClose() = 0; 1.431 + virtual nsresult ForceClose() = 0; 1.432 + 1.433 + bool IsModalContentWindow() const 1.434 + { 1.435 + return mIsModalContentWindow; 1.436 + } 1.437 + 1.438 + /** 1.439 + * Call this to indicate that some node (this window, its document, 1.440 + * or content in that document) has a paint event listener. 1.441 + */ 1.442 + void SetHasPaintEventListeners() 1.443 + { 1.444 + mMayHavePaintEventListener = true; 1.445 + } 1.446 + 1.447 + /** 1.448 + * Call this to check whether some node (this window, its document, 1.449 + * or content in that document) has a paint event listener. 1.450 + */ 1.451 + bool HasPaintEventListeners() 1.452 + { 1.453 + return mMayHavePaintEventListener; 1.454 + } 1.455 + 1.456 + /** 1.457 + * Call this to indicate that some node (this window, its document, 1.458 + * or content in that document) has a touch event listener. 1.459 + */ 1.460 + void SetHasTouchEventListeners() 1.461 + { 1.462 + mMayHaveTouchEventListener = true; 1.463 + MaybeUpdateTouchState(); 1.464 + } 1.465 + 1.466 + bool HasTouchEventListeners() 1.467 + { 1.468 + return mMayHaveTouchEventListener; 1.469 + } 1.470 + 1.471 + /** 1.472 + * Moves the top-level window into fullscreen mode if aIsFullScreen is true, 1.473 + * otherwise exits fullscreen. If aRequireTrust is true, this method only 1.474 + * changes window state in a context trusted for write. 1.475 + */ 1.476 + virtual nsresult SetFullScreenInternal(bool aIsFullScreen, bool aRequireTrust) = 0; 1.477 + 1.478 + /** 1.479 + * Call this to check whether some node (this window, its document, 1.480 + * or content in that document) has a mouseenter/leave event listener. 1.481 + */ 1.482 + bool HasMouseEnterLeaveEventListeners() 1.483 + { 1.484 + return mMayHaveMouseEnterLeaveEventListener; 1.485 + } 1.486 + 1.487 + /** 1.488 + * Call this to indicate that some node (this window, its document, 1.489 + * or content in that document) has a mouseenter/leave event listener. 1.490 + */ 1.491 + void SetHasMouseEnterLeaveEventListeners() 1.492 + { 1.493 + mMayHaveMouseEnterLeaveEventListener = true; 1.494 + } 1.495 + 1.496 + /** 1.497 + * Call this to check whether some node (this window, its document, 1.498 + * or content in that document) has a Pointerenter/leave event listener. 1.499 + */ 1.500 + bool HasPointerEnterLeaveEventListeners() 1.501 + { 1.502 + return mMayHavePointerEnterLeaveEventListener; 1.503 + } 1.504 + 1.505 + /** 1.506 + * Call this to indicate that some node (this window, its document, 1.507 + * or content in that document) has a Pointerenter/leave event listener. 1.508 + */ 1.509 + void SetHasPointerEnterLeaveEventListeners() 1.510 + { 1.511 + mMayHavePointerEnterLeaveEventListener = true; 1.512 + } 1.513 + 1.514 + 1.515 + virtual JSObject* GetCachedXBLPrototypeHandler(nsXBLPrototypeHandler* aKey) = 0; 1.516 + virtual void CacheXBLPrototypeHandler(nsXBLPrototypeHandler* aKey, 1.517 + JS::Handle<JSObject*> aHandler) = 0; 1.518 + 1.519 + /* 1.520 + * Get and set the currently focused element within the document. If 1.521 + * aNeedsFocus is true, then set mNeedsFocus to true to indicate that a 1.522 + * document focus event is needed. 1.523 + * 1.524 + * DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER 1.525 + * INSTEAD. 1.526 + */ 1.527 + nsIContent* GetFocusedNode() 1.528 + { 1.529 + if (IsOuterWindow()) { 1.530 + return mInnerWindow ? mInnerWindow->mFocusedNode.get() : nullptr; 1.531 + } 1.532 + return mFocusedNode; 1.533 + } 1.534 + virtual void SetFocusedNode(nsIContent* aNode, 1.535 + uint32_t aFocusMethod = 0, 1.536 + bool aNeedsFocus = false) = 0; 1.537 + 1.538 + /** 1.539 + * Retrieves the method that was used to focus the current node. 1.540 + */ 1.541 + virtual uint32_t GetFocusMethod() = 0; 1.542 + 1.543 + /* 1.544 + * Tells the window that it now has focus or has lost focus, based on the 1.545 + * state of aFocus. If this method returns true, then the document loaded 1.546 + * in the window has never received a focus event and expects to receive 1.547 + * one. If false is returned, the document has received a focus event before 1.548 + * and should only receive one if the window is being focused. 1.549 + * 1.550 + * aFocusMethod may be set to one of the focus method constants in 1.551 + * nsIFocusManager to indicate how focus was set. 1.552 + */ 1.553 + virtual bool TakeFocus(bool aFocus, uint32_t aFocusMethod) = 0; 1.554 + 1.555 + /** 1.556 + * Indicates that the window may now accept a document focus event. This 1.557 + * should be called once a document has been loaded into the window. 1.558 + */ 1.559 + virtual void SetReadyForFocus() = 0; 1.560 + 1.561 + /** 1.562 + * Whether the focused content within the window should show a focus ring. 1.563 + */ 1.564 + virtual bool ShouldShowFocusRing() = 0; 1.565 + 1.566 + /** 1.567 + * Set the keyboard indicator state for accelerators and focus rings. 1.568 + */ 1.569 + virtual void SetKeyboardIndicators(UIStateChangeType aShowAccelerators, 1.570 + UIStateChangeType aShowFocusRings) = 0; 1.571 + 1.572 + /** 1.573 + * Get the keyboard indicator state for accelerators and focus rings. 1.574 + */ 1.575 + virtual void GetKeyboardIndicators(bool* aShowAccelerators, 1.576 + bool* aShowFocusRings) = 0; 1.577 + 1.578 + /** 1.579 + * Indicates that the page in the window has been hidden. This is used to 1.580 + * reset the focus state. 1.581 + */ 1.582 + virtual void PageHidden() = 0; 1.583 + 1.584 + /** 1.585 + * Instructs this window to asynchronously dispatch a hashchange event. This 1.586 + * method must be called on an inner window. 1.587 + */ 1.588 + virtual nsresult DispatchAsyncHashchange(nsIURI *aOldURI, 1.589 + nsIURI *aNewURI) = 0; 1.590 + 1.591 + /** 1.592 + * Instructs this window to synchronously dispatch a popState event. 1.593 + */ 1.594 + virtual nsresult DispatchSyncPopState() = 0; 1.595 + 1.596 + /** 1.597 + * Tell this window that it should listen for sensor changes of the given 1.598 + * type. 1.599 + * 1.600 + * Inner windows only. 1.601 + */ 1.602 + virtual void EnableDeviceSensor(uint32_t aType) = 0; 1.603 + 1.604 + /** 1.605 + * Tell this window that it should remove itself from sensor change 1.606 + * notifications. 1.607 + * 1.608 + * Inner windows only. 1.609 + */ 1.610 + virtual void DisableDeviceSensor(uint32_t aType) = 0; 1.611 + 1.612 + virtual void EnableTimeChangeNotifications() = 0; 1.613 + virtual void DisableTimeChangeNotifications() = 0; 1.614 + 1.615 +#ifdef MOZ_B2G 1.616 + /** 1.617 + * Tell the window that it should start to listen to the network event of the 1.618 + * given aType. 1.619 + * 1.620 + * Inner windows only. 1.621 + */ 1.622 + virtual void EnableNetworkEvent(uint32_t aType) = 0; 1.623 + 1.624 + /** 1.625 + * Tell the window that it should stop to listen to the network event of the 1.626 + * given aType. 1.627 + * 1.628 + * Inner windows only. 1.629 + */ 1.630 + virtual void DisableNetworkEvent(uint32_t aType) = 0; 1.631 +#endif // MOZ_B2G 1.632 + 1.633 + /** 1.634 + * Tell this window that there is an observer for gamepad input 1.635 + */ 1.636 + virtual void SetHasGamepadEventListener(bool aHasGamepad = true) = 0; 1.637 + 1.638 + /** 1.639 + * Set a arguments for this window. This will be set on the window 1.640 + * right away (if there's an existing document) and it will also be 1.641 + * installed on the window when the next document is loaded. 1.642 + * 1.643 + * This function serves double-duty for passing both |arguments| and 1.644 + * |dialogArguments| back from nsWindowWatcher to nsGlobalWindow. For the 1.645 + * latter, the array is an array of length 0 whose only element is a 1.646 + * DialogArgumentsHolder representing the JS value passed to showModalDialog. 1.647 + */ 1.648 + virtual nsresult SetArguments(nsIArray *aArguments) = 0; 1.649 + 1.650 + /** 1.651 + * NOTE! This function *will* be called on multiple threads so the 1.652 + * implementation must not do any AddRef/Release or other actions that will 1.653 + * mutate internal state. 1.654 + */ 1.655 + virtual uint32_t GetSerial() = 0; 1.656 + 1.657 + /** 1.658 + * Return the window id of this window 1.659 + */ 1.660 + uint64_t WindowID() const { return mWindowID; } 1.661 + 1.662 + /** 1.663 + * Dispatch a custom event with name aEventName targeted at this window. 1.664 + * Returns whether the default action should be performed. 1.665 + */ 1.666 + virtual bool DispatchCustomEvent(const char *aEventName) = 0; 1.667 + 1.668 + /** 1.669 + * Notify the active inner window that the document principal may have changed 1.670 + * and that the compartment principal needs to be updated. 1.671 + */ 1.672 + virtual void RefreshCompartmentPrincipal() = 0; 1.673 + 1.674 + /** 1.675 + * Like nsIDOMWindow::Open, except that we don't navigate to the given URL. 1.676 + */ 1.677 + virtual nsresult 1.678 + OpenNoNavigate(const nsAString& aUrl, const nsAString& aName, 1.679 + const nsAString& aOptions, nsIDOMWindow **_retval) = 0; 1.680 + 1.681 + void AddAudioContext(mozilla::dom::AudioContext* aAudioContext); 1.682 + void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext); 1.683 + void MuteAudioContexts(); 1.684 + void UnmuteAudioContexts(); 1.685 + 1.686 + // Given an inner window, return its outer if the inner is the current inner. 1.687 + // Otherwise (argument null or not an inner or not current) return null. 1.688 + static nsPIDOMWindow* GetOuterFromCurrentInner(nsPIDOMWindow* aInner) 1.689 + { 1.690 + if (!aInner) { 1.691 + return nullptr; 1.692 + } 1.693 + 1.694 + nsPIDOMWindow* outer = aInner->GetOuterWindow(); 1.695 + if (!outer || outer->GetCurrentInnerWindow() != aInner) { 1.696 + return nullptr; 1.697 + } 1.698 + 1.699 + return outer; 1.700 + } 1.701 + 1.702 + // WebIDL-ish APIs 1.703 + nsPerformance* GetPerformance(); 1.704 + 1.705 + void MarkUncollectableForCCGeneration(uint32_t aGeneration) 1.706 + { 1.707 + mMarkedCCGeneration = aGeneration; 1.708 + } 1.709 + 1.710 + uint32_t GetMarkedCCGeneration() 1.711 + { 1.712 + return mMarkedCCGeneration; 1.713 + } 1.714 +protected: 1.715 + // The nsPIDOMWindow constructor. The aOuterWindow argument should 1.716 + // be null if and only if the created window itself is an outer 1.717 + // window. In all other cases aOuterWindow should be the outer 1.718 + // window for the inner window that is being created. 1.719 + nsPIDOMWindow(nsPIDOMWindow *aOuterWindow); 1.720 + 1.721 + ~nsPIDOMWindow(); 1.722 + 1.723 + void SetChromeEventHandlerInternal(mozilla::dom::EventTarget* aChromeEventHandler) { 1.724 + mChromeEventHandler = aChromeEventHandler; 1.725 + // mParentTarget will be set when the next event is dispatched. 1.726 + mParentTarget = nullptr; 1.727 + } 1.728 + 1.729 + virtual void UpdateParentTarget() = 0; 1.730 + 1.731 + // Helper for creating performance objects. 1.732 + void CreatePerformanceObjectIfNeeded(); 1.733 + 1.734 + // These two variables are special in that they're set to the same 1.735 + // value on both the outer window and the current inner window. Make 1.736 + // sure you keep them in sync! 1.737 + nsCOMPtr<mozilla::dom::EventTarget> mChromeEventHandler; // strong 1.738 + nsCOMPtr<nsIDocument> mDoc; // strong 1.739 + // Cache the URI when mDoc is cleared. 1.740 + nsCOMPtr<nsIURI> mDocumentURI; // strong 1.741 + nsCOMPtr<nsIURI> mDocBaseURI; // strong 1.742 + 1.743 + nsCOMPtr<mozilla::dom::EventTarget> mParentTarget; // strong 1.744 + 1.745 + // These members are only used on outer windows. 1.746 + nsCOMPtr<mozilla::dom::Element> mFrameElement; 1.747 + nsIDocShell *mDocShell; // Weak Reference 1.748 + 1.749 + // mPerformance is only used on inner windows. 1.750 + nsRefPtr<nsPerformance> mPerformance; 1.751 + 1.752 + uint32_t mModalStateDepth; 1.753 + 1.754 + // These variables are only used on inner windows. 1.755 + nsTimeout *mRunningTimeout; 1.756 + 1.757 + uint32_t mMutationBits; 1.758 + 1.759 + bool mIsDocumentLoaded; 1.760 + bool mIsHandlingResizeEvent; 1.761 + bool mIsInnerWindow; 1.762 + bool mMayHavePaintEventListener; 1.763 + bool mMayHaveTouchEventListener; 1.764 + bool mMayHaveMouseEnterLeaveEventListener; 1.765 + bool mMayHavePointerEnterLeaveEventListener; 1.766 + 1.767 + // This variable is used on both inner and outer windows (and they 1.768 + // should match). 1.769 + bool mIsModalContentWindow; 1.770 + 1.771 + // Tracks activation state that's used for :-moz-window-inactive. 1.772 + // Only used on outer windows. 1.773 + bool mIsActive; 1.774 + 1.775 + // Tracks whether our docshell is active. If it is, mIsBackground 1.776 + // is false. Too bad we have so many different concepts of 1.777 + // "active". Only used on outer windows. 1.778 + bool mIsBackground; 1.779 + 1.780 + bool mAudioMuted; 1.781 + float mAudioVolume; 1.782 + 1.783 + // And these are the references between inner and outer windows. 1.784 + nsPIDOMWindow *mInnerWindow; 1.785 + nsCOMPtr<nsPIDOMWindow> mOuterWindow; 1.786 + 1.787 + // the element within the document that is currently focused when this 1.788 + // window is active 1.789 + nsCOMPtr<nsIContent> mFocusedNode; 1.790 + 1.791 + // The AudioContexts created for the current document, if any. 1.792 + nsTArray<mozilla::dom::AudioContext*> mAudioContexts; // Weak 1.793 + 1.794 + // A unique (as long as our 64-bit counter doesn't roll over) id for 1.795 + // this window. 1.796 + uint64_t mWindowID; 1.797 + 1.798 + // This is only used by the inner window. Set to true once we've sent 1.799 + // the (chrome|content)-document-global-created notification. 1.800 + bool mHasNotifiedGlobalCreated; 1.801 + 1.802 + uint32_t mMarkedCCGeneration; 1.803 +}; 1.804 + 1.805 + 1.806 +NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindow, NS_PIDOMWINDOW_IID) 1.807 + 1.808 +#ifdef MOZILLA_INTERNAL_API 1.809 +PopupControlState 1.810 +PushPopupControlState(PopupControlState aState, bool aForce); 1.811 + 1.812 +void 1.813 +PopPopupControlState(PopupControlState aState); 1.814 + 1.815 +#define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherInternal 1.816 +#else 1.817 +#define NS_AUTO_POPUP_STATE_PUSHER nsAutoPopupStatePusherExternal 1.818 +#endif 1.819 + 1.820 +// Helper class that helps with pushing and popping popup control 1.821 +// state. Note that this class looks different from within code that's 1.822 +// part of the layout library than it does in code outside the layout 1.823 +// library. We give the two object layouts different names so the symbols 1.824 +// don't conflict, but code should always use the name 1.825 +// |nsAutoPopupStatePusher|. 1.826 +class NS_AUTO_POPUP_STATE_PUSHER 1.827 +{ 1.828 +public: 1.829 +#ifdef MOZILLA_INTERNAL_API 1.830 + NS_AUTO_POPUP_STATE_PUSHER(PopupControlState aState, bool aForce = false) 1.831 + : mOldState(::PushPopupControlState(aState, aForce)) 1.832 + { 1.833 + } 1.834 + 1.835 + ~NS_AUTO_POPUP_STATE_PUSHER() 1.836 + { 1.837 + PopPopupControlState(mOldState); 1.838 + } 1.839 +#else 1.840 + NS_AUTO_POPUP_STATE_PUSHER(nsPIDOMWindow *aWindow, PopupControlState aState) 1.841 + : mWindow(aWindow), mOldState(openAbused) 1.842 + { 1.843 + if (aWindow) { 1.844 + mOldState = aWindow->PushPopupControlState(aState, false); 1.845 + } 1.846 + } 1.847 + 1.848 + ~NS_AUTO_POPUP_STATE_PUSHER() 1.849 + { 1.850 + if (mWindow) { 1.851 + mWindow->PopPopupControlState(mOldState); 1.852 + } 1.853 + } 1.854 +#endif 1.855 + 1.856 +protected: 1.857 +#ifndef MOZILLA_INTERNAL_API 1.858 + nsCOMPtr<nsPIDOMWindow> mWindow; 1.859 +#endif 1.860 + PopupControlState mOldState; 1.861 + 1.862 +private: 1.863 + // Hide so that this class can only be stack-allocated 1.864 + static void* operator new(size_t /*size*/) CPP_THROW_NEW { return nullptr; } 1.865 + static void operator delete(void* /*memory*/) {} 1.866 +}; 1.867 + 1.868 +#define nsAutoPopupStatePusher NS_AUTO_POPUP_STATE_PUSHER 1.869 + 1.870 +#endif // nsPIDOMWindow_h__