Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / dom / ipc / BrowserParent.h
blob4d4ae287b47690fc134d7d1296ced3095d19c29f
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
10 #include <utility>
12 #include "LiveResizeListener.h"
13 #include "Units.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"
25 #include "nsCOMPtr.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"
32 #include "nsTArray.h"
33 #include "nsWeakReference.h"
35 class imgIContainer;
36 class nsCycleCollectionTraversalCallback;
37 class nsDocShellLoadState;
38 class nsFrameLoader;
39 class nsIBrowser;
40 class nsIContent;
41 class nsIContentSecurityPolicy;
42 class nsIDocShell;
43 class nsILoadContext;
44 class nsIPrincipal;
45 class nsIRequest;
46 class nsIURI;
47 class nsIWebBrowserPersistDocumentReceiver;
48 class nsIWebProgress;
49 class nsIXULBrowserWindow;
50 class nsPIDOMWindowOuter;
52 namespace mozilla {
54 namespace a11y {
55 class DocAccessibleParent;
58 namespace widget {
59 struct IMENotification;
60 } // namespace widget
62 namespace gfx {
63 class SourceSurface;
64 } // namespace gfx
66 namespace dom {
68 class CanonicalBrowsingContext;
69 class ClonedMessageData;
70 class ContentParent;
71 class Element;
72 class DataTransfer;
73 class BrowserHost;
74 class BrowserBridgeParent;
76 namespace ipc {
77 class StructuredCloneData;
78 } // namespace ipc
80 /**
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,
88 public TabContext,
89 public LiveResizeListener {
90 typedef mozilla::dom::ClonedMessageData ClonedMessageData;
91 using TapType = GeckoContentController_TapType;
93 friend class PBrowserParent;
95 virtual ~BrowserParent();
97 public:
98 // Helper class for ContentParent::RecvCreateWindow.
99 struct AutoUseNewTab;
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
115 * is focused.
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) {
211 aCallback(this);
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);
257 void Destroy();
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,
281 nsIURI* aHandlerURI,
282 const nsString& aTitle,
283 nsIURI* aDocURI);
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,
307 const Maybe<mozilla::ContentBlockingNotifier::CanvasFingerprinter>&
308 aCanvasFingerprinter,
309 const Maybe<bool>& aCanvasFingerprinterKnownText);
311 mozilla::ipc::IPCResult RecvNavigationFinished();
313 already_AddRefed<nsIBrowser> GetBrowser();
315 already_AddRefed<CanonicalBrowsingContext> BrowsingContextForWebProgress(
316 const WebProgressData& aWebProgressData);
318 mozilla::ipc::IPCResult RecvIntrinsicSizeOrRatioChanged(
319 const Maybe<IntrinsicSize>& aIntrinsicSize,
320 const Maybe<AspectRatio>& aIntrinsicRatio);
322 mozilla::ipc::IPCResult RecvImageLoadComplete(const nsresult& aResult);
324 mozilla::ipc::IPCResult RecvSyncMessage(
325 const nsString& aMessage, const ClonedMessageData& aData,
326 nsTArray<ipc::StructuredCloneData>* aRetVal);
328 mozilla::ipc::IPCResult RecvAsyncMessage(const nsString& aMessage,
329 const ClonedMessageData& aData);
331 mozilla::ipc::IPCResult RecvNotifyIMEFocus(
332 const ContentCache& aContentCache,
333 const widget::IMENotification& aEventMessage,
334 NotifyIMEFocusResolver&& aResolve);
336 mozilla::ipc::IPCResult RecvNotifyIMETextChange(
337 const ContentCache& aContentCache,
338 const widget::IMENotification& aEventMessage);
340 mozilla::ipc::IPCResult RecvNotifyIMECompositionUpdate(
341 const ContentCache& aContentCache,
342 const widget::IMENotification& aEventMessage);
344 mozilla::ipc::IPCResult RecvNotifyIMESelection(
345 const ContentCache& aContentCache,
346 const widget::IMENotification& aEventMessage);
348 mozilla::ipc::IPCResult RecvUpdateContentCache(
349 const ContentCache& aContentCache);
351 mozilla::ipc::IPCResult RecvNotifyIMEMouseButtonEvent(
352 const widget::IMENotification& aEventMessage, bool* aConsumedByIME);
354 mozilla::ipc::IPCResult RecvNotifyIMEPositionChange(
355 const ContentCache& aContentCache,
356 const widget::IMENotification& aEventMessage);
358 mozilla::ipc::IPCResult RecvOnEventNeedingAckHandled(
359 const EventMessage& aMessage, const uint32_t& aCompositionId);
361 mozilla::ipc::IPCResult RecvRequestIMEToCommitComposition(
362 const bool& aCancel, const uint32_t& aCompositionId, bool* aIsCommitted,
363 nsString* aCommittedString);
365 mozilla::ipc::IPCResult RecvGetInputContext(widget::IMEState* aIMEState);
367 mozilla::ipc::IPCResult RecvSetInputContext(
368 const widget::InputContext& aContext,
369 const widget::InputContextAction& aAction);
371 mozilla::ipc::IPCResult RecvRequestFocus(const bool& aCanRaise,
372 const CallerType aCallerType);
374 mozilla::ipc::IPCResult RecvWheelZoomChange(bool aIncrease);
376 mozilla::ipc::IPCResult RecvLookUpDictionary(
377 const nsString& aText, nsTArray<mozilla::FontRange>&& aFontRangeArray,
378 const bool& aIsVertical, const LayoutDeviceIntPoint& aPoint);
380 mozilla::ipc::IPCResult RecvEnableDisableCommands(
381 const MaybeDiscarded<BrowsingContext>& aContext, const nsString& aAction,
382 nsTArray<nsCString>&& aEnabledCommands,
383 nsTArray<nsCString>&& aDisabledCommands);
385 mozilla::ipc::IPCResult RecvSetCursor(
386 const nsCursor& aValue, const bool& aHasCustomCursor,
387 Maybe<BigBuffer>&& aCursorData, const uint32_t& aWidth,
388 const uint32_t& aHeight, const float& aResolutionX,
389 const float& aResolutionY, const uint32_t& aStride,
390 const gfx::SurfaceFormat& aFormat, const uint32_t& aHotspotX,
391 const uint32_t& aHotspotY, const bool& aForce);
393 mozilla::ipc::IPCResult RecvSetLinkStatus(const nsString& aStatus);
395 mozilla::ipc::IPCResult RecvShowTooltip(const uint32_t& aX,
396 const uint32_t& aY,
397 const nsString& aTooltip,
398 const nsString& aDirection);
400 mozilla::ipc::IPCResult RecvHideTooltip();
402 mozilla::ipc::IPCResult RecvRespondStartSwipeEvent(
403 const uint64_t& aInputBlockId, const bool& aStartSwipe);
405 mozilla::ipc::IPCResult RecvDispatchWheelEvent(
406 const mozilla::WidgetWheelEvent& aEvent);
408 mozilla::ipc::IPCResult RecvDispatchMouseEvent(
409 const mozilla::WidgetMouseEvent& aEvent);
411 mozilla::ipc::IPCResult RecvDispatchKeyboardEvent(
412 const mozilla::WidgetKeyboardEvent& aEvent);
414 mozilla::ipc::IPCResult RecvDispatchTouchEvent(
415 const mozilla::WidgetTouchEvent& aEvent);
417 mozilla::ipc::IPCResult RecvScrollRectIntoView(
418 const nsRect& aRect, const ScrollAxis& aVertical,
419 const ScrollAxis& aHorizontal, const ScrollFlags& aScrollFlags,
420 const int32_t& aAppUnitsPerDevPixel);
422 already_AddRefed<PColorPickerParent> AllocPColorPickerParent(
423 const nsString& aTitle, const nsString& aInitialColor,
424 const nsTArray<nsString>& aDefaultColors);
426 PVsyncParent* AllocPVsyncParent();
428 bool DeallocPVsyncParent(PVsyncParent* aActor);
430 #ifdef ACCESSIBILITY
431 PDocAccessibleParent* AllocPDocAccessibleParent(
432 PDocAccessibleParent*, const uint64_t&,
433 const MaybeDiscardedBrowsingContext&);
434 bool DeallocPDocAccessibleParent(PDocAccessibleParent*);
435 virtual mozilla::ipc::IPCResult RecvPDocAccessibleConstructor(
436 PDocAccessibleParent* aDoc, PDocAccessibleParent* aParentDoc,
437 const uint64_t& aParentID,
438 const MaybeDiscardedBrowsingContext& aBrowsingContext) override;
439 #endif
441 already_AddRefed<PSessionStoreParent> AllocPSessionStoreParent();
443 mozilla::ipc::IPCResult RecvNewWindowGlobal(
444 ManagedEndpoint<PWindowGlobalParent>&& aEndpoint,
445 const WindowGlobalInit& aInit);
447 mozilla::ipc::IPCResult RecvIsWindowSupportingProtectedMedia(
448 const uint64_t& aOuterWindowID,
449 IsWindowSupportingProtectedMediaResolver&& aResolve);
451 mozilla::ipc::IPCResult RecvIsWindowSupportingWebVR(
452 const uint64_t& aOuterWindowID,
453 IsWindowSupportingWebVRResolver&& aResolve);
455 void LoadURL(nsDocShellLoadState* aLoadState);
457 void ResumeLoad(uint64_t aPendingSwitchID);
459 void InitRendering();
460 bool AttachWindowRenderer();
461 void MaybeShowFrame();
463 bool Show(const OwnerShowInfo&);
465 void UpdateDimensions(const nsIntRect& aRect, const ScreenIntSize& aSize);
467 DimensionInfo GetDimensionInfo();
469 nsresult UpdatePosition();
471 // Notify position update to all descendant documents in this browser parent.
472 // NOTE: This should use only for browsers in popup windows attached to the
473 // main browser window.
474 void NotifyPositionUpdatedForContentsInPopup();
476 void SizeModeChanged(const nsSizeMode& aSizeMode);
478 void HandleAccessKey(const WidgetKeyboardEvent& aEvent,
479 nsTArray<uint32_t>& aCharCodes);
481 #if defined(MOZ_WIDGET_ANDROID)
482 void DynamicToolbarMaxHeightChanged(ScreenIntCoord aHeight);
483 void DynamicToolbarOffsetChanged(ScreenIntCoord aOffset);
484 #endif
486 void Activate(uint64_t aActionId);
488 void Deactivate(bool aWindowLowering, uint64_t aActionId);
490 void MouseEnterIntoWidget();
492 bool MapEventCoordinatesForChildProcess(mozilla::WidgetEvent* aEvent);
494 void MapEventCoordinatesForChildProcess(const LayoutDeviceIntPoint& aOffset,
495 mozilla::WidgetEvent* aEvent);
497 LayoutDeviceToCSSScale GetLayoutDeviceToCSSScale();
499 MOZ_CAN_RUN_SCRIPT_BOUNDARY mozilla::ipc::IPCResult
500 RecvRequestNativeKeyBindings(const uint32_t& aType,
501 const mozilla::WidgetKeyboardEvent& aEvent,
502 nsTArray<mozilla::CommandInt>* aCommands);
504 mozilla::ipc::IPCResult RecvSynthesizeNativeKeyEvent(
505 const int32_t& aNativeKeyboardLayout, const int32_t& aNativeKeyCode,
506 const uint32_t& aModifierFlags, const nsString& aCharacters,
507 const nsString& aUnmodifiedCharacters, const uint64_t& aObserverId);
509 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseEvent(
510 const LayoutDeviceIntPoint& aPoint, const uint32_t& aNativeMessage,
511 const int16_t& aButton, const uint32_t& aModifierFlags,
512 const uint64_t& aObserverId);
514 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseMove(
515 const LayoutDeviceIntPoint& aPoint, const uint64_t& aObserverId);
517 mozilla::ipc::IPCResult RecvSynthesizeNativeMouseScrollEvent(
518 const LayoutDeviceIntPoint& aPoint, const uint32_t& aNativeMessage,
519 const double& aDeltaX, const double& aDeltaY, const double& aDeltaZ,
520 const uint32_t& aModifierFlags, const uint32_t& aAdditionalFlags,
521 const uint64_t& aObserverId);
523 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchPoint(
524 const uint32_t& aPointerId, const TouchPointerState& aPointerState,
525 const LayoutDeviceIntPoint& aPoint, const double& aPointerPressure,
526 const uint32_t& aPointerOrientation, const uint64_t& aObserverId);
528 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchPadPinch(
529 const TouchpadGesturePhase& aEventPhase, const float& aScale,
530 const LayoutDeviceIntPoint& aPoint, const int32_t& aModifierFlags);
532 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchTap(
533 const LayoutDeviceIntPoint& aPoint, const bool& aLongTap,
534 const uint64_t& aObserverId);
536 mozilla::ipc::IPCResult RecvClearNativeTouchSequence(
537 const uint64_t& aObserverId);
539 mozilla::ipc::IPCResult RecvSynthesizeNativePenInput(
540 const uint32_t& aPointerId, const TouchPointerState& aPointerState,
541 const LayoutDeviceIntPoint& aPoint, const double& aPressure,
542 const uint32_t& aRotation, const int32_t& aTiltX, const int32_t& aTiltY,
543 const int32_t& aButton, const uint64_t& aObserverId);
545 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchpadDoubleTap(
546 const LayoutDeviceIntPoint& aPoint, const uint32_t& aModifierFlags);
548 mozilla::ipc::IPCResult RecvSynthesizeNativeTouchpadPan(
549 const TouchpadGesturePhase& aEventPhase,
550 const LayoutDeviceIntPoint& aPoint, const double& aDeltaX,
551 const double& aDeltaY, const int32_t& aModifierFlags,
552 const uint64_t& aObserverId);
554 mozilla::ipc::IPCResult RecvLockNativePointer();
556 mozilla::ipc::IPCResult RecvUnlockNativePointer();
559 * The following Send*Event() marks aEvent as posted to remote process if
560 * it succeeded. So, you can check the result with
561 * aEvent.HasBeenPostedToRemoteProcess().
563 void SendRealMouseEvent(WidgetMouseEvent& aEvent);
565 void SendRealDragEvent(WidgetDragEvent& aEvent, uint32_t aDragAction,
566 uint32_t aDropEffect, nsIPrincipal* aPrincipal,
567 nsIContentSecurityPolicy* aCsp);
569 void SendMouseWheelEvent(WidgetWheelEvent& aEvent);
572 * Only when the event is synthesized, retrieving writing mode may flush
573 * the layout.
575 MOZ_CAN_RUN_SCRIPT_BOUNDARY void SendRealKeyEvent(
576 WidgetKeyboardEvent& aEvent);
578 void SendRealTouchEvent(WidgetTouchEvent& aEvent);
581 * Different from above Send*Event(), these methods return true if the
582 * event has been posted to the remote process or failed to do that but
583 * shouldn't be handled by following event listeners.
584 * If you need to check if it's actually posted to the remote process,
585 * you can refer aEvent.HasBeenPostedToRemoteProcess().
587 bool SendCompositionEvent(mozilla::WidgetCompositionEvent& aEvent,
588 uint32_t aCompositionId);
590 bool SendSelectionEvent(mozilla::WidgetSelectionEvent& aEvent);
592 MOZ_CAN_RUN_SCRIPT_BOUNDARY bool SendHandleTap(
593 TapType aType, const LayoutDevicePoint& aPoint, Modifiers aModifiers,
594 const ScrollableLayerGuid& aGuid, uint64_t aInputBlockId,
595 const Maybe<DoubleTapToZoomMetrics>& aDoubleTapToZoomMetrics);
597 already_AddRefed<PFilePickerParent> AllocPFilePickerParent(
598 const nsString& aTitle, const nsIFilePicker::Mode& aMode);
600 bool GetGlobalJSObject(JSContext* cx, JSObject** globalp);
602 void StartPersistence(CanonicalBrowsingContext* aContext,
603 nsIWebBrowserPersistDocumentReceiver* aRecv,
604 ErrorResult& aRv);
606 bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent);
608 bool SendInsertText(const nsString& aStringToInsert);
610 bool SendPasteTransferable(IPCTransferable&& aTransferable);
612 // Helper for transforming a point
613 LayoutDeviceIntPoint TransformPoint(
614 const LayoutDeviceIntPoint& aPoint,
615 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix);
616 LayoutDevicePoint TransformPoint(
617 const LayoutDevicePoint& aPoint,
618 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix);
620 // Transform a coordinate from the parent process coordinate space to the
621 // child process coordinate space.
622 LayoutDeviceIntPoint TransformParentToChild(const WidgetMouseEvent& aEvent);
623 LayoutDeviceIntPoint TransformParentToChild(
624 const LayoutDeviceIntPoint& aPoint);
625 LayoutDevicePoint TransformParentToChild(const LayoutDevicePoint& aPoint);
627 // Transform a coordinate from the child process coordinate space to the
628 // parent process coordinate space.
629 LayoutDeviceIntPoint TransformChildToParent(
630 const LayoutDeviceIntPoint& aPoint);
631 LayoutDevicePoint TransformChildToParent(const LayoutDevicePoint& aPoint);
632 LayoutDeviceIntRect TransformChildToParent(const LayoutDeviceIntRect& aRect);
634 // Returns the matrix that transforms event coordinates from the coordinate
635 // space of the child process to the coordinate space of the parent process.
636 LayoutDeviceToLayoutDeviceMatrix4x4 GetChildToParentConversionMatrix();
638 void SetChildToParentConversionMatrix(
639 const Maybe<LayoutDeviceToLayoutDeviceMatrix4x4>& aMatrix,
640 const ScreenRect& aRemoteDocumentRect);
642 // Returns the offset from the origin of our frameloader's nearest widget to
643 // the origin of its layout frame. This offset is used to translate event
644 // coordinates relative to the PuppetWidget origin in the child process.
646 // GOING AWAY. PLEASE AVOID ADDING CALLERS. Use the above tranformation
647 // methods instead.
648 LayoutDeviceIntPoint GetChildProcessOffset();
650 // Returns the offset from the on-screen origin of our top-level window's
651 // widget (including window decorations) to the origin of our frameloader's
652 // nearest widget. This offset is used to translate coordinates from the
653 // PuppetWidget's origin to absolute screen coordinates in the child.
654 LayoutDeviceIntPoint GetClientOffset();
656 void StopIMEStateManagement();
658 PPaymentRequestParent* AllocPPaymentRequestParent();
660 bool DeallocPPaymentRequestParent(PPaymentRequestParent* aActor);
662 bool SendLoadRemoteScript(const nsAString& aURL,
663 const bool& aRunInGlobalScope);
665 void LayerTreeUpdate(bool aActive);
667 mozilla::ipc::IPCResult RecvInvokeDragSession(
668 nsTArray<IPCTransferableData>&& aTransferables, const uint32_t& aAction,
669 Maybe<BigBuffer>&& aVisualDnDData, const uint32_t& aStride,
670 const gfx::SurfaceFormat& aFormat, const LayoutDeviceIntRect& aDragRect,
671 nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
672 const CookieJarSettingsArgs& aCookieJarSettingsArgs,
673 const MaybeDiscarded<WindowContext>& aSourceWindowContext,
674 const MaybeDiscarded<WindowContext>& aSourceTopWindowContext);
676 void AddInitialDnDDataTo(IPCTransferableData* aTransferableData,
677 nsIPrincipal** aPrincipal);
679 bool TakeDragVisualization(RefPtr<mozilla::gfx::SourceSurface>& aSurface,
680 LayoutDeviceIntRect* aDragRect);
682 mozilla::ipc::IPCResult RecvEnsureLayersConnected(
683 CompositorOptions* aCompositorOptions);
685 // LiveResizeListener implementation
686 void LiveResizeStarted() override;
687 void LiveResizeStopped() override;
689 void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents = true; }
690 bool IsReadyToHandleInputEvents() { return mIsReadyToHandleInputEvents; }
692 void NavigateByKey(bool aForward, bool aForDocumentNavigation);
694 bool GetDocShellIsActive();
695 void SetDocShellIsActive(bool aDocShellIsActive);
697 bool GetHasPresented();
698 bool GetHasLayers();
699 bool GetRenderLayers();
700 void SetRenderLayers(bool aRenderLayers);
701 bool GetPriorityHint();
702 void SetPriorityHint(bool aPriorityHint);
703 void PreserveLayers(bool aPreserveLayers);
704 void NotifyResolutionChanged();
706 bool CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType,
707 int32_t aNavigationIndex,
708 nsIURI* aNavigationURI) const;
710 // Called when the BrowserParent is being destroyed or entering bfcache.
711 void Deactivated();
713 protected:
714 friend BrowserBridgeParent;
715 friend BrowserHost;
717 void SetBrowserBridgeParent(BrowserBridgeParent* aBrowser);
718 void SetBrowserHost(BrowserHost* aBrowser);
720 bool ReceiveMessage(
721 const nsString& aMessage, bool aSync, ipc::StructuredCloneData* aData,
722 nsTArray<ipc::StructuredCloneData>* aJSONRetVal = nullptr);
724 virtual void ActorDestroy(ActorDestroyReason why) override;
726 mozilla::ipc::IPCResult RecvRemoteIsReadyToHandleInputEvents();
728 mozilla::ipc::IPCResult RecvSetDimensions(mozilla::DimensionRequest aRequest,
729 const double& aScale);
731 mozilla::ipc::IPCResult RecvShowCanvasPermissionPrompt(
732 const nsCString& aOrigin, const bool& aHideDoorHanger);
734 mozilla::ipc::IPCResult RecvSetSystemFont(const nsCString& aFontName);
735 mozilla::ipc::IPCResult RecvGetSystemFont(nsCString* aFontName);
737 mozilla::ipc::IPCResult RecvVisitURI(nsIURI* aURI, nsIURI* aLastVisitedURI,
738 const uint32_t& aFlags,
739 const uint64_t& aBrowserId);
741 mozilla::ipc::IPCResult RecvQueryVisitedState(
742 nsTArray<RefPtr<nsIURI>>&& aURIs);
744 mozilla::ipc::IPCResult RecvMaybeFireEmbedderLoadEvents(
745 EmbedderElementEventType aFireEventAtEmbeddingElement);
747 mozilla::ipc::IPCResult RecvRequestPointerLock(
748 RequestPointerLockResolver&& aResolve);
749 mozilla::ipc::IPCResult RecvReleasePointerLock();
751 mozilla::ipc::IPCResult RecvRequestPointerCapture(
752 const uint32_t& aPointerId, RequestPointerCaptureResolver&& aResolve);
753 mozilla::ipc::IPCResult RecvReleasePointerCapture(const uint32_t& aPointerId);
755 mozilla::ipc::IPCResult RecvShowDynamicToolbar();
757 private:
758 void SuppressDisplayport(bool aEnabled);
760 void SetRenderLayersInternal(bool aEnabled);
762 already_AddRefed<nsFrameLoader> GetFrameLoader(
763 bool aUseCachedFrameLoaderAfterDestroy = false) const;
765 void TryCacheDPIAndScale();
767 bool AsyncPanZoomEnabled() const;
769 // Update state prior to routing an APZ-aware event to the child process.
770 // |aOutTargetGuid| will contain the identifier
771 // of the APZC instance that handled the event. aOutTargetGuid may be null.
772 // |aOutInputBlockId| will contain the identifier of the input block
773 // that this event was added to, if there was one. aOutInputBlockId may be
774 // null. |aOutApzResponse| will contain the response that the APZ gave when
775 // processing the input block; this is used for generating appropriate
776 // pointercancel events.
777 void ApzAwareEventRoutingToChild(ScrollableLayerGuid* aOutTargetGuid,
778 uint64_t* aOutInputBlockId,
779 nsEventStatus* aOutApzResponse);
781 // When dropping links we perform a roundtrip from
782 // Parent (SendRealDragEvent) -> Child -> Parent (RecvDropLinks)
783 // and have to ensure that the child did not modify links to be loaded.
784 bool QueryDropLinksForVerification();
786 void UnlockNativePointer();
788 void UpdateNativePointerLockCenter(nsIWidget* aWidget);
790 private:
791 // This is used when APZ needs to find the BrowserParent associated with a
792 // layer to dispatch events.
793 typedef nsTHashMap<nsUint64HashKey, BrowserParent*> LayerToBrowserParentTable;
794 static LayerToBrowserParentTable* sLayerToBrowserParentTable;
796 static void AddBrowserParentToTable(layers::LayersId aLayersId,
797 BrowserParent* aBrowserParent);
799 static void RemoveBrowserParentFromTable(layers::LayersId aLayersId);
801 // Keeps track of which BrowserParent has keyboard focus.
802 // If nullptr, the parent process has focus.
803 // Use UpdateFocus() to manage.
804 static BrowserParent* sFocus;
806 // Keeps track of which top-level BrowserParent the keyboard focus is under.
807 // If nullptr, the parent process has focus.
808 // Use SetTopLevelWebFocus and UnsetTopLevelWebFocus to manage.
809 static BrowserParent* sTopLevelWebFocus;
811 // Setter for sTopLevelWebFocus
812 static void SetTopLevelWebFocus(BrowserParent* aBrowserParent);
814 // Unsetter for sTopLevelWebFocus; only unsets if argument matches
815 // current sTopLevelWebFocus. Use UnsetTopLevelWebFocusAll() to
816 // unset regardless of current value.
817 static void UnsetTopLevelWebFocus(BrowserParent* aBrowserParent);
819 // Recomputes sFocus and returns it.
820 static BrowserParent* UpdateFocus();
822 // Keeps track of which BrowserParent the real mouse event is sent to.
823 static BrowserParent* sLastMouseRemoteTarget;
825 // Unsetter for LastMouseRemoteTarget; only unsets if argument matches
826 // current sLastMouseRemoteTarget.
827 static void UnsetLastMouseRemoteTarget(BrowserParent* aBrowserParent);
829 struct APZData {
830 bool operator==(const APZData& aOther) const {
831 return aOther.guid == guid && aOther.blockId == blockId &&
832 aOther.apzResponse == apzResponse;
835 bool operator!=(const APZData& aOther) const { return !(*this == aOther); }
837 ScrollableLayerGuid guid;
838 uint64_t blockId;
839 nsEventStatus apzResponse;
841 void SendRealTouchMoveEvent(WidgetTouchEvent& aEvent, APZData& aAPZData,
842 uint32_t aConsecutiveTouchMoveCount);
844 void UpdateVsyncParentVsyncDispatcher();
846 public:
847 // Unsets sTopLevelWebFocus regardless of its current value.
848 static void UnsetTopLevelWebFocusAll();
850 // Recomputes focus when the BrowsingContext tree changes in a
851 // way that potentially invalidates the sFocus.
852 static void UpdateFocusFromBrowsingContext();
854 private:
855 TabId mTabId;
857 RefPtr<ContentParent> mManager;
858 // The root browsing context loaded in this BrowserParent.
859 RefPtr<CanonicalBrowsingContext> mBrowsingContext;
860 nsCOMPtr<nsILoadContext> mLoadContext;
861 RefPtr<Element> mFrameElement;
862 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
863 // We keep a strong reference to the frameloader after we've sent the
864 // Destroy message and before we've received __delete__. This allows us to
865 // dispatch message manager messages during this time.
866 RefPtr<nsFrameLoader> mFrameLoader;
867 uint32_t mChromeFlags;
869 // Pointer back to BrowserBridgeParent if there is one associated with
870 // this BrowserParent. This is non-owning to avoid cycles and is managed
871 // by the BrowserBridgeParent instance, which has the strong reference
872 // to this BrowserParent.
873 BrowserBridgeParent* mBrowserBridgeParent;
874 // Pointer to the BrowserHost that owns us, if any. This is mutually
875 // exclusive with mBrowserBridgeParent, and one is guaranteed to be
876 // non-null.
877 BrowserHost* mBrowserHost;
879 ContentCacheInParent mContentCache;
881 layout::RemoteLayerTreeOwner mRemoteLayerTreeOwner;
883 Maybe<LayoutDeviceToLayoutDeviceMatrix4x4> mChildToParentConversionMatrix;
884 Maybe<ScreenRect> mRemoteDocumentRect;
886 // mWaitingReplyKeyboardEvents stores keyboard events which are sent from
887 // SendRealKeyEvent and the event will be back as a reply event. They are
888 // removed when RecvReplyKeyEvent receives corresponding event or newer event.
889 // Note that reply event will be used for handling non-reserved shortcut keys.
890 // Therefore, we need to store only important data for GlobalKeyHandler.
891 struct SentKeyEventData {
892 uint32_t mKeyCode;
893 uint32_t mCharCode;
894 uint32_t mPseudoCharCode;
895 KeyNameIndex mKeyNameIndex;
896 CodeNameIndex mCodeNameIndex;
897 Modifiers mModifiers;
898 nsID mUUID;
900 nsTArray<SentKeyEventData> mWaitingReplyKeyboardEvents;
902 nsIntRect mRect;
903 ScreenIntSize mDimensions;
904 float mDPI;
905 int32_t mRounding;
906 CSSToLayoutDeviceScale mDefaultScale;
907 bool mUpdatedDimensions;
908 nsSizeMode mSizeMode;
909 LayoutDeviceIntPoint mClientOffset;
910 LayoutDeviceIntPoint mChromeOffset;
912 // When loading a new tab or window via window.open, the child is
913 // responsible for loading the URL it wants into the new BrowserChild. When
914 // the parent receives the CreateWindow message, though, it sends a LoadURL
915 // message, usually for about:blank. It's important for the about:blank load
916 // to get processed because the Firefox frontend expects every new window to
917 // immediately start loading something (see bug 1123090). However, we want
918 // the child to process the LoadURL message before it returns from
919 // ProvideWindow so that the URL sent from the parent doesn't override the
920 // child's URL. This is not possible using our IPC mechanisms. To solve the
921 // problem, we skip sending the LoadURL message in the parent and instead
922 // return the URL as a result from CreateWindow. The child simulates
923 // receiving a LoadURL message before returning from ProvideWindow.
925 // The mCreatingWindow flag is set while dispatching CreateWindow. During
926 // that time, any LoadURL calls are skipped.
927 bool mCreatingWindow;
929 // When loading a new tab or window via window.open, we want to ensure that
930 // frame scripts for that tab are loaded before any scripts start to run in
931 // the window. We can't load the frame scripts the normal way, using
932 // separate IPC messages, since they won't be processed by the child until
933 // returning to the event loop, which is too late. Instead, we queue up
934 // frame scripts that we intend to load and send them as part of the
935 // CreateWindow response. Then BrowserChild loads them immediately.
936 nsTArray<FrameScriptInfo> mDelayedFrameScripts;
938 // Cached cursor setting from BrowserChild. When the cursor is over the
939 // tab, it should take this appearance.
940 nsIWidget::Cursor mCursor;
942 nsTArray<nsString> mVerifyDropLinks;
944 RefPtr<VsyncParent> mVsyncParent;
946 #ifdef DEBUG
947 int32_t mActiveSupressDisplayportCount = 0;
948 #endif
950 // When true, we've initiated normal shutdown and notified our managing
951 // PContent.
952 bool mMarkedDestroying : 1;
953 // When true, the BrowserParent is invalid and we should not send IPC
954 // messages anymore.
955 bool mIsDestroyed : 1;
956 // True if the cursor changes from the BrowserChild should change the widget
957 // cursor. This happens whenever the cursor is in the remote target's
958 // region.
959 bool mRemoteTargetSetsCursor : 1;
961 // If this flag is set, then the tab's layers will be preserved even when
962 // the tab's docshell is inactive.
963 bool mIsPreservingLayers : 1;
965 // Holds the most recent value passed to the RenderLayers function. This
966 // does not necessarily mean that the layers have finished rendering
967 // and have uploaded - for that, use mHasLayers.
968 bool mRenderLayers : 1;
970 // True if process should be set to a higher priority.
971 bool mPriorityHint : 1;
973 // True if the compositor has reported that the BrowserChild has uploaded
974 // layers.
975 bool mHasLayers : 1;
977 // True if this BrowserParent has had its layer tree sent to the compositor
978 // at least once.
979 bool mHasPresented : 1;
981 // True when the remote browser is created and ready to handle input events.
982 bool mIsReadyToHandleInputEvents : 1;
984 // True if we suppress the eMouseEnterIntoWidget event due to the
985 // BrowserChild was not ready to handle it. We will resend it when the next
986 // time we fire a mouse event and the BrowserChild is ready.
987 bool mIsMouseEnterIntoWidgetEventSuppressed : 1;
989 // True after RecvLockNativePointer has been called and until
990 // UnlockNativePointer has been called.
991 bool mLockedNativePointer : 1;
993 // True between ShowTooltip and HideTooltip messages.
994 bool mShowingTooltip : 1;
997 struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {
998 public:
999 explicit AutoUseNewTab(BrowserParent* aNewTab) : mNewTab(aNewTab) {
1000 MOZ_ASSERT(!aNewTab->mCreatingWindow);
1001 aNewTab->mCreatingWindow = true;
1004 ~AutoUseNewTab() { mNewTab->mCreatingWindow = false; }
1006 private:
1007 RefPtr<BrowserParent> mNewTab;
1010 } // namespace dom
1011 } // namespace mozilla
1013 #endif // mozilla_dom_BrowserParent_h