BrowserChild.h (36620B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_BrowserChild_h 8 #define mozilla_dom_BrowserChild_h 9 10 #include "PuppetWidget.h" 11 #include "mozilla/Attributes.h" 12 #include "mozilla/DOMEventTargetHelper.h" 13 #include "mozilla/EventDispatcher.h" 14 #include "mozilla/EventForwards.h" 15 #include "mozilla/dom/CoalescedMouseData.h" 16 #include "mozilla/dom/CoalescedTouchData.h" 17 #include "mozilla/dom/CoalescedWheelData.h" 18 #include "mozilla/dom/ContentFrameMessageManager.h" 19 #include "mozilla/dom/MessageManagerCallback.h" 20 #include "mozilla/dom/PBrowserChild.h" 21 #include "mozilla/dom/TabContext.h" 22 #include "mozilla/dom/VsyncMainChild.h" 23 #include "mozilla/dom/ipc/IdType.h" 24 #include "mozilla/layers/APZCCallbackHelper.h" 25 #include "mozilla/layers/CompositorOptions.h" 26 #include "mozilla/layers/CompositorTypes.h" 27 #include "mozilla/layers/GeckoContentControllerTypes.h" 28 #include "nsCOMPtr.h" 29 #include "nsDeque.h" 30 #include "nsIBrowserChild.h" 31 #include "nsIDocShell.h" 32 #include "nsIInterfaceRequestor.h" 33 #include "nsIInterfaceRequestorUtils.h" 34 #include "nsIRemoteTab.h" 35 #include "nsITooltipListener.h" 36 #include "nsIWebBrowserChrome.h" 37 #include "nsIWebNavigation.h" 38 #include "nsIWebProgressListener.h" 39 #include "nsIWindowProvider.h" 40 #include "nsWeakReference.h" 41 42 class nsBrowserStatusFilter; 43 class nsIDOMWindow; 44 class nsIHttpChannel; 45 class nsIRequest; 46 class nsISerialEventTarget; 47 class nsIWebProgress; 48 class nsPIDOMWindowInner; 49 class nsWebBrowser; 50 class nsDocShellLoadState; 51 class nsIOpenWindowInfo; 52 53 template <typename T> 54 class nsTHashtable; 55 template <typename T> 56 class nsPtrHashKey; 57 58 namespace mozilla { 59 enum class NativeKeyBindingsType : uint8_t; 60 61 class AbstractThread; 62 class PresShell; 63 64 namespace layers { 65 class APZChild; 66 class APZEventState; 67 class AsyncDragMetrics; 68 class IAPZCTreeManager; 69 class ImageCompositeNotification; 70 class PCompositorBridgeChild; 71 } // namespace layers 72 73 namespace widget { 74 struct AutoCacheNativeKeyCommands; 75 } // namespace widget 76 77 namespace dom { 78 79 class BrowserChild; 80 class BrowsingContext; 81 class TabGroup; 82 class ClonedMessageData; 83 class CoalescedMouseData; 84 class CoalescedWheelData; 85 class SessionStoreChild; 86 class RequestData; 87 class WebProgressData; 88 89 #define DOM_BROWSERCHILD_IID \ 90 {0x58a5775d, 0xba05, 0x45bf, {0xbd, 0xb8, 0xd7, 0x61, 0xf9, 0x01, 0x01, 0x31}} 91 92 class BrowserChildMessageManager : public ContentFrameMessageManager, 93 public nsIMessageSender, 94 public nsSupportsWeakReference { 95 public: 96 explicit BrowserChildMessageManager(BrowserChild* aBrowserChild); 97 98 NS_DECL_ISUPPORTS_INHERITED 99 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BrowserChildMessageManager, 100 DOMEventTargetHelper) 101 102 void MarkForCC(); 103 104 JSObject* WrapObject(JSContext* aCx, 105 JS::Handle<JSObject*> aGivenProto) override; 106 107 Nullable<WindowProxyHolder> GetContent(ErrorResult& aError) override; 108 already_AddRefed<nsIDocShell> GetDocShell(ErrorResult& aError) override; 109 already_AddRefed<nsIEventTarget> GetTabEventTarget() override; 110 111 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) 112 113 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override { 114 aVisitor.mForceContentDispatch = true; 115 } 116 117 // Dispatch a runnable related to the global. 118 nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const; 119 120 RefPtr<BrowserChild> mBrowserChild; 121 122 protected: 123 ~BrowserChildMessageManager(); 124 }; 125 126 /** 127 * BrowserChild implements the child actor part of the PBrowser protocol. See 128 * PBrowser for more information. 129 */ 130 class BrowserChild final : public nsMessageManagerScriptExecutor, 131 public ipc::MessageManagerCallback, 132 public PBrowserChild, 133 public nsIWebBrowserChrome, 134 public nsIInterfaceRequestor, 135 public nsIWindowProvider, 136 public nsSupportsWeakReference, 137 public nsIBrowserChild, 138 public nsIObserver, 139 public nsIWebProgressListener, 140 public TabContext, 141 public nsITooltipListener, 142 public mozilla::ipc::IShmemAllocator { 143 using PuppetWidget = mozilla::widget::PuppetWidget; 144 using ClonedMessageData = mozilla::dom::ClonedMessageData; 145 using CoalescedMouseData = mozilla::dom::CoalescedMouseData; 146 using CoalescedWheelData = mozilla::dom::CoalescedWheelData; 147 using APZEventState = mozilla::layers::APZEventState; 148 using TouchBehaviorFlags = mozilla::layers::TouchBehaviorFlags; 149 150 friend class PBrowserChild; 151 152 public: 153 /** 154 * Find BrowserChild of aTabId in the same content process of the 155 * caller. 156 */ 157 static already_AddRefed<BrowserChild> FindBrowserChild(const TabId& aTabId); 158 159 // Return a list of all active BrowserChildren. 160 static nsTArray<RefPtr<BrowserChild>> GetAll(); 161 162 public: 163 /** 164 * Create a new BrowserChild object. 165 */ 166 BrowserChild(ContentChild* aManager, const TabId& aTabId, 167 const TabContext& aContext, 168 dom::BrowsingContext* aBrowsingContext, uint32_t aChromeFlags, 169 bool aIsTopLevel); 170 171 MOZ_CAN_RUN_SCRIPT nsresult Init(mozIDOMWindowProxy* aParent, 172 WindowGlobalChild* aInitialWindowChild, 173 nsIOpenWindowInfo* aOpenWindowInfo); 174 175 /** Return a BrowserChild with the given attributes. */ 176 static already_AddRefed<BrowserChild> Create( 177 ContentChild* aManager, const TabId& aTabId, const TabContext& aContext, 178 BrowsingContext* aBrowsingContext, uint32_t aChromeFlags, 179 bool aIsTopLevel); 180 181 // Let managees query if it is safe to send messages. 182 bool IsDestroyed() const { return mDestroyed; } 183 184 TabId GetTabId() const { 185 MOZ_ASSERT(mUniqueId != 0); 186 return mUniqueId; 187 } 188 189 NS_INLINE_DECL_STATIC_IID(DOM_BROWSERCHILD_IID) 190 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 191 NS_DECL_NSIWEBBROWSERCHROME 192 NS_DECL_NSIINTERFACEREQUESTOR 193 NS_DECL_NSIWINDOWPROVIDER 194 NS_DECL_NSIBROWSERCHILD 195 NS_DECL_NSIOBSERVER 196 NS_DECL_NSIWEBPROGRESSLISTENER 197 NS_DECL_NSITOOLTIPLISTENER 198 199 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(BrowserChild, 200 nsIBrowserChild) 201 202 FORWARD_SHMEM_ALLOCATOR_TO(PBrowserChild) 203 204 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 205 return mBrowserChildMessageManager->WrapObject(aCx, aGivenProto); 206 } 207 208 // Get the Document for the top-level window in this tab. 209 already_AddRefed<Document> GetTopLevelDocument() const; 210 211 // Get the pres-shell of the document for the top-level window in this tab. 212 PresShell* GetTopLevelPresShell() const; 213 214 BrowserChildMessageManager* GetMessageManager() { 215 return mBrowserChildMessageManager; 216 } 217 218 bool IsTopLevel() const { return mIsTopLevel; } 219 220 bool ShouldSendWebProgressEventsToParent() const { 221 return mShouldSendWebProgressEventsToParent; 222 } 223 224 /** 225 * MessageManagerCallback methods that we override. 226 */ 227 virtual bool DoSendBlockingMessage( 228 const nsAString& aMessage, ipc::StructuredCloneData& aData, 229 nsTArray<UniquePtr<ipc::StructuredCloneData>>* aRetVal) override; 230 231 virtual nsresult DoSendAsyncMessage(const nsAString& aMessage, 232 ipc::StructuredCloneData& aData) override; 233 234 bool DoUpdateZoomConstraints(const uint32_t& aPresShellId, 235 const ViewID& aViewId, 236 const Maybe<ZoomConstraints>& aConstraints); 237 238 mozilla::ipc::IPCResult RecvLoadURL(nsDocShellLoadState* aLoadState, 239 const ParentShowInfo& aInfo); 240 241 mozilla::ipc::IPCResult RecvCreateAboutBlankDocumentViewer( 242 nsIPrincipal* aPrincipal, nsIPrincipal* aPartitionedPrincipal); 243 244 mozilla::ipc::IPCResult RecvResumeLoad(const uint64_t& aPendingSwitchID, 245 const ParentShowInfo&); 246 247 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult 248 RecvCloneDocumentTreeIntoSelf( 249 const MaybeDiscarded<BrowsingContext>& aSourceBC, 250 const embedding::PrintData& aPrintData, 251 CloneDocumentTreeIntoSelfResolver&& aResolve); 252 253 MOZ_CAN_RUN_SCRIPT_BOUNDARY 254 mozilla::ipc::IPCResult RecvUpdateRemotePrintSettings( 255 const embedding::PrintData& aPrintData); 256 257 MOZ_CAN_RUN_SCRIPT_BOUNDARY 258 mozilla::ipc::IPCResult RecvShow(const ParentShowInfo&, const OwnerShowInfo&); 259 260 mozilla::ipc::IPCResult RecvInitRendering( 261 const TextureFactoryIdentifier& aTextureFactoryIdentifier, 262 const layers::LayersId& aLayersId, 263 const mozilla::layers::CompositorOptions& aCompositorOptions, 264 const bool& aLayersConnected); 265 266 mozilla::ipc::IPCResult RecvCompositorOptionsChanged( 267 const mozilla::layers::CompositorOptions& aNewOptions); 268 269 mozilla::ipc::IPCResult RecvUpdateDimensions( 270 const mozilla::dom::DimensionInfo& aDimensionInfo); 271 mozilla::ipc::IPCResult RecvSizeModeChanged(const nsSizeMode& aSizeMode); 272 273 mozilla::ipc::IPCResult RecvChildToParentMatrix( 274 const mozilla::Maybe<mozilla::gfx::Matrix4x4>& aMatrix, 275 const mozilla::ScreenRect& aTopLevelViewportVisibleRectInBrowserCoords); 276 277 MOZ_CAN_RUN_SCRIPT_BOUNDARY 278 mozilla::ipc::IPCResult RecvDynamicToolbarMaxHeightChanged( 279 const mozilla::ScreenIntCoord& aHeight); 280 281 mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged( 282 const mozilla::ScreenIntCoord& aOffset); 283 284 mozilla::ipc::IPCResult RecvKeyboardHeightChanged( 285 const mozilla::ScreenIntCoord& aHeight); 286 287 mozilla::ipc::IPCResult RecvAndroidPipModeChanged(bool aPipMode); 288 289 mozilla::ipc::IPCResult RecvActivate(uint64_t aActionId); 290 291 mozilla::ipc::IPCResult RecvDeactivate(uint64_t aActionId); 292 293 mozilla::ipc::IPCResult RecvRealMouseMoveEvent( 294 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 295 const uint64_t& aInputBlockId); 296 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseMoveEvent( 297 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 298 const uint64_t& aInputBlockId); 299 mozilla::ipc::IPCResult RecvRealMouseMoveEventForTests( 300 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 301 const uint64_t& aInputBlockId); 302 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseMoveEventForTests( 303 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 304 const uint64_t& aInputBlockId); 305 306 mozilla::ipc::IPCResult RecvSynthMouseMoveEvent( 307 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 308 const uint64_t& aInputBlockId); 309 mozilla::ipc::IPCResult RecvNormalPrioritySynthMouseMoveEvent( 310 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 311 const uint64_t& aInputBlockId); 312 313 mozilla::ipc::IPCResult RecvRealMouseButtonEvent( 314 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 315 const uint64_t& aInputBlockId); 316 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseButtonEvent( 317 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 318 const uint64_t& aInputBlockId); 319 320 mozilla::ipc::IPCResult RecvRealPointerButtonEvent( 321 const mozilla::WidgetPointerEvent& aEvent, 322 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId); 323 mozilla::ipc::IPCResult RecvNormalPriorityRealPointerButtonEvent( 324 const mozilla::WidgetPointerEvent& aEvent, 325 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId); 326 327 mozilla::ipc::IPCResult RecvRealMouseEnterExitWidgetEvent( 328 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 329 const uint64_t& aInputBlockId); 330 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseEnterExitWidgetEvent( 331 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 332 const uint64_t& aInputBlockId); 333 334 MOZ_CAN_RUN_SCRIPT_BOUNDARY 335 mozilla::ipc::IPCResult RecvRealDragEvent( 336 const WidgetDragEvent& aEvent, const uint32_t& aDragAction, 337 const uint32_t& aDropEffect, nsIPrincipal* aPrincipal, 338 nsIPolicyContainer* aPolicyContainer); 339 340 mozilla::ipc::IPCResult RecvRealKeyEvent( 341 const mozilla::WidgetKeyboardEvent& aEvent, const nsID& aUUID); 342 343 mozilla::ipc::IPCResult RecvNormalPriorityRealKeyEvent( 344 const mozilla::WidgetKeyboardEvent& aEvent, const nsID& aUUID); 345 346 mozilla::ipc::IPCResult RecvMouseWheelEvent( 347 const mozilla::WidgetWheelEvent& aEvent, const ScrollableLayerGuid& aGuid, 348 const uint64_t& aInputBlockId); 349 350 mozilla::ipc::IPCResult RecvNormalPriorityMouseWheelEvent( 351 const mozilla::WidgetWheelEvent& aEvent, const ScrollableLayerGuid& aGuid, 352 const uint64_t& aInputBlockId); 353 354 mozilla::ipc::IPCResult RecvRealTouchEvent(const WidgetTouchEvent& aEvent, 355 const ScrollableLayerGuid& aGuid, 356 const uint64_t& aInputBlockId, 357 const nsEventStatus& aApzResponse); 358 359 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchEvent( 360 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 361 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 362 363 mozilla::ipc::IPCResult RecvRealTouchMoveEvent( 364 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 365 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 366 367 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchMoveEvent( 368 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 369 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 370 371 mozilla::ipc::IPCResult RecvRealTouchMoveEvent2( 372 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 373 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse) { 374 return RecvRealTouchMoveEvent(aEvent, aGuid, aInputBlockId, aApzResponse); 375 } 376 377 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchMoveEvent2( 378 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 379 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse) { 380 return RecvNormalPriorityRealTouchMoveEvent(aEvent, aGuid, aInputBlockId, 381 aApzResponse); 382 } 383 384 mozilla::ipc::IPCResult RecvUpdateSHistory(); 385 386 mozilla::ipc::IPCResult RecvSynthesizedEventResponse( 387 const uint64_t& aCallbackId); 388 389 mozilla::ipc::IPCResult RecvCompositionEvent( 390 const mozilla::WidgetCompositionEvent& aEvent); 391 392 mozilla::ipc::IPCResult RecvNormalPriorityCompositionEvent( 393 const mozilla::WidgetCompositionEvent& aEvent); 394 395 mozilla::ipc::IPCResult RecvSelectionEvent( 396 const mozilla::WidgetSelectionEvent& aEvent); 397 398 mozilla::ipc::IPCResult RecvNormalPrioritySelectionEvent( 399 const mozilla::WidgetSelectionEvent& aEvent); 400 401 mozilla::ipc::IPCResult RecvSimpleContentCommandEvent( 402 const mozilla::EventMessage& aMessage); 403 404 mozilla::ipc::IPCResult RecvNormalPrioritySimpleContentCommandEvent( 405 const mozilla::EventMessage& aMessage); 406 407 mozilla::ipc::IPCResult RecvInsertText(const nsAString& aStringToInsert); 408 409 mozilla::ipc::IPCResult RecvUpdateRemoteStyle( 410 const StyleImageRendering& aImageRendering); 411 412 mozilla::ipc::IPCResult RecvNormalPriorityInsertText( 413 const nsAString& aStringToInsert); 414 415 mozilla::ipc::IPCResult RecvReplaceText(const nsString& aReplaceSrcString, 416 const nsString& aStringToInsert, 417 uint32_t aOffset, 418 bool aPreventSetSelection); 419 420 mozilla::ipc::IPCResult RecvNormalPriorityReplaceText( 421 const nsString& aReplaceSrcString, const nsString& aStringToInsert, 422 uint32_t aOffset, bool aPreventSetSelection); 423 424 MOZ_CAN_RUN_SCRIPT_BOUNDARY 425 mozilla::ipc::IPCResult RecvPasteTransferable( 426 const IPCTransferable& aTransferable); 427 428 mozilla::ipc::IPCResult RecvLoadRemoteScript(const nsAString& aURL, 429 const bool& aRunInGlobalScope); 430 431 mozilla::ipc::IPCResult RecvAsyncMessage(const nsAString& aMessage, 432 const ClonedMessageData& aData); 433 mozilla::ipc::IPCResult RecvSwappedWithOtherRemoteLoader( 434 const IPCTabContext& aContext); 435 436 mozilla::ipc::IPCResult RecvSafeAreaInsetsChanged( 437 const mozilla::LayoutDeviceIntMargin& aSafeAreaInsets); 438 439 #ifdef ACCESSIBILITY 440 PDocAccessibleChild* AllocPDocAccessibleChild( 441 PDocAccessibleChild*, const uint64_t&, 442 const MaybeDiscardedBrowsingContext&); 443 bool DeallocPDocAccessibleChild(PDocAccessibleChild*); 444 #endif 445 446 RefPtr<VsyncMainChild> GetVsyncChild(); 447 448 nsIWebNavigation* WebNavigation() const { return mWebNav; } 449 450 PuppetWidget* WebWidget() { return mPuppetWidget; } 451 452 bool IsTransparent() const { return mIsTransparent; } 453 454 const EffectsInfo& GetEffectsInfo() const { return mEffectsInfo; } 455 456 void SetBackgroundColor(const nscolor& aColor); 457 458 MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual mozilla::ipc::IPCResult RecvUpdateEffects( 459 const EffectsInfo& aEffects); 460 461 void RequestEditCommands(NativeKeyBindingsType aType, 462 const WidgetKeyboardEvent& aEvent, 463 nsTArray<CommandInt>& aCommands); 464 465 bool IsVisible(); 466 bool IsPreservingLayers() const { return mIsPreservingLayers; } 467 468 /** 469 * Signal to this BrowserChild that it should be made visible: 470 * activated widget, retained layer tree, etc. (Respectively, 471 * made not visible.) 472 */ 473 void UpdateVisibility(); 474 void MakeVisible(); 475 void MakeHidden(); 476 void PresShellActivenessMaybeChanged(); 477 478 ContentChild* Manager() const { return mManager; } 479 480 static inline BrowserChild* GetFrom(nsIDocShell* aDocShell) { 481 if (!aDocShell) { 482 return nullptr; 483 } 484 485 nsCOMPtr<nsIBrowserChild> tc = aDocShell->GetBrowserChild(); 486 return static_cast<BrowserChild*>(tc.get()); 487 } 488 489 static inline BrowserChild* GetFrom(mozIDOMWindow* aWindow) { 490 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 491 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 492 return GetFrom(docShell); 493 } 494 495 static inline BrowserChild* GetFrom(mozIDOMWindowProxy* aWindow) { 496 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 497 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 498 return GetFrom(docShell); 499 } 500 501 static BrowserChild* GetFrom(PresShell* aPresShell); 502 static BrowserChild* GetFrom(layers::LayersId aLayersId); 503 504 layers::LayersId GetLayersId() { return mLayersId; } 505 Maybe<bool> IsLayersConnected() { return mLayersConnected; } 506 507 void DidComposite(mozilla::layers::TransactionId aTransactionId, 508 const TimeStamp& aCompositeStart, 509 const TimeStamp& aCompositeEnd); 510 511 void ClearCachedResources(); 512 void SchedulePaint(); 513 void ReinitRendering(); 514 void ReinitRenderingForDeviceReset(); 515 516 void NotifyJankedAnimations(const nsTArray<uint64_t>& aJankedAnimations); 517 518 static inline BrowserChild* GetFrom(nsIDOMWindow* aWindow) { 519 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 520 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 521 return GetFrom(docShell); 522 } 523 524 mozilla::ipc::IPCResult RecvUIResolutionChanged(const float& aDpi, 525 const int32_t& aRounding, 526 const double& aScale); 527 528 mozilla::ipc::IPCResult RecvTransparencyChanged(const bool& aIsTransparent); 529 530 mozilla::ipc::IPCResult RecvHandleAccessKey(const WidgetKeyboardEvent& aEvent, 531 nsTArray<uint32_t>&& aCharCodes); 532 MOZ_CAN_RUN_SCRIPT_BOUNDARY 533 mozilla::ipc::IPCResult RecvPrintPreview(const PrintData& aPrintData, 534 const MaybeDiscardedBrowsingContext&, 535 PrintPreviewResolver&& aCallback); 536 537 mozilla::ipc::IPCResult RecvExitPrintPreview(); 538 539 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult RecvPrint( 540 const MaybeDiscardedBrowsingContext&, const PrintData&, bool, 541 PrintResolver&&); 542 543 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult RecvPrintClonedPage( 544 const MaybeDiscardedBrowsingContext&, const PrintData&, 545 const MaybeDiscardedBrowsingContext&); 546 547 mozilla::ipc::IPCResult RecvDestroyPrintClone( 548 const MaybeDiscardedBrowsingContext&); 549 550 mozilla::ipc::IPCResult RecvUpdateNativeWindowHandle( 551 const uintptr_t& aNewHandle); 552 553 mozilla::ipc::IPCResult RecvWillChangeProcess(); 554 555 PPaymentRequestChild* AllocPPaymentRequestChild(); 556 557 bool DeallocPPaymentRequestChild(PPaymentRequestChild* aActor); 558 559 LayoutDeviceIntPoint GetClientOffset() const { return mClientOffset; } 560 LayoutDeviceIntPoint GetChromeOffset() const { return mChromeOffset; }; 561 ScreenIntCoord GetDynamicToolbarMaxHeight() const { 562 return mDynamicToolbarMaxHeight; 563 }; 564 mozilla::ScreenIntCoord GetKeyboardHeight() const { return mKeyboardHeight; } 565 566 bool InAndroidPipMode() const { return mInAndroidPipMode; } 567 568 bool IPCOpen() const { return mIPCOpen; } 569 570 const mozilla::layers::CompositorOptions& GetCompositorOptions() const; 571 bool AsyncPanZoomEnabled() const; 572 573 LayoutDeviceIntSize GetInnerSize(); 574 CSSSize GetUnscaledInnerSize() { return mUnscaledInnerSize; } 575 576 Maybe<nsRect> GetVisibleRect() const; 577 578 // Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow(). 579 void DoFakeShow(const ParentShowInfo&); 580 581 void ContentReceivedInputBlock(uint64_t aInputBlockId, 582 bool aPreventDefault) const; 583 void SetTargetAPZC( 584 uint64_t aInputBlockId, 585 const nsTArray<layers::ScrollableLayerGuid>& aTargets) const; 586 MOZ_CAN_RUN_SCRIPT_BOUNDARY 587 mozilla::ipc::IPCResult RecvHandleTap( 588 const layers::GeckoContentController_TapType& aType, 589 const LayoutDevicePoint& aPoint, const Modifiers& aModifiers, 590 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId, 591 const Maybe<DoubleTapToZoomMetrics>& aDoubleTapToZoomMetrics); 592 593 MOZ_CAN_RUN_SCRIPT_BOUNDARY 594 mozilla::ipc::IPCResult RecvNormalPriorityHandleTap( 595 const layers::GeckoContentController_TapType& aType, 596 const LayoutDevicePoint& aPoint, const Modifiers& aModifiers, 597 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId, 598 const Maybe<DoubleTapToZoomMetrics>& aDoubleTapToZoomMetrics); 599 600 bool UpdateFrame(const layers::RepaintRequest& aRequest); 601 void NotifyAPZStateChange( 602 const ViewID& aViewId, 603 const layers::GeckoContentController_APZStateChange& aChange, 604 const int& aArg, Maybe<uint64_t> aInputBlockId); 605 void StartScrollbarDrag(const layers::AsyncDragMetrics& aDragMetrics); 606 void ZoomToRect(const uint32_t& aPresShellId, 607 const ScrollableLayerGuid::ViewID& aViewId, 608 const CSSRect& aRect, const uint32_t& aFlags); 609 610 // Request that the docshell be marked as active. 611 void PaintWhileInterruptingJS(); 612 613 void UnloadLayersWhileInterruptingJS(); 614 615 nsresult CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType, 616 int32_t aNavigationIndex, nsIURI* aNavigationURI, 617 int32_t aEpoch, bool* aCanCancel); 618 619 #if defined(XP_WIN) && defined(ACCESSIBILITY) 620 uintptr_t GetNativeWindowHandle() const { return mNativeWindowHandle; } 621 #endif 622 623 BrowsingContext* GetBrowsingContext() const { return mBrowsingContext; } 624 625 // The transform from the coordinate space of this BrowserChild to the 626 // coordinate space of the native window its BrowserParent is in. 627 mozilla::LayoutDeviceToLayoutDeviceMatrix4x4 628 GetChildToParentConversionMatrix() const; 629 630 // Returns the portion of the visible rect of this remote document in the 631 // top browser window coordinate system. This is the result of being 632 // clipped by all ancestor viewports. 633 Maybe<ScreenRect> GetTopLevelViewportVisibleRectInBrowserCoords() const; 634 635 // Similar to above GetTopLevelViewportVisibleRectInBrowserCoords(), but 636 // in this out-of-process document's coordinate system. 637 Maybe<LayoutDeviceRect> GetTopLevelViewportVisibleRectInSelfCoords() const; 638 639 // Prepare to dispatch all coalesced mousemove events. We'll move all data 640 // in mCoalescedMouseData to a nsDeque; then we start processing them. We 641 // can't fetch the coalesced event one by one and dispatch it because we 642 // may reentry the event loop and access to the same hashtable. It's 643 // called when dispatching some mouse events other than mousemove. 644 void FlushAllCoalescedMouseData(); 645 646 void ProcessPendingCoalescedMouseDataAndDispatchEvents(); 647 648 void ProcessPendingCoalescedTouchData(); 649 650 /** 651 * Dispatch an eMouseRawUpdate event for dispatching ePointerRawUpdate event 652 * into the DOM immediately when aPendingEvent will be dispatched later. 653 * This does nothing if there is no window which has at least one 654 * `pointerrawupdate` event listener. 655 */ 656 void HandleMouseRawUpdateEvent(const WidgetMouseEvent& aPendingMouseEvent, 657 const ScrollableLayerGuid& aGuid, 658 const uint64_t& aInputBlockId); 659 660 void HandleRealMouseButtonEvent(const WidgetMouseEvent& aEvent, 661 const ScrollableLayerGuid& aGuid, 662 const uint64_t& aInputBlockId); 663 664 /** 665 * Dispatch an eTouchRawUpdate event for dispatching ePointerRawUpdate event 666 * into the DOM immediately when aPendingEvent will be dispatched later. 667 * This does nothing if there is no window which has at least one 668 * `pointerrawupdate` event listener. 669 */ 670 void HandleTouchRawUpdateEvent(const WidgetTouchEvent& aPendingTouchEvent, 671 const ScrollableLayerGuid& aGuid, 672 const uint64_t& aInputBlockId, 673 const nsEventStatus& aApzResponse); 674 675 void SetCancelContentJSEpoch(int32_t aEpoch) { 676 mCancelContentJSEpoch = aEpoch; 677 } 678 679 void UpdateSessionStore(); 680 681 mozilla::dom::SessionStoreChild* GetSessionStoreChild() { 682 return mSessionStoreChild; 683 } 684 685 #ifdef XP_WIN 686 // Check if the window this BrowserChild is associated with supports 687 // protected media (EME) or not. 688 // Returns a promise the will resolve true if the window supports 689 // protected media or false if it does not. The promise will be rejected 690 // with an ResponseRejectReason if the IPC needed to do the check fails. 691 // Callers should treat the reject case as if the window does not support 692 // protected media to ensure robust handling. 693 RefPtr<IsWindowSupportingProtectedMediaPromise> 694 DoesWindowSupportProtectedMedia(); 695 #endif 696 697 // Notify the content blocking event in the parent process. This sends an 698 // IPC message to the BrowserParent in the parent. The BrowserParent will 699 // find the top-level WindowGlobalParent and notify the event from it. 700 void NotifyContentBlockingEvent( 701 uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, 702 const nsACString& aTrackingOrigin, 703 const nsTArray<nsCString>& aTrackingFullHashes, 704 const Maybe< 705 ContentBlockingNotifier::StorageAccessPermissionGrantedReason>& 706 aReason, 707 const Maybe<CanvasFingerprintingEvent>& aCanvasFingerprintingEvent); 708 709 already_AddRefed<nsIDragSession> GetDragSession(); 710 void SetDragSession(nsIDragSession* aSession); 711 712 mozilla::ipc::IPCResult RecvInvokeChildDragSession( 713 const MaybeDiscarded<WindowContext>& aSourceWindowContext, 714 const MaybeDiscarded<WindowContext>& aSourceTopWindowContext, 715 nsIPrincipal* aPrincipal, nsTArray<IPCTransferableData>&& aTransferables, 716 const uint32_t& aAction); 717 718 mozilla::ipc::IPCResult RecvUpdateDragSession( 719 nsIPrincipal* aPrincipal, nsTArray<IPCTransferableData>&& aTransferables, 720 EventMessage aEventMessage); 721 722 MOZ_CAN_RUN_SCRIPT_BOUNDARY 723 mozilla::ipc::IPCResult RecvEndDragSession( 724 const bool& aDoneDrag, const bool& aUserCancelled, 725 const mozilla::LayoutDeviceIntPoint& aEndDragPoint, 726 const uint32_t& aKeyModifiers, const uint32_t& aDropEffect); 727 728 mozilla::ipc::IPCResult RecvStoreDropTargetAndDelayEndDragSession( 729 const LayoutDeviceIntPoint& aPt, uint32_t aDropEffect, 730 uint32_t aDragAction, nsIPrincipal* aPrincipal, 731 nsIPolicyContainer* aPolicyContainer); 732 733 MOZ_CAN_RUN_SCRIPT_BOUNDARY 734 mozilla::ipc::IPCResult RecvDispatchToDropTargetAndResumeEndDragSession( 735 bool aShouldDrop, nsTHashSet<nsString>&& aAllowedFilesPaths); 736 737 void OnPointerRawUpdateEventListenerAdded(const nsPIDOMWindowInner* aWindow); 738 void OnPointerRawUpdateEventListenerRemoved( 739 const nsPIDOMWindowInner* aWindow); 740 [[nodiscard]] bool HasPointerRawUpdateEventListeners() const { 741 return !!mPointerRawUpdateWindowCount; 742 } 743 744 protected: 745 virtual ~BrowserChild(); 746 747 mozilla::ipc::IPCResult RecvDestroy(); 748 749 MOZ_CAN_RUN_SCRIPT_BOUNDARY 750 mozilla::ipc::IPCResult RecvRenderLayers(const bool& aEnabled); 751 752 mozilla::ipc::IPCResult RecvPreserveLayers(bool); 753 754 mozilla::ipc::IPCResult RecvNavigateByKey(const bool& aForward, 755 const bool& aForDocumentNavigation); 756 757 mozilla::ipc::IPCResult RecvSuppressDisplayport(const bool& aEnabled); 758 759 mozilla::ipc::IPCResult RecvScrollbarPreferenceChanged(ScrollbarPreference); 760 761 mozilla::ipc::IPCResult RecvStopIMEStateManagement(); 762 763 mozilla::ipc::IPCResult RecvAllowScriptsToClose(); 764 765 mozilla::ipc::IPCResult RecvReleaseAllPointerCapture(); 766 767 mozilla::ipc::IPCResult RecvReleasePointerLock(); 768 769 private: 770 void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers, 771 const ScrollableLayerGuid& aGuid, 772 const DoubleTapToZoomMetrics& aMetrics); 773 774 void ActorDestroy(ActorDestroyReason why) override; 775 776 bool InitBrowserChildMessageManager(); 777 778 void InitRenderingState( 779 const TextureFactoryIdentifier& aTextureFactoryIdentifier, 780 const layers::LayersId& aLayersId, 781 const mozilla::layers::CompositorOptions& aCompositorOptions); 782 void InitAPZState(); 783 784 void DestroyWindow(); 785 786 void ApplyParentShowInfo(const ParentShowInfo&); 787 788 bool HasValidInnerSize(); 789 790 LayoutDeviceIntRect GetOuterRect(); 791 792 void SetUnscaledInnerSize(const CSSSize& aSize) { 793 mUnscaledInnerSize = aSize; 794 } 795 796 bool SkipRepeatedKeyEvent(const WidgetKeyboardEvent& aEvent); 797 798 void UpdateRepeatedKeyEventEndTime(const WidgetKeyboardEvent& aEvent); 799 800 void DispatchCoalescedWheelEvent(); 801 802 /** 803 * Dispatch aEvent on aEvent.mWidget. 804 */ 805 nsEventStatus DispatchWidgetEventViaAPZ(WidgetGUIEvent& aEvent); 806 807 void DispatchWheelEvent(const WidgetWheelEvent& aEvent, 808 const ScrollableLayerGuid& aGuid, 809 const uint64_t& aInputBlockId); 810 811 void InternalSetDocShellIsActive(bool aIsActive); 812 813 MOZ_CAN_RUN_SCRIPT 814 mozilla::ipc::IPCResult CommonPrint( 815 const MaybeDiscardedBrowsingContext& aBc, const PrintData& aPrintData, 816 RefPtr<BrowsingContext>* aCachedBrowsingContext); 817 818 bool CreateRemoteLayerManager( 819 mozilla::layers::PCompositorBridgeChild* aCompositorChild); 820 821 nsresult PrepareRequestData(nsIRequest* aRequest, RequestData& aRequestData); 822 nsresult PrepareProgressListenerData(nsIWebProgress* aWebProgress, 823 nsIRequest* aRequest, 824 WebProgressData& aWebProgressData, 825 RequestData& aRequestData); 826 827 MOZ_CAN_RUN_SCRIPT_BOUNDARY 828 nsresult UpdateRemotePrintSettings(const embedding::PrintData& aPrintData); 829 830 MOZ_CAN_RUN_SCRIPT_BOUNDARY 831 nsresult CloneDocumentTreeIntoSelf( 832 const MaybeDiscarded<BrowsingContext>& aSourceBC, 833 const embedding::PrintData& aPrintData); 834 835 already_AddRefed<DataTransfer> ConvertToDataTransfer( 836 nsIPrincipal* aPrincipal, nsTArray<IPCTransferableData>&& aTransferables, 837 EventMessage aMessage); 838 839 class DelayedDeleteRunnable; 840 841 RefPtr<BrowserChildMessageManager> mBrowserChildMessageManager; 842 TextureFactoryIdentifier mTextureFactoryIdentifier; 843 RefPtr<nsWebBrowser> mWebBrowser; 844 nsCOMPtr<nsIWebNavigation> mWebNav; 845 RefPtr<PuppetWidget> mPuppetWidget; 846 nsCOMPtr<nsIURI> mLastURI; 847 RefPtr<ContentChild> mManager; 848 RefPtr<BrowsingContext> mBrowsingContext; 849 RefPtr<nsIDragSession> mDragSession; 850 851 Maybe<CodeNameIndex> mPreviousConsumedKeyDownCode; 852 uint32_t mChromeFlags; 853 uint32_t mMaxTouchPoints; 854 // The number of windows which may have ePointerRawUpdate event listener. 855 uint32_t mPointerRawUpdateWindowCount = 0; 856 layers::LayersId mLayersId; 857 CSSRect mUnscaledOuterRect; 858 Maybe<bool> mLayersConnected; 859 Maybe<bool> mLayersConnectRequested; 860 EffectsInfo mEffectsInfo; 861 862 RefPtr<APZEventState> mAPZEventState; 863 864 // Position of client area relative to the outer window 865 LayoutDeviceIntPoint mClientOffset; 866 // Position of tab, relative to parent widget (typically the window) 867 // NOTE: This value is valuable only for the top level browser. 868 LayoutDeviceIntPoint mChromeOffset; 869 ScreenIntCoord mDynamicToolbarMaxHeight; 870 // The software keyboard height. 871 ScreenIntCoord mKeyboardHeight; 872 TabId mUniqueId; 873 874 // Position of a delayed drop event. 875 LayoutDeviceIntPoint mDelayedDropPoint; 876 877 bool mDidFakeShow : 1; 878 bool mTriedBrowserInit : 1; 879 bool mHasValidInnerSize : 1; 880 bool mDestroyed : 1; 881 // Whether we're in Android's PiP mode. 882 bool mInAndroidPipMode : 1; 883 884 // Whether or not this browser is the child part of the top level PBrowser 885 // actor in a remote browser. 886 bool mIsTopLevel : 1; 887 888 bool mIsTransparent : 1; 889 bool mIPCOpen : 1; 890 891 bool mDidSetRealShowInfo : 1; 892 bool mDidLoadURLInit : 1; 893 894 bool mSkipKeyPress : 1; 895 896 bool mCoalesceMouseMoveEvents : 1; 897 898 bool mShouldSendWebProgressEventsToParent : 1; 899 900 // Whether we are rendering to the compositor or not. 901 bool mRenderLayers : 1; 902 903 // Whether we're artificially preserving layers. 904 bool mIsPreservingLayers : 1; 905 906 // Holds the compositor options for the compositor rendering this tab, 907 // once we find out which compositor that is. 908 Maybe<mozilla::layers::CompositorOptions> mCompositorOptions; 909 910 friend class ContentChild; 911 912 CSSSize mUnscaledInnerSize; 913 914 // Store the end time of the handling of the last repeated 915 // keydown/keypress event so that in case event handling takes time, some 916 // repeated events can be skipped to not flood child process. 917 mozilla::TimeStamp mRepeatedKeyEventTime; 918 919 // Similar to mRepeatedKeyEventTime, store the end time (from parent 920 // process) of handling the last repeated wheel event so that in case 921 // event handling takes time, some repeated events can be skipped to not 922 // flood child process. 923 mozilla::TimeStamp mLastWheelProcessedTimeFromParent; 924 mozilla::TimeDuration mLastWheelProcessingDuration; 925 926 // Hash table to track coalesced mousemove events for different pointers. 927 nsClassHashtable<nsUint32HashKey, CoalescedMouseData> mCoalescedMouseData; 928 929 nsDeque<CoalescedMouseData> mToBeDispatchedMouseData; 930 931 CoalescedWheelData mCoalescedWheelData; 932 CoalescedTouchData mCoalescedTouchData; 933 934 RefPtr<CoalescedMouseMoveFlusher> mCoalescedMouseEventFlusher; 935 RefPtr<CoalescedTouchMoveFlusher> mCoalescedTouchMoveEventFlusher; 936 937 RefPtr<layers::IAPZCTreeManager> mApzcTreeManager; 938 RefPtr<SessionStoreChild> mSessionStoreChild; 939 940 #if defined(XP_WIN) && defined(ACCESSIBILITY) 941 // The handle associated with the native window that contains this tab 942 uintptr_t mNativeWindowHandle; 943 #endif // defined(XP_WIN) 944 945 int32_t mCancelContentJSEpoch; 946 947 Maybe<LayoutDeviceToLayoutDeviceMatrix4x4> mChildToParentConversionMatrix; 948 // When mChildToParentConversionMatrix is Nothing() this value is invalid. 949 ScreenRect mTopLevelViewportVisibleRectInBrowserCoords; 950 951 #ifdef XP_WIN 952 // Should only be accessed on main thread. 953 Maybe<bool> mWindowSupportsProtectedMedia; 954 #endif 955 956 // If set, resolve when we receive ChildToParentMatrix. 957 RefPtr<dom::Promise> mContentTransformPromise; 958 959 DISALLOW_EVIL_CONSTRUCTORS(BrowserChild); 960 }; 961 962 } // namespace dom 963 } // namespace mozilla 964 965 #endif // mozilla_dom_BrowserChild_h