1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_BrowserChild_h
8 #define mozilla_dom_BrowserChild_h
10 #include "mozilla/dom/ContentFrameMessageManager.h"
11 #include "mozilla/dom/PBrowserChild.h"
12 #include "nsIWebNavigation.h"
14 #include "nsIWebBrowserChrome.h"
15 #include "nsIEmbeddingSiteWindow.h"
16 #include "nsIWebBrowserChromeFocus.h"
17 #include "nsIDOMEventListener.h"
18 #include "nsIInterfaceRequestor.h"
19 #include "nsIWindowProvider.h"
20 #include "nsIDocShell.h"
21 #include "nsIInterfaceRequestorUtils.h"
22 #include "nsFrameMessageManager.h"
23 #include "nsWeakReference.h"
24 #include "nsIBrowserChild.h"
25 #include "nsITooltipListener.h"
26 #include "nsIWebProgressListener.h"
27 #include "nsIWebProgressListener2.h"
28 #include "mozilla/Attributes.h"
29 #include "mozilla/dom/TabContext.h"
30 #include "mozilla/dom/CoalescedMouseData.h"
31 #include "mozilla/dom/CoalescedWheelData.h"
32 #include "mozilla/DOMEventTargetHelper.h"
33 #include "mozilla/EventDispatcher.h"
34 #include "mozilla/EventForwards.h"
35 #include "mozilla/layers/CompositorTypes.h"
36 #include "mozilla/layers/APZCCallbackHelper.h"
37 #include "mozilla/layers/CompositorOptions.h"
38 #include "mozilla/layers/GeckoContentControllerTypes.h"
39 #include "nsIWebBrowserChrome3.h"
40 #include "mozilla/dom/ipc/IdType.h"
41 #include "AudioChannelService.h"
42 #include "PuppetWidget.h"
45 class nsBrowserStatusFilter
;
49 class nsISerialEventTarget
;
65 class AsyncDragMetrics
;
66 class IAPZCTreeManager
;
67 class ImageCompositeNotification
;
68 class PCompositorBridgeChild
;
72 struct AutoCacheNativeKeyCommands
;
78 class BrowsingContext
;
80 class ClonedMessageData
;
81 class CoalescedMouseData
;
82 class CoalescedWheelData
;
83 class ContentSessionStore
;
86 class WebProgressData
;
88 class BrowserChildMessageManager
: public ContentFrameMessageManager
,
89 public nsIMessageSender
,
90 public DispatcherTrait
,
91 public nsSupportsWeakReference
{
93 explicit BrowserChildMessageManager(BrowserChild
* aBrowserChild
);
95 NS_DECL_ISUPPORTS_INHERITED
96 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BrowserChildMessageManager
,
101 JSObject
* WrapObject(JSContext
* aCx
,
102 JS::Handle
<JSObject
*> aGivenProto
) override
;
104 virtual Nullable
<WindowProxyHolder
> GetContent(ErrorResult
& aError
) override
;
105 virtual already_AddRefed
<nsIDocShell
> GetDocShell(
106 ErrorResult
& aError
) override
;
107 virtual already_AddRefed
<nsIEventTarget
> GetTabEventTarget() override
;
108 virtual uint64_t ChromeOuterWindowID() override
;
110 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager
)
112 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
{
113 aVisitor
.mForceContentDispatch
= true;
116 // Dispatch a runnable related to the global.
117 virtual nsresult
Dispatch(mozilla::TaskCategory aCategory
,
118 already_AddRefed
<nsIRunnable
>&& aRunnable
) override
;
120 virtual nsISerialEventTarget
* EventTargetFor(
121 mozilla::TaskCategory aCategory
) const override
;
123 virtual AbstractThread
* AbstractMainThreadFor(
124 mozilla::TaskCategory aCategory
) override
;
126 RefPtr
<BrowserChild
> mBrowserChild
;
129 ~BrowserChildMessageManager();
132 class ContentListener final
: public nsIDOMEventListener
{
134 explicit ContentListener(BrowserChild
* aBrowserChild
)
135 : mBrowserChild(aBrowserChild
) {}
137 NS_DECL_NSIDOMEVENTLISTENER
139 ~ContentListener() = default;
140 BrowserChild
* mBrowserChild
;
144 * BrowserChild implements the child actor part of the PBrowser protocol. See
145 * PBrowser for more information.
147 class BrowserChild final
: public nsMessageManagerScriptExecutor
,
148 public ipc::MessageManagerCallback
,
149 public PBrowserChild
,
150 public nsIWebBrowserChrome
,
151 public nsIEmbeddingSiteWindow
,
152 public nsIWebBrowserChromeFocus
,
153 public nsIInterfaceRequestor
,
154 public nsIWindowProvider
,
155 public nsSupportsWeakReference
,
156 public nsIBrowserChild
,
158 public nsIWebProgressListener2
,
160 public nsITooltipListener
,
161 public mozilla::ipc::IShmemAllocator
{
162 typedef mozilla::widget::PuppetWidget PuppetWidget
;
163 typedef mozilla::dom::ClonedMessageData ClonedMessageData
;
164 typedef mozilla::dom::CoalescedMouseData CoalescedMouseData
;
165 typedef mozilla::dom::CoalescedWheelData CoalescedWheelData
;
166 typedef mozilla::layers::APZEventState APZEventState
;
167 typedef mozilla::layers::SetAllowedTouchBehaviorCallback
168 SetAllowedTouchBehaviorCallback
;
169 typedef mozilla::layers::TouchBehaviorFlags TouchBehaviorFlags
;
171 friend class PBrowserChild
;
175 * Find BrowserChild of aTabId in the same content process of the
178 static already_AddRefed
<BrowserChild
> FindBrowserChild(const TabId
& aTabId
);
180 // Return a list of all active BrowserChildren.
181 static nsTArray
<RefPtr
<BrowserChild
>> GetAll();
185 * Create a new BrowserChild object.
187 BrowserChild(ContentChild
* aManager
, const TabId
& aTabId
,
188 const TabContext
& aContext
,
189 dom::BrowsingContext
* aBrowsingContext
, uint32_t aChromeFlags
,
192 nsresult
Init(mozIDOMWindowProxy
* aParent
,
193 WindowGlobalChild
* aInitialWindowChild
);
195 /** Return a BrowserChild with the given attributes. */
196 static already_AddRefed
<BrowserChild
> Create(
197 ContentChild
* aManager
, const TabId
& aTabId
, const TabContext
& aContext
,
198 BrowsingContext
* aBrowsingContext
, uint32_t aChromeFlags
,
201 // Let managees query if it is safe to send messages.
202 bool IsDestroyed() const { return mDestroyed
; }
204 const TabId
GetTabId() const {
205 MOZ_ASSERT(mUniqueId
!= 0);
209 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
210 NS_DECL_NSIWEBBROWSERCHROME
211 NS_DECL_NSIEMBEDDINGSITEWINDOW
212 NS_DECL_NSIWEBBROWSERCHROMEFOCUS
213 NS_DECL_NSIINTERFACEREQUESTOR
214 NS_DECL_NSIWINDOWPROVIDER
215 NS_DECL_NSIBROWSERCHILD
217 NS_DECL_NSIWEBPROGRESSLISTENER
218 NS_DECL_NSIWEBPROGRESSLISTENER2
219 NS_DECL_NSITOOLTIPLISTENER
221 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(BrowserChild
,
224 FORWARD_SHMEM_ALLOCATOR_TO(PBrowserChild
)
226 JSObject
* WrapObject(JSContext
* aCx
, JS::Handle
<JSObject
*> aGivenProto
) {
227 return mBrowserChildMessageManager
->WrapObject(aCx
, aGivenProto
);
230 // Get the Document for the top-level window in this tab.
231 already_AddRefed
<Document
> GetTopLevelDocument() const;
233 // Get the pres-shell of the document for the top-level window in this tab.
234 PresShell
* GetTopLevelPresShell() const;
236 BrowserChildMessageManager
* GetMessageManager() {
237 return mBrowserChildMessageManager
;
240 bool IsTopLevel() const { return mIsTopLevel
; }
243 * MessageManagerCallback methods that we override.
245 virtual bool DoSendBlockingMessage(
246 const nsAString
& aMessage
, StructuredCloneData
& aData
,
247 nsTArray
<StructuredCloneData
>* aRetVal
) override
;
249 virtual nsresult
DoSendAsyncMessage(const nsAString
& aMessage
,
250 StructuredCloneData
& aData
) override
;
252 bool DoUpdateZoomConstraints(const uint32_t& aPresShellId
,
253 const ViewID
& aViewId
,
254 const Maybe
<ZoomConstraints
>& aConstraints
);
256 mozilla::ipc::IPCResult
RecvLoadURL(const nsCString
& aURI
,
257 const ParentShowInfo
&);
259 mozilla::ipc::IPCResult
RecvResumeLoad(const uint64_t& aPendingSwitchID
,
260 const ParentShowInfo
&);
262 MOZ_CAN_RUN_SCRIPT_BOUNDARY
263 mozilla::ipc::IPCResult
RecvShow(const ParentShowInfo
&, const OwnerShowInfo
&);
265 mozilla::ipc::IPCResult
RecvInitRendering(
266 const TextureFactoryIdentifier
& aTextureFactoryIdentifier
,
267 const layers::LayersId
& aLayersId
,
268 const mozilla::layers::CompositorOptions
& aCompositorOptions
,
269 const bool& aLayersConnected
);
271 mozilla::ipc::IPCResult
RecvCompositorOptionsChanged(
272 const mozilla::layers::CompositorOptions
& aNewOptions
);
274 mozilla::ipc::IPCResult
RecvUpdateDimensions(
275 const mozilla::dom::DimensionInfo
& aDimensionInfo
);
276 mozilla::ipc::IPCResult
RecvSizeModeChanged(const nsSizeMode
& aSizeMode
);
278 mozilla::ipc::IPCResult
RecvChildToParentMatrix(
279 const mozilla::Maybe
<mozilla::gfx::Matrix4x4
>& aMatrix
,
280 const mozilla::ScreenRect
& aTopLevelViewportVisibleRectInBrowserCoords
);
282 MOZ_CAN_RUN_SCRIPT_BOUNDARY
283 mozilla::ipc::IPCResult
RecvDynamicToolbarMaxHeightChanged(
284 const mozilla::ScreenIntCoord
& aHeight
);
286 mozilla::ipc::IPCResult
RecvDynamicToolbarOffsetChanged(
287 const mozilla::ScreenIntCoord
& aOffset
);
289 mozilla::ipc::IPCResult
RecvActivate();
291 mozilla::ipc::IPCResult
RecvDeactivate();
293 MOZ_CAN_RUN_SCRIPT_BOUNDARY
294 mozilla::ipc::IPCResult
RecvMouseEvent(const nsString
& aType
, const float& aX
,
296 const int32_t& aButton
,
297 const int32_t& aClickCount
,
298 const int32_t& aModifiers
);
300 mozilla::ipc::IPCResult
RecvRealMouseMoveEvent(
301 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
302 const uint64_t& aInputBlockId
);
304 mozilla::ipc::IPCResult
RecvNormalPriorityRealMouseMoveEvent(
305 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
306 const uint64_t& aInputBlockId
);
308 mozilla::ipc::IPCResult
RecvSynthMouseMoveEvent(
309 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
310 const uint64_t& aInputBlockId
);
311 mozilla::ipc::IPCResult
RecvNormalPrioritySynthMouseMoveEvent(
312 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
313 const uint64_t& aInputBlockId
);
315 mozilla::ipc::IPCResult
RecvRealMouseButtonEvent(
316 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
317 const uint64_t& aInputBlockId
);
318 mozilla::ipc::IPCResult
RecvNormalPriorityRealMouseButtonEvent(
319 const mozilla::WidgetMouseEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
320 const uint64_t& aInputBlockId
);
322 MOZ_CAN_RUN_SCRIPT_BOUNDARY
323 mozilla::ipc::IPCResult
RecvRealDragEvent(const WidgetDragEvent
& aEvent
,
324 const uint32_t& aDragAction
,
325 const uint32_t& aDropEffect
,
326 nsIPrincipal
* aPrincipal
,
327 nsIContentSecurityPolicy
* aCsp
);
329 mozilla::ipc::IPCResult
RecvRealKeyEvent(
330 const mozilla::WidgetKeyboardEvent
& aEvent
);
332 mozilla::ipc::IPCResult
RecvNormalPriorityRealKeyEvent(
333 const mozilla::WidgetKeyboardEvent
& aEvent
);
335 mozilla::ipc::IPCResult
RecvMouseWheelEvent(
336 const mozilla::WidgetWheelEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
337 const uint64_t& aInputBlockId
);
339 mozilla::ipc::IPCResult
RecvNormalPriorityMouseWheelEvent(
340 const mozilla::WidgetWheelEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
341 const uint64_t& aInputBlockId
);
343 mozilla::ipc::IPCResult
RecvRealTouchEvent(const WidgetTouchEvent
& aEvent
,
344 const ScrollableLayerGuid
& aGuid
,
345 const uint64_t& aInputBlockId
,
346 const nsEventStatus
& aApzResponse
);
348 mozilla::ipc::IPCResult
RecvNormalPriorityRealTouchEvent(
349 const WidgetTouchEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
350 const uint64_t& aInputBlockId
, const nsEventStatus
& aApzResponse
);
352 mozilla::ipc::IPCResult
RecvRealTouchMoveEvent(
353 const WidgetTouchEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
354 const uint64_t& aInputBlockId
, const nsEventStatus
& aApzResponse
);
356 mozilla::ipc::IPCResult
RecvNormalPriorityRealTouchMoveEvent(
357 const WidgetTouchEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
358 const uint64_t& aInputBlockId
, const nsEventStatus
& aApzResponse
);
360 mozilla::ipc::IPCResult
RecvRealTouchMoveEvent2(
361 const WidgetTouchEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
362 const uint64_t& aInputBlockId
, const nsEventStatus
& aApzResponse
) {
363 return RecvRealTouchMoveEvent(aEvent
, aGuid
, aInputBlockId
, aApzResponse
);
366 mozilla::ipc::IPCResult
RecvNormalPriorityRealTouchMoveEvent2(
367 const WidgetTouchEvent
& aEvent
, const ScrollableLayerGuid
& aGuid
,
368 const uint64_t& aInputBlockId
, const nsEventStatus
& aApzResponse
) {
369 return RecvNormalPriorityRealTouchMoveEvent(aEvent
, aGuid
, aInputBlockId
,
373 mozilla::ipc::IPCResult
RecvFlushTabState(const uint32_t& aFlushId
,
374 const bool& aIsFinal
);
376 mozilla::ipc::IPCResult
RecvUpdateEpoch(const uint32_t& aEpoch
);
378 mozilla::ipc::IPCResult
RecvUpdateSHistory(const bool& aImmediately
);
380 mozilla::ipc::IPCResult
RecvNativeSynthesisResponse(
381 const uint64_t& aObserverId
, const nsCString
& aResponse
);
383 mozilla::ipc::IPCResult
RecvPluginEvent(const WidgetPluginEvent
& aEvent
);
385 mozilla::ipc::IPCResult
RecvCompositionEvent(
386 const mozilla::WidgetCompositionEvent
& aEvent
);
388 mozilla::ipc::IPCResult
RecvNormalPriorityCompositionEvent(
389 const mozilla::WidgetCompositionEvent
& aEvent
);
391 mozilla::ipc::IPCResult
RecvSelectionEvent(
392 const mozilla::WidgetSelectionEvent
& aEvent
);
394 mozilla::ipc::IPCResult
RecvNormalPrioritySelectionEvent(
395 const mozilla::WidgetSelectionEvent
& aEvent
);
397 mozilla::ipc::IPCResult
RecvSetIsUnderHiddenEmbedderElement(
398 const bool& aIsUnderHiddenEmbedderElement
);
400 MOZ_CAN_RUN_SCRIPT_BOUNDARY
401 mozilla::ipc::IPCResult
RecvPasteTransferable(
402 const IPCDataTransfer
& aDataTransfer
, const bool& aIsPrivateData
,
403 nsIPrincipal
* aRequestingPrincipal
, const uint32_t& aContentPolicyType
);
405 mozilla::ipc::IPCResult
RecvActivateFrameEvent(const nsString
& aType
,
406 const bool& aCapture
);
408 mozilla::ipc::IPCResult
RecvLoadRemoteScript(const nsString
& aURL
,
409 const bool& aRunInGlobalScope
);
411 mozilla::ipc::IPCResult
RecvAsyncMessage(const nsString
& aMessage
,
412 const ClonedMessageData
& aData
);
413 mozilla::ipc::IPCResult
RecvSwappedWithOtherRemoteLoader(
414 const IPCTabContext
& aContext
);
416 mozilla::ipc::IPCResult
RecvSafeAreaInsetsChanged(
417 const mozilla::ScreenIntMargin
& aSafeAreaInsets
);
420 PDocAccessibleChild
* AllocPDocAccessibleChild(PDocAccessibleChild
*,
423 const IAccessibleHolder
&);
424 bool DeallocPDocAccessibleChild(PDocAccessibleChild
*);
427 PColorPickerChild
* AllocPColorPickerChild(const nsString
& aTitle
,
428 const nsString
& aInitialColor
);
430 bool DeallocPColorPickerChild(PColorPickerChild
* aActor
);
432 PFilePickerChild
* AllocPFilePickerChild(const nsString
& aTitle
,
433 const int16_t& aMode
);
435 bool DeallocPFilePickerChild(PFilePickerChild
* aActor
);
437 nsIWebNavigation
* WebNavigation() const { return mWebNav
; }
439 PuppetWidget
* WebWidget() { return mPuppetWidget
; }
441 bool IsTransparent() const { return mIsTransparent
; }
443 const EffectsInfo
& GetEffectsInfo() const { return mEffectsInfo
; }
445 hal::ScreenOrientation
GetOrientation() const { return mOrientation
; }
447 void SetBackgroundColor(const nscolor
& aColor
);
449 void NotifyPainted();
451 MOZ_CAN_RUN_SCRIPT_BOUNDARY
virtual mozilla::ipc::IPCResult
RecvUpdateEffects(
452 const EffectsInfo
& aEffects
);
454 void RequestEditCommands(nsIWidget::NativeKeyBindingsType aType
,
455 const WidgetKeyboardEvent
& aEvent
,
456 nsTArray
<CommandInt
>& aCommands
);
461 * Signal to this BrowserChild that it should be made visible:
462 * activated widget, retained layer tree, etc. (Respectively,
465 MOZ_CAN_RUN_SCRIPT
void UpdateVisibility();
466 MOZ_CAN_RUN_SCRIPT
void MakeVisible();
469 ContentChild
* Manager() const { return mManager
; }
471 static inline BrowserChild
* GetFrom(nsIDocShell
* aDocShell
) {
476 nsCOMPtr
<nsIBrowserChild
> tc
= aDocShell
->GetBrowserChild();
477 return static_cast<BrowserChild
*>(tc
.get());
480 static inline BrowserChild
* GetFrom(mozIDOMWindow
* aWindow
) {
481 nsCOMPtr
<nsIWebNavigation
> webNav
= do_GetInterface(aWindow
);
482 nsCOMPtr
<nsIDocShell
> docShell
= do_QueryInterface(webNav
);
483 return GetFrom(docShell
);
486 static inline BrowserChild
* GetFrom(mozIDOMWindowProxy
* aWindow
) {
487 nsCOMPtr
<nsIWebNavigation
> webNav
= do_GetInterface(aWindow
);
488 nsCOMPtr
<nsIDocShell
> docShell
= do_QueryInterface(webNav
);
489 return GetFrom(docShell
);
492 static BrowserChild
* GetFrom(PresShell
* aPresShell
);
493 static BrowserChild
* GetFrom(layers::LayersId aLayersId
);
495 layers::LayersId
GetLayersId() { return mLayersId
; }
496 Maybe
<bool> IsLayersConnected() { return mLayersConnected
; }
498 void DidComposite(mozilla::layers::TransactionId aTransactionId
,
499 const TimeStamp
& aCompositeStart
,
500 const TimeStamp
& aCompositeEnd
);
502 void DidRequestComposite(const TimeStamp
& aCompositeReqStart
,
503 const TimeStamp
& aCompositeReqEnd
);
505 void ClearCachedResources();
506 void InvalidateLayers();
507 void SchedulePaint();
508 void ReinitRendering();
509 void ReinitRenderingForDeviceReset();
511 static inline BrowserChild
* GetFrom(nsIDOMWindow
* aWindow
) {
512 nsCOMPtr
<nsIWebNavigation
> webNav
= do_GetInterface(aWindow
);
513 nsCOMPtr
<nsIDocShell
> docShell
= do_QueryInterface(webNav
);
514 return GetFrom(docShell
);
517 mozilla::ipc::IPCResult
RecvUIResolutionChanged(const float& aDpi
,
518 const int32_t& aRounding
,
519 const double& aScale
);
521 mozilla::ipc::IPCResult
RecvThemeChanged(
522 nsTArray
<LookAndFeelInt
>&& aLookAndFeelIntCache
);
524 mozilla::ipc::IPCResult
RecvHandleAccessKey(const WidgetKeyboardEvent
& aEvent
,
525 nsTArray
<uint32_t>&& aCharCodes
);
527 mozilla::ipc::IPCResult
RecvHandledWindowedPluginKeyEvent(
528 const mozilla::NativeEventData
& aKeyEventData
, const bool& aIsConsumed
);
530 mozilla::ipc::IPCResult
RecvPrint(const uint64_t& aOuterWindowID
,
531 const PrintData
& aPrintData
);
533 mozilla::ipc::IPCResult
RecvUpdateNativeWindowHandle(
534 const uintptr_t& aNewHandle
);
536 mozilla::ipc::IPCResult
RecvWillChangeProcess(
537 WillChangeProcessResolver
&& aResolve
);
539 * Native widget remoting protocol for use with windowed plugins with e10s.
541 PPluginWidgetChild
* AllocPPluginWidgetChild();
543 bool DeallocPPluginWidgetChild(PPluginWidgetChild
* aActor
);
546 nsresult
CreatePluginWidget(nsIWidget
* aParent
, nsIWidget
** aOut
);
549 PPaymentRequestChild
* AllocPPaymentRequestChild();
551 bool DeallocPPaymentRequestChild(PPaymentRequestChild
* aActor
);
553 LayoutDeviceIntPoint
GetClientOffset() const { return mClientOffset
; }
554 LayoutDeviceIntPoint
GetChromeOffset() const { return mChromeOffset
; };
555 ScreenIntCoord
GetDynamicToolbarMaxHeight() const {
556 return mDynamicToolbarMaxHeight
;
559 bool IPCOpen() const { return mIPCOpen
; }
561 bool ParentIsActive() const { return mParentIsActive
; }
563 const mozilla::layers::CompositorOptions
& GetCompositorOptions() const;
564 bool AsyncPanZoomEnabled() const;
566 ScreenIntSize
GetInnerSize();
567 CSSSize
GetUnscaledInnerSize() { return mUnscaledInnerSize
; }
569 Maybe
<LayoutDeviceIntRect
> GetVisibleRect() const;
571 // Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow().
572 void DoFakeShow(const ParentShowInfo
&);
574 void ContentReceivedInputBlock(uint64_t aInputBlockId
,
575 bool aPreventDefault
) const;
577 uint64_t aInputBlockId
,
578 const nsTArray
<layers::ScrollableLayerGuid
>& aTargets
) const;
579 MOZ_CAN_RUN_SCRIPT_BOUNDARY
580 mozilla::ipc::IPCResult
RecvHandleTap(
581 const layers::GeckoContentController_TapType
& aType
,
582 const LayoutDevicePoint
& aPoint
, const Modifiers
& aModifiers
,
583 const ScrollableLayerGuid
& aGuid
, const uint64_t& aInputBlockId
);
585 MOZ_CAN_RUN_SCRIPT_BOUNDARY
586 mozilla::ipc::IPCResult
RecvNormalPriorityHandleTap(
587 const layers::GeckoContentController_TapType
& aType
,
588 const LayoutDevicePoint
& aPoint
, const Modifiers
& aModifiers
,
589 const ScrollableLayerGuid
& aGuid
, const uint64_t& aInputBlockId
);
591 void SetAllowedTouchBehavior(
592 uint64_t aInputBlockId
, const nsTArray
<TouchBehaviorFlags
>& aFlags
) const;
594 bool UpdateFrame(const layers::RepaintRequest
& aRequest
);
595 bool NotifyAPZStateChange(
596 const ViewID
& aViewId
,
597 const layers::GeckoContentController_APZStateChange
& aChange
,
599 void StartScrollbarDrag(const layers::AsyncDragMetrics
& aDragMetrics
);
600 void ZoomToRect(const uint32_t& aPresShellId
,
601 const ScrollableLayerGuid::ViewID
& aViewId
,
602 const CSSRect
& aRect
, const uint32_t& aFlags
);
604 // Request that the docshell be marked as active.
605 void PaintWhileInterruptingJS(const layers::LayersObserverEpoch
& aEpoch
);
607 nsresult
CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType
,
608 int32_t aNavigationIndex
, nsIURI
* aNavigationURI
,
609 int32_t aEpoch
, bool* aCanCancel
);
611 layers::LayersObserverEpoch
LayersObserverEpoch() const {
612 return mLayersObserverEpoch
;
615 #if defined(XP_WIN) && defined(ACCESSIBILITY)
616 uintptr_t GetNativeWindowHandle() const { return mNativeWindowHandle
; }
619 // These methods return `true` if this BrowserChild is currently awaiting a
620 // Large-Allocation header.
621 bool StopAwaitingLargeAlloc();
622 bool IsAwaitingLargeAlloc();
624 BrowsingContext
* GetBrowsingContext() const { return mBrowsingContext
; }
626 #if defined(ACCESSIBILITY)
627 void SetTopLevelDocAccessibleChild(PDocAccessibleChild
* aTopLevelChild
) {
628 mTopLevelDocAccessibleChild
= aTopLevelChild
;
631 PDocAccessibleChild
* GetTopLevelDocAccessibleChild() {
632 return mTopLevelDocAccessibleChild
;
636 void AddPendingDocShellBlocker();
637 void RemovePendingDocShellBlocker();
639 // The HANDLE object for the widget this BrowserChild in.
640 WindowsHandle
WidgetNativeData() { return mWidgetNativeData
; }
642 // The transform from the coordinate space of this BrowserChild to the
643 // coordinate space of the native window its BrowserParent is in.
644 mozilla::LayoutDeviceToLayoutDeviceMatrix4x4
645 GetChildToParentConversionMatrix() const;
647 // Returns the portion of the visible rect of this remote document in the
648 // top browser window coordinate system. This is the result of being clipped
649 // by all ancestor viewports.
650 mozilla::ScreenRect
GetTopLevelViewportVisibleRectInBrowserCoords() const;
652 // Similar to above GetTopLevelViewportVisibleRectInBrowserCoords(), but in
653 // this out-of-process document's coordinate system.
654 Maybe
<LayoutDeviceRect
> GetTopLevelViewportVisibleRectInSelfCoords() const;
656 // Prepare to dispatch all coalesced mousemove events. We'll move all data
657 // in mCoalescedMouseData to a nsDeque; then we start processing them. We
658 // can't fetch the coalesced event one by one and dispatch it because we may
659 // reentry the event loop and access to the same hashtable. It's called when
660 // dispatching some mouse events other than mousemove.
661 void FlushAllCoalescedMouseData();
662 void ProcessPendingCoalescedMouseDataAndDispatchEvents();
664 void HandleRealMouseButtonEvent(const WidgetMouseEvent
& aEvent
,
665 const ScrollableLayerGuid
& aGuid
,
666 const uint64_t& aInputBlockId
);
668 void SetCancelContentJSEpoch(int32_t aEpoch
) {
669 mCancelContentJSEpoch
= aEpoch
;
672 static bool HasVisibleTabs() {
673 return sVisibleTabs
&& !sVisibleTabs
->IsEmpty();
676 // Returns the set of BrowserChilds that are currently rendering layers. There
677 // can be multiple BrowserChilds in this state if Firefox has multiple windows
678 // open or is warming tabs up. There can also be zero BrowserChilds in this
679 // state. Note that this function should only be called if HasVisibleTabs()
681 static const nsTHashtable
<nsPtrHashKey
<BrowserChild
>>& GetVisibleTabs() {
682 MOZ_ASSERT(HasVisibleTabs());
683 return *sVisibleTabs
;
686 bool UpdateSessionStore(uint32_t aFlushId
, bool aIsFinal
= false);
689 // Check if the window this BrowserChild is associated with supports
690 // protected media (EME) or not.
691 // Returns a promise the will resolve true if the window supports protected
692 // media or false if it does not. The promise will be rejected with an
693 // ResponseRejectReason if the IPC needed to do the check fails. Callers
694 // should treat the reject case as if the window does not support protected
695 // media to ensure robust handling.
696 RefPtr
<IsWindowSupportingProtectedMediaPromise
>
697 DoesWindowSupportProtectedMedia();
700 // Notify the content blocking event in the parent process. This sends an IPC
701 // message to the BrowserParent in the parent. The BrowserParent will find the
702 // top-level WindowGlobalParent and notify the event from it.
703 void NotifyContentBlockingEvent(
704 uint32_t aEvent
, nsIChannel
* aChannel
, bool aBlocked
,
705 const nsACString
& aTrackingOrigin
,
706 const nsTArray
<nsCString
>& aTrackingFullHashes
,
707 const Maybe
<ContentBlockingNotifier::StorageAccessGrantedReason
>&
711 virtual ~BrowserChild();
713 mozilla::ipc::IPCResult
RecvDestroy();
715 mozilla::ipc::IPCResult
RecvSetDocShellIsActive(const bool& aIsActive
);
717 mozilla::ipc::IPCResult
RecvSetSuspendMediaWhenInactive(
718 const bool& aSuspendMediaWhenInactive
);
720 MOZ_CAN_RUN_SCRIPT_BOUNDARY
721 mozilla::ipc::IPCResult
RecvRenderLayers(
722 const bool& aEnabled
, const layers::LayersObserverEpoch
& aEpoch
);
724 mozilla::ipc::IPCResult
RecvNavigateByKey(const bool& aForward
,
725 const bool& aForDocumentNavigation
);
727 mozilla::ipc::IPCResult
RecvRequestNotifyAfterRemotePaint();
729 mozilla::ipc::IPCResult
RecvSuppressDisplayport(const bool& aEnabled
);
731 mozilla::ipc::IPCResult
RecvParentActivated(const bool& aActivated
);
733 mozilla::ipc::IPCResult
RecvScrollbarPreferenceChanged(ScrollbarPreference
);
735 mozilla::ipc::IPCResult
RecvSetKeyboardIndicators(
736 const UIStateChangeType
& aShowFocusRings
);
738 mozilla::ipc::IPCResult
RecvStopIMEStateManagement();
740 mozilla::ipc::IPCResult
RecvAwaitLargeAlloc();
742 mozilla::ipc::IPCResult
RecvAllowScriptsToClose();
744 mozilla::ipc::IPCResult
RecvSetWidgetNativeData(
745 const WindowsHandle
& aWidgetNativeData
);
748 // Wraps up a JSON object as a structured clone and sends it to the browser
751 // XXX/bug 780335: Do the work the browser chrome script does in C++ instead
752 // so we don't need things like this.
753 void DispatchMessageManagerMessage(const nsAString
& aMessageName
,
754 const nsAString
& aJSONData
);
756 void ProcessUpdateFrame(const mozilla::layers::RepaintRequest
& aRequest
);
758 bool UpdateFrameHandler(const mozilla::layers::RepaintRequest
& aRequest
);
760 void HandleDoubleTap(const CSSPoint
& aPoint
, const Modifiers
& aModifiers
,
761 const ScrollableLayerGuid
& aGuid
);
763 // Notify others that our TabContext has been updated.
765 // You should call this after calling TabContext::SetTabContext(). We also
766 // call this during Init().
767 void NotifyTabContextUpdated();
769 void ActorDestroy(ActorDestroyReason why
) override
;
771 bool InitBrowserChildMessageManager();
773 void InitRenderingState(
774 const TextureFactoryIdentifier
& aTextureFactoryIdentifier
,
775 const layers::LayersId
& aLayersId
,
776 const mozilla::layers::CompositorOptions
& aCompositorOptions
);
779 void DestroyWindow();
781 void ApplyParentShowInfo(const ParentShowInfo
&);
783 bool HasValidInnerSize();
785 void SetTabId(const TabId
& aTabId
);
787 ScreenIntRect
GetOuterRect();
789 void SetUnscaledInnerSize(const CSSSize
& aSize
) {
790 mUnscaledInnerSize
= aSize
;
793 bool SkipRepeatedKeyEvent(const WidgetKeyboardEvent
& aEvent
);
795 void UpdateRepeatedKeyEventEndTime(const WidgetKeyboardEvent
& aEvent
);
797 bool MaybeCoalesceWheelEvent(const WidgetWheelEvent
& aEvent
,
798 const ScrollableLayerGuid
& aGuid
,
799 const uint64_t& aInputBlockId
,
800 bool* aIsNextWheelEvent
);
802 void MaybeDispatchCoalescedWheelEvent();
805 * Dispatch aEvent on aEvent.mWidget.
807 nsEventStatus
DispatchWidgetEventViaAPZ(WidgetGUIEvent
& aEvent
);
809 void DispatchWheelEvent(const WidgetWheelEvent
& aEvent
,
810 const ScrollableLayerGuid
& aGuid
,
811 const uint64_t& aInputBlockId
);
813 void InternalSetDocShellIsActive(bool aIsActive
);
815 void InternalSetSuspendMediaWhenInactive(bool aSuspendMediaWhenInactive
);
817 bool CreateRemoteLayerManager(
818 mozilla::layers::PCompositorBridgeChild
* aCompositorChild
);
820 nsresult
PrepareProgressListenerData(nsIWebProgress
* aWebProgress
,
821 nsIRequest
* aRequest
,
822 Maybe
<WebProgressData
>& aWebProgressData
,
823 RequestData
& aRequestData
);
824 already_AddRefed
<nsIWebBrowserChrome3
> GetWebBrowserChromeActor();
826 class DelayedDeleteRunnable
;
828 RefPtr
<BrowserChildMessageManager
> mBrowserChildMessageManager
;
829 nsCOMPtr
<nsIWebBrowserChrome3
> mWebBrowserChrome
;
830 TextureFactoryIdentifier mTextureFactoryIdentifier
;
831 RefPtr
<nsWebBrowser
> mWebBrowser
;
832 nsCOMPtr
<nsIWebNavigation
> mWebNav
;
833 RefPtr
<PuppetWidget
> mPuppetWidget
;
834 nsCOMPtr
<nsIURI
> mLastURI
;
835 RefPtr
<ContentChild
> mManager
;
836 RefPtr
<BrowsingContext
> mBrowsingContext
;
837 RefPtr
<nsBrowserStatusFilter
> mStatusFilter
;
838 uint32_t mChromeFlags
;
839 uint32_t mMaxTouchPoints
;
840 layers::LayersId mLayersId
;
841 CSSRect mUnscaledOuterRect
;
842 Maybe
<bool> mLayersConnected
;
843 EffectsInfo mEffectsInfo
;
846 bool mTriedBrowserInit
;
847 hal::ScreenOrientation mOrientation
;
849 bool mIgnoreKeyPressEvent
;
850 RefPtr
<APZEventState
> mAPZEventState
;
851 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback
;
852 bool mHasValidInnerSize
;
855 // Position of client area relative to the outer window
856 LayoutDeviceIntPoint mClientOffset
;
857 // Position of tab, relative to parent widget (typically the window)
858 LayoutDeviceIntPoint mChromeOffset
;
859 ScreenIntCoord mDynamicToolbarMaxHeight
;
862 // Whether or not this browser is the child part of the top level PBrowser
863 // actor in a remote browser.
866 // Whether or not this tab has siblings (other tabs in the same window).
867 // This is one factor used when choosing to allow or deny a non-system
868 // script's attempt to resize the window.
871 // Holds the compositor options for the compositor rendering this tab,
872 // once we find out which compositor that is.
873 Maybe
<mozilla::layers::CompositorOptions
> mCompositorOptions
;
875 friend class ContentChild
;
880 bool mParentIsActive
;
881 CSSSize mUnscaledInnerSize
;
882 bool mDidSetRealShowInfo
;
883 bool mDidLoadURLInit
;
888 // Store the end time of the handling of the last repeated keydown/keypress
889 // event so that in case event handling takes time, some repeated events can
890 // be skipped to not flood child process.
891 mozilla::TimeStamp mRepeatedKeyEventTime
;
893 // Similar to mRepeatedKeyEventTime, store the end time (from parent process)
894 // of handling the last repeated wheel event so that in case event handling
895 // takes time, some repeated events can be skipped to not flood child process.
896 mozilla::TimeStamp mLastWheelProcessedTimeFromParent
;
897 mozilla::TimeDuration mLastWheelProcessingDuration
;
899 // Hash table to track coalesced mousemove events for different pointers.
900 nsClassHashtable
<nsUint32HashKey
, CoalescedMouseData
> mCoalescedMouseData
;
902 nsDeque mToBeDispatchedMouseData
;
904 CoalescedWheelData mCoalescedWheelData
;
905 RefPtr
<CoalescedMouseMoveFlusher
> mCoalescedMouseEventFlusher
;
907 RefPtr
<layers::IAPZCTreeManager
> mApzcTreeManager
;
908 RefPtr
<TabListener
> mSessionStoreListener
;
910 // The most recently seen layer observer epoch in RecvSetDocShellIsActive.
911 layers::LayersObserverEpoch mLayersObserverEpoch
;
913 #if defined(XP_WIN) && defined(ACCESSIBILITY)
914 // The handle associated with the native window that contains this tab
915 uintptr_t mNativeWindowHandle
;
916 #endif // defined(XP_WIN)
918 #if defined(ACCESSIBILITY)
919 PDocAccessibleChild
* mTopLevelDocAccessibleChild
;
921 bool mCoalesceMouseMoveEvents
;
923 bool mShouldSendWebProgressEventsToParent
;
925 // Whether we are rendering to the compositor or not.
928 // In some circumstances, a DocShell might be in a state where it is
929 // "blocked", and we should not attempt to change its active state or
930 // the underlying PresShell state until the DocShell becomes unblocked.
931 // It is possible, however, for the parent process to send commands to
932 // change those states while the DocShell is blocked. We store those
933 // states temporarily as "pending", and only apply them once the DocShell
934 // is no longer blocked.
935 bool mPendingDocShellIsActive
;
936 bool mPendingSuspendMediaWhenInactive
;
937 bool mPendingDocShellReceivedMessage
;
938 bool mPendingRenderLayers
;
939 bool mPendingRenderLayersReceivedMessage
;
940 layers::LayersObserverEpoch mPendingLayersObserverEpoch
;
941 // When mPendingDocShellBlockers is greater than 0, the DocShell is blocked,
942 // and once it reaches 0, it is no longer blocked.
943 uint32_t mPendingDocShellBlockers
;
944 int32_t mCancelContentJSEpoch
;
946 WindowsHandle mWidgetNativeData
;
948 Maybe
<LayoutDeviceToLayoutDeviceMatrix4x4
> mChildToParentConversionMatrix
;
949 ScreenRect mTopLevelViewportVisibleRectInBrowserCoords
;
952 // Should only be accessed on main thread.
953 Maybe
<bool> mWindowSupportsProtectedMedia
;
956 // This state is used to keep track of the current visible tabs (the ones
957 // rendering layers). There may be more than one if there are multiple browser
958 // windows open, or tabs are being warmed up. There may be none if this
959 // process does not host any visible or warming tabs.
960 static nsTHashtable
<nsPtrHashKey
<BrowserChild
>>* sVisibleTabs
;
962 DISALLOW_EVIL_CONSTRUCTORS(BrowserChild
);
966 } // namespace mozilla
968 #endif // mozilla_dom_BrowserChild_h