no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / ipc / BrowserParent.h
blob63a52c6ac466f0bdcc214c92be15ff74e1225e12
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,
599 const MaybeDiscarded<BrowsingContext>& aBrowsingContext);
601 bool GetGlobalJSObject(JSContext* cx, JSObject** globalp);
603 void StartPersistence(CanonicalBrowsingContext* aContext,
604 nsIWebBrowserPersistDocumentReceiver* aRecv,
605 ErrorResult& aRv);
607 bool HandleQueryContentEvent(mozilla::WidgetQueryContentEvent& aEvent);
609 bool SendInsertText(const nsString& aStringToInsert);
611 bool SendPasteTransferable(IPCTransferable&& aTransferable);
613 // Helper for transforming a point
614 LayoutDeviceIntPoint TransformPoint(
615 const LayoutDeviceIntPoint& aPoint,
616 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix);
617 LayoutDevicePoint TransformPoint(
618 const LayoutDevicePoint& aPoint,
619 const LayoutDeviceToLayoutDeviceMatrix4x4& aMatrix);
621 // Transform a coordinate from the parent process coordinate space to the
622 // child process coordinate space.
623 LayoutDeviceIntPoint TransformParentToChild(const WidgetMouseEvent& aEvent);
624 LayoutDeviceIntPoint TransformParentToChild(
625 const LayoutDeviceIntPoint& aPoint);
626 LayoutDevicePoint TransformParentToChild(const LayoutDevicePoint& aPoint);
628 // Transform a coordinate from the child process coordinate space to the
629 // parent process coordinate space.
630 LayoutDeviceIntPoint TransformChildToParent(
631 const LayoutDeviceIntPoint& aPoint);
632 LayoutDevicePoint TransformChildToParent(const LayoutDevicePoint& aPoint);
633 LayoutDeviceIntRect TransformChildToParent(const LayoutDeviceIntRect& aRect);
635 // Returns the matrix that transforms event coordinates from the coordinate
636 // space of the child process to the coordinate space of the parent process.
637 LayoutDeviceToLayoutDeviceMatrix4x4 GetChildToParentConversionMatrix();
639 void SetChildToParentConversionMatrix(
640 const Maybe<LayoutDeviceToLayoutDeviceMatrix4x4>& aMatrix,
641 const ScreenRect& aRemoteDocumentRect);
643 // Returns the offset from the origin of our frameloader's nearest widget to
644 // the origin of its layout frame. This offset is used to translate event
645 // coordinates relative to the PuppetWidget origin in the child process.
647 // GOING AWAY. PLEASE AVOID ADDING CALLERS. Use the above tranformation
648 // methods instead.
649 LayoutDeviceIntPoint GetChildProcessOffset();
651 // Returns the offset from the on-screen origin of our top-level window's
652 // widget (including window decorations) to the origin of our frameloader's
653 // nearest widget. This offset is used to translate coordinates from the
654 // PuppetWidget's origin to absolute screen coordinates in the child.
655 LayoutDeviceIntPoint GetClientOffset();
657 void StopIMEStateManagement();
659 PPaymentRequestParent* AllocPPaymentRequestParent();
661 bool DeallocPPaymentRequestParent(PPaymentRequestParent* aActor);
663 bool SendLoadRemoteScript(const nsAString& aURL,
664 const bool& aRunInGlobalScope);
666 void LayerTreeUpdate(bool aActive);
668 mozilla::ipc::IPCResult RecvInvokeDragSession(
669 nsTArray<IPCTransferableData>&& aTransferables, const uint32_t& aAction,
670 Maybe<BigBuffer>&& aVisualDnDData, const uint32_t& aStride,
671 const gfx::SurfaceFormat& aFormat, const LayoutDeviceIntRect& aDragRect,
672 nsIPrincipal* aPrincipal, nsIContentSecurityPolicy* aCsp,
673 const CookieJarSettingsArgs& aCookieJarSettingsArgs,
674 const MaybeDiscarded<WindowContext>& aSourceWindowContext,
675 const MaybeDiscarded<WindowContext>& aSourceTopWindowContext);
677 void AddInitialDnDDataTo(IPCTransferableData* aTransferableData,
678 nsIPrincipal** aPrincipal);
680 bool TakeDragVisualization(RefPtr<mozilla::gfx::SourceSurface>& aSurface,
681 LayoutDeviceIntRect* aDragRect);
683 mozilla::ipc::IPCResult RecvEnsureLayersConnected(
684 CompositorOptions* aCompositorOptions);
686 // LiveResizeListener implementation
687 void LiveResizeStarted() override;
688 void LiveResizeStopped() override;
690 void SetReadyToHandleInputEvents() { mIsReadyToHandleInputEvents = true; }
691 bool IsReadyToHandleInputEvents() { return mIsReadyToHandleInputEvents; }
693 void NavigateByKey(bool aForward, bool aForDocumentNavigation);
695 bool GetDocShellIsActive();
696 void SetDocShellIsActive(bool aDocShellIsActive);
698 bool GetHasPresented();
699 bool GetHasLayers();
700 bool GetRenderLayers();
701 void SetRenderLayers(bool aRenderLayers);
702 bool GetPriorityHint();
703 void SetPriorityHint(bool aPriorityHint);
704 void PreserveLayers(bool aPreserveLayers);
705 void NotifyResolutionChanged();
707 bool CanCancelContentJS(nsIRemoteTab::NavigationType aNavigationType,
708 int32_t aNavigationIndex,
709 nsIURI* aNavigationURI) const;
711 // Called when the BrowserParent is being destroyed or entering bfcache.
712 void Deactivated();
714 protected:
715 friend BrowserBridgeParent;
716 friend BrowserHost;
718 void SetBrowserBridgeParent(BrowserBridgeParent* aBrowser);
719 void SetBrowserHost(BrowserHost* aBrowser);
721 bool ReceiveMessage(
722 const nsString& aMessage, bool aSync, ipc::StructuredCloneData* aData,
723 nsTArray<ipc::StructuredCloneData>* aJSONRetVal = nullptr);
725 virtual void ActorDestroy(ActorDestroyReason why) override;
727 mozilla::ipc::IPCResult RecvRemoteIsReadyToHandleInputEvents();
729 mozilla::ipc::IPCResult RecvSetDimensions(mozilla::DimensionRequest aRequest,
730 const double& aScale);
732 mozilla::ipc::IPCResult RecvShowCanvasPermissionPrompt(
733 const nsCString& aOrigin, const bool& aHideDoorHanger);
735 mozilla::ipc::IPCResult RecvSetSystemFont(const nsCString& aFontName);
736 mozilla::ipc::IPCResult RecvGetSystemFont(nsCString* aFontName);
738 mozilla::ipc::IPCResult RecvVisitURI(nsIURI* aURI, nsIURI* aLastVisitedURI,
739 const uint32_t& aFlags,
740 const uint64_t& aBrowserId);
742 mozilla::ipc::IPCResult RecvQueryVisitedState(
743 nsTArray<RefPtr<nsIURI>>&& aURIs);
745 mozilla::ipc::IPCResult RecvMaybeFireEmbedderLoadEvents(
746 EmbedderElementEventType aFireEventAtEmbeddingElement);
748 mozilla::ipc::IPCResult RecvRequestPointerLock(
749 RequestPointerLockResolver&& aResolve);
750 mozilla::ipc::IPCResult RecvReleasePointerLock();
752 mozilla::ipc::IPCResult RecvRequestPointerCapture(
753 const uint32_t& aPointerId, RequestPointerCaptureResolver&& aResolve);
754 mozilla::ipc::IPCResult RecvReleasePointerCapture(const uint32_t& aPointerId);
756 mozilla::ipc::IPCResult RecvShowDynamicToolbar();
758 private:
759 void SuppressDisplayport(bool aEnabled);
761 void SetRenderLayersInternal(bool aEnabled);
763 already_AddRefed<nsFrameLoader> GetFrameLoader(
764 bool aUseCachedFrameLoaderAfterDestroy = false) const;
766 void TryCacheDPIAndScale();
768 bool AsyncPanZoomEnabled() const;
770 // Update state prior to routing an APZ-aware event to the child process.
771 // |aOutTargetGuid| will contain the identifier
772 // of the APZC instance that handled the event. aOutTargetGuid may be null.
773 // |aOutInputBlockId| will contain the identifier of the input block
774 // that this event was added to, if there was one. aOutInputBlockId may be
775 // null. |aOutApzResponse| will contain the response that the APZ gave when
776 // processing the input block; this is used for generating appropriate
777 // pointercancel events.
778 void ApzAwareEventRoutingToChild(ScrollableLayerGuid* aOutTargetGuid,
779 uint64_t* aOutInputBlockId,
780 nsEventStatus* aOutApzResponse);
782 // When dropping links we perform a roundtrip from
783 // Parent (SendRealDragEvent) -> Child -> Parent (RecvDropLinks)
784 // and have to ensure that the child did not modify links to be loaded.
785 bool QueryDropLinksForVerification();
787 void UnlockNativePointer();
789 void UpdateNativePointerLockCenter(nsIWidget* aWidget);
791 private:
792 // This is used when APZ needs to find the BrowserParent associated with a
793 // layer to dispatch events.
794 typedef nsTHashMap<nsUint64HashKey, BrowserParent*> LayerToBrowserParentTable;
795 static LayerToBrowserParentTable* sLayerToBrowserParentTable;
797 static void AddBrowserParentToTable(layers::LayersId aLayersId,
798 BrowserParent* aBrowserParent);
800 static void RemoveBrowserParentFromTable(layers::LayersId aLayersId);
802 // Keeps track of which BrowserParent has keyboard focus.
803 // If nullptr, the parent process has focus.
804 // Use UpdateFocus() to manage.
805 static BrowserParent* sFocus;
807 // Keeps track of which top-level BrowserParent the keyboard focus is under.
808 // If nullptr, the parent process has focus.
809 // Use SetTopLevelWebFocus and UnsetTopLevelWebFocus to manage.
810 static BrowserParent* sTopLevelWebFocus;
812 // Setter for sTopLevelWebFocus
813 static void SetTopLevelWebFocus(BrowserParent* aBrowserParent);
815 // Unsetter for sTopLevelWebFocus; only unsets if argument matches
816 // current sTopLevelWebFocus. Use UnsetTopLevelWebFocusAll() to
817 // unset regardless of current value.
818 static void UnsetTopLevelWebFocus(BrowserParent* aBrowserParent);
820 // Recomputes sFocus and returns it.
821 static BrowserParent* UpdateFocus();
823 // Keeps track of which BrowserParent the real mouse event is sent to.
824 static BrowserParent* sLastMouseRemoteTarget;
826 // Unsetter for LastMouseRemoteTarget; only unsets if argument matches
827 // current sLastMouseRemoteTarget.
828 static void UnsetLastMouseRemoteTarget(BrowserParent* aBrowserParent);
830 struct APZData {
831 bool operator==(const APZData& aOther) const {
832 return aOther.guid == guid && aOther.blockId == blockId &&
833 aOther.apzResponse == apzResponse;
836 bool operator!=(const APZData& aOther) const { return !(*this == aOther); }
838 ScrollableLayerGuid guid;
839 uint64_t blockId;
840 nsEventStatus apzResponse;
842 void SendRealTouchMoveEvent(WidgetTouchEvent& aEvent, APZData& aAPZData,
843 uint32_t aConsecutiveTouchMoveCount);
845 void UpdateVsyncParentVsyncDispatcher();
847 public:
848 // Unsets sTopLevelWebFocus regardless of its current value.
849 static void UnsetTopLevelWebFocusAll();
851 // Recomputes focus when the BrowsingContext tree changes in a
852 // way that potentially invalidates the sFocus.
853 static void UpdateFocusFromBrowsingContext();
855 private:
856 TabId mTabId;
858 RefPtr<ContentParent> mManager;
859 // The root browsing context loaded in this BrowserParent.
860 RefPtr<CanonicalBrowsingContext> mBrowsingContext;
861 nsCOMPtr<nsILoadContext> mLoadContext;
862 RefPtr<Element> mFrameElement;
863 nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
864 // We keep a strong reference to the frameloader after we've sent the
865 // Destroy message and before we've received __delete__. This allows us to
866 // dispatch message manager messages during this time.
867 RefPtr<nsFrameLoader> mFrameLoader;
868 uint32_t mChromeFlags;
870 // Pointer back to BrowserBridgeParent if there is one associated with
871 // this BrowserParent. This is non-owning to avoid cycles and is managed
872 // by the BrowserBridgeParent instance, which has the strong reference
873 // to this BrowserParent.
874 BrowserBridgeParent* mBrowserBridgeParent;
875 // Pointer to the BrowserHost that owns us, if any. This is mutually
876 // exclusive with mBrowserBridgeParent, and one is guaranteed to be
877 // non-null.
878 BrowserHost* mBrowserHost;
880 ContentCacheInParent mContentCache;
882 layout::RemoteLayerTreeOwner mRemoteLayerTreeOwner;
884 Maybe<LayoutDeviceToLayoutDeviceMatrix4x4> mChildToParentConversionMatrix;
885 Maybe<ScreenRect> mRemoteDocumentRect;
887 // mWaitingReplyKeyboardEvents stores keyboard events which are sent from
888 // SendRealKeyEvent and the event will be back as a reply event. They are
889 // removed when RecvReplyKeyEvent receives corresponding event or newer event.
890 // Note that reply event will be used for handling non-reserved shortcut keys.
891 // Therefore, we need to store only important data for GlobalKeyHandler.
892 struct SentKeyEventData {
893 uint32_t mKeyCode;
894 uint32_t mCharCode;
895 uint32_t mPseudoCharCode;
896 KeyNameIndex mKeyNameIndex;
897 CodeNameIndex mCodeNameIndex;
898 Modifiers mModifiers;
899 nsID mUUID;
901 nsTArray<SentKeyEventData> mWaitingReplyKeyboardEvents;
903 nsIntRect mRect;
904 ScreenIntSize mDimensions;
905 float mDPI;
906 int32_t mRounding;
907 CSSToLayoutDeviceScale mDefaultScale;
908 bool mUpdatedDimensions;
909 nsSizeMode mSizeMode;
910 LayoutDeviceIntPoint mClientOffset;
911 LayoutDeviceIntPoint mChromeOffset;
913 // When loading a new tab or window via window.open, the child is
914 // responsible for loading the URL it wants into the new BrowserChild. When
915 // the parent receives the CreateWindow message, though, it sends a LoadURL
916 // message, usually for about:blank. It's important for the about:blank load
917 // to get processed because the Firefox frontend expects every new window to
918 // immediately start loading something (see bug 1123090). However, we want
919 // the child to process the LoadURL message before it returns from
920 // ProvideWindow so that the URL sent from the parent doesn't override the
921 // child's URL. This is not possible using our IPC mechanisms. To solve the
922 // problem, we skip sending the LoadURL message in the parent and instead
923 // return the URL as a result from CreateWindow. The child simulates
924 // receiving a LoadURL message before returning from ProvideWindow.
926 // The mCreatingWindow flag is set while dispatching CreateWindow. During
927 // that time, any LoadURL calls are skipped.
928 bool mCreatingWindow;
930 // When loading a new tab or window via window.open, we want to ensure that
931 // frame scripts for that tab are loaded before any scripts start to run in
932 // the window. We can't load the frame scripts the normal way, using
933 // separate IPC messages, since they won't be processed by the child until
934 // returning to the event loop, which is too late. Instead, we queue up
935 // frame scripts that we intend to load and send them as part of the
936 // CreateWindow response. Then BrowserChild loads them immediately.
937 nsTArray<FrameScriptInfo> mDelayedFrameScripts;
939 // Cached cursor setting from BrowserChild. When the cursor is over the
940 // tab, it should take this appearance.
941 nsIWidget::Cursor mCursor;
943 nsTArray<nsString> mVerifyDropLinks;
945 RefPtr<VsyncParent> mVsyncParent;
947 #ifdef DEBUG
948 int32_t mActiveSupressDisplayportCount = 0;
949 #endif
951 // When true, we've initiated normal shutdown and notified our managing
952 // PContent.
953 bool mMarkedDestroying : 1;
954 // When true, the BrowserParent is invalid and we should not send IPC
955 // messages anymore.
956 bool mIsDestroyed : 1;
957 // True if the cursor changes from the BrowserChild should change the widget
958 // cursor. This happens whenever the cursor is in the remote target's
959 // region.
960 bool mRemoteTargetSetsCursor : 1;
962 // If this flag is set, then the tab's layers will be preserved even when
963 // the tab's docshell is inactive.
964 bool mIsPreservingLayers : 1;
966 // Holds the most recent value passed to the RenderLayers function. This
967 // does not necessarily mean that the layers have finished rendering
968 // and have uploaded - for that, use mHasLayers.
969 bool mRenderLayers : 1;
971 // True if process should be set to a higher priority.
972 bool mPriorityHint : 1;
974 // True if the compositor has reported that the BrowserChild has uploaded
975 // layers.
976 bool mHasLayers : 1;
978 // True if this BrowserParent has had its layer tree sent to the compositor
979 // at least once.
980 bool mHasPresented : 1;
982 // True when the remote browser is created and ready to handle input events.
983 bool mIsReadyToHandleInputEvents : 1;
985 // True if we suppress the eMouseEnterIntoWidget event due to the
986 // BrowserChild was not ready to handle it. We will resend it when the next
987 // time we fire a mouse event and the BrowserChild is ready.
988 bool mIsMouseEnterIntoWidgetEventSuppressed : 1;
990 // True after RecvLockNativePointer has been called and until
991 // UnlockNativePointer has been called.
992 bool mLockedNativePointer : 1;
994 // True between ShowTooltip and HideTooltip messages.
995 bool mShowingTooltip : 1;
998 struct MOZ_STACK_CLASS BrowserParent::AutoUseNewTab final {
999 public:
1000 explicit AutoUseNewTab(BrowserParent* aNewTab) : mNewTab(aNewTab) {
1001 MOZ_ASSERT(!aNewTab->mCreatingWindow);
1002 aNewTab->mCreatingWindow = true;
1005 ~AutoUseNewTab() { mNewTab->mCreatingWindow = false; }
1007 private:
1008 RefPtr<BrowserParent> mNewTab;
1011 } // namespace dom
1012 } // namespace mozilla
1014 #endif // mozilla_dom_BrowserParent_h