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_BrowserParent_h 8 #define mozilla_dom_BrowserParent_h 9 10 #include <utility> 11 12 #include "LiveResizeListener.h" 13 #include "Units.h" 14 #include "js/TypeDecls.h" 15 #include "mozilla/ContentCache.h" 16 #include "mozilla/EventForwards.h" 17 #include "mozilla/RefPtr.h" 18 #include "mozilla/dom/BrowserBridgeParent.h" 19 #include "mozilla/dom/PBrowserParent.h" 20 #include "mozilla/dom/TabContext.h" 21 #include "mozilla/dom/VsyncParent.h" 22 #include "mozilla/dom/ipc/IdType.h" 23 #include "mozilla/layout/RemoteLayerTreeOwner.h" 24 #include "nsCOMPtr.h" 25 #include "nsIAuthPromptProvider.h" 26 #include "nsIBrowserDOMWindow.h" 27 #include "nsIDOMEventListener.h" 28 #include "nsIRemoteTab.h" 29 #include "nsIWidget.h" 30 #include "nsWeakReference.h" 31 32 class imgIContainer; 33 class nsCycleCollectionTraversalCallback; 34 class nsDocShellLoadState; 35 class nsFrameLoader; 36 class nsIBrowser; 37 class nsIContent; 38 class nsIContentSecurityPolicy; 39 class nsIDocShell; 40 class nsILoadContext; 41 class nsIPrincipal; 42 class nsIRequest; 43 class nsIURI; 44 class nsIWebBrowserPersistDocumentReceiver; 45 class nsIWebProgress; 46 class nsIXULBrowserWindow; 47 class nsPIDOMWindowOuter; 48 49 namespace mozilla { 50 51 namespace a11y { 52 class DocAccessibleParent; 53 } 54 55 namespace widget { 56 struct IMENotification; 57 } // namespace widget 58 59 namespace gfx { 60 class SourceSurface; 61 } // namespace gfx 62 63 namespace dom { 64 65 class CanonicalBrowsingContext; 66 class ClonedMessageData; 67 class ContentParent; 68 class Element; 69 class DataTransfer; 70 class BrowserHost; 71 class BrowserBridgeParent; 72 73 namespace ipc { 74 class StructuredCloneData; 75 } // namespace ipc 76 77 /** 78 * BrowserParent implements the parent actor part of the PBrowser protocol. See 79 * PBrowser for more information. 80 */ 81 class BrowserParent final : public PBrowserParent, 82 public nsIDOMEventListener, 83 public nsIAuthPromptProvider, 84 public nsSupportsWeakReference, 85 public TabContext, 86 public LiveResizeListener { 87 typedef mozilla::dom::ClonedMessageData ClonedMessageData; 88 using TapType = GeckoContentController_TapType; 89 90 friend class PBrowserParent; 91 92 virtual ~BrowserParent(); 93 94 public: 95 // Helper class for ContentParent::RecvCreateWindow. 96 struct AutoUseNewTab; 97 98 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 99 NS_DECL_NSIAUTHPROMPTPROVIDER 100 // nsIDOMEventListener interfaces 101 NS_DECL_NSIDOMEVENTLISTENER 102 103 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowserParent, nsIDOMEventListener) 104 105 BrowserParent(ContentParent* aManager, const TabId& aTabId, 106 const TabContext& aContext, 107 CanonicalBrowsingContext* aBrowsingContext, 108 uint32_t aChromeFlags); 109 110 /** 111 * Returns the focused BrowserParent or nullptr if chrome or another app 112 * is focused. 113 */ 114 static BrowserParent* GetFocused(); 115 116 static BrowserParent* GetLastMouseRemoteTarget(); 117 118 static BrowserParent* GetFrom(nsFrameLoader* aFrameLoader); 119 120 static BrowserParent* GetFrom(PBrowserParent* aBrowserParent); 121 122 static BrowserParent* GetFrom(nsIContent* aContent); 123 124 static BrowserParent* GetBrowserParentFromLayersId( 125 layers::LayersId aLayersId); 126 127 static TabId GetTabIdFrom(nsIDocShell* docshell); 128 GetTabId()129 const TabId GetTabId() const { return mTabId; } 130 Manager()131 ContentParent* Manager() const { return mManager; } 132 GetBrowsingContext()133 CanonicalBrowsingContext* GetBrowsingContext() { return mBrowsingContext; } 134 135 already_AddRefed<nsILoadContext> GetLoadContext(); 136 GetOwnerElement()137 Element* GetOwnerElement() const { return mFrameElement; } 138 GetBrowserDOMWindow()139 nsIBrowserDOMWindow* GetBrowserDOMWindow() const { return mBrowserDOMWindow; } 140 141 already_AddRefed<nsPIDOMWindowOuter> GetParentWindowOuter(); 142 143 already_AddRefed<nsIWidget> GetTopLevelWidget(); 144 145 // Returns the closest widget for our frameloader's content. 146 already_AddRefed<nsIWidget> GetWidget() const; 147 148 // Returns the top-level widget for our frameloader's document. 149 already_AddRefed<nsIWidget> GetDocWidget() const; 150 151 /** 152 * Returns the widget which may have native focus and handles text input 153 * like keyboard input, IME, etc. 154 */ 155 already_AddRefed<nsIWidget> GetTextInputHandlingWidget() const; 156 157 nsIXULBrowserWindow* GetXULBrowserWindow(); 158 159 static uint32_t GetMaxTouchPoints(Element* aElement); GetMaxTouchPoints()160 uint32_t GetMaxTouchPoints() { return GetMaxTouchPoints(mFrameElement); } 161 162 /** 163 * Return the top level DocAccessibleParent for this BrowserParent. 164 * Note that in the case of an out-of-process iframe, the returned actor 165 * might not be at the top level of the DocAccessibleParent tree; i.e. it 166 * might have a parent. However, it will be at the top level in its content 167 * process. That is, doc->IsTopLevelInContentProcess() will always be true, 168 * but doc->IsTopLevel() might not. 169 */ 170 a11y::DocAccessibleParent* GetTopLevelDocAccessible() const; 171 172 LayersId GetLayersId() const; 173 174 // Returns the BrowserBridgeParent if this BrowserParent is for an 175 // out-of-process iframe and nullptr otherwise. 176 BrowserBridgeParent* GetBrowserBridgeParent() const; 177 178 // Returns the BrowserHost if this BrowserParent is for a top-level browser 179 // and nullptr otherwise. 180 BrowserHost* GetBrowserHost() const; 181 182 ParentShowInfo GetShowInfo(); 183 184 // Get the content principal from the owner element. 185 already_AddRefed<nsIPrincipal> GetContentPrincipal() const; 186 187 /** 188 * Let managees query if Destroy() is already called so they don't send out 189 * messages when the PBrowser actor is being destroyed. 190 */ IsDestroyed()191 bool IsDestroyed() const { return mIsDestroyed; } 192 193 /** 194 * Returns whether we're in the process of creating a new window (from 195 * window.open). If so, LoadURL calls are being skipped until everything is 196 * set up. For further details, see `mCreatingWindow` below. 197 */ CreatingWindow()198 bool CreatingWindow() const { return mCreatingWindow; } 199 200 /* 201 * Visit each BrowserParent in the tree formed by PBrowser and 202 * PBrowserBridge, including `this`. 203 */ 204 template <typename Callback> VisitAll(Callback aCallback)205 void VisitAll(Callback aCallback) { 206 aCallback(this); 207 VisitAllDescendants(aCallback); 208 } 209 210 /* 211 * Visit each BrowserParent in the tree formed by PBrowser and 212 * PBrowserBridge, excluding `this`. 213 */ 214 template <typename Callback> VisitAllDescendants(Callback aCallback)215 void VisitAllDescendants(Callback aCallback) { 216 const auto& browserBridges = ManagedPBrowserBridgeParent(); 217 for (const auto& key : browserBridges) { 218 BrowserBridgeParent* browserBridge = 219 static_cast<BrowserBridgeParent*>(key); 220 BrowserParent* browserParent = browserBridge->GetBrowserParent(); 221 222 aCallback(browserParent); 223 browserParent->VisitAllDescendants(aCallback); 224 } 225 } 226 227 /* 228 * Visit each BrowserBridgeParent that is a child of this BrowserParent. 229 */ 230 template <typename Callback> VisitChildren(Callback aCallback)231 void VisitChildren(Callback aCallback) { 232 const auto& browserBridges = ManagedPBrowserBridgeParent(); 233 for (const auto& key : browserBridges) { 234 BrowserBridgeParent* browserBridge = 235 static_cast<BrowserBridgeParent*>(key); 236 aCallback(browserBridge); 237 } 238 } 239 240 void SetOwnerElement(Element* aElement); 241 SetBrowserDOMWindow(nsIBrowserDOMWindow * aBrowserDOMWindow)242 void SetBrowserDOMWindow(nsIBrowserDOMWindow* aBrowserDOMWindow) { 243 mBrowserDOMWindow = aBrowserDOMWindow; 244 } 245 SwapFrameScriptsFrom(nsTArray<FrameScriptInfo> & aFrameScripts)246 void SwapFrameScriptsFrom(nsTArray<FrameScriptInfo>& aFrameScripts) { 247 aFrameScripts.SwapElements(mDelayedFrameScripts); 248 } 249 250 void CacheFrameLoader(nsFrameLoader* aFrameLoader); 251 252 void Destroy(); 253 254 void RemoveWindowListeners(); 255 256 void AddWindowListeners(); 257 258 mozilla::ipc::IPCResult RecvMoveFocus(const bool& aForward, 259 const bool& aForDocumentNavigation); 260 261 mozilla::ipc::IPCResult RecvSizeShellTo(const uint32_t& aFlags, 262 const int32_t& aWidth, 263 const int32_t& aHeight, 264 const int32_t& aShellItemWidth, 265 const int32_t& aShellItemHeight); 266 267 mozilla::ipc::IPCResult RecvDropLinks(nsTArray<nsString>&& aLinks); 268 269 mozilla::ipc::IPCResult RecvEvent(const RemoteDOMEvent& aEvent); 270 271 mozilla::ipc::IPCResult RecvReplyKeyEvent(const WidgetKeyboardEvent& aEvent); 272 273 mozilla::ipc::IPCResult RecvAccessKeyNotHandled( 274 const WidgetKeyboardEvent& aEvent); 275 276 mozilla::ipc::IPCResult RecvRegisterProtocolHandler(const nsString& aScheme, 277 nsIURI* aHandlerURI, 278 const nsString& aTitle, 279 nsIURI* aDocURI); 280 281 mozilla::ipc::IPCResult RecvOnStateChange( 282 const WebProgressData& aWebProgressData, const RequestData& aRequestData, 283 const uint32_t aStateFlags, const nsresult aStatus, 284 const Maybe<WebProgressStateChangeData>& aStateChangeData); 285 286 mozilla::ipc::IPCResult RecvOnProgressChange(const int32_t aCurTotalProgres, 287 const int32_t aMaxTotalProgress); 288 289 mozilla::ipc::IPCResult RecvOnLocationChange( 290 const WebProgressData& aWebProgressData, const RequestData& aRequestData, 291 nsIURI* aLocation, const uint32_t aFlags, const bool aCanGoBack, 292 const bool aCanGoForward, 293 const Maybe<WebProgressLocationChangeData>& aLocationChangeData); 294 295 mozilla::ipc::IPCResult RecvOnStatusChange(const nsString& aMessage); 296 297 mozilla::ipc::IPCResult RecvNotifyContentBlockingEvent( 298 const uint32_t& aEvent, const RequestData& aRequestData, 299 const bool aBlocked, const nsACString& aTrackingOrigin, 300 nsTArray<nsCString>&& aTrackingFullHashes, 301 const Maybe<mozilla::ContentBlockingNotifier:: 302 StorageAccessPermissionGrantedReason>& aReason); 303 304 mozilla::ipc::IPCResult RecvSetAllowDeprecatedTls(bool value); 305 306 mozilla::ipc::IPCResult RecvNavigationFinished(); 307 308 already_AddRefed<nsIBrowser> GetBrowser(); 309 310 already_AddRefed<CanonicalBrowsingContext> BrowsingContextForWebProgress( 311 const WebProgressData& aWebProgressData); 312 313 mozilla::ipc::IPCResult RecvSessionStoreUpdate( 314 const Maybe<nsCString>& aDocShellCaps, const Maybe<bool>& aPrivatedMode, 315 const bool aNeedCollectSHistory, const uint32_t& aEpoch); 316 317 mozilla::ipc::IPCResult RecvIntrinsicSizeOrRatioChanged( 318 const Maybe<IntrinsicSize>& aIntrinsicSize, 319 const Maybe<AspectRatio>& aIntrinsicRatio); 320 321 mozilla::ipc::IPCResult RecvSyncMessage( 322 const nsString& aMessage, const ClonedMessageData& aData, 323 nsTArray<ipc::StructuredCloneData>* aRetVal); 324 325 mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMessage, 326 const ClonedMessageData& aData); 327 328 mozilla::ipc::IPCResult RecvNotifyIMEFocus( 329 const ContentCache& aContentCache, 330 const widget::IMENotification& aEventMessage, 331 NotifyIMEFocusResolver&& aResolve); 332 333 mozilla::ipc::IPCResult RecvNotifyIMETextChange( 334 const ContentCache& aContentCache, 335 const widget::IMENotification& aEventMessage); 336 337 mozilla::ipc::IPCResult RecvNotifyIMECompositionUpdate( 338 const ContentCache& aContentCache, 339 const widget::IMENotification& aEventMessage); 340 341 mozilla::ipc::IPCResult RecvNotifyIMESelection( 342 const ContentCache& aContentCache, 343 const widget::IMENotification& aEventMessage); 344 345 mozilla::ipc::IPCResult RecvUpdateContentCache( 346 const ContentCache& aContentCache); 347 348 mozilla::ipc::IPCResult RecvNotifyIMEMouseButtonEvent( 349 const widget::IMENotification& aEventMessage, bool* aConsumedByIME); 350 351 mozilla::ipc::IPCResult RecvNotifyIMEPositionChange( 352 const ContentCache& aContentCache, 353 const widget::IMENotification& aEventMessage); 354 355 mozilla::ipc::IPCResult RecvOnEventNeedingAckHandled( 356 const EventMessage& aMessage); 357 358 mozilla::ipc::IPCResult RecvRequestIMEToCommitComposition( 359 const bool& aCancel, bool* aIsCommitted, nsString* aCommittedString); 360 361 mozilla::ipc::IPCResult RecvGetInputContext(widget::IMEState* aIMEState); 362 363 mozilla::ipc::IPCResult RecvSetInputContext( 364 const widget::InputContext& aContext, 365 const widget::InputContextAction& aAction); 366 367 mozilla::ipc::IPCResult RecvRequestFocus(const bool& aCanRaise, 368 const CallerType aCallerType); 369 370 mozilla::ipc::IPCResult RecvWheelZoomChange(bool aIncrease); 371 372 mozilla::ipc::IPCResult RecvLookUpDictionary( 373 const nsString& aText, nsTArray<mozilla::FontRange>&& aFontRangeArray, 374 const bool& aIsVertical, const LayoutDeviceIntPoint& aPoint); 375 376 mozilla::ipc::IPCResult RecvEnableDisableCommands( 377 const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aAction, 378 nsTArray<nsCString>&& aEnabledCommands, 379 nsTArray<nsCString>&& aDisabledCommands); 380 381 mozilla::ipc::IPCResult RecvSetCursor( 382 const nsCursor& aValue, const bool& aHasCustomCursor, 383 const nsCString& aCursorData, const uint32_t& aWidth, 384 const uint32_t& aHeight, const float& aResolutionX, 385 const float& aResolutionY, const uint32_t& aStride, 386 const gfx::SurfaceFormat& aFormat, const uint32_t& aHotspotX, 387 const uint32_t& aHotspotY, const bool& aForce); 388 389 mozilla::ipc::IPCResult RecvSetLinkStatus(const nsString& aStatus); 390 391 mozilla::ipc::IPCResult RecvShowTooltip(const uint32_t& aX, 392 const uint32_t& aY, 393 const nsString& aTooltip, 394 const nsString& aDirection); 395 396 mozilla::ipc::IPCResult RecvHideTooltip(); 397 398 mozilla::ipc::IPCResult RecvDispatchFocusToTopLevelWindow(); 399 400 mozilla::ipc::IPCResult RecvRespondStartSwipeEvent( 401 const uint64_t& aInputBlockId, const bool& aStartSwipe); 402 403 mozilla::ipc::IPCResult RecvDispatchWheelEvent( 404 const mozilla::WidgetWheelEvent& aEvent); 405 406 mozilla::ipc::IPCResult RecvDispatchMouseEvent( 407 const mozilla::WidgetMouseEvent& aEvent); 408 409 mozilla::ipc::IPCResult RecvDispatchKeyboardEvent( 410 const mozilla::WidgetKeyboardEvent& aEvent); 411 412 mozilla::ipc::IPCResult RecvDispatchTouchEvent( 413 const mozilla::WidgetTouchEvent& aEvent); 414 415 mozilla::ipc::IPCResult RecvScrollRectIntoView( 416 const nsRect& aRect, const ScrollAxis& aVertical, 417 const ScrollAxis& aHorizontal, const ScrollFlags& aScrollFlags, 418 const int32_t& aAppUnitsPerDevPixel); 419 420 PColorPickerParent* AllocPColorPickerParent(const nsString& aTitle, 421 const nsString& aInitialColor); 422 423 bool DeallocPColorPickerParent(PColorPickerParent* aColorPicker); 424 425 PVsyncParent* AllocPVsyncParent(); 426 427 bool DeallocPVsyncParent(PVsyncParent* aActor); 428 429 #ifdef ACCESSIBILITY 430 PDocAccessibleParent* AllocPDocAccessibleParent(PDocAccessibleParent*, 431 const uint64_t&, 432 const uint32_t&, 433 const IAccessibleHolder&); 434 bool DeallocPDocAccessibleParent(PDocAccessibleParent*); 435 virtual mozilla::ipc::IPCResult RecvPDocAccessibleConstructor( 436 PDocAccessibleParent* aDoc, PDocAccessibleParent* aParentDoc, 437 const uint64_t& aParentID, const uint32_t& aMsaaID, 438 const IAccessibleHolder& aDocCOMProxy) override; 439 #endif 440 441 mozilla::ipc::IPCResult RecvNewWindowGlobal( 442 ManagedEndpoint<PWindowGlobalParent>&& aEndpoint, 443 const WindowGlobalInit& aInit); 444 445 mozilla::ipc::IPCResult RecvIsWindowSupportingProtectedMedia( 446 const uint64_t& aOuterWindowID, 447 IsWindowSupportingProtectedMediaResolver&& aResolve); 448 449 mozilla::ipc::IPCResult RecvIsWindowSupportingWebVR( 450 const uint64_t& aOuterWindowID, 451 IsWindowSupportingWebVRResolver&& aResolve); 452 453 void LoadURL(nsDocShellLoadState* aLoadState); 454 455 void ResumeLoad(uint64_t aPendingSwitchID); 456 457 void InitRendering(); 458 bool AttachLayerManager(); 459 void MaybeShowFrame(); 460 461 bool Show(const OwnerShowInfo&); 462 463 void UpdateDimensions(const nsIntRect& aRect, const ScreenIntSize& aSize); 464 465 DimensionInfo GetDimensionInfo(); 466 467 nsresult UpdatePosition(); 468 469 // Notify position update to all descendant documents in this browser parent. 470 // NOTE: This should use only for browsers in popup windows attached to the 471 // main browser window. 472 void NotifyPositionUpdatedForContentsInPopup(); 473 474 void SizeModeChanged(const nsSizeMode& aSizeMode); 475 476 void HandleAccessKey(const WidgetKeyboardEvent& aEvent, 477 nsTArray<uint32_t>& aCharCodes); 478 479 #if defined(MOZ_WIDGET_ANDROID) 480 void DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight); 481 void DynamicToolbarOffsetChanged(ScreenIntCoord aOffset); 482 #endif 483 484 void Activate(uint64_t aActionId); 485 486 void Deactivate(bool aWindowLowering, uint64_t aActionId); 487 488 void MouseEnterIntoWidget(); 489 490 bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent* aEvent); 491 492 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset, 493 mozilla::WidgetEvent* aEvent); 494 495 LayoutDeviceToCSSScale GetLayoutDeviceToCSSScale(); 496 497 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult 498 RecvRequestNativeKeyBindings(const uint32_t& aType, 499 const mozilla::WidgetKeyboardEvent& aEvent, 500 nsTArray<mozilla::CommandInt>* aCommands); 501 502 mozilla::ipc::IPCResult RecvSynthesizeNativeKeyEvent( 503 const int32_t& aNativeKeyboardLayout, const int32_t& aNativeKeyCode, 504 const uint32_t& aModifierFlags, const nsString& aCharacters, 505 const nsString& aUnmodifiedCharacters, const uint64_t& aObserverId); 506 507 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseEvent( 508 const LayoutDeviceIntPoint& aPoint, const uint32_t& aNativeMessage, 509 const int16_t& aButton, const uint32_t& aModifierFlags, 510 const uint64_t& aObserverId); 511 512 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseMove( 513 const LayoutDeviceIntPoint& aPoint, const uint64_t& aObserverId); 514 515 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseScrollEvent( 516 const LayoutDeviceIntPoint& aPoint, const uint32_t& aNativeMessage, 517 const double& aDeltaX, const double& aDeltaY, const double& aDeltaZ, 518 const uint32_t& aModifierFlags, const uint32_t& aAdditionalFlags, 519 const uint64_t& aObserverId); 520 521 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchPoint( 522 const uint32_t& aPointerId, const TouchPointerState& aPointerState, 523 const LayoutDeviceIntPoint& aPoint, const double& aPointerPressure, 524 const uint32_t& aPointerOrientation, const uint64_t& aObserverId); 525 526 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchPadPinch( 527 const TouchpadPinchPhase& aEventPhase, const float& aScale, 528 const LayoutDeviceIntPoint& aPoint, const int32_t& aModifierFlags); 529 530 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchTap( 531 const LayoutDeviceIntPoint& aPoint, const bool& aLongTap, 532 const uint64_t& aObserverId); 533 534 mozilla::ipc::IPCResult RecvClearNativeTouchSequence( 535 const uint64_t& aObserverId); 536 537 mozilla::ipc::IPCResult RecvSynthesizeNativePenInput( 538 const uint32_t& aPointerId, const TouchPointerState& aPointerState, 539 const LayoutDeviceIntPoint& aPoint, const double& aPressure, 540 const uint32_t& aRotation, const int32_t& aTiltX, const int32_t& aTiltY, 541 const uint64_t& aObserverId); 542 543 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchpadDoubleTap( 544 const LayoutDeviceIntPoint& aPoint, const uint32_t& aModifierFlags); 545 546 mozilla::ipc::IPCResult RecvLockNativePointer(); 547 548 mozilla::ipc::IPCResult RecvUnlockNativePointer(); 549 550 /** 551 * The following Send*Event() marks aEvent as posted to remote process if 552 * it succeeded. So, you can check the result with 553 * aEvent.HasBeenPostedToRemoteProcess(). 554 */ 555 void SendRealMouseEvent(WidgetMouseEvent& aEvent); 556 557 void SendRealDragEvent(WidgetDragEvent& aEvent, uint32_t aDragAction, 558 uint32_t aDropEffect, nsIPrincipal* aPrincipal, 559 nsIContentSecurityPolicy* aCsp); 560 561 void SendMouseWheelEvent(WidgetWheelEvent& aEvent); 562 563 /** 564 * Only when the event is synthesized, retrieving writing mode may flush 565 * the layout. 566 */ 567 MOZ_CAN_RUN_SCRIPT_BOUNDARY void SendRealKeyEvent( 568 WidgetKeyboardEvent& aEvent); 569 570 void SendRealTouchEvent(WidgetTouchEvent& aEvent); 571 572 /** 573 * Different from above Send*Event(), these methods return true if the 574 * event has been posted to the remote process or failed to do that but 575 * shouldn't be handled by following event listeners. 576 * If you need to check if it's actually posted to the remote process, 577 * you can refer aEvent.HasBeenPostedToRemoteProcess(). 578 */ 579 bool SendCompositionEvent(mozilla::WidgetCompositionEvent& aEvent); 580 581 bool SendSelectionEvent(mozilla::WidgetSelectionEvent& aEvent); 582 583 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool SendHandleTap( 584 TapType aType, const LayoutDevicePoint& aPoint, Modifiers aModifiers, 585 const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId); 586 587 PFilePickerParent* AllocPFilePickerParent(const nsString& aTitle, 588 const int16_t& aMode); 589 590 bool DeallocPFilePickerParent(PFilePickerParent* actor); 591 592 mozilla::ipc::IPCResult RecvIndexedDBPermissionRequest( 593 nsIPrincipal* aPrincipal, IndexedDBPermissionRequestResolver&& aResolve); 594 595 bool GetGlobalJSObject(JSContext* cx, JSObject** globalp); 596 597 void StartPersistence(CanonicalBrowsingContext* aContext, 598 nsIWebBrowserPersistDocumentReceiver* aRecv, 599 ErrorResult& aRv); 600 601 bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent); 602 603 bool SendInsertText(const nsString& aStringToInsert); 604 605 bool SendPasteTransferable(const IPCDataTransfer& aDataTransfer, 606 const bool& aIsPrivateData, 607 nsIPrincipal* aRequestingPrincipal, 608 const nsContentPolicyType& aContentPolicyType); 609 610 // Helper for transforming a point 611 LayoutDeviceIntPoint TransformPoint( 612 const LayoutDeviceIntPoint& aPoint, 613 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix); 614 LayoutDevicePoint TransformPoint( 615 const LayoutDevicePoint& aPoint, 616 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix); 617 618 // Transform a coordinate from the parent process coordinate space to the 619 // child process coordinate space. 620 LayoutDeviceIntPoint TransformParentToChild( 621 const LayoutDeviceIntPoint& aPoint); 622 LayoutDevicePoint TransformParentToChild(const LayoutDevicePoint& aPoint); 623 624 // Transform a coordinate from the child process coordinate space to the 625 // parent process coordinate space. 626 LayoutDeviceIntPoint TransformChildToParent( 627 const LayoutDeviceIntPoint& aPoint); 628 LayoutDevicePoint TransformChildToParent(const LayoutDevicePoint& aPoint); 629 LayoutDeviceIntRect TransformChildToParent(const LayoutDeviceIntRect& aRect); 630 631 // Returns the matrix that transforms event coordinates from the coordinate 632 // space of the child process to the coordinate space of the parent process. 633 LayoutDeviceToLayoutDeviceMatrix4x4 GetChildToParentConversionMatrix(); 634 635 void SetChildToParentConversionMatrix( 636 const Maybe<LayoutDeviceToLayoutDeviceMatrix4x4>& aMatrix, 637 const ScreenRect& aRemoteDocumentRect); 638 639 // Returns the offset from the origin of our frameloader's nearest widget to 640 // the origin of its layout frame. This offset is used to translate event 641 // coordinates relative to the PuppetWidget origin in the child process. 642 // 643 // GOING AWAY. PLEASE AVOID ADDING CALLERS. Use the above tranformation 644 // methods instead. 645 LayoutDeviceIntPoint GetChildProcessOffset(); 646 647 // Returns the offset from the on-screen origin of our top-level window's 648 // widget (including window decorations) to the origin of our frameloader's 649 // nearest widget. This offset is used to translate coordinates from the 650 // PuppetWidget's origin to absolute screen coordinates in the child. 651 LayoutDeviceIntPoint GetClientOffset(); 652 653 void StopIMEStateManagement(); 654 655 PPaymentRequestParent* AllocPPaymentRequestParent(); 656 657 bool DeallocPPaymentRequestParent(PPaymentRequestParent* aActor); 658 659 bool SendLoadRemoteScript(const nsString& aURL, 660 const bool& aRunInGlobalScope); 661 662 void LayerTreeUpdate(const LayersObserverEpoch& aEpoch, bool aActive); 663 664 mozilla::ipc::IPCResult RecvInvokeDragSession( 665 nsTArray<IPCDataTransfer>&& aTransfers, const uint32_t& aAction, 666 Maybe<Shmem>&& aVisualDnDData, const uint32_t& aStride, 667 const gfx::SurfaceFormat& aFormat, const LayoutDeviceIntRect& aDragRect, 668 nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp, 669 const CookieJarSettingsArgs& aCookieJarSettingsArgs); 670 671 void AddInitialDnDDataTo(DataTransfer* aDataTransfer, 672 nsIPrincipal** aPrincipal); 673 674 bool TakeDragVisualization(RefPtr<mozilla::gfx::SourceSurface>& aSurface, 675 LayoutDeviceIntRect* aDragRect); 676 677 mozilla::ipc::IPCResult RecvEnsureLayersConnected( 678 CompositorOptions* aCompositorOptions); 679 680 // LiveResizeListener implementation 681 void LiveResizeStarted() override; 682 void LiveResizeStopped() override; 683 SetReadyToHandleInputEvents()684 void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents = true; } IsReadyToHandleInputEvents()685 bool IsReadyToHandleInputEvents() { return mIsReadyToHandleInputEvents; } 686 687 void NavigateByKey(bool aForward, bool aForDocumentNavigation); 688 689 bool GetDocShellIsActive(); 690 void SetDocShellIsActive(bool aDocShellIsActive); 691 692 bool GetHasPresented(); 693 bool GetHasLayers(); 694 bool GetRenderLayers(); 695 void SetRenderLayers(bool aRenderLayers); 696 void PreserveLayers(bool aPreserveLayers); 697 void NotifyResolutionChanged(); 698 699 bool StartApzAutoscroll(float aAnchorX, float aAnchorY, nsViewID aScrollId, 700 uint32_t aPresShellId); 701 void StopApzAutoscroll(nsViewID aScrollId, uint32_t aPresShellId); 702 703 bool CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType, 704 int32_t aNavigationIndex, 705 nsIURI* aNavigationURI) const; 706 707 // Called when the BrowserParent is being destroyed or entering bfcache. 708 void Deactivated(); 709 710 protected: 711 friend BrowserBridgeParent; 712 friend BrowserHost; 713 714 void SetBrowserBridgeParent(BrowserBridgeParent* aBrowser); 715 void SetBrowserHost(BrowserHost* aBrowser); 716 717 bool ReceiveMessage( 718 const nsString& aMessage, bool aSync, ipc::StructuredCloneData* aData, 719 nsTArray<ipc::StructuredCloneData>* aJSONRetVal = nullptr); 720 721 virtual mozilla::ipc::IPCResult Recv__delete__() override; 722 723 virtual void ActorDestroy(ActorDestroyReason why) override; 724 725 mozilla::ipc::IPCResult RecvRemotePaintIsReady(); 726 727 mozilla::ipc::IPCResult RecvRemoteIsReadyToHandleInputEvents(); 728 729 mozilla::ipc::IPCResult RecvPaintWhileInterruptingJSNoOp( 730 const LayersObserverEpoch& aEpoch); 731 732 mozilla::ipc::IPCResult RecvSetDimensions( 733 const uint32_t& aFlags, const int32_t& aX, const int32_t& aY, 734 const int32_t& aCx, const int32_t& aCy, const double& aScale); 735 736 mozilla::ipc::IPCResult RecvShowCanvasPermissionPrompt( 737 const nsCString& aOrigin, const bool& aHideDoorHanger); 738 739 mozilla::ipc::IPCResult RecvSetSystemFont(const nsCString& aFontName); 740 mozilla::ipc::IPCResult RecvGetSystemFont(nsCString* aFontName); 741 742 mozilla::ipc::IPCResult RecvVisitURI(nsIURI* aURI, nsIURI* aLastVisitedURI, 743 const uint32_t& aFlags); 744 745 mozilla::ipc::IPCResult RecvQueryVisitedState( 746 nsTArray<RefPtr<nsIURI>>&& aURIs); 747 748 mozilla::ipc::IPCResult RecvMaybeFireEmbedderLoadEvents( 749 EmbedderElementEventType aFireEventAtEmbeddingElement); 750 751 mozilla::ipc::IPCResult RecvRequestPointerLock( 752 RequestPointerLockResolver&& aResolve); 753 mozilla::ipc::IPCResult RecvReleasePointerLock(); 754 755 mozilla::ipc::IPCResult RecvRequestPointerCapture( 756 const uint32_t& aPointerId, RequestPointerCaptureResolver&& aResolve); 757 mozilla::ipc::IPCResult RecvReleasePointerCapture(const uint32_t& aPointerId); 758 759 private: 760 void SuppressDisplayport(bool aEnabled); 761 762 void DestroyInternal(); 763 764 void SetRenderLayersInternal(bool aEnabled); 765 766 already_AddRefed<nsFrameLoader> GetFrameLoader( 767 bool aUseCachedFrameLoaderAfterDestroy = false) const; 768 769 void TryCacheDPIAndScale(); 770 771 bool AsyncPanZoomEnabled() const; 772 773 // Update state prior to routing an APZ-aware event to the child process. 774 // |aOutTargetGuid| will contain the identifier 775 // of the APZC instance that handled the event. aOutTargetGuid may be null. 776 // |aOutInputBlockId| will contain the identifier of the input block 777 // that this event was added to, if there was one. aOutInputBlockId may be 778 // null. |aOutApzResponse| will contain the response that the APZ gave when 779 // processing the input block; this is used for generating appropriate 780 // pointercancel events. 781 void ApzAwareEventRoutingToChild(ScrollableLayerGuid* aOutTargetGuid, 782 uint64_t* aOutInputBlockId, 783 nsEventStatus* aOutApzResponse); 784 785 // When dropping links we perform a roundtrip from 786 // Parent (SendRealDragEvent) -> Child -> Parent (RecvDropLinks) 787 // and have to ensure that the child did not modify links to be loaded. 788 bool QueryDropLinksForVerification(); 789 790 void UnlockNativePointer(); 791 792 void UpdateNativePointerLockCenter(nsIWidget* aWidget); 793 794 private: 795 // This is used when APZ needs to find the BrowserParent associated with a 796 // layer to dispatch events. 797 typedef nsTHashMap<nsUint64HashKey, BrowserParent*> LayerToBrowserParentTable; 798 static LayerToBrowserParentTable* sLayerToBrowserParentTable; 799 800 static void AddBrowserParentToTable(layers::LayersId aLayersId, 801 BrowserParent* aBrowserParent); 802 803 static void RemoveBrowserParentFromTable(layers::LayersId aLayersId); 804 805 // Keeps track of which BrowserParent has keyboard focus. 806 // If nullptr, the parent process has focus. 807 // Use UpdateFocus() to manage. 808 static BrowserParent* sFocus; 809 810 // Keeps track of which top-level BrowserParent the keyboard focus is under. 811 // If nullptr, the parent process has focus. 812 // Use SetTopLevelWebFocus and UnsetTopLevelWebFocus to manage. 813 static BrowserParent* sTopLevelWebFocus; 814 815 // Setter for sTopLevelWebFocus 816 static void SetTopLevelWebFocus(BrowserParent* aBrowserParent); 817 818 // Unsetter for sTopLevelWebFocus; only unsets if argument matches 819 // current sTopLevelWebFocus. Use UnsetTopLevelWebFocusAll() to 820 // unset regardless of current value. 821 static void UnsetTopLevelWebFocus(BrowserParent* aBrowserParent); 822 823 // Recomputes sFocus and returns it. 824 static BrowserParent* UpdateFocus(); 825 826 // Keeps track of which BrowserParent the real mouse event is sent to. 827 static BrowserParent* sLastMouseRemoteTarget; 828 829 // Unsetter for LastMouseRemoteTarget; only unsets if argument matches 830 // current sLastMouseRemoteTarget. 831 static void UnsetLastMouseRemoteTarget(BrowserParent* aBrowserParent); 832 833 struct APZData { 834 bool operator==(const APZData& aOther) { 835 return aOther.guid == guid && aOther.blockId == blockId && 836 aOther.apzResponse == apzResponse; 837 } 838 839 bool operator!=(const APZData& aOther) { return !(*this == aOther); } 840 841 ScrollableLayerGuid guid; 842 uint64_t blockId; 843 nsEventStatus apzResponse; 844 }; 845 void SendRealTouchMoveEvent(WidgetTouchEvent& aEvent, APZData& aAPZData, 846 uint32_t aConsecutiveTouchMoveCount); 847 848 void UpdateVsyncParentVsyncSource(); 849 850 public: 851 // Unsets sTopLevelWebFocus regardless of its current value. 852 static void UnsetTopLevelWebFocusAll(); 853 854 // Recomputes focus when the BrowsingContext tree changes in a 855 // way that potentially invalidates the sFocus. 856 static void UpdateFocusFromBrowsingContext(); 857 858 private: 859 TabId mTabId; 860 861 RefPtr<ContentParent> mManager; 862 // The root browsing context loaded in this BrowserParent. 863 RefPtr<CanonicalBrowsingContext> mBrowsingContext; 864 nsCOMPtr<nsILoadContext> mLoadContext; 865 RefPtr<Element> mFrameElement; 866 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow; 867 // We keep a strong reference to the frameloader after we've sent the 868 // Destroy message and before we've received __delete__. This allows us to 869 // dispatch message manager messages during this time. 870 RefPtr<nsFrameLoader> mFrameLoader; 871 uint32_t mChromeFlags; 872 873 // Pointer back to BrowserBridgeParent if there is one associated with 874 // this BrowserParent. This is non-owning to avoid cycles and is managed 875 // by the BrowserBridgeParent instance, which has the strong reference 876 // to this BrowserParent. 877 BrowserBridgeParent* mBrowserBridgeParent; 878 // Pointer to the BrowserHost that owns us, if any. This is mutually 879 // exclusive with mBrowserBridgeParent, and one is guaranteed to be 880 // non-null. 881 BrowserHost* mBrowserHost; 882 883 ContentCacheInParent mContentCache; 884 885 layout::RemoteLayerTreeOwner mRemoteLayerTreeOwner; 886 LayersObserverEpoch mLayerTreeEpoch; 887 888 Maybe<LayoutDeviceToLayoutDeviceMatrix4x4> mChildToParentConversionMatrix; 889 Maybe<ScreenRect> mRemoteDocumentRect; 890 891 nsIntRect mRect; 892 ScreenIntSize mDimensions; 893 hal::ScreenOrientation mOrientation; 894 float mDPI; 895 int32_t mRounding; 896 CSSToLayoutDeviceScale mDefaultScale; 897 bool mUpdatedDimensions; 898 nsSizeMode mSizeMode; 899 LayoutDeviceIntPoint mClientOffset; 900 LayoutDeviceIntPoint mChromeOffset; 901 902 // When loading a new tab or window via window.open, the child is 903 // responsible for loading the URL it wants into the new BrowserChild. When 904 // the parent receives the CreateWindow message, though, it sends a LoadURL 905 // message, usually for about:blank. It's important for the about:blank load 906 // to get processed because the Firefox frontend expects every new window to 907 // immediately start loading something (see bug 1123090). However, we want 908 // the child to process the LoadURL message before it returns from 909 // ProvideWindow so that the URL sent from the parent doesn't override the 910 // child's URL. This is not possible using our IPC mechanisms. To solve the 911 // problem, we skip sending the LoadURL message in the parent and instead 912 // return the URL as a result from CreateWindow. The child simulates 913 // receiving a LoadURL message before returning from ProvideWindow. 914 // 915 // The mCreatingWindow flag is set while dispatching CreateWindow. During 916 // that time, any LoadURL calls are skipped. 917 bool mCreatingWindow; 918 919 // When loading a new tab or window via window.open, we want to ensure that 920 // frame scripts for that tab are loaded before any scripts start to run in 921 // the window. We can't load the frame scripts the normal way, using 922 // separate IPC messages, since they won't be processed by the child until 923 // returning to the event loop, which is too late. Instead, we queue up 924 // frame scripts that we intend to load and send them as part of the 925 // CreateWindow response. Then BrowserChild loads them immediately. 926 nsTArray<FrameScriptInfo> mDelayedFrameScripts; 927 928 // Cached cursor setting from BrowserChild. When the cursor is over the 929 // tab, it should take this appearance. 930 nsIWidget::Cursor mCursor; 931 932 nsTArray<nsString> mVerifyDropLinks; 933 934 RefPtr<VsyncParent> mVsyncParent; 935 936 #ifdef DEBUG 937 int32_t mActiveSupressDisplayportCount = 0; 938 #endif 939 940 // When true, we've initiated normal shutdown and notified our managing 941 // PContent. 942 bool mMarkedDestroying : 1; 943 // When true, the BrowserParent is invalid and we should not send IPC 944 // messages anymore. 945 bool mIsDestroyed : 1; 946 // True if the cursor changes from the BrowserChild should change the widget 947 // cursor. This happens whenever the cursor is in the remote target's 948 // region. 949 bool mRemoteTargetSetsCursor : 1; 950 951 // If this flag is set, then the tab's layers will be preserved even when 952 // the tab's docshell is inactive. 953 bool mIsPreservingLayers : 1; 954 955 // Holds the most recent value passed to the RenderLayers function. This 956 // does not necessarily mean that the layers have finished rendering 957 // and have uploaded - for that, use mHasLayers. 958 bool mRenderLayers : 1; 959 960 // True if the compositor has reported that the BrowserChild has uploaded 961 // layers. 962 bool mHasLayers : 1; 963 964 // True if this BrowserParent has had its layer tree sent to the compositor 965 // at least once. 966 bool mHasPresented : 1; 967 968 // True when the remote browser is created and ready to handle input events. 969 bool mIsReadyToHandleInputEvents : 1; 970 971 // True if we suppress the eMouseEnterIntoWidget event due to the 972 // BrowserChild was not ready to handle it. We will resend it when the next 973 // time we fire a mouse event and the BrowserChild is ready. 974 bool mIsMouseEnterIntoWidgetEventSuppressed : 1; 975 976 // True after RecvLockNativePointer has been called and until 977 // UnlockNativePointer has been called. 978 bool mLockedNativePointer : 1; 979 }; 980 981 struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final { 982 public: AutoUseNewTabfinal983 explicit AutoUseNewTab(BrowserParent* aNewTab) : mNewTab(aNewTab) { 984 MOZ_ASSERT(!aNewTab->mCreatingWindow); 985 aNewTab->mCreatingWindow = true; 986 } 987 ~AutoUseNewTabfinal988 ~AutoUseNewTab() { mNewTab->mCreatingWindow = false; } 989 990 private: 991 RefPtr<BrowserParent> mNewTab; 992 }; 993 994 } // namespace dom 995 } // namespace mozilla 996 997 #endif // mozilla_dom_BrowserParent_h 998