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 "mozilla/dom/ContentFrameMessageManager.h" 11 #include "mozilla/dom/PBrowserChild.h" 12 #include "nsIWebNavigation.h" 13 #include "nsCOMPtr.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" 43 #include "nsDeque.h" 44 45 class nsBrowserStatusFilter; 46 class nsIDOMWindow; 47 class nsIHttpChannel; 48 class nsIRequest; 49 class nsISerialEventTarget; 50 class nsIWebProgress; 51 class nsWebBrowser; 52 53 template <typename T> 54 class nsTHashtable; 55 template <typename T> 56 class nsPtrHashKey; 57 58 namespace mozilla { 59 class AbstractThread; 60 class PresShell; 61 62 namespace layers { 63 class APZChild; 64 class APZEventState; 65 class AsyncDragMetrics; 66 class IAPZCTreeManager; 67 class ImageCompositeNotification; 68 class PCompositorBridgeChild; 69 } // namespace layers 70 71 namespace widget { 72 struct AutoCacheNativeKeyCommands; 73 } // namespace widget 74 75 namespace dom { 76 77 class BrowserChild; 78 class BrowsingContext; 79 class TabGroup; 80 class ClonedMessageData; 81 class CoalescedMouseData; 82 class CoalescedWheelData; 83 class ContentSessionStore; 84 class TabListener; 85 class RequestData; 86 class WebProgressData; 87 88 class BrowserChildMessageManager : public ContentFrameMessageManager, 89 public nsIMessageSender, 90 public DispatcherTrait, 91 public nsSupportsWeakReference { 92 public: 93 explicit BrowserChildMessageManager(BrowserChild* aBrowserChild); 94 95 NS_DECL_ISUPPORTS_INHERITED 96 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BrowserChildMessageManager, 97 DOMEventTargetHelper) 98 99 void MarkForCC(); 100 101 JSObject* WrapObject(JSContext* aCx, 102 JS::Handle<JSObject*> aGivenProto) override; 103 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; 109 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager)110 NS_FORWARD_SAFE_NSIMESSAGESENDER(mMessageManager) 111 112 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override { 113 aVisitor.mForceContentDispatch = true; 114 } 115 116 // Dispatch a runnable related to the global. 117 virtual nsresult Dispatch(mozilla::TaskCategory aCategory, 118 already_AddRefed<nsIRunnable>&& aRunnable) override; 119 120 virtual nsISerialEventTarget* EventTargetFor( 121 mozilla::TaskCategory aCategory) const override; 122 123 virtual AbstractThread* AbstractMainThreadFor( 124 mozilla::TaskCategory aCategory) override; 125 126 RefPtr<BrowserChild> mBrowserChild; 127 128 protected: 129 ~BrowserChildMessageManager(); 130 }; 131 132 class ContentListener final : public nsIDOMEventListener { 133 public: ContentListener(BrowserChild * aBrowserChild)134 explicit ContentListener(BrowserChild* aBrowserChild) 135 : mBrowserChild(aBrowserChild) {} 136 NS_DECL_ISUPPORTS 137 NS_DECL_NSIDOMEVENTLISTENER 138 protected: 139 ~ContentListener() = default; 140 BrowserChild* mBrowserChild; 141 }; 142 143 /** 144 * BrowserChild implements the child actor part of the PBrowser protocol. See 145 * PBrowser for more information. 146 */ 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, 157 public nsIObserver, 158 public nsIWebProgressListener2, 159 public TabContext, 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; 170 171 friend class PBrowserChild; 172 173 public: 174 /** 175 * Find BrowserChild of aTabId in the same content process of the 176 * caller. 177 */ 178 static already_AddRefed<BrowserChild> FindBrowserChild(const TabId& aTabId); 179 180 // Return a list of all active BrowserChildren. 181 static nsTArray<RefPtr<BrowserChild>> GetAll(); 182 183 public: 184 /** 185 * Create a new BrowserChild object. 186 */ 187 BrowserChild(ContentChild* aManager, const TabId& aTabId, 188 const TabContext& aContext, 189 dom::BrowsingContext* aBrowsingContext, uint32_t aChromeFlags, 190 bool aIsTopLevel); 191 192 nsresult Init(mozIDOMWindowProxy* aParent, 193 WindowGlobalChild* aInitialWindowChild); 194 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, 199 bool aIsTopLevel); 200 201 // Let managees query if it is safe to send messages. IsDestroyed()202 bool IsDestroyed() const { return mDestroyed; } 203 GetTabId()204 const TabId GetTabId() const { 205 MOZ_ASSERT(mUniqueId != 0); 206 return mUniqueId; 207 } 208 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 216 NS_DECL_NSIOBSERVER 217 NS_DECL_NSIWEBPROGRESSLISTENER 218 NS_DECL_NSIWEBPROGRESSLISTENER2 219 NS_DECL_NSITOOLTIPLISTENER 220 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(BrowserChild,nsIBrowserChild)221 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(BrowserChild, 222 nsIBrowserChild) 223 224 FORWARD_SHMEM_ALLOCATOR_TO(PBrowserChild) 225 226 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 227 return mBrowserChildMessageManager->WrapObject(aCx, aGivenProto); 228 } 229 230 // Get the Document for the top-level window in this tab. 231 already_AddRefed<Document> GetTopLevelDocument() const; 232 233 // Get the pres-shell of the document for the top-level window in this tab. 234 PresShell* GetTopLevelPresShell() const; 235 GetMessageManager()236 BrowserChildMessageManager* GetMessageManager() { 237 return mBrowserChildMessageManager; 238 } 239 IsTopLevel()240 bool IsTopLevel() const { return mIsTopLevel; } 241 242 /** 243 * MessageManagerCallback methods that we override. 244 */ 245 virtual bool DoSendBlockingMessage( 246 const nsAString& aMessage, StructuredCloneData& aData, 247 nsTArray<StructuredCloneData>* aRetVal) override; 248 249 virtual nsresult DoSendAsyncMessage(const nsAString& aMessage, 250 StructuredCloneData& aData) override; 251 252 bool DoUpdateZoomConstraints(const uint32_t& aPresShellId, 253 const ViewID& aViewId, 254 const Maybe<ZoomConstraints>& aConstraints); 255 256 mozilla::ipc::IPCResult RecvLoadURL(const nsCString& aURI, 257 nsIPrincipal* aTriggeringPrincipal, 258 const ParentShowInfo&); 259 260 mozilla::ipc::IPCResult RecvResumeLoad(const uint64_t& aPendingSwitchID, 261 const ParentShowInfo&); 262 263 MOZ_CAN_RUN_SCRIPT_BOUNDARY 264 mozilla::ipc::IPCResult RecvShow(const ParentShowInfo&, const OwnerShowInfo&); 265 266 mozilla::ipc::IPCResult RecvInitRendering( 267 const TextureFactoryIdentifier& aTextureFactoryIdentifier, 268 const layers::LayersId& aLayersId, 269 const mozilla::layers::CompositorOptions& aCompositorOptions, 270 const bool& aLayersConnected); 271 272 mozilla::ipc::IPCResult RecvCompositorOptionsChanged( 273 const mozilla::layers::CompositorOptions& aNewOptions); 274 275 mozilla::ipc::IPCResult RecvUpdateDimensions( 276 const mozilla::dom::DimensionInfo& aDimensionInfo); 277 mozilla::ipc::IPCResult RecvSizeModeChanged(const nsSizeMode& aSizeMode); 278 279 mozilla::ipc::IPCResult RecvChildToParentMatrix( 280 const mozilla::Maybe<mozilla::gfx::Matrix4x4>& aMatrix, 281 const mozilla::ScreenRect& aTopLevelViewportVisibleRectInBrowserCoords); 282 283 MOZ_CAN_RUN_SCRIPT_BOUNDARY 284 mozilla::ipc::IPCResult RecvDynamicToolbarMaxHeightChanged( 285 const mozilla::ScreenIntCoord& aHeight); 286 287 mozilla::ipc::IPCResult RecvDynamicToolbarOffsetChanged( 288 const mozilla::ScreenIntCoord& aOffset); 289 290 mozilla::ipc::IPCResult RecvActivate(); 291 292 mozilla::ipc::IPCResult RecvDeactivate(); 293 294 MOZ_CAN_RUN_SCRIPT_BOUNDARY 295 mozilla::ipc::IPCResult RecvMouseEvent(const nsString& aType, const float& aX, 296 const float& aY, 297 const int32_t& aButton, 298 const int32_t& aClickCount, 299 const int32_t& aModifiers); 300 301 mozilla::ipc::IPCResult RecvRealMouseMoveEvent( 302 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 303 const uint64_t& aInputBlockId); 304 305 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseMoveEvent( 306 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 307 const uint64_t& aInputBlockId); 308 309 mozilla::ipc::IPCResult RecvSynthMouseMoveEvent( 310 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 311 const uint64_t& aInputBlockId); 312 mozilla::ipc::IPCResult RecvNormalPrioritySynthMouseMoveEvent( 313 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 314 const uint64_t& aInputBlockId); 315 316 mozilla::ipc::IPCResult RecvRealMouseButtonEvent( 317 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 318 const uint64_t& aInputBlockId); 319 mozilla::ipc::IPCResult RecvNormalPriorityRealMouseButtonEvent( 320 const mozilla::WidgetMouseEvent& aEvent, const ScrollableLayerGuid& aGuid, 321 const uint64_t& aInputBlockId); 322 323 MOZ_CAN_RUN_SCRIPT_BOUNDARY 324 mozilla::ipc::IPCResult RecvRealDragEvent(const WidgetDragEvent& aEvent, 325 const uint32_t& aDragAction, 326 const uint32_t& aDropEffect, 327 nsIPrincipal* aPrincipal, 328 nsIContentSecurityPolicy* aCsp); 329 330 mozilla::ipc::IPCResult RecvRealKeyEvent( 331 const mozilla::WidgetKeyboardEvent& aEvent); 332 333 mozilla::ipc::IPCResult RecvNormalPriorityRealKeyEvent( 334 const mozilla::WidgetKeyboardEvent& aEvent); 335 336 mozilla::ipc::IPCResult RecvMouseWheelEvent( 337 const mozilla::WidgetWheelEvent& aEvent, const ScrollableLayerGuid& aGuid, 338 const uint64_t& aInputBlockId); 339 340 mozilla::ipc::IPCResult RecvNormalPriorityMouseWheelEvent( 341 const mozilla::WidgetWheelEvent& aEvent, const ScrollableLayerGuid& aGuid, 342 const uint64_t& aInputBlockId); 343 344 mozilla::ipc::IPCResult RecvRealTouchEvent(const WidgetTouchEvent& aEvent, 345 const ScrollableLayerGuid& aGuid, 346 const uint64_t& aInputBlockId, 347 const nsEventStatus& aApzResponse); 348 349 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchEvent( 350 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 351 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 352 353 mozilla::ipc::IPCResult RecvRealTouchMoveEvent( 354 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 355 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 356 357 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchMoveEvent( 358 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 359 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse); 360 RecvRealTouchMoveEvent2(const WidgetTouchEvent & aEvent,const ScrollableLayerGuid & aGuid,const uint64_t & aInputBlockId,const nsEventStatus & aApzResponse)361 mozilla::ipc::IPCResult RecvRealTouchMoveEvent2( 362 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 363 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse) { 364 return RecvRealTouchMoveEvent(aEvent, aGuid, aInputBlockId, aApzResponse); 365 } 366 RecvNormalPriorityRealTouchMoveEvent2(const WidgetTouchEvent & aEvent,const ScrollableLayerGuid & aGuid,const uint64_t & aInputBlockId,const nsEventStatus & aApzResponse)367 mozilla::ipc::IPCResult RecvNormalPriorityRealTouchMoveEvent2( 368 const WidgetTouchEvent& aEvent, const ScrollableLayerGuid& aGuid, 369 const uint64_t& aInputBlockId, const nsEventStatus& aApzResponse) { 370 return RecvNormalPriorityRealTouchMoveEvent(aEvent, aGuid, aInputBlockId, 371 aApzResponse); 372 } 373 374 mozilla::ipc::IPCResult RecvFlushTabState(const uint32_t& aFlushId, 375 const bool& aIsFinal); 376 377 mozilla::ipc::IPCResult RecvUpdateEpoch(const uint32_t& aEpoch); 378 379 mozilla::ipc::IPCResult RecvUpdateSHistory(const bool& aImmediately); 380 381 mozilla::ipc::IPCResult RecvNativeSynthesisResponse( 382 const uint64_t& aObserverId, const nsCString& aResponse); 383 384 mozilla::ipc::IPCResult RecvPluginEvent(const WidgetPluginEvent& aEvent); 385 386 mozilla::ipc::IPCResult RecvCompositionEvent( 387 const mozilla::WidgetCompositionEvent& aEvent); 388 389 mozilla::ipc::IPCResult RecvNormalPriorityCompositionEvent( 390 const mozilla::WidgetCompositionEvent& aEvent); 391 392 mozilla::ipc::IPCResult RecvSelectionEvent( 393 const mozilla::WidgetSelectionEvent& aEvent); 394 395 mozilla::ipc::IPCResult RecvNormalPrioritySelectionEvent( 396 const mozilla::WidgetSelectionEvent& aEvent); 397 398 mozilla::ipc::IPCResult RecvSetIsUnderHiddenEmbedderElement( 399 const bool& aIsUnderHiddenEmbedderElement); 400 401 MOZ_CAN_RUN_SCRIPT_BOUNDARY 402 mozilla::ipc::IPCResult RecvPasteTransferable( 403 const IPCDataTransfer& aDataTransfer, const bool& aIsPrivateData, 404 nsIPrincipal* aRequestingPrincipal, const uint32_t& aContentPolicyType); 405 406 mozilla::ipc::IPCResult RecvActivateFrameEvent(const nsString& aType, 407 const bool& aCapture); 408 409 mozilla::ipc::IPCResult RecvLoadRemoteScript(const nsString& aURL, 410 const bool& aRunInGlobalScope); 411 412 mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMessage, 413 const ClonedMessageData& aData); 414 mozilla::ipc::IPCResult RecvSwappedWithOtherRemoteLoader( 415 const IPCTabContext& aContext); 416 417 mozilla::ipc::IPCResult RecvSafeAreaInsetsChanged( 418 const mozilla::ScreenIntMargin& aSafeAreaInsets); 419 420 #ifdef ACCESSIBILITY 421 PDocAccessibleChild* AllocPDocAccessibleChild(PDocAccessibleChild*, 422 const uint64_t&, 423 const uint32_t&, 424 const IAccessibleHolder&); 425 bool DeallocPDocAccessibleChild(PDocAccessibleChild*); 426 #endif 427 428 PColorPickerChild* AllocPColorPickerChild(const nsString& aTitle, 429 const nsString& aInitialColor); 430 431 bool DeallocPColorPickerChild(PColorPickerChild* aActor); 432 433 PFilePickerChild* AllocPFilePickerChild(const nsString& aTitle, 434 const int16_t& aMode); 435 436 bool DeallocPFilePickerChild(PFilePickerChild* aActor); 437 WebNavigation()438 nsIWebNavigation* WebNavigation() const { return mWebNav; } 439 WebWidget()440 PuppetWidget* WebWidget() { return mPuppetWidget; } 441 IsTransparent()442 bool IsTransparent() const { return mIsTransparent; } 443 GetEffectsInfo()444 const EffectsInfo& GetEffectsInfo() const { return mEffectsInfo; } 445 GetOrientation()446 hal::ScreenOrientation GetOrientation() const { return mOrientation; } 447 448 void SetBackgroundColor(const nscolor& aColor); 449 450 void NotifyPainted(); 451 452 MOZ_CAN_RUN_SCRIPT_BOUNDARY virtual mozilla::ipc::IPCResult RecvUpdateEffects( 453 const EffectsInfo& aEffects); 454 455 void RequestEditCommands(nsIWidget::NativeKeyBindingsType aType, 456 const WidgetKeyboardEvent& aEvent, 457 nsTArray<CommandInt>& aCommands); 458 459 bool IsVisible(); 460 461 /** 462 * Signal to this BrowserChild that it should be made visible: 463 * activated widget, retained layer tree, etc. (Respectively, 464 * made not visible.) 465 */ 466 MOZ_CAN_RUN_SCRIPT void UpdateVisibility(); 467 MOZ_CAN_RUN_SCRIPT void MakeVisible(); 468 void MakeHidden(); 469 Manager()470 ContentChild* Manager() const { return mManager; } 471 GetFrom(nsIDocShell * aDocShell)472 static inline BrowserChild* GetFrom(nsIDocShell* aDocShell) { 473 if (!aDocShell) { 474 return nullptr; 475 } 476 477 nsCOMPtr<nsIBrowserChild> tc = aDocShell->GetBrowserChild(); 478 return static_cast<BrowserChild*>(tc.get()); 479 } 480 GetFrom(mozIDOMWindow * aWindow)481 static inline BrowserChild* GetFrom(mozIDOMWindow* aWindow) { 482 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 483 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 484 return GetFrom(docShell); 485 } 486 GetFrom(mozIDOMWindowProxy * aWindow)487 static inline BrowserChild* GetFrom(mozIDOMWindowProxy* aWindow) { 488 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 489 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 490 return GetFrom(docShell); 491 } 492 493 static BrowserChild* GetFrom(PresShell* aPresShell); 494 static BrowserChild* GetFrom(layers::LayersId aLayersId); 495 GetLayersId()496 layers::LayersId GetLayersId() { return mLayersId; } IsLayersConnected()497 Maybe<bool> IsLayersConnected() { return mLayersConnected; } 498 499 void DidComposite(mozilla::layers::TransactionId aTransactionId, 500 const TimeStamp& aCompositeStart, 501 const TimeStamp& aCompositeEnd); 502 503 void DidRequestComposite(const TimeStamp& aCompositeReqStart, 504 const TimeStamp& aCompositeReqEnd); 505 506 void ClearCachedResources(); 507 void InvalidateLayers(); 508 void SchedulePaint(); 509 void ReinitRendering(); 510 void ReinitRenderingForDeviceReset(); 511 GetFrom(nsIDOMWindow * aWindow)512 static inline BrowserChild* GetFrom(nsIDOMWindow* aWindow) { 513 nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow); 514 nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(webNav); 515 return GetFrom(docShell); 516 } 517 518 mozilla::ipc::IPCResult RecvUIResolutionChanged(const float& aDpi, 519 const int32_t& aRounding, 520 const double& aScale); 521 522 mozilla::ipc::IPCResult RecvHandleAccessKey(const WidgetKeyboardEvent& aEvent, 523 nsTArray<uint32_t>&& aCharCodes); 524 525 mozilla::ipc::IPCResult RecvHandledWindowedPluginKeyEvent( 526 const mozilla::NativeEventData& aKeyEventData, const bool& aIsConsumed); 527 528 mozilla::ipc::IPCResult RecvPrint(const uint64_t& aOuterWindowID, 529 const PrintData& aPrintData); 530 531 mozilla::ipc::IPCResult RecvUpdateNativeWindowHandle( 532 const uintptr_t& aNewHandle); 533 534 mozilla::ipc::IPCResult RecvWillChangeProcess( 535 WillChangeProcessResolver&& aResolve); 536 /** 537 * Native widget remoting protocol for use with windowed plugins with e10s. 538 */ 539 PPluginWidgetChild* AllocPPluginWidgetChild(); 540 541 bool DeallocPPluginWidgetChild(PPluginWidgetChild* aActor); 542 543 #ifdef XP_WIN 544 nsresult CreatePluginWidget(nsIWidget* aParent, nsIWidget** aOut); 545 #endif 546 547 PPaymentRequestChild* AllocPPaymentRequestChild(); 548 549 bool DeallocPPaymentRequestChild(PPaymentRequestChild* aActor); 550 GetClientOffset()551 LayoutDeviceIntPoint GetClientOffset() const { return mClientOffset; } GetChromeOffset()552 LayoutDeviceIntPoint GetChromeOffset() const { return mChromeOffset; }; GetDynamicToolbarMaxHeight()553 ScreenIntCoord GetDynamicToolbarMaxHeight() const { 554 return mDynamicToolbarMaxHeight; 555 }; 556 IPCOpen()557 bool IPCOpen() const { return mIPCOpen; } 558 ParentIsActive()559 bool ParentIsActive() const { return mParentIsActive; } 560 561 const mozilla::layers::CompositorOptions& GetCompositorOptions() const; 562 bool AsyncPanZoomEnabled() const; 563 564 ScreenIntSize GetInnerSize(); GetUnscaledInnerSize()565 CSSSize GetUnscaledInnerSize() { return mUnscaledInnerSize; } 566 567 Maybe<LayoutDeviceIntRect> GetVisibleRect() const; 568 569 // Call RecvShow(nsIntSize(0, 0)) and block future calls to RecvShow(). 570 void DoFakeShow(const ParentShowInfo&); 571 572 void ContentReceivedInputBlock(uint64_t aInputBlockId, 573 bool aPreventDefault) const; 574 void SetTargetAPZC( 575 uint64_t aInputBlockId, 576 const nsTArray<layers::ScrollableLayerGuid>& aTargets) const; 577 MOZ_CAN_RUN_SCRIPT_BOUNDARY 578 mozilla::ipc::IPCResult RecvHandleTap( 579 const layers::GeckoContentController_TapType& aType, 580 const LayoutDevicePoint& aPoint, const Modifiers& aModifiers, 581 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId); 582 583 MOZ_CAN_RUN_SCRIPT_BOUNDARY 584 mozilla::ipc::IPCResult RecvNormalPriorityHandleTap( 585 const layers::GeckoContentController_TapType& aType, 586 const LayoutDevicePoint& aPoint, const Modifiers& aModifiers, 587 const ScrollableLayerGuid& aGuid, const uint64_t& aInputBlockId); 588 589 void SetAllowedTouchBehavior( 590 uint64_t aInputBlockId, const nsTArray<TouchBehaviorFlags>& aFlags) const; 591 592 bool UpdateFrame(const layers::RepaintRequest& aRequest); 593 bool NotifyAPZStateChange( 594 const ViewID& aViewId, 595 const layers::GeckoContentController_APZStateChange& aChange, 596 const int& aArg); 597 void StartScrollbarDrag(const layers::AsyncDragMetrics& aDragMetrics); 598 void ZoomToRect(const uint32_t& aPresShellId, 599 const ScrollableLayerGuid::ViewID& aViewId, 600 const CSSRect& aRect, const uint32_t& aFlags); 601 602 // Request that the docshell be marked as active. 603 void PaintWhileInterruptingJS(const layers::LayersObserverEpoch& aEpoch); 604 605 nsresult CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType, 606 int32_t aNavigationIndex, nsIURI* aNavigationURI, 607 int32_t aEpoch, bool* aCanCancel); 608 LayersObserverEpoch()609 layers::LayersObserverEpoch LayersObserverEpoch() const { 610 return mLayersObserverEpoch; 611 } 612 613 #if defined(XP_WIN) && defined(ACCESSIBILITY) GetNativeWindowHandle()614 uintptr_t GetNativeWindowHandle() const { return mNativeWindowHandle; } 615 #endif 616 617 // These methods return `true` if this BrowserChild is currently awaiting a 618 // Large-Allocation header. 619 bool StopAwaitingLargeAlloc(); 620 bool IsAwaitingLargeAlloc(); 621 GetBrowsingContext()622 BrowsingContext* GetBrowsingContext() const { return mBrowsingContext; } 623 624 #if defined(ACCESSIBILITY) SetTopLevelDocAccessibleChild(PDocAccessibleChild * aTopLevelChild)625 void SetTopLevelDocAccessibleChild(PDocAccessibleChild* aTopLevelChild) { 626 mTopLevelDocAccessibleChild = aTopLevelChild; 627 } 628 GetTopLevelDocAccessibleChild()629 PDocAccessibleChild* GetTopLevelDocAccessibleChild() { 630 return mTopLevelDocAccessibleChild; 631 } 632 #endif 633 634 void AddPendingDocShellBlocker(); 635 void RemovePendingDocShellBlocker(); 636 637 // The HANDLE object for the widget this BrowserChild in. WidgetNativeData()638 WindowsHandle WidgetNativeData() { return mWidgetNativeData; } 639 640 // The transform from the coordinate space of this BrowserChild to the 641 // coordinate space of the native window its BrowserParent is in. 642 mozilla::LayoutDeviceToLayoutDeviceMatrix4x4 643 GetChildToParentConversionMatrix() const; 644 645 // Returns the portion of the visible rect of this remote document in the 646 // top browser window coordinate system. This is the result of being clipped 647 // by all ancestor viewports. 648 mozilla::ScreenRect GetTopLevelViewportVisibleRectInBrowserCoords() const; 649 650 // Similar to above GetTopLevelViewportVisibleRectInBrowserCoords(), but in 651 // this out-of-process document's coordinate system. 652 Maybe<LayoutDeviceRect> GetTopLevelViewportVisibleRectInSelfCoords() const; 653 654 // Prepare to dispatch all coalesced mousemove events. We'll move all data 655 // in mCoalescedMouseData to a nsDeque; then we start processing them. We 656 // can't fetch the coalesced event one by one and dispatch it because we may 657 // reentry the event loop and access to the same hashtable. It's called when 658 // dispatching some mouse events other than mousemove. 659 void FlushAllCoalescedMouseData(); 660 void ProcessPendingCoalescedMouseDataAndDispatchEvents(); 661 662 void HandleRealMouseButtonEvent(const WidgetMouseEvent& aEvent, 663 const ScrollableLayerGuid& aGuid, 664 const uint64_t& aInputBlockId); 665 SetCancelContentJSEpoch(int32_t aEpoch)666 void SetCancelContentJSEpoch(int32_t aEpoch) { 667 mCancelContentJSEpoch = aEpoch; 668 } 669 HasVisibleTabs()670 static bool HasVisibleTabs() { 671 return sVisibleTabs && !sVisibleTabs->IsEmpty(); 672 } 673 674 // Returns the set of BrowserChilds that are currently rendering layers. There 675 // can be multiple BrowserChilds in this state if Firefox has multiple windows 676 // open or is warming tabs up. There can also be zero BrowserChilds in this 677 // state. Note that this function should only be called if HasVisibleTabs() 678 // returns true. GetVisibleTabs()679 static const nsTHashtable<nsPtrHashKey<BrowserChild>>& GetVisibleTabs() { 680 MOZ_ASSERT(HasVisibleTabs()); 681 return *sVisibleTabs; 682 } 683 684 bool UpdateSessionStore(uint32_t aFlushId, bool aIsFinal = false); 685 686 #ifdef XP_WIN 687 // Check if the window this BrowserChild is associated with supports 688 // protected media (EME) or not. 689 // Returns a promise the will resolve true if the window supports protected 690 // media or false if it does not. The promise will be rejected with an 691 // ResponseRejectReason if the IPC needed to do the check fails. Callers 692 // should treat the reject case as if the window does not support protected 693 // media to ensure robust handling. 694 RefPtr<IsWindowSupportingProtectedMediaPromise> 695 DoesWindowSupportProtectedMedia(); 696 #endif 697 698 // Notify the content blocking event in the parent process. This sends an IPC 699 // message to the BrowserParent in the parent. The BrowserParent will find the 700 // top-level WindowGlobalParent and notify the event from it. 701 void NotifyContentBlockingEvent( 702 uint32_t aEvent, nsIChannel* aChannel, bool aBlocked, 703 const nsACString& aTrackingOrigin, 704 const nsTArray<nsCString>& aTrackingFullHashes, 705 const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& 706 aReason); 707 708 protected: 709 virtual ~BrowserChild(); 710 711 mozilla::ipc::IPCResult RecvDestroy(); 712 713 mozilla::ipc::IPCResult RecvSetDocShellIsActive(const bool& aIsActive); 714 715 mozilla::ipc::IPCResult RecvSetSuspendMediaWhenInactive( 716 const bool& aSuspendMediaWhenInactive); 717 718 MOZ_CAN_RUN_SCRIPT_BOUNDARY 719 mozilla::ipc::IPCResult RecvRenderLayers( 720 const bool& aEnabled, const layers::LayersObserverEpoch& aEpoch); 721 722 mozilla::ipc::IPCResult RecvNavigateByKey(const bool& aForward, 723 const bool& aForDocumentNavigation); 724 725 mozilla::ipc::IPCResult RecvRequestNotifyAfterRemotePaint(); 726 727 mozilla::ipc::IPCResult RecvSuppressDisplayport(const bool& aEnabled); 728 729 mozilla::ipc::IPCResult RecvParentActivated(const bool& aActivated); 730 731 mozilla::ipc::IPCResult RecvScrollbarPreferenceChanged(ScrollbarPreference); 732 733 mozilla::ipc::IPCResult RecvSetKeyboardIndicators( 734 const UIStateChangeType& aShowFocusRings); 735 736 mozilla::ipc::IPCResult RecvStopIMEStateManagement(); 737 738 mozilla::ipc::IPCResult RecvAwaitLargeAlloc(); 739 740 mozilla::ipc::IPCResult RecvAllowScriptsToClose(); 741 742 mozilla::ipc::IPCResult RecvSetWidgetNativeData( 743 const WindowsHandle& aWidgetNativeData); 744 745 private: 746 // Wraps up a JSON object as a structured clone and sends it to the browser 747 // chrome script. 748 // 749 // XXX/bug 780335: Do the work the browser chrome script does in C++ instead 750 // so we don't need things like this. 751 void DispatchMessageManagerMessage(const nsAString& aMessageName, 752 const nsAString& aJSONData); 753 754 void ProcessUpdateFrame(const mozilla::layers::RepaintRequest& aRequest); 755 756 bool UpdateFrameHandler(const mozilla::layers::RepaintRequest& aRequest); 757 758 void HandleDoubleTap(const CSSPoint& aPoint, const Modifiers& aModifiers, 759 const ScrollableLayerGuid& aGuid); 760 761 // Notify others that our TabContext has been updated. 762 // 763 // You should call this after calling TabContext::SetTabContext(). We also 764 // call this during Init(). 765 void NotifyTabContextUpdated(); 766 767 void ActorDestroy(ActorDestroyReason why) override; 768 769 bool InitBrowserChildMessageManager(); 770 771 void InitRenderingState( 772 const TextureFactoryIdentifier& aTextureFactoryIdentifier, 773 const layers::LayersId& aLayersId, 774 const mozilla::layers::CompositorOptions& aCompositorOptions); 775 void InitAPZState(); 776 777 void DestroyWindow(); 778 779 void ApplyParentShowInfo(const ParentShowInfo&); 780 781 bool HasValidInnerSize(); 782 783 void SetTabId(const TabId& aTabId); 784 785 ScreenIntRect GetOuterRect(); 786 SetUnscaledInnerSize(const CSSSize & aSize)787 void SetUnscaledInnerSize(const CSSSize& aSize) { 788 mUnscaledInnerSize = aSize; 789 } 790 791 bool SkipRepeatedKeyEvent(const WidgetKeyboardEvent& aEvent); 792 793 void UpdateRepeatedKeyEventEndTime(const WidgetKeyboardEvent& aEvent); 794 795 bool MaybeCoalesceWheelEvent(const WidgetWheelEvent& aEvent, 796 const ScrollableLayerGuid& aGuid, 797 const uint64_t& aInputBlockId, 798 bool* aIsNextWheelEvent); 799 800 void MaybeDispatchCoalescedWheelEvent(); 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 void InternalSetSuspendMediaWhenInactive(bool aSuspendMediaWhenInactive); 814 815 bool CreateRemoteLayerManager( 816 mozilla::layers::PCompositorBridgeChild* aCompositorChild); 817 818 nsresult PrepareProgressListenerData(nsIWebProgress* aWebProgress, 819 nsIRequest* aRequest, 820 Maybe<WebProgressData>& aWebProgressData, 821 RequestData& aRequestData); 822 already_AddRefed<nsIWebBrowserChrome3> GetWebBrowserChromeActor(); 823 824 class DelayedDeleteRunnable; 825 826 RefPtr<BrowserChildMessageManager> mBrowserChildMessageManager; 827 nsCOMPtr<nsIWebBrowserChrome3> mWebBrowserChrome; 828 TextureFactoryIdentifier mTextureFactoryIdentifier; 829 RefPtr<nsWebBrowser> mWebBrowser; 830 nsCOMPtr<nsIWebNavigation> mWebNav; 831 RefPtr<PuppetWidget> mPuppetWidget; 832 nsCOMPtr<nsIURI> mLastURI; 833 RefPtr<ContentChild> mManager; 834 RefPtr<BrowsingContext> mBrowsingContext; 835 RefPtr<nsBrowserStatusFilter> mStatusFilter; 836 uint32_t mChromeFlags; 837 uint32_t mMaxTouchPoints; 838 layers::LayersId mLayersId; 839 CSSRect mUnscaledOuterRect; 840 Maybe<bool> mLayersConnected; 841 EffectsInfo mEffectsInfo; 842 bool mDidFakeShow; 843 bool mNotified; 844 bool mTriedBrowserInit; 845 hal::ScreenOrientation mOrientation; 846 847 bool mIgnoreKeyPressEvent; 848 RefPtr<APZEventState> mAPZEventState; 849 SetAllowedTouchBehaviorCallback mSetAllowedTouchBehaviorCallback; 850 bool mHasValidInnerSize; 851 bool mDestroyed; 852 853 // Position of client area relative to the outer window 854 LayoutDeviceIntPoint mClientOffset; 855 // Position of tab, relative to parent widget (typically the window) 856 LayoutDeviceIntPoint mChromeOffset; 857 ScreenIntCoord mDynamicToolbarMaxHeight; 858 TabId mUniqueId; 859 860 // Whether or not this browser is the child part of the top level PBrowser 861 // actor in a remote browser. 862 bool mIsTopLevel; 863 864 // Whether or not this tab has siblings (other tabs in the same window). 865 // This is one factor used when choosing to allow or deny a non-system 866 // script's attempt to resize the window. 867 bool mHasSiblings; 868 869 // Holds the compositor options for the compositor rendering this tab, 870 // once we find out which compositor that is. 871 Maybe<mozilla::layers::CompositorOptions> mCompositorOptions; 872 873 friend class ContentChild; 874 875 bool mIsTransparent; 876 877 bool mIPCOpen; 878 bool mParentIsActive; 879 CSSSize mUnscaledInnerSize; 880 bool mDidSetRealShowInfo; 881 bool mDidLoadURLInit; 882 bool mAwaitingLA; 883 884 bool mSkipKeyPress; 885 886 // Store the end time of the handling of the last repeated keydown/keypress 887 // event so that in case event handling takes time, some repeated events can 888 // be skipped to not flood child process. 889 mozilla::TimeStamp mRepeatedKeyEventTime; 890 891 // Similar to mRepeatedKeyEventTime, store the end time (from parent process) 892 // of handling the last repeated wheel event so that in case event handling 893 // takes time, some repeated events can be skipped to not flood child process. 894 mozilla::TimeStamp mLastWheelProcessedTimeFromParent; 895 mozilla::TimeDuration mLastWheelProcessingDuration; 896 897 // Hash table to track coalesced mousemove events for different pointers. 898 nsClassHashtable<nsUint32HashKey, CoalescedMouseData> mCoalescedMouseData; 899 900 nsDeque mToBeDispatchedMouseData; 901 902 CoalescedWheelData mCoalescedWheelData; 903 RefPtr<CoalescedMouseMoveFlusher> mCoalescedMouseEventFlusher; 904 905 RefPtr<layers::IAPZCTreeManager> mApzcTreeManager; 906 RefPtr<TabListener> mSessionStoreListener; 907 908 // The most recently seen layer observer epoch in RecvSetDocShellIsActive. 909 layers::LayersObserverEpoch mLayersObserverEpoch; 910 911 #if defined(XP_WIN) && defined(ACCESSIBILITY) 912 // The handle associated with the native window that contains this tab 913 uintptr_t mNativeWindowHandle; 914 #endif // defined(XP_WIN) 915 916 #if defined(ACCESSIBILITY) 917 PDocAccessibleChild* mTopLevelDocAccessibleChild; 918 #endif 919 bool mCoalesceMouseMoveEvents; 920 921 bool mShouldSendWebProgressEventsToParent; 922 923 // Whether we are rendering to the compositor or not. 924 bool mRenderLayers; 925 926 // In some circumstances, a DocShell might be in a state where it is 927 // "blocked", and we should not attempt to change its active state or 928 // the underlying PresShell state until the DocShell becomes unblocked. 929 // It is possible, however, for the parent process to send commands to 930 // change those states while the DocShell is blocked. We store those 931 // states temporarily as "pending", and only apply them once the DocShell 932 // is no longer blocked. 933 bool mPendingDocShellIsActive; 934 bool mPendingSuspendMediaWhenInactive; 935 bool mPendingDocShellReceivedMessage; 936 bool mPendingRenderLayers; 937 bool mPendingRenderLayersReceivedMessage; 938 layers::LayersObserverEpoch mPendingLayersObserverEpoch; 939 // When mPendingDocShellBlockers is greater than 0, the DocShell is blocked, 940 // and once it reaches 0, it is no longer blocked. 941 uint32_t mPendingDocShellBlockers; 942 int32_t mCancelContentJSEpoch; 943 944 WindowsHandle mWidgetNativeData; 945 946 Maybe<LayoutDeviceToLayoutDeviceMatrix4x4> mChildToParentConversionMatrix; 947 ScreenRect mTopLevelViewportVisibleRectInBrowserCoords; 948 949 #ifdef XP_WIN 950 // Should only be accessed on main thread. 951 Maybe<bool> mWindowSupportsProtectedMedia; 952 #endif 953 954 // This state is used to keep track of the current visible tabs (the ones 955 // rendering layers). There may be more than one if there are multiple browser 956 // windows open, or tabs are being warmed up. There may be none if this 957 // process does not host any visible or warming tabs. 958 static nsTHashtable<nsPtrHashKey<BrowserChild>>* sVisibleTabs; 959 960 DISALLOW_EVIL_CONSTRUCTORS(BrowserChild); 961 }; 962 963 } // namespace dom 964 } // namespace mozilla 965 966 #endif // mozilla_dom_BrowserChild_h 967