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