1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_BrowserParent_h
8 #define mozilla_dom_BrowserParent_h
12 #include "LiveResizeListener.h"
14 #include "js/TypeDecls.h"
15 #include "mozilla/AlreadyAddRefed.h"
16 #include "mozilla/ContentCache.h"
17 #include "mozilla/EventForwards.h"
18 #include "mozilla/RefPtr.h"
19 #include "mozilla/dom/BrowserBridgeParent.h"
20 #include "mozilla/dom/PBrowserParent.h"
21 #include "mozilla/dom/TabContext.h"
22 #include "mozilla/dom/VsyncParent.h"
23 #include "mozilla/dom/ipc/IdType.h"
24 #include "mozilla/layout/RemoteLayerTreeOwner.h"
26 #include "nsIAuthPromptProvider.h"
27 #include "nsIBrowserDOMWindow.h"
28 #include "nsIDOMEventListener.h"
29 #include "nsIFilePicker.h"
30 #include "nsIRemoteTab.h"
31 #include "nsIWidget.h"
33 #include "nsWeakReference.h"
36 class nsCycleCollectionTraversalCallback
;
37 class nsDocShellLoadState
;
41 class nsIContentSecurityPolicy
;
47 class nsIWebBrowserPersistDocumentReceiver
;
49 class nsIXULBrowserWindow
;
50 class nsPIDOMWindowOuter
;
55 class DocAccessibleParent
;
59 struct IMENotification
;
68 class CanonicalBrowsingContext
;
69 class ClonedMessageData
;
74 class BrowserBridgeParent
;
77 class StructuredCloneData
;
81 * BrowserParent implements the parent actor part of the PBrowser protocol. See
82 * PBrowser for more information.
84 class BrowserParent final
: public PBrowserParent
,
85 public nsIDOMEventListener
,
86 public nsIAuthPromptProvider
,
87 public nsSupportsWeakReference
,
89 public LiveResizeListener
{
90 typedef mozilla::dom::ClonedMessageData ClonedMessageData
;
91 using TapType
= GeckoContentController_TapType
;
93 friend class PBrowserParent
;
95 virtual ~BrowserParent();
98 // Helper class for ContentParent::RecvCreateWindow.
101 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
102 NS_DECL_NSIAUTHPROMPTPROVIDER
103 // nsIDOMEventListener interfaces
104 NS_DECL_NSIDOMEVENTLISTENER
106 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowserParent
, nsIDOMEventListener
)
108 BrowserParent(ContentParent
* aManager
, const TabId
& aTabId
,
109 const TabContext
& aContext
,
110 CanonicalBrowsingContext
* aBrowsingContext
,
111 uint32_t aChromeFlags
);
114 * Returns the focused BrowserParent or nullptr if chrome or another app
117 static BrowserParent
* GetFocused();
119 static BrowserParent
* GetLastMouseRemoteTarget();
121 static BrowserParent
* GetFrom(nsFrameLoader
* aFrameLoader
);
123 static BrowserParent
* GetFrom(PBrowserParent
* aBrowserParent
);
125 static BrowserParent
* GetFrom(nsIContent
* aContent
);
127 static BrowserParent
* GetBrowserParentFromLayersId(
128 layers::LayersId aLayersId
);
130 static TabId
GetTabIdFrom(nsIDocShell
* docshell
);
132 const TabId
GetTabId() const { return mTabId
; }
134 ContentParent
* Manager() const { return mManager
; }
136 CanonicalBrowsingContext
* GetBrowsingContext() { return mBrowsingContext
; }
138 void RecomputeProcessPriority();
140 already_AddRefed
<nsILoadContext
> GetLoadContext();
142 Element
* GetOwnerElement() const { return mFrameElement
; }
144 nsIBrowserDOMWindow
* GetBrowserDOMWindow() const { return mBrowserDOMWindow
; }
146 already_AddRefed
<nsPIDOMWindowOuter
> GetParentWindowOuter();
148 already_AddRefed
<nsIWidget
> GetTopLevelWidget();
150 // Returns the closest widget for our frameloader's content.
151 already_AddRefed
<nsIWidget
> GetWidget() const;
153 // Returns the top-level widget for our frameloader's document.
154 already_AddRefed
<nsIWidget
> GetDocWidget() const;
157 * Returns the widget which may have native focus and handles text input
158 * like keyboard input, IME, etc.
160 already_AddRefed
<nsIWidget
> GetTextInputHandlingWidget() const;
162 nsIXULBrowserWindow
* GetXULBrowserWindow();
164 static uint32_t GetMaxTouchPoints(Element
* aElement
);
165 uint32_t GetMaxTouchPoints() { return GetMaxTouchPoints(mFrameElement
); }
168 * Return the top level DocAccessibleParent for this BrowserParent.
169 * Note that in the case of an out-of-process iframe, the returned actor
170 * might not be at the top level of the DocAccessibleParent tree; i.e. it
171 * might have a parent. However, it will be at the top level in its content
172 * process. That is, doc->IsTopLevelInContentProcess() will always be true,
173 * but doc->IsTopLevel() might not.
175 a11y::DocAccessibleParent
* GetTopLevelDocAccessible() const;
177 LayersId
GetLayersId() const;
179 // Returns the BrowserBridgeParent if this BrowserParent is for an
180 // out-of-process iframe and nullptr otherwise.
181 BrowserBridgeParent
* GetBrowserBridgeParent() const;
183 // Returns the BrowserHost if this BrowserParent is for a top-level browser
184 // and nullptr otherwise.
185 BrowserHost
* GetBrowserHost() const;
187 ParentShowInfo
GetShowInfo();
189 // Get the content principal from the owner element.
190 already_AddRefed
<nsIPrincipal
> GetContentPrincipal() const;
193 * Let managees query if Destroy() is already called so they don't send out
194 * messages when the PBrowser actor is being destroyed.
196 bool IsDestroyed() const { return mIsDestroyed
; }
199 * Returns whether we're in the process of creating a new window (from
200 * window.open). If so, LoadURL calls are being skipped until everything is
201 * set up. For further details, see `mCreatingWindow` below.
203 bool CreatingWindow() const { return mCreatingWindow
; }
206 * Visit each BrowserParent in the tree formed by PBrowser and
207 * PBrowserBridge, including `this`.
209 template <typename Callback
>
210 void VisitAll(Callback aCallback
) {
212 VisitAllDescendants(aCallback
);
216 * Visit each BrowserParent in the tree formed by PBrowser and
217 * PBrowserBridge, excluding `this`.
219 template <typename Callback
>
220 void VisitAllDescendants(Callback aCallback
) {
221 const auto& browserBridges
= ManagedPBrowserBridgeParent();
222 for (const auto& key
: browserBridges
) {
223 BrowserBridgeParent
* browserBridge
=
224 static_cast<BrowserBridgeParent
*>(key
);
225 BrowserParent
* browserParent
= browserBridge
->GetBrowserParent();
227 aCallback(browserParent
);
228 browserParent
->VisitAllDescendants(aCallback
);
233 * Visit each BrowserBridgeParent that is a child of this BrowserParent.
235 template <typename Callback
>
236 void VisitChildren(Callback aCallback
) {
237 const auto& browserBridges
= ManagedPBrowserBridgeParent();
238 for (const auto& key
: browserBridges
) {
239 BrowserBridgeParent
* browserBridge
=
240 static_cast<BrowserBridgeParent
*>(key
);
241 aCallback(browserBridge
);
245 void SetOwnerElement(Element
* aElement
);
247 void SetBrowserDOMWindow(nsIBrowserDOMWindow
* aBrowserDOMWindow
) {
248 mBrowserDOMWindow
= aBrowserDOMWindow
;
251 void SwapFrameScriptsFrom(nsTArray
<FrameScriptInfo
>& aFrameScripts
) {
252 aFrameScripts
.SwapElements(mDelayedFrameScripts
);
255 void CacheFrameLoader(nsFrameLoader
* aFrameLoader
);
259 void RemoveWindowListeners();
261 void AddWindowListeners();
263 mozilla::ipc::IPCResult
RecvDidUnsuppressPainting();
264 mozilla::ipc::IPCResult
RecvDidUnsuppressPaintingNormalPriority() {
265 return RecvDidUnsuppressPainting();
267 mozilla::ipc::IPCResult
RecvMoveFocus(const bool& aForward
,
268 const bool& aForDocumentNavigation
);
270 mozilla::ipc::IPCResult
RecvDropLinks(nsTArray
<nsString
>&& aLinks
);
272 // TODO: Use MOZ_CAN_RUN_SCRIPT when it gains IPDL support (bug 1539864)
273 MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult
RecvReplyKeyEvent(
274 const WidgetKeyboardEvent
& aEvent
, const nsID
& aUUID
);
276 // TODO: Use MOZ_CAN_RUN_SCRIPT when it gains IPDL support (bug 1539864)
277 MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult
RecvAccessKeyNotHandled(
278 const WidgetKeyboardEvent
& aEvent
);
280 mozilla::ipc::IPCResult
RecvRegisterProtocolHandler(const nsString
& aScheme
,
282 const nsString
& aTitle
,
285 mozilla::ipc::IPCResult
RecvOnStateChange(
286 const WebProgressData
& aWebProgressData
, const RequestData
& aRequestData
,
287 const uint32_t aStateFlags
, const nsresult aStatus
,
288 const Maybe
<WebProgressStateChangeData
>& aStateChangeData
);
290 mozilla::ipc::IPCResult
RecvOnProgressChange(const int32_t aCurTotalProgres
,
291 const int32_t aMaxTotalProgress
);
293 mozilla::ipc::IPCResult
RecvOnLocationChange(
294 const WebProgressData
& aWebProgressData
, const RequestData
& aRequestData
,
295 nsIURI
* aLocation
, const uint32_t aFlags
, const bool aCanGoBack
,
296 const bool aCanGoForward
,
297 const Maybe
<WebProgressLocationChangeData
>& aLocationChangeData
);
299 mozilla::ipc::IPCResult
RecvOnStatusChange(const nsString
& aMessage
);
301 mozilla::ipc::IPCResult
RecvNotifyContentBlockingEvent(
302 const uint32_t& aEvent
, const RequestData
& aRequestData
,
303 const bool aBlocked
, const nsACString
& aTrackingOrigin
,
304 nsTArray
<nsCString
>&& aTrackingFullHashes
,
305 const Maybe
<mozilla::ContentBlockingNotifier::
306 StorageAccessPermissionGrantedReason
>& aReason
);
308 mozilla::ipc::IPCResult
RecvNavigationFinished();
310 already_AddRefed
<nsIBrowser
> GetBrowser();
312 already_AddRefed
<CanonicalBrowsingContext
> BrowsingContextForWebProgress(
313 const WebProgressData
& aWebProgressData
);
315 mozilla::ipc::IPCResult
RecvIntrinsicSizeOrRatioChanged(
316 const Maybe
<IntrinsicSize
>& aIntrinsicSize
,
317 const Maybe
<AspectRatio
>& aIntrinsicRatio
);
319 mozilla::ipc::IPCResult
RecvImageLoadComplete(const nsresult
& aResult
);
321 mozilla::ipc::IPCResult
RecvSyncMessage(
322 const nsString
& aMessage
, const ClonedMessageData
& aData
,
323 nsTArray
<ipc::StructuredCloneData
>* aRetVal
);
325 mozilla::ipc::IPCResult
RecvAsyncMessage(const nsString
& aMessage
,
326 const ClonedMessageData
& aData
);
328 mozilla::ipc::IPCResult
RecvNotifyIMEFocus(
329 const ContentCache
& aContentCache
,
330 const widget::IMENotification
& aEventMessage
,
331 NotifyIMEFocusResolver
&& aResolve
);
333 mozilla::ipc::IPCResult
RecvNotifyIMETextChange(
334 const ContentCache
& aContentCache
,
335 const widget::IMENotification
& aEventMessage
);
337 mozilla::ipc::IPCResult
RecvNotifyIMECompositionUpdate(
338 const ContentCache
& aContentCache
,
339 const widget::IMENotification
& aEventMessage
);
341 mozilla::ipc::IPCResult
RecvNotifyIMESelection(
342 const ContentCache
& aContentCache
,
343 const widget::IMENotification
& aEventMessage
);
345 mozilla::ipc::IPCResult
RecvUpdateContentCache(
346 const ContentCache
& aContentCache
);
348 mozilla::ipc::IPCResult
RecvNotifyIMEMouseButtonEvent(
349 const widget::IMENotification
& aEventMessage
, bool* aConsumedByIME
);
351 mozilla::ipc::IPCResult
RecvNotifyIMEPositionChange(
352 const ContentCache
& aContentCache
,
353 const widget::IMENotification
& aEventMessage
);
355 mozilla::ipc::IPCResult
RecvOnEventNeedingAckHandled(
356 const EventMessage
& aMessage
, const uint32_t& aCompositionId
);
358 mozilla::ipc::IPCResult
RecvRequestIMEToCommitComposition(
359 const bool& aCancel
, const uint32_t& aCompositionId
, bool* aIsCommitted
,
360 nsString
* aCommittedString
);
362 mozilla::ipc::IPCResult
RecvGetInputContext(widget::IMEState
* aIMEState
);
364 mozilla::ipc::IPCResult
RecvSetInputContext(
365 const widget::InputContext
& aContext
,
366 const widget::InputContextAction
& aAction
);
368 mozilla::ipc::IPCResult
RecvRequestFocus(const bool& aCanRaise
,
369 const CallerType aCallerType
);
371 mozilla::ipc::IPCResult
RecvWheelZoomChange(bool aIncrease
);
373 mozilla::ipc::IPCResult
RecvLookUpDictionary(
374 const nsString
& aText
, nsTArray
<mozilla::FontRange
>&& aFontRangeArray
,
375 const bool& aIsVertical
, const LayoutDeviceIntPoint
& aPoint
);
377 mozilla::ipc::IPCResult
RecvEnableDisableCommands(
378 const MaybeDiscarded
<BrowsingContext
>& aContext
, const nsString
& aAction
,
379 nsTArray
<nsCString
>&& aEnabledCommands
,
380 nsTArray
<nsCString
>&& aDisabledCommands
);
382 mozilla::ipc::IPCResult
RecvSetCursor(
383 const nsCursor
& aValue
, const bool& aHasCustomCursor
,
384 Maybe
<BigBuffer
>&& aCursorData
, const uint32_t& aWidth
,
385 const uint32_t& aHeight
, const float& aResolutionX
,
386 const float& aResolutionY
, const uint32_t& aStride
,
387 const gfx::SurfaceFormat
& aFormat
, const uint32_t& aHotspotX
,
388 const uint32_t& aHotspotY
, const bool& aForce
);
390 mozilla::ipc::IPCResult
RecvSetLinkStatus(const nsString
& aStatus
);
392 mozilla::ipc::IPCResult
RecvShowTooltip(const uint32_t& aX
,
394 const nsString
& aTooltip
,
395 const nsString
& aDirection
);
397 mozilla::ipc::IPCResult
RecvHideTooltip();
399 mozilla::ipc::IPCResult
RecvRespondStartSwipeEvent(
400 const uint64_t& aInputBlockId
, const bool& aStartSwipe
);
402 mozilla::ipc::IPCResult
RecvDispatchWheelEvent(
403 const mozilla::WidgetWheelEvent
& aEvent
);
405 mozilla::ipc::IPCResult
RecvDispatchMouseEvent(
406 const mozilla::WidgetMouseEvent
& aEvent
);
408 mozilla::ipc::IPCResult
RecvDispatchKeyboardEvent(
409 const mozilla::WidgetKeyboardEvent
& aEvent
);
411 mozilla::ipc::IPCResult
RecvDispatchTouchEvent(
412 const mozilla::WidgetTouchEvent
& aEvent
);
414 mozilla::ipc::IPCResult
RecvScrollRectIntoView(
415 const nsRect
& aRect
, const ScrollAxis
& aVertical
,
416 const ScrollAxis
& aHorizontal
, const ScrollFlags
& aScrollFlags
,
417 const int32_t& aAppUnitsPerDevPixel
);
419 already_AddRefed
<PColorPickerParent
> AllocPColorPickerParent(
420 const nsString
& aTitle
, const nsString
& aInitialColor
,
421 const nsTArray
<nsString
>& aDefaultColors
);
423 PVsyncParent
* AllocPVsyncParent();
425 bool DeallocPVsyncParent(PVsyncParent
* aActor
);
428 PDocAccessibleParent
* AllocPDocAccessibleParent(
429 PDocAccessibleParent
*, const uint64_t&,
430 const MaybeDiscardedBrowsingContext
&);
431 bool DeallocPDocAccessibleParent(PDocAccessibleParent
*);
432 virtual mozilla::ipc::IPCResult
RecvPDocAccessibleConstructor(
433 PDocAccessibleParent
* aDoc
, PDocAccessibleParent
* aParentDoc
,
434 const uint64_t& aParentID
,
435 const MaybeDiscardedBrowsingContext
& aBrowsingContext
) override
;
438 already_AddRefed
<PSessionStoreParent
> AllocPSessionStoreParent();
440 mozilla::ipc::IPCResult
RecvNewWindowGlobal(
441 ManagedEndpoint
<PWindowGlobalParent
>&& aEndpoint
,
442 const WindowGlobalInit
& aInit
);
444 mozilla::ipc::IPCResult
RecvIsWindowSupportingProtectedMedia(
445 const uint64_t& aOuterWindowID
,
446 IsWindowSupportingProtectedMediaResolver
&& aResolve
);
448 mozilla::ipc::IPCResult
RecvIsWindowSupportingWebVR(
449 const uint64_t& aOuterWindowID
,
450 IsWindowSupportingWebVRResolver
&& aResolve
);
452 void LoadURL(nsDocShellLoadState
* aLoadState
);
454 void ResumeLoad(uint64_t aPendingSwitchID
);
456 void InitRendering();
457 bool AttachWindowRenderer();
458 void MaybeShowFrame();
460 bool Show(const OwnerShowInfo
&);
462 void UpdateDimensions(const nsIntRect
& aRect
, const ScreenIntSize
& aSize
);
464 DimensionInfo
GetDimensionInfo();
466 nsresult
UpdatePosition();
468 // Notify position update to all descendant documents in this browser parent.
469 // NOTE: This should use only for browsers in popup windows attached to the
470 // main browser window.
471 void NotifyPositionUpdatedForContentsInPopup();
473 void SizeModeChanged(const nsSizeMode
& aSizeMode
);
475 void HandleAccessKey(const WidgetKeyboardEvent
& aEvent
,
476 nsTArray
<uint32_t>& aCharCodes
);
478 #if defined(MOZ_WIDGET_ANDROID)
479 void DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight
);
480 void DynamicToolbarOffsetChanged(ScreenIntCoord aOffset
);
483 void Activate(uint64_t aActionId
);
485 void Deactivate(bool aWindowLowering
, uint64_t aActionId
);
487 void MouseEnterIntoWidget();
489 bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent
* aEvent
);
491 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint
& aOffset
,
492 mozilla::WidgetEvent
* aEvent
);
494 LayoutDeviceToCSSScale
GetLayoutDeviceToCSSScale();
496 MOZ_CAN_RUN_SCRIPT_BOUNDARY
mozilla::ipc::IPCResult
497 RecvRequestNativeKeyBindings(const uint32_t& aType
,
498 const mozilla::WidgetKeyboardEvent
& aEvent
,
499 nsTArray
<mozilla::CommandInt
>* aCommands
);
501 mozilla::ipc::IPCResult
RecvSynthesizeNativeKeyEvent(
502 const int32_t& aNativeKeyboardLayout
, const int32_t& aNativeKeyCode
,
503 const uint32_t& aModifierFlags
, const nsString
& aCharacters
,
504 const nsString
& aUnmodifiedCharacters
, const uint64_t& aObserverId
);
506 mozilla::ipc::IPCResult
RecvSynthesizeNativeMouseEvent(
507 const LayoutDeviceIntPoint
& aPoint
, const uint32_t& aNativeMessage
,
508 const int16_t& aButton
, const uint32_t& aModifierFlags
,
509 const uint64_t& aObserverId
);
511 mozilla::ipc::IPCResult
RecvSynthesizeNativeMouseMove(
512 const LayoutDeviceIntPoint
& aPoint
, const uint64_t& aObserverId
);
514 mozilla::ipc::IPCResult
RecvSynthesizeNativeMouseScrollEvent(
515 const LayoutDeviceIntPoint
& aPoint
, const uint32_t& aNativeMessage
,
516 const double& aDeltaX
, const double& aDeltaY
, const double& aDeltaZ
,
517 const uint32_t& aModifierFlags
, const uint32_t& aAdditionalFlags
,
518 const uint64_t& aObserverId
);
520 mozilla::ipc::IPCResult
RecvSynthesizeNativeTouchPoint(
521 const uint32_t& aPointerId
, const TouchPointerState
& aPointerState
,
522 const LayoutDeviceIntPoint
& aPoint
, const double& aPointerPressure
,
523 const uint32_t& aPointerOrientation
, const uint64_t& aObserverId
);
525 mozilla::ipc::IPCResult
RecvSynthesizeNativeTouchPadPinch(
526 const TouchpadGesturePhase
& aEventPhase
, const float& aScale
,
527 const LayoutDeviceIntPoint
& aPoint
, const int32_t& aModifierFlags
);
529 mozilla::ipc::IPCResult
RecvSynthesizeNativeTouchTap(
530 const LayoutDeviceIntPoint
& aPoint
, const bool& aLongTap
,
531 const uint64_t& aObserverId
);
533 mozilla::ipc::IPCResult
RecvClearNativeTouchSequence(
534 const uint64_t& aObserverId
);
536 mozilla::ipc::IPCResult
RecvSynthesizeNativePenInput(
537 const uint32_t& aPointerId
, const TouchPointerState
& aPointerState
,
538 const LayoutDeviceIntPoint
& aPoint
, const double& aPressure
,
539 const uint32_t& aRotation
, const int32_t& aTiltX
, const int32_t& aTiltY
,
540 const int32_t& aButton
, const uint64_t& aObserverId
);
542 mozilla::ipc::IPCResult
RecvSynthesizeNativeTouchpadDoubleTap(
543 const LayoutDeviceIntPoint
& aPoint
, const uint32_t& aModifierFlags
);
545 mozilla::ipc::IPCResult
RecvSynthesizeNativeTouchpadPan(
546 const TouchpadGesturePhase
& aEventPhase
,
547 const LayoutDeviceIntPoint
& aPoint
, const double& aDeltaX
,
548 const double& aDeltaY
, const int32_t& aModifierFlags
,
549 const uint64_t& aObserverId
);
551 mozilla::ipc::IPCResult
RecvLockNativePointer();
553 mozilla::ipc::IPCResult
RecvUnlockNativePointer();
556 * The following Send*Event() marks aEvent as posted to remote process if
557 * it succeeded. So, you can check the result with
558 * aEvent.HasBeenPostedToRemoteProcess().
560 void SendRealMouseEvent(WidgetMouseEvent
& aEvent
);
562 void SendRealDragEvent(WidgetDragEvent
& aEvent
, uint32_t aDragAction
,
563 uint32_t aDropEffect
, nsIPrincipal
* aPrincipal
,
564 nsIContentSecurityPolicy
* aCsp
);
566 void SendMouseWheelEvent(WidgetWheelEvent
& aEvent
);
569 * Only when the event is synthesized, retrieving writing mode may flush
572 MOZ_CAN_RUN_SCRIPT_BOUNDARY
void SendRealKeyEvent(
573 WidgetKeyboardEvent
& aEvent
);
575 void SendRealTouchEvent(WidgetTouchEvent
& aEvent
);
578 * Different from above Send*Event(), these methods return true if the
579 * event has been posted to the remote process or failed to do that but
580 * shouldn't be handled by following event listeners.
581 * If you need to check if it's actually posted to the remote process,
582 * you can refer aEvent.HasBeenPostedToRemoteProcess().
584 bool SendCompositionEvent(mozilla::WidgetCompositionEvent
& aEvent
,
585 uint32_t aCompositionId
);
587 bool SendSelectionEvent(mozilla::WidgetSelectionEvent
& aEvent
);
589 MOZ_CAN_RUN_SCRIPT_BOUNDARY
bool SendHandleTap(
590 TapType aType
, const LayoutDevicePoint
& aPoint
, Modifiers aModifiers
,
591 const ScrollableLayerGuid
& aGuid
, uint64_t aInputBlockId
);
593 already_AddRefed
<PFilePickerParent
> AllocPFilePickerParent(
594 const nsString
& aTitle
, const nsIFilePicker::Mode
& aMode
);
596 bool GetGlobalJSObject(JSContext
* cx
, JSObject
** globalp
);
598 void StartPersistence(CanonicalBrowsingContext
* aContext
,
599 nsIWebBrowserPersistDocumentReceiver
* aRecv
,
602 bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent
& aEvent
);
604 bool SendInsertText(const nsString
& aStringToInsert
);
606 bool SendPasteTransferable(IPCTransferableData
&& aTransferableData
,
607 const bool& aIsPrivateData
,
608 nsIPrincipal
* aRequestingPrincipal
,
609 const nsContentPolicyType
& aContentPolicyType
);
611 // Helper for transforming a point
612 LayoutDeviceIntPoint
TransformPoint(
613 const LayoutDeviceIntPoint
& aPoint
,
614 const LayoutDeviceToLayoutDeviceMatrix4x4
& aMatrix
);
615 LayoutDevicePoint
TransformPoint(
616 const LayoutDevicePoint
& aPoint
,
617 const LayoutDeviceToLayoutDeviceMatrix4x4
& aMatrix
);
619 // Transform a coordinate from the parent process coordinate space to the
620 // child process coordinate space.
621 LayoutDeviceIntPoint
TransformParentToChild(
622 const LayoutDeviceIntPoint
& aPoint
);
623 LayoutDevicePoint
TransformParentToChild(const LayoutDevicePoint
& aPoint
);
625 // Transform a coordinate from the child process coordinate space to the
626 // parent process coordinate space.
627 LayoutDeviceIntPoint
TransformChildToParent(
628 const LayoutDeviceIntPoint
& aPoint
);
629 LayoutDevicePoint
TransformChildToParent(const LayoutDevicePoint
& aPoint
);
630 LayoutDeviceIntRect
TransformChildToParent(const LayoutDeviceIntRect
& aRect
);
632 // Returns the matrix that transforms event coordinates from the coordinate
633 // space of the child process to the coordinate space of the parent process.
634 LayoutDeviceToLayoutDeviceMatrix4x4
GetChildToParentConversionMatrix();
636 void SetChildToParentConversionMatrix(
637 const Maybe
<LayoutDeviceToLayoutDeviceMatrix4x4
>& aMatrix
,
638 const ScreenRect
& aRemoteDocumentRect
);
640 // Returns the offset from the origin of our frameloader's nearest widget to
641 // the origin of its layout frame. This offset is used to translate event
642 // coordinates relative to the PuppetWidget origin in the child process.
644 // GOING AWAY. PLEASE AVOID ADDING CALLERS. Use the above tranformation
646 LayoutDeviceIntPoint
GetChildProcessOffset();
648 // Returns the offset from the on-screen origin of our top-level window's
649 // widget (including window decorations) to the origin of our frameloader's
650 // nearest widget. This offset is used to translate coordinates from the
651 // PuppetWidget's origin to absolute screen coordinates in the child.
652 LayoutDeviceIntPoint
GetClientOffset();
654 void StopIMEStateManagement();
656 PPaymentRequestParent
* AllocPPaymentRequestParent();
658 bool DeallocPPaymentRequestParent(PPaymentRequestParent
* aActor
);
660 bool SendLoadRemoteScript(const nsAString
& aURL
,
661 const bool& aRunInGlobalScope
);
663 void LayerTreeUpdate(bool aActive
);
665 mozilla::ipc::IPCResult
RecvInvokeDragSession(
666 nsTArray
<IPCTransferableData
>&& aTransferables
, const uint32_t& aAction
,
667 Maybe
<BigBuffer
>&& aVisualDnDData
, const uint32_t& aStride
,
668 const gfx::SurfaceFormat
& aFormat
, const LayoutDeviceIntRect
& aDragRect
,
669 nsIPrincipal
* aPrincipal
, nsIContentSecurityPolicy
* aCsp
,
670 const CookieJarSettingsArgs
& aCookieJarSettingsArgs
,
671 const MaybeDiscarded
<WindowContext
>& aSourceWindowContext
,
672 const MaybeDiscarded
<WindowContext
>& aSourceTopWindowContext
);
674 void AddInitialDnDDataTo(IPCTransferableData
* aTransferableData
,
675 nsIPrincipal
** aPrincipal
);
677 bool TakeDragVisualization(RefPtr
<mozilla::gfx::SourceSurface
>& aSurface
,
678 LayoutDeviceIntRect
* aDragRect
);
680 mozilla::ipc::IPCResult
RecvEnsureLayersConnected(
681 CompositorOptions
* aCompositorOptions
);
683 // LiveResizeListener implementation
684 void LiveResizeStarted() override
;
685 void LiveResizeStopped() override
;
687 void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents
= true; }
688 bool IsReadyToHandleInputEvents() { return mIsReadyToHandleInputEvents
; }
690 void NavigateByKey(bool aForward
, bool aForDocumentNavigation
);
692 bool GetDocShellIsActive();
693 void SetDocShellIsActive(bool aDocShellIsActive
);
695 bool GetHasPresented();
697 bool GetRenderLayers();
698 void SetRenderLayers(bool aRenderLayers
);
699 bool GetPriorityHint();
700 void SetPriorityHint(bool aPriorityHint
);
701 void PreserveLayers(bool aPreserveLayers
);
702 void NotifyResolutionChanged();
704 bool CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType
,
705 int32_t aNavigationIndex
,
706 nsIURI
* aNavigationURI
) const;
708 // Called when the BrowserParent is being destroyed or entering bfcache.
712 friend BrowserBridgeParent
;
715 void SetBrowserBridgeParent(BrowserBridgeParent
* aBrowser
);
716 void SetBrowserHost(BrowserHost
* aBrowser
);
719 const nsString
& aMessage
, bool aSync
, ipc::StructuredCloneData
* aData
,
720 nsTArray
<ipc::StructuredCloneData
>* aJSONRetVal
= nullptr);
722 virtual void ActorDestroy(ActorDestroyReason why
) override
;
724 mozilla::ipc::IPCResult
RecvRemoteIsReadyToHandleInputEvents();
726 mozilla::ipc::IPCResult
RecvSetDimensions(mozilla::DimensionRequest aRequest
,
727 const double& aScale
);
729 mozilla::ipc::IPCResult
RecvShowCanvasPermissionPrompt(
730 const nsCString
& aOrigin
, const bool& aHideDoorHanger
);
732 mozilla::ipc::IPCResult
RecvSetSystemFont(const nsCString
& aFontName
);
733 mozilla::ipc::IPCResult
RecvGetSystemFont(nsCString
* aFontName
);
735 mozilla::ipc::IPCResult
RecvVisitURI(nsIURI
* aURI
, nsIURI
* aLastVisitedURI
,
736 const uint32_t& aFlags
,
737 const uint64_t& aBrowserId
);
739 mozilla::ipc::IPCResult
RecvQueryVisitedState(
740 nsTArray
<RefPtr
<nsIURI
>>&& aURIs
);
742 mozilla::ipc::IPCResult
RecvMaybeFireEmbedderLoadEvents(
743 EmbedderElementEventType aFireEventAtEmbeddingElement
);
745 mozilla::ipc::IPCResult
RecvRequestPointerLock(
746 RequestPointerLockResolver
&& aResolve
);
747 mozilla::ipc::IPCResult
RecvReleasePointerLock();
749 mozilla::ipc::IPCResult
RecvRequestPointerCapture(
750 const uint32_t& aPointerId
, RequestPointerCaptureResolver
&& aResolve
);
751 mozilla::ipc::IPCResult
RecvReleasePointerCapture(const uint32_t& aPointerId
);
753 mozilla::ipc::IPCResult
RecvShowDynamicToolbar();
756 void SuppressDisplayport(bool aEnabled
);
758 void SetRenderLayersInternal(bool aEnabled
);
760 already_AddRefed
<nsFrameLoader
> GetFrameLoader(
761 bool aUseCachedFrameLoaderAfterDestroy
= false) const;
763 void TryCacheDPIAndScale();
765 bool AsyncPanZoomEnabled() const;
767 // Update state prior to routing an APZ-aware event to the child process.
768 // |aOutTargetGuid| will contain the identifier
769 // of the APZC instance that handled the event. aOutTargetGuid may be null.
770 // |aOutInputBlockId| will contain the identifier of the input block
771 // that this event was added to, if there was one. aOutInputBlockId may be
772 // null. |aOutApzResponse| will contain the response that the APZ gave when
773 // processing the input block; this is used for generating appropriate
774 // pointercancel events.
775 void ApzAwareEventRoutingToChild(ScrollableLayerGuid
* aOutTargetGuid
,
776 uint64_t* aOutInputBlockId
,
777 nsEventStatus
* aOutApzResponse
);
779 // When dropping links we perform a roundtrip from
780 // Parent (SendRealDragEvent) -> Child -> Parent (RecvDropLinks)
781 // and have to ensure that the child did not modify links to be loaded.
782 bool QueryDropLinksForVerification();
784 void UnlockNativePointer();
786 void UpdateNativePointerLockCenter(nsIWidget
* aWidget
);
789 // This is used when APZ needs to find the BrowserParent associated with a
790 // layer to dispatch events.
791 typedef nsTHashMap
<nsUint64HashKey
, BrowserParent
*> LayerToBrowserParentTable
;
792 static LayerToBrowserParentTable
* sLayerToBrowserParentTable
;
794 static void AddBrowserParentToTable(layers::LayersId aLayersId
,
795 BrowserParent
* aBrowserParent
);
797 static void RemoveBrowserParentFromTable(layers::LayersId aLayersId
);
799 // Keeps track of which BrowserParent has keyboard focus.
800 // If nullptr, the parent process has focus.
801 // Use UpdateFocus() to manage.
802 static BrowserParent
* sFocus
;
804 // Keeps track of which top-level BrowserParent the keyboard focus is under.
805 // If nullptr, the parent process has focus.
806 // Use SetTopLevelWebFocus and UnsetTopLevelWebFocus to manage.
807 static BrowserParent
* sTopLevelWebFocus
;
809 // Setter for sTopLevelWebFocus
810 static void SetTopLevelWebFocus(BrowserParent
* aBrowserParent
);
812 // Unsetter for sTopLevelWebFocus; only unsets if argument matches
813 // current sTopLevelWebFocus. Use UnsetTopLevelWebFocusAll() to
814 // unset regardless of current value.
815 static void UnsetTopLevelWebFocus(BrowserParent
* aBrowserParent
);
817 // Recomputes sFocus and returns it.
818 static BrowserParent
* UpdateFocus();
820 // Keeps track of which BrowserParent the real mouse event is sent to.
821 static BrowserParent
* sLastMouseRemoteTarget
;
823 // Unsetter for LastMouseRemoteTarget; only unsets if argument matches
824 // current sLastMouseRemoteTarget.
825 static void UnsetLastMouseRemoteTarget(BrowserParent
* aBrowserParent
);
828 bool operator==(const APZData
& aOther
) const {
829 return aOther
.guid
== guid
&& aOther
.blockId
== blockId
&&
830 aOther
.apzResponse
== apzResponse
;
833 bool operator!=(const APZData
& aOther
) const { return !(*this == aOther
); }
835 ScrollableLayerGuid guid
;
837 nsEventStatus apzResponse
;
839 void SendRealTouchMoveEvent(WidgetTouchEvent
& aEvent
, APZData
& aAPZData
,
840 uint32_t aConsecutiveTouchMoveCount
);
842 void UpdateVsyncParentVsyncDispatcher();
845 // Unsets sTopLevelWebFocus regardless of its current value.
846 static void UnsetTopLevelWebFocusAll();
848 // Recomputes focus when the BrowsingContext tree changes in a
849 // way that potentially invalidates the sFocus.
850 static void UpdateFocusFromBrowsingContext();
855 RefPtr
<ContentParent
> mManager
;
856 // The root browsing context loaded in this BrowserParent.
857 RefPtr
<CanonicalBrowsingContext
> mBrowsingContext
;
858 nsCOMPtr
<nsILoadContext
> mLoadContext
;
859 RefPtr
<Element
> mFrameElement
;
860 nsCOMPtr
<nsIBrowserDOMWindow
> mBrowserDOMWindow
;
861 // We keep a strong reference to the frameloader after we've sent the
862 // Destroy message and before we've received __delete__. This allows us to
863 // dispatch message manager messages during this time.
864 RefPtr
<nsFrameLoader
> mFrameLoader
;
865 uint32_t mChromeFlags
;
867 // Pointer back to BrowserBridgeParent if there is one associated with
868 // this BrowserParent. This is non-owning to avoid cycles and is managed
869 // by the BrowserBridgeParent instance, which has the strong reference
870 // to this BrowserParent.
871 BrowserBridgeParent
* mBrowserBridgeParent
;
872 // Pointer to the BrowserHost that owns us, if any. This is mutually
873 // exclusive with mBrowserBridgeParent, and one is guaranteed to be
875 BrowserHost
* mBrowserHost
;
877 ContentCacheInParent mContentCache
;
879 layout::RemoteLayerTreeOwner mRemoteLayerTreeOwner
;
881 Maybe
<LayoutDeviceToLayoutDeviceMatrix4x4
> mChildToParentConversionMatrix
;
882 Maybe
<ScreenRect
> mRemoteDocumentRect
;
884 // mWaitingReplyKeyboardEvents stores keyboard events which are sent from
885 // SendRealKeyEvent and the event will be back as a reply event. They are
886 // removed when RecvReplyKeyEvent receives corresponding event or newer event.
887 // Note that reply event will be used for handling non-reserved shortcut keys.
888 // Therefore, we need to store only important data for GlobalKeyHandler.
889 struct SentKeyEventData
{
892 uint32_t mPseudoCharCode
;
893 KeyNameIndex mKeyNameIndex
;
894 CodeNameIndex mCodeNameIndex
;
895 Modifiers mModifiers
;
898 nsTArray
<SentKeyEventData
> mWaitingReplyKeyboardEvents
;
901 ScreenIntSize mDimensions
;
904 CSSToLayoutDeviceScale mDefaultScale
;
905 bool mUpdatedDimensions
;
906 nsSizeMode mSizeMode
;
907 LayoutDeviceIntPoint mClientOffset
;
908 LayoutDeviceIntPoint mChromeOffset
;
910 // When loading a new tab or window via window.open, the child is
911 // responsible for loading the URL it wants into the new BrowserChild. When
912 // the parent receives the CreateWindow message, though, it sends a LoadURL
913 // message, usually for about:blank. It's important for the about:blank load
914 // to get processed because the Firefox frontend expects every new window to
915 // immediately start loading something (see bug 1123090). However, we want
916 // the child to process the LoadURL message before it returns from
917 // ProvideWindow so that the URL sent from the parent doesn't override the
918 // child's URL. This is not possible using our IPC mechanisms. To solve the
919 // problem, we skip sending the LoadURL message in the parent and instead
920 // return the URL as a result from CreateWindow. The child simulates
921 // receiving a LoadURL message before returning from ProvideWindow.
923 // The mCreatingWindow flag is set while dispatching CreateWindow. During
924 // that time, any LoadURL calls are skipped.
925 bool mCreatingWindow
;
927 // When loading a new tab or window via window.open, we want to ensure that
928 // frame scripts for that tab are loaded before any scripts start to run in
929 // the window. We can't load the frame scripts the normal way, using
930 // separate IPC messages, since they won't be processed by the child until
931 // returning to the event loop, which is too late. Instead, we queue up
932 // frame scripts that we intend to load and send them as part of the
933 // CreateWindow response. Then BrowserChild loads them immediately.
934 nsTArray
<FrameScriptInfo
> mDelayedFrameScripts
;
936 // Cached cursor setting from BrowserChild. When the cursor is over the
937 // tab, it should take this appearance.
938 nsIWidget::Cursor mCursor
;
940 nsTArray
<nsString
> mVerifyDropLinks
;
942 RefPtr
<VsyncParent
> mVsyncParent
;
945 int32_t mActiveSupressDisplayportCount
= 0;
948 // When true, we've initiated normal shutdown and notified our managing
950 bool mMarkedDestroying
: 1;
951 // When true, the BrowserParent is invalid and we should not send IPC
953 bool mIsDestroyed
: 1;
954 // True if the cursor changes from the BrowserChild should change the widget
955 // cursor. This happens whenever the cursor is in the remote target's
957 bool mRemoteTargetSetsCursor
: 1;
959 // If this flag is set, then the tab's layers will be preserved even when
960 // the tab's docshell is inactive.
961 bool mIsPreservingLayers
: 1;
963 // Holds the most recent value passed to the RenderLayers function. This
964 // does not necessarily mean that the layers have finished rendering
965 // and have uploaded - for that, use mHasLayers.
966 bool mRenderLayers
: 1;
968 // True if process should be set to a higher priority.
969 bool mPriorityHint
: 1;
971 // True if the compositor has reported that the BrowserChild has uploaded
975 // True if this BrowserParent has had its layer tree sent to the compositor
977 bool mHasPresented
: 1;
979 // True when the remote browser is created and ready to handle input events.
980 bool mIsReadyToHandleInputEvents
: 1;
982 // True if we suppress the eMouseEnterIntoWidget event due to the
983 // BrowserChild was not ready to handle it. We will resend it when the next
984 // time we fire a mouse event and the BrowserChild is ready.
985 bool mIsMouseEnterIntoWidgetEventSuppressed
: 1;
987 // True after RecvLockNativePointer has been called and until
988 // UnlockNativePointer has been called.
989 bool mLockedNativePointer
: 1;
991 // True between ShowTooltip and HideTooltip messages.
992 bool mShowingTooltip
: 1;
995 struct MOZ_STACK_CLASS
BrowserParent::AutoUseNewTab final
{
997 explicit AutoUseNewTab(BrowserParent
* aNewTab
) : mNewTab(aNewTab
) {
998 MOZ_ASSERT(!aNewTab
->mCreatingWindow
);
999 aNewTab
->mCreatingWindow
= true;
1002 ~AutoUseNewTab() { mNewTab
->mCreatingWindow
= false; }
1005 RefPtr
<BrowserParent
> mNewTab
;
1009 } // namespace mozilla
1011 #endif // mozilla_dom_BrowserParent_h